ipx_proc.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * IPX proc routines
  3. *
  4. * Copyright(C) Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2002
  5. */
  6. #include <linux/init.h>
  7. #ifdef CONFIG_PROC_FS
  8. #include <linux/proc_fs.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/seq_file.h>
  11. #include <net/net_namespace.h>
  12. #include <net/tcp_states.h>
  13. #include <net/ipx.h>
  14. static void *ipx_seq_interface_start(struct seq_file *seq, loff_t *pos)
  15. {
  16. spin_lock_bh(&ipx_interfaces_lock);
  17. return seq_list_start_head(&ipx_interfaces, *pos);
  18. }
  19. static void *ipx_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos)
  20. {
  21. return seq_list_next(v, &ipx_interfaces, pos);
  22. }
  23. static void ipx_seq_interface_stop(struct seq_file *seq, void *v)
  24. {
  25. spin_unlock_bh(&ipx_interfaces_lock);
  26. }
  27. static int ipx_seq_interface_show(struct seq_file *seq, void *v)
  28. {
  29. struct ipx_interface *i;
  30. if (v == &ipx_interfaces) {
  31. seq_puts(seq, "Network Node_Address Primary Device "
  32. "Frame_Type");
  33. #ifdef IPX_REFCNT_DEBUG
  34. seq_puts(seq, " refcnt");
  35. #endif
  36. seq_puts(seq, "\n");
  37. goto out;
  38. }
  39. i = list_entry(v, struct ipx_interface, node);
  40. seq_printf(seq, "%08lX ", (unsigned long int)ntohl(i->if_netnum));
  41. seq_printf(seq, "%02X%02X%02X%02X%02X%02X ",
  42. i->if_node[0], i->if_node[1], i->if_node[2],
  43. i->if_node[3], i->if_node[4], i->if_node[5]);
  44. seq_printf(seq, "%-9s", i == ipx_primary_net ? "Yes" : "No");
  45. seq_printf(seq, "%-11s", ipx_device_name(i));
  46. seq_printf(seq, "%-9s", ipx_frame_name(i->if_dlink_type));
  47. #ifdef IPX_REFCNT_DEBUG
  48. seq_printf(seq, "%6d", atomic_read(&i->refcnt));
  49. #endif
  50. seq_puts(seq, "\n");
  51. out:
  52. return 0;
  53. }
  54. static void *ipx_seq_route_start(struct seq_file *seq, loff_t *pos)
  55. {
  56. read_lock_bh(&ipx_routes_lock);
  57. return seq_list_start_head(&ipx_routes, *pos);
  58. }
  59. static void *ipx_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
  60. {
  61. return seq_list_next(v, &ipx_routes, pos);
  62. }
  63. static void ipx_seq_route_stop(struct seq_file *seq, void *v)
  64. {
  65. read_unlock_bh(&ipx_routes_lock);
  66. }
  67. static int ipx_seq_route_show(struct seq_file *seq, void *v)
  68. {
  69. struct ipx_route *rt;
  70. if (v == &ipx_routes) {
  71. seq_puts(seq, "Network Router_Net Router_Node\n");
  72. goto out;
  73. }
  74. rt = list_entry(v, struct ipx_route, node);
  75. seq_printf(seq, "%08lX ", (unsigned long int)ntohl(rt->ir_net));
  76. if (rt->ir_routed)
  77. seq_printf(seq, "%08lX %02X%02X%02X%02X%02X%02X\n",
  78. (long unsigned int)ntohl(rt->ir_intrfc->if_netnum),
  79. rt->ir_router_node[0], rt->ir_router_node[1],
  80. rt->ir_router_node[2], rt->ir_router_node[3],
  81. rt->ir_router_node[4], rt->ir_router_node[5]);
  82. else
  83. seq_puts(seq, "Directly Connected\n");
  84. out:
  85. return 0;
  86. }
  87. static __inline__ struct sock *ipx_get_socket_idx(loff_t pos)
  88. {
  89. struct sock *s = NULL;
  90. struct hlist_node *node;
  91. struct ipx_interface *i;
  92. list_for_each_entry(i, &ipx_interfaces, node) {
  93. spin_lock_bh(&i->if_sklist_lock);
  94. sk_for_each(s, node, &i->if_sklist) {
  95. if (!pos)
  96. break;
  97. --pos;
  98. }
  99. spin_unlock_bh(&i->if_sklist_lock);
  100. if (!pos) {
  101. if (node)
  102. goto found;
  103. break;
  104. }
  105. }
  106. s = NULL;
  107. found:
  108. return s;
  109. }
  110. static void *ipx_seq_socket_start(struct seq_file *seq, loff_t *pos)
  111. {
  112. loff_t l = *pos;
  113. spin_lock_bh(&ipx_interfaces_lock);
  114. return l ? ipx_get_socket_idx(--l) : SEQ_START_TOKEN;
  115. }
  116. static void *ipx_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
  117. {
  118. struct sock* sk, *next;
  119. struct ipx_interface *i;
  120. struct ipx_sock *ipxs;
  121. ++*pos;
  122. if (v == SEQ_START_TOKEN) {
  123. sk = NULL;
  124. i = ipx_interfaces_head();
  125. if (!i)
  126. goto out;
  127. sk = sk_head(&i->if_sklist);
  128. if (sk)
  129. spin_lock_bh(&i->if_sklist_lock);
  130. goto out;
  131. }
  132. sk = v;
  133. next = sk_next(sk);
  134. if (next) {
  135. sk = next;
  136. goto out;
  137. }
  138. ipxs = ipx_sk(sk);
  139. i = ipxs->intrfc;
  140. spin_unlock_bh(&i->if_sklist_lock);
  141. sk = NULL;
  142. for (;;) {
  143. if (i->node.next == &ipx_interfaces)
  144. break;
  145. i = list_entry(i->node.next, struct ipx_interface, node);
  146. spin_lock_bh(&i->if_sklist_lock);
  147. if (!hlist_empty(&i->if_sklist)) {
  148. sk = sk_head(&i->if_sklist);
  149. break;
  150. }
  151. spin_unlock_bh(&i->if_sklist_lock);
  152. }
  153. out:
  154. return sk;
  155. }
  156. static int ipx_seq_socket_show(struct seq_file *seq, void *v)
  157. {
  158. struct sock *s;
  159. struct ipx_sock *ipxs;
  160. if (v == SEQ_START_TOKEN) {
  161. #ifdef CONFIG_IPX_INTERN
  162. seq_puts(seq, "Local_Address "
  163. "Remote_Address Tx_Queue "
  164. "Rx_Queue State Uid\n");
  165. #else
  166. seq_puts(seq, "Local_Address Remote_Address "
  167. "Tx_Queue Rx_Queue State Uid\n");
  168. #endif
  169. goto out;
  170. }
  171. s = v;
  172. ipxs = ipx_sk(s);
  173. #ifdef CONFIG_IPX_INTERN
  174. seq_printf(seq, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
  175. (unsigned long)ntohl(ipxs->intrfc->if_netnum),
  176. ipxs->node[0], ipxs->node[1], ipxs->node[2], ipxs->node[3],
  177. ipxs->node[4], ipxs->node[5], ntohs(ipxs->port));
  178. #else
  179. seq_printf(seq, "%08lX:%04X ", (unsigned long) ntohl(ipxs->intrfc->if_netnum),
  180. ntohs(ipxs->port));
  181. #endif /* CONFIG_IPX_INTERN */
  182. if (s->sk_state != TCP_ESTABLISHED)
  183. seq_printf(seq, "%-28s", "Not_Connected");
  184. else {
  185. seq_printf(seq, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
  186. (unsigned long)ntohl(ipxs->dest_addr.net),
  187. ipxs->dest_addr.node[0], ipxs->dest_addr.node[1],
  188. ipxs->dest_addr.node[2], ipxs->dest_addr.node[3],
  189. ipxs->dest_addr.node[4], ipxs->dest_addr.node[5],
  190. ntohs(ipxs->dest_addr.sock));
  191. }
  192. seq_printf(seq, "%08X %08X %02X %03d\n",
  193. sk_wmem_alloc_get(s),
  194. sk_rmem_alloc_get(s),
  195. s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
  196. out:
  197. return 0;
  198. }
  199. static const struct seq_operations ipx_seq_interface_ops = {
  200. .start = ipx_seq_interface_start,
  201. .next = ipx_seq_interface_next,
  202. .stop = ipx_seq_interface_stop,
  203. .show = ipx_seq_interface_show,
  204. };
  205. static const struct seq_operations ipx_seq_route_ops = {
  206. .start = ipx_seq_route_start,
  207. .next = ipx_seq_route_next,
  208. .stop = ipx_seq_route_stop,
  209. .show = ipx_seq_route_show,
  210. };
  211. static const struct seq_operations ipx_seq_socket_ops = {
  212. .start = ipx_seq_socket_start,
  213. .next = ipx_seq_socket_next,
  214. .stop = ipx_seq_interface_stop,
  215. .show = ipx_seq_socket_show,
  216. };
  217. static int ipx_seq_route_open(struct inode *inode, struct file *file)
  218. {
  219. return seq_open(file, &ipx_seq_route_ops);
  220. }
  221. static int ipx_seq_interface_open(struct inode *inode, struct file *file)
  222. {
  223. return seq_open(file, &ipx_seq_interface_ops);
  224. }
  225. static int ipx_seq_socket_open(struct inode *inode, struct file *file)
  226. {
  227. return seq_open(file, &ipx_seq_socket_ops);
  228. }
  229. static const struct file_operations ipx_seq_interface_fops = {
  230. .owner = THIS_MODULE,
  231. .open = ipx_seq_interface_open,
  232. .read = seq_read,
  233. .llseek = seq_lseek,
  234. .release = seq_release,
  235. };
  236. static const struct file_operations ipx_seq_route_fops = {
  237. .owner = THIS_MODULE,
  238. .open = ipx_seq_route_open,
  239. .read = seq_read,
  240. .llseek = seq_lseek,
  241. .release = seq_release,
  242. };
  243. static const struct file_operations ipx_seq_socket_fops = {
  244. .owner = THIS_MODULE,
  245. .open = ipx_seq_socket_open,
  246. .read = seq_read,
  247. .llseek = seq_lseek,
  248. .release = seq_release,
  249. };
  250. static struct proc_dir_entry *ipx_proc_dir;
  251. int __init ipx_proc_init(void)
  252. {
  253. struct proc_dir_entry *p;
  254. int rc = -ENOMEM;
  255. ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
  256. if (!ipx_proc_dir)
  257. goto out;
  258. p = proc_create("interface", S_IRUGO,
  259. ipx_proc_dir, &ipx_seq_interface_fops);
  260. if (!p)
  261. goto out_interface;
  262. p = proc_create("route", S_IRUGO, ipx_proc_dir, &ipx_seq_route_fops);
  263. if (!p)
  264. goto out_route;
  265. p = proc_create("socket", S_IRUGO, ipx_proc_dir, &ipx_seq_socket_fops);
  266. if (!p)
  267. goto out_socket;
  268. rc = 0;
  269. out:
  270. return rc;
  271. out_socket:
  272. remove_proc_entry("route", ipx_proc_dir);
  273. out_route:
  274. remove_proc_entry("interface", ipx_proc_dir);
  275. out_interface:
  276. remove_proc_entry("ipx", init_net.proc_net);
  277. goto out;
  278. }
  279. void __exit ipx_proc_exit(void)
  280. {
  281. remove_proc_entry("interface", ipx_proc_dir);
  282. remove_proc_entry("route", ipx_proc_dir);
  283. remove_proc_entry("socket", ipx_proc_dir);
  284. remove_proc_entry("ipx", init_net.proc_net);
  285. }
  286. #else /* CONFIG_PROC_FS */
  287. int __init ipx_proc_init(void)
  288. {
  289. return 0;
  290. }
  291. void __exit ipx_proc_exit(void)
  292. {
  293. }
  294. #endif /* CONFIG_PROC_FS */