proc.c 15 KB

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