ipx_proc.c 9.1 KB

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