x25_proc.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
  85. __acquires(x25_list_lock)
  86. {
  87. read_lock_bh(&x25_list_lock);
  88. return seq_hlist_start_head(&x25_list, *pos);
  89. }
  90. static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
  91. {
  92. return seq_hlist_next(v, &x25_list, pos);
  93. }
  94. static void x25_seq_socket_stop(struct seq_file *seq, void *v)
  95. __releases(x25_list_lock)
  96. {
  97. read_unlock_bh(&x25_list_lock);
  98. }
  99. static int x25_seq_socket_show(struct seq_file *seq, void *v)
  100. {
  101. struct sock *s;
  102. struct x25_sock *x25;
  103. struct net_device *dev;
  104. const char *devname;
  105. if (v == SEQ_START_TOKEN) {
  106. seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
  107. "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
  108. goto out;
  109. }
  110. s = sk_entry(v);
  111. x25 = x25_sk(s);
  112. if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
  113. devname = "???";
  114. else
  115. devname = x25->neighbour->dev->name;
  116. seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
  117. "%3lu %3lu %3lu %5d %5d %ld\n",
  118. !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
  119. !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
  120. devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
  121. x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
  122. x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
  123. sk_wmem_alloc_get(s),
  124. sk_rmem_alloc_get(s),
  125. s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
  126. out:
  127. return 0;
  128. }
  129. static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
  130. {
  131. struct x25_forward *f;
  132. struct list_head *entry;
  133. list_for_each(entry, &x25_forward_list) {
  134. f = list_entry(entry, struct x25_forward, node);
  135. if (!pos--)
  136. goto found;
  137. }
  138. f = NULL;
  139. found:
  140. return f;
  141. }
  142. static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
  143. __acquires(x25_forward_list_lock)
  144. {
  145. loff_t l = *pos;
  146. read_lock_bh(&x25_forward_list_lock);
  147. return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN;
  148. }
  149. static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
  150. {
  151. struct x25_forward *f;
  152. ++*pos;
  153. if (v == SEQ_START_TOKEN) {
  154. f = NULL;
  155. if (!list_empty(&x25_forward_list))
  156. f = list_entry(x25_forward_list.next,
  157. struct x25_forward, node);
  158. goto out;
  159. }
  160. f = v;
  161. if (f->node.next != &x25_forward_list)
  162. f = list_entry(f->node.next, struct x25_forward, node);
  163. else
  164. f = NULL;
  165. out:
  166. return f;
  167. }
  168. static void x25_seq_forward_stop(struct seq_file *seq, void *v)
  169. __releases(x25_forward_list_lock)
  170. {
  171. read_unlock_bh(&x25_forward_list_lock);
  172. }
  173. static int x25_seq_forward_show(struct seq_file *seq, void *v)
  174. {
  175. struct x25_forward *f;
  176. if (v == SEQ_START_TOKEN) {
  177. seq_printf(seq, "lci dev1 dev2\n");
  178. goto out;
  179. }
  180. f = v;
  181. seq_printf(seq, "%d %-10s %-10s\n",
  182. f->lci, f->dev1->name, f->dev2->name);
  183. out:
  184. return 0;
  185. }
  186. static const struct seq_operations x25_seq_route_ops = {
  187. .start = x25_seq_route_start,
  188. .next = x25_seq_route_next,
  189. .stop = x25_seq_route_stop,
  190. .show = x25_seq_route_show,
  191. };
  192. static const struct seq_operations x25_seq_socket_ops = {
  193. .start = x25_seq_socket_start,
  194. .next = x25_seq_socket_next,
  195. .stop = x25_seq_socket_stop,
  196. .show = x25_seq_socket_show,
  197. };
  198. static const struct seq_operations x25_seq_forward_ops = {
  199. .start = x25_seq_forward_start,
  200. .next = x25_seq_forward_next,
  201. .stop = x25_seq_forward_stop,
  202. .show = x25_seq_forward_show,
  203. };
  204. static int x25_seq_socket_open(struct inode *inode, struct file *file)
  205. {
  206. return seq_open(file, &x25_seq_socket_ops);
  207. }
  208. static int x25_seq_route_open(struct inode *inode, struct file *file)
  209. {
  210. return seq_open(file, &x25_seq_route_ops);
  211. }
  212. static int x25_seq_forward_open(struct inode *inode, struct file *file)
  213. {
  214. return seq_open(file, &x25_seq_forward_ops);
  215. }
  216. static const struct file_operations x25_seq_socket_fops = {
  217. .owner = THIS_MODULE,
  218. .open = x25_seq_socket_open,
  219. .read = seq_read,
  220. .llseek = seq_lseek,
  221. .release = seq_release,
  222. };
  223. static const struct file_operations x25_seq_route_fops = {
  224. .owner = THIS_MODULE,
  225. .open = x25_seq_route_open,
  226. .read = seq_read,
  227. .llseek = seq_lseek,
  228. .release = seq_release,
  229. };
  230. static const struct file_operations x25_seq_forward_fops = {
  231. .owner = THIS_MODULE,
  232. .open = x25_seq_forward_open,
  233. .read = seq_read,
  234. .llseek = seq_lseek,
  235. .release = seq_release,
  236. };
  237. static struct proc_dir_entry *x25_proc_dir;
  238. int __init x25_proc_init(void)
  239. {
  240. struct proc_dir_entry *p;
  241. int rc = -ENOMEM;
  242. x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
  243. if (!x25_proc_dir)
  244. goto out;
  245. p = proc_create("route", S_IRUGO, x25_proc_dir, &x25_seq_route_fops);
  246. if (!p)
  247. goto out_route;
  248. p = proc_create("socket", S_IRUGO, x25_proc_dir, &x25_seq_socket_fops);
  249. if (!p)
  250. goto out_socket;
  251. p = proc_create("forward", S_IRUGO, x25_proc_dir,
  252. &x25_seq_forward_fops);
  253. if (!p)
  254. goto out_forward;
  255. rc = 0;
  256. out:
  257. return rc;
  258. out_forward:
  259. remove_proc_entry("socket", x25_proc_dir);
  260. out_socket:
  261. remove_proc_entry("route", x25_proc_dir);
  262. out_route:
  263. remove_proc_entry("x25", init_net.proc_net);
  264. goto out;
  265. }
  266. void __exit x25_proc_exit(void)
  267. {
  268. remove_proc_entry("forward", x25_proc_dir);
  269. remove_proc_entry("route", x25_proc_dir);
  270. remove_proc_entry("socket", x25_proc_dir);
  271. remove_proc_entry("x25", init_net.proc_net);
  272. }
  273. #else /* CONFIG_PROC_FS */
  274. int __init x25_proc_init(void)
  275. {
  276. return 0;
  277. }
  278. void __exit x25_proc_exit(void)
  279. {
  280. }
  281. #endif /* CONFIG_PROC_FS */