x25_proc.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * X.25 Packet Layer release 002
  3. *
  4. * This is ALPHA test software. This code may break your machine,
  5. * randomly fail to work with new releases, misbehave and/or generally
  6. * screw up. It might even work.
  7. *
  8. * This code REQUIRES 2.4 with seq_file support
  9. *
  10. * This module:
  11. * This module is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. *
  16. * History
  17. * 2002/10/06 Arnaldo Carvalho de Melo seq_file support
  18. */
  19. #include <linux/init.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/seq_file.h>
  22. #include <net/net_namespace.h>
  23. #include <net/sock.h>
  24. #include <net/x25.h>
  25. #ifdef CONFIG_PROC_FS
  26. static __inline__ struct x25_route *x25_get_route_idx(loff_t pos)
  27. {
  28. struct list_head *route_entry;
  29. struct x25_route *rt = NULL;
  30. list_for_each(route_entry, &x25_route_list) {
  31. rt = list_entry(route_entry, struct x25_route, node);
  32. if (!pos--)
  33. goto found;
  34. }
  35. rt = NULL;
  36. found:
  37. return rt;
  38. }
  39. static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
  40. __acquires(x25_route_list_lock)
  41. {
  42. loff_t l = *pos;
  43. read_lock_bh(&x25_route_list_lock);
  44. return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN;
  45. }
  46. static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
  47. {
  48. struct x25_route *rt;
  49. ++*pos;
  50. if (v == SEQ_START_TOKEN) {
  51. rt = NULL;
  52. if (!list_empty(&x25_route_list))
  53. rt = list_entry(x25_route_list.next,
  54. struct x25_route, node);
  55. goto out;
  56. }
  57. rt = v;
  58. if (rt->node.next != &x25_route_list)
  59. rt = list_entry(rt->node.next, struct x25_route, node);
  60. else
  61. rt = NULL;
  62. out:
  63. return rt;
  64. }
  65. static void x25_seq_route_stop(struct seq_file *seq, void *v)
  66. __releases(x25_route_list_lock)
  67. {
  68. read_unlock_bh(&x25_route_list_lock);
  69. }
  70. static int x25_seq_route_show(struct seq_file *seq, void *v)
  71. {
  72. struct x25_route *rt;
  73. if (v == SEQ_START_TOKEN) {
  74. seq_puts(seq, "Address Digits Device\n");
  75. goto out;
  76. }
  77. rt = v;
  78. seq_printf(seq, "%-15s %-6d %-5s\n",
  79. rt->address.x25_addr, rt->sigdigits,
  80. rt->dev ? rt->dev->name : "???");
  81. out:
  82. return 0;
  83. }
  84. static __inline__ struct sock *x25_get_socket_idx(loff_t pos)
  85. {
  86. struct sock *s;
  87. struct hlist_node *node;
  88. sk_for_each(s, node, &x25_list)
  89. if (!pos--)
  90. goto found;
  91. s = NULL;
  92. found:
  93. return s;
  94. }
  95. static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
  96. __acquires(x25_list_lock)
  97. {
  98. loff_t l = *pos;
  99. read_lock_bh(&x25_list_lock);
  100. return l ? x25_get_socket_idx(--l) : SEQ_START_TOKEN;
  101. }
  102. static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
  103. {
  104. struct sock *s;
  105. ++*pos;
  106. if (v == SEQ_START_TOKEN) {
  107. s = sk_head(&x25_list);
  108. goto out;
  109. }
  110. s = sk_next(v);
  111. out:
  112. return s;
  113. }
  114. static void x25_seq_socket_stop(struct seq_file *seq, void *v)
  115. __releases(x25_list_lock)
  116. {
  117. read_unlock_bh(&x25_list_lock);
  118. }
  119. static int x25_seq_socket_show(struct seq_file *seq, void *v)
  120. {
  121. struct sock *s;
  122. struct x25_sock *x25;
  123. struct net_device *dev;
  124. const char *devname;
  125. if (v == SEQ_START_TOKEN) {
  126. seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
  127. "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
  128. goto out;
  129. }
  130. s = v;
  131. x25 = x25_sk(s);
  132. if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
  133. devname = "???";
  134. else
  135. devname = x25->neighbour->dev->name;
  136. seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
  137. "%3lu %3lu %3lu %5d %5d %ld\n",
  138. !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
  139. !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
  140. devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
  141. x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
  142. x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
  143. atomic_read(&s->sk_wmem_alloc),
  144. atomic_read(&s->sk_rmem_alloc),
  145. s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
  146. out:
  147. return 0;
  148. }
  149. static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
  150. {
  151. struct x25_forward *f;
  152. struct list_head *entry;
  153. list_for_each(entry, &x25_forward_list) {
  154. f = list_entry(entry, struct x25_forward, node);
  155. if (!pos--)
  156. goto found;
  157. }
  158. f = NULL;
  159. found:
  160. return f;
  161. }
  162. static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
  163. __acquires(x25_forward_list_lock)
  164. {
  165. loff_t l = *pos;
  166. read_lock_bh(&x25_forward_list_lock);
  167. return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN;
  168. }
  169. static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
  170. {
  171. struct x25_forward *f;
  172. ++*pos;
  173. if (v == SEQ_START_TOKEN) {
  174. f = NULL;
  175. if (!list_empty(&x25_forward_list))
  176. f = list_entry(x25_forward_list.next,
  177. struct x25_forward, node);
  178. goto out;
  179. }
  180. f = v;
  181. if (f->node.next != &x25_forward_list)
  182. f = list_entry(f->node.next, struct x25_forward, node);
  183. else
  184. f = NULL;
  185. out:
  186. return f;
  187. }
  188. static void x25_seq_forward_stop(struct seq_file *seq, void *v)
  189. __releases(x25_forward_list_lock)
  190. {
  191. read_unlock_bh(&x25_forward_list_lock);
  192. }
  193. static int x25_seq_forward_show(struct seq_file *seq, void *v)
  194. {
  195. struct x25_forward *f;
  196. if (v == SEQ_START_TOKEN) {
  197. seq_printf(seq, "lci dev1 dev2\n");
  198. goto out;
  199. }
  200. f = v;
  201. seq_printf(seq, "%d %-10s %-10s\n",
  202. f->lci, f->dev1->name, f->dev2->name);
  203. out:
  204. return 0;
  205. }
  206. static const struct seq_operations x25_seq_route_ops = {
  207. .start = x25_seq_route_start,
  208. .next = x25_seq_route_next,
  209. .stop = x25_seq_route_stop,
  210. .show = x25_seq_route_show,
  211. };
  212. static const struct seq_operations x25_seq_socket_ops = {
  213. .start = x25_seq_socket_start,
  214. .next = x25_seq_socket_next,
  215. .stop = x25_seq_socket_stop,
  216. .show = x25_seq_socket_show,
  217. };
  218. static const struct seq_operations x25_seq_forward_ops = {
  219. .start = x25_seq_forward_start,
  220. .next = x25_seq_forward_next,
  221. .stop = x25_seq_forward_stop,
  222. .show = x25_seq_forward_show,
  223. };
  224. static int x25_seq_socket_open(struct inode *inode, struct file *file)
  225. {
  226. return seq_open(file, &x25_seq_socket_ops);
  227. }
  228. static int x25_seq_route_open(struct inode *inode, struct file *file)
  229. {
  230. return seq_open(file, &x25_seq_route_ops);
  231. }
  232. static int x25_seq_forward_open(struct inode *inode, struct file *file)
  233. {
  234. return seq_open(file, &x25_seq_forward_ops);
  235. }
  236. static const struct file_operations x25_seq_socket_fops = {
  237. .owner = THIS_MODULE,
  238. .open = x25_seq_socket_open,
  239. .read = seq_read,
  240. .llseek = seq_lseek,
  241. .release = seq_release,
  242. };
  243. static const struct file_operations x25_seq_route_fops = {
  244. .owner = THIS_MODULE,
  245. .open = x25_seq_route_open,
  246. .read = seq_read,
  247. .llseek = seq_lseek,
  248. .release = seq_release,
  249. };
  250. static const struct file_operations x25_seq_forward_fops = {
  251. .owner = THIS_MODULE,
  252. .open = x25_seq_forward_open,
  253. .read = seq_read,
  254. .llseek = seq_lseek,
  255. .release = seq_release,
  256. };
  257. static struct proc_dir_entry *x25_proc_dir;
  258. int __init x25_proc_init(void)
  259. {
  260. struct proc_dir_entry *p;
  261. int rc = -ENOMEM;
  262. x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
  263. if (!x25_proc_dir)
  264. goto out;
  265. p = proc_create("route", S_IRUGO, x25_proc_dir, &x25_seq_route_fops);
  266. if (!p)
  267. goto out_route;
  268. p = proc_create("socket", S_IRUGO, x25_proc_dir, &x25_seq_socket_fops);
  269. if (!p)
  270. goto out_socket;
  271. p = proc_create("forward", S_IRUGO, x25_proc_dir,
  272. &x25_seq_forward_fops);
  273. if (!p)
  274. goto out_forward;
  275. rc = 0;
  276. out:
  277. return rc;
  278. out_forward:
  279. remove_proc_entry("socket", x25_proc_dir);
  280. out_socket:
  281. remove_proc_entry("route", x25_proc_dir);
  282. out_route:
  283. remove_proc_entry("x25", init_net.proc_net);
  284. goto out;
  285. }
  286. void __exit x25_proc_exit(void)
  287. {
  288. remove_proc_entry("forward", x25_proc_dir);
  289. remove_proc_entry("route", x25_proc_dir);
  290. remove_proc_entry("socket", x25_proc_dir);
  291. remove_proc_entry("x25", init_net.proc_net);
  292. }
  293. #else /* CONFIG_PROC_FS */
  294. int __init x25_proc_init(void)
  295. {
  296. return 0;
  297. }
  298. void __exit x25_proc_exit(void)
  299. {
  300. }
  301. #endif /* CONFIG_PROC_FS */