x25_proc.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. {
  41. loff_t l = *pos;
  42. read_lock_bh(&x25_route_list_lock);
  43. return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN;
  44. }
  45. static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
  46. {
  47. struct x25_route *rt;
  48. ++*pos;
  49. if (v == SEQ_START_TOKEN) {
  50. rt = NULL;
  51. if (!list_empty(&x25_route_list))
  52. rt = list_entry(x25_route_list.next,
  53. struct x25_route, node);
  54. goto out;
  55. }
  56. rt = v;
  57. if (rt->node.next != &x25_route_list)
  58. rt = list_entry(rt->node.next, struct x25_route, node);
  59. else
  60. rt = NULL;
  61. out:
  62. return rt;
  63. }
  64. static void x25_seq_route_stop(struct seq_file *seq, void *v)
  65. {
  66. read_unlock_bh(&x25_route_list_lock);
  67. }
  68. static int x25_seq_route_show(struct seq_file *seq, void *v)
  69. {
  70. struct x25_route *rt;
  71. if (v == SEQ_START_TOKEN) {
  72. seq_puts(seq, "Address Digits Device\n");
  73. goto out;
  74. }
  75. rt = v;
  76. seq_printf(seq, "%-15s %-6d %-5s\n",
  77. rt->address.x25_addr, rt->sigdigits,
  78. rt->dev ? rt->dev->name : "???");
  79. out:
  80. return 0;
  81. }
  82. static __inline__ struct sock *x25_get_socket_idx(loff_t pos)
  83. {
  84. struct sock *s;
  85. struct hlist_node *node;
  86. sk_for_each(s, node, &x25_list)
  87. if (!pos--)
  88. goto found;
  89. s = NULL;
  90. found:
  91. return s;
  92. }
  93. static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
  94. {
  95. loff_t l = *pos;
  96. read_lock_bh(&x25_list_lock);
  97. return l ? x25_get_socket_idx(--l) : SEQ_START_TOKEN;
  98. }
  99. static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
  100. {
  101. struct sock *s;
  102. ++*pos;
  103. if (v == SEQ_START_TOKEN) {
  104. s = sk_head(&x25_list);
  105. goto out;
  106. }
  107. s = sk_next(v);
  108. out:
  109. return s;
  110. }
  111. static void x25_seq_socket_stop(struct seq_file *seq, void *v)
  112. {
  113. read_unlock_bh(&x25_list_lock);
  114. }
  115. static int x25_seq_socket_show(struct seq_file *seq, void *v)
  116. {
  117. struct sock *s;
  118. struct x25_sock *x25;
  119. struct net_device *dev;
  120. const char *devname;
  121. if (v == SEQ_START_TOKEN) {
  122. seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
  123. "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
  124. goto out;
  125. }
  126. s = v;
  127. x25 = x25_sk(s);
  128. if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
  129. devname = "???";
  130. else
  131. devname = x25->neighbour->dev->name;
  132. seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
  133. "%3lu %3lu %3lu %5d %5d %ld\n",
  134. !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
  135. !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
  136. devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
  137. x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
  138. x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
  139. atomic_read(&s->sk_wmem_alloc),
  140. atomic_read(&s->sk_rmem_alloc),
  141. s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
  142. out:
  143. return 0;
  144. }
  145. static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
  146. {
  147. struct x25_forward *f;
  148. struct list_head *entry;
  149. list_for_each(entry, &x25_forward_list) {
  150. f = list_entry(entry, struct x25_forward, node);
  151. if (!pos--)
  152. goto found;
  153. }
  154. f = NULL;
  155. found:
  156. return f;
  157. }
  158. static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
  159. {
  160. loff_t l = *pos;
  161. read_lock_bh(&x25_forward_list_lock);
  162. return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN;
  163. }
  164. static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
  165. {
  166. struct x25_forward *f;
  167. ++*pos;
  168. if (v == SEQ_START_TOKEN) {
  169. f = NULL;
  170. if (!list_empty(&x25_forward_list))
  171. f = list_entry(x25_forward_list.next,
  172. struct x25_forward, node);
  173. goto out;
  174. }
  175. f = v;
  176. if (f->node.next != &x25_forward_list)
  177. f = list_entry(f->node.next, struct x25_forward, node);
  178. else
  179. f = NULL;
  180. out:
  181. return f;
  182. }
  183. static void x25_seq_forward_stop(struct seq_file *seq, void *v)
  184. {
  185. read_unlock_bh(&x25_forward_list_lock);
  186. }
  187. static int x25_seq_forward_show(struct seq_file *seq, void *v)
  188. {
  189. struct x25_forward *f;
  190. if (v == SEQ_START_TOKEN) {
  191. seq_printf(seq, "lci dev1 dev2\n");
  192. goto out;
  193. }
  194. f = v;
  195. seq_printf(seq, "%d %-10s %-10s\n",
  196. f->lci, f->dev1->name, f->dev2->name);
  197. out:
  198. return 0;
  199. }
  200. static const struct seq_operations x25_seq_route_ops = {
  201. .start = x25_seq_route_start,
  202. .next = x25_seq_route_next,
  203. .stop = x25_seq_route_stop,
  204. .show = x25_seq_route_show,
  205. };
  206. static const struct seq_operations x25_seq_socket_ops = {
  207. .start = x25_seq_socket_start,
  208. .next = x25_seq_socket_next,
  209. .stop = x25_seq_socket_stop,
  210. .show = x25_seq_socket_show,
  211. };
  212. static const struct seq_operations x25_seq_forward_ops = {
  213. .start = x25_seq_forward_start,
  214. .next = x25_seq_forward_next,
  215. .stop = x25_seq_forward_stop,
  216. .show = x25_seq_forward_show,
  217. };
  218. static int x25_seq_socket_open(struct inode *inode, struct file *file)
  219. {
  220. return seq_open(file, &x25_seq_socket_ops);
  221. }
  222. static int x25_seq_route_open(struct inode *inode, struct file *file)
  223. {
  224. return seq_open(file, &x25_seq_route_ops);
  225. }
  226. static int x25_seq_forward_open(struct inode *inode, struct file *file)
  227. {
  228. return seq_open(file, &x25_seq_forward_ops);
  229. }
  230. static const struct file_operations x25_seq_socket_fops = {
  231. .owner = THIS_MODULE,
  232. .open = x25_seq_socket_open,
  233. .read = seq_read,
  234. .llseek = seq_lseek,
  235. .release = seq_release,
  236. };
  237. static const struct file_operations x25_seq_route_fops = {
  238. .owner = THIS_MODULE,
  239. .open = x25_seq_route_open,
  240. .read = seq_read,
  241. .llseek = seq_lseek,
  242. .release = seq_release,
  243. };
  244. static struct file_operations x25_seq_forward_fops = {
  245. .owner = THIS_MODULE,
  246. .open = x25_seq_forward_open,
  247. .read = seq_read,
  248. .llseek = seq_lseek,
  249. .release = seq_release,
  250. };
  251. static struct proc_dir_entry *x25_proc_dir;
  252. int __init x25_proc_init(void)
  253. {
  254. struct proc_dir_entry *p;
  255. int rc = -ENOMEM;
  256. x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
  257. if (!x25_proc_dir)
  258. goto out;
  259. p = create_proc_entry("route", S_IRUGO, x25_proc_dir);
  260. if (!p)
  261. goto out_route;
  262. p->proc_fops = &x25_seq_route_fops;
  263. p = create_proc_entry("socket", S_IRUGO, x25_proc_dir);
  264. if (!p)
  265. goto out_socket;
  266. p->proc_fops = &x25_seq_socket_fops;
  267. p = create_proc_entry("forward", S_IRUGO, x25_proc_dir);
  268. if (!p)
  269. goto out_forward;
  270. p->proc_fops = &x25_seq_forward_fops;
  271. rc = 0;
  272. out:
  273. return rc;
  274. out_forward:
  275. remove_proc_entry("socket", x25_proc_dir);
  276. out_socket:
  277. remove_proc_entry("route", x25_proc_dir);
  278. out_route:
  279. remove_proc_entry("x25", init_net.proc_net);
  280. goto out;
  281. }
  282. void __exit x25_proc_exit(void)
  283. {
  284. remove_proc_entry("forward", x25_proc_dir);
  285. remove_proc_entry("route", x25_proc_dir);
  286. remove_proc_entry("socket", x25_proc_dir);
  287. remove_proc_entry("x25", init_net.proc_net);
  288. }
  289. #else /* CONFIG_PROC_FS */
  290. int __init x25_proc_init(void)
  291. {
  292. return 0;
  293. }
  294. void __exit x25_proc_exit(void)
  295. {
  296. }
  297. #endif /* CONFIG_PROC_FS */