proc.c 11 KB

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