174fd40c9SRandall Stewart /*- 274fd40c9SRandall Stewart * Copyright (c) 2001-2007, by Weongyo Jeong. All rights reserved. 32e34c19bSMichael Tuexen * Copyright (c) 2011, by Michael Tuexen. All rights reserved. 474fd40c9SRandall Stewart * 574fd40c9SRandall Stewart * Redistribution and use in source and binary forms, with or without 674fd40c9SRandall Stewart * modification, are permitted provided that the following conditions are met: 774fd40c9SRandall Stewart * 874fd40c9SRandall Stewart * a) Redistributions of source code must retain the above copyright notice, 974fd40c9SRandall Stewart * this list of conditions and the following disclaimer. 1074fd40c9SRandall Stewart * 1174fd40c9SRandall Stewart * b) Redistributions in binary form must reproduce the above copyright 1274fd40c9SRandall Stewart * notice, this list of conditions and the following disclaimer in 1374fd40c9SRandall Stewart * the documentation and/or other materials provided with the distribution. 1474fd40c9SRandall Stewart * 1574fd40c9SRandall Stewart * c) Neither the name of Cisco Systems, Inc. nor the names of its 1674fd40c9SRandall Stewart * contributors may be used to endorse or promote products derived 1774fd40c9SRandall Stewart * from this software without specific prior written permission. 1874fd40c9SRandall Stewart * 1974fd40c9SRandall Stewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2074fd40c9SRandall Stewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 2174fd40c9SRandall Stewart * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2274fd40c9SRandall Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2374fd40c9SRandall Stewart * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2474fd40c9SRandall Stewart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2574fd40c9SRandall Stewart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2674fd40c9SRandall Stewart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2774fd40c9SRandall Stewart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2874fd40c9SRandall Stewart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 2974fd40c9SRandall Stewart * THE POSSIBILITY OF SUCH DAMAGE. 3074fd40c9SRandall Stewart */ 3174fd40c9SRandall Stewart 3274fd40c9SRandall Stewart #if 0 3374fd40c9SRandall Stewart #ifndef lint 3474fd40c9SRandall Stewart static char sccsid[] = "@(#)sctp.c 0.1 (Berkeley) 4/18/2007"; 3574fd40c9SRandall Stewart #endif /* not lint */ 3674fd40c9SRandall Stewart #endif 3774fd40c9SRandall Stewart 3874fd40c9SRandall Stewart #include <sys/cdefs.h> 3974fd40c9SRandall Stewart __FBSDID("$FreeBSD$"); 4074fd40c9SRandall Stewart 4174fd40c9SRandall Stewart #include <sys/param.h> 4274fd40c9SRandall Stewart #include <sys/queue.h> 4374fd40c9SRandall Stewart #include <sys/types.h> 4474fd40c9SRandall Stewart #include <sys/socket.h> 4574fd40c9SRandall Stewart #include <sys/socketvar.h> 4674fd40c9SRandall Stewart #include <sys/sysctl.h> 4774fd40c9SRandall Stewart #include <sys/protosw.h> 4874fd40c9SRandall Stewart 4974fd40c9SRandall Stewart #include <netinet/in.h> 5074fd40c9SRandall Stewart #include <netinet/sctp.h> 5174fd40c9SRandall Stewart #include <netinet/sctp_constants.h> 5274fd40c9SRandall Stewart #include <arpa/inet.h> 5374fd40c9SRandall Stewart 5474fd40c9SRandall Stewart #include <err.h> 5574fd40c9SRandall Stewart #include <errno.h> 56821df508SXin LI #include <libutil.h> 57821df508SXin LI #include <netdb.h> 5874fd40c9SRandall Stewart #include <stdint.h> 5974fd40c9SRandall Stewart #include <stdio.h> 6074fd40c9SRandall Stewart #include <stdlib.h> 61ade9ccfeSMarcel Moolenaar #include <stdbool.h> 6274fd40c9SRandall Stewart #include <string.h> 63821df508SXin LI #include <unistd.h> 6474fd40c9SRandall Stewart #include "netstat.h" 65ade9ccfeSMarcel Moolenaar #include <libxo/xo.h> 6674fd40c9SRandall Stewart 6774fd40c9SRandall Stewart #ifdef SCTP 6874fd40c9SRandall Stewart 6974fd40c9SRandall Stewart static void sctp_statesprint(uint32_t state); 7074fd40c9SRandall Stewart 7174fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_CLOSED 0x0 7274fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_BOUND 0x1 7374fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_LISTEN 0x2 7474fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_COOKIE_WAIT 0x3 7574fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_COOKIE_ECHOED 0x4 7674fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_ESTABLISHED 0x5 7774fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_SHUTDOWN_SENT 0x6 7874fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED 0x7 7974fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT 0x8 8074fd40c9SRandall Stewart #define NETSTAT_SCTP_STATES_SHUTDOWN_PENDING 0x9 8174fd40c9SRandall Stewart 8210d5269fSHiroki Sato static const char *sctpstates[] = { 8374fd40c9SRandall Stewart "CLOSED", 8474fd40c9SRandall Stewart "BOUND", 8574fd40c9SRandall Stewart "LISTEN", 8674fd40c9SRandall Stewart "COOKIE_WAIT", 8774fd40c9SRandall Stewart "COOKIE_ECHOED", 8874fd40c9SRandall Stewart "ESTABLISHED", 8974fd40c9SRandall Stewart "SHUTDOWN_SENT", 9074fd40c9SRandall Stewart "SHUTDOWN_RECEIVED", 9174fd40c9SRandall Stewart "SHUTDOWN_ACK_SENT", 9274fd40c9SRandall Stewart "SHUTDOWN_PENDING" 9374fd40c9SRandall Stewart }; 9474fd40c9SRandall Stewart 9510d5269fSHiroki Sato static LIST_HEAD(xladdr_list, xladdr_entry) xladdr_head; 9674fd40c9SRandall Stewart struct xladdr_entry { 9774fd40c9SRandall Stewart struct xsctp_laddr *xladdr; 9874fd40c9SRandall Stewart LIST_ENTRY(xladdr_entry) xladdr_entries; 9974fd40c9SRandall Stewart }; 10074fd40c9SRandall Stewart 10110d5269fSHiroki Sato static LIST_HEAD(xraddr_list, xraddr_entry) xraddr_head; 10274fd40c9SRandall Stewart struct xraddr_entry { 10374fd40c9SRandall Stewart struct xsctp_raddr *xraddr; 10474fd40c9SRandall Stewart LIST_ENTRY(xraddr_entry) xraddr_entries; 10574fd40c9SRandall Stewart }; 10674fd40c9SRandall Stewart 1072e34c19bSMichael Tuexen /* 1082e34c19bSMichael Tuexen * Construct an Internet address representation. 1092e34c19bSMichael Tuexen * If numeric_addr has been supplied, give 1102e34c19bSMichael Tuexen * numeric value, otherwise try for symbolic name. 1112e34c19bSMichael Tuexen */ 1123dcc856bSMichael Tuexen #ifdef INET 1132e34c19bSMichael Tuexen static char * 1142e34c19bSMichael Tuexen inetname(struct in_addr *inp) 1152e34c19bSMichael Tuexen { 1162e34c19bSMichael Tuexen char *cp; 1172e34c19bSMichael Tuexen static char line[MAXHOSTNAMELEN]; 1182e34c19bSMichael Tuexen struct hostent *hp; 1192e34c19bSMichael Tuexen struct netent *np; 1202e34c19bSMichael Tuexen 1212e34c19bSMichael Tuexen cp = 0; 1222e34c19bSMichael Tuexen if (!numeric_addr && inp->s_addr != INADDR_ANY) { 1232e34c19bSMichael Tuexen int net = inet_netof(*inp); 1242e34c19bSMichael Tuexen int lna = inet_lnaof(*inp); 1252e34c19bSMichael Tuexen 1262e34c19bSMichael Tuexen if (lna == INADDR_ANY) { 1272e34c19bSMichael Tuexen np = getnetbyaddr(net, AF_INET); 1282e34c19bSMichael Tuexen if (np) 1292e34c19bSMichael Tuexen cp = np->n_name; 1302e34c19bSMichael Tuexen } 131ef1cb629SMarcelo Araujo if (cp == NULL) { 1322e34c19bSMichael Tuexen hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); 1332e34c19bSMichael Tuexen if (hp) { 1342e34c19bSMichael Tuexen cp = hp->h_name; 1352e34c19bSMichael Tuexen trimdomain(cp, strlen(cp)); 1362e34c19bSMichael Tuexen } 1372e34c19bSMichael Tuexen } 1382e34c19bSMichael Tuexen } 1392e34c19bSMichael Tuexen if (inp->s_addr == INADDR_ANY) 1402e34c19bSMichael Tuexen strcpy(line, "*"); 1412e34c19bSMichael Tuexen else if (cp) { 1422e34c19bSMichael Tuexen strlcpy(line, cp, sizeof(line)); 1432e34c19bSMichael Tuexen } else { 1442e34c19bSMichael Tuexen inp->s_addr = ntohl(inp->s_addr); 1452e34c19bSMichael Tuexen #define C(x) ((u_int)((x) & 0xff)) 1462e34c19bSMichael Tuexen sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24), 1472e34c19bSMichael Tuexen C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr)); 1482e34c19bSMichael Tuexen inp->s_addr = htonl(inp->s_addr); 1492e34c19bSMichael Tuexen } 1502e34c19bSMichael Tuexen return (line); 1512e34c19bSMichael Tuexen } 1523dcc856bSMichael Tuexen #endif 1532e34c19bSMichael Tuexen 1542e34c19bSMichael Tuexen #ifdef INET6 1552e34c19bSMichael Tuexen static char ntop_buf[INET6_ADDRSTRLEN]; 1562e34c19bSMichael Tuexen 1572e34c19bSMichael Tuexen static char * 1582e34c19bSMichael Tuexen inet6name(struct in6_addr *in6p) 1592e34c19bSMichael Tuexen { 1602e34c19bSMichael Tuexen char *cp; 1612e34c19bSMichael Tuexen static char line[50]; 1622e34c19bSMichael Tuexen struct hostent *hp; 1632e34c19bSMichael Tuexen static char domain[MAXHOSTNAMELEN]; 1642e34c19bSMichael Tuexen static int first = 1; 1652e34c19bSMichael Tuexen 1662e34c19bSMichael Tuexen if (first && !numeric_addr) { 1672e34c19bSMichael Tuexen first = 0; 1682e34c19bSMichael Tuexen if (gethostname(domain, MAXHOSTNAMELEN) == 0 && 169b3608ae1SEd Schouten (cp = strchr(domain, '.'))) 1702e34c19bSMichael Tuexen (void) strcpy(domain, cp + 1); 1712e34c19bSMichael Tuexen else 1722e34c19bSMichael Tuexen domain[0] = 0; 1732e34c19bSMichael Tuexen } 1742e34c19bSMichael Tuexen cp = 0; 1752e34c19bSMichael Tuexen if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { 1762e34c19bSMichael Tuexen hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); 1772e34c19bSMichael Tuexen if (hp) { 178b3608ae1SEd Schouten if ((cp = strchr(hp->h_name, '.')) && 1792e34c19bSMichael Tuexen !strcmp(cp + 1, domain)) 1802e34c19bSMichael Tuexen *cp = 0; 1812e34c19bSMichael Tuexen cp = hp->h_name; 1822e34c19bSMichael Tuexen } 1832e34c19bSMichael Tuexen } 1842e34c19bSMichael Tuexen if (IN6_IS_ADDR_UNSPECIFIED(in6p)) 1852e34c19bSMichael Tuexen strcpy(line, "*"); 1862e34c19bSMichael Tuexen else if (cp) 1872e34c19bSMichael Tuexen strcpy(line, cp); 1882e34c19bSMichael Tuexen else 1892e34c19bSMichael Tuexen sprintf(line, "%s", 1902e34c19bSMichael Tuexen inet_ntop(AF_INET6, (void *)in6p, ntop_buf, 1912e34c19bSMichael Tuexen sizeof(ntop_buf))); 1922e34c19bSMichael Tuexen return (line); 1932e34c19bSMichael Tuexen } 1942e34c19bSMichael Tuexen #endif 1952e34c19bSMichael Tuexen 1962e34c19bSMichael Tuexen static void 197ade9ccfeSMarcel Moolenaar sctp_print_address(const char *container, union sctp_sockstore *address, 198ade9ccfeSMarcel Moolenaar int port, int num_port) 1992e34c19bSMichael Tuexen { 2002e34c19bSMichael Tuexen struct servent *sp = 0; 2012e34c19bSMichael Tuexen char line[80], *cp; 2022e34c19bSMichael Tuexen int width; 2032e34c19bSMichael Tuexen 204ade9ccfeSMarcel Moolenaar if (container) 205ade9ccfeSMarcel Moolenaar xo_open_container(container); 206ade9ccfeSMarcel Moolenaar 2072e34c19bSMichael Tuexen switch (address->sa.sa_family) { 2083dcc856bSMichael Tuexen #ifdef INET 2092e34c19bSMichael Tuexen case AF_INET: 2102e34c19bSMichael Tuexen sprintf(line, "%.*s.", Wflag ? 39 : 16, inetname(&address->sin.sin_addr)); 2112e34c19bSMichael Tuexen break; 2123dcc856bSMichael Tuexen #endif 2132e34c19bSMichael Tuexen #ifdef INET6 2142e34c19bSMichael Tuexen case AF_INET6: 2152e34c19bSMichael Tuexen sprintf(line, "%.*s.", Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr)); 2162e34c19bSMichael Tuexen break; 2172e34c19bSMichael Tuexen #endif 2182e34c19bSMichael Tuexen default: 2192e34c19bSMichael Tuexen sprintf(line, "%.*s.", Wflag ? 39 : 16, ""); 2202e34c19bSMichael Tuexen break; 2212e34c19bSMichael Tuexen } 222b3608ae1SEd Schouten cp = strchr(line, '\0'); 2232e34c19bSMichael Tuexen if (!num_port && port) 2242e34c19bSMichael Tuexen sp = getservbyport((int)port, "sctp"); 2252e34c19bSMichael Tuexen if (sp || port == 0) 2262e34c19bSMichael Tuexen sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); 2272e34c19bSMichael Tuexen else 2282e34c19bSMichael Tuexen sprintf(cp, "%d ", ntohs((u_short)port)); 2292e34c19bSMichael Tuexen width = Wflag ? 45 : 22; 230ade9ccfeSMarcel Moolenaar xo_emit("{d:target/%-*.*s} ", width, width, line); 231ade9ccfeSMarcel Moolenaar 232ade9ccfeSMarcel Moolenaar int alen = cp - line - 1, plen = strlen(cp) - 1; 233ade9ccfeSMarcel Moolenaar xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, 234ade9ccfeSMarcel Moolenaar plen, cp); 235ade9ccfeSMarcel Moolenaar 236ade9ccfeSMarcel Moolenaar if (container) 237ade9ccfeSMarcel Moolenaar xo_close_container(container); 2382e34c19bSMichael Tuexen } 2392e34c19bSMichael Tuexen 24074fd40c9SRandall Stewart static int 24174fd40c9SRandall Stewart sctp_skip_xinpcb_ifneed(char *buf, const size_t buflen, size_t *offset) 24274fd40c9SRandall Stewart { 24374fd40c9SRandall Stewart int exist_tcb = 0; 24474fd40c9SRandall Stewart struct xsctp_tcb *xstcb; 24574fd40c9SRandall Stewart struct xsctp_raddr *xraddr; 24674fd40c9SRandall Stewart struct xsctp_laddr *xladdr; 24774fd40c9SRandall Stewart 24874fd40c9SRandall Stewart while (*offset < buflen) { 24974fd40c9SRandall Stewart xladdr = (struct xsctp_laddr *)(buf + *offset); 25074fd40c9SRandall Stewart *offset += sizeof(struct xsctp_laddr); 25174fd40c9SRandall Stewart if (xladdr->last == 1) 25274fd40c9SRandall Stewart break; 25374fd40c9SRandall Stewart } 25474fd40c9SRandall Stewart 25574fd40c9SRandall Stewart while (*offset < buflen) { 25674fd40c9SRandall Stewart xstcb = (struct xsctp_tcb *)(buf + *offset); 25774fd40c9SRandall Stewart *offset += sizeof(struct xsctp_tcb); 25874fd40c9SRandall Stewart if (xstcb->last == 1) 25974fd40c9SRandall Stewart break; 26074fd40c9SRandall Stewart 26174fd40c9SRandall Stewart exist_tcb = 1; 26274fd40c9SRandall Stewart 26374fd40c9SRandall Stewart while (*offset < buflen) { 26474fd40c9SRandall Stewart xladdr = (struct xsctp_laddr *)(buf + *offset); 26574fd40c9SRandall Stewart *offset += sizeof(struct xsctp_laddr); 26674fd40c9SRandall Stewart if (xladdr->last == 1) 26774fd40c9SRandall Stewart break; 26874fd40c9SRandall Stewart } 26974fd40c9SRandall Stewart 27074fd40c9SRandall Stewart while (*offset < buflen) { 27174fd40c9SRandall Stewart xraddr = (struct xsctp_raddr *)(buf + *offset); 27274fd40c9SRandall Stewart *offset += sizeof(struct xsctp_raddr); 27374fd40c9SRandall Stewart if (xraddr->last == 1) 27474fd40c9SRandall Stewart break; 27574fd40c9SRandall Stewart } 27674fd40c9SRandall Stewart } 27774fd40c9SRandall Stewart 27874fd40c9SRandall Stewart /* 27974fd40c9SRandall Stewart * If Lflag is set, we don't care about the return value. 28074fd40c9SRandall Stewart */ 28174fd40c9SRandall Stewart if (Lflag) 28274fd40c9SRandall Stewart return 0; 28374fd40c9SRandall Stewart 28474fd40c9SRandall Stewart return exist_tcb; 28574fd40c9SRandall Stewart } 28674fd40c9SRandall Stewart 28774fd40c9SRandall Stewart static void 2882e34c19bSMichael Tuexen sctp_process_tcb(struct xsctp_tcb *xstcb, 28974fd40c9SRandall Stewart char *buf, const size_t buflen, size_t *offset, int *indent) 29074fd40c9SRandall Stewart { 29174fd40c9SRandall Stewart int i, xl_total = 0, xr_total = 0, x_max; 29274fd40c9SRandall Stewart struct xsctp_raddr *xraddr; 29374fd40c9SRandall Stewart struct xsctp_laddr *xladdr; 29474fd40c9SRandall Stewart struct xladdr_entry *prev_xl = NULL, *xl = NULL, *xl_tmp; 29574fd40c9SRandall Stewart struct xraddr_entry *prev_xr = NULL, *xr = NULL, *xr_tmp; 29674fd40c9SRandall Stewart 29774fd40c9SRandall Stewart LIST_INIT(&xladdr_head); 29874fd40c9SRandall Stewart LIST_INIT(&xraddr_head); 29974fd40c9SRandall Stewart 30074fd40c9SRandall Stewart /* 30174fd40c9SRandall Stewart * Make `struct xladdr_list' list and `struct xraddr_list' list 30274fd40c9SRandall Stewart * to handle the address flexibly. 30374fd40c9SRandall Stewart */ 30474fd40c9SRandall Stewart while (*offset < buflen) { 30574fd40c9SRandall Stewart xladdr = (struct xsctp_laddr *)(buf + *offset); 30674fd40c9SRandall Stewart *offset += sizeof(struct xsctp_laddr); 30774fd40c9SRandall Stewart if (xladdr->last == 1) 30874fd40c9SRandall Stewart break; 30974fd40c9SRandall Stewart 31074fd40c9SRandall Stewart prev_xl = xl; 31174fd40c9SRandall Stewart xl = malloc(sizeof(struct xladdr_entry)); 31274fd40c9SRandall Stewart if (xl == NULL) { 313ade9ccfeSMarcel Moolenaar xo_warnx("malloc %lu bytes", 31474fd40c9SRandall Stewart (u_long)sizeof(struct xladdr_entry)); 31574fd40c9SRandall Stewart goto out; 31674fd40c9SRandall Stewart } 31774fd40c9SRandall Stewart xl->xladdr = xladdr; 31874fd40c9SRandall Stewart if (prev_xl == NULL) 31974fd40c9SRandall Stewart LIST_INSERT_HEAD(&xladdr_head, xl, xladdr_entries); 32074fd40c9SRandall Stewart else 32174fd40c9SRandall Stewart LIST_INSERT_AFTER(prev_xl, xl, xladdr_entries); 32274fd40c9SRandall Stewart xl_total++; 32374fd40c9SRandall Stewart } 32474fd40c9SRandall Stewart 32574fd40c9SRandall Stewart while (*offset < buflen) { 32674fd40c9SRandall Stewart xraddr = (struct xsctp_raddr *)(buf + *offset); 32774fd40c9SRandall Stewart *offset += sizeof(struct xsctp_raddr); 32874fd40c9SRandall Stewart if (xraddr->last == 1) 32974fd40c9SRandall Stewart break; 33074fd40c9SRandall Stewart 33174fd40c9SRandall Stewart prev_xr = xr; 33274fd40c9SRandall Stewart xr = malloc(sizeof(struct xraddr_entry)); 33374fd40c9SRandall Stewart if (xr == NULL) { 334ade9ccfeSMarcel Moolenaar xo_warnx("malloc %lu bytes", 33574fd40c9SRandall Stewart (u_long)sizeof(struct xraddr_entry)); 33674fd40c9SRandall Stewart goto out; 33774fd40c9SRandall Stewart } 33874fd40c9SRandall Stewart xr->xraddr = xraddr; 33974fd40c9SRandall Stewart if (prev_xr == NULL) 34074fd40c9SRandall Stewart LIST_INSERT_HEAD(&xraddr_head, xr, xraddr_entries); 34174fd40c9SRandall Stewart else 34274fd40c9SRandall Stewart LIST_INSERT_AFTER(prev_xr, xr, xraddr_entries); 34374fd40c9SRandall Stewart xr_total++; 34474fd40c9SRandall Stewart } 34574fd40c9SRandall Stewart 34674fd40c9SRandall Stewart /* 34774fd40c9SRandall Stewart * Let's print the address infos. 34874fd40c9SRandall Stewart */ 349ade9ccfeSMarcel Moolenaar xo_open_list("address"); 35074fd40c9SRandall Stewart xl = LIST_FIRST(&xladdr_head); 35174fd40c9SRandall Stewart xr = LIST_FIRST(&xraddr_head); 352*fcc0131fSMarcelo Araujo x_max = MAX(xl_total, xr_total); 35374fd40c9SRandall Stewart for (i = 0; i < x_max; i++) { 354ade9ccfeSMarcel Moolenaar xo_open_instance("address"); 355ade9ccfeSMarcel Moolenaar 35674fd40c9SRandall Stewart if (((*indent == 0) && i > 0) || *indent > 0) 357ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-12s} ", " "); 35874fd40c9SRandall Stewart 35974fd40c9SRandall Stewart if (xl != NULL) { 360ade9ccfeSMarcel Moolenaar sctp_print_address("local", &(xl->xladdr->address), 3612e34c19bSMichael Tuexen htons(xstcb->local_port), numeric_port); 3622e34c19bSMichael Tuexen } else { 3632e34c19bSMichael Tuexen if (Wflag) { 364ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45s} ", " "); 3652e34c19bSMichael Tuexen } else { 366ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-22s} ", " "); 36774fd40c9SRandall Stewart } 36874fd40c9SRandall Stewart } 36974fd40c9SRandall Stewart 37074fd40c9SRandall Stewart if (xr != NULL && !Lflag) { 371ade9ccfeSMarcel Moolenaar sctp_print_address("remote", &(xr->xraddr->address), 3722e34c19bSMichael Tuexen htons(xstcb->remote_port), numeric_port); 37374fd40c9SRandall Stewart } 37474fd40c9SRandall Stewart 37574fd40c9SRandall Stewart if (xl != NULL) 37674fd40c9SRandall Stewart xl = LIST_NEXT(xl, xladdr_entries); 37774fd40c9SRandall Stewart if (xr != NULL) 37874fd40c9SRandall Stewart xr = LIST_NEXT(xr, xraddr_entries); 37974fd40c9SRandall Stewart 38074fd40c9SRandall Stewart if (i == 0 && !Lflag) 38174fd40c9SRandall Stewart sctp_statesprint(xstcb->state); 38274fd40c9SRandall Stewart 38374fd40c9SRandall Stewart if (i < x_max) 384ade9ccfeSMarcel Moolenaar xo_emit("\n"); 385ade9ccfeSMarcel Moolenaar xo_close_instance("address"); 38674fd40c9SRandall Stewart } 38774fd40c9SRandall Stewart 38874fd40c9SRandall Stewart out: 38974fd40c9SRandall Stewart /* 39074fd40c9SRandall Stewart * Free the list which be used to handle the address. 39174fd40c9SRandall Stewart */ 39274fd40c9SRandall Stewart xl = LIST_FIRST(&xladdr_head); 39374fd40c9SRandall Stewart while (xl != NULL) { 39474fd40c9SRandall Stewart xl_tmp = LIST_NEXT(xl, xladdr_entries); 39574fd40c9SRandall Stewart free(xl); 39674fd40c9SRandall Stewart xl = xl_tmp; 39774fd40c9SRandall Stewart } 39874fd40c9SRandall Stewart 39974fd40c9SRandall Stewart xr = LIST_FIRST(&xraddr_head); 40074fd40c9SRandall Stewart while (xr != NULL) { 40174fd40c9SRandall Stewart xr_tmp = LIST_NEXT(xr, xraddr_entries); 40274fd40c9SRandall Stewart free(xr); 40374fd40c9SRandall Stewart xr = xr_tmp; 40474fd40c9SRandall Stewart } 40574fd40c9SRandall Stewart } 40674fd40c9SRandall Stewart 40774fd40c9SRandall Stewart static void 4082e34c19bSMichael Tuexen sctp_process_inpcb(struct xsctp_inpcb *xinpcb, 40974fd40c9SRandall Stewart char *buf, const size_t buflen, size_t *offset) 41074fd40c9SRandall Stewart { 4112e34c19bSMichael Tuexen int indent = 0, xladdr_total = 0, is_listening = 0; 41274fd40c9SRandall Stewart static int first = 1; 413321ae07fSPhilippe Charnier const char *tname, *pname; 41474fd40c9SRandall Stewart struct xsctp_tcb *xstcb; 41574fd40c9SRandall Stewart struct xsctp_laddr *xladdr; 4162e34c19bSMichael Tuexen size_t offset_laddr; 4172e34c19bSMichael Tuexen int process_closed; 41874fd40c9SRandall Stewart 4192e34c19bSMichael Tuexen if (xinpcb->maxqlen > 0) 42074fd40c9SRandall Stewart is_listening = 1; 42174fd40c9SRandall Stewart 42274fd40c9SRandall Stewart if (first) { 42374fd40c9SRandall Stewart if (!Lflag) { 424ade9ccfeSMarcel Moolenaar xo_emit("Active SCTP associations"); 42574fd40c9SRandall Stewart if (aflag) 426ade9ccfeSMarcel Moolenaar xo_emit(" (including servers)"); 42774fd40c9SRandall Stewart } else 428ade9ccfeSMarcel Moolenaar xo_emit("Current listen queue sizes (qlen/maxqlen)"); 429ade9ccfeSMarcel Moolenaar xo_emit("\n"); 43074fd40c9SRandall Stewart if (Lflag) 431ade9ccfeSMarcel Moolenaar xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-8.8s} " 432ade9ccfeSMarcel Moolenaar "{T:/%-22.22s}\n", 43374fd40c9SRandall Stewart "Proto", "Type", "Listen", "Local Address"); 43474fd40c9SRandall Stewart else 4352e34c19bSMichael Tuexen if (Wflag) 436ade9ccfeSMarcel Moolenaar xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-45.45s} " 437ade9ccfeSMarcel Moolenaar "{T:/%-45.45s} {T:/%s}\n", 4382e34c19bSMichael Tuexen "Proto", "Type", 4392e34c19bSMichael Tuexen "Local Address", "Foreign Address", 4402e34c19bSMichael Tuexen "(state)"); 4412e34c19bSMichael Tuexen else 442ade9ccfeSMarcel Moolenaar xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-22.22s} " 443ade9ccfeSMarcel Moolenaar "{T:/%-22.22s} {T:/%s}\n", 44474fd40c9SRandall Stewart "Proto", "Type", 44574fd40c9SRandall Stewart "Local Address", "Foreign Address", 44674fd40c9SRandall Stewart "(state)"); 44774fd40c9SRandall Stewart first = 0; 44874fd40c9SRandall Stewart } 4492e34c19bSMichael Tuexen xladdr = (struct xsctp_laddr *)(buf + *offset); 4502e34c19bSMichael Tuexen if (Lflag && !is_listening) { 45193f8854cSDimitry Andric sctp_skip_xinpcb_ifneed(buf, buflen, offset); 45274fd40c9SRandall Stewart return; 45374fd40c9SRandall Stewart } 45474fd40c9SRandall Stewart 4552e34c19bSMichael Tuexen if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) { 4562e34c19bSMichael Tuexen /* Can't distinguish between sctp46 and sctp6 */ 4572e34c19bSMichael Tuexen pname = "sctp46"; 4582e34c19bSMichael Tuexen } else { 4592e34c19bSMichael Tuexen pname = "sctp4"; 4602e34c19bSMichael Tuexen } 46174fd40c9SRandall Stewart 46274fd40c9SRandall Stewart if (xinpcb->flags & SCTP_PCB_FLAGS_TCPTYPE) 46374fd40c9SRandall Stewart tname = "1to1"; 46474fd40c9SRandall Stewart else if (xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE) 46574fd40c9SRandall Stewart tname = "1toN"; 46674fd40c9SRandall Stewart else 4672e34c19bSMichael Tuexen tname = "????"; 46874fd40c9SRandall Stewart 46974fd40c9SRandall Stewart if (Lflag) { 4707325dfbbSAlfred Perlstein char buf1[22]; 47174fd40c9SRandall Stewart 4727325dfbbSAlfred Perlstein snprintf(buf1, sizeof buf1, "%u/%u", 4737325dfbbSAlfred Perlstein xinpcb->qlen, xinpcb->maxqlen); 474ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ", 475ade9ccfeSMarcel Moolenaar pname, tname); 476ade9ccfeSMarcel Moolenaar xo_emit("{d:queues/%-8.8s}{e:queue-len/%hu}" 477ade9ccfeSMarcel Moolenaar "{e:max-queue-len/%hu} ", 478ade9ccfeSMarcel Moolenaar buf1, xinpcb->qlen, xinpcb->maxqlen); 47974fd40c9SRandall Stewart } 4802e34c19bSMichael Tuexen 4812e34c19bSMichael Tuexen offset_laddr = *offset; 4822e34c19bSMichael Tuexen process_closed = 0; 483ade9ccfeSMarcel Moolenaar 484ade9ccfeSMarcel Moolenaar xo_open_list("local-address"); 4852e34c19bSMichael Tuexen retry: 48674fd40c9SRandall Stewart while (*offset < buflen) { 48774fd40c9SRandall Stewart xladdr = (struct xsctp_laddr *)(buf + *offset); 48874fd40c9SRandall Stewart *offset += sizeof(struct xsctp_laddr); 4892e34c19bSMichael Tuexen if (xladdr->last) { 4902e34c19bSMichael Tuexen if (aflag && !Lflag && (xladdr_total == 0) && process_closed) { 491ade9ccfeSMarcel Moolenaar xo_open_instance("local-address"); 492ade9ccfeSMarcel Moolenaar 493ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} " 494ade9ccfeSMarcel Moolenaar "{:type/%-5.5s/%s} ", pname, tname); 4952e34c19bSMichael Tuexen if (Wflag) { 496ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-91.91s/%s} " 497ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 4982e34c19bSMichael Tuexen } else { 499ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45.45s/%s} " 500ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 5012e34c19bSMichael Tuexen } 502ade9ccfeSMarcel Moolenaar xo_close_instance("local-address"); 5032e34c19bSMichael Tuexen } 5042e34c19bSMichael Tuexen if (process_closed || is_listening) { 505ade9ccfeSMarcel Moolenaar xo_emit("\n"); 5062e34c19bSMichael Tuexen } 50774fd40c9SRandall Stewart break; 5082e34c19bSMichael Tuexen } 50974fd40c9SRandall Stewart 5102e34c19bSMichael Tuexen if (!Lflag && !is_listening && !process_closed) 51174fd40c9SRandall Stewart continue; 51274fd40c9SRandall Stewart 513ade9ccfeSMarcel Moolenaar xo_open_instance("local-address"); 514ade9ccfeSMarcel Moolenaar 5152e34c19bSMichael Tuexen if (xladdr_total == 0) { 516ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ", 517ade9ccfeSMarcel Moolenaar pname, tname); 5182e34c19bSMichael Tuexen } else { 519ade9ccfeSMarcel Moolenaar xo_emit("\n"); 520ade9ccfeSMarcel Moolenaar xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ", 521ade9ccfeSMarcel Moolenaar " "); 52274fd40c9SRandall Stewart } 523ade9ccfeSMarcel Moolenaar sctp_print_address("local", &(xladdr->address), 5242e34c19bSMichael Tuexen htons(xinpcb->local_port), numeric_port); 5252e34c19bSMichael Tuexen if (aflag && !Lflag && xladdr_total == 0) { 5262e34c19bSMichael Tuexen if (Wflag) { 5272e34c19bSMichael Tuexen if (process_closed) { 528ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45.45s} " 529ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 5302e34c19bSMichael Tuexen } else { 531ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45.45s} " 532ade9ccfeSMarcel Moolenaar "{:state:LISTEN}", " "); 5332e34c19bSMichael Tuexen } 5342e34c19bSMichael Tuexen } else { 5352e34c19bSMichael Tuexen if (process_closed) { 536ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-22.22s} " 537ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 5382e34c19bSMichael Tuexen } else { 539ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-22.22s} " 540ade9ccfeSMarcel Moolenaar "{:state/LISTEN}", " "); 5412e34c19bSMichael Tuexen } 5422e34c19bSMichael Tuexen } 5432e34c19bSMichael Tuexen } 54474fd40c9SRandall Stewart xladdr_total++; 545ade9ccfeSMarcel Moolenaar xo_close_instance("local-address"); 54674fd40c9SRandall Stewart } 54774fd40c9SRandall Stewart 54874fd40c9SRandall Stewart xstcb = (struct xsctp_tcb *)(buf + *offset); 54974fd40c9SRandall Stewart *offset += sizeof(struct xsctp_tcb); 5502e34c19bSMichael Tuexen if (aflag && (xladdr_total == 0) && xstcb->last && !process_closed) { 5512e34c19bSMichael Tuexen process_closed = 1; 5522e34c19bSMichael Tuexen *offset = offset_laddr; 5532e34c19bSMichael Tuexen goto retry; 5542e34c19bSMichael Tuexen } 55574fd40c9SRandall Stewart while (xstcb->last == 0 && *offset < buflen) { 556ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ", 557ade9ccfeSMarcel Moolenaar pname, tname); 5582e34c19bSMichael Tuexen sctp_process_tcb(xstcb, buf, buflen, offset, &indent); 55974fd40c9SRandall Stewart indent++; 56074fd40c9SRandall Stewart xstcb = (struct xsctp_tcb *)(buf + *offset); 56174fd40c9SRandall Stewart *offset += sizeof(struct xsctp_tcb); 56274fd40c9SRandall Stewart } 563ade9ccfeSMarcel Moolenaar 564ade9ccfeSMarcel Moolenaar xo_close_list("local-address"); 56574fd40c9SRandall Stewart } 56674fd40c9SRandall Stewart 56774fd40c9SRandall Stewart /* 56874fd40c9SRandall Stewart * Print a summary of SCTP connections related to an Internet 56974fd40c9SRandall Stewart * protocol. 57074fd40c9SRandall Stewart */ 57174fd40c9SRandall Stewart void 572feda1a43SJohn Baldwin sctp_protopr(u_long off __unused, 573321ae07fSPhilippe Charnier const char *name __unused, int af1 __unused, int proto) 57474fd40c9SRandall Stewart { 57574fd40c9SRandall Stewart char *buf; 57674fd40c9SRandall Stewart const char *mibvar = "net.inet.sctp.assoclist"; 57704b764d8SXin LI size_t offset = 0; 57874fd40c9SRandall Stewart size_t len = 0; 57974fd40c9SRandall Stewart struct xsctp_inpcb *xinpcb; 58074fd40c9SRandall Stewart 58174fd40c9SRandall Stewart if (proto != IPPROTO_SCTP) 58274fd40c9SRandall Stewart return; 58374fd40c9SRandall Stewart 58474fd40c9SRandall Stewart if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { 58574fd40c9SRandall Stewart if (errno != ENOENT) 586ade9ccfeSMarcel Moolenaar xo_warn("sysctl: %s", mibvar); 58774fd40c9SRandall Stewart return; 58874fd40c9SRandall Stewart } 589ef1cb629SMarcelo Araujo if ((buf = malloc(len)) == NULL) { 590ade9ccfeSMarcel Moolenaar xo_warnx("malloc %lu bytes", (u_long)len); 59174fd40c9SRandall Stewart return; 59274fd40c9SRandall Stewart } 59374fd40c9SRandall Stewart if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { 594ade9ccfeSMarcel Moolenaar xo_warn("sysctl: %s", mibvar); 59574fd40c9SRandall Stewart free(buf); 59674fd40c9SRandall Stewart return; 59774fd40c9SRandall Stewart } 59874fd40c9SRandall Stewart 59974fd40c9SRandall Stewart xinpcb = (struct xsctp_inpcb *)(buf + offset); 60074fd40c9SRandall Stewart offset += sizeof(struct xsctp_inpcb); 60174fd40c9SRandall Stewart while (xinpcb->last == 0 && offset < len) { 6022e34c19bSMichael Tuexen sctp_process_inpcb(xinpcb, buf, (const size_t)len, 60374fd40c9SRandall Stewart &offset); 60474fd40c9SRandall Stewart 60574fd40c9SRandall Stewart xinpcb = (struct xsctp_inpcb *)(buf + offset); 60674fd40c9SRandall Stewart offset += sizeof(struct xsctp_inpcb); 60774fd40c9SRandall Stewart } 60874fd40c9SRandall Stewart 60974fd40c9SRandall Stewart free(buf); 61074fd40c9SRandall Stewart } 61174fd40c9SRandall Stewart 61274fd40c9SRandall Stewart static void 61374fd40c9SRandall Stewart sctp_statesprint(uint32_t state) 61474fd40c9SRandall Stewart { 61574fd40c9SRandall Stewart int idx; 61674fd40c9SRandall Stewart 61774fd40c9SRandall Stewart switch (state) { 6180835304fSMichael Tuexen case SCTP_CLOSED: 6190835304fSMichael Tuexen idx = NETSTAT_SCTP_STATES_CLOSED; 6200835304fSMichael Tuexen break; 6210835304fSMichael Tuexen case SCTP_BOUND: 6220835304fSMichael Tuexen idx = NETSTAT_SCTP_STATES_BOUND; 6230835304fSMichael Tuexen break; 6240835304fSMichael Tuexen case SCTP_LISTEN: 6250835304fSMichael Tuexen idx = NETSTAT_SCTP_STATES_LISTEN; 6260835304fSMichael Tuexen break; 6270835304fSMichael Tuexen case SCTP_COOKIE_WAIT: 62874fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_COOKIE_WAIT; 62974fd40c9SRandall Stewart break; 6300835304fSMichael Tuexen case SCTP_COOKIE_ECHOED: 63174fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_COOKIE_ECHOED; 63274fd40c9SRandall Stewart break; 6330835304fSMichael Tuexen case SCTP_ESTABLISHED: 63474fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_ESTABLISHED; 63574fd40c9SRandall Stewart break; 6360835304fSMichael Tuexen case SCTP_SHUTDOWN_SENT: 63774fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_SENT; 63874fd40c9SRandall Stewart break; 6390835304fSMichael Tuexen case SCTP_SHUTDOWN_RECEIVED: 64074fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED; 64174fd40c9SRandall Stewart break; 6420835304fSMichael Tuexen case SCTP_SHUTDOWN_ACK_SENT: 64374fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT; 64474fd40c9SRandall Stewart break; 6450835304fSMichael Tuexen case SCTP_SHUTDOWN_PENDING: 64674fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING; 64774fd40c9SRandall Stewart break; 64874fd40c9SRandall Stewart default: 649ade9ccfeSMarcel Moolenaar xo_emit("UNKNOWN {:state/0x%08x}", state); 65074fd40c9SRandall Stewart return; 65174fd40c9SRandall Stewart } 65274fd40c9SRandall Stewart 653ade9ccfeSMarcel Moolenaar xo_emit("{:state/%s}", sctpstates[idx]); 65474fd40c9SRandall Stewart } 65574fd40c9SRandall Stewart 65674fd40c9SRandall Stewart /* 65774fd40c9SRandall Stewart * Dump SCTP statistics structure. 65874fd40c9SRandall Stewart */ 65974fd40c9SRandall Stewart void 660feda1a43SJohn Baldwin sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 66174fd40c9SRandall Stewart { 6629eddb899SMark Johnston struct sctpstat sctpstat; 66374fd40c9SRandall Stewart 6649eddb899SMark Johnston if (fetch_stats("net.inet.sctp.stats", off, &sctpstat, 6659eddb899SMark Johnston sizeof(sctpstat), kread) != 0) 66674fd40c9SRandall Stewart return; 66774fd40c9SRandall Stewart 668ade9ccfeSMarcel Moolenaar xo_open_container(name); 669ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 67074fd40c9SRandall Stewart 67174fd40c9SRandall Stewart #define p(f, m) if (sctpstat.f || sflag <= 1) \ 672ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)sctpstat.f, plural(sctpstat.f)) 67374fd40c9SRandall Stewart #define p1a(f, m) if (sctpstat.f || sflag <= 1) \ 674ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)sctpstat.f) 67574fd40c9SRandall Stewart 67674fd40c9SRandall Stewart /* 67774fd40c9SRandall Stewart * input statistics 67874fd40c9SRandall Stewart */ 679ade9ccfeSMarcel Moolenaar p(sctps_recvpackets, "\t{:received-packets/%ju} " 680ade9ccfeSMarcel Moolenaar "{N:/input packet%s}\n"); 681ade9ccfeSMarcel Moolenaar p(sctps_recvdatagrams, "\t\t{:received-datagrams/%ju} " 682ade9ccfeSMarcel Moolenaar "{N:/datagram%s}\n"); 683ade9ccfeSMarcel Moolenaar p(sctps_recvpktwithdata, "\t\t{:received-with-data/%ju} " 684ade9ccfeSMarcel Moolenaar "{N:/packet%s that had data}\n"); 685ade9ccfeSMarcel Moolenaar p(sctps_recvsacks, "\t\t{:received-sack-chunks/%ju} " 686ade9ccfeSMarcel Moolenaar "{N:/input SACK chunk%s}\n"); 687ade9ccfeSMarcel Moolenaar p(sctps_recvdata, "\t\t{:received-data-chunks/%ju} " 688ade9ccfeSMarcel Moolenaar "{N:/input DATA chunk%s}\n"); 689ade9ccfeSMarcel Moolenaar p(sctps_recvdupdata, "\t\t{:received-duplicate-data-chunks/%ju} " 690ade9ccfeSMarcel Moolenaar "{N:/duplicate DATA chunk%s}\n"); 691ade9ccfeSMarcel Moolenaar p(sctps_recvheartbeat, "\t\t{:received-hb-chunks/%ju} " 692ade9ccfeSMarcel Moolenaar "{N:/input HB chunk%s}\n"); 693ade9ccfeSMarcel Moolenaar p(sctps_recvheartbeatack, "\t\t{:received-hb-ack-chunks/%ju} " 694ade9ccfeSMarcel Moolenaar "{N:/HB-ACK chunk%s}\n"); 695ade9ccfeSMarcel Moolenaar p(sctps_recvecne, "\t\t{:received-ecne-chunks/%ju} " 696ade9ccfeSMarcel Moolenaar "{N:/input ECNE chunk%s}\n"); 697ade9ccfeSMarcel Moolenaar p(sctps_recvauth, "\t\t{:received-auth-chunks/%ju} " 698ade9ccfeSMarcel Moolenaar "{N:/input AUTH chunk%s}\n"); 699ade9ccfeSMarcel Moolenaar p(sctps_recvauthmissing, "\t\t{:dropped-missing-auth/%ju} " 700ade9ccfeSMarcel Moolenaar "{N:/chunk%s missing AUTH}\n"); 701ade9ccfeSMarcel Moolenaar p(sctps_recvivalhmacid, "\t\t{:dropped-invalid-hmac/%ju} " 702ade9ccfeSMarcel Moolenaar "{N:/invalid HMAC id%s received}\n"); 703ade9ccfeSMarcel Moolenaar p(sctps_recvivalkeyid, "\t\t{:dropped-invalid-secret/%ju} " 704ade9ccfeSMarcel Moolenaar "{N:/invalid secret id%s received}\n"); 705ade9ccfeSMarcel Moolenaar p1a(sctps_recvauthfailed, "\t\t{:dropped-auth-failed/%ju} " 706ade9ccfeSMarcel Moolenaar "{N:/auth failed}\n"); 707ade9ccfeSMarcel Moolenaar p1a(sctps_recvexpress, "\t\t{:received-fast-path/%ju} " 708ade9ccfeSMarcel Moolenaar "{N:/fast path receives all one chunk}\n"); 709ade9ccfeSMarcel Moolenaar p1a(sctps_recvexpressm, "\t\t{:receives-fast-path-multipart/%ju} " 710ade9ccfeSMarcel Moolenaar "{N:/fast path multi-part data}\n"); 71174fd40c9SRandall Stewart 71274fd40c9SRandall Stewart /* 71374fd40c9SRandall Stewart * output statistics 71474fd40c9SRandall Stewart */ 715ade9ccfeSMarcel Moolenaar p(sctps_sendpackets, "\t{:sent-packets/%ju} " 716ade9ccfeSMarcel Moolenaar "{N:/output packet%s}\n"); 717ade9ccfeSMarcel Moolenaar p(sctps_sendsacks, "\t\t{:sent-sacks/%ju} " 718ade9ccfeSMarcel Moolenaar "{N:/output SACK%s}\n"); 719ade9ccfeSMarcel Moolenaar p(sctps_senddata, "\t\t{:sent-data-chunks/%ju} " 720ade9ccfeSMarcel Moolenaar "{N:/output DATA chunk%s}\n"); 721ade9ccfeSMarcel Moolenaar p(sctps_sendretransdata, "\t\t{:sent-retransmitted-data-chunks/%ju} " 722ade9ccfeSMarcel Moolenaar "{N:/retransmitted DATA chunk%s}\n"); 723ade9ccfeSMarcel Moolenaar p(sctps_sendfastretrans, "\t\t" 724ade9ccfeSMarcel Moolenaar "{:sent-fast-retransmitted-data-chunks/%ju} " 725ade9ccfeSMarcel Moolenaar "{N:/fast retransmitted DATA chunk%s}\n"); 726ade9ccfeSMarcel Moolenaar p(sctps_sendmultfastretrans, "\t\t" 727ade9ccfeSMarcel Moolenaar "{:sent-fast-retransmitted-data-chunk-multiple-times/%ju} " 728ade9ccfeSMarcel Moolenaar "{N:/FR'%s that happened more than once to same chunk}\n"); 729ade9ccfeSMarcel Moolenaar p(sctps_sendheartbeat, "\t\t{:sent-hb-chunks/%ju} " 730ade9ccfeSMarcel Moolenaar "{N:/output HB chunk%s}\n"); 731ade9ccfeSMarcel Moolenaar p(sctps_sendecne, "\t\t{:sent-ecne-chunks/%ju} " 732ade9ccfeSMarcel Moolenaar "{N:/output ECNE chunk%s}\n"); 733ade9ccfeSMarcel Moolenaar p(sctps_sendauth, "\t\t{:sent-auth-chunks/%ju} " 734ade9ccfeSMarcel Moolenaar "{N:/output AUTH chunk%s}\n"); 735ade9ccfeSMarcel Moolenaar p1a(sctps_senderrors, "\t\t{:send-errors/%ju} " 736ade9ccfeSMarcel Moolenaar "{N:/ip_output error counter}\n"); 73774fd40c9SRandall Stewart 73874fd40c9SRandall Stewart /* 73974fd40c9SRandall Stewart * PCKDROPREP statistics 74074fd40c9SRandall Stewart */ 741ade9ccfeSMarcel Moolenaar xo_emit("\t{T:Packet drop statistics}:\n"); 742ade9ccfeSMarcel Moolenaar xo_open_container("drop-statistics"); 743ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpfmbox, "\t\t{:middle-box/%ju} " 744ade9ccfeSMarcel Moolenaar "{N:/from middle box}\n"); 745ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpfehos, "\t\t{:end-host/%ju} " 746ade9ccfeSMarcel Moolenaar "{N:/from end host}\n"); 747ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpmbda, "\t\t{:with-data/%ju} " 748ade9ccfeSMarcel Moolenaar "{N:/with data}\n"); 749ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpmbct, "\t\t{:non-data/%ju} " 750ade9ccfeSMarcel Moolenaar "{N:/non-data, non-endhost}\n"); 751ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpbwrpt, "\t\t{:non-endhost/%ju} " 752ade9ccfeSMarcel Moolenaar "{N:/non-endhost, bandwidth rep only}\n"); 753ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpcrupt, "\t\t{:short-header/%ju} " 754ade9ccfeSMarcel Moolenaar "{N:/not enough for chunk header}\n"); 755ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpnedat, "\t\t{:short-data/%ju} " 756ade9ccfeSMarcel Moolenaar "{N:/not enough data to confirm}\n"); 757ade9ccfeSMarcel Moolenaar p1a(sctps_pdrppdbrk, "\t\t{:chunk-break/%ju} " 758ade9ccfeSMarcel Moolenaar "{N:/where process_chunk_drop said break}\n"); 759ade9ccfeSMarcel Moolenaar p1a(sctps_pdrptsnnf, "\t\t{:tsn-not-found/%ju} " 760ade9ccfeSMarcel Moolenaar "{N:/failed to find TSN}\n"); 761ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpdnfnd, "\t\t{:reverse-tsn/%ju} " 762ade9ccfeSMarcel Moolenaar "{N:/attempt reverse TSN lookup}\n"); 763ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpdiwnp, "\t\t{:confirmed-zero-window/%ju} " 764ade9ccfeSMarcel Moolenaar "{N:/e-host confirms zero-rwnd}\n"); 765ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpdizrw, "\t\t{:middle-box-no-space/%ju} " 766ade9ccfeSMarcel Moolenaar "{N:/midbox confirms no space}\n"); 767ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpbadd, "\t\t{:bad-data/%ju} " 768ade9ccfeSMarcel Moolenaar "{N:/data did not match TSN}\n"); 769ade9ccfeSMarcel Moolenaar p(sctps_pdrpmark, "\t\t{:tsn-marked-fast-retransmission/%ju} " 770ade9ccfeSMarcel Moolenaar "{N:/TSN'%s marked for Fast Retran}\n"); 771ade9ccfeSMarcel Moolenaar xo_close_container("drop-statistics"); 77274fd40c9SRandall Stewart 77374fd40c9SRandall Stewart /* 77474fd40c9SRandall Stewart * Timeouts 77574fd40c9SRandall Stewart */ 776ade9ccfeSMarcel Moolenaar xo_emit("\t{T:Timeouts}:\n"); 777ade9ccfeSMarcel Moolenaar xo_open_container("timeouts"); 778ade9ccfeSMarcel Moolenaar p(sctps_timoiterator, "\t\t{:iterator/%ju} " 779ade9ccfeSMarcel Moolenaar "{N:/iterator timer%s fired}\n"); 780ade9ccfeSMarcel Moolenaar p(sctps_timodata, "\t\t{:t3-data/%ju} " 781ade9ccfeSMarcel Moolenaar "{N:/T3 data time out%s}\n"); 782ade9ccfeSMarcel Moolenaar p(sctps_timowindowprobe, "\t\t{:window-probe/%ju} " 783ade9ccfeSMarcel Moolenaar "{N:/window probe (T3) timer%s fired}\n"); 784ade9ccfeSMarcel Moolenaar p(sctps_timoinit, "\t\t{:init-timer/%ju} " 785ade9ccfeSMarcel Moolenaar "{N:/INIT timer%s fired}\n"); 786ade9ccfeSMarcel Moolenaar p(sctps_timosack, "\t\t{:sack-timer/%ju} " 787ade9ccfeSMarcel Moolenaar "{N:/sack timer%s fired}\n"); 788ade9ccfeSMarcel Moolenaar p(sctps_timoshutdown, "\t\t{:shutdown-timer/%ju} " 789ade9ccfeSMarcel Moolenaar "{N:/shutdown timer%s fired}\n"); 790ade9ccfeSMarcel Moolenaar p(sctps_timoheartbeat, "\t\t{:heartbeat-timer/%ju} " 791ade9ccfeSMarcel Moolenaar "{N:/heartbeat timer%s fired}\n"); 792ade9ccfeSMarcel Moolenaar p1a(sctps_timocookie, "\t\t{:cookie-timer/%ju} " 793ade9ccfeSMarcel Moolenaar "{N:/a cookie timeout fired}\n"); 794ade9ccfeSMarcel Moolenaar p1a(sctps_timosecret, "\t\t{:endpoint-changed-cookie/%ju} " 795ade9ccfeSMarcel Moolenaar "{N:/an endpoint changed its cook}ie" 796b8a1761eSRandall Stewart "secret\n"); 797ade9ccfeSMarcel Moolenaar p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} " 798ade9ccfeSMarcel Moolenaar "{N:/PMTU timer%s fired}\n"); 799ade9ccfeSMarcel Moolenaar p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} " 800ade9ccfeSMarcel Moolenaar "{N:/shutdown ack timer%s fired}\n"); 801ade9ccfeSMarcel Moolenaar p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} " 802ade9ccfeSMarcel Moolenaar "{N:/shutdown guard timer%s fired}\n"); 803ade9ccfeSMarcel Moolenaar p(sctps_timostrmrst, "\t\t{:stream-reset-timer/%ju} " 804ade9ccfeSMarcel Moolenaar "{N:/stream reset timer%s fired}\n"); 805ade9ccfeSMarcel Moolenaar p(sctps_timoearlyfr, "\t\t{:early-fast-retransmission-timer/%ju} " 806ade9ccfeSMarcel Moolenaar "{N:/early FR timer%s fired}\n"); 807ade9ccfeSMarcel Moolenaar p1a(sctps_timoasconf, "\t\t{:asconf-timer/%ju} " 808ade9ccfeSMarcel Moolenaar "{N:/an asconf timer fired}\n"); 809ade9ccfeSMarcel Moolenaar p1a(sctps_timoautoclose, "\t\t{:auto-close-timer/%ju} " 810ade9ccfeSMarcel Moolenaar "{N:/auto close timer fired}\n"); 811ade9ccfeSMarcel Moolenaar p(sctps_timoassockill, "\t\t{:asoc-free-timer/%ju} " 812ade9ccfeSMarcel Moolenaar "{N:/asoc free timer%s expired}\n"); 813ade9ccfeSMarcel Moolenaar p(sctps_timoinpkill, "\t\t{:input-free-timer/%ju} " 814ade9ccfeSMarcel Moolenaar "{N:/inp free timer%s expired}\n"); 815ade9ccfeSMarcel Moolenaar xo_close_container("timeouts"); 81674fd40c9SRandall Stewart 81774fd40c9SRandall Stewart #if 0 81874fd40c9SRandall Stewart /* 81974fd40c9SRandall Stewart * Early fast retransmission counters 82074fd40c9SRandall Stewart */ 821e5221e8bSRandall Stewart p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n"); 822e5221e8bSRandall Stewart p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n"); 823e5221e8bSRandall Stewart p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n"); 824e5221e8bSRandall Stewart p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n"); 825e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n"); 826e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n"); 827e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n"); 828e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n"); 829e5221e8bSRandall Stewart p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n"); 830e5221e8bSRandall Stewart p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n"); 831e5221e8bSRandall Stewart p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n"); 83274fd40c9SRandall Stewart #endif 83374fd40c9SRandall Stewart 83474fd40c9SRandall Stewart /* 83574fd40c9SRandall Stewart * Others 83674fd40c9SRandall Stewart */ 837ade9ccfeSMarcel Moolenaar p1a(sctps_hdrops, "\t{:dropped-too-short/%ju} " 838ade9ccfeSMarcel Moolenaar "{N:/packet shorter than header}\n"); 839ade9ccfeSMarcel Moolenaar p1a(sctps_badsum, "\t{:dropped-bad-checksum/%ju} " 840ade9ccfeSMarcel Moolenaar "{N:/checksum error}\n"); 841ade9ccfeSMarcel Moolenaar p1a(sctps_noport, "\t{:dropped-no-endpoint/%ju} " 842ade9ccfeSMarcel Moolenaar "{N:/no endpoint for port}\n"); 843ade9ccfeSMarcel Moolenaar p1a(sctps_badvtag, "\t{:dropped-bad-v-tag/%ju} " 844ade9ccfeSMarcel Moolenaar "{N:/bad v-tag}\n"); 845ade9ccfeSMarcel Moolenaar p1a(sctps_badsid, "\t{:dropped-bad-sid/%ju} " 846ade9ccfeSMarcel Moolenaar "{N:/bad SID}\n"); 847ade9ccfeSMarcel Moolenaar p1a(sctps_nomem, "\t{:dropped-no-memory/%ju} " 848ade9ccfeSMarcel Moolenaar "{N:/no memory}\n"); 849ade9ccfeSMarcel Moolenaar p1a(sctps_fastretransinrtt, "\t{:multiple-fast-retransmits-in-rtt/%ju} " 850ade9ccfeSMarcel Moolenaar "{N:/number of multiple FR in a RT}T window\n"); 85174fd40c9SRandall Stewart #if 0 852e5221e8bSRandall Stewart p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n"); 85374fd40c9SRandall Stewart #endif 854ade9ccfeSMarcel Moolenaar p1a(sctps_naglesent, "\t{:rfc813-sent/%ju} " 855ade9ccfeSMarcel Moolenaar "{N:/RFC813 allowed sending}\n"); 856ade9ccfeSMarcel Moolenaar p1a(sctps_naglequeued, "\t{:rfc813-queued/%ju} " 857ade9ccfeSMarcel Moolenaar "{N:/RFC813 does not allow sending}\n"); 858ade9ccfeSMarcel Moolenaar p1a(sctps_maxburstqueued, "\t{:max-burst-queued/%ju} " 859ade9ccfeSMarcel Moolenaar "{N:/times max burst prohibited sending}\n"); 860ade9ccfeSMarcel Moolenaar p1a(sctps_ifnomemqueued, "\t{:no-memory-in-interface/%ju} " 861ade9ccfeSMarcel Moolenaar "{N:/look ahead tells us no memory in interface}\n"); 862ade9ccfeSMarcel Moolenaar p(sctps_windowprobed, "\t{:sent-window-probes/%ju} " 863ade9ccfeSMarcel Moolenaar "{N:/number%s of window probes sent}\n"); 864ade9ccfeSMarcel Moolenaar p(sctps_lowlevelerr, "\t{:low-level-err/%ju} " 865ade9ccfeSMarcel Moolenaar "{N:/time%s an output error to clamp down on next user send}\n"); 866ade9ccfeSMarcel Moolenaar p(sctps_lowlevelerrusr, "\t{:low-level-user-error/%ju} " 867ade9ccfeSMarcel Moolenaar "{N:/time%s sctp_senderrors were caused from a user}\n"); 868ade9ccfeSMarcel Moolenaar p(sctps_datadropchklmt, "\t{:dropped-chunk-limit/%ju} " 869ade9ccfeSMarcel Moolenaar "{N:/number of in data drop%s due to chunk limit reached}\n"); 870ade9ccfeSMarcel Moolenaar p(sctps_datadroprwnd, "\t{:dropped-rwnd-limit/%ju} " 871ade9ccfeSMarcel Moolenaar "{N:/number of in data drop%s due to rwnd limit reached}\n"); 872ade9ccfeSMarcel Moolenaar p(sctps_ecnereducedcwnd, "\t{:ecn-reduced-cwnd/%ju} " 873ade9ccfeSMarcel Moolenaar "{N:/time%s a ECN reduced the cwnd}\n"); 874ade9ccfeSMarcel Moolenaar p1a(sctps_vtagexpress, "\t{:v-tag-express-lookup/%ju} " 875ade9ccfeSMarcel Moolenaar "{N:/used express lookup via vtag}\n"); 876ade9ccfeSMarcel Moolenaar p1a(sctps_vtagbogus, "\t{:v-tag-collision/%ju} " 877ade9ccfeSMarcel Moolenaar "{N:/collision in express lookup}\n"); 878ade9ccfeSMarcel Moolenaar p(sctps_primary_randry, "\t{:sender-ran-dry/%ju} " 879ade9ccfeSMarcel Moolenaar "{N:/time%s the sender ran dry of user data on primary}\n"); 880ade9ccfeSMarcel Moolenaar p1a(sctps_cmt_randry, "\t{:cmt-ran-dry/%ju} " 881ade9ccfeSMarcel Moolenaar "{N:/same for above}\n"); 882ade9ccfeSMarcel Moolenaar p(sctps_slowpath_sack, "\t{:slow-path-sack/%ju} " 883ade9ccfeSMarcel Moolenaar "{N:/sack%s the slow way}\n"); 884ade9ccfeSMarcel Moolenaar p(sctps_wu_sacks_sent, "\t{:sent-window-update-only-sack/%ju} " 885ade9ccfeSMarcel Moolenaar "{N:/window update only sack%s sent}\n"); 886ade9ccfeSMarcel Moolenaar p(sctps_sends_with_flags, "\t{:sent-with-sinfo/%ju} " 887ade9ccfeSMarcel Moolenaar "{N:/send%s with sinfo_flags !=0}\n"); 888ade9ccfeSMarcel Moolenaar p(sctps_sends_with_unord, "\t{:sent-with-unordered/%ju} " 889ade9ccfeSMarcel Moolenaar "{N:/unordered send%s}\n"); 890ade9ccfeSMarcel Moolenaar p(sctps_sends_with_eof, "\t{:sent-with-eof/%ju} " 891ade9ccfeSMarcel Moolenaar "{N:/send%s with EOF flag set}\n"); 892ade9ccfeSMarcel Moolenaar p(sctps_sends_with_abort, "\t{:sent-with-abort/%ju} " 893ade9ccfeSMarcel Moolenaar "{N:/send%s with ABORT flag set}\n"); 894ade9ccfeSMarcel Moolenaar p(sctps_protocol_drain_calls, "\t{:protocol-drain-called/%ju} " 895ade9ccfeSMarcel Moolenaar "{N:/time%s protocol drain called}\n"); 896ade9ccfeSMarcel Moolenaar p(sctps_protocol_drains_done, "\t{:protocol-drain/%ju} " 897ade9ccfeSMarcel Moolenaar "{N:/time%s we did a protocol drain}\n"); 898ade9ccfeSMarcel Moolenaar p(sctps_read_peeks, "\t{:read-with-peek/%ju} " 899ade9ccfeSMarcel Moolenaar "{N:/time%s recv was called with peek}\n"); 900ade9ccfeSMarcel Moolenaar p(sctps_cached_chk, "\t{:cached-chunks/%ju} " 901ade9ccfeSMarcel Moolenaar "{N:/cached chunk%s used}\n"); 902ade9ccfeSMarcel Moolenaar p1a(sctps_cached_strmoq, "\t{:cached-output-queue-used/%ju} " 903ade9ccfeSMarcel Moolenaar "{N:/cached stream oq's used}\n"); 904ade9ccfeSMarcel Moolenaar p(sctps_left_abandon, "\t{:messages-abandoned/%ju} " 905ade9ccfeSMarcel Moolenaar "{N:/unread message%s abandonded by close}\n"); 906ade9ccfeSMarcel Moolenaar p1a(sctps_send_burst_avoid, "\t{:send-burst-avoidance/%ju} " 907ade9ccfeSMarcel Moolenaar "{N:/send burst avoidance, already max burst inflight to net}\n"); 908ade9ccfeSMarcel Moolenaar p1a(sctps_send_cwnd_avoid, "\t{:send-cwnd-avoidance/%ju} " 909ade9ccfeSMarcel Moolenaar "{N:/send cwnd full avoidance, already max burst inflight " 910ade9ccfeSMarcel Moolenaar "to net}\n"); 911ade9ccfeSMarcel Moolenaar p(sctps_fwdtsn_map_over, "\t{:tsn-map-overruns/%ju} " 912ade9ccfeSMarcel Moolenaar "{N:/number of map array over-run%s via fwd-tsn's}\n"); 913b8a1761eSRandall Stewart 914b8a1761eSRandall Stewart #undef p 915b8a1761eSRandall Stewart #undef p1a 916ade9ccfeSMarcel Moolenaar xo_close_container(name); 91774fd40c9SRandall Stewart } 91874fd40c9SRandall Stewart 91974fd40c9SRandall Stewart #endif /* SCTP */ 920