x25_proc.c 5.9 KB

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