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