proc.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* SCTP kernel reference Implementation
  2. * Copyright (c) 2003 International Business Machines, Corp.
  3. *
  4. * This file is part of the SCTP kernel reference Implementation
  5. *
  6. * The SCTP reference implementation is free software;
  7. * you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * The SCTP reference implementation is distributed in the hope that it
  13. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  14. * ************************
  15. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. * See the GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU CC; see the file COPYING. If not, write to
  20. * the Free Software Foundation, 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. *
  23. * Please send any bug reports or fixes you make to the
  24. * email address(es):
  25. * lksctp developers <lksctp-developers@lists.sourceforge.net>
  26. *
  27. * Or submit a bug report through the following website:
  28. * http://www.sf.net/projects/lksctp
  29. *
  30. * Written or modified by:
  31. * Sridhar Samudrala <sri@us.ibm.com>
  32. *
  33. * Any bugs reported given to us we will try to fix... any fixes shared will
  34. * be incorporated into the next SCTP release.
  35. */
  36. #include <linux/types.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/init.h>
  39. #include <net/sctp/sctp.h>
  40. static struct snmp_mib sctp_snmp_list[] = {
  41. SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
  42. SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS),
  43. SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS),
  44. SNMP_MIB_ITEM("SctpAborteds", SCTP_MIB_ABORTEDS),
  45. SNMP_MIB_ITEM("SctpShutdowns", SCTP_MIB_SHUTDOWNS),
  46. SNMP_MIB_ITEM("SctpOutOfBlues", SCTP_MIB_OUTOFBLUES),
  47. SNMP_MIB_ITEM("SctpChecksumErrors", SCTP_MIB_CHECKSUMERRORS),
  48. SNMP_MIB_ITEM("SctpOutCtrlChunks", SCTP_MIB_OUTCTRLCHUNKS),
  49. SNMP_MIB_ITEM("SctpOutOrderChunks", SCTP_MIB_OUTORDERCHUNKS),
  50. SNMP_MIB_ITEM("SctpOutUnorderChunks", SCTP_MIB_OUTUNORDERCHUNKS),
  51. SNMP_MIB_ITEM("SctpInCtrlChunks", SCTP_MIB_INCTRLCHUNKS),
  52. SNMP_MIB_ITEM("SctpInOrderChunks", SCTP_MIB_INORDERCHUNKS),
  53. SNMP_MIB_ITEM("SctpInUnorderChunks", SCTP_MIB_INUNORDERCHUNKS),
  54. SNMP_MIB_ITEM("SctpFragUsrMsgs", SCTP_MIB_FRAGUSRMSGS),
  55. SNMP_MIB_ITEM("SctpReasmUsrMsgs", SCTP_MIB_REASMUSRMSGS),
  56. SNMP_MIB_ITEM("SctpOutSCTPPacks", SCTP_MIB_OUTSCTPPACKS),
  57. SNMP_MIB_ITEM("SctpInSCTPPacks", SCTP_MIB_INSCTPPACKS),
  58. SNMP_MIB_SENTINEL
  59. };
  60. /* Return the current value of a particular entry in the mib by adding its
  61. * per cpu counters.
  62. */
  63. static unsigned long
  64. fold_field(void *mib[], int nr)
  65. {
  66. unsigned long res = 0;
  67. int i;
  68. for_each_cpu(i) {
  69. res +=
  70. *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
  71. sizeof (unsigned long) * nr));
  72. res +=
  73. *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
  74. sizeof (unsigned long) * nr));
  75. }
  76. return res;
  77. }
  78. /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
  79. static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
  80. {
  81. int i;
  82. for (i = 0; sctp_snmp_list[i].name != NULL; i++)
  83. seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
  84. fold_field((void **)sctp_statistics,
  85. sctp_snmp_list[i].entry));
  86. return 0;
  87. }
  88. /* Initialize the seq file operations for 'snmp' object. */
  89. static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
  90. {
  91. return single_open(file, sctp_snmp_seq_show, NULL);
  92. }
  93. static struct file_operations sctp_snmp_seq_fops = {
  94. .owner = THIS_MODULE,
  95. .open = sctp_snmp_seq_open,
  96. .read = seq_read,
  97. .llseek = seq_lseek,
  98. .release = single_release,
  99. };
  100. /* Set up the proc fs entry for 'snmp' object. */
  101. int __init sctp_snmp_proc_init(void)
  102. {
  103. struct proc_dir_entry *p;
  104. p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
  105. if (!p)
  106. return -ENOMEM;
  107. p->proc_fops = &sctp_snmp_seq_fops;
  108. return 0;
  109. }
  110. /* Cleanup the proc fs entry for 'snmp' object. */
  111. void sctp_snmp_proc_exit(void)
  112. {
  113. remove_proc_entry("snmp", proc_net_sctp);
  114. }
  115. /* Dump local addresses of an association/endpoint. */
  116. static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
  117. {
  118. struct list_head *pos;
  119. struct sctp_association *asoc;
  120. struct sctp_sockaddr_entry *laddr;
  121. struct sctp_transport *peer;
  122. union sctp_addr *addr, *primary = NULL;
  123. struct sctp_af *af;
  124. if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
  125. asoc = sctp_assoc(epb);
  126. peer = asoc->peer.primary_path;
  127. primary = &peer->saddr;
  128. }
  129. list_for_each(pos, &epb->bind_addr.address_list) {
  130. laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
  131. addr = (union sctp_addr *)&laddr->a;
  132. af = sctp_get_af_specific(addr->sa.sa_family);
  133. if (primary && af->cmp_addr(addr, primary)) {
  134. seq_printf(seq, "*");
  135. }
  136. af->seq_dump_addr(seq, addr);
  137. }
  138. }
  139. /* Dump remote addresses of an association. */
  140. static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
  141. {
  142. struct list_head *pos;
  143. struct sctp_transport *transport;
  144. union sctp_addr *addr, *primary;
  145. struct sctp_af *af;
  146. primary = &(assoc->peer.primary_addr);
  147. list_for_each(pos, &assoc->peer.transport_addr_list) {
  148. transport = list_entry(pos, struct sctp_transport, transports);
  149. addr = (union sctp_addr *)&transport->ipaddr;
  150. af = sctp_get_af_specific(addr->sa.sa_family);
  151. if (af->cmp_addr(addr, primary)) {
  152. seq_printf(seq, "*");
  153. }
  154. af->seq_dump_addr(seq, addr);
  155. }
  156. }
  157. static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
  158. {
  159. if (*pos >= sctp_ep_hashsize)
  160. return NULL;
  161. if (*pos < 0)
  162. *pos = 0;
  163. if (*pos == 0)
  164. seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
  165. return (void *)pos;
  166. }
  167. static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
  168. {
  169. return;
  170. }
  171. static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  172. {
  173. if (++*pos >= sctp_ep_hashsize)
  174. return NULL;
  175. return pos;
  176. }
  177. /* Display sctp endpoints (/proc/net/sctp/eps). */
  178. static int sctp_eps_seq_show(struct seq_file *seq, void *v)
  179. {
  180. struct sctp_hashbucket *head;
  181. struct sctp_ep_common *epb;
  182. struct sctp_endpoint *ep;
  183. struct sock *sk;
  184. int hash = *(loff_t *)v;
  185. if (hash >= sctp_ep_hashsize)
  186. return -ENOMEM;
  187. head = &sctp_ep_hashtable[hash];
  188. sctp_local_bh_disable();
  189. read_lock(&head->lock);
  190. for (epb = head->chain; epb; epb = epb->next) {
  191. ep = sctp_ep(epb);
  192. sk = epb->sk;
  193. seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
  194. sctp_sk(sk)->type, sk->sk_state, hash,
  195. epb->bind_addr.port,
  196. sock_i_uid(sk), sock_i_ino(sk));
  197. sctp_seq_dump_local_addrs(seq, epb);
  198. seq_printf(seq, "\n");
  199. }
  200. read_unlock(&head->lock);
  201. sctp_local_bh_enable();
  202. return 0;
  203. }
  204. static struct seq_operations sctp_eps_ops = {
  205. .start = sctp_eps_seq_start,
  206. .next = sctp_eps_seq_next,
  207. .stop = sctp_eps_seq_stop,
  208. .show = sctp_eps_seq_show,
  209. };
  210. /* Initialize the seq file operations for 'eps' object. */
  211. static int sctp_eps_seq_open(struct inode *inode, struct file *file)
  212. {
  213. return seq_open(file, &sctp_eps_ops);
  214. }
  215. static struct file_operations sctp_eps_seq_fops = {
  216. .open = sctp_eps_seq_open,
  217. .read = seq_read,
  218. .llseek = seq_lseek,
  219. .release = seq_release,
  220. };
  221. /* Set up the proc fs entry for 'eps' object. */
  222. int __init sctp_eps_proc_init(void)
  223. {
  224. struct proc_dir_entry *p;
  225. p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
  226. if (!p)
  227. return -ENOMEM;
  228. p->proc_fops = &sctp_eps_seq_fops;
  229. return 0;
  230. }
  231. /* Cleanup the proc fs entry for 'eps' object. */
  232. void sctp_eps_proc_exit(void)
  233. {
  234. remove_proc_entry("eps", proc_net_sctp);
  235. }
  236. static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
  237. {
  238. if (*pos >= sctp_assoc_hashsize)
  239. return NULL;
  240. if (*pos < 0)
  241. *pos = 0;
  242. if (*pos == 0)
  243. seq_printf(seq, " ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
  244. "RPORT LADDRS <-> RADDRS\n");
  245. return (void *)pos;
  246. }
  247. static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
  248. {
  249. return;
  250. }
  251. static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  252. {
  253. if (++*pos >= sctp_assoc_hashsize)
  254. return NULL;
  255. return pos;
  256. }
  257. /* Display sctp associations (/proc/net/sctp/assocs). */
  258. static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
  259. {
  260. struct sctp_hashbucket *head;
  261. struct sctp_ep_common *epb;
  262. struct sctp_association *assoc;
  263. struct sock *sk;
  264. int hash = *(loff_t *)v;
  265. if (hash >= sctp_assoc_hashsize)
  266. return -ENOMEM;
  267. head = &sctp_assoc_hashtable[hash];
  268. sctp_local_bh_disable();
  269. read_lock(&head->lock);
  270. for (epb = head->chain; epb; epb = epb->next) {
  271. assoc = sctp_assoc(epb);
  272. sk = epb->sk;
  273. seq_printf(seq,
  274. "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ",
  275. assoc, sk, sctp_sk(sk)->type, sk->sk_state,
  276. assoc->state, hash, assoc->assoc_id,
  277. (sk->sk_rcvbuf - assoc->rwnd),
  278. assoc->sndbuf_used,
  279. sock_i_uid(sk), sock_i_ino(sk),
  280. epb->bind_addr.port,
  281. assoc->peer.port);
  282. seq_printf(seq, " ");
  283. sctp_seq_dump_local_addrs(seq, epb);
  284. seq_printf(seq, "<-> ");
  285. sctp_seq_dump_remote_addrs(seq, assoc);
  286. seq_printf(seq, "\n");
  287. }
  288. read_unlock(&head->lock);
  289. sctp_local_bh_enable();
  290. return 0;
  291. }
  292. static struct seq_operations sctp_assoc_ops = {
  293. .start = sctp_assocs_seq_start,
  294. .next = sctp_assocs_seq_next,
  295. .stop = sctp_assocs_seq_stop,
  296. .show = sctp_assocs_seq_show,
  297. };
  298. /* Initialize the seq file operations for 'assocs' object. */
  299. static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
  300. {
  301. return seq_open(file, &sctp_assoc_ops);
  302. }
  303. static struct file_operations sctp_assocs_seq_fops = {
  304. .open = sctp_assocs_seq_open,
  305. .read = seq_read,
  306. .llseek = seq_lseek,
  307. .release = seq_release,
  308. };
  309. /* Set up the proc fs entry for 'assocs' object. */
  310. int __init sctp_assocs_proc_init(void)
  311. {
  312. struct proc_dir_entry *p;
  313. p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
  314. if (!p)
  315. return -ENOMEM;
  316. p->proc_fops = &sctp_assocs_seq_fops;
  317. return 0;
  318. }
  319. /* Cleanup the proc fs entry for 'assocs' object. */
  320. void sctp_assocs_proc_exit(void)
  321. {
  322. remove_proc_entry("assocs", proc_net_sctp);
  323. }