proc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /* SCTP kernel implementation
  2. * Copyright (c) 2003 International Business Machines, Corp.
  3. *
  4. * This file is part of the SCTP kernel implementation
  5. *
  6. * This SCTP 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. * This SCTP 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. #include <net/ip.h> /* for snmp_fold_field */
  41. static struct snmp_mib sctp_snmp_list[] = {
  42. SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
  43. SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS),
  44. SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS),
  45. SNMP_MIB_ITEM("SctpAborteds", SCTP_MIB_ABORTEDS),
  46. SNMP_MIB_ITEM("SctpShutdowns", SCTP_MIB_SHUTDOWNS),
  47. SNMP_MIB_ITEM("SctpOutOfBlues", SCTP_MIB_OUTOFBLUES),
  48. SNMP_MIB_ITEM("SctpChecksumErrors", SCTP_MIB_CHECKSUMERRORS),
  49. SNMP_MIB_ITEM("SctpOutCtrlChunks", SCTP_MIB_OUTCTRLCHUNKS),
  50. SNMP_MIB_ITEM("SctpOutOrderChunks", SCTP_MIB_OUTORDERCHUNKS),
  51. SNMP_MIB_ITEM("SctpOutUnorderChunks", SCTP_MIB_OUTUNORDERCHUNKS),
  52. SNMP_MIB_ITEM("SctpInCtrlChunks", SCTP_MIB_INCTRLCHUNKS),
  53. SNMP_MIB_ITEM("SctpInOrderChunks", SCTP_MIB_INORDERCHUNKS),
  54. SNMP_MIB_ITEM("SctpInUnorderChunks", SCTP_MIB_INUNORDERCHUNKS),
  55. SNMP_MIB_ITEM("SctpFragUsrMsgs", SCTP_MIB_FRAGUSRMSGS),
  56. SNMP_MIB_ITEM("SctpReasmUsrMsgs", SCTP_MIB_REASMUSRMSGS),
  57. SNMP_MIB_ITEM("SctpOutSCTPPacks", SCTP_MIB_OUTSCTPPACKS),
  58. SNMP_MIB_ITEM("SctpInSCTPPacks", SCTP_MIB_INSCTPPACKS),
  59. SNMP_MIB_ITEM("SctpT1InitExpireds", SCTP_MIB_T1_INIT_EXPIREDS),
  60. SNMP_MIB_ITEM("SctpT1CookieExpireds", SCTP_MIB_T1_COOKIE_EXPIREDS),
  61. SNMP_MIB_ITEM("SctpT2ShutdownExpireds", SCTP_MIB_T2_SHUTDOWN_EXPIREDS),
  62. SNMP_MIB_ITEM("SctpT3RtxExpireds", SCTP_MIB_T3_RTX_EXPIREDS),
  63. SNMP_MIB_ITEM("SctpT4RtoExpireds", SCTP_MIB_T4_RTO_EXPIREDS),
  64. SNMP_MIB_ITEM("SctpT5ShutdownGuardExpireds", SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS),
  65. SNMP_MIB_ITEM("SctpDelaySackExpireds", SCTP_MIB_DELAY_SACK_EXPIREDS),
  66. SNMP_MIB_ITEM("SctpAutocloseExpireds", SCTP_MIB_AUTOCLOSE_EXPIREDS),
  67. SNMP_MIB_ITEM("SctpT3Retransmits", SCTP_MIB_T3_RETRANSMITS),
  68. SNMP_MIB_ITEM("SctpPmtudRetransmits", SCTP_MIB_PMTUD_RETRANSMITS),
  69. SNMP_MIB_ITEM("SctpFastRetransmits", SCTP_MIB_FAST_RETRANSMITS),
  70. SNMP_MIB_ITEM("SctpInPktSoftirq", SCTP_MIB_IN_PKT_SOFTIRQ),
  71. SNMP_MIB_ITEM("SctpInPktBacklog", SCTP_MIB_IN_PKT_BACKLOG),
  72. SNMP_MIB_ITEM("SctpInPktDiscards", SCTP_MIB_IN_PKT_DISCARDS),
  73. SNMP_MIB_ITEM("SctpInDataChunkDiscards", SCTP_MIB_IN_DATA_CHUNK_DISCARDS),
  74. SNMP_MIB_SENTINEL
  75. };
  76. /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
  77. static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
  78. {
  79. int i;
  80. for (i = 0; sctp_snmp_list[i].name != NULL; i++)
  81. seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
  82. snmp_fold_field((void **)sctp_statistics,
  83. sctp_snmp_list[i].entry));
  84. return 0;
  85. }
  86. /* Initialize the seq file operations for 'snmp' object. */
  87. static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
  88. {
  89. return single_open(file, sctp_snmp_seq_show, NULL);
  90. }
  91. static const struct file_operations sctp_snmp_seq_fops = {
  92. .owner = THIS_MODULE,
  93. .open = sctp_snmp_seq_open,
  94. .read = seq_read,
  95. .llseek = seq_lseek,
  96. .release = single_release,
  97. };
  98. /* Set up the proc fs entry for 'snmp' object. */
  99. int __init sctp_snmp_proc_init(void)
  100. {
  101. struct proc_dir_entry *p;
  102. p = proc_create("snmp", S_IRUGO, proc_net_sctp, &sctp_snmp_seq_fops);
  103. if (!p)
  104. return -ENOMEM;
  105. return 0;
  106. }
  107. /* Cleanup the proc fs entry for 'snmp' object. */
  108. void sctp_snmp_proc_exit(void)
  109. {
  110. remove_proc_entry("snmp", proc_net_sctp);
  111. }
  112. /* Dump local addresses of an association/endpoint. */
  113. static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
  114. {
  115. struct sctp_association *asoc;
  116. struct sctp_sockaddr_entry *laddr;
  117. struct sctp_transport *peer;
  118. union sctp_addr *addr, *primary = NULL;
  119. struct sctp_af *af;
  120. if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
  121. asoc = sctp_assoc(epb);
  122. peer = asoc->peer.primary_path;
  123. primary = &peer->saddr;
  124. }
  125. list_for_each_entry(laddr, &epb->bind_addr.address_list, list) {
  126. addr = &laddr->a;
  127. af = sctp_get_af_specific(addr->sa.sa_family);
  128. if (primary && af->cmp_addr(addr, primary)) {
  129. seq_printf(seq, "*");
  130. }
  131. af->seq_dump_addr(seq, addr);
  132. }
  133. }
  134. /* Dump remote addresses of an association. */
  135. static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
  136. {
  137. struct sctp_transport *transport;
  138. union sctp_addr *addr, *primary;
  139. struct sctp_af *af;
  140. primary = &assoc->peer.primary_addr;
  141. list_for_each_entry(transport, &assoc->peer.transport_addr_list,
  142. transports) {
  143. addr = &transport->ipaddr;
  144. af = sctp_get_af_specific(addr->sa.sa_family);
  145. if (af->cmp_addr(addr, primary)) {
  146. seq_printf(seq, "*");
  147. }
  148. af->seq_dump_addr(seq, addr);
  149. }
  150. }
  151. static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
  152. {
  153. if (*pos >= sctp_ep_hashsize)
  154. return NULL;
  155. if (*pos < 0)
  156. *pos = 0;
  157. if (*pos == 0)
  158. seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
  159. return (void *)pos;
  160. }
  161. static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
  162. {
  163. return;
  164. }
  165. static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  166. {
  167. if (++*pos >= sctp_ep_hashsize)
  168. return NULL;
  169. return pos;
  170. }
  171. /* Display sctp endpoints (/proc/net/sctp/eps). */
  172. static int sctp_eps_seq_show(struct seq_file *seq, void *v)
  173. {
  174. struct sctp_hashbucket *head;
  175. struct sctp_ep_common *epb;
  176. struct sctp_endpoint *ep;
  177. struct sock *sk;
  178. struct hlist_node *node;
  179. int hash = *(loff_t *)v;
  180. if (hash >= sctp_ep_hashsize)
  181. return -ENOMEM;
  182. head = &sctp_ep_hashtable[hash];
  183. sctp_local_bh_disable();
  184. read_lock(&head->lock);
  185. sctp_for_each_hentry(epb, node, &head->chain) {
  186. ep = sctp_ep(epb);
  187. sk = epb->sk;
  188. seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
  189. sctp_sk(sk)->type, sk->sk_state, hash,
  190. epb->bind_addr.port,
  191. sock_i_uid(sk), sock_i_ino(sk));
  192. sctp_seq_dump_local_addrs(seq, epb);
  193. seq_printf(seq, "\n");
  194. }
  195. read_unlock(&head->lock);
  196. sctp_local_bh_enable();
  197. return 0;
  198. }
  199. static const struct seq_operations sctp_eps_ops = {
  200. .start = sctp_eps_seq_start,
  201. .next = sctp_eps_seq_next,
  202. .stop = sctp_eps_seq_stop,
  203. .show = sctp_eps_seq_show,
  204. };
  205. /* Initialize the seq file operations for 'eps' object. */
  206. static int sctp_eps_seq_open(struct inode *inode, struct file *file)
  207. {
  208. return seq_open(file, &sctp_eps_ops);
  209. }
  210. static const struct file_operations sctp_eps_seq_fops = {
  211. .open = sctp_eps_seq_open,
  212. .read = seq_read,
  213. .llseek = seq_lseek,
  214. .release = seq_release,
  215. };
  216. /* Set up the proc fs entry for 'eps' object. */
  217. int __init sctp_eps_proc_init(void)
  218. {
  219. struct proc_dir_entry *p;
  220. p = proc_create("eps", S_IRUGO, proc_net_sctp, &sctp_eps_seq_fops);
  221. if (!p)
  222. return -ENOMEM;
  223. return 0;
  224. }
  225. /* Cleanup the proc fs entry for 'eps' object. */
  226. void sctp_eps_proc_exit(void)
  227. {
  228. remove_proc_entry("eps", proc_net_sctp);
  229. }
  230. static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
  231. {
  232. if (*pos >= sctp_assoc_hashsize)
  233. return NULL;
  234. if (*pos < 0)
  235. *pos = 0;
  236. if (*pos == 0)
  237. seq_printf(seq, " ASSOC SOCK STY SST ST HBKT "
  238. "ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
  239. "RPORT LADDRS <-> RADDRS "
  240. "HBINT INS OUTS MAXRT T1X T2X RTXC\n");
  241. return (void *)pos;
  242. }
  243. static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
  244. {
  245. return;
  246. }
  247. static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  248. {
  249. if (++*pos >= sctp_assoc_hashsize)
  250. return NULL;
  251. return pos;
  252. }
  253. /* Display sctp associations (/proc/net/sctp/assocs). */
  254. static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
  255. {
  256. struct sctp_hashbucket *head;
  257. struct sctp_ep_common *epb;
  258. struct sctp_association *assoc;
  259. struct sock *sk;
  260. struct hlist_node *node;
  261. int hash = *(loff_t *)v;
  262. if (hash >= sctp_assoc_hashsize)
  263. return -ENOMEM;
  264. head = &sctp_assoc_hashtable[hash];
  265. sctp_local_bh_disable();
  266. read_lock(&head->lock);
  267. sctp_for_each_hentry(epb, node, &head->chain) {
  268. assoc = sctp_assoc(epb);
  269. sk = epb->sk;
  270. seq_printf(seq,
  271. "%8p %8p %-3d %-3d %-2d %-4d "
  272. "%4d %8d %8d %7d %5lu %-5d %5d ",
  273. assoc, sk, sctp_sk(sk)->type, sk->sk_state,
  274. assoc->state, hash,
  275. assoc->assoc_id,
  276. assoc->sndbuf_used,
  277. atomic_read(&assoc->rmem_alloc),
  278. sock_i_uid(sk), sock_i_ino(sk),
  279. epb->bind_addr.port,
  280. assoc->peer.port);
  281. seq_printf(seq, " ");
  282. sctp_seq_dump_local_addrs(seq, epb);
  283. seq_printf(seq, "<-> ");
  284. sctp_seq_dump_remote_addrs(seq, assoc);
  285. seq_printf(seq, "\t%8lu %5d %5d %4d %4d %4d %8d ",
  286. assoc->hbinterval, assoc->c.sinit_max_instreams,
  287. assoc->c.sinit_num_ostreams, assoc->max_retrans,
  288. assoc->init_retries, assoc->shutdown_retries,
  289. assoc->rtx_data_chunks);
  290. seq_printf(seq, "\n");
  291. }
  292. read_unlock(&head->lock);
  293. sctp_local_bh_enable();
  294. return 0;
  295. }
  296. static const struct seq_operations sctp_assoc_ops = {
  297. .start = sctp_assocs_seq_start,
  298. .next = sctp_assocs_seq_next,
  299. .stop = sctp_assocs_seq_stop,
  300. .show = sctp_assocs_seq_show,
  301. };
  302. /* Initialize the seq file operations for 'assocs' object. */
  303. static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
  304. {
  305. return seq_open(file, &sctp_assoc_ops);
  306. }
  307. static const struct file_operations sctp_assocs_seq_fops = {
  308. .open = sctp_assocs_seq_open,
  309. .read = seq_read,
  310. .llseek = seq_lseek,
  311. .release = seq_release,
  312. };
  313. /* Set up the proc fs entry for 'assocs' object. */
  314. int __init sctp_assocs_proc_init(void)
  315. {
  316. struct proc_dir_entry *p;
  317. p = proc_create("assocs", S_IRUGO, proc_net_sctp,
  318. &sctp_assocs_seq_fops);
  319. if (!p)
  320. return -ENOMEM;
  321. return 0;
  322. }
  323. /* Cleanup the proc fs entry for 'assocs' object. */
  324. void sctp_assocs_proc_exit(void)
  325. {
  326. remove_proc_entry("assocs", proc_net_sctp);
  327. }
  328. static void *sctp_remaddr_seq_start(struct seq_file *seq, loff_t *pos)
  329. {
  330. if (*pos >= sctp_assoc_hashsize)
  331. return NULL;
  332. if (*pos < 0)
  333. *pos = 0;
  334. if (*pos == 0)
  335. seq_printf(seq, "ADDR ASSOC_ID HB_ACT RTO MAX_PATH_RTX "
  336. "REM_ADDR_RTX START\n");
  337. return (void *)pos;
  338. }
  339. static void *sctp_remaddr_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  340. {
  341. if (++*pos >= sctp_assoc_hashsize)
  342. return NULL;
  343. return pos;
  344. }
  345. static void sctp_remaddr_seq_stop(struct seq_file *seq, void *v)
  346. {
  347. return;
  348. }
  349. static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
  350. {
  351. struct sctp_hashbucket *head;
  352. struct sctp_ep_common *epb;
  353. struct sctp_association *assoc;
  354. struct hlist_node *node;
  355. struct sctp_transport *tsp;
  356. int hash = *(loff_t *)v;
  357. if (hash >= sctp_assoc_hashsize)
  358. return -ENOMEM;
  359. head = &sctp_assoc_hashtable[hash];
  360. sctp_local_bh_disable();
  361. read_lock(&head->lock);
  362. sctp_for_each_hentry(epb, node, &head->chain) {
  363. assoc = sctp_assoc(epb);
  364. list_for_each_entry(tsp, &assoc->peer.transport_addr_list,
  365. transports) {
  366. /*
  367. * The remote address (ADDR)
  368. */
  369. tsp->af_specific->seq_dump_addr(seq, &tsp->ipaddr);
  370. seq_printf(seq, " ");
  371. /*
  372. * The association ID (ASSOC_ID)
  373. */
  374. seq_printf(seq, "%d ", tsp->asoc->assoc_id);
  375. /*
  376. * If the Heartbeat is active (HB_ACT)
  377. * Note: 1 = Active, 0 = Inactive
  378. */
  379. seq_printf(seq, "%d ", timer_pending(&tsp->hb_timer));
  380. /*
  381. * Retransmit time out (RTO)
  382. */
  383. seq_printf(seq, "%lu ", tsp->rto);
  384. /*
  385. * Maximum path retransmit count (PATH_MAX_RTX)
  386. */
  387. seq_printf(seq, "%d ", tsp->pathmaxrxt);
  388. /*
  389. * remote address retransmit count (REM_ADDR_RTX)
  390. * Note: We don't have a way to tally this at the moment
  391. * so lets just leave it as zero for the moment
  392. */
  393. seq_printf(seq, "0 ");
  394. /*
  395. * remote address start time (START). This is also not
  396. * currently implemented, but we can record it with a
  397. * jiffies marker in a subsequent patch
  398. */
  399. seq_printf(seq, "0");
  400. seq_printf(seq, "\n");
  401. }
  402. }
  403. read_unlock(&head->lock);
  404. sctp_local_bh_enable();
  405. return 0;
  406. }
  407. static const struct seq_operations sctp_remaddr_ops = {
  408. .start = sctp_remaddr_seq_start,
  409. .next = sctp_remaddr_seq_next,
  410. .stop = sctp_remaddr_seq_stop,
  411. .show = sctp_remaddr_seq_show,
  412. };
  413. /* Cleanup the proc fs entry for 'remaddr' object. */
  414. void sctp_remaddr_proc_exit(void)
  415. {
  416. remove_proc_entry("remaddr", proc_net_sctp);
  417. }
  418. static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
  419. {
  420. return seq_open(file, &sctp_remaddr_ops);
  421. }
  422. static const struct file_operations sctp_remaddr_seq_fops = {
  423. .open = sctp_remaddr_seq_open,
  424. .read = seq_read,
  425. .llseek = seq_lseek,
  426. .release = seq_release,
  427. };
  428. int __init sctp_remaddr_proc_init(void)
  429. {
  430. struct proc_dir_entry *p;
  431. p = create_proc_entry("remaddr", S_IRUGO, proc_net_sctp);
  432. if (!p)
  433. return -ENOMEM;
  434. p->proc_fops = &sctp_remaddr_seq_fops;
  435. return 0;
  436. }