proc.c 14 KB

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