xref: /freebsd/usr.bin/netstat/sctp.c (revision 8a16b7a18f5d0b031f09832fd7752fba717e2a97)
174fd40c9SRandall Stewart /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
474fd40c9SRandall Stewart  * Copyright (c) 2001-2007, by Weongyo Jeong. All rights reserved.
52e34c19bSMichael Tuexen  * Copyright (c) 2011, by Michael Tuexen. All rights reserved.
674fd40c9SRandall Stewart  *
774fd40c9SRandall Stewart  * Redistribution and use in source and binary forms, with or without
874fd40c9SRandall Stewart  * modification, are permitted provided that the following conditions are met:
974fd40c9SRandall Stewart  *
1074fd40c9SRandall Stewart  * a) Redistributions of source code must retain the above copyright notice,
1174fd40c9SRandall Stewart  *   this list of conditions and the following disclaimer.
1274fd40c9SRandall Stewart  *
1374fd40c9SRandall Stewart  * b) Redistributions in binary form must reproduce the above copyright
1474fd40c9SRandall Stewart  *    notice, this list of conditions and the following disclaimer in
1574fd40c9SRandall Stewart  *   the documentation and/or other materials provided with the distribution.
1674fd40c9SRandall Stewart  *
1774fd40c9SRandall Stewart  * c) Neither the name of Cisco Systems, Inc. nor the names of its
1874fd40c9SRandall Stewart  *    contributors may be used to endorse or promote products derived
1974fd40c9SRandall Stewart  *    from this software without specific prior written permission.
2074fd40c9SRandall Stewart  *
2174fd40c9SRandall Stewart  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2274fd40c9SRandall Stewart  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2374fd40c9SRandall Stewart  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2474fd40c9SRandall Stewart  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2574fd40c9SRandall Stewart  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2674fd40c9SRandall Stewart  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2774fd40c9SRandall Stewart  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2874fd40c9SRandall Stewart  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2974fd40c9SRandall Stewart  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3074fd40c9SRandall Stewart  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3174fd40c9SRandall Stewart  * THE POSSIBILITY OF SUCH DAMAGE.
3274fd40c9SRandall Stewart  */
3374fd40c9SRandall Stewart 
3474fd40c9SRandall Stewart #if 0
3574fd40c9SRandall Stewart #ifndef lint
3674fd40c9SRandall Stewart static char sccsid[] = "@(#)sctp.c	0.1 (Berkeley) 4/18/2007";
3774fd40c9SRandall Stewart #endif /* not lint */
3874fd40c9SRandall Stewart #endif
3974fd40c9SRandall Stewart 
4074fd40c9SRandall Stewart #include <sys/cdefs.h>
4174fd40c9SRandall Stewart __FBSDID("$FreeBSD$");
4274fd40c9SRandall Stewart 
4374fd40c9SRandall Stewart #include <sys/param.h>
4474fd40c9SRandall Stewart #include <sys/queue.h>
4574fd40c9SRandall Stewart #include <sys/types.h>
4674fd40c9SRandall Stewart #include <sys/socket.h>
4774fd40c9SRandall Stewart #include <sys/socketvar.h>
4874fd40c9SRandall Stewart #include <sys/sysctl.h>
4974fd40c9SRandall Stewart #include <sys/protosw.h>
5074fd40c9SRandall Stewart 
5174fd40c9SRandall Stewart #include <netinet/in.h>
5274fd40c9SRandall Stewart #include <netinet/sctp.h>
5374fd40c9SRandall Stewart #include <netinet/sctp_constants.h>
5474fd40c9SRandall Stewart #include <arpa/inet.h>
5574fd40c9SRandall Stewart 
5674fd40c9SRandall Stewart #include <err.h>
5774fd40c9SRandall Stewart #include <errno.h>
58821df508SXin LI #include <libutil.h>
59821df508SXin LI #include <netdb.h>
6074fd40c9SRandall Stewart #include <stdint.h>
6174fd40c9SRandall Stewart #include <stdio.h>
6274fd40c9SRandall Stewart #include <stdlib.h>
63ade9ccfeSMarcel Moolenaar #include <stdbool.h>
6474fd40c9SRandall Stewart #include <string.h>
65821df508SXin LI #include <unistd.h>
6674fd40c9SRandall Stewart #include "netstat.h"
67ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
6874fd40c9SRandall Stewart 
6974fd40c9SRandall Stewart #ifdef SCTP
7074fd40c9SRandall Stewart 
7174fd40c9SRandall Stewart static void sctp_statesprint(uint32_t state);
7274fd40c9SRandall Stewart 
7374fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_CLOSED		0x0
7474fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_BOUND		0x1
7574fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_LISTEN		0x2
7674fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_COOKIE_WAIT		0x3
7774fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_COOKIE_ECHOED	0x4
7874fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_ESTABLISHED		0x5
7974fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_SENT	0x6
8074fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED	0x7
8174fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT	0x8
8274fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_PENDING	0x9
8374fd40c9SRandall Stewart 
8410d5269fSHiroki Sato static const char *sctpstates[] = {
8574fd40c9SRandall Stewart 	"CLOSED",
8674fd40c9SRandall Stewart 	"BOUND",
8774fd40c9SRandall Stewart 	"LISTEN",
8874fd40c9SRandall Stewart 	"COOKIE_WAIT",
8974fd40c9SRandall Stewart 	"COOKIE_ECHOED",
9074fd40c9SRandall Stewart 	"ESTABLISHED",
9174fd40c9SRandall Stewart 	"SHUTDOWN_SENT",
9274fd40c9SRandall Stewart 	"SHUTDOWN_RECEIVED",
9374fd40c9SRandall Stewart 	"SHUTDOWN_ACK_SENT",
9474fd40c9SRandall Stewart 	"SHUTDOWN_PENDING"
9574fd40c9SRandall Stewart };
9674fd40c9SRandall Stewart 
9710d5269fSHiroki Sato static LIST_HEAD(xladdr_list, xladdr_entry) xladdr_head;
9874fd40c9SRandall Stewart struct xladdr_entry {
9974fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
10074fd40c9SRandall Stewart 	LIST_ENTRY(xladdr_entry) xladdr_entries;
10174fd40c9SRandall Stewart };
10274fd40c9SRandall Stewart 
10310d5269fSHiroki Sato static LIST_HEAD(xraddr_list, xraddr_entry) xraddr_head;
10474fd40c9SRandall Stewart struct xraddr_entry {
10574fd40c9SRandall Stewart 	struct xsctp_raddr *xraddr;
10674fd40c9SRandall Stewart 	LIST_ENTRY(xraddr_entry) xraddr_entries;
10774fd40c9SRandall Stewart };
10874fd40c9SRandall Stewart 
1092e34c19bSMichael Tuexen static void
110ade9ccfeSMarcel Moolenaar sctp_print_address(const char *container, union sctp_sockstore *address,
111ade9ccfeSMarcel Moolenaar     int port, int num_port)
1122e34c19bSMichael Tuexen {
1132e34c19bSMichael Tuexen 	struct servent *sp = 0;
1142e34c19bSMichael Tuexen 	char line[80], *cp;
1152e34c19bSMichael Tuexen 	int width;
116f193c8ceSXin LI 	size_t alen, plen;
1172e34c19bSMichael Tuexen 
118ade9ccfeSMarcel Moolenaar 	if (container)
119ade9ccfeSMarcel Moolenaar 		xo_open_container(container);
120ade9ccfeSMarcel Moolenaar 
1212e34c19bSMichael Tuexen 	switch (address->sa.sa_family) {
1223dcc856bSMichael Tuexen #ifdef INET
1232e34c19bSMichael Tuexen 	case AF_INET:
124f193c8ceSXin LI 		snprintf(line, sizeof(line), "%.*s.",
125f193c8ceSXin LI 		    Wflag ? 39 : 16, inetname(&address->sin.sin_addr));
1262e34c19bSMichael Tuexen 		break;
1273dcc856bSMichael Tuexen #endif
1282e34c19bSMichael Tuexen #ifdef INET6
1292e34c19bSMichael Tuexen 	case AF_INET6:
130f193c8ceSXin LI 		snprintf(line, sizeof(line), "%.*s.",
131f193c8ceSXin LI 		    Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr));
1322e34c19bSMichael Tuexen 		break;
1332e34c19bSMichael Tuexen #endif
1342e34c19bSMichael Tuexen 	default:
135f193c8ceSXin LI 		snprintf(line, sizeof(line), "%.*s.",
136f193c8ceSXin LI 		    Wflag ? 39 : 16, "");
1372e34c19bSMichael Tuexen 		break;
1382e34c19bSMichael Tuexen 	}
139f193c8ceSXin LI 	alen = strlen(line);
140f193c8ceSXin LI 	cp = line + alen;
1412e34c19bSMichael Tuexen 	if (!num_port && port)
1422e34c19bSMichael Tuexen 		sp = getservbyport((int)port, "sctp");
1432e34c19bSMichael Tuexen 	if (sp || port == 0)
144f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
145f193c8ceSXin LI 		    "%.15s ", sp ? sp->s_name : "*");
1462e34c19bSMichael Tuexen 	else
147f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
148f193c8ceSXin LI 		    "%d ", ntohs((u_short)port));
1492e34c19bSMichael Tuexen 	width = Wflag ? 45 : 22;
150ade9ccfeSMarcel Moolenaar 	xo_emit("{d:target/%-*.*s} ", width, width, line);
151ade9ccfeSMarcel Moolenaar 
152f193c8ceSXin LI 	plen = strlen(cp) - 1;
153f193c8ceSXin LI 	alen--;
154ade9ccfeSMarcel Moolenaar 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
155ade9ccfeSMarcel Moolenaar 	    plen, cp);
156ade9ccfeSMarcel Moolenaar 
157ade9ccfeSMarcel Moolenaar 	if (container)
158ade9ccfeSMarcel Moolenaar 		xo_close_container(container);
1592e34c19bSMichael Tuexen }
1602e34c19bSMichael Tuexen 
16174fd40c9SRandall Stewart static int
16274fd40c9SRandall Stewart sctp_skip_xinpcb_ifneed(char *buf, const size_t buflen, size_t *offset)
16374fd40c9SRandall Stewart {
16474fd40c9SRandall Stewart 	int exist_tcb = 0;
16574fd40c9SRandall Stewart 	struct xsctp_tcb *xstcb;
16674fd40c9SRandall Stewart 	struct xsctp_raddr *xraddr;
16774fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
16874fd40c9SRandall Stewart 
16974fd40c9SRandall Stewart 	while (*offset < buflen) {
17074fd40c9SRandall Stewart 		xladdr = (struct xsctp_laddr *)(buf + *offset);
17174fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_laddr);
17274fd40c9SRandall Stewart 		if (xladdr->last == 1)
17374fd40c9SRandall Stewart 			break;
17474fd40c9SRandall Stewart 	}
17574fd40c9SRandall Stewart 
17674fd40c9SRandall Stewart 	while (*offset < buflen) {
17774fd40c9SRandall Stewart 		xstcb = (struct xsctp_tcb *)(buf + *offset);
17874fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_tcb);
17974fd40c9SRandall Stewart 		if (xstcb->last == 1)
18074fd40c9SRandall Stewart 			break;
18174fd40c9SRandall Stewart 
18274fd40c9SRandall Stewart 		exist_tcb = 1;
18374fd40c9SRandall Stewart 
18474fd40c9SRandall Stewart 		while (*offset < buflen) {
18574fd40c9SRandall Stewart 			xladdr = (struct xsctp_laddr *)(buf + *offset);
18674fd40c9SRandall Stewart 			*offset += sizeof(struct xsctp_laddr);
18774fd40c9SRandall Stewart 			if (xladdr->last == 1)
18874fd40c9SRandall Stewart 				break;
18974fd40c9SRandall Stewart 		}
19074fd40c9SRandall Stewart 
19174fd40c9SRandall Stewart 		while (*offset < buflen) {
19274fd40c9SRandall Stewart 			xraddr = (struct xsctp_raddr *)(buf + *offset);
19374fd40c9SRandall Stewart 			*offset += sizeof(struct xsctp_raddr);
19474fd40c9SRandall Stewart 			if (xraddr->last == 1)
19574fd40c9SRandall Stewart 				break;
19674fd40c9SRandall Stewart 		}
19774fd40c9SRandall Stewart 	}
19874fd40c9SRandall Stewart 
19974fd40c9SRandall Stewart 	/*
20074fd40c9SRandall Stewart 	 * If Lflag is set, we don't care about the return value.
20174fd40c9SRandall Stewart 	 */
20274fd40c9SRandall Stewart 	if (Lflag)
20374fd40c9SRandall Stewart 		return 0;
20474fd40c9SRandall Stewart 
20574fd40c9SRandall Stewart 	return exist_tcb;
20674fd40c9SRandall Stewart }
20774fd40c9SRandall Stewart 
20874fd40c9SRandall Stewart static void
2092e34c19bSMichael Tuexen sctp_process_tcb(struct xsctp_tcb *xstcb,
21074fd40c9SRandall Stewart     char *buf, const size_t buflen, size_t *offset, int *indent)
21174fd40c9SRandall Stewart {
21274fd40c9SRandall Stewart 	int i, xl_total = 0, xr_total = 0, x_max;
21374fd40c9SRandall Stewart 	struct xsctp_raddr *xraddr;
21474fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
21574fd40c9SRandall Stewart 	struct xladdr_entry *prev_xl = NULL, *xl = NULL, *xl_tmp;
21674fd40c9SRandall Stewart 	struct xraddr_entry *prev_xr = NULL, *xr = NULL, *xr_tmp;
21774fd40c9SRandall Stewart 
21874fd40c9SRandall Stewart 	LIST_INIT(&xladdr_head);
21974fd40c9SRandall Stewart 	LIST_INIT(&xraddr_head);
22074fd40c9SRandall Stewart 
22174fd40c9SRandall Stewart 	/*
22274fd40c9SRandall Stewart 	 * Make `struct xladdr_list' list and `struct xraddr_list' list
22374fd40c9SRandall Stewart 	 * to handle the address flexibly.
22474fd40c9SRandall Stewart 	 */
22574fd40c9SRandall Stewart 	while (*offset < buflen) {
22674fd40c9SRandall Stewart 		xladdr = (struct xsctp_laddr *)(buf + *offset);
22774fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_laddr);
22874fd40c9SRandall Stewart 		if (xladdr->last == 1)
22974fd40c9SRandall Stewart 			break;
23074fd40c9SRandall Stewart 
23174fd40c9SRandall Stewart 		prev_xl = xl;
23274fd40c9SRandall Stewart 		xl = malloc(sizeof(struct xladdr_entry));
23374fd40c9SRandall Stewart 		if (xl == NULL) {
234ade9ccfeSMarcel Moolenaar 			xo_warnx("malloc %lu bytes",
23574fd40c9SRandall Stewart 			    (u_long)sizeof(struct xladdr_entry));
23674fd40c9SRandall Stewart 			goto out;
23774fd40c9SRandall Stewart 		}
23874fd40c9SRandall Stewart 		xl->xladdr = xladdr;
23974fd40c9SRandall Stewart 		if (prev_xl == NULL)
24074fd40c9SRandall Stewart 			LIST_INSERT_HEAD(&xladdr_head, xl, xladdr_entries);
24174fd40c9SRandall Stewart 		else
24274fd40c9SRandall Stewart 			LIST_INSERT_AFTER(prev_xl, xl, xladdr_entries);
24374fd40c9SRandall Stewart 		xl_total++;
24474fd40c9SRandall Stewart 	}
24574fd40c9SRandall Stewart 
24674fd40c9SRandall Stewart 	while (*offset < buflen) {
24774fd40c9SRandall Stewart 		xraddr = (struct xsctp_raddr *)(buf + *offset);
24874fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_raddr);
24974fd40c9SRandall Stewart 		if (xraddr->last == 1)
25074fd40c9SRandall Stewart 			break;
25174fd40c9SRandall Stewart 
25274fd40c9SRandall Stewart 		prev_xr = xr;
25374fd40c9SRandall Stewart 		xr = malloc(sizeof(struct xraddr_entry));
25474fd40c9SRandall Stewart 		if (xr == NULL) {
255ade9ccfeSMarcel Moolenaar 			xo_warnx("malloc %lu bytes",
25674fd40c9SRandall Stewart 			    (u_long)sizeof(struct xraddr_entry));
25774fd40c9SRandall Stewart 			goto out;
25874fd40c9SRandall Stewart 		}
25974fd40c9SRandall Stewart 		xr->xraddr = xraddr;
26074fd40c9SRandall Stewart 		if (prev_xr == NULL)
26174fd40c9SRandall Stewart 			LIST_INSERT_HEAD(&xraddr_head, xr, xraddr_entries);
26274fd40c9SRandall Stewart 		else
26374fd40c9SRandall Stewart 			LIST_INSERT_AFTER(prev_xr, xr, xraddr_entries);
26474fd40c9SRandall Stewart 		xr_total++;
26574fd40c9SRandall Stewart 	}
26674fd40c9SRandall Stewart 
26774fd40c9SRandall Stewart 	/*
26874fd40c9SRandall Stewart 	 * Let's print the address infos.
26974fd40c9SRandall Stewart 	 */
270ade9ccfeSMarcel Moolenaar 	xo_open_list("address");
27174fd40c9SRandall Stewart 	xl = LIST_FIRST(&xladdr_head);
27274fd40c9SRandall Stewart 	xr = LIST_FIRST(&xraddr_head);
273fcc0131fSMarcelo Araujo 	x_max = MAX(xl_total, xr_total);
27474fd40c9SRandall Stewart 	for (i = 0; i < x_max; i++) {
275ade9ccfeSMarcel Moolenaar 		xo_open_instance("address");
276ade9ccfeSMarcel Moolenaar 
27774fd40c9SRandall Stewart 		if (((*indent == 0) && i > 0) || *indent > 0)
278ade9ccfeSMarcel Moolenaar 			xo_emit("{P:/%-12s} ", " ");
27974fd40c9SRandall Stewart 
28074fd40c9SRandall Stewart 		if (xl != NULL) {
281ade9ccfeSMarcel Moolenaar 			sctp_print_address("local", &(xl->xladdr->address),
2822e34c19bSMichael Tuexen 			    htons(xstcb->local_port), numeric_port);
2832e34c19bSMichael Tuexen 		} else {
2842e34c19bSMichael Tuexen 			if (Wflag) {
285ade9ccfeSMarcel Moolenaar 				xo_emit("{P:/%-45s} ", " ");
2862e34c19bSMichael Tuexen 			} else {
287ade9ccfeSMarcel Moolenaar 				xo_emit("{P:/%-22s} ", " ");
28874fd40c9SRandall Stewart 			}
28974fd40c9SRandall Stewart 		}
29074fd40c9SRandall Stewart 
29174fd40c9SRandall Stewart 		if (xr != NULL && !Lflag) {
292ade9ccfeSMarcel Moolenaar 			sctp_print_address("remote", &(xr->xraddr->address),
2932e34c19bSMichael Tuexen 			    htons(xstcb->remote_port), numeric_port);
29474fd40c9SRandall Stewart 		}
29574fd40c9SRandall Stewart 
29674fd40c9SRandall Stewart 		if (xl != NULL)
29774fd40c9SRandall Stewart 			xl = LIST_NEXT(xl, xladdr_entries);
29874fd40c9SRandall Stewart 		if (xr != NULL)
29974fd40c9SRandall Stewart 			xr = LIST_NEXT(xr, xraddr_entries);
30074fd40c9SRandall Stewart 
30174fd40c9SRandall Stewart 		if (i == 0 && !Lflag)
30274fd40c9SRandall Stewart 			sctp_statesprint(xstcb->state);
30374fd40c9SRandall Stewart 
30474fd40c9SRandall Stewart 		if (i < x_max)
305ade9ccfeSMarcel Moolenaar 			xo_emit("\n");
306ade9ccfeSMarcel Moolenaar 		xo_close_instance("address");
30774fd40c9SRandall Stewart 	}
30874fd40c9SRandall Stewart 
30974fd40c9SRandall Stewart out:
31074fd40c9SRandall Stewart 	/*
31174fd40c9SRandall Stewart 	 * Free the list which be used to handle the address.
31274fd40c9SRandall Stewart 	 */
31374fd40c9SRandall Stewart 	xl = LIST_FIRST(&xladdr_head);
31474fd40c9SRandall Stewart 	while (xl != NULL) {
31574fd40c9SRandall Stewart 		xl_tmp = LIST_NEXT(xl, xladdr_entries);
31674fd40c9SRandall Stewart 		free(xl);
31774fd40c9SRandall Stewart 		xl = xl_tmp;
31874fd40c9SRandall Stewart 	}
31974fd40c9SRandall Stewart 
32074fd40c9SRandall Stewart 	xr = LIST_FIRST(&xraddr_head);
32174fd40c9SRandall Stewart 	while (xr != NULL) {
32274fd40c9SRandall Stewart 		xr_tmp = LIST_NEXT(xr, xraddr_entries);
32374fd40c9SRandall Stewart 		free(xr);
32474fd40c9SRandall Stewart 		xr = xr_tmp;
32574fd40c9SRandall Stewart 	}
32674fd40c9SRandall Stewart }
32774fd40c9SRandall Stewart 
32874fd40c9SRandall Stewart static void
3292e34c19bSMichael Tuexen sctp_process_inpcb(struct xsctp_inpcb *xinpcb,
33074fd40c9SRandall Stewart     char *buf, const size_t buflen, size_t *offset)
33174fd40c9SRandall Stewart {
3322e34c19bSMichael Tuexen 	int indent = 0, xladdr_total = 0, is_listening = 0;
33374fd40c9SRandall Stewart 	static int first = 1;
334321ae07fSPhilippe Charnier 	const char *tname, *pname;
33574fd40c9SRandall Stewart 	struct xsctp_tcb *xstcb;
33674fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
3372e34c19bSMichael Tuexen 	size_t offset_laddr;
3382e34c19bSMichael Tuexen 	int process_closed;
33974fd40c9SRandall Stewart 
3402e34c19bSMichael Tuexen 	if (xinpcb->maxqlen > 0)
34174fd40c9SRandall Stewart 		is_listening = 1;
34274fd40c9SRandall Stewart 
34374fd40c9SRandall Stewart 	if (first) {
34474fd40c9SRandall Stewart 		if (!Lflag) {
345ade9ccfeSMarcel Moolenaar 			xo_emit("Active SCTP associations");
34674fd40c9SRandall Stewart 			if (aflag)
347ade9ccfeSMarcel Moolenaar 				xo_emit(" (including servers)");
34874fd40c9SRandall Stewart 		} else
349ade9ccfeSMarcel Moolenaar 			xo_emit("Current listen queue sizes (qlen/maxqlen)");
350ade9ccfeSMarcel Moolenaar 		xo_emit("\n");
35174fd40c9SRandall Stewart 		if (Lflag)
352ade9ccfeSMarcel Moolenaar 			xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-8.8s} "
353ade9ccfeSMarcel Moolenaar 			    "{T:/%-22.22s}\n",
35474fd40c9SRandall Stewart 			    "Proto", "Type", "Listen", "Local Address");
35574fd40c9SRandall Stewart 		else
3562e34c19bSMichael Tuexen 			if (Wflag)
357ade9ccfeSMarcel Moolenaar 				xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-45.45s} "
358ade9ccfeSMarcel Moolenaar 				    "{T:/%-45.45s} {T:/%s}\n",
3592e34c19bSMichael Tuexen 				    "Proto", "Type",
3602e34c19bSMichael Tuexen 				    "Local Address", "Foreign Address",
3612e34c19bSMichael Tuexen 				    "(state)");
3622e34c19bSMichael Tuexen 			else
363ade9ccfeSMarcel Moolenaar 				xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-22.22s} "
364ade9ccfeSMarcel Moolenaar 				    "{T:/%-22.22s} {T:/%s}\n",
36574fd40c9SRandall Stewart 				    "Proto", "Type",
36674fd40c9SRandall Stewart 				    "Local Address", "Foreign Address",
36774fd40c9SRandall Stewart 				    "(state)");
36874fd40c9SRandall Stewart 		first = 0;
36974fd40c9SRandall Stewart 	}
3702e34c19bSMichael Tuexen 	xladdr = (struct xsctp_laddr *)(buf + *offset);
371ca658db3SMichael Tuexen 	if ((!aflag && is_listening) ||
372ca658db3SMichael Tuexen 	    (Lflag && !is_listening)) {
37393f8854cSDimitry Andric 		sctp_skip_xinpcb_ifneed(buf, buflen, offset);
37474fd40c9SRandall Stewart 		return;
37574fd40c9SRandall Stewart 	}
37674fd40c9SRandall Stewart 
3772e34c19bSMichael Tuexen 	if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) {
3782e34c19bSMichael Tuexen 		/* Can't distinguish between sctp46 and sctp6 */
3792e34c19bSMichael Tuexen 		pname = "sctp46";
3802e34c19bSMichael Tuexen 	} else {
3812e34c19bSMichael Tuexen 		pname = "sctp4";
3822e34c19bSMichael Tuexen 	}
38374fd40c9SRandall Stewart 
38474fd40c9SRandall Stewart 	if (xinpcb->flags & SCTP_PCB_FLAGS_TCPTYPE)
38574fd40c9SRandall Stewart 		tname = "1to1";
38674fd40c9SRandall Stewart 	else if (xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE)
38774fd40c9SRandall Stewart 		tname = "1toN";
38874fd40c9SRandall Stewart 	else
3892e34c19bSMichael Tuexen 		tname = "????";
39074fd40c9SRandall Stewart 
39174fd40c9SRandall Stewart 	if (Lflag) {
3927325dfbbSAlfred Perlstein 		char buf1[22];
39374fd40c9SRandall Stewart 
3947325dfbbSAlfred Perlstein 		snprintf(buf1, sizeof buf1, "%u/%u",
3957325dfbbSAlfred Perlstein 		    xinpcb->qlen, xinpcb->maxqlen);
396ade9ccfeSMarcel Moolenaar 		xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
397ade9ccfeSMarcel Moolenaar 		    pname, tname);
398ade9ccfeSMarcel Moolenaar 		xo_emit("{d:queues/%-8.8s}{e:queue-len/%hu}"
399ade9ccfeSMarcel Moolenaar 		    "{e:max-queue-len/%hu} ",
400ade9ccfeSMarcel Moolenaar 		    buf1, xinpcb->qlen, xinpcb->maxqlen);
40174fd40c9SRandall Stewart 	}
4022e34c19bSMichael Tuexen 
4032e34c19bSMichael Tuexen 	offset_laddr = *offset;
4042e34c19bSMichael Tuexen 	process_closed = 0;
405ade9ccfeSMarcel Moolenaar 
406ade9ccfeSMarcel Moolenaar 	xo_open_list("local-address");
4072e34c19bSMichael Tuexen retry:
40874fd40c9SRandall Stewart 	while (*offset < buflen) {
40974fd40c9SRandall Stewart 		xladdr = (struct xsctp_laddr *)(buf + *offset);
41074fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_laddr);
4112e34c19bSMichael Tuexen 		if (xladdr->last) {
4122e34c19bSMichael Tuexen 			if (aflag && !Lflag && (xladdr_total == 0) && process_closed) {
413ade9ccfeSMarcel Moolenaar 				xo_open_instance("local-address");
414ade9ccfeSMarcel Moolenaar 
415ade9ccfeSMarcel Moolenaar 				xo_emit("{:protocol/%-6.6s/%s} "
416ade9ccfeSMarcel Moolenaar 				    "{:type/%-5.5s/%s} ", pname, tname);
4172e34c19bSMichael Tuexen 				if (Wflag) {
418ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-91.91s/%s} "
419ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4202e34c19bSMichael Tuexen 				} else {
421ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-45.45s/%s} "
422ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4232e34c19bSMichael Tuexen 				}
424ade9ccfeSMarcel Moolenaar 				xo_close_instance("local-address");
4252e34c19bSMichael Tuexen 			}
4262e34c19bSMichael Tuexen 			if (process_closed || is_listening) {
427ade9ccfeSMarcel Moolenaar 				xo_emit("\n");
4282e34c19bSMichael Tuexen 			}
42974fd40c9SRandall Stewart 			break;
4302e34c19bSMichael Tuexen 		}
43174fd40c9SRandall Stewart 
4322e34c19bSMichael Tuexen 		if (!Lflag && !is_listening && !process_closed)
43374fd40c9SRandall Stewart 			continue;
43474fd40c9SRandall Stewart 
435ade9ccfeSMarcel Moolenaar 		xo_open_instance("local-address");
436ade9ccfeSMarcel Moolenaar 
4372e34c19bSMichael Tuexen 		if (xladdr_total == 0) {
438ca658db3SMichael Tuexen 			if (!Lflag) {
439ca658db3SMichael Tuexen 				xo_emit("{:protocol/%-6.6s/%s} "
440ca658db3SMichael Tuexen 				    "{:type/%-5.5s/%s} ", pname, tname);
441ca658db3SMichael Tuexen 			}
4422e34c19bSMichael Tuexen 		} else {
443ade9ccfeSMarcel Moolenaar 			xo_emit("\n");
444ade9ccfeSMarcel Moolenaar 			xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ",
445ade9ccfeSMarcel Moolenaar 			    " ");
44674fd40c9SRandall Stewart 		}
447ade9ccfeSMarcel Moolenaar 		sctp_print_address("local", &(xladdr->address),
4482e34c19bSMichael Tuexen 		    htons(xinpcb->local_port), numeric_port);
4492e34c19bSMichael Tuexen 		if (aflag && !Lflag && xladdr_total == 0) {
4502e34c19bSMichael Tuexen 			if (Wflag) {
4512e34c19bSMichael Tuexen 				if (process_closed) {
452ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-45.45s} "
453ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4542e34c19bSMichael Tuexen 				} else {
455ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-45.45s} "
456282d1dd7SMichael Tuexen 					    "{:state/LISTEN}", " ");
4572e34c19bSMichael Tuexen 				}
4582e34c19bSMichael Tuexen 			} else {
4592e34c19bSMichael Tuexen 				if (process_closed) {
460ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-22.22s} "
461ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4622e34c19bSMichael Tuexen 				} else {
463ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-22.22s} "
464ade9ccfeSMarcel Moolenaar 					    "{:state/LISTEN}", " ");
4652e34c19bSMichael Tuexen 				}
4662e34c19bSMichael Tuexen 			}
4672e34c19bSMichael Tuexen 		}
46874fd40c9SRandall Stewart 		xladdr_total++;
469ade9ccfeSMarcel Moolenaar 		xo_close_instance("local-address");
47074fd40c9SRandall Stewart 	}
47174fd40c9SRandall Stewart 
47274fd40c9SRandall Stewart 	xstcb = (struct xsctp_tcb *)(buf + *offset);
47374fd40c9SRandall Stewart 	*offset += sizeof(struct xsctp_tcb);
4742e34c19bSMichael Tuexen 	if (aflag && (xladdr_total == 0) && xstcb->last && !process_closed) {
4752e34c19bSMichael Tuexen 		process_closed = 1;
4762e34c19bSMichael Tuexen 		*offset = offset_laddr;
4772e34c19bSMichael Tuexen 		goto retry;
4782e34c19bSMichael Tuexen 	}
47974fd40c9SRandall Stewart 	while (xstcb->last == 0 && *offset < buflen) {
480ade9ccfeSMarcel Moolenaar 		xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
481ade9ccfeSMarcel Moolenaar 		    pname, tname);
4822e34c19bSMichael Tuexen 		sctp_process_tcb(xstcb, buf, buflen, offset, &indent);
48374fd40c9SRandall Stewart 		indent++;
48474fd40c9SRandall Stewart 		xstcb = (struct xsctp_tcb *)(buf + *offset);
48574fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_tcb);
48674fd40c9SRandall Stewart 	}
487ade9ccfeSMarcel Moolenaar 
488ade9ccfeSMarcel Moolenaar 	xo_close_list("local-address");
48974fd40c9SRandall Stewart }
49074fd40c9SRandall Stewart 
49174fd40c9SRandall Stewart /*
49274fd40c9SRandall Stewart  * Print a summary of SCTP connections related to an Internet
49374fd40c9SRandall Stewart  * protocol.
49474fd40c9SRandall Stewart  */
49574fd40c9SRandall Stewart void
496feda1a43SJohn Baldwin sctp_protopr(u_long off __unused,
497321ae07fSPhilippe Charnier     const char *name __unused, int af1 __unused, int proto)
49874fd40c9SRandall Stewart {
49974fd40c9SRandall Stewart 	char *buf;
50074fd40c9SRandall Stewart 	const char *mibvar = "net.inet.sctp.assoclist";
50104b764d8SXin LI 	size_t offset = 0;
50274fd40c9SRandall Stewart 	size_t len = 0;
50374fd40c9SRandall Stewart 	struct xsctp_inpcb *xinpcb;
50474fd40c9SRandall Stewart 
50574fd40c9SRandall Stewart 	if (proto != IPPROTO_SCTP)
50674fd40c9SRandall Stewart 		return;
50774fd40c9SRandall Stewart 
50874fd40c9SRandall Stewart 	if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
50974fd40c9SRandall Stewart 		if (errno != ENOENT)
510ade9ccfeSMarcel Moolenaar 			xo_warn("sysctl: %s", mibvar);
51174fd40c9SRandall Stewart 		return;
51274fd40c9SRandall Stewart 	}
513ef1cb629SMarcelo Araujo 	if ((buf = malloc(len)) == NULL) {
514ade9ccfeSMarcel Moolenaar 		xo_warnx("malloc %lu bytes", (u_long)len);
51574fd40c9SRandall Stewart 		return;
51674fd40c9SRandall Stewart 	}
51774fd40c9SRandall Stewart 	if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
518ade9ccfeSMarcel Moolenaar 		xo_warn("sysctl: %s", mibvar);
51974fd40c9SRandall Stewart 		free(buf);
52074fd40c9SRandall Stewart 		return;
52174fd40c9SRandall Stewart 	}
52274fd40c9SRandall Stewart 
52374fd40c9SRandall Stewart 	xinpcb = (struct xsctp_inpcb *)(buf + offset);
52474fd40c9SRandall Stewart 	offset += sizeof(struct xsctp_inpcb);
52574fd40c9SRandall Stewart 	while (xinpcb->last == 0 && offset < len) {
5262e34c19bSMichael Tuexen 		sctp_process_inpcb(xinpcb, buf, (const size_t)len,
52774fd40c9SRandall Stewart 		    &offset);
52874fd40c9SRandall Stewart 
52974fd40c9SRandall Stewart 		xinpcb = (struct xsctp_inpcb *)(buf + offset);
53074fd40c9SRandall Stewart 		offset += sizeof(struct xsctp_inpcb);
53174fd40c9SRandall Stewart 	}
53274fd40c9SRandall Stewart 
53374fd40c9SRandall Stewart 	free(buf);
53474fd40c9SRandall Stewart }
53574fd40c9SRandall Stewart 
53674fd40c9SRandall Stewart static void
53774fd40c9SRandall Stewart sctp_statesprint(uint32_t state)
53874fd40c9SRandall Stewart {
53974fd40c9SRandall Stewart 	int idx;
54074fd40c9SRandall Stewart 
54174fd40c9SRandall Stewart 	switch (state) {
5420835304fSMichael Tuexen 	case SCTP_CLOSED:
5430835304fSMichael Tuexen 		idx = NETSTAT_SCTP_STATES_CLOSED;
5440835304fSMichael Tuexen 		break;
5450835304fSMichael Tuexen 	case SCTP_BOUND:
5460835304fSMichael Tuexen 		idx = NETSTAT_SCTP_STATES_BOUND;
5470835304fSMichael Tuexen 		break;
5480835304fSMichael Tuexen 	case SCTP_LISTEN:
5490835304fSMichael Tuexen 		idx = NETSTAT_SCTP_STATES_LISTEN;
5500835304fSMichael Tuexen 		break;
5510835304fSMichael Tuexen 	case SCTP_COOKIE_WAIT:
55274fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_COOKIE_WAIT;
55374fd40c9SRandall Stewart 		break;
5540835304fSMichael Tuexen 	case SCTP_COOKIE_ECHOED:
55574fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_COOKIE_ECHOED;
55674fd40c9SRandall Stewart 		break;
5570835304fSMichael Tuexen 	case SCTP_ESTABLISHED:
55874fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_ESTABLISHED;
55974fd40c9SRandall Stewart 		break;
5600835304fSMichael Tuexen 	case SCTP_SHUTDOWN_SENT:
56174fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_SENT;
56274fd40c9SRandall Stewart 		break;
5630835304fSMichael Tuexen 	case SCTP_SHUTDOWN_RECEIVED:
56474fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED;
56574fd40c9SRandall Stewart 		break;
5660835304fSMichael Tuexen 	case SCTP_SHUTDOWN_ACK_SENT:
56774fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT;
56874fd40c9SRandall Stewart 		break;
5690835304fSMichael Tuexen 	case SCTP_SHUTDOWN_PENDING:
57074fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING;
57174fd40c9SRandall Stewart 		break;
57274fd40c9SRandall Stewart 	default:
573ade9ccfeSMarcel Moolenaar 		xo_emit("UNKNOWN {:state/0x%08x}", state);
57474fd40c9SRandall Stewart 		return;
57574fd40c9SRandall Stewart 	}
57674fd40c9SRandall Stewart 
577ade9ccfeSMarcel Moolenaar 	xo_emit("{:state/%s}", sctpstates[idx]);
57874fd40c9SRandall Stewart }
57974fd40c9SRandall Stewart 
58074fd40c9SRandall Stewart /*
58174fd40c9SRandall Stewart  * Dump SCTP statistics structure.
58274fd40c9SRandall Stewart  */
58374fd40c9SRandall Stewart void
584feda1a43SJohn Baldwin sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
58574fd40c9SRandall Stewart {
5869eddb899SMark Johnston 	struct sctpstat sctpstat;
58774fd40c9SRandall Stewart 
5889eddb899SMark Johnston 	if (fetch_stats("net.inet.sctp.stats", off, &sctpstat,
5899eddb899SMark Johnston 	    sizeof(sctpstat), kread) != 0)
59074fd40c9SRandall Stewart 		return;
59174fd40c9SRandall Stewart 
592ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
593ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
59474fd40c9SRandall Stewart 
59574fd40c9SRandall Stewart #define	p(f, m) if (sctpstat.f || sflag <= 1) \
596ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)sctpstat.f, plural(sctpstat.f))
59774fd40c9SRandall Stewart #define	p1a(f, m) if (sctpstat.f || sflag <= 1) \
598ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)sctpstat.f)
59974fd40c9SRandall Stewart 
60074fd40c9SRandall Stewart 	/*
60174fd40c9SRandall Stewart 	 * input statistics
60274fd40c9SRandall Stewart 	 */
603ade9ccfeSMarcel Moolenaar 	p(sctps_recvpackets, "\t{:received-packets/%ju} "
604ade9ccfeSMarcel Moolenaar 	    "{N:/input packet%s}\n");
605ade9ccfeSMarcel Moolenaar 	p(sctps_recvdatagrams, "\t\t{:received-datagrams/%ju} "
606ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s}\n");
607ade9ccfeSMarcel Moolenaar 	p(sctps_recvpktwithdata, "\t\t{:received-with-data/%ju} "
608ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s that had data}\n");
609ade9ccfeSMarcel Moolenaar 	p(sctps_recvsacks, "\t\t{:received-sack-chunks/%ju} "
610ade9ccfeSMarcel Moolenaar 	    "{N:/input SACK chunk%s}\n");
611ade9ccfeSMarcel Moolenaar 	p(sctps_recvdata, "\t\t{:received-data-chunks/%ju} "
612ade9ccfeSMarcel Moolenaar 	    "{N:/input DATA chunk%s}\n");
613ade9ccfeSMarcel Moolenaar 	p(sctps_recvdupdata, "\t\t{:received-duplicate-data-chunks/%ju} "
614ade9ccfeSMarcel Moolenaar 	    "{N:/duplicate DATA chunk%s}\n");
615ade9ccfeSMarcel Moolenaar 	p(sctps_recvheartbeat, "\t\t{:received-hb-chunks/%ju} "
616ade9ccfeSMarcel Moolenaar 	    "{N:/input HB chunk%s}\n");
617ade9ccfeSMarcel Moolenaar 	p(sctps_recvheartbeatack, "\t\t{:received-hb-ack-chunks/%ju} "
618ade9ccfeSMarcel Moolenaar 	    "{N:/HB-ACK chunk%s}\n");
619ade9ccfeSMarcel Moolenaar 	p(sctps_recvecne, "\t\t{:received-ecne-chunks/%ju} "
620ade9ccfeSMarcel Moolenaar 	    "{N:/input ECNE chunk%s}\n");
621ade9ccfeSMarcel Moolenaar 	p(sctps_recvauth, "\t\t{:received-auth-chunks/%ju} "
622ade9ccfeSMarcel Moolenaar 	    "{N:/input AUTH chunk%s}\n");
623ade9ccfeSMarcel Moolenaar 	p(sctps_recvauthmissing, "\t\t{:dropped-missing-auth/%ju} "
624ade9ccfeSMarcel Moolenaar 	    "{N:/chunk%s missing AUTH}\n");
625ade9ccfeSMarcel Moolenaar 	p(sctps_recvivalhmacid, "\t\t{:dropped-invalid-hmac/%ju} "
626ade9ccfeSMarcel Moolenaar 	    "{N:/invalid HMAC id%s received}\n");
627ade9ccfeSMarcel Moolenaar 	p(sctps_recvivalkeyid, "\t\t{:dropped-invalid-secret/%ju} "
628ade9ccfeSMarcel Moolenaar 	    "{N:/invalid secret id%s received}\n");
629ade9ccfeSMarcel Moolenaar 	p1a(sctps_recvauthfailed, "\t\t{:dropped-auth-failed/%ju} "
630ade9ccfeSMarcel Moolenaar 	    "{N:/auth failed}\n");
631ade9ccfeSMarcel Moolenaar 	p1a(sctps_recvexpress, "\t\t{:received-fast-path/%ju} "
632ade9ccfeSMarcel Moolenaar 	    "{N:/fast path receives all one chunk}\n");
633ade9ccfeSMarcel Moolenaar 	p1a(sctps_recvexpressm, "\t\t{:receives-fast-path-multipart/%ju} "
634ade9ccfeSMarcel Moolenaar 	    "{N:/fast path multi-part data}\n");
63574fd40c9SRandall Stewart 
63674fd40c9SRandall Stewart 	/*
63774fd40c9SRandall Stewart 	 * output statistics
63874fd40c9SRandall Stewart 	 */
639ade9ccfeSMarcel Moolenaar 	p(sctps_sendpackets, "\t{:sent-packets/%ju} "
640ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s}\n");
641ade9ccfeSMarcel Moolenaar 	p(sctps_sendsacks, "\t\t{:sent-sacks/%ju} "
642ade9ccfeSMarcel Moolenaar 	    "{N:/output SACK%s}\n");
643ade9ccfeSMarcel Moolenaar 	p(sctps_senddata, "\t\t{:sent-data-chunks/%ju} "
644ade9ccfeSMarcel Moolenaar 	    "{N:/output DATA chunk%s}\n");
645ade9ccfeSMarcel Moolenaar 	p(sctps_sendretransdata, "\t\t{:sent-retransmitted-data-chunks/%ju} "
646ade9ccfeSMarcel Moolenaar 	    "{N:/retransmitted DATA chunk%s}\n");
647ade9ccfeSMarcel Moolenaar 	p(sctps_sendfastretrans, "\t\t"
648ade9ccfeSMarcel Moolenaar 	    "{:sent-fast-retransmitted-data-chunks/%ju} "
649ade9ccfeSMarcel Moolenaar 	    "{N:/fast retransmitted DATA chunk%s}\n");
650ade9ccfeSMarcel Moolenaar 	p(sctps_sendmultfastretrans, "\t\t"
651ade9ccfeSMarcel Moolenaar 	    "{:sent-fast-retransmitted-data-chunk-multiple-times/%ju} "
652ade9ccfeSMarcel Moolenaar 	    "{N:/FR'%s that happened more than once to same chunk}\n");
653ade9ccfeSMarcel Moolenaar 	p(sctps_sendheartbeat, "\t\t{:sent-hb-chunks/%ju} "
654ade9ccfeSMarcel Moolenaar 	    "{N:/output HB chunk%s}\n");
655ade9ccfeSMarcel Moolenaar 	p(sctps_sendecne, "\t\t{:sent-ecne-chunks/%ju} "
656ade9ccfeSMarcel Moolenaar 	    "{N:/output ECNE chunk%s}\n");
657ade9ccfeSMarcel Moolenaar 	p(sctps_sendauth, "\t\t{:sent-auth-chunks/%ju} "
658ade9ccfeSMarcel Moolenaar 	    "{N:/output AUTH chunk%s}\n");
659ade9ccfeSMarcel Moolenaar 	p1a(sctps_senderrors, "\t\t{:send-errors/%ju} "
660ade9ccfeSMarcel Moolenaar 	    "{N:/ip_output error counter}\n");
66174fd40c9SRandall Stewart 
66274fd40c9SRandall Stewart 	/*
66374fd40c9SRandall Stewart 	 * PCKDROPREP statistics
66474fd40c9SRandall Stewart 	 */
665ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Packet drop statistics}:\n");
666ade9ccfeSMarcel Moolenaar 	xo_open_container("drop-statistics");
667ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpfmbox, "\t\t{:middle-box/%ju} "
668ade9ccfeSMarcel Moolenaar 	    "{N:/from middle box}\n");
669ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpfehos, "\t\t{:end-host/%ju} "
670ade9ccfeSMarcel Moolenaar 	    "{N:/from end host}\n");
671ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpmbda, "\t\t{:with-data/%ju} "
672ade9ccfeSMarcel Moolenaar 	    "{N:/with data}\n");
673ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpmbct, "\t\t{:non-data/%ju} "
674ade9ccfeSMarcel Moolenaar 	    "{N:/non-data, non-endhost}\n");
675ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpbwrpt, "\t\t{:non-endhost/%ju} "
676ade9ccfeSMarcel Moolenaar 	    "{N:/non-endhost, bandwidth rep only}\n");
677ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpcrupt, "\t\t{:short-header/%ju} "
678ade9ccfeSMarcel Moolenaar 	    "{N:/not enough for chunk header}\n");
679ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpnedat, "\t\t{:short-data/%ju} "
680ade9ccfeSMarcel Moolenaar 	    "{N:/not enough data to confirm}\n");
681ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrppdbrk, "\t\t{:chunk-break/%ju} "
682ade9ccfeSMarcel Moolenaar 	    "{N:/where process_chunk_drop said break}\n");
683ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrptsnnf, "\t\t{:tsn-not-found/%ju} "
684ade9ccfeSMarcel Moolenaar 	    "{N:/failed to find TSN}\n");
685ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpdnfnd, "\t\t{:reverse-tsn/%ju} "
686ade9ccfeSMarcel Moolenaar 	    "{N:/attempt reverse TSN lookup}\n");
687ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpdiwnp, "\t\t{:confirmed-zero-window/%ju} "
688ade9ccfeSMarcel Moolenaar 	    "{N:/e-host confirms zero-rwnd}\n");
689ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpdizrw, "\t\t{:middle-box-no-space/%ju} "
690ade9ccfeSMarcel Moolenaar 	    "{N:/midbox confirms no space}\n");
691ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpbadd, "\t\t{:bad-data/%ju} "
692ade9ccfeSMarcel Moolenaar 	    "{N:/data did not match TSN}\n");
693ade9ccfeSMarcel Moolenaar 	p(sctps_pdrpmark, "\t\t{:tsn-marked-fast-retransmission/%ju} "
694ade9ccfeSMarcel Moolenaar 	    "{N:/TSN'%s marked for Fast Retran}\n");
695ade9ccfeSMarcel Moolenaar 	xo_close_container("drop-statistics");
69674fd40c9SRandall Stewart 
69774fd40c9SRandall Stewart 	/*
69874fd40c9SRandall Stewart 	 * Timeouts
69974fd40c9SRandall Stewart 	 */
700ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Timeouts}:\n");
701ade9ccfeSMarcel Moolenaar 	xo_open_container("timeouts");
702ade9ccfeSMarcel Moolenaar 	p(sctps_timoiterator, "\t\t{:iterator/%ju} "
703ade9ccfeSMarcel Moolenaar 	    "{N:/iterator timer%s fired}\n");
704ade9ccfeSMarcel Moolenaar 	p(sctps_timodata, "\t\t{:t3-data/%ju} "
705ade9ccfeSMarcel Moolenaar 	    "{N:/T3 data time out%s}\n");
706ade9ccfeSMarcel Moolenaar 	p(sctps_timowindowprobe, "\t\t{:window-probe/%ju} "
707ade9ccfeSMarcel Moolenaar 	    "{N:/window probe (T3) timer%s fired}\n");
708ade9ccfeSMarcel Moolenaar 	p(sctps_timoinit, "\t\t{:init-timer/%ju} "
709ade9ccfeSMarcel Moolenaar 	    "{N:/INIT timer%s fired}\n");
710ade9ccfeSMarcel Moolenaar 	p(sctps_timosack, "\t\t{:sack-timer/%ju} "
711ade9ccfeSMarcel Moolenaar 	    "{N:/sack timer%s fired}\n");
712ade9ccfeSMarcel Moolenaar 	p(sctps_timoshutdown, "\t\t{:shutdown-timer/%ju} "
713ade9ccfeSMarcel Moolenaar 	    "{N:/shutdown timer%s fired}\n");
714ade9ccfeSMarcel Moolenaar 	p(sctps_timoheartbeat, "\t\t{:heartbeat-timer/%ju} "
715ade9ccfeSMarcel Moolenaar 	    "{N:/heartbeat timer%s fired}\n");
716ade9ccfeSMarcel Moolenaar 	p1a(sctps_timocookie, "\t\t{:cookie-timer/%ju} "
717ade9ccfeSMarcel Moolenaar 	    "{N:/a cookie timeout fired}\n");
718ade9ccfeSMarcel Moolenaar 	p1a(sctps_timosecret, "\t\t{:endpoint-changed-cookie/%ju} "
719ade9ccfeSMarcel Moolenaar 	    "{N:/an endpoint changed its cook}ie"
720b8a1761eSRandall Stewart 	    "secret\n");
721ade9ccfeSMarcel Moolenaar 	p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} "
722ade9ccfeSMarcel Moolenaar 	    "{N:/PMTU timer%s fired}\n");
723ade9ccfeSMarcel Moolenaar 	p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} "
724ade9ccfeSMarcel Moolenaar 	    "{N:/shutdown ack timer%s fired}\n");
725ade9ccfeSMarcel Moolenaar 	p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} "
726ade9ccfeSMarcel Moolenaar 	    "{N:/shutdown guard timer%s fired}\n");
727ade9ccfeSMarcel Moolenaar 	p(sctps_timostrmrst, "\t\t{:stream-reset-timer/%ju} "
728ade9ccfeSMarcel Moolenaar 	    "{N:/stream reset timer%s fired}\n");
729ade9ccfeSMarcel Moolenaar 	p(sctps_timoearlyfr, "\t\t{:early-fast-retransmission-timer/%ju} "
730ade9ccfeSMarcel Moolenaar 	    "{N:/early FR timer%s fired}\n");
731ade9ccfeSMarcel Moolenaar 	p1a(sctps_timoasconf, "\t\t{:asconf-timer/%ju} "
732ade9ccfeSMarcel Moolenaar 	    "{N:/an asconf timer fired}\n");
733ade9ccfeSMarcel Moolenaar 	p1a(sctps_timoautoclose, "\t\t{:auto-close-timer/%ju} "
734ade9ccfeSMarcel Moolenaar 	    "{N:/auto close timer fired}\n");
735ade9ccfeSMarcel Moolenaar 	p(sctps_timoassockill, "\t\t{:asoc-free-timer/%ju} "
736ade9ccfeSMarcel Moolenaar 	    "{N:/asoc free timer%s expired}\n");
737ade9ccfeSMarcel Moolenaar 	p(sctps_timoinpkill, "\t\t{:input-free-timer/%ju} "
738ade9ccfeSMarcel Moolenaar 	    "{N:/inp free timer%s expired}\n");
739ade9ccfeSMarcel Moolenaar 	xo_close_container("timeouts");
74074fd40c9SRandall Stewart 
74174fd40c9SRandall Stewart #if 0
74274fd40c9SRandall Stewart 	/*
74374fd40c9SRandall Stewart 	 * Early fast retransmission counters
74474fd40c9SRandall Stewart 	 */
745e5221e8bSRandall Stewart 	p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n");
746e5221e8bSRandall Stewart 	p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n");
747e5221e8bSRandall Stewart 	p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n");
748e5221e8bSRandall Stewart 	p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n");
749e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n");
750e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n");
751e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n");
752e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n");
753e5221e8bSRandall Stewart 	p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n");
754e5221e8bSRandall Stewart 	p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n");
755e5221e8bSRandall Stewart 	p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n");
75674fd40c9SRandall Stewart #endif
75774fd40c9SRandall Stewart 
75874fd40c9SRandall Stewart 	/*
75974fd40c9SRandall Stewart 	 * Others
76074fd40c9SRandall Stewart 	 */
761ade9ccfeSMarcel Moolenaar 	p1a(sctps_hdrops, "\t{:dropped-too-short/%ju} "
762ade9ccfeSMarcel Moolenaar 	    "{N:/packet shorter than header}\n");
763ade9ccfeSMarcel Moolenaar 	p1a(sctps_badsum, "\t{:dropped-bad-checksum/%ju} "
764ade9ccfeSMarcel Moolenaar 	    "{N:/checksum error}\n");
765ade9ccfeSMarcel Moolenaar 	p1a(sctps_noport, "\t{:dropped-no-endpoint/%ju} "
766ade9ccfeSMarcel Moolenaar 	    "{N:/no endpoint for port}\n");
767ade9ccfeSMarcel Moolenaar 	p1a(sctps_badvtag, "\t{:dropped-bad-v-tag/%ju} "
768ade9ccfeSMarcel Moolenaar 	    "{N:/bad v-tag}\n");
769ade9ccfeSMarcel Moolenaar 	p1a(sctps_badsid, "\t{:dropped-bad-sid/%ju} "
770ade9ccfeSMarcel Moolenaar 	    "{N:/bad SID}\n");
771ade9ccfeSMarcel Moolenaar 	p1a(sctps_nomem, "\t{:dropped-no-memory/%ju} "
772ade9ccfeSMarcel Moolenaar 	    "{N:/no memory}\n");
773ade9ccfeSMarcel Moolenaar 	p1a(sctps_fastretransinrtt, "\t{:multiple-fast-retransmits-in-rtt/%ju} "
774ade9ccfeSMarcel Moolenaar 	    "{N:/number of multiple FR in a RT}T window\n");
77574fd40c9SRandall Stewart #if 0
776e5221e8bSRandall Stewart 	p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n");
77774fd40c9SRandall Stewart #endif
778ade9ccfeSMarcel Moolenaar 	p1a(sctps_naglesent, "\t{:rfc813-sent/%ju} "
779ade9ccfeSMarcel Moolenaar 	    "{N:/RFC813 allowed sending}\n");
780ade9ccfeSMarcel Moolenaar 	p1a(sctps_naglequeued, "\t{:rfc813-queued/%ju} "
781ade9ccfeSMarcel Moolenaar 	    "{N:/RFC813 does not allow sending}\n");
782ade9ccfeSMarcel Moolenaar 	p1a(sctps_maxburstqueued, "\t{:max-burst-queued/%ju} "
783ade9ccfeSMarcel Moolenaar 	    "{N:/times max burst prohibited sending}\n");
784ade9ccfeSMarcel Moolenaar 	p1a(sctps_ifnomemqueued, "\t{:no-memory-in-interface/%ju} "
785ade9ccfeSMarcel Moolenaar 	    "{N:/look ahead tells us no memory in interface}\n");
786ade9ccfeSMarcel Moolenaar 	p(sctps_windowprobed, "\t{:sent-window-probes/%ju} "
787ade9ccfeSMarcel Moolenaar 	    "{N:/number%s of window probes sent}\n");
788ade9ccfeSMarcel Moolenaar 	p(sctps_lowlevelerr, "\t{:low-level-err/%ju} "
789ade9ccfeSMarcel Moolenaar 	    "{N:/time%s an output error to clamp down on next user send}\n");
790ade9ccfeSMarcel Moolenaar 	p(sctps_lowlevelerrusr, "\t{:low-level-user-error/%ju} "
791ade9ccfeSMarcel Moolenaar 	    "{N:/time%s sctp_senderrors were caused from a user}\n");
792ade9ccfeSMarcel Moolenaar 	p(sctps_datadropchklmt, "\t{:dropped-chunk-limit/%ju} "
793ade9ccfeSMarcel Moolenaar 	    "{N:/number of in data drop%s due to chunk limit reached}\n");
794ade9ccfeSMarcel Moolenaar 	p(sctps_datadroprwnd, "\t{:dropped-rwnd-limit/%ju} "
795ade9ccfeSMarcel Moolenaar 	    "{N:/number of in data drop%s due to rwnd limit reached}\n");
796ade9ccfeSMarcel Moolenaar 	p(sctps_ecnereducedcwnd, "\t{:ecn-reduced-cwnd/%ju} "
797ade9ccfeSMarcel Moolenaar 	    "{N:/time%s a ECN reduced the cwnd}\n");
798ade9ccfeSMarcel Moolenaar 	p1a(sctps_vtagexpress, "\t{:v-tag-express-lookup/%ju} "
799ade9ccfeSMarcel Moolenaar 	    "{N:/used express lookup via vtag}\n");
800ade9ccfeSMarcel Moolenaar 	p1a(sctps_vtagbogus, "\t{:v-tag-collision/%ju} "
801ade9ccfeSMarcel Moolenaar 	    "{N:/collision in express lookup}\n");
802ade9ccfeSMarcel Moolenaar 	p(sctps_primary_randry, "\t{:sender-ran-dry/%ju} "
803ade9ccfeSMarcel Moolenaar 	    "{N:/time%s the sender ran dry of user data on primary}\n");
804ade9ccfeSMarcel Moolenaar 	p1a(sctps_cmt_randry, "\t{:cmt-ran-dry/%ju} "
805ade9ccfeSMarcel Moolenaar 	    "{N:/same for above}\n");
806ade9ccfeSMarcel Moolenaar 	p(sctps_slowpath_sack, "\t{:slow-path-sack/%ju} "
807ade9ccfeSMarcel Moolenaar 	    "{N:/sack%s the slow way}\n");
808ade9ccfeSMarcel Moolenaar 	p(sctps_wu_sacks_sent, "\t{:sent-window-update-only-sack/%ju} "
809ade9ccfeSMarcel Moolenaar 	    "{N:/window update only sack%s sent}\n");
810ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_flags, "\t{:sent-with-sinfo/%ju} "
811ade9ccfeSMarcel Moolenaar 	    "{N:/send%s with sinfo_flags !=0}\n");
812ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_unord, "\t{:sent-with-unordered/%ju} "
813ade9ccfeSMarcel Moolenaar 	    "{N:/unordered send%s}\n");
814ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_eof, "\t{:sent-with-eof/%ju} "
815ade9ccfeSMarcel Moolenaar 	    "{N:/send%s with EOF flag set}\n");
816ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_abort, "\t{:sent-with-abort/%ju} "
817ade9ccfeSMarcel Moolenaar 	    "{N:/send%s with ABORT flag set}\n");
818ade9ccfeSMarcel Moolenaar 	p(sctps_protocol_drain_calls, "\t{:protocol-drain-called/%ju} "
819ade9ccfeSMarcel Moolenaar 	    "{N:/time%s protocol drain called}\n");
820ade9ccfeSMarcel Moolenaar 	p(sctps_protocol_drains_done, "\t{:protocol-drain/%ju} "
821ade9ccfeSMarcel Moolenaar 	    "{N:/time%s we did a protocol drain}\n");
822ade9ccfeSMarcel Moolenaar 	p(sctps_read_peeks, "\t{:read-with-peek/%ju} "
823ade9ccfeSMarcel Moolenaar 	    "{N:/time%s recv was called with peek}\n");
824ade9ccfeSMarcel Moolenaar 	p(sctps_cached_chk, "\t{:cached-chunks/%ju} "
825ade9ccfeSMarcel Moolenaar 	    "{N:/cached chunk%s used}\n");
826ade9ccfeSMarcel Moolenaar 	p1a(sctps_cached_strmoq, "\t{:cached-output-queue-used/%ju} "
827ade9ccfeSMarcel Moolenaar 	    "{N:/cached stream oq's used}\n");
828ade9ccfeSMarcel Moolenaar 	p(sctps_left_abandon, "\t{:messages-abandoned/%ju} "
829ade9ccfeSMarcel Moolenaar 	    "{N:/unread message%s abandonded by close}\n");
830ade9ccfeSMarcel Moolenaar 	p1a(sctps_send_burst_avoid, "\t{:send-burst-avoidance/%ju} "
831ade9ccfeSMarcel Moolenaar 	    "{N:/send burst avoidance, already max burst inflight to net}\n");
832ade9ccfeSMarcel Moolenaar 	p1a(sctps_send_cwnd_avoid, "\t{:send-cwnd-avoidance/%ju} "
833ade9ccfeSMarcel Moolenaar 	    "{N:/send cwnd full avoidance, already max burst inflight "
834ade9ccfeSMarcel Moolenaar 	    "to net}\n");
835ade9ccfeSMarcel Moolenaar 	p(sctps_fwdtsn_map_over, "\t{:tsn-map-overruns/%ju} "
836ade9ccfeSMarcel Moolenaar 	   "{N:/number of map array over-run%s via fwd-tsn's}\n");
837b8a1761eSRandall Stewart 
838b8a1761eSRandall Stewart #undef p
839b8a1761eSRandall Stewart #undef p1a
840ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
84174fd40c9SRandall Stewart }
84274fd40c9SRandall Stewart 
84374fd40c9SRandall Stewart #endif /* SCTP */
844