x25_proc.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/config.h>
  20. #include <linux/init.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/seq_file.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 struct seq_operations x25_seq_route_ops = {
  146. .start = x25_seq_route_start,
  147. .next = x25_seq_route_next,
  148. .stop = x25_seq_route_stop,
  149. .show = x25_seq_route_show,
  150. };
  151. static struct seq_operations x25_seq_socket_ops = {
  152. .start = x25_seq_socket_start,
  153. .next = x25_seq_socket_next,
  154. .stop = x25_seq_socket_stop,
  155. .show = x25_seq_socket_show,
  156. };
  157. static int x25_seq_socket_open(struct inode *inode, struct file *file)
  158. {
  159. return seq_open(file, &x25_seq_socket_ops);
  160. }
  161. static int x25_seq_route_open(struct inode *inode, struct file *file)
  162. {
  163. return seq_open(file, &x25_seq_route_ops);
  164. }
  165. static struct file_operations x25_seq_socket_fops = {
  166. .owner = THIS_MODULE,
  167. .open = x25_seq_socket_open,
  168. .read = seq_read,
  169. .llseek = seq_lseek,
  170. .release = seq_release,
  171. };
  172. static struct file_operations x25_seq_route_fops = {
  173. .owner = THIS_MODULE,
  174. .open = x25_seq_route_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", proc_net);
  185. if (!x25_proc_dir)
  186. goto out;
  187. p = create_proc_entry("route", S_IRUGO, x25_proc_dir);
  188. if (!p)
  189. goto out_route;
  190. p->proc_fops = &x25_seq_route_fops;
  191. p = create_proc_entry("socket", S_IRUGO, x25_proc_dir);
  192. if (!p)
  193. goto out_socket;
  194. p->proc_fops = &x25_seq_socket_fops;
  195. rc = 0;
  196. out:
  197. return rc;
  198. out_socket:
  199. remove_proc_entry("route", x25_proc_dir);
  200. out_route:
  201. remove_proc_entry("x25", proc_net);
  202. goto out;
  203. }
  204. void __exit x25_proc_exit(void)
  205. {
  206. remove_proc_entry("route", x25_proc_dir);
  207. remove_proc_entry("socket", x25_proc_dir);
  208. remove_proc_entry("x25", proc_net);
  209. }
  210. #else /* CONFIG_PROC_FS */
  211. int __init x25_proc_init(void)
  212. {
  213. return 0;
  214. }
  215. void __exit x25_proc_exit(void)
  216. {
  217. }
  218. #endif /* CONFIG_PROC_FS */