x25_proc.c 5.5 KB

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