x25_proc.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
  27. __acquires(x25_route_list_lock)
  28. {
  29. read_lock_bh(&x25_route_list_lock);
  30. return seq_list_start_head(&x25_route_list, *pos);
  31. }
  32. static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
  33. {
  34. return seq_list_next(v, &x25_route_list, pos);
  35. }
  36. static void x25_seq_route_stop(struct seq_file *seq, void *v)
  37. __releases(x25_route_list_lock)
  38. {
  39. read_unlock_bh(&x25_route_list_lock);
  40. }
  41. static int x25_seq_route_show(struct seq_file *seq, void *v)
  42. {
  43. struct x25_route *rt = list_entry(v, struct x25_route, node);
  44. if (v == &x25_route_list) {
  45. seq_puts(seq, "Address Digits Device\n");
  46. goto out;
  47. }
  48. rt = v;
  49. seq_printf(seq, "%-15s %-6d %-5s\n",
  50. rt->address.x25_addr, rt->sigdigits,
  51. rt->dev ? rt->dev->name : "???");
  52. out:
  53. return 0;
  54. }
  55. static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
  56. __acquires(x25_list_lock)
  57. {
  58. read_lock_bh(&x25_list_lock);
  59. return seq_hlist_start_head(&x25_list, *pos);
  60. }
  61. static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
  62. {
  63. return seq_hlist_next(v, &x25_list, pos);
  64. }
  65. static void x25_seq_socket_stop(struct seq_file *seq, void *v)
  66. __releases(x25_list_lock)
  67. {
  68. read_unlock_bh(&x25_list_lock);
  69. }
  70. static int x25_seq_socket_show(struct seq_file *seq, void *v)
  71. {
  72. struct sock *s;
  73. struct x25_sock *x25;
  74. struct net_device *dev;
  75. const char *devname;
  76. if (v == SEQ_START_TOKEN) {
  77. seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
  78. "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
  79. goto out;
  80. }
  81. s = sk_entry(v);
  82. x25 = x25_sk(s);
  83. if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
  84. devname = "???";
  85. else
  86. devname = x25->neighbour->dev->name;
  87. seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
  88. "%3lu %3lu %3lu %5d %5d %ld\n",
  89. !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
  90. !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
  91. devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
  92. x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
  93. x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
  94. sk_wmem_alloc_get(s),
  95. sk_rmem_alloc_get(s),
  96. s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
  97. out:
  98. return 0;
  99. }
  100. static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
  101. __acquires(x25_forward_list_lock)
  102. {
  103. read_lock_bh(&x25_forward_list_lock);
  104. return seq_list_start_head(&x25_forward_list, *pos);
  105. }
  106. static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
  107. {
  108. return seq_list_next(v, &x25_forward_list, pos);
  109. }
  110. static void x25_seq_forward_stop(struct seq_file *seq, void *v)
  111. __releases(x25_forward_list_lock)
  112. {
  113. read_unlock_bh(&x25_forward_list_lock);
  114. }
  115. static int x25_seq_forward_show(struct seq_file *seq, void *v)
  116. {
  117. struct x25_forward *f = list_entry(v, struct x25_forward, node);
  118. if (v == &x25_forward_list) {
  119. seq_printf(seq, "lci dev1 dev2\n");
  120. goto out;
  121. }
  122. f = v;
  123. seq_printf(seq, "%d %-10s %-10s\n",
  124. f->lci, f->dev1->name, f->dev2->name);
  125. out:
  126. return 0;
  127. }
  128. static const struct seq_operations x25_seq_route_ops = {
  129. .start = x25_seq_route_start,
  130. .next = x25_seq_route_next,
  131. .stop = x25_seq_route_stop,
  132. .show = x25_seq_route_show,
  133. };
  134. static const struct seq_operations x25_seq_socket_ops = {
  135. .start = x25_seq_socket_start,
  136. .next = x25_seq_socket_next,
  137. .stop = x25_seq_socket_stop,
  138. .show = x25_seq_socket_show,
  139. };
  140. static const struct seq_operations x25_seq_forward_ops = {
  141. .start = x25_seq_forward_start,
  142. .next = x25_seq_forward_next,
  143. .stop = x25_seq_forward_stop,
  144. .show = x25_seq_forward_show,
  145. };
  146. static int x25_seq_socket_open(struct inode *inode, struct file *file)
  147. {
  148. return seq_open(file, &x25_seq_socket_ops);
  149. }
  150. static int x25_seq_route_open(struct inode *inode, struct file *file)
  151. {
  152. return seq_open(file, &x25_seq_route_ops);
  153. }
  154. static int x25_seq_forward_open(struct inode *inode, struct file *file)
  155. {
  156. return seq_open(file, &x25_seq_forward_ops);
  157. }
  158. static const struct file_operations x25_seq_socket_fops = {
  159. .owner = THIS_MODULE,
  160. .open = x25_seq_socket_open,
  161. .read = seq_read,
  162. .llseek = seq_lseek,
  163. .release = seq_release,
  164. };
  165. static const struct file_operations x25_seq_route_fops = {
  166. .owner = THIS_MODULE,
  167. .open = x25_seq_route_open,
  168. .read = seq_read,
  169. .llseek = seq_lseek,
  170. .release = seq_release,
  171. };
  172. static const struct file_operations x25_seq_forward_fops = {
  173. .owner = THIS_MODULE,
  174. .open = x25_seq_forward_open,
  175. .read = seq_read,
  176. .llseek = seq_lseek,
  177. .release = seq_release,
  178. };
  179. static struct proc_dir_entry *x25_proc_dir;
  180. int __init x25_proc_init(void)
  181. {
  182. struct proc_dir_entry *p;
  183. int rc = -ENOMEM;
  184. x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
  185. if (!x25_proc_dir)
  186. goto out;
  187. p = proc_create("route", S_IRUGO, x25_proc_dir, &x25_seq_route_fops);
  188. if (!p)
  189. goto out_route;
  190. p = proc_create("socket", S_IRUGO, x25_proc_dir, &x25_seq_socket_fops);
  191. if (!p)
  192. goto out_socket;
  193. p = proc_create("forward", S_IRUGO, x25_proc_dir,
  194. &x25_seq_forward_fops);
  195. if (!p)
  196. goto out_forward;
  197. rc = 0;
  198. out:
  199. return rc;
  200. out_forward:
  201. remove_proc_entry("socket", x25_proc_dir);
  202. out_socket:
  203. remove_proc_entry("route", x25_proc_dir);
  204. out_route:
  205. remove_proc_entry("x25", init_net.proc_net);
  206. goto out;
  207. }
  208. void __exit x25_proc_exit(void)
  209. {
  210. remove_proc_entry("forward", x25_proc_dir);
  211. remove_proc_entry("route", x25_proc_dir);
  212. remove_proc_entry("socket", x25_proc_dir);
  213. remove_proc_entry("x25", init_net.proc_net);
  214. }
  215. #else /* CONFIG_PROC_FS */
  216. int __init x25_proc_init(void)
  217. {
  218. return 0;
  219. }
  220. void __exit x25_proc_exit(void)
  221. {
  222. }
  223. #endif /* CONFIG_PROC_FS */