x25_proc.c 7.5 KB

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