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); 352fcc0131fSMarcelo 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); 450*ca658db3SMichael Tuexen if ((!aflag && is_listening) || 451*ca658db3SMichael Tuexen (Lflag && !is_listening)) { 45293f8854cSDimitry Andric sctp_skip_xinpcb_ifneed(buf, buflen, offset); 45374fd40c9SRandall Stewart return; 45474fd40c9SRandall Stewart } 45574fd40c9SRandall Stewart 4562e34c19bSMichael Tuexen if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) { 4572e34c19bSMichael Tuexen /* Can't distinguish between sctp46 and sctp6 */ 4582e34c19bSMichael Tuexen pname = "sctp46"; 4592e34c19bSMichael Tuexen } else { 4602e34c19bSMichael Tuexen pname = "sctp4"; 4612e34c19bSMichael Tuexen } 46274fd40c9SRandall Stewart 46374fd40c9SRandall Stewart if (xinpcb->flags & SCTP_PCB_FLAGS_TCPTYPE) 46474fd40c9SRandall Stewart tname = "1to1"; 46574fd40c9SRandall Stewart else if (xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE) 46674fd40c9SRandall Stewart tname = "1toN"; 46774fd40c9SRandall Stewart else 4682e34c19bSMichael Tuexen tname = "????"; 46974fd40c9SRandall Stewart 47074fd40c9SRandall Stewart if (Lflag) { 4717325dfbbSAlfred Perlstein char buf1[22]; 47274fd40c9SRandall Stewart 4737325dfbbSAlfred Perlstein snprintf(buf1, sizeof buf1, "%u/%u", 4747325dfbbSAlfred Perlstein xinpcb->qlen, xinpcb->maxqlen); 475ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ", 476ade9ccfeSMarcel Moolenaar pname, tname); 477ade9ccfeSMarcel Moolenaar xo_emit("{d:queues/%-8.8s}{e:queue-len/%hu}" 478ade9ccfeSMarcel Moolenaar "{e:max-queue-len/%hu} ", 479ade9ccfeSMarcel Moolenaar buf1, xinpcb->qlen, xinpcb->maxqlen); 48074fd40c9SRandall Stewart } 4812e34c19bSMichael Tuexen 4822e34c19bSMichael Tuexen offset_laddr = *offset; 4832e34c19bSMichael Tuexen process_closed = 0; 484ade9ccfeSMarcel Moolenaar 485ade9ccfeSMarcel Moolenaar xo_open_list("local-address"); 4862e34c19bSMichael Tuexen retry: 48774fd40c9SRandall Stewart while (*offset < buflen) { 48874fd40c9SRandall Stewart xladdr = (struct xsctp_laddr *)(buf + *offset); 48974fd40c9SRandall Stewart *offset += sizeof(struct xsctp_laddr); 4902e34c19bSMichael Tuexen if (xladdr->last) { 4912e34c19bSMichael Tuexen if (aflag && !Lflag && (xladdr_total == 0) && process_closed) { 492ade9ccfeSMarcel Moolenaar xo_open_instance("local-address"); 493ade9ccfeSMarcel Moolenaar 494ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} " 495ade9ccfeSMarcel Moolenaar "{:type/%-5.5s/%s} ", pname, tname); 4962e34c19bSMichael Tuexen if (Wflag) { 497ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-91.91s/%s} " 498ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 4992e34c19bSMichael Tuexen } else { 500ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45.45s/%s} " 501ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 5022e34c19bSMichael Tuexen } 503ade9ccfeSMarcel Moolenaar xo_close_instance("local-address"); 5042e34c19bSMichael Tuexen } 5052e34c19bSMichael Tuexen if (process_closed || is_listening) { 506ade9ccfeSMarcel Moolenaar xo_emit("\n"); 5072e34c19bSMichael Tuexen } 50874fd40c9SRandall Stewart break; 5092e34c19bSMichael Tuexen } 51074fd40c9SRandall Stewart 5112e34c19bSMichael Tuexen if (!Lflag && !is_listening && !process_closed) 51274fd40c9SRandall Stewart continue; 51374fd40c9SRandall Stewart 514ade9ccfeSMarcel Moolenaar xo_open_instance("local-address"); 515ade9ccfeSMarcel Moolenaar 5162e34c19bSMichael Tuexen if (xladdr_total == 0) { 517*ca658db3SMichael Tuexen if (!Lflag) { 518*ca658db3SMichael Tuexen xo_emit("{:protocol/%-6.6s/%s} " 519*ca658db3SMichael Tuexen "{:type/%-5.5s/%s} ", pname, tname); 520*ca658db3SMichael Tuexen } 5212e34c19bSMichael Tuexen } else { 522ade9ccfeSMarcel Moolenaar xo_emit("\n"); 523ade9ccfeSMarcel Moolenaar xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ", 524ade9ccfeSMarcel Moolenaar " "); 52574fd40c9SRandall Stewart } 526ade9ccfeSMarcel Moolenaar sctp_print_address("local", &(xladdr->address), 5272e34c19bSMichael Tuexen htons(xinpcb->local_port), numeric_port); 5282e34c19bSMichael Tuexen if (aflag && !Lflag && xladdr_total == 0) { 5292e34c19bSMichael Tuexen if (Wflag) { 5302e34c19bSMichael Tuexen if (process_closed) { 531ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45.45s} " 532ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 5332e34c19bSMichael Tuexen } else { 534ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-45.45s} " 535282d1dd7SMichael Tuexen "{:state/LISTEN}", " "); 5362e34c19bSMichael Tuexen } 5372e34c19bSMichael Tuexen } else { 5382e34c19bSMichael Tuexen if (process_closed) { 539ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-22.22s} " 540ade9ccfeSMarcel Moolenaar "{:state/CLOSED}", " "); 5412e34c19bSMichael Tuexen } else { 542ade9ccfeSMarcel Moolenaar xo_emit("{P:/%-22.22s} " 543ade9ccfeSMarcel Moolenaar "{:state/LISTEN}", " "); 5442e34c19bSMichael Tuexen } 5452e34c19bSMichael Tuexen } 5462e34c19bSMichael Tuexen } 54774fd40c9SRandall Stewart xladdr_total++; 548ade9ccfeSMarcel Moolenaar xo_close_instance("local-address"); 54974fd40c9SRandall Stewart } 55074fd40c9SRandall Stewart 55174fd40c9SRandall Stewart xstcb = (struct xsctp_tcb *)(buf + *offset); 55274fd40c9SRandall Stewart *offset += sizeof(struct xsctp_tcb); 5532e34c19bSMichael Tuexen if (aflag && (xladdr_total == 0) && xstcb->last && !process_closed) { 5542e34c19bSMichael Tuexen process_closed = 1; 5552e34c19bSMichael Tuexen *offset = offset_laddr; 5562e34c19bSMichael Tuexen goto retry; 5572e34c19bSMichael Tuexen } 55874fd40c9SRandall Stewart while (xstcb->last == 0 && *offset < buflen) { 559ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ", 560ade9ccfeSMarcel Moolenaar pname, tname); 5612e34c19bSMichael Tuexen sctp_process_tcb(xstcb, buf, buflen, offset, &indent); 56274fd40c9SRandall Stewart indent++; 56374fd40c9SRandall Stewart xstcb = (struct xsctp_tcb *)(buf + *offset); 56474fd40c9SRandall Stewart *offset += sizeof(struct xsctp_tcb); 56574fd40c9SRandall Stewart } 566ade9ccfeSMarcel Moolenaar 567ade9ccfeSMarcel Moolenaar xo_close_list("local-address"); 56874fd40c9SRandall Stewart } 56974fd40c9SRandall Stewart 57074fd40c9SRandall Stewart /* 57174fd40c9SRandall Stewart * Print a summary of SCTP connections related to an Internet 57274fd40c9SRandall Stewart * protocol. 57374fd40c9SRandall Stewart */ 57474fd40c9SRandall Stewart void 575feda1a43SJohn Baldwin sctp_protopr(u_long off __unused, 576321ae07fSPhilippe Charnier const char *name __unused, int af1 __unused, int proto) 57774fd40c9SRandall Stewart { 57874fd40c9SRandall Stewart char *buf; 57974fd40c9SRandall Stewart const char *mibvar = "net.inet.sctp.assoclist"; 58004b764d8SXin LI size_t offset = 0; 58174fd40c9SRandall Stewart size_t len = 0; 58274fd40c9SRandall Stewart struct xsctp_inpcb *xinpcb; 58374fd40c9SRandall Stewart 58474fd40c9SRandall Stewart if (proto != IPPROTO_SCTP) 58574fd40c9SRandall Stewart return; 58674fd40c9SRandall Stewart 58774fd40c9SRandall Stewart if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { 58874fd40c9SRandall Stewart if (errno != ENOENT) 589ade9ccfeSMarcel Moolenaar xo_warn("sysctl: %s", mibvar); 59074fd40c9SRandall Stewart return; 59174fd40c9SRandall Stewart } 592ef1cb629SMarcelo Araujo if ((buf = malloc(len)) == NULL) { 593ade9ccfeSMarcel Moolenaar xo_warnx("malloc %lu bytes", (u_long)len); 59474fd40c9SRandall Stewart return; 59574fd40c9SRandall Stewart } 59674fd40c9SRandall Stewart if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { 597ade9ccfeSMarcel Moolenaar xo_warn("sysctl: %s", mibvar); 59874fd40c9SRandall Stewart free(buf); 59974fd40c9SRandall Stewart return; 60074fd40c9SRandall Stewart } 60174fd40c9SRandall Stewart 60274fd40c9SRandall Stewart xinpcb = (struct xsctp_inpcb *)(buf + offset); 60374fd40c9SRandall Stewart offset += sizeof(struct xsctp_inpcb); 60474fd40c9SRandall Stewart while (xinpcb->last == 0 && offset < len) { 6052e34c19bSMichael Tuexen sctp_process_inpcb(xinpcb, buf, (const size_t)len, 60674fd40c9SRandall Stewart &offset); 60774fd40c9SRandall Stewart 60874fd40c9SRandall Stewart xinpcb = (struct xsctp_inpcb *)(buf + offset); 60974fd40c9SRandall Stewart offset += sizeof(struct xsctp_inpcb); 61074fd40c9SRandall Stewart } 61174fd40c9SRandall Stewart 61274fd40c9SRandall Stewart free(buf); 61374fd40c9SRandall Stewart } 61474fd40c9SRandall Stewart 61574fd40c9SRandall Stewart static void 61674fd40c9SRandall Stewart sctp_statesprint(uint32_t state) 61774fd40c9SRandall Stewart { 61874fd40c9SRandall Stewart int idx; 61974fd40c9SRandall Stewart 62074fd40c9SRandall Stewart switch (state) { 6210835304fSMichael Tuexen case SCTP_CLOSED: 6220835304fSMichael Tuexen idx = NETSTAT_SCTP_STATES_CLOSED; 6230835304fSMichael Tuexen break; 6240835304fSMichael Tuexen case SCTP_BOUND: 6250835304fSMichael Tuexen idx = NETSTAT_SCTP_STATES_BOUND; 6260835304fSMichael Tuexen break; 6270835304fSMichael Tuexen case SCTP_LISTEN: 6280835304fSMichael Tuexen idx = NETSTAT_SCTP_STATES_LISTEN; 6290835304fSMichael Tuexen break; 6300835304fSMichael Tuexen case SCTP_COOKIE_WAIT: 63174fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_COOKIE_WAIT; 63274fd40c9SRandall Stewart break; 6330835304fSMichael Tuexen case SCTP_COOKIE_ECHOED: 63474fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_COOKIE_ECHOED; 63574fd40c9SRandall Stewart break; 6360835304fSMichael Tuexen case SCTP_ESTABLISHED: 63774fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_ESTABLISHED; 63874fd40c9SRandall Stewart break; 6390835304fSMichael Tuexen case SCTP_SHUTDOWN_SENT: 64074fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_SENT; 64174fd40c9SRandall Stewart break; 6420835304fSMichael Tuexen case SCTP_SHUTDOWN_RECEIVED: 64374fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED; 64474fd40c9SRandall Stewart break; 6450835304fSMichael Tuexen case SCTP_SHUTDOWN_ACK_SENT: 64674fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT; 64774fd40c9SRandall Stewart break; 6480835304fSMichael Tuexen case SCTP_SHUTDOWN_PENDING: 64974fd40c9SRandall Stewart idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING; 65074fd40c9SRandall Stewart break; 65174fd40c9SRandall Stewart default: 652ade9ccfeSMarcel Moolenaar xo_emit("UNKNOWN {:state/0x%08x}", state); 65374fd40c9SRandall Stewart return; 65474fd40c9SRandall Stewart } 65574fd40c9SRandall Stewart 656ade9ccfeSMarcel Moolenaar xo_emit("{:state/%s}", sctpstates[idx]); 65774fd40c9SRandall Stewart } 65874fd40c9SRandall Stewart 65974fd40c9SRandall Stewart /* 66074fd40c9SRandall Stewart * Dump SCTP statistics structure. 66174fd40c9SRandall Stewart */ 66274fd40c9SRandall Stewart void 663feda1a43SJohn Baldwin sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 66474fd40c9SRandall Stewart { 6659eddb899SMark Johnston struct sctpstat sctpstat; 66674fd40c9SRandall Stewart 6679eddb899SMark Johnston if (fetch_stats("net.inet.sctp.stats", off, &sctpstat, 6689eddb899SMark Johnston sizeof(sctpstat), kread) != 0) 66974fd40c9SRandall Stewart return; 67074fd40c9SRandall Stewart 671ade9ccfeSMarcel Moolenaar xo_open_container(name); 672ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 67374fd40c9SRandall Stewart 67474fd40c9SRandall Stewart #define p(f, m) if (sctpstat.f || sflag <= 1) \ 675ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)sctpstat.f, plural(sctpstat.f)) 67674fd40c9SRandall Stewart #define p1a(f, m) if (sctpstat.f || sflag <= 1) \ 677ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)sctpstat.f) 67874fd40c9SRandall Stewart 67974fd40c9SRandall Stewart /* 68074fd40c9SRandall Stewart * input statistics 68174fd40c9SRandall Stewart */ 682ade9ccfeSMarcel Moolenaar p(sctps_recvpackets, "\t{:received-packets/%ju} " 683ade9ccfeSMarcel Moolenaar "{N:/input packet%s}\n"); 684ade9ccfeSMarcel Moolenaar p(sctps_recvdatagrams, "\t\t{:received-datagrams/%ju} " 685ade9ccfeSMarcel Moolenaar "{N:/datagram%s}\n"); 686ade9ccfeSMarcel Moolenaar p(sctps_recvpktwithdata, "\t\t{:received-with-data/%ju} " 687ade9ccfeSMarcel Moolenaar "{N:/packet%s that had data}\n"); 688ade9ccfeSMarcel Moolenaar p(sctps_recvsacks, "\t\t{:received-sack-chunks/%ju} " 689ade9ccfeSMarcel Moolenaar "{N:/input SACK chunk%s}\n"); 690ade9ccfeSMarcel Moolenaar p(sctps_recvdata, "\t\t{:received-data-chunks/%ju} " 691ade9ccfeSMarcel Moolenaar "{N:/input DATA chunk%s}\n"); 692ade9ccfeSMarcel Moolenaar p(sctps_recvdupdata, "\t\t{:received-duplicate-data-chunks/%ju} " 693ade9ccfeSMarcel Moolenaar "{N:/duplicate DATA chunk%s}\n"); 694ade9ccfeSMarcel Moolenaar p(sctps_recvheartbeat, "\t\t{:received-hb-chunks/%ju} " 695ade9ccfeSMarcel Moolenaar "{N:/input HB chunk%s}\n"); 696ade9ccfeSMarcel Moolenaar p(sctps_recvheartbeatack, "\t\t{:received-hb-ack-chunks/%ju} " 697ade9ccfeSMarcel Moolenaar "{N:/HB-ACK chunk%s}\n"); 698ade9ccfeSMarcel Moolenaar p(sctps_recvecne, "\t\t{:received-ecne-chunks/%ju} " 699ade9ccfeSMarcel Moolenaar "{N:/input ECNE chunk%s}\n"); 700ade9ccfeSMarcel Moolenaar p(sctps_recvauth, "\t\t{:received-auth-chunks/%ju} " 701ade9ccfeSMarcel Moolenaar "{N:/input AUTH chunk%s}\n"); 702ade9ccfeSMarcel Moolenaar p(sctps_recvauthmissing, "\t\t{:dropped-missing-auth/%ju} " 703ade9ccfeSMarcel Moolenaar "{N:/chunk%s missing AUTH}\n"); 704ade9ccfeSMarcel Moolenaar p(sctps_recvivalhmacid, "\t\t{:dropped-invalid-hmac/%ju} " 705ade9ccfeSMarcel Moolenaar "{N:/invalid HMAC id%s received}\n"); 706ade9ccfeSMarcel Moolenaar p(sctps_recvivalkeyid, "\t\t{:dropped-invalid-secret/%ju} " 707ade9ccfeSMarcel Moolenaar "{N:/invalid secret id%s received}\n"); 708ade9ccfeSMarcel Moolenaar p1a(sctps_recvauthfailed, "\t\t{:dropped-auth-failed/%ju} " 709ade9ccfeSMarcel Moolenaar "{N:/auth failed}\n"); 710ade9ccfeSMarcel Moolenaar p1a(sctps_recvexpress, "\t\t{:received-fast-path/%ju} " 711ade9ccfeSMarcel Moolenaar "{N:/fast path receives all one chunk}\n"); 712ade9ccfeSMarcel Moolenaar p1a(sctps_recvexpressm, "\t\t{:receives-fast-path-multipart/%ju} " 713ade9ccfeSMarcel Moolenaar "{N:/fast path multi-part data}\n"); 71474fd40c9SRandall Stewart 71574fd40c9SRandall Stewart /* 71674fd40c9SRandall Stewart * output statistics 71774fd40c9SRandall Stewart */ 718ade9ccfeSMarcel Moolenaar p(sctps_sendpackets, "\t{:sent-packets/%ju} " 719ade9ccfeSMarcel Moolenaar "{N:/output packet%s}\n"); 720ade9ccfeSMarcel Moolenaar p(sctps_sendsacks, "\t\t{:sent-sacks/%ju} " 721ade9ccfeSMarcel Moolenaar "{N:/output SACK%s}\n"); 722ade9ccfeSMarcel Moolenaar p(sctps_senddata, "\t\t{:sent-data-chunks/%ju} " 723ade9ccfeSMarcel Moolenaar "{N:/output DATA chunk%s}\n"); 724ade9ccfeSMarcel Moolenaar p(sctps_sendretransdata, "\t\t{:sent-retransmitted-data-chunks/%ju} " 725ade9ccfeSMarcel Moolenaar "{N:/retransmitted DATA chunk%s}\n"); 726ade9ccfeSMarcel Moolenaar p(sctps_sendfastretrans, "\t\t" 727ade9ccfeSMarcel Moolenaar "{:sent-fast-retransmitted-data-chunks/%ju} " 728ade9ccfeSMarcel Moolenaar "{N:/fast retransmitted DATA chunk%s}\n"); 729ade9ccfeSMarcel Moolenaar p(sctps_sendmultfastretrans, "\t\t" 730ade9ccfeSMarcel Moolenaar "{:sent-fast-retransmitted-data-chunk-multiple-times/%ju} " 731ade9ccfeSMarcel Moolenaar "{N:/FR'%s that happened more than once to same chunk}\n"); 732ade9ccfeSMarcel Moolenaar p(sctps_sendheartbeat, "\t\t{:sent-hb-chunks/%ju} " 733ade9ccfeSMarcel Moolenaar "{N:/output HB chunk%s}\n"); 734ade9ccfeSMarcel Moolenaar p(sctps_sendecne, "\t\t{:sent-ecne-chunks/%ju} " 735ade9ccfeSMarcel Moolenaar "{N:/output ECNE chunk%s}\n"); 736ade9ccfeSMarcel Moolenaar p(sctps_sendauth, "\t\t{:sent-auth-chunks/%ju} " 737ade9ccfeSMarcel Moolenaar "{N:/output AUTH chunk%s}\n"); 738ade9ccfeSMarcel Moolenaar p1a(sctps_senderrors, "\t\t{:send-errors/%ju} " 739ade9ccfeSMarcel Moolenaar "{N:/ip_output error counter}\n"); 74074fd40c9SRandall Stewart 74174fd40c9SRandall Stewart /* 74274fd40c9SRandall Stewart * PCKDROPREP statistics 74374fd40c9SRandall Stewart */ 744ade9ccfeSMarcel Moolenaar xo_emit("\t{T:Packet drop statistics}:\n"); 745ade9ccfeSMarcel Moolenaar xo_open_container("drop-statistics"); 746ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpfmbox, "\t\t{:middle-box/%ju} " 747ade9ccfeSMarcel Moolenaar "{N:/from middle box}\n"); 748ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpfehos, "\t\t{:end-host/%ju} " 749ade9ccfeSMarcel Moolenaar "{N:/from end host}\n"); 750ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpmbda, "\t\t{:with-data/%ju} " 751ade9ccfeSMarcel Moolenaar "{N:/with data}\n"); 752ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpmbct, "\t\t{:non-data/%ju} " 753ade9ccfeSMarcel Moolenaar "{N:/non-data, non-endhost}\n"); 754ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpbwrpt, "\t\t{:non-endhost/%ju} " 755ade9ccfeSMarcel Moolenaar "{N:/non-endhost, bandwidth rep only}\n"); 756ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpcrupt, "\t\t{:short-header/%ju} " 757ade9ccfeSMarcel Moolenaar "{N:/not enough for chunk header}\n"); 758ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpnedat, "\t\t{:short-data/%ju} " 759ade9ccfeSMarcel Moolenaar "{N:/not enough data to confirm}\n"); 760ade9ccfeSMarcel Moolenaar p1a(sctps_pdrppdbrk, "\t\t{:chunk-break/%ju} " 761ade9ccfeSMarcel Moolenaar "{N:/where process_chunk_drop said break}\n"); 762ade9ccfeSMarcel Moolenaar p1a(sctps_pdrptsnnf, "\t\t{:tsn-not-found/%ju} " 763ade9ccfeSMarcel Moolenaar "{N:/failed to find TSN}\n"); 764ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpdnfnd, "\t\t{:reverse-tsn/%ju} " 765ade9ccfeSMarcel Moolenaar "{N:/attempt reverse TSN lookup}\n"); 766ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpdiwnp, "\t\t{:confirmed-zero-window/%ju} " 767ade9ccfeSMarcel Moolenaar "{N:/e-host confirms zero-rwnd}\n"); 768ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpdizrw, "\t\t{:middle-box-no-space/%ju} " 769ade9ccfeSMarcel Moolenaar "{N:/midbox confirms no space}\n"); 770ade9ccfeSMarcel Moolenaar p1a(sctps_pdrpbadd, "\t\t{:bad-data/%ju} " 771ade9ccfeSMarcel Moolenaar "{N:/data did not match TSN}\n"); 772ade9ccfeSMarcel Moolenaar p(sctps_pdrpmark, "\t\t{:tsn-marked-fast-retransmission/%ju} " 773ade9ccfeSMarcel Moolenaar "{N:/TSN'%s marked for Fast Retran}\n"); 774ade9ccfeSMarcel Moolenaar xo_close_container("drop-statistics"); 77574fd40c9SRandall Stewart 77674fd40c9SRandall Stewart /* 77774fd40c9SRandall Stewart * Timeouts 77874fd40c9SRandall Stewart */ 779ade9ccfeSMarcel Moolenaar xo_emit("\t{T:Timeouts}:\n"); 780ade9ccfeSMarcel Moolenaar xo_open_container("timeouts"); 781ade9ccfeSMarcel Moolenaar p(sctps_timoiterator, "\t\t{:iterator/%ju} " 782ade9ccfeSMarcel Moolenaar "{N:/iterator timer%s fired}\n"); 783ade9ccfeSMarcel Moolenaar p(sctps_timodata, "\t\t{:t3-data/%ju} " 784ade9ccfeSMarcel Moolenaar "{N:/T3 data time out%s}\n"); 785ade9ccfeSMarcel Moolenaar p(sctps_timowindowprobe, "\t\t{:window-probe/%ju} " 786ade9ccfeSMarcel Moolenaar "{N:/window probe (T3) timer%s fired}\n"); 787ade9ccfeSMarcel Moolenaar p(sctps_timoinit, "\t\t{:init-timer/%ju} " 788ade9ccfeSMarcel Moolenaar "{N:/INIT timer%s fired}\n"); 789ade9ccfeSMarcel Moolenaar p(sctps_timosack, "\t\t{:sack-timer/%ju} " 790ade9ccfeSMarcel Moolenaar "{N:/sack timer%s fired}\n"); 791ade9ccfeSMarcel Moolenaar p(sctps_timoshutdown, "\t\t{:shutdown-timer/%ju} " 792ade9ccfeSMarcel Moolenaar "{N:/shutdown timer%s fired}\n"); 793ade9ccfeSMarcel Moolenaar p(sctps_timoheartbeat, "\t\t{:heartbeat-timer/%ju} " 794ade9ccfeSMarcel Moolenaar "{N:/heartbeat timer%s fired}\n"); 795ade9ccfeSMarcel Moolenaar p1a(sctps_timocookie, "\t\t{:cookie-timer/%ju} " 796ade9ccfeSMarcel Moolenaar "{N:/a cookie timeout fired}\n"); 797ade9ccfeSMarcel Moolenaar p1a(sctps_timosecret, "\t\t{:endpoint-changed-cookie/%ju} " 798ade9ccfeSMarcel Moolenaar "{N:/an endpoint changed its cook}ie" 799b8a1761eSRandall Stewart "secret\n"); 800ade9ccfeSMarcel Moolenaar p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} " 801ade9ccfeSMarcel Moolenaar "{N:/PMTU timer%s fired}\n"); 802ade9ccfeSMarcel Moolenaar p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} " 803ade9ccfeSMarcel Moolenaar "{N:/shutdown ack timer%s fired}\n"); 804ade9ccfeSMarcel Moolenaar p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} " 805ade9ccfeSMarcel Moolenaar "{N:/shutdown guard timer%s fired}\n"); 806ade9ccfeSMarcel Moolenaar p(sctps_timostrmrst, "\t\t{:stream-reset-timer/%ju} " 807ade9ccfeSMarcel Moolenaar "{N:/stream reset timer%s fired}\n"); 808ade9ccfeSMarcel Moolenaar p(sctps_timoearlyfr, "\t\t{:early-fast-retransmission-timer/%ju} " 809ade9ccfeSMarcel Moolenaar "{N:/early FR timer%s fired}\n"); 810ade9ccfeSMarcel Moolenaar p1a(sctps_timoasconf, "\t\t{:asconf-timer/%ju} " 811ade9ccfeSMarcel Moolenaar "{N:/an asconf timer fired}\n"); 812ade9ccfeSMarcel Moolenaar p1a(sctps_timoautoclose, "\t\t{:auto-close-timer/%ju} " 813ade9ccfeSMarcel Moolenaar "{N:/auto close timer fired}\n"); 814ade9ccfeSMarcel Moolenaar p(sctps_timoassockill, "\t\t{:asoc-free-timer/%ju} " 815ade9ccfeSMarcel Moolenaar "{N:/asoc free timer%s expired}\n"); 816ade9ccfeSMarcel Moolenaar p(sctps_timoinpkill, "\t\t{:input-free-timer/%ju} " 817ade9ccfeSMarcel Moolenaar "{N:/inp free timer%s expired}\n"); 818ade9ccfeSMarcel Moolenaar xo_close_container("timeouts"); 81974fd40c9SRandall Stewart 82074fd40c9SRandall Stewart #if 0 82174fd40c9SRandall Stewart /* 82274fd40c9SRandall Stewart * Early fast retransmission counters 82374fd40c9SRandall Stewart */ 824e5221e8bSRandall Stewart p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n"); 825e5221e8bSRandall Stewart p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n"); 826e5221e8bSRandall Stewart p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n"); 827e5221e8bSRandall Stewart p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n"); 828e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n"); 829e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n"); 830e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n"); 831e5221e8bSRandall Stewart p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n"); 832e5221e8bSRandall Stewart p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n"); 833e5221e8bSRandall Stewart p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n"); 834e5221e8bSRandall Stewart p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n"); 83574fd40c9SRandall Stewart #endif 83674fd40c9SRandall Stewart 83774fd40c9SRandall Stewart /* 83874fd40c9SRandall Stewart * Others 83974fd40c9SRandall Stewart */ 840ade9ccfeSMarcel Moolenaar p1a(sctps_hdrops, "\t{:dropped-too-short/%ju} " 841ade9ccfeSMarcel Moolenaar "{N:/packet shorter than header}\n"); 842ade9ccfeSMarcel Moolenaar p1a(sctps_badsum, "\t{:dropped-bad-checksum/%ju} " 843ade9ccfeSMarcel Moolenaar "{N:/checksum error}\n"); 844ade9ccfeSMarcel Moolenaar p1a(sctps_noport, "\t{:dropped-no-endpoint/%ju} " 845ade9ccfeSMarcel Moolenaar "{N:/no endpoint for port}\n"); 846ade9ccfeSMarcel Moolenaar p1a(sctps_badvtag, "\t{:dropped-bad-v-tag/%ju} " 847ade9ccfeSMarcel Moolenaar "{N:/bad v-tag}\n"); 848ade9ccfeSMarcel Moolenaar p1a(sctps_badsid, "\t{:dropped-bad-sid/%ju} " 849ade9ccfeSMarcel Moolenaar "{N:/bad SID}\n"); 850ade9ccfeSMarcel Moolenaar p1a(sctps_nomem, "\t{:dropped-no-memory/%ju} " 851ade9ccfeSMarcel Moolenaar "{N:/no memory}\n"); 852ade9ccfeSMarcel Moolenaar p1a(sctps_fastretransinrtt, "\t{:multiple-fast-retransmits-in-rtt/%ju} " 853ade9ccfeSMarcel Moolenaar "{N:/number of multiple FR in a RT}T window\n"); 85474fd40c9SRandall Stewart #if 0 855e5221e8bSRandall Stewart p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n"); 85674fd40c9SRandall Stewart #endif 857ade9ccfeSMarcel Moolenaar p1a(sctps_naglesent, "\t{:rfc813-sent/%ju} " 858ade9ccfeSMarcel Moolenaar "{N:/RFC813 allowed sending}\n"); 859ade9ccfeSMarcel Moolenaar p1a(sctps_naglequeued, "\t{:rfc813-queued/%ju} " 860ade9ccfeSMarcel Moolenaar "{N:/RFC813 does not allow sending}\n"); 861ade9ccfeSMarcel Moolenaar p1a(sctps_maxburstqueued, "\t{:max-burst-queued/%ju} " 862ade9ccfeSMarcel Moolenaar "{N:/times max burst prohibited sending}\n"); 863ade9ccfeSMarcel Moolenaar p1a(sctps_ifnomemqueued, "\t{:no-memory-in-interface/%ju} " 864ade9ccfeSMarcel Moolenaar "{N:/look ahead tells us no memory in interface}\n"); 865ade9ccfeSMarcel Moolenaar p(sctps_windowprobed, "\t{:sent-window-probes/%ju} " 866ade9ccfeSMarcel Moolenaar "{N:/number%s of window probes sent}\n"); 867ade9ccfeSMarcel Moolenaar p(sctps_lowlevelerr, "\t{:low-level-err/%ju} " 868ade9ccfeSMarcel Moolenaar "{N:/time%s an output error to clamp down on next user send}\n"); 869ade9ccfeSMarcel Moolenaar p(sctps_lowlevelerrusr, "\t{:low-level-user-error/%ju} " 870ade9ccfeSMarcel Moolenaar "{N:/time%s sctp_senderrors were caused from a user}\n"); 871ade9ccfeSMarcel Moolenaar p(sctps_datadropchklmt, "\t{:dropped-chunk-limit/%ju} " 872ade9ccfeSMarcel Moolenaar "{N:/number of in data drop%s due to chunk limit reached}\n"); 873ade9ccfeSMarcel Moolenaar p(sctps_datadroprwnd, "\t{:dropped-rwnd-limit/%ju} " 874ade9ccfeSMarcel Moolenaar "{N:/number of in data drop%s due to rwnd limit reached}\n"); 875ade9ccfeSMarcel Moolenaar p(sctps_ecnereducedcwnd, "\t{:ecn-reduced-cwnd/%ju} " 876ade9ccfeSMarcel Moolenaar "{N:/time%s a ECN reduced the cwnd}\n"); 877ade9ccfeSMarcel Moolenaar p1a(sctps_vtagexpress, "\t{:v-tag-express-lookup/%ju} " 878ade9ccfeSMarcel Moolenaar "{N:/used express lookup via vtag}\n"); 879ade9ccfeSMarcel Moolenaar p1a(sctps_vtagbogus, "\t{:v-tag-collision/%ju} " 880ade9ccfeSMarcel Moolenaar "{N:/collision in express lookup}\n"); 881ade9ccfeSMarcel Moolenaar p(sctps_primary_randry, "\t{:sender-ran-dry/%ju} " 882ade9ccfeSMarcel Moolenaar "{N:/time%s the sender ran dry of user data on primary}\n"); 883ade9ccfeSMarcel Moolenaar p1a(sctps_cmt_randry, "\t{:cmt-ran-dry/%ju} " 884ade9ccfeSMarcel Moolenaar "{N:/same for above}\n"); 885ade9ccfeSMarcel Moolenaar p(sctps_slowpath_sack, "\t{:slow-path-sack/%ju} " 886ade9ccfeSMarcel Moolenaar "{N:/sack%s the slow way}\n"); 887ade9ccfeSMarcel Moolenaar p(sctps_wu_sacks_sent, "\t{:sent-window-update-only-sack/%ju} " 888ade9ccfeSMarcel Moolenaar "{N:/window update only sack%s sent}\n"); 889ade9ccfeSMarcel Moolenaar p(sctps_sends_with_flags, "\t{:sent-with-sinfo/%ju} " 890ade9ccfeSMarcel Moolenaar "{N:/send%s with sinfo_flags !=0}\n"); 891ade9ccfeSMarcel Moolenaar p(sctps_sends_with_unord, "\t{:sent-with-unordered/%ju} " 892ade9ccfeSMarcel Moolenaar "{N:/unordered send%s}\n"); 893ade9ccfeSMarcel Moolenaar p(sctps_sends_with_eof, "\t{:sent-with-eof/%ju} " 894ade9ccfeSMarcel Moolenaar "{N:/send%s with EOF flag set}\n"); 895ade9ccfeSMarcel Moolenaar p(sctps_sends_with_abort, "\t{:sent-with-abort/%ju} " 896ade9ccfeSMarcel Moolenaar "{N:/send%s with ABORT flag set}\n"); 897ade9ccfeSMarcel Moolenaar p(sctps_protocol_drain_calls, "\t{:protocol-drain-called/%ju} " 898ade9ccfeSMarcel Moolenaar "{N:/time%s protocol drain called}\n"); 899ade9ccfeSMarcel Moolenaar p(sctps_protocol_drains_done, "\t{:protocol-drain/%ju} " 900ade9ccfeSMarcel Moolenaar "{N:/time%s we did a protocol drain}\n"); 901ade9ccfeSMarcel Moolenaar p(sctps_read_peeks, "\t{:read-with-peek/%ju} " 902ade9ccfeSMarcel Moolenaar "{N:/time%s recv was called with peek}\n"); 903ade9ccfeSMarcel Moolenaar p(sctps_cached_chk, "\t{:cached-chunks/%ju} " 904ade9ccfeSMarcel Moolenaar "{N:/cached chunk%s used}\n"); 905ade9ccfeSMarcel Moolenaar p1a(sctps_cached_strmoq, "\t{:cached-output-queue-used/%ju} " 906ade9ccfeSMarcel Moolenaar "{N:/cached stream oq's used}\n"); 907ade9ccfeSMarcel Moolenaar p(sctps_left_abandon, "\t{:messages-abandoned/%ju} " 908ade9ccfeSMarcel Moolenaar "{N:/unread message%s abandonded by close}\n"); 909ade9ccfeSMarcel Moolenaar p1a(sctps_send_burst_avoid, "\t{:send-burst-avoidance/%ju} " 910ade9ccfeSMarcel Moolenaar "{N:/send burst avoidance, already max burst inflight to net}\n"); 911ade9ccfeSMarcel Moolenaar p1a(sctps_send_cwnd_avoid, "\t{:send-cwnd-avoidance/%ju} " 912ade9ccfeSMarcel Moolenaar "{N:/send cwnd full avoidance, already max burst inflight " 913ade9ccfeSMarcel Moolenaar "to net}\n"); 914ade9ccfeSMarcel Moolenaar p(sctps_fwdtsn_map_over, "\t{:tsn-map-overruns/%ju} " 915ade9ccfeSMarcel Moolenaar "{N:/number of map array over-run%s via fwd-tsn's}\n"); 916b8a1761eSRandall Stewart 917b8a1761eSRandall Stewart #undef p 918b8a1761eSRandall Stewart #undef p1a 919ade9ccfeSMarcel Moolenaar xo_close_container(name); 92074fd40c9SRandall Stewart } 92174fd40c9SRandall Stewart 92274fd40c9SRandall Stewart #endif /* SCTP */ 923