atalk_proc.c 6.9 KB

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