xref: /freebsd/usr.bin/netstat/sctp.c (revision 5e3934b1)
174fd40c9SRandall Stewart /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro 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 #include <sys/param.h>
3574fd40c9SRandall Stewart #include <sys/queue.h>
3674fd40c9SRandall Stewart #include <sys/types.h>
3774fd40c9SRandall Stewart #include <sys/socket.h>
3874fd40c9SRandall Stewart #include <sys/socketvar.h>
3974fd40c9SRandall Stewart #include <sys/sysctl.h>
4074fd40c9SRandall Stewart #include <sys/protosw.h>
4174fd40c9SRandall Stewart 
4274fd40c9SRandall Stewart #include <netinet/in.h>
4374fd40c9SRandall Stewart #include <netinet/sctp.h>
4474fd40c9SRandall Stewart #include <netinet/sctp_constants.h>
4574fd40c9SRandall Stewart #include <arpa/inet.h>
4674fd40c9SRandall Stewart 
4774fd40c9SRandall Stewart #include <err.h>
4874fd40c9SRandall Stewart #include <errno.h>
49821df508SXin LI #include <libutil.h>
50821df508SXin LI #include <netdb.h>
5174fd40c9SRandall Stewart #include <stdint.h>
5274fd40c9SRandall Stewart #include <stdio.h>
5374fd40c9SRandall Stewart #include <stdlib.h>
54ade9ccfeSMarcel Moolenaar #include <stdbool.h>
5574fd40c9SRandall Stewart #include <string.h>
56821df508SXin LI #include <unistd.h>
5774fd40c9SRandall Stewart #include "netstat.h"
58ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
5974fd40c9SRandall Stewart 
6074fd40c9SRandall Stewart #ifdef SCTP
6174fd40c9SRandall Stewart 
6274fd40c9SRandall Stewart static void sctp_statesprint(uint32_t state);
6374fd40c9SRandall Stewart 
6474fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_CLOSED		0x0
6574fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_BOUND		0x1
6674fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_LISTEN		0x2
6774fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_COOKIE_WAIT		0x3
6874fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_COOKIE_ECHOED	0x4
6974fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_ESTABLISHED		0x5
7074fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_SENT	0x6
7174fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED	0x7
7274fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT	0x8
7374fd40c9SRandall Stewart #define	NETSTAT_SCTP_STATES_SHUTDOWN_PENDING	0x9
7474fd40c9SRandall Stewart 
7510d5269fSHiroki Sato static const char *sctpstates[] = {
7674fd40c9SRandall Stewart 	"CLOSED",
7774fd40c9SRandall Stewart 	"BOUND",
7874fd40c9SRandall Stewart 	"LISTEN",
7974fd40c9SRandall Stewart 	"COOKIE_WAIT",
8074fd40c9SRandall Stewart 	"COOKIE_ECHOED",
8174fd40c9SRandall Stewart 	"ESTABLISHED",
8274fd40c9SRandall Stewart 	"SHUTDOWN_SENT",
8374fd40c9SRandall Stewart 	"SHUTDOWN_RECEIVED",
8474fd40c9SRandall Stewart 	"SHUTDOWN_ACK_SENT",
8574fd40c9SRandall Stewart 	"SHUTDOWN_PENDING"
8674fd40c9SRandall Stewart };
8774fd40c9SRandall Stewart 
8810d5269fSHiroki Sato static LIST_HEAD(xladdr_list, xladdr_entry) xladdr_head;
8974fd40c9SRandall Stewart struct xladdr_entry {
9074fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
9174fd40c9SRandall Stewart 	LIST_ENTRY(xladdr_entry) xladdr_entries;
9274fd40c9SRandall Stewart };
9374fd40c9SRandall Stewart 
9410d5269fSHiroki Sato static LIST_HEAD(xraddr_list, xraddr_entry) xraddr_head;
9574fd40c9SRandall Stewart struct xraddr_entry {
9674fd40c9SRandall Stewart 	struct xsctp_raddr *xraddr;
9774fd40c9SRandall Stewart 	LIST_ENTRY(xraddr_entry) xraddr_entries;
9874fd40c9SRandall Stewart };
9974fd40c9SRandall Stewart 
1002e34c19bSMichael Tuexen static void
sctp_print_address(const char * container,union sctp_sockstore * address,int port,int num_port)101ade9ccfeSMarcel Moolenaar sctp_print_address(const char *container, union sctp_sockstore *address,
102ade9ccfeSMarcel Moolenaar     int port, int num_port)
1032e34c19bSMichael Tuexen {
1042e34c19bSMichael Tuexen 	struct servent *sp = 0;
1052e34c19bSMichael Tuexen 	char line[80], *cp;
1062e34c19bSMichael Tuexen 	int width;
107f193c8ceSXin LI 	size_t alen, plen;
1082e34c19bSMichael Tuexen 
109ade9ccfeSMarcel Moolenaar 	if (container)
110ade9ccfeSMarcel Moolenaar 		xo_open_container(container);
111ade9ccfeSMarcel Moolenaar 
1122e34c19bSMichael Tuexen 	switch (address->sa.sa_family) {
1133dcc856bSMichael Tuexen #ifdef INET
1142e34c19bSMichael Tuexen 	case AF_INET:
115f193c8ceSXin LI 		snprintf(line, sizeof(line), "%.*s.",
116f193c8ceSXin LI 		    Wflag ? 39 : 16, inetname(&address->sin.sin_addr));
1172e34c19bSMichael Tuexen 		break;
1183dcc856bSMichael Tuexen #endif
1192e34c19bSMichael Tuexen #ifdef INET6
1202e34c19bSMichael Tuexen 	case AF_INET6:
121f193c8ceSXin LI 		snprintf(line, sizeof(line), "%.*s.",
122f193c8ceSXin LI 		    Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr));
1232e34c19bSMichael Tuexen 		break;
1242e34c19bSMichael Tuexen #endif
1252e34c19bSMichael Tuexen 	default:
126f193c8ceSXin LI 		snprintf(line, sizeof(line), "%.*s.",
127f193c8ceSXin LI 		    Wflag ? 39 : 16, "");
1282e34c19bSMichael Tuexen 		break;
1292e34c19bSMichael Tuexen 	}
130f193c8ceSXin LI 	alen = strlen(line);
131f193c8ceSXin LI 	cp = line + alen;
1322e34c19bSMichael Tuexen 	if (!num_port && port)
1332e34c19bSMichael Tuexen 		sp = getservbyport((int)port, "sctp");
1342e34c19bSMichael Tuexen 	if (sp || port == 0)
135f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
136f193c8ceSXin LI 		    "%.15s ", sp ? sp->s_name : "*");
1372e34c19bSMichael Tuexen 	else
138f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
139f193c8ceSXin LI 		    "%d ", ntohs((u_short)port));
1402e34c19bSMichael Tuexen 	width = Wflag ? 45 : 22;
141ade9ccfeSMarcel Moolenaar 	xo_emit("{d:target/%-*.*s} ", width, width, line);
142ade9ccfeSMarcel Moolenaar 
143f193c8ceSXin LI 	plen = strlen(cp) - 1;
144f193c8ceSXin LI 	alen--;
145ade9ccfeSMarcel Moolenaar 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
146ade9ccfeSMarcel Moolenaar 	    plen, cp);
147ade9ccfeSMarcel Moolenaar 
148ade9ccfeSMarcel Moolenaar 	if (container)
149ade9ccfeSMarcel Moolenaar 		xo_close_container(container);
1502e34c19bSMichael Tuexen }
1512e34c19bSMichael Tuexen 
15274fd40c9SRandall Stewart static int
sctp_skip_xinpcb_ifneed(char * buf,const size_t buflen,size_t * offset)15374fd40c9SRandall Stewart sctp_skip_xinpcb_ifneed(char *buf, const size_t buflen, size_t *offset)
15474fd40c9SRandall Stewart {
15574fd40c9SRandall Stewart 	int exist_tcb = 0;
15674fd40c9SRandall Stewart 	struct xsctp_tcb *xstcb;
15774fd40c9SRandall Stewart 	struct xsctp_raddr *xraddr;
15874fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
15974fd40c9SRandall Stewart 
16074fd40c9SRandall Stewart 	while (*offset < buflen) {
16174fd40c9SRandall Stewart 		xladdr = (struct xsctp_laddr *)(buf + *offset);
16274fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_laddr);
16374fd40c9SRandall Stewart 		if (xladdr->last == 1)
16474fd40c9SRandall Stewart 			break;
16574fd40c9SRandall Stewart 	}
16674fd40c9SRandall Stewart 
16774fd40c9SRandall Stewart 	while (*offset < buflen) {
16874fd40c9SRandall Stewart 		xstcb = (struct xsctp_tcb *)(buf + *offset);
16974fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_tcb);
17074fd40c9SRandall Stewart 		if (xstcb->last == 1)
17174fd40c9SRandall Stewart 			break;
17274fd40c9SRandall Stewart 
17374fd40c9SRandall Stewart 		exist_tcb = 1;
17474fd40c9SRandall Stewart 
17574fd40c9SRandall Stewart 		while (*offset < buflen) {
17674fd40c9SRandall Stewart 			xladdr = (struct xsctp_laddr *)(buf + *offset);
17774fd40c9SRandall Stewart 			*offset += sizeof(struct xsctp_laddr);
17874fd40c9SRandall Stewart 			if (xladdr->last == 1)
17974fd40c9SRandall Stewart 				break;
18074fd40c9SRandall Stewart 		}
18174fd40c9SRandall Stewart 
18274fd40c9SRandall Stewart 		while (*offset < buflen) {
18374fd40c9SRandall Stewart 			xraddr = (struct xsctp_raddr *)(buf + *offset);
18474fd40c9SRandall Stewart 			*offset += sizeof(struct xsctp_raddr);
18574fd40c9SRandall Stewart 			if (xraddr->last == 1)
18674fd40c9SRandall Stewart 				break;
18774fd40c9SRandall Stewart 		}
18874fd40c9SRandall Stewart 	}
18974fd40c9SRandall Stewart 
19074fd40c9SRandall Stewart 	/*
19174fd40c9SRandall Stewart 	 * If Lflag is set, we don't care about the return value.
19274fd40c9SRandall Stewart 	 */
19374fd40c9SRandall Stewart 	if (Lflag)
19474fd40c9SRandall Stewart 		return 0;
19574fd40c9SRandall Stewart 
19674fd40c9SRandall Stewart 	return exist_tcb;
19774fd40c9SRandall Stewart }
19874fd40c9SRandall Stewart 
19974fd40c9SRandall Stewart static void
sctp_process_tcb(struct xsctp_tcb * xstcb,char * buf,const size_t buflen,size_t * offset,int * indent)2002e34c19bSMichael Tuexen sctp_process_tcb(struct xsctp_tcb *xstcb,
20174fd40c9SRandall Stewart     char *buf, const size_t buflen, size_t *offset, int *indent)
20274fd40c9SRandall Stewart {
20374fd40c9SRandall Stewart 	int i, xl_total = 0, xr_total = 0, x_max;
20474fd40c9SRandall Stewart 	struct xsctp_raddr *xraddr;
20574fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
20674fd40c9SRandall Stewart 	struct xladdr_entry *prev_xl = NULL, *xl = NULL, *xl_tmp;
20774fd40c9SRandall Stewart 	struct xraddr_entry *prev_xr = NULL, *xr = NULL, *xr_tmp;
20874fd40c9SRandall Stewart 
20974fd40c9SRandall Stewart 	LIST_INIT(&xladdr_head);
21074fd40c9SRandall Stewart 	LIST_INIT(&xraddr_head);
21174fd40c9SRandall Stewart 
21274fd40c9SRandall Stewart 	/*
21374fd40c9SRandall Stewart 	 * Make `struct xladdr_list' list and `struct xraddr_list' list
21474fd40c9SRandall Stewart 	 * to handle the address flexibly.
21574fd40c9SRandall Stewart 	 */
21674fd40c9SRandall Stewart 	while (*offset < buflen) {
21774fd40c9SRandall Stewart 		xladdr = (struct xsctp_laddr *)(buf + *offset);
21874fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_laddr);
21974fd40c9SRandall Stewart 		if (xladdr->last == 1)
22074fd40c9SRandall Stewart 			break;
22174fd40c9SRandall Stewart 
22274fd40c9SRandall Stewart 		prev_xl = xl;
22374fd40c9SRandall Stewart 		xl = malloc(sizeof(struct xladdr_entry));
22474fd40c9SRandall Stewart 		if (xl == NULL) {
225ade9ccfeSMarcel Moolenaar 			xo_warnx("malloc %lu bytes",
22674fd40c9SRandall Stewart 			    (u_long)sizeof(struct xladdr_entry));
22774fd40c9SRandall Stewart 			goto out;
22874fd40c9SRandall Stewart 		}
22974fd40c9SRandall Stewart 		xl->xladdr = xladdr;
23074fd40c9SRandall Stewart 		if (prev_xl == NULL)
23174fd40c9SRandall Stewart 			LIST_INSERT_HEAD(&xladdr_head, xl, xladdr_entries);
23274fd40c9SRandall Stewart 		else
23374fd40c9SRandall Stewart 			LIST_INSERT_AFTER(prev_xl, xl, xladdr_entries);
23474fd40c9SRandall Stewart 		xl_total++;
23574fd40c9SRandall Stewart 	}
23674fd40c9SRandall Stewart 
23774fd40c9SRandall Stewart 	while (*offset < buflen) {
23874fd40c9SRandall Stewart 		xraddr = (struct xsctp_raddr *)(buf + *offset);
23974fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_raddr);
24074fd40c9SRandall Stewart 		if (xraddr->last == 1)
24174fd40c9SRandall Stewart 			break;
24274fd40c9SRandall Stewart 
24374fd40c9SRandall Stewart 		prev_xr = xr;
24474fd40c9SRandall Stewart 		xr = malloc(sizeof(struct xraddr_entry));
24574fd40c9SRandall Stewart 		if (xr == NULL) {
246ade9ccfeSMarcel Moolenaar 			xo_warnx("malloc %lu bytes",
24774fd40c9SRandall Stewart 			    (u_long)sizeof(struct xraddr_entry));
24874fd40c9SRandall Stewart 			goto out;
24974fd40c9SRandall Stewart 		}
25074fd40c9SRandall Stewart 		xr->xraddr = xraddr;
25174fd40c9SRandall Stewart 		if (prev_xr == NULL)
25274fd40c9SRandall Stewart 			LIST_INSERT_HEAD(&xraddr_head, xr, xraddr_entries);
25374fd40c9SRandall Stewart 		else
25474fd40c9SRandall Stewart 			LIST_INSERT_AFTER(prev_xr, xr, xraddr_entries);
25574fd40c9SRandall Stewart 		xr_total++;
25674fd40c9SRandall Stewart 	}
25774fd40c9SRandall Stewart 
25874fd40c9SRandall Stewart 	/*
25974fd40c9SRandall Stewart 	 * Let's print the address infos.
26074fd40c9SRandall Stewart 	 */
261ade9ccfeSMarcel Moolenaar 	xo_open_list("address");
26274fd40c9SRandall Stewart 	xl = LIST_FIRST(&xladdr_head);
26374fd40c9SRandall Stewart 	xr = LIST_FIRST(&xraddr_head);
264fcc0131fSMarcelo Araujo 	x_max = MAX(xl_total, xr_total);
26574fd40c9SRandall Stewart 	for (i = 0; i < x_max; i++) {
266ade9ccfeSMarcel Moolenaar 		xo_open_instance("address");
267ade9ccfeSMarcel Moolenaar 
26874fd40c9SRandall Stewart 		if (((*indent == 0) && i > 0) || *indent > 0)
269ade9ccfeSMarcel Moolenaar 			xo_emit("{P:/%-12s} ", " ");
27074fd40c9SRandall Stewart 
27174fd40c9SRandall Stewart 		if (xl != NULL) {
272ade9ccfeSMarcel Moolenaar 			sctp_print_address("local", &(xl->xladdr->address),
2732e34c19bSMichael Tuexen 			    htons(xstcb->local_port), numeric_port);
2742e34c19bSMichael Tuexen 		} else {
2752e34c19bSMichael Tuexen 			if (Wflag) {
276ade9ccfeSMarcel Moolenaar 				xo_emit("{P:/%-45s} ", " ");
2772e34c19bSMichael Tuexen 			} else {
278ade9ccfeSMarcel Moolenaar 				xo_emit("{P:/%-22s} ", " ");
27974fd40c9SRandall Stewart 			}
28074fd40c9SRandall Stewart 		}
28174fd40c9SRandall Stewart 
28274fd40c9SRandall Stewart 		if (xr != NULL && !Lflag) {
283ade9ccfeSMarcel Moolenaar 			sctp_print_address("remote", &(xr->xraddr->address),
2842e34c19bSMichael Tuexen 			    htons(xstcb->remote_port), numeric_port);
28574fd40c9SRandall Stewart 		}
28674fd40c9SRandall Stewart 
28774fd40c9SRandall Stewart 		if (xl != NULL)
28874fd40c9SRandall Stewart 			xl = LIST_NEXT(xl, xladdr_entries);
28974fd40c9SRandall Stewart 		if (xr != NULL)
29074fd40c9SRandall Stewart 			xr = LIST_NEXT(xr, xraddr_entries);
29174fd40c9SRandall Stewart 
29274fd40c9SRandall Stewart 		if (i == 0 && !Lflag)
29374fd40c9SRandall Stewart 			sctp_statesprint(xstcb->state);
29474fd40c9SRandall Stewart 
29574fd40c9SRandall Stewart 		if (i < x_max)
296ade9ccfeSMarcel Moolenaar 			xo_emit("\n");
297ade9ccfeSMarcel Moolenaar 		xo_close_instance("address");
29874fd40c9SRandall Stewart 	}
29974fd40c9SRandall Stewart 
30074fd40c9SRandall Stewart out:
30174fd40c9SRandall Stewart 	/*
30274fd40c9SRandall Stewart 	 * Free the list which be used to handle the address.
30374fd40c9SRandall Stewart 	 */
30474fd40c9SRandall Stewart 	xl = LIST_FIRST(&xladdr_head);
30574fd40c9SRandall Stewart 	while (xl != NULL) {
30674fd40c9SRandall Stewart 		xl_tmp = LIST_NEXT(xl, xladdr_entries);
30774fd40c9SRandall Stewart 		free(xl);
30874fd40c9SRandall Stewart 		xl = xl_tmp;
30974fd40c9SRandall Stewart 	}
31074fd40c9SRandall Stewart 
31174fd40c9SRandall Stewart 	xr = LIST_FIRST(&xraddr_head);
31274fd40c9SRandall Stewart 	while (xr != NULL) {
31374fd40c9SRandall Stewart 		xr_tmp = LIST_NEXT(xr, xraddr_entries);
31474fd40c9SRandall Stewart 		free(xr);
31574fd40c9SRandall Stewart 		xr = xr_tmp;
31674fd40c9SRandall Stewart 	}
31774fd40c9SRandall Stewart }
31874fd40c9SRandall Stewart 
31974fd40c9SRandall Stewart static void
sctp_process_inpcb(struct xsctp_inpcb * xinpcb,char * buf,const size_t buflen,size_t * offset)3202e34c19bSMichael Tuexen sctp_process_inpcb(struct xsctp_inpcb *xinpcb,
32174fd40c9SRandall Stewart     char *buf, const size_t buflen, size_t *offset)
32274fd40c9SRandall Stewart {
3232e34c19bSMichael Tuexen 	int indent = 0, xladdr_total = 0, is_listening = 0;
32474fd40c9SRandall Stewart 	static int first = 1;
325321ae07fSPhilippe Charnier 	const char *tname, *pname;
32674fd40c9SRandall Stewart 	struct xsctp_tcb *xstcb;
32774fd40c9SRandall Stewart 	struct xsctp_laddr *xladdr;
3282e34c19bSMichael Tuexen 	size_t offset_laddr;
3292e34c19bSMichael Tuexen 	int process_closed;
33074fd40c9SRandall Stewart 
3312e34c19bSMichael Tuexen 	if (xinpcb->maxqlen > 0)
33274fd40c9SRandall Stewart 		is_listening = 1;
33374fd40c9SRandall Stewart 
33474fd40c9SRandall Stewart 	if (first) {
33574fd40c9SRandall Stewart 		if (!Lflag) {
336ade9ccfeSMarcel Moolenaar 			xo_emit("Active SCTP associations");
33774fd40c9SRandall Stewart 			if (aflag)
338ade9ccfeSMarcel Moolenaar 				xo_emit(" (including servers)");
33974fd40c9SRandall Stewart 		} else
340ade9ccfeSMarcel Moolenaar 			xo_emit("Current listen queue sizes (qlen/maxqlen)");
341ade9ccfeSMarcel Moolenaar 		xo_emit("\n");
34274fd40c9SRandall Stewart 		if (Lflag)
343ade9ccfeSMarcel Moolenaar 			xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-8.8s} "
344ade9ccfeSMarcel Moolenaar 			    "{T:/%-22.22s}\n",
34574fd40c9SRandall Stewart 			    "Proto", "Type", "Listen", "Local Address");
34674fd40c9SRandall Stewart 		else
3472e34c19bSMichael Tuexen 			if (Wflag)
348ade9ccfeSMarcel Moolenaar 				xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-45.45s} "
349ade9ccfeSMarcel Moolenaar 				    "{T:/%-45.45s} {T:/%s}\n",
3502e34c19bSMichael Tuexen 				    "Proto", "Type",
3512e34c19bSMichael Tuexen 				    "Local Address", "Foreign Address",
3522e34c19bSMichael Tuexen 				    "(state)");
3532e34c19bSMichael Tuexen 			else
354ade9ccfeSMarcel Moolenaar 				xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-22.22s} "
355ade9ccfeSMarcel Moolenaar 				    "{T:/%-22.22s} {T:/%s}\n",
35674fd40c9SRandall Stewart 				    "Proto", "Type",
35774fd40c9SRandall Stewart 				    "Local Address", "Foreign Address",
35874fd40c9SRandall Stewart 				    "(state)");
35974fd40c9SRandall Stewart 		first = 0;
36074fd40c9SRandall Stewart 	}
3612e34c19bSMichael Tuexen 	xladdr = (struct xsctp_laddr *)(buf + *offset);
362ca658db3SMichael Tuexen 	if ((!aflag && is_listening) ||
363ca658db3SMichael Tuexen 	    (Lflag && !is_listening)) {
36493f8854cSDimitry Andric 		sctp_skip_xinpcb_ifneed(buf, buflen, offset);
36574fd40c9SRandall Stewart 		return;
36674fd40c9SRandall Stewart 	}
36774fd40c9SRandall Stewart 
3682e34c19bSMichael Tuexen 	if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) {
3692e34c19bSMichael Tuexen 		/* Can't distinguish between sctp46 and sctp6 */
3702e34c19bSMichael Tuexen 		pname = "sctp46";
3712e34c19bSMichael Tuexen 	} else {
3722e34c19bSMichael Tuexen 		pname = "sctp4";
3732e34c19bSMichael Tuexen 	}
37474fd40c9SRandall Stewart 
37574fd40c9SRandall Stewart 	if (xinpcb->flags & SCTP_PCB_FLAGS_TCPTYPE)
37674fd40c9SRandall Stewart 		tname = "1to1";
37774fd40c9SRandall Stewart 	else if (xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE)
37874fd40c9SRandall Stewart 		tname = "1toN";
37974fd40c9SRandall Stewart 	else
3802e34c19bSMichael Tuexen 		tname = "????";
38174fd40c9SRandall Stewart 
38274fd40c9SRandall Stewart 	if (Lflag) {
3837325dfbbSAlfred Perlstein 		char buf1[22];
38474fd40c9SRandall Stewart 
3857325dfbbSAlfred Perlstein 		snprintf(buf1, sizeof buf1, "%u/%u",
3867325dfbbSAlfred Perlstein 		    xinpcb->qlen, xinpcb->maxqlen);
387ade9ccfeSMarcel Moolenaar 		xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
388ade9ccfeSMarcel Moolenaar 		    pname, tname);
389ade9ccfeSMarcel Moolenaar 		xo_emit("{d:queues/%-8.8s}{e:queue-len/%hu}"
390ade9ccfeSMarcel Moolenaar 		    "{e:max-queue-len/%hu} ",
391ade9ccfeSMarcel Moolenaar 		    buf1, xinpcb->qlen, xinpcb->maxqlen);
39274fd40c9SRandall Stewart 	}
3932e34c19bSMichael Tuexen 
3942e34c19bSMichael Tuexen 	offset_laddr = *offset;
3952e34c19bSMichael Tuexen 	process_closed = 0;
396ade9ccfeSMarcel Moolenaar 
397ade9ccfeSMarcel Moolenaar 	xo_open_list("local-address");
3982e34c19bSMichael Tuexen retry:
39974fd40c9SRandall Stewart 	while (*offset < buflen) {
40074fd40c9SRandall Stewart 		xladdr = (struct xsctp_laddr *)(buf + *offset);
40174fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_laddr);
4022e34c19bSMichael Tuexen 		if (xladdr->last) {
4032e34c19bSMichael Tuexen 			if (aflag && !Lflag && (xladdr_total == 0) && process_closed) {
404ade9ccfeSMarcel Moolenaar 				xo_open_instance("local-address");
405ade9ccfeSMarcel Moolenaar 
406ade9ccfeSMarcel Moolenaar 				xo_emit("{:protocol/%-6.6s/%s} "
407ade9ccfeSMarcel Moolenaar 				    "{:type/%-5.5s/%s} ", pname, tname);
4082e34c19bSMichael Tuexen 				if (Wflag) {
409ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-91.91s/%s} "
410ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4112e34c19bSMichael Tuexen 				} else {
412ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-45.45s/%s} "
413ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4142e34c19bSMichael Tuexen 				}
415ade9ccfeSMarcel Moolenaar 				xo_close_instance("local-address");
4162e34c19bSMichael Tuexen 			}
4172e34c19bSMichael Tuexen 			if (process_closed || is_listening) {
418ade9ccfeSMarcel Moolenaar 				xo_emit("\n");
4192e34c19bSMichael Tuexen 			}
42074fd40c9SRandall Stewart 			break;
4212e34c19bSMichael Tuexen 		}
42274fd40c9SRandall Stewart 
4232e34c19bSMichael Tuexen 		if (!Lflag && !is_listening && !process_closed)
42474fd40c9SRandall Stewart 			continue;
42574fd40c9SRandall Stewart 
426ade9ccfeSMarcel Moolenaar 		xo_open_instance("local-address");
427ade9ccfeSMarcel Moolenaar 
4282e34c19bSMichael Tuexen 		if (xladdr_total == 0) {
429ca658db3SMichael Tuexen 			if (!Lflag) {
430ca658db3SMichael Tuexen 				xo_emit("{:protocol/%-6.6s/%s} "
431ca658db3SMichael Tuexen 				    "{:type/%-5.5s/%s} ", pname, tname);
432ca658db3SMichael Tuexen 			}
4332e34c19bSMichael Tuexen 		} else {
434ade9ccfeSMarcel Moolenaar 			xo_emit("\n");
435ade9ccfeSMarcel Moolenaar 			xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ",
436ade9ccfeSMarcel Moolenaar 			    " ");
43774fd40c9SRandall Stewart 		}
438ade9ccfeSMarcel Moolenaar 		sctp_print_address("local", &(xladdr->address),
4392e34c19bSMichael Tuexen 		    htons(xinpcb->local_port), numeric_port);
4402e34c19bSMichael Tuexen 		if (aflag && !Lflag && xladdr_total == 0) {
4412e34c19bSMichael Tuexen 			if (Wflag) {
4422e34c19bSMichael Tuexen 				if (process_closed) {
443ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-45.45s} "
444ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4452e34c19bSMichael Tuexen 				} else {
446ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-45.45s} "
447282d1dd7SMichael Tuexen 					    "{:state/LISTEN}", " ");
4482e34c19bSMichael Tuexen 				}
4492e34c19bSMichael Tuexen 			} else {
4502e34c19bSMichael Tuexen 				if (process_closed) {
451ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-22.22s} "
452ade9ccfeSMarcel Moolenaar 					    "{:state/CLOSED}", " ");
4532e34c19bSMichael Tuexen 				} else {
454ade9ccfeSMarcel Moolenaar 					xo_emit("{P:/%-22.22s} "
455ade9ccfeSMarcel Moolenaar 					    "{:state/LISTEN}", " ");
4562e34c19bSMichael Tuexen 				}
4572e34c19bSMichael Tuexen 			}
4582e34c19bSMichael Tuexen 		}
45974fd40c9SRandall Stewart 		xladdr_total++;
460ade9ccfeSMarcel Moolenaar 		xo_close_instance("local-address");
46174fd40c9SRandall Stewart 	}
46274fd40c9SRandall Stewart 
46374fd40c9SRandall Stewart 	xstcb = (struct xsctp_tcb *)(buf + *offset);
46474fd40c9SRandall Stewart 	*offset += sizeof(struct xsctp_tcb);
4652e34c19bSMichael Tuexen 	if (aflag && (xladdr_total == 0) && xstcb->last && !process_closed) {
4662e34c19bSMichael Tuexen 		process_closed = 1;
4672e34c19bSMichael Tuexen 		*offset = offset_laddr;
4682e34c19bSMichael Tuexen 		goto retry;
4692e34c19bSMichael Tuexen 	}
47074fd40c9SRandall Stewart 	while (xstcb->last == 0 && *offset < buflen) {
471ade9ccfeSMarcel Moolenaar 		xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
472ade9ccfeSMarcel Moolenaar 		    pname, tname);
4732e34c19bSMichael Tuexen 		sctp_process_tcb(xstcb, buf, buflen, offset, &indent);
47474fd40c9SRandall Stewart 		indent++;
47574fd40c9SRandall Stewart 		xstcb = (struct xsctp_tcb *)(buf + *offset);
47674fd40c9SRandall Stewart 		*offset += sizeof(struct xsctp_tcb);
47774fd40c9SRandall Stewart 	}
478ade9ccfeSMarcel Moolenaar 
479ade9ccfeSMarcel Moolenaar 	xo_close_list("local-address");
48074fd40c9SRandall Stewart }
48174fd40c9SRandall Stewart 
48274fd40c9SRandall Stewart /*
48374fd40c9SRandall Stewart  * Print a summary of SCTP connections related to an Internet
48474fd40c9SRandall Stewart  * protocol.
48574fd40c9SRandall Stewart  */
48674fd40c9SRandall Stewart void
sctp_protopr(u_long off __unused,const char * name __unused,int af1 __unused,int proto)487feda1a43SJohn Baldwin sctp_protopr(u_long off __unused,
488321ae07fSPhilippe Charnier     const char *name __unused, int af1 __unused, int proto)
48974fd40c9SRandall Stewart {
49074fd40c9SRandall Stewart 	char *buf;
49174fd40c9SRandall Stewart 	const char *mibvar = "net.inet.sctp.assoclist";
49204b764d8SXin LI 	size_t offset = 0;
49374fd40c9SRandall Stewart 	size_t len = 0;
49474fd40c9SRandall Stewart 	struct xsctp_inpcb *xinpcb;
49574fd40c9SRandall Stewart 
49674fd40c9SRandall Stewart 	if (proto != IPPROTO_SCTP)
49774fd40c9SRandall Stewart 		return;
49874fd40c9SRandall Stewart 
49974fd40c9SRandall Stewart 	if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
50074fd40c9SRandall Stewart 		if (errno != ENOENT)
501ade9ccfeSMarcel Moolenaar 			xo_warn("sysctl: %s", mibvar);
50274fd40c9SRandall Stewart 		return;
50374fd40c9SRandall Stewart 	}
504ef1cb629SMarcelo Araujo 	if ((buf = malloc(len)) == NULL) {
505ade9ccfeSMarcel Moolenaar 		xo_warnx("malloc %lu bytes", (u_long)len);
50674fd40c9SRandall Stewart 		return;
50774fd40c9SRandall Stewart 	}
50874fd40c9SRandall Stewart 	if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
509ade9ccfeSMarcel Moolenaar 		xo_warn("sysctl: %s", mibvar);
51074fd40c9SRandall Stewart 		free(buf);
51174fd40c9SRandall Stewart 		return;
51274fd40c9SRandall Stewart 	}
51374fd40c9SRandall Stewart 
51474fd40c9SRandall Stewart 	xinpcb = (struct xsctp_inpcb *)(buf + offset);
51574fd40c9SRandall Stewart 	offset += sizeof(struct xsctp_inpcb);
51674fd40c9SRandall Stewart 	while (xinpcb->last == 0 && offset < len) {
5172e34c19bSMichael Tuexen 		sctp_process_inpcb(xinpcb, buf, (const size_t)len,
51874fd40c9SRandall Stewart 		    &offset);
51974fd40c9SRandall Stewart 
52074fd40c9SRandall Stewart 		xinpcb = (struct xsctp_inpcb *)(buf + offset);
52174fd40c9SRandall Stewart 		offset += sizeof(struct xsctp_inpcb);
52274fd40c9SRandall Stewart 	}
52374fd40c9SRandall Stewart 
52474fd40c9SRandall Stewart 	free(buf);
52574fd40c9SRandall Stewart }
52674fd40c9SRandall Stewart 
52774fd40c9SRandall Stewart static void
sctp_statesprint(uint32_t state)52874fd40c9SRandall Stewart sctp_statesprint(uint32_t state)
52974fd40c9SRandall Stewart {
53074fd40c9SRandall Stewart 	int idx;
53174fd40c9SRandall Stewart 
53274fd40c9SRandall Stewart 	switch (state) {
5330835304fSMichael Tuexen 	case SCTP_CLOSED:
5340835304fSMichael Tuexen 		idx = NETSTAT_SCTP_STATES_CLOSED;
5350835304fSMichael Tuexen 		break;
5360835304fSMichael Tuexen 	case SCTP_BOUND:
5370835304fSMichael Tuexen 		idx = NETSTAT_SCTP_STATES_BOUND;
5380835304fSMichael Tuexen 		break;
5390835304fSMichael Tuexen 	case SCTP_LISTEN:
5400835304fSMichael Tuexen 		idx = NETSTAT_SCTP_STATES_LISTEN;
5410835304fSMichael Tuexen 		break;
5420835304fSMichael Tuexen 	case SCTP_COOKIE_WAIT:
54374fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_COOKIE_WAIT;
54474fd40c9SRandall Stewart 		break;
5450835304fSMichael Tuexen 	case SCTP_COOKIE_ECHOED:
54674fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_COOKIE_ECHOED;
54774fd40c9SRandall Stewart 		break;
5480835304fSMichael Tuexen 	case SCTP_ESTABLISHED:
54974fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_ESTABLISHED;
55074fd40c9SRandall Stewart 		break;
5510835304fSMichael Tuexen 	case SCTP_SHUTDOWN_SENT:
55274fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_SENT;
55374fd40c9SRandall Stewart 		break;
5540835304fSMichael Tuexen 	case SCTP_SHUTDOWN_RECEIVED:
55574fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED;
55674fd40c9SRandall Stewart 		break;
5570835304fSMichael Tuexen 	case SCTP_SHUTDOWN_ACK_SENT:
55874fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT;
55974fd40c9SRandall Stewart 		break;
5600835304fSMichael Tuexen 	case SCTP_SHUTDOWN_PENDING:
56174fd40c9SRandall Stewart 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING;
56274fd40c9SRandall Stewart 		break;
56374fd40c9SRandall Stewart 	default:
564ade9ccfeSMarcel Moolenaar 		xo_emit("UNKNOWN {:state/0x%08x}", state);
56574fd40c9SRandall Stewart 		return;
56674fd40c9SRandall Stewart 	}
56774fd40c9SRandall Stewart 
568ade9ccfeSMarcel Moolenaar 	xo_emit("{:state/%s}", sctpstates[idx]);
56974fd40c9SRandall Stewart }
57074fd40c9SRandall Stewart 
57174fd40c9SRandall Stewart /*
57274fd40c9SRandall Stewart  * Dump SCTP statistics structure.
57374fd40c9SRandall Stewart  */
57474fd40c9SRandall Stewart void
sctp_stats(u_long off,const char * name,int af1 __unused,int proto __unused)575feda1a43SJohn Baldwin sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
57674fd40c9SRandall Stewart {
5779eddb899SMark Johnston 	struct sctpstat sctpstat;
57874fd40c9SRandall Stewart 
5799eddb899SMark Johnston 	if (fetch_stats("net.inet.sctp.stats", off, &sctpstat,
5809eddb899SMark Johnston 	    sizeof(sctpstat), kread) != 0)
58174fd40c9SRandall Stewart 		return;
58274fd40c9SRandall Stewart 
583ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
584ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
58574fd40c9SRandall Stewart 
58674fd40c9SRandall Stewart #define	p(f, m) if (sctpstat.f || sflag <= 1) \
587ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)sctpstat.f, plural(sctpstat.f))
58874fd40c9SRandall Stewart #define	p1a(f, m) if (sctpstat.f || sflag <= 1) \
589ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)sctpstat.f)
59074fd40c9SRandall Stewart 
59174fd40c9SRandall Stewart 	/*
59274fd40c9SRandall Stewart 	 * input statistics
59374fd40c9SRandall Stewart 	 */
594ade9ccfeSMarcel Moolenaar 	p(sctps_recvpackets, "\t{:received-packets/%ju} "
595ade9ccfeSMarcel Moolenaar 	    "{N:/input packet%s}\n");
596ade9ccfeSMarcel Moolenaar 	p(sctps_recvdatagrams, "\t\t{:received-datagrams/%ju} "
597ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s}\n");
598ade9ccfeSMarcel Moolenaar 	p(sctps_recvpktwithdata, "\t\t{:received-with-data/%ju} "
599ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s that had data}\n");
600ade9ccfeSMarcel Moolenaar 	p(sctps_recvsacks, "\t\t{:received-sack-chunks/%ju} "
601ade9ccfeSMarcel Moolenaar 	    "{N:/input SACK chunk%s}\n");
602ade9ccfeSMarcel Moolenaar 	p(sctps_recvdata, "\t\t{:received-data-chunks/%ju} "
603ade9ccfeSMarcel Moolenaar 	    "{N:/input DATA chunk%s}\n");
604ade9ccfeSMarcel Moolenaar 	p(sctps_recvdupdata, "\t\t{:received-duplicate-data-chunks/%ju} "
605ade9ccfeSMarcel Moolenaar 	    "{N:/duplicate DATA chunk%s}\n");
606ade9ccfeSMarcel Moolenaar 	p(sctps_recvheartbeat, "\t\t{:received-hb-chunks/%ju} "
607ade9ccfeSMarcel Moolenaar 	    "{N:/input HB chunk%s}\n");
608ade9ccfeSMarcel Moolenaar 	p(sctps_recvheartbeatack, "\t\t{:received-hb-ack-chunks/%ju} "
609ade9ccfeSMarcel Moolenaar 	    "{N:/HB-ACK chunk%s}\n");
610ade9ccfeSMarcel Moolenaar 	p(sctps_recvecne, "\t\t{:received-ecne-chunks/%ju} "
611ade9ccfeSMarcel Moolenaar 	    "{N:/input ECNE chunk%s}\n");
612ade9ccfeSMarcel Moolenaar 	p(sctps_recvauth, "\t\t{:received-auth-chunks/%ju} "
613ade9ccfeSMarcel Moolenaar 	    "{N:/input AUTH chunk%s}\n");
614ade9ccfeSMarcel Moolenaar 	p(sctps_recvauthmissing, "\t\t{:dropped-missing-auth/%ju} "
615ade9ccfeSMarcel Moolenaar 	    "{N:/chunk%s missing AUTH}\n");
616ade9ccfeSMarcel Moolenaar 	p(sctps_recvivalhmacid, "\t\t{:dropped-invalid-hmac/%ju} "
617ade9ccfeSMarcel Moolenaar 	    "{N:/invalid HMAC id%s received}\n");
618ade9ccfeSMarcel Moolenaar 	p(sctps_recvivalkeyid, "\t\t{:dropped-invalid-secret/%ju} "
619ade9ccfeSMarcel Moolenaar 	    "{N:/invalid secret id%s received}\n");
620ade9ccfeSMarcel Moolenaar 	p1a(sctps_recvauthfailed, "\t\t{:dropped-auth-failed/%ju} "
621ade9ccfeSMarcel Moolenaar 	    "{N:/auth failed}\n");
622ade9ccfeSMarcel Moolenaar 	p1a(sctps_recvexpress, "\t\t{:received-fast-path/%ju} "
623ade9ccfeSMarcel Moolenaar 	    "{N:/fast path receives all one chunk}\n");
624ade9ccfeSMarcel Moolenaar 	p1a(sctps_recvexpressm, "\t\t{:receives-fast-path-multipart/%ju} "
625ade9ccfeSMarcel Moolenaar 	    "{N:/fast path multi-part data}\n");
62674fd40c9SRandall Stewart 
62774fd40c9SRandall Stewart 	/*
62874fd40c9SRandall Stewart 	 * output statistics
62974fd40c9SRandall Stewart 	 */
630ade9ccfeSMarcel Moolenaar 	p(sctps_sendpackets, "\t{:sent-packets/%ju} "
631ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s}\n");
632ade9ccfeSMarcel Moolenaar 	p(sctps_sendsacks, "\t\t{:sent-sacks/%ju} "
633ade9ccfeSMarcel Moolenaar 	    "{N:/output SACK%s}\n");
634ade9ccfeSMarcel Moolenaar 	p(sctps_senddata, "\t\t{:sent-data-chunks/%ju} "
635ade9ccfeSMarcel Moolenaar 	    "{N:/output DATA chunk%s}\n");
636ade9ccfeSMarcel Moolenaar 	p(sctps_sendretransdata, "\t\t{:sent-retransmitted-data-chunks/%ju} "
637ade9ccfeSMarcel Moolenaar 	    "{N:/retransmitted DATA chunk%s}\n");
638ade9ccfeSMarcel Moolenaar 	p(sctps_sendfastretrans, "\t\t"
639ade9ccfeSMarcel Moolenaar 	    "{:sent-fast-retransmitted-data-chunks/%ju} "
640ade9ccfeSMarcel Moolenaar 	    "{N:/fast retransmitted DATA chunk%s}\n");
641ade9ccfeSMarcel Moolenaar 	p(sctps_sendmultfastretrans, "\t\t"
642ade9ccfeSMarcel Moolenaar 	    "{:sent-fast-retransmitted-data-chunk-multiple-times/%ju} "
643ade9ccfeSMarcel Moolenaar 	    "{N:/FR'%s that happened more than once to same chunk}\n");
644ade9ccfeSMarcel Moolenaar 	p(sctps_sendheartbeat, "\t\t{:sent-hb-chunks/%ju} "
645ade9ccfeSMarcel Moolenaar 	    "{N:/output HB chunk%s}\n");
646ade9ccfeSMarcel Moolenaar 	p(sctps_sendecne, "\t\t{:sent-ecne-chunks/%ju} "
647ade9ccfeSMarcel Moolenaar 	    "{N:/output ECNE chunk%s}\n");
648ade9ccfeSMarcel Moolenaar 	p(sctps_sendauth, "\t\t{:sent-auth-chunks/%ju} "
649ade9ccfeSMarcel Moolenaar 	    "{N:/output AUTH chunk%s}\n");
650ade9ccfeSMarcel Moolenaar 	p1a(sctps_senderrors, "\t\t{:send-errors/%ju} "
651ade9ccfeSMarcel Moolenaar 	    "{N:/ip_output error counter}\n");
65274fd40c9SRandall Stewart 
65374fd40c9SRandall Stewart 	/*
65474fd40c9SRandall Stewart 	 * PCKDROPREP statistics
65574fd40c9SRandall Stewart 	 */
656ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Packet drop statistics}:\n");
657ade9ccfeSMarcel Moolenaar 	xo_open_container("drop-statistics");
658ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpfmbox, "\t\t{:middle-box/%ju} "
659ade9ccfeSMarcel Moolenaar 	    "{N:/from middle box}\n");
660ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpfehos, "\t\t{:end-host/%ju} "
661ade9ccfeSMarcel Moolenaar 	    "{N:/from end host}\n");
662ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpmbda, "\t\t{:with-data/%ju} "
663ade9ccfeSMarcel Moolenaar 	    "{N:/with data}\n");
664ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpmbct, "\t\t{:non-data/%ju} "
665ade9ccfeSMarcel Moolenaar 	    "{N:/non-data, non-endhost}\n");
666ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpbwrpt, "\t\t{:non-endhost/%ju} "
667ade9ccfeSMarcel Moolenaar 	    "{N:/non-endhost, bandwidth rep only}\n");
668ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpcrupt, "\t\t{:short-header/%ju} "
669ade9ccfeSMarcel Moolenaar 	    "{N:/not enough for chunk header}\n");
670ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpnedat, "\t\t{:short-data/%ju} "
671ade9ccfeSMarcel Moolenaar 	    "{N:/not enough data to confirm}\n");
672ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrppdbrk, "\t\t{:chunk-break/%ju} "
673ade9ccfeSMarcel Moolenaar 	    "{N:/where process_chunk_drop said break}\n");
674ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrptsnnf, "\t\t{:tsn-not-found/%ju} "
675ade9ccfeSMarcel Moolenaar 	    "{N:/failed to find TSN}\n");
676ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpdnfnd, "\t\t{:reverse-tsn/%ju} "
677ade9ccfeSMarcel Moolenaar 	    "{N:/attempt reverse TSN lookup}\n");
678ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpdiwnp, "\t\t{:confirmed-zero-window/%ju} "
679ade9ccfeSMarcel Moolenaar 	    "{N:/e-host confirms zero-rwnd}\n");
680ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpdizrw, "\t\t{:middle-box-no-space/%ju} "
681ade9ccfeSMarcel Moolenaar 	    "{N:/midbox confirms no space}\n");
682ade9ccfeSMarcel Moolenaar 	p1a(sctps_pdrpbadd, "\t\t{:bad-data/%ju} "
683ade9ccfeSMarcel Moolenaar 	    "{N:/data did not match TSN}\n");
684ade9ccfeSMarcel Moolenaar 	p(sctps_pdrpmark, "\t\t{:tsn-marked-fast-retransmission/%ju} "
685ade9ccfeSMarcel Moolenaar 	    "{N:/TSN'%s marked for Fast Retran}\n");
686ade9ccfeSMarcel Moolenaar 	xo_close_container("drop-statistics");
68774fd40c9SRandall Stewart 
68874fd40c9SRandall Stewart 	/*
68974fd40c9SRandall Stewart 	 * Timeouts
69074fd40c9SRandall Stewart 	 */
691ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Timeouts}:\n");
692ade9ccfeSMarcel Moolenaar 	xo_open_container("timeouts");
693ade9ccfeSMarcel Moolenaar 	p(sctps_timoiterator, "\t\t{:iterator/%ju} "
694ade9ccfeSMarcel Moolenaar 	    "{N:/iterator timer%s fired}\n");
695ade9ccfeSMarcel Moolenaar 	p(sctps_timodata, "\t\t{:t3-data/%ju} "
696ade9ccfeSMarcel Moolenaar 	    "{N:/T3 data time out%s}\n");
697ade9ccfeSMarcel Moolenaar 	p(sctps_timowindowprobe, "\t\t{:window-probe/%ju} "
698ade9ccfeSMarcel Moolenaar 	    "{N:/window probe (T3) timer%s fired}\n");
699ade9ccfeSMarcel Moolenaar 	p(sctps_timoinit, "\t\t{:init-timer/%ju} "
700ade9ccfeSMarcel Moolenaar 	    "{N:/INIT timer%s fired}\n");
701ade9ccfeSMarcel Moolenaar 	p(sctps_timosack, "\t\t{:sack-timer/%ju} "
702ade9ccfeSMarcel Moolenaar 	    "{N:/sack timer%s fired}\n");
703ade9ccfeSMarcel Moolenaar 	p(sctps_timoshutdown, "\t\t{:shutdown-timer/%ju} "
704ade9ccfeSMarcel Moolenaar 	    "{N:/shutdown timer%s fired}\n");
705ade9ccfeSMarcel Moolenaar 	p(sctps_timoheartbeat, "\t\t{:heartbeat-timer/%ju} "
706ade9ccfeSMarcel Moolenaar 	    "{N:/heartbeat timer%s fired}\n");
707ade9ccfeSMarcel Moolenaar 	p1a(sctps_timocookie, "\t\t{:cookie-timer/%ju} "
708ade9ccfeSMarcel Moolenaar 	    "{N:/a cookie timeout fired}\n");
709ade9ccfeSMarcel Moolenaar 	p1a(sctps_timosecret, "\t\t{:endpoint-changed-cookie/%ju} "
710ade9ccfeSMarcel Moolenaar 	    "{N:/an endpoint changed its cook}ie"
711b8a1761eSRandall Stewart 	    "secret\n");
712ade9ccfeSMarcel Moolenaar 	p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} "
713ade9ccfeSMarcel Moolenaar 	    "{N:/PMTU timer%s fired}\n");
714ade9ccfeSMarcel Moolenaar 	p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} "
715ade9ccfeSMarcel Moolenaar 	    "{N:/shutdown ack timer%s fired}\n");
716ade9ccfeSMarcel Moolenaar 	p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} "
717ade9ccfeSMarcel Moolenaar 	    "{N:/shutdown guard timer%s fired}\n");
718ade9ccfeSMarcel Moolenaar 	p(sctps_timostrmrst, "\t\t{:stream-reset-timer/%ju} "
719ade9ccfeSMarcel Moolenaar 	    "{N:/stream reset timer%s fired}\n");
720ade9ccfeSMarcel Moolenaar 	p(sctps_timoearlyfr, "\t\t{:early-fast-retransmission-timer/%ju} "
721ade9ccfeSMarcel Moolenaar 	    "{N:/early FR timer%s fired}\n");
722ade9ccfeSMarcel Moolenaar 	p1a(sctps_timoasconf, "\t\t{:asconf-timer/%ju} "
723ade9ccfeSMarcel Moolenaar 	    "{N:/an asconf timer fired}\n");
724ade9ccfeSMarcel Moolenaar 	p1a(sctps_timoautoclose, "\t\t{:auto-close-timer/%ju} "
725ade9ccfeSMarcel Moolenaar 	    "{N:/auto close timer fired}\n");
726ade9ccfeSMarcel Moolenaar 	p(sctps_timoassockill, "\t\t{:asoc-free-timer/%ju} "
727ade9ccfeSMarcel Moolenaar 	    "{N:/asoc free timer%s expired}\n");
728ade9ccfeSMarcel Moolenaar 	p(sctps_timoinpkill, "\t\t{:input-free-timer/%ju} "
729ade9ccfeSMarcel Moolenaar 	    "{N:/inp free timer%s expired}\n");
730ade9ccfeSMarcel Moolenaar 	xo_close_container("timeouts");
73174fd40c9SRandall Stewart 
73274fd40c9SRandall Stewart #if 0
73374fd40c9SRandall Stewart 	/*
73474fd40c9SRandall Stewart 	 * Early fast retransmission counters
73574fd40c9SRandall Stewart 	 */
736e5221e8bSRandall Stewart 	p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n");
737e5221e8bSRandall Stewart 	p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n");
738e5221e8bSRandall Stewart 	p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n");
739e5221e8bSRandall Stewart 	p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n");
740e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n");
741e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n");
742e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n");
743e5221e8bSRandall Stewart 	p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n");
744e5221e8bSRandall Stewart 	p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n");
745e5221e8bSRandall Stewart 	p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n");
746e5221e8bSRandall Stewart 	p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n");
74774fd40c9SRandall Stewart #endif
74874fd40c9SRandall Stewart 
74974fd40c9SRandall Stewart 	/*
75074fd40c9SRandall Stewart 	 * Others
75174fd40c9SRandall Stewart 	 */
752ade9ccfeSMarcel Moolenaar 	p1a(sctps_hdrops, "\t{:dropped-too-short/%ju} "
753ade9ccfeSMarcel Moolenaar 	    "{N:/packet shorter than header}\n");
754ade9ccfeSMarcel Moolenaar 	p1a(sctps_badsum, "\t{:dropped-bad-checksum/%ju} "
755ade9ccfeSMarcel Moolenaar 	    "{N:/checksum error}\n");
756ade9ccfeSMarcel Moolenaar 	p1a(sctps_noport, "\t{:dropped-no-endpoint/%ju} "
757ade9ccfeSMarcel Moolenaar 	    "{N:/no endpoint for port}\n");
758ade9ccfeSMarcel Moolenaar 	p1a(sctps_badvtag, "\t{:dropped-bad-v-tag/%ju} "
759ade9ccfeSMarcel Moolenaar 	    "{N:/bad v-tag}\n");
760ade9ccfeSMarcel Moolenaar 	p1a(sctps_badsid, "\t{:dropped-bad-sid/%ju} "
761ade9ccfeSMarcel Moolenaar 	    "{N:/bad SID}\n");
762ade9ccfeSMarcel Moolenaar 	p1a(sctps_nomem, "\t{:dropped-no-memory/%ju} "
763ade9ccfeSMarcel Moolenaar 	    "{N:/no memory}\n");
764ade9ccfeSMarcel Moolenaar 	p1a(sctps_fastretransinrtt, "\t{:multiple-fast-retransmits-in-rtt/%ju} "
765ade9ccfeSMarcel Moolenaar 	    "{N:/number of multiple FR in a RT}T window\n");
76674fd40c9SRandall Stewart #if 0
767e5221e8bSRandall Stewart 	p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n");
76874fd40c9SRandall Stewart #endif
769ade9ccfeSMarcel Moolenaar 	p1a(sctps_naglesent, "\t{:rfc813-sent/%ju} "
770ade9ccfeSMarcel Moolenaar 	    "{N:/RFC813 allowed sending}\n");
771ade9ccfeSMarcel Moolenaar 	p1a(sctps_naglequeued, "\t{:rfc813-queued/%ju} "
772ade9ccfeSMarcel Moolenaar 	    "{N:/RFC813 does not allow sending}\n");
773ade9ccfeSMarcel Moolenaar 	p1a(sctps_maxburstqueued, "\t{:max-burst-queued/%ju} "
774ade9ccfeSMarcel Moolenaar 	    "{N:/times max burst prohibited sending}\n");
775ade9ccfeSMarcel Moolenaar 	p1a(sctps_ifnomemqueued, "\t{:no-memory-in-interface/%ju} "
776ade9ccfeSMarcel Moolenaar 	    "{N:/look ahead tells us no memory in interface}\n");
777ade9ccfeSMarcel Moolenaar 	p(sctps_windowprobed, "\t{:sent-window-probes/%ju} "
778ade9ccfeSMarcel Moolenaar 	    "{N:/number%s of window probes sent}\n");
779ade9ccfeSMarcel Moolenaar 	p(sctps_lowlevelerr, "\t{:low-level-err/%ju} "
780ade9ccfeSMarcel Moolenaar 	    "{N:/time%s an output error to clamp down on next user send}\n");
781ade9ccfeSMarcel Moolenaar 	p(sctps_lowlevelerrusr, "\t{:low-level-user-error/%ju} "
782ade9ccfeSMarcel Moolenaar 	    "{N:/time%s sctp_senderrors were caused from a user}\n");
783ade9ccfeSMarcel Moolenaar 	p(sctps_datadropchklmt, "\t{:dropped-chunk-limit/%ju} "
784ade9ccfeSMarcel Moolenaar 	    "{N:/number of in data drop%s due to chunk limit reached}\n");
785ade9ccfeSMarcel Moolenaar 	p(sctps_datadroprwnd, "\t{:dropped-rwnd-limit/%ju} "
786ade9ccfeSMarcel Moolenaar 	    "{N:/number of in data drop%s due to rwnd limit reached}\n");
787ade9ccfeSMarcel Moolenaar 	p(sctps_ecnereducedcwnd, "\t{:ecn-reduced-cwnd/%ju} "
788ade9ccfeSMarcel Moolenaar 	    "{N:/time%s a ECN reduced the cwnd}\n");
789ade9ccfeSMarcel Moolenaar 	p1a(sctps_vtagexpress, "\t{:v-tag-express-lookup/%ju} "
790ade9ccfeSMarcel Moolenaar 	    "{N:/used express lookup via vtag}\n");
791ade9ccfeSMarcel Moolenaar 	p1a(sctps_vtagbogus, "\t{:v-tag-collision/%ju} "
792ade9ccfeSMarcel Moolenaar 	    "{N:/collision in express lookup}\n");
793ade9ccfeSMarcel Moolenaar 	p(sctps_primary_randry, "\t{:sender-ran-dry/%ju} "
794ade9ccfeSMarcel Moolenaar 	    "{N:/time%s the sender ran dry of user data on primary}\n");
795ade9ccfeSMarcel Moolenaar 	p1a(sctps_cmt_randry, "\t{:cmt-ran-dry/%ju} "
796ade9ccfeSMarcel Moolenaar 	    "{N:/same for above}\n");
797ade9ccfeSMarcel Moolenaar 	p(sctps_slowpath_sack, "\t{:slow-path-sack/%ju} "
798ade9ccfeSMarcel Moolenaar 	    "{N:/sack%s the slow way}\n");
799ade9ccfeSMarcel Moolenaar 	p(sctps_wu_sacks_sent, "\t{:sent-window-update-only-sack/%ju} "
800ade9ccfeSMarcel Moolenaar 	    "{N:/window update only sack%s sent}\n");
801ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_flags, "\t{:sent-with-sinfo/%ju} "
802ade9ccfeSMarcel Moolenaar 	    "{N:/send%s with sinfo_flags !=0}\n");
803ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_unord, "\t{:sent-with-unordered/%ju} "
804ade9ccfeSMarcel Moolenaar 	    "{N:/unordered send%s}\n");
805ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_eof, "\t{:sent-with-eof/%ju} "
806ade9ccfeSMarcel Moolenaar 	    "{N:/send%s with EOF flag set}\n");
807ade9ccfeSMarcel Moolenaar 	p(sctps_sends_with_abort, "\t{:sent-with-abort/%ju} "
808ade9ccfeSMarcel Moolenaar 	    "{N:/send%s with ABORT flag set}\n");
809ade9ccfeSMarcel Moolenaar 	p(sctps_protocol_drain_calls, "\t{:protocol-drain-called/%ju} "
810ade9ccfeSMarcel Moolenaar 	    "{N:/time%s protocol drain called}\n");
811ade9ccfeSMarcel Moolenaar 	p(sctps_protocol_drains_done, "\t{:protocol-drain/%ju} "
812ade9ccfeSMarcel Moolenaar 	    "{N:/time%s we did a protocol drain}\n");
813ade9ccfeSMarcel Moolenaar 	p(sctps_read_peeks, "\t{:read-with-peek/%ju} "
814ade9ccfeSMarcel Moolenaar 	    "{N:/time%s recv was called with peek}\n");
815ade9ccfeSMarcel Moolenaar 	p(sctps_cached_chk, "\t{:cached-chunks/%ju} "
816ade9ccfeSMarcel Moolenaar 	    "{N:/cached chunk%s used}\n");
817ade9ccfeSMarcel Moolenaar 	p1a(sctps_cached_strmoq, "\t{:cached-output-queue-used/%ju} "
818ade9ccfeSMarcel Moolenaar 	    "{N:/cached stream oq's used}\n");
819ade9ccfeSMarcel Moolenaar 	p(sctps_left_abandon, "\t{:messages-abandoned/%ju} "
820ade9ccfeSMarcel Moolenaar 	    "{N:/unread message%s abandonded by close}\n");
821ade9ccfeSMarcel Moolenaar 	p1a(sctps_send_burst_avoid, "\t{:send-burst-avoidance/%ju} "
822ade9ccfeSMarcel Moolenaar 	    "{N:/send burst avoidance, already max burst inflight to net}\n");
823ade9ccfeSMarcel Moolenaar 	p1a(sctps_send_cwnd_avoid, "\t{:send-cwnd-avoidance/%ju} "
824ade9ccfeSMarcel Moolenaar 	    "{N:/send cwnd full avoidance, already max burst inflight "
825ade9ccfeSMarcel Moolenaar 	    "to net}\n");
826ade9ccfeSMarcel Moolenaar 	p(sctps_fwdtsn_map_over, "\t{:tsn-map-overruns/%ju} "
827ade9ccfeSMarcel Moolenaar 	   "{N:/number of map array over-run%s via fwd-tsn's}\n");
828b8a1761eSRandall Stewart 
829b8a1761eSRandall Stewart #undef p
830b8a1761eSRandall Stewart #undef p1a
831ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
83274fd40c9SRandall Stewart }
83374fd40c9SRandall Stewart 
83474fd40c9SRandall Stewart #endif /* SCTP */
835