proc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 (i = 0; i < NR_CPUS; i++) {
  69. if (!cpu_possible(i))
  70. continue;
  71. res +=
  72. *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
  73. sizeof (unsigned long) * nr));
  74. res +=
  75. *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
  76. sizeof (unsigned long) * nr));
  77. }
  78. return res;
  79. }
  80. /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
  81. static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
  82. {
  83. int i;
  84. for (i = 0; sctp_snmp_list[i].name != NULL; i++)
  85. seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
  86. fold_field((void **)sctp_statistics,
  87. sctp_snmp_list[i].entry));
  88. return 0;
  89. }
  90. /* Initialize the seq file operations for 'snmp' object. */
  91. static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
  92. {
  93. return single_open(file, sctp_snmp_seq_show, NULL);
  94. }
  95. static struct file_operations sctp_snmp_seq_fops = {
  96. .owner = THIS_MODULE,
  97. .open = sctp_snmp_seq_open,
  98. .read = seq_read,
  99. .llseek = seq_lseek,
  100. .release = single_release,
  101. };
  102. /* Set up the proc fs entry for 'snmp' object. */
  103. int __init sctp_snmp_proc_init(void)
  104. {
  105. struct proc_dir_entry *p;
  106. p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
  107. if (!p)
  108. return -ENOMEM;
  109. p->proc_fops = &sctp_snmp_seq_fops;
  110. return 0;
  111. }
  112. /* Cleanup the proc fs entry for 'snmp' object. */
  113. void sctp_snmp_proc_exit(void)
  114. {
  115. remove_proc_entry("snmp", proc_net_sctp);
  116. }
  117. /* Dump local addresses of an association/endpoint. */
  118. static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
  119. {
  120. struct list_head *pos;
  121. struct sctp_association *asoc;
  122. struct sctp_sockaddr_entry *laddr;
  123. struct sctp_transport *peer;
  124. union sctp_addr *addr, *primary = NULL;
  125. struct sctp_af *af;
  126. if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
  127. asoc = sctp_assoc(epb);
  128. peer = asoc->peer.primary_path;
  129. primary = &peer->saddr;
  130. }
  131. list_for_each(pos, &epb->bind_addr.address_list) {
  132. laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
  133. addr = (union sctp_addr *)&laddr->a;
  134. af = sctp_get_af_specific(addr->sa.sa_family);
  135. if (primary && af->cmp_addr(addr, primary)) {
  136. seq_printf(seq, "*");
  137. }
  138. af->seq_dump_addr(seq, addr);
  139. }
  140. }
  141. /* Dump remote addresses of an association. */
  142. static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
  143. {
  144. struct list_head *pos;
  145. struct sctp_transport *transport;
  146. union sctp_addr *addr, *primary;
  147. struct sctp_af *af;
  148. primary = &(assoc->peer.primary_addr);
  149. list_for_each(pos, &assoc->peer.transport_addr_list) {
  150. transport = list_entry(pos, struct sctp_transport, transports);
  151. addr = (union sctp_addr *)&transport->ipaddr;
  152. af = sctp_get_af_specific(addr->sa.sa_family);
  153. if (af->cmp_addr(addr, primary)) {
  154. seq_printf(seq, "*");
  155. }
  156. af->seq_dump_addr(seq, addr);
  157. }
  158. }
  159. static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
  160. {
  161. if (*pos > sctp_ep_hashsize)
  162. return NULL;
  163. if (*pos < 0)
  164. *pos = 0;
  165. if (*pos == 0)
  166. seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
  167. ++*pos;
  168. return (void *)pos;
  169. }
  170. static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
  171. {
  172. return;
  173. }
  174. static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  175. {
  176. if (*pos > sctp_ep_hashsize)
  177. return NULL;
  178. ++*pos;
  179. return pos;
  180. }
  181. /* Display sctp endpoints (/proc/net/sctp/eps). */
  182. static int sctp_eps_seq_show(struct seq_file *seq, void *v)
  183. {
  184. struct sctp_hashbucket *head;
  185. struct sctp_ep_common *epb;
  186. struct sctp_endpoint *ep;
  187. struct sock *sk;
  188. int hash = *(int *)v;
  189. if (hash > sctp_ep_hashsize)
  190. return -ENOMEM;
  191. head = &sctp_ep_hashtable[hash-1];
  192. sctp_local_bh_disable();
  193. read_lock(&head->lock);
  194. for (epb = head->chain; epb; epb = epb->next) {
  195. ep = sctp_ep(epb);
  196. sk = epb->sk;
  197. seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
  198. sctp_sk(sk)->type, sk->sk_state, hash-1,
  199. epb->bind_addr.port,
  200. sock_i_uid(sk), sock_i_ino(sk));
  201. sctp_seq_dump_local_addrs(seq, epb);
  202. seq_printf(seq, "\n");
  203. }
  204. read_unlock(&head->lock);
  205. sctp_local_bh_enable();
  206. return 0;
  207. }
  208. static struct seq_operations sctp_eps_ops = {
  209. .start = sctp_eps_seq_start,
  210. .next = sctp_eps_seq_next,
  211. .stop = sctp_eps_seq_stop,
  212. .show = sctp_eps_seq_show,
  213. };
  214. /* Initialize the seq file operations for 'eps' object. */
  215. static int sctp_eps_seq_open(struct inode *inode, struct file *file)
  216. {
  217. return seq_open(file, &sctp_eps_ops);
  218. }
  219. static struct file_operations sctp_eps_seq_fops = {
  220. .open = sctp_eps_seq_open,
  221. .read = seq_read,
  222. .llseek = seq_lseek,
  223. .release = seq_release,
  224. };
  225. /* Set up the proc fs entry for 'eps' object. */
  226. int __init sctp_eps_proc_init(void)
  227. {
  228. struct proc_dir_entry *p;
  229. p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
  230. if (!p)
  231. return -ENOMEM;
  232. p->proc_fops = &sctp_eps_seq_fops;
  233. return 0;
  234. }
  235. /* Cleanup the proc fs entry for 'eps' object. */
  236. void sctp_eps_proc_exit(void)
  237. {
  238. remove_proc_entry("eps", proc_net_sctp);
  239. }
  240. static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
  241. {
  242. if (*pos > sctp_assoc_hashsize)
  243. return NULL;
  244. if (*pos < 0)
  245. *pos = 0;
  246. if (*pos == 0)
  247. seq_printf(seq, " ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
  248. "RPORT LADDRS <-> RADDRS\n");
  249. ++*pos;
  250. return (void *)pos;
  251. }
  252. static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
  253. {
  254. return;
  255. }
  256. static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  257. {
  258. if (*pos > sctp_assoc_hashsize)
  259. return NULL;
  260. ++*pos;
  261. return pos;
  262. }
  263. /* Display sctp associations (/proc/net/sctp/assocs). */
  264. static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
  265. {
  266. struct sctp_hashbucket *head;
  267. struct sctp_ep_common *epb;
  268. struct sctp_association *assoc;
  269. struct sock *sk;
  270. int hash = *(int *)v;
  271. if (hash > sctp_assoc_hashsize)
  272. return -ENOMEM;
  273. head = &sctp_assoc_hashtable[hash-1];
  274. sctp_local_bh_disable();
  275. read_lock(&head->lock);
  276. for (epb = head->chain; epb; epb = epb->next) {
  277. assoc = sctp_assoc(epb);
  278. sk = epb->sk;
  279. seq_printf(seq,
  280. "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ",
  281. assoc, sk, sctp_sk(sk)->type, sk->sk_state,
  282. assoc->state, hash-1, assoc->assoc_id,
  283. (sk->sk_rcvbuf - assoc->rwnd),
  284. assoc->sndbuf_used,
  285. sock_i_uid(sk), sock_i_ino(sk),
  286. epb->bind_addr.port,
  287. assoc->peer.port);
  288. seq_printf(seq, " ");
  289. sctp_seq_dump_local_addrs(seq, epb);
  290. seq_printf(seq, "<-> ");
  291. sctp_seq_dump_remote_addrs(seq, assoc);
  292. seq_printf(seq, "\n");
  293. }
  294. read_unlock(&head->lock);
  295. sctp_local_bh_enable();
  296. return 0;
  297. }
  298. static struct seq_operations sctp_assoc_ops = {
  299. .start = sctp_assocs_seq_start,
  300. .next = sctp_assocs_seq_next,
  301. .stop = sctp_assocs_seq_stop,
  302. .show = sctp_assocs_seq_show,
  303. };
  304. /* Initialize the seq file operations for 'assocs' object. */
  305. static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
  306. {
  307. return seq_open(file, &sctp_assoc_ops);
  308. }
  309. static struct file_operations sctp_assocs_seq_fops = {
  310. .open = sctp_assocs_seq_open,
  311. .read = seq_read,
  312. .llseek = seq_lseek,
  313. .release = seq_release,
  314. };
  315. /* Set up the proc fs entry for 'assocs' object. */
  316. int __init sctp_assocs_proc_init(void)
  317. {
  318. struct proc_dir_entry *p;
  319. p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
  320. if (!p)
  321. return -ENOMEM;
  322. p->proc_fops = &sctp_assocs_seq_fops;
  323. return 0;
  324. }
  325. /* Cleanup the proc fs entry for 'assocs' object. */
  326. void sctp_assocs_proc_exit(void)
  327. {
  328. remove_proc_entry("assocs", proc_net_sctp);
  329. }