ipx_proc.c 7.9 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, "%08X ", 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, "%08X ", ntohl(rt->ir_net));
  77. if (rt->ir_routed)
  78. seq_printf(seq, "%08X %02X%02X%02X%02X%02X%02X\n",
  79. 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 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, &i->if_sklist) {
  95. if (!pos)
  96. break;
  97. --pos;
  98. }
  99. spin_unlock_bh(&i->if_sklist_lock);
  100. if (!pos) {
  101. if (s)
  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, "%08X:%02X%02X%02X%02X%02X%02X:%04X ",
  175. 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, "%08X:%04X ", 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, "%08X:%02X%02X%02X%02X%02X%02X:%04X ",
  186. 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 %03u\n",
  193. sk_wmem_alloc_get(s),
  194. sk_rmem_alloc_get(s),
  195. s->sk_state,
  196. from_kuid_munged(seq_user_ns(seq), sock_i_uid(s)));
  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 */