proc.c 10 KB

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