proc.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. };
  59. /* Return the current value of a particular entry in the mib by adding its
  60. * per cpu counters.
  61. */
  62. static unsigned long
  63. fold_field(void *mib[], int nr)
  64. {
  65. unsigned long res = 0;
  66. int i;
  67. for (i = 0; i < NR_CPUS; i++) {
  68. if (!cpu_possible(i))
  69. continue;
  70. res +=
  71. *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
  72. sizeof (unsigned long) * nr));
  73. res +=
  74. *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
  75. sizeof (unsigned long) * nr));
  76. }
  77. return res;
  78. }
  79. /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
  80. static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
  81. {
  82. int i;
  83. for (i = 0; sctp_snmp_list[i].name != NULL; i++)
  84. seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
  85. fold_field((void **)sctp_statistics,
  86. sctp_snmp_list[i].entry));
  87. return 0;
  88. }
  89. /* Initialize the seq file operations for 'snmp' object. */
  90. static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
  91. {
  92. return single_open(file, sctp_snmp_seq_show, NULL);
  93. }
  94. static struct file_operations sctp_snmp_seq_fops = {
  95. .owner = THIS_MODULE,
  96. .open = sctp_snmp_seq_open,
  97. .read = seq_read,
  98. .llseek = seq_lseek,
  99. .release = single_release,
  100. };
  101. /* Set up the proc fs entry for 'snmp' object. */
  102. int __init sctp_snmp_proc_init(void)
  103. {
  104. struct proc_dir_entry *p;
  105. p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
  106. if (!p)
  107. return -ENOMEM;
  108. p->proc_fops = &sctp_snmp_seq_fops;
  109. return 0;
  110. }
  111. /* Cleanup the proc fs entry for 'snmp' object. */
  112. void sctp_snmp_proc_exit(void)
  113. {
  114. remove_proc_entry("snmp", proc_net_sctp);
  115. }
  116. /* Dump local addresses of an association/endpoint. */
  117. static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
  118. {
  119. struct list_head *pos;
  120. struct sctp_sockaddr_entry *laddr;
  121. union sctp_addr *addr;
  122. struct sctp_af *af;
  123. list_for_each(pos, &epb->bind_addr.address_list) {
  124. laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
  125. addr = (union sctp_addr *)&laddr->a;
  126. af = sctp_get_af_specific(addr->sa.sa_family);
  127. af->seq_dump_addr(seq, addr);
  128. }
  129. }
  130. /* Dump remote addresses of an association. */
  131. static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
  132. {
  133. struct list_head *pos;
  134. struct sctp_transport *transport;
  135. union sctp_addr *addr;
  136. struct sctp_af *af;
  137. list_for_each(pos, &assoc->peer.transport_addr_list) {
  138. transport = list_entry(pos, struct sctp_transport, transports);
  139. addr = (union sctp_addr *)&transport->ipaddr;
  140. af = sctp_get_af_specific(addr->sa.sa_family);
  141. af->seq_dump_addr(seq, addr);
  142. }
  143. }
  144. /* Display sctp endpoints (/proc/net/sctp/eps). */
  145. static int sctp_eps_seq_show(struct seq_file *seq, void *v)
  146. {
  147. struct sctp_hashbucket *head;
  148. struct sctp_ep_common *epb;
  149. struct sctp_endpoint *ep;
  150. struct sock *sk;
  151. int hash;
  152. seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT LADDRS\n");
  153. for (hash = 0; hash < sctp_ep_hashsize; hash++) {
  154. head = &sctp_ep_hashtable[hash];
  155. read_lock(&head->lock);
  156. for (epb = head->chain; epb; epb = epb->next) {
  157. ep = sctp_ep(epb);
  158. sk = epb->sk;
  159. seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d ", ep, sk,
  160. sctp_sk(sk)->type, sk->sk_state, hash,
  161. epb->bind_addr.port);
  162. sctp_seq_dump_local_addrs(seq, epb);
  163. seq_printf(seq, "\n");
  164. }
  165. read_unlock(&head->lock);
  166. }
  167. return 0;
  168. }
  169. /* Initialize the seq file operations for 'eps' object. */
  170. static int sctp_eps_seq_open(struct inode *inode, struct file *file)
  171. {
  172. return single_open(file, sctp_eps_seq_show, NULL);
  173. }
  174. static struct file_operations sctp_eps_seq_fops = {
  175. .open = sctp_eps_seq_open,
  176. .read = seq_read,
  177. .llseek = seq_lseek,
  178. .release = single_release,
  179. };
  180. /* Set up the proc fs entry for 'eps' object. */
  181. int __init sctp_eps_proc_init(void)
  182. {
  183. struct proc_dir_entry *p;
  184. p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
  185. if (!p)
  186. return -ENOMEM;
  187. p->proc_fops = &sctp_eps_seq_fops;
  188. return 0;
  189. }
  190. /* Cleanup the proc fs entry for 'eps' object. */
  191. void sctp_eps_proc_exit(void)
  192. {
  193. remove_proc_entry("eps", proc_net_sctp);
  194. }
  195. /* Display sctp associations (/proc/net/sctp/assocs). */
  196. static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
  197. {
  198. struct sctp_hashbucket *head;
  199. struct sctp_ep_common *epb;
  200. struct sctp_association *assoc;
  201. struct sock *sk;
  202. int hash;
  203. seq_printf(seq, " ASSOC SOCK STY SST ST HBKT LPORT RPORT "
  204. "LADDRS <-> RADDRS\n");
  205. for (hash = 0; hash < sctp_assoc_hashsize; hash++) {
  206. head = &sctp_assoc_hashtable[hash];
  207. read_lock(&head->lock);
  208. for (epb = head->chain; epb; epb = epb->next) {
  209. assoc = sctp_assoc(epb);
  210. sk = epb->sk;
  211. seq_printf(seq,
  212. "%8p %8p %-3d %-3d %-2d %-4d %-5d %-5d ",
  213. assoc, sk, sctp_sk(sk)->type, sk->sk_state,
  214. assoc->state, hash, epb->bind_addr.port,
  215. assoc->peer.port);
  216. sctp_seq_dump_local_addrs(seq, epb);
  217. seq_printf(seq, "<-> ");
  218. sctp_seq_dump_remote_addrs(seq, assoc);
  219. seq_printf(seq, "\n");
  220. }
  221. read_unlock(&head->lock);
  222. }
  223. return 0;
  224. }
  225. /* Initialize the seq file operations for 'assocs' object. */
  226. static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
  227. {
  228. return single_open(file, sctp_assocs_seq_show, NULL);
  229. }
  230. static struct file_operations sctp_assocs_seq_fops = {
  231. .open = sctp_assocs_seq_open,
  232. .read = seq_read,
  233. .llseek = seq_lseek,
  234. .release = single_release,
  235. };
  236. /* Set up the proc fs entry for 'assocs' object. */
  237. int __init sctp_assocs_proc_init(void)
  238. {
  239. struct proc_dir_entry *p;
  240. p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
  241. if (!p)
  242. return -ENOMEM;
  243. p->proc_fops = &sctp_assocs_seq_fops;
  244. return 0;
  245. }
  246. /* Cleanup the proc fs entry for 'assocs' object. */
  247. void sctp_assocs_proc_exit(void)
  248. {
  249. remove_proc_entry("assocs", proc_net_sctp);
  250. }