atalk_proc.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * atalk_proc.c - proc support for Appletalk
  3. *
  4. * Copyright(c) Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, version 2.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/seq_file.h>
  13. #include <net/net_namespace.h>
  14. #include <net/sock.h>
  15. #include <linux/atalk.h>
  16. static __inline__ struct atalk_iface *atalk_get_interface_idx(loff_t pos)
  17. {
  18. struct atalk_iface *i;
  19. for (i = atalk_interfaces; pos && i; i = i->next)
  20. --pos;
  21. return i;
  22. }
  23. static void *atalk_seq_interface_start(struct seq_file *seq, loff_t *pos)
  24. __acquires(atalk_interfaces_lock)
  25. {
  26. loff_t l = *pos;
  27. read_lock_bh(&atalk_interfaces_lock);
  28. return l ? atalk_get_interface_idx(--l) : SEQ_START_TOKEN;
  29. }
  30. static void *atalk_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos)
  31. {
  32. struct atalk_iface *i;
  33. ++*pos;
  34. if (v == SEQ_START_TOKEN) {
  35. i = NULL;
  36. if (atalk_interfaces)
  37. i = atalk_interfaces;
  38. goto out;
  39. }
  40. i = v;
  41. i = i->next;
  42. out:
  43. return i;
  44. }
  45. static void atalk_seq_interface_stop(struct seq_file *seq, void *v)
  46. __releases(atalk_interfaces_lock)
  47. {
  48. read_unlock_bh(&atalk_interfaces_lock);
  49. }
  50. static int atalk_seq_interface_show(struct seq_file *seq, void *v)
  51. {
  52. struct atalk_iface *iface;
  53. if (v == SEQ_START_TOKEN) {
  54. seq_puts(seq, "Interface Address Networks "
  55. "Status\n");
  56. goto out;
  57. }
  58. iface = v;
  59. seq_printf(seq, "%-16s %04X:%02X %04X-%04X %d\n",
  60. iface->dev->name, ntohs(iface->address.s_net),
  61. iface->address.s_node, ntohs(iface->nets.nr_firstnet),
  62. ntohs(iface->nets.nr_lastnet), iface->status);
  63. out:
  64. return 0;
  65. }
  66. static __inline__ struct atalk_route *atalk_get_route_idx(loff_t pos)
  67. {
  68. struct atalk_route *r;
  69. for (r = atalk_routes; pos && r; r = r->next)
  70. --pos;
  71. return r;
  72. }
  73. static void *atalk_seq_route_start(struct seq_file *seq, loff_t *pos)
  74. __acquires(atalk_routes_lock)
  75. {
  76. loff_t l = *pos;
  77. read_lock_bh(&atalk_routes_lock);
  78. return l ? atalk_get_route_idx(--l) : SEQ_START_TOKEN;
  79. }
  80. static void *atalk_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
  81. {
  82. struct atalk_route *r;
  83. ++*pos;
  84. if (v == SEQ_START_TOKEN) {
  85. r = NULL;
  86. if (atalk_routes)
  87. r = atalk_routes;
  88. goto out;
  89. }
  90. r = v;
  91. r = r->next;
  92. out:
  93. return r;
  94. }
  95. static void atalk_seq_route_stop(struct seq_file *seq, void *v)
  96. __releases(atalk_routes_lock)
  97. {
  98. read_unlock_bh(&atalk_routes_lock);
  99. }
  100. static int atalk_seq_route_show(struct seq_file *seq, void *v)
  101. {
  102. struct atalk_route *rt;
  103. if (v == SEQ_START_TOKEN) {
  104. seq_puts(seq, "Target Router Flags Dev\n");
  105. goto out;
  106. }
  107. if (atrtr_default.dev) {
  108. rt = &atrtr_default;
  109. seq_printf(seq, "Default %04X:%02X %-4d %s\n",
  110. ntohs(rt->gateway.s_net), rt->gateway.s_node,
  111. rt->flags, rt->dev->name);
  112. }
  113. rt = v;
  114. seq_printf(seq, "%04X:%02X %04X:%02X %-4d %s\n",
  115. ntohs(rt->target.s_net), rt->target.s_node,
  116. ntohs(rt->gateway.s_net), rt->gateway.s_node,
  117. rt->flags, rt->dev->name);
  118. out:
  119. return 0;
  120. }
  121. static void *atalk_seq_socket_start(struct seq_file *seq, loff_t *pos)
  122. __acquires(atalk_sockets_lock)
  123. {
  124. read_lock_bh(&atalk_sockets_lock);
  125. return seq_hlist_start_head(&atalk_sockets, *pos);
  126. }
  127. static void *atalk_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
  128. {
  129. return seq_hlist_next(v, &atalk_sockets, pos);
  130. }
  131. static void atalk_seq_socket_stop(struct seq_file *seq, void *v)
  132. __releases(atalk_sockets_lock)
  133. {
  134. read_unlock_bh(&atalk_sockets_lock);
  135. }
  136. static int atalk_seq_socket_show(struct seq_file *seq, void *v)
  137. {
  138. struct sock *s;
  139. struct atalk_sock *at;
  140. if (v == SEQ_START_TOKEN) {
  141. seq_printf(seq, "Type Local_addr Remote_addr Tx_queue "
  142. "Rx_queue St UID\n");
  143. goto out;
  144. }
  145. s = sk_entry(v);
  146. at = at_sk(s);
  147. seq_printf(seq, "%02X %04X:%02X:%02X %04X:%02X:%02X %08X:%08X "
  148. "%02X %d\n",
  149. s->sk_type, ntohs(at->src_net), at->src_node, at->src_port,
  150. ntohs(at->dest_net), at->dest_node, at->dest_port,
  151. sk_wmem_alloc_get(s),
  152. sk_rmem_alloc_get(s),
  153. s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
  154. out:
  155. return 0;
  156. }
  157. static const struct seq_operations atalk_seq_interface_ops = {
  158. .start = atalk_seq_interface_start,
  159. .next = atalk_seq_interface_next,
  160. .stop = atalk_seq_interface_stop,
  161. .show = atalk_seq_interface_show,
  162. };
  163. static const struct seq_operations atalk_seq_route_ops = {
  164. .start = atalk_seq_route_start,
  165. .next = atalk_seq_route_next,
  166. .stop = atalk_seq_route_stop,
  167. .show = atalk_seq_route_show,
  168. };
  169. static const struct seq_operations atalk_seq_socket_ops = {
  170. .start = atalk_seq_socket_start,
  171. .next = atalk_seq_socket_next,
  172. .stop = atalk_seq_socket_stop,
  173. .show = atalk_seq_socket_show,
  174. };
  175. static int atalk_seq_interface_open(struct inode *inode, struct file *file)
  176. {
  177. return seq_open(file, &atalk_seq_interface_ops);
  178. }
  179. static int atalk_seq_route_open(struct inode *inode, struct file *file)
  180. {
  181. return seq_open(file, &atalk_seq_route_ops);
  182. }
  183. static int atalk_seq_socket_open(struct inode *inode, struct file *file)
  184. {
  185. return seq_open(file, &atalk_seq_socket_ops);
  186. }
  187. static const struct file_operations atalk_seq_interface_fops = {
  188. .owner = THIS_MODULE,
  189. .open = atalk_seq_interface_open,
  190. .read = seq_read,
  191. .llseek = seq_lseek,
  192. .release = seq_release,
  193. };
  194. static const struct file_operations atalk_seq_route_fops = {
  195. .owner = THIS_MODULE,
  196. .open = atalk_seq_route_open,
  197. .read = seq_read,
  198. .llseek = seq_lseek,
  199. .release = seq_release,
  200. };
  201. static const struct file_operations atalk_seq_socket_fops = {
  202. .owner = THIS_MODULE,
  203. .open = atalk_seq_socket_open,
  204. .read = seq_read,
  205. .llseek = seq_lseek,
  206. .release = seq_release,
  207. };
  208. static struct proc_dir_entry *atalk_proc_dir;
  209. int __init atalk_proc_init(void)
  210. {
  211. struct proc_dir_entry *p;
  212. int rc = -ENOMEM;
  213. atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
  214. if (!atalk_proc_dir)
  215. goto out;
  216. p = proc_create("interface", S_IRUGO, atalk_proc_dir,
  217. &atalk_seq_interface_fops);
  218. if (!p)
  219. goto out_interface;
  220. p = proc_create("route", S_IRUGO, atalk_proc_dir,
  221. &atalk_seq_route_fops);
  222. if (!p)
  223. goto out_route;
  224. p = proc_create("socket", S_IRUGO, atalk_proc_dir,
  225. &atalk_seq_socket_fops);
  226. if (!p)
  227. goto out_socket;
  228. p = proc_create("arp", S_IRUGO, atalk_proc_dir, &atalk_seq_arp_fops);
  229. if (!p)
  230. goto out_arp;
  231. rc = 0;
  232. out:
  233. return rc;
  234. out_arp:
  235. remove_proc_entry("socket", atalk_proc_dir);
  236. out_socket:
  237. remove_proc_entry("route", atalk_proc_dir);
  238. out_route:
  239. remove_proc_entry("interface", atalk_proc_dir);
  240. out_interface:
  241. remove_proc_entry("atalk", init_net.proc_net);
  242. goto out;
  243. }
  244. void __exit atalk_proc_exit(void)
  245. {
  246. remove_proc_entry("interface", atalk_proc_dir);
  247. remove_proc_entry("route", atalk_proc_dir);
  248. remove_proc_entry("socket", atalk_proc_dir);
  249. remove_proc_entry("arp", atalk_proc_dir);
  250. remove_proc_entry("atalk", init_net.proc_net);
  251. }