ipx_proc.c 8.0 KB

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