proc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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, see
  20. * <http://www.gnu.org/licenses/>.
  21. *
  22. * Please send any bug reports or fixes you make to the
  23. * email address(es):
  24. * lksctp developers <linux-sctp@vger.kernel.org>
  25. *
  26. * Written or modified by:
  27. * Sridhar Samudrala <sri@us.ibm.com>
  28. */
  29. #include <linux/types.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/init.h>
  32. #include <linux/export.h>
  33. #include <net/sctp/sctp.h>
  34. #include <net/ip.h> /* for snmp_fold_field */
  35. static const struct snmp_mib sctp_snmp_list[] = {
  36. SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
  37. SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS),
  38. SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS),
  39. SNMP_MIB_ITEM("SctpAborteds", SCTP_MIB_ABORTEDS),
  40. SNMP_MIB_ITEM("SctpShutdowns", SCTP_MIB_SHUTDOWNS),
  41. SNMP_MIB_ITEM("SctpOutOfBlues", SCTP_MIB_OUTOFBLUES),
  42. SNMP_MIB_ITEM("SctpChecksumErrors", SCTP_MIB_CHECKSUMERRORS),
  43. SNMP_MIB_ITEM("SctpOutCtrlChunks", SCTP_MIB_OUTCTRLCHUNKS),
  44. SNMP_MIB_ITEM("SctpOutOrderChunks", SCTP_MIB_OUTORDERCHUNKS),
  45. SNMP_MIB_ITEM("SctpOutUnorderChunks", SCTP_MIB_OUTUNORDERCHUNKS),
  46. SNMP_MIB_ITEM("SctpInCtrlChunks", SCTP_MIB_INCTRLCHUNKS),
  47. SNMP_MIB_ITEM("SctpInOrderChunks", SCTP_MIB_INORDERCHUNKS),
  48. SNMP_MIB_ITEM("SctpInUnorderChunks", SCTP_MIB_INUNORDERCHUNKS),
  49. SNMP_MIB_ITEM("SctpFragUsrMsgs", SCTP_MIB_FRAGUSRMSGS),
  50. SNMP_MIB_ITEM("SctpReasmUsrMsgs", SCTP_MIB_REASMUSRMSGS),
  51. SNMP_MIB_ITEM("SctpOutSCTPPacks", SCTP_MIB_OUTSCTPPACKS),
  52. SNMP_MIB_ITEM("SctpInSCTPPacks", SCTP_MIB_INSCTPPACKS),
  53. SNMP_MIB_ITEM("SctpT1InitExpireds", SCTP_MIB_T1_INIT_EXPIREDS),
  54. SNMP_MIB_ITEM("SctpT1CookieExpireds", SCTP_MIB_T1_COOKIE_EXPIREDS),
  55. SNMP_MIB_ITEM("SctpT2ShutdownExpireds", SCTP_MIB_T2_SHUTDOWN_EXPIREDS),
  56. SNMP_MIB_ITEM("SctpT3RtxExpireds", SCTP_MIB_T3_RTX_EXPIREDS),
  57. SNMP_MIB_ITEM("SctpT4RtoExpireds", SCTP_MIB_T4_RTO_EXPIREDS),
  58. SNMP_MIB_ITEM("SctpT5ShutdownGuardExpireds", SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS),
  59. SNMP_MIB_ITEM("SctpDelaySackExpireds", SCTP_MIB_DELAY_SACK_EXPIREDS),
  60. SNMP_MIB_ITEM("SctpAutocloseExpireds", SCTP_MIB_AUTOCLOSE_EXPIREDS),
  61. SNMP_MIB_ITEM("SctpT3Retransmits", SCTP_MIB_T3_RETRANSMITS),
  62. SNMP_MIB_ITEM("SctpPmtudRetransmits", SCTP_MIB_PMTUD_RETRANSMITS),
  63. SNMP_MIB_ITEM("SctpFastRetransmits", SCTP_MIB_FAST_RETRANSMITS),
  64. SNMP_MIB_ITEM("SctpInPktSoftirq", SCTP_MIB_IN_PKT_SOFTIRQ),
  65. SNMP_MIB_ITEM("SctpInPktBacklog", SCTP_MIB_IN_PKT_BACKLOG),
  66. SNMP_MIB_ITEM("SctpInPktDiscards", SCTP_MIB_IN_PKT_DISCARDS),
  67. SNMP_MIB_ITEM("SctpInDataChunkDiscards", SCTP_MIB_IN_DATA_CHUNK_DISCARDS),
  68. SNMP_MIB_SENTINEL
  69. };
  70. /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
  71. static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
  72. {
  73. unsigned long buff[SCTP_MIB_MAX];
  74. struct net *net = seq->private;
  75. int i;
  76. memset(buff, 0, sizeof(unsigned long) * SCTP_MIB_MAX);
  77. snmp_get_cpu_field_batch(buff, sctp_snmp_list,
  78. net->sctp.sctp_statistics);
  79. for (i = 0; sctp_snmp_list[i].name; i++)
  80. seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
  81. buff[i]);
  82. return 0;
  83. }
  84. /* Dump local addresses of an association/endpoint. */
  85. static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
  86. {
  87. struct sctp_association *asoc;
  88. struct sctp_sockaddr_entry *laddr;
  89. struct sctp_transport *peer;
  90. union sctp_addr *addr, *primary = NULL;
  91. struct sctp_af *af;
  92. if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
  93. asoc = sctp_assoc(epb);
  94. peer = asoc->peer.primary_path;
  95. if (unlikely(peer == NULL)) {
  96. WARN(1, "Association %p with NULL primary path!\n", asoc);
  97. return;
  98. }
  99. primary = &peer->saddr;
  100. }
  101. rcu_read_lock();
  102. list_for_each_entry_rcu(laddr, &epb->bind_addr.address_list, list) {
  103. if (!laddr->valid)
  104. continue;
  105. addr = &laddr->a;
  106. af = sctp_get_af_specific(addr->sa.sa_family);
  107. if (primary && af->cmp_addr(addr, primary)) {
  108. seq_printf(seq, "*");
  109. }
  110. af->seq_dump_addr(seq, addr);
  111. }
  112. rcu_read_unlock();
  113. }
  114. /* Dump remote addresses of an association. */
  115. static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
  116. {
  117. struct sctp_transport *transport;
  118. union sctp_addr *addr, *primary;
  119. struct sctp_af *af;
  120. primary = &assoc->peer.primary_addr;
  121. list_for_each_entry_rcu(transport, &assoc->peer.transport_addr_list,
  122. transports) {
  123. addr = &transport->ipaddr;
  124. af = sctp_get_af_specific(addr->sa.sa_family);
  125. if (af->cmp_addr(addr, primary)) {
  126. seq_printf(seq, "*");
  127. }
  128. af->seq_dump_addr(seq, addr);
  129. }
  130. }
  131. static void *sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
  132. {
  133. if (*pos >= sctp_ep_hashsize)
  134. return NULL;
  135. if (*pos < 0)
  136. *pos = 0;
  137. if (*pos == 0)
  138. seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
  139. return (void *)pos;
  140. }
  141. static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
  142. {
  143. }
  144. static void *sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  145. {
  146. if (++*pos >= sctp_ep_hashsize)
  147. return NULL;
  148. return pos;
  149. }
  150. /* Display sctp endpoints (/proc/net/sctp/eps). */
  151. static int sctp_eps_seq_show(struct seq_file *seq, void *v)
  152. {
  153. struct sctp_hashbucket *head;
  154. struct sctp_ep_common *epb;
  155. struct sctp_endpoint *ep;
  156. struct sock *sk;
  157. int hash = *(loff_t *)v;
  158. if (hash >= sctp_ep_hashsize)
  159. return -ENOMEM;
  160. head = &sctp_ep_hashtable[hash];
  161. read_lock_bh(&head->lock);
  162. sctp_for_each_hentry(epb, &head->chain) {
  163. ep = sctp_ep(epb);
  164. sk = epb->sk;
  165. if (!net_eq(sock_net(sk), seq_file_net(seq)))
  166. continue;
  167. seq_printf(seq, "%8pK %8pK %-3d %-3d %-4d %-5d %5u %5lu ", ep, sk,
  168. sctp_sk(sk)->type, sk->sk_state, hash,
  169. epb->bind_addr.port,
  170. from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
  171. sock_i_ino(sk));
  172. sctp_seq_dump_local_addrs(seq, epb);
  173. seq_printf(seq, "\n");
  174. }
  175. read_unlock_bh(&head->lock);
  176. return 0;
  177. }
  178. static const struct seq_operations sctp_eps_ops = {
  179. .start = sctp_eps_seq_start,
  180. .next = sctp_eps_seq_next,
  181. .stop = sctp_eps_seq_stop,
  182. .show = sctp_eps_seq_show,
  183. };
  184. struct sctp_ht_iter {
  185. struct seq_net_private p;
  186. struct rhashtable_iter hti;
  187. };
  188. static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
  189. {
  190. struct sctp_ht_iter *iter = seq->private;
  191. sctp_transport_walk_start(&iter->hti);
  192. return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos);
  193. }
  194. static void sctp_transport_seq_stop(struct seq_file *seq, void *v)
  195. {
  196. struct sctp_ht_iter *iter = seq->private;
  197. sctp_transport_walk_stop(&iter->hti);
  198. }
  199. static void *sctp_transport_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  200. {
  201. struct sctp_ht_iter *iter = seq->private;
  202. ++*pos;
  203. return sctp_transport_get_next(seq_file_net(seq), &iter->hti);
  204. }
  205. /* Display sctp associations (/proc/net/sctp/assocs). */
  206. static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
  207. {
  208. struct sctp_transport *transport;
  209. struct sctp_association *assoc;
  210. struct sctp_ep_common *epb;
  211. struct sock *sk;
  212. if (v == SEQ_START_TOKEN) {
  213. seq_printf(seq, " ASSOC SOCK STY SST ST HBKT "
  214. "ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
  215. "RPORT LADDRS <-> RADDRS "
  216. "HBINT INS OUTS MAXRT T1X T2X RTXC "
  217. "wmema wmemq sndbuf rcvbuf\n");
  218. return 0;
  219. }
  220. transport = (struct sctp_transport *)v;
  221. assoc = transport->asoc;
  222. epb = &assoc->base;
  223. sk = epb->sk;
  224. seq_printf(seq,
  225. "%8pK %8pK %-3d %-3d %-2d %-4d "
  226. "%4d %8d %8d %7u %5lu %-5d %5d ",
  227. assoc, sk, sctp_sk(sk)->type, sk->sk_state,
  228. assoc->state, 0,
  229. assoc->assoc_id,
  230. assoc->sndbuf_used,
  231. atomic_read(&assoc->rmem_alloc),
  232. from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
  233. sock_i_ino(sk),
  234. epb->bind_addr.port,
  235. assoc->peer.port);
  236. seq_printf(seq, " ");
  237. sctp_seq_dump_local_addrs(seq, epb);
  238. seq_printf(seq, "<-> ");
  239. sctp_seq_dump_remote_addrs(seq, assoc);
  240. seq_printf(seq, "\t%8lu %5d %5d %4d %4d %4d %8d "
  241. "%8d %8d %8d %8d",
  242. assoc->hbinterval, assoc->stream.incnt,
  243. assoc->stream.outcnt, assoc->max_retrans,
  244. assoc->init_retries, assoc->shutdown_retries,
  245. assoc->rtx_data_chunks,
  246. refcount_read(&sk->sk_wmem_alloc),
  247. sk->sk_wmem_queued,
  248. sk->sk_sndbuf,
  249. sk->sk_rcvbuf);
  250. seq_printf(seq, "\n");
  251. sctp_transport_put(transport);
  252. return 0;
  253. }
  254. static const struct seq_operations sctp_assoc_ops = {
  255. .start = sctp_transport_seq_start,
  256. .next = sctp_transport_seq_next,
  257. .stop = sctp_transport_seq_stop,
  258. .show = sctp_assocs_seq_show,
  259. };
  260. static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
  261. {
  262. struct sctp_association *assoc;
  263. struct sctp_transport *transport, *tsp;
  264. if (v == SEQ_START_TOKEN) {
  265. seq_printf(seq, "ADDR ASSOC_ID HB_ACT RTO MAX_PATH_RTX "
  266. "REM_ADDR_RTX START STATE\n");
  267. return 0;
  268. }
  269. transport = (struct sctp_transport *)v;
  270. assoc = transport->asoc;
  271. list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list,
  272. transports) {
  273. /*
  274. * The remote address (ADDR)
  275. */
  276. tsp->af_specific->seq_dump_addr(seq, &tsp->ipaddr);
  277. seq_printf(seq, " ");
  278. /*
  279. * The association ID (ASSOC_ID)
  280. */
  281. seq_printf(seq, "%d ", tsp->asoc->assoc_id);
  282. /*
  283. * If the Heartbeat is active (HB_ACT)
  284. * Note: 1 = Active, 0 = Inactive
  285. */
  286. seq_printf(seq, "%d ", timer_pending(&tsp->hb_timer));
  287. /*
  288. * Retransmit time out (RTO)
  289. */
  290. seq_printf(seq, "%lu ", tsp->rto);
  291. /*
  292. * Maximum path retransmit count (PATH_MAX_RTX)
  293. */
  294. seq_printf(seq, "%d ", tsp->pathmaxrxt);
  295. /*
  296. * remote address retransmit count (REM_ADDR_RTX)
  297. * Note: We don't have a way to tally this at the moment
  298. * so lets just leave it as zero for the moment
  299. */
  300. seq_puts(seq, "0 ");
  301. /*
  302. * remote address start time (START). This is also not
  303. * currently implemented, but we can record it with a
  304. * jiffies marker in a subsequent patch
  305. */
  306. seq_puts(seq, "0 ");
  307. /*
  308. * The current state of this destination. I.e.
  309. * SCTP_ACTIVE, SCTP_INACTIVE, ...
  310. */
  311. seq_printf(seq, "%d", tsp->state);
  312. seq_printf(seq, "\n");
  313. }
  314. sctp_transport_put(transport);
  315. return 0;
  316. }
  317. static const struct seq_operations sctp_remaddr_ops = {
  318. .start = sctp_transport_seq_start,
  319. .next = sctp_transport_seq_next,
  320. .stop = sctp_transport_seq_stop,
  321. .show = sctp_remaddr_seq_show,
  322. };
  323. /* Set up the proc fs entry for the SCTP protocol. */
  324. int __net_init sctp_proc_init(struct net *net)
  325. {
  326. net->sctp.proc_net_sctp = proc_net_mkdir(net, "sctp", net->proc_net);
  327. if (!net->sctp.proc_net_sctp)
  328. return -ENOMEM;
  329. if (!proc_create_net_single("snmp", 0444, net->sctp.proc_net_sctp,
  330. sctp_snmp_seq_show, NULL))
  331. goto cleanup;
  332. if (!proc_create_net("eps", 0444, net->sctp.proc_net_sctp,
  333. &sctp_eps_ops, sizeof(struct seq_net_private)))
  334. goto cleanup;
  335. if (!proc_create_net("assocs", 0444, net->sctp.proc_net_sctp,
  336. &sctp_assoc_ops, sizeof(struct sctp_ht_iter)))
  337. goto cleanup;
  338. if (!proc_create_net("remaddr", 0444, net->sctp.proc_net_sctp,
  339. &sctp_remaddr_ops, sizeof(struct sctp_ht_iter)))
  340. goto cleanup;
  341. return 0;
  342. cleanup:
  343. remove_proc_subtree("sctp", net->proc_net);
  344. net->sctp.proc_net_sctp = NULL;
  345. return -ENOMEM;
  346. }