xref: /freebsd/usr.bin/netstat/sctp.c (revision edf8578117e8844e02c0121147f45e4609b30680)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2001-2007, by Weongyo Jeong. All rights reserved.
5  * Copyright (c) 2011, by Michael Tuexen. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * a) Redistributions of source code must retain the above copyright notice,
11  *   this list of conditions and the following disclaimer.
12  *
13  * b) Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *   the documentation and/or other materials provided with the distribution.
16  *
17  * c) Neither the name of Cisco Systems, Inc. nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #if 0
35 #ifndef lint
36 static char sccsid[] = "@(#)sctp.c	0.1 (Berkeley) 4/18/2007";
37 #endif /* not lint */
38 #endif
39 
40 #include <sys/cdefs.h>
41 #include <sys/param.h>
42 #include <sys/queue.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
46 #include <sys/sysctl.h>
47 #include <sys/protosw.h>
48 
49 #include <netinet/in.h>
50 #include <netinet/sctp.h>
51 #include <netinet/sctp_constants.h>
52 #include <arpa/inet.h>
53 
54 #include <err.h>
55 #include <errno.h>
56 #include <libutil.h>
57 #include <netdb.h>
58 #include <stdint.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <stdbool.h>
62 #include <string.h>
63 #include <unistd.h>
64 #include "netstat.h"
65 #include <libxo/xo.h>
66 
67 #ifdef SCTP
68 
69 static void sctp_statesprint(uint32_t state);
70 
71 #define	NETSTAT_SCTP_STATES_CLOSED		0x0
72 #define	NETSTAT_SCTP_STATES_BOUND		0x1
73 #define	NETSTAT_SCTP_STATES_LISTEN		0x2
74 #define	NETSTAT_SCTP_STATES_COOKIE_WAIT		0x3
75 #define	NETSTAT_SCTP_STATES_COOKIE_ECHOED	0x4
76 #define	NETSTAT_SCTP_STATES_ESTABLISHED		0x5
77 #define	NETSTAT_SCTP_STATES_SHUTDOWN_SENT	0x6
78 #define	NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED	0x7
79 #define	NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT	0x8
80 #define	NETSTAT_SCTP_STATES_SHUTDOWN_PENDING	0x9
81 
82 static const char *sctpstates[] = {
83 	"CLOSED",
84 	"BOUND",
85 	"LISTEN",
86 	"COOKIE_WAIT",
87 	"COOKIE_ECHOED",
88 	"ESTABLISHED",
89 	"SHUTDOWN_SENT",
90 	"SHUTDOWN_RECEIVED",
91 	"SHUTDOWN_ACK_SENT",
92 	"SHUTDOWN_PENDING"
93 };
94 
95 static LIST_HEAD(xladdr_list, xladdr_entry) xladdr_head;
96 struct xladdr_entry {
97 	struct xsctp_laddr *xladdr;
98 	LIST_ENTRY(xladdr_entry) xladdr_entries;
99 };
100 
101 static LIST_HEAD(xraddr_list, xraddr_entry) xraddr_head;
102 struct xraddr_entry {
103 	struct xsctp_raddr *xraddr;
104 	LIST_ENTRY(xraddr_entry) xraddr_entries;
105 };
106 
107 static void
108 sctp_print_address(const char *container, union sctp_sockstore *address,
109     int port, int num_port)
110 {
111 	struct servent *sp = 0;
112 	char line[80], *cp;
113 	int width;
114 	size_t alen, plen;
115 
116 	if (container)
117 		xo_open_container(container);
118 
119 	switch (address->sa.sa_family) {
120 #ifdef INET
121 	case AF_INET:
122 		snprintf(line, sizeof(line), "%.*s.",
123 		    Wflag ? 39 : 16, inetname(&address->sin.sin_addr));
124 		break;
125 #endif
126 #ifdef INET6
127 	case AF_INET6:
128 		snprintf(line, sizeof(line), "%.*s.",
129 		    Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr));
130 		break;
131 #endif
132 	default:
133 		snprintf(line, sizeof(line), "%.*s.",
134 		    Wflag ? 39 : 16, "");
135 		break;
136 	}
137 	alen = strlen(line);
138 	cp = line + alen;
139 	if (!num_port && port)
140 		sp = getservbyport((int)port, "sctp");
141 	if (sp || port == 0)
142 		snprintf(cp, sizeof(line) - alen,
143 		    "%.15s ", sp ? sp->s_name : "*");
144 	else
145 		snprintf(cp, sizeof(line) - alen,
146 		    "%d ", ntohs((u_short)port));
147 	width = Wflag ? 45 : 22;
148 	xo_emit("{d:target/%-*.*s} ", width, width, line);
149 
150 	plen = strlen(cp) - 1;
151 	alen--;
152 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
153 	    plen, cp);
154 
155 	if (container)
156 		xo_close_container(container);
157 }
158 
159 static int
160 sctp_skip_xinpcb_ifneed(char *buf, const size_t buflen, size_t *offset)
161 {
162 	int exist_tcb = 0;
163 	struct xsctp_tcb *xstcb;
164 	struct xsctp_raddr *xraddr;
165 	struct xsctp_laddr *xladdr;
166 
167 	while (*offset < buflen) {
168 		xladdr = (struct xsctp_laddr *)(buf + *offset);
169 		*offset += sizeof(struct xsctp_laddr);
170 		if (xladdr->last == 1)
171 			break;
172 	}
173 
174 	while (*offset < buflen) {
175 		xstcb = (struct xsctp_tcb *)(buf + *offset);
176 		*offset += sizeof(struct xsctp_tcb);
177 		if (xstcb->last == 1)
178 			break;
179 
180 		exist_tcb = 1;
181 
182 		while (*offset < buflen) {
183 			xladdr = (struct xsctp_laddr *)(buf + *offset);
184 			*offset += sizeof(struct xsctp_laddr);
185 			if (xladdr->last == 1)
186 				break;
187 		}
188 
189 		while (*offset < buflen) {
190 			xraddr = (struct xsctp_raddr *)(buf + *offset);
191 			*offset += sizeof(struct xsctp_raddr);
192 			if (xraddr->last == 1)
193 				break;
194 		}
195 	}
196 
197 	/*
198 	 * If Lflag is set, we don't care about the return value.
199 	 */
200 	if (Lflag)
201 		return 0;
202 
203 	return exist_tcb;
204 }
205 
206 static void
207 sctp_process_tcb(struct xsctp_tcb *xstcb,
208     char *buf, const size_t buflen, size_t *offset, int *indent)
209 {
210 	int i, xl_total = 0, xr_total = 0, x_max;
211 	struct xsctp_raddr *xraddr;
212 	struct xsctp_laddr *xladdr;
213 	struct xladdr_entry *prev_xl = NULL, *xl = NULL, *xl_tmp;
214 	struct xraddr_entry *prev_xr = NULL, *xr = NULL, *xr_tmp;
215 
216 	LIST_INIT(&xladdr_head);
217 	LIST_INIT(&xraddr_head);
218 
219 	/*
220 	 * Make `struct xladdr_list' list and `struct xraddr_list' list
221 	 * to handle the address flexibly.
222 	 */
223 	while (*offset < buflen) {
224 		xladdr = (struct xsctp_laddr *)(buf + *offset);
225 		*offset += sizeof(struct xsctp_laddr);
226 		if (xladdr->last == 1)
227 			break;
228 
229 		prev_xl = xl;
230 		xl = malloc(sizeof(struct xladdr_entry));
231 		if (xl == NULL) {
232 			xo_warnx("malloc %lu bytes",
233 			    (u_long)sizeof(struct xladdr_entry));
234 			goto out;
235 		}
236 		xl->xladdr = xladdr;
237 		if (prev_xl == NULL)
238 			LIST_INSERT_HEAD(&xladdr_head, xl, xladdr_entries);
239 		else
240 			LIST_INSERT_AFTER(prev_xl, xl, xladdr_entries);
241 		xl_total++;
242 	}
243 
244 	while (*offset < buflen) {
245 		xraddr = (struct xsctp_raddr *)(buf + *offset);
246 		*offset += sizeof(struct xsctp_raddr);
247 		if (xraddr->last == 1)
248 			break;
249 
250 		prev_xr = xr;
251 		xr = malloc(sizeof(struct xraddr_entry));
252 		if (xr == NULL) {
253 			xo_warnx("malloc %lu bytes",
254 			    (u_long)sizeof(struct xraddr_entry));
255 			goto out;
256 		}
257 		xr->xraddr = xraddr;
258 		if (prev_xr == NULL)
259 			LIST_INSERT_HEAD(&xraddr_head, xr, xraddr_entries);
260 		else
261 			LIST_INSERT_AFTER(prev_xr, xr, xraddr_entries);
262 		xr_total++;
263 	}
264 
265 	/*
266 	 * Let's print the address infos.
267 	 */
268 	xo_open_list("address");
269 	xl = LIST_FIRST(&xladdr_head);
270 	xr = LIST_FIRST(&xraddr_head);
271 	x_max = MAX(xl_total, xr_total);
272 	for (i = 0; i < x_max; i++) {
273 		xo_open_instance("address");
274 
275 		if (((*indent == 0) && i > 0) || *indent > 0)
276 			xo_emit("{P:/%-12s} ", " ");
277 
278 		if (xl != NULL) {
279 			sctp_print_address("local", &(xl->xladdr->address),
280 			    htons(xstcb->local_port), numeric_port);
281 		} else {
282 			if (Wflag) {
283 				xo_emit("{P:/%-45s} ", " ");
284 			} else {
285 				xo_emit("{P:/%-22s} ", " ");
286 			}
287 		}
288 
289 		if (xr != NULL && !Lflag) {
290 			sctp_print_address("remote", &(xr->xraddr->address),
291 			    htons(xstcb->remote_port), numeric_port);
292 		}
293 
294 		if (xl != NULL)
295 			xl = LIST_NEXT(xl, xladdr_entries);
296 		if (xr != NULL)
297 			xr = LIST_NEXT(xr, xraddr_entries);
298 
299 		if (i == 0 && !Lflag)
300 			sctp_statesprint(xstcb->state);
301 
302 		if (i < x_max)
303 			xo_emit("\n");
304 		xo_close_instance("address");
305 	}
306 
307 out:
308 	/*
309 	 * Free the list which be used to handle the address.
310 	 */
311 	xl = LIST_FIRST(&xladdr_head);
312 	while (xl != NULL) {
313 		xl_tmp = LIST_NEXT(xl, xladdr_entries);
314 		free(xl);
315 		xl = xl_tmp;
316 	}
317 
318 	xr = LIST_FIRST(&xraddr_head);
319 	while (xr != NULL) {
320 		xr_tmp = LIST_NEXT(xr, xraddr_entries);
321 		free(xr);
322 		xr = xr_tmp;
323 	}
324 }
325 
326 static void
327 sctp_process_inpcb(struct xsctp_inpcb *xinpcb,
328     char *buf, const size_t buflen, size_t *offset)
329 {
330 	int indent = 0, xladdr_total = 0, is_listening = 0;
331 	static int first = 1;
332 	const char *tname, *pname;
333 	struct xsctp_tcb *xstcb;
334 	struct xsctp_laddr *xladdr;
335 	size_t offset_laddr;
336 	int process_closed;
337 
338 	if (xinpcb->maxqlen > 0)
339 		is_listening = 1;
340 
341 	if (first) {
342 		if (!Lflag) {
343 			xo_emit("Active SCTP associations");
344 			if (aflag)
345 				xo_emit(" (including servers)");
346 		} else
347 			xo_emit("Current listen queue sizes (qlen/maxqlen)");
348 		xo_emit("\n");
349 		if (Lflag)
350 			xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-8.8s} "
351 			    "{T:/%-22.22s}\n",
352 			    "Proto", "Type", "Listen", "Local Address");
353 		else
354 			if (Wflag)
355 				xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-45.45s} "
356 				    "{T:/%-45.45s} {T:/%s}\n",
357 				    "Proto", "Type",
358 				    "Local Address", "Foreign Address",
359 				    "(state)");
360 			else
361 				xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-22.22s} "
362 				    "{T:/%-22.22s} {T:/%s}\n",
363 				    "Proto", "Type",
364 				    "Local Address", "Foreign Address",
365 				    "(state)");
366 		first = 0;
367 	}
368 	xladdr = (struct xsctp_laddr *)(buf + *offset);
369 	if ((!aflag && is_listening) ||
370 	    (Lflag && !is_listening)) {
371 		sctp_skip_xinpcb_ifneed(buf, buflen, offset);
372 		return;
373 	}
374 
375 	if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) {
376 		/* Can't distinguish between sctp46 and sctp6 */
377 		pname = "sctp46";
378 	} else {
379 		pname = "sctp4";
380 	}
381 
382 	if (xinpcb->flags & SCTP_PCB_FLAGS_TCPTYPE)
383 		tname = "1to1";
384 	else if (xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE)
385 		tname = "1toN";
386 	else
387 		tname = "????";
388 
389 	if (Lflag) {
390 		char buf1[22];
391 
392 		snprintf(buf1, sizeof buf1, "%u/%u",
393 		    xinpcb->qlen, xinpcb->maxqlen);
394 		xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
395 		    pname, tname);
396 		xo_emit("{d:queues/%-8.8s}{e:queue-len/%hu}"
397 		    "{e:max-queue-len/%hu} ",
398 		    buf1, xinpcb->qlen, xinpcb->maxqlen);
399 	}
400 
401 	offset_laddr = *offset;
402 	process_closed = 0;
403 
404 	xo_open_list("local-address");
405 retry:
406 	while (*offset < buflen) {
407 		xladdr = (struct xsctp_laddr *)(buf + *offset);
408 		*offset += sizeof(struct xsctp_laddr);
409 		if (xladdr->last) {
410 			if (aflag && !Lflag && (xladdr_total == 0) && process_closed) {
411 				xo_open_instance("local-address");
412 
413 				xo_emit("{:protocol/%-6.6s/%s} "
414 				    "{:type/%-5.5s/%s} ", pname, tname);
415 				if (Wflag) {
416 					xo_emit("{P:/%-91.91s/%s} "
417 					    "{:state/CLOSED}", " ");
418 				} else {
419 					xo_emit("{P:/%-45.45s/%s} "
420 					    "{:state/CLOSED}", " ");
421 				}
422 				xo_close_instance("local-address");
423 			}
424 			if (process_closed || is_listening) {
425 				xo_emit("\n");
426 			}
427 			break;
428 		}
429 
430 		if (!Lflag && !is_listening && !process_closed)
431 			continue;
432 
433 		xo_open_instance("local-address");
434 
435 		if (xladdr_total == 0) {
436 			if (!Lflag) {
437 				xo_emit("{:protocol/%-6.6s/%s} "
438 				    "{:type/%-5.5s/%s} ", pname, tname);
439 			}
440 		} else {
441 			xo_emit("\n");
442 			xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ",
443 			    " ");
444 		}
445 		sctp_print_address("local", &(xladdr->address),
446 		    htons(xinpcb->local_port), numeric_port);
447 		if (aflag && !Lflag && xladdr_total == 0) {
448 			if (Wflag) {
449 				if (process_closed) {
450 					xo_emit("{P:/%-45.45s} "
451 					    "{:state/CLOSED}", " ");
452 				} else {
453 					xo_emit("{P:/%-45.45s} "
454 					    "{:state/LISTEN}", " ");
455 				}
456 			} else {
457 				if (process_closed) {
458 					xo_emit("{P:/%-22.22s} "
459 					    "{:state/CLOSED}", " ");
460 				} else {
461 					xo_emit("{P:/%-22.22s} "
462 					    "{:state/LISTEN}", " ");
463 				}
464 			}
465 		}
466 		xladdr_total++;
467 		xo_close_instance("local-address");
468 	}
469 
470 	xstcb = (struct xsctp_tcb *)(buf + *offset);
471 	*offset += sizeof(struct xsctp_tcb);
472 	if (aflag && (xladdr_total == 0) && xstcb->last && !process_closed) {
473 		process_closed = 1;
474 		*offset = offset_laddr;
475 		goto retry;
476 	}
477 	while (xstcb->last == 0 && *offset < buflen) {
478 		xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
479 		    pname, tname);
480 		sctp_process_tcb(xstcb, buf, buflen, offset, &indent);
481 		indent++;
482 		xstcb = (struct xsctp_tcb *)(buf + *offset);
483 		*offset += sizeof(struct xsctp_tcb);
484 	}
485 
486 	xo_close_list("local-address");
487 }
488 
489 /*
490  * Print a summary of SCTP connections related to an Internet
491  * protocol.
492  */
493 void
494 sctp_protopr(u_long off __unused,
495     const char *name __unused, int af1 __unused, int proto)
496 {
497 	char *buf;
498 	const char *mibvar = "net.inet.sctp.assoclist";
499 	size_t offset = 0;
500 	size_t len = 0;
501 	struct xsctp_inpcb *xinpcb;
502 
503 	if (proto != IPPROTO_SCTP)
504 		return;
505 
506 	if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
507 		if (errno != ENOENT)
508 			xo_warn("sysctl: %s", mibvar);
509 		return;
510 	}
511 	if ((buf = malloc(len)) == NULL) {
512 		xo_warnx("malloc %lu bytes", (u_long)len);
513 		return;
514 	}
515 	if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
516 		xo_warn("sysctl: %s", mibvar);
517 		free(buf);
518 		return;
519 	}
520 
521 	xinpcb = (struct xsctp_inpcb *)(buf + offset);
522 	offset += sizeof(struct xsctp_inpcb);
523 	while (xinpcb->last == 0 && offset < len) {
524 		sctp_process_inpcb(xinpcb, buf, (const size_t)len,
525 		    &offset);
526 
527 		xinpcb = (struct xsctp_inpcb *)(buf + offset);
528 		offset += sizeof(struct xsctp_inpcb);
529 	}
530 
531 	free(buf);
532 }
533 
534 static void
535 sctp_statesprint(uint32_t state)
536 {
537 	int idx;
538 
539 	switch (state) {
540 	case SCTP_CLOSED:
541 		idx = NETSTAT_SCTP_STATES_CLOSED;
542 		break;
543 	case SCTP_BOUND:
544 		idx = NETSTAT_SCTP_STATES_BOUND;
545 		break;
546 	case SCTP_LISTEN:
547 		idx = NETSTAT_SCTP_STATES_LISTEN;
548 		break;
549 	case SCTP_COOKIE_WAIT:
550 		idx = NETSTAT_SCTP_STATES_COOKIE_WAIT;
551 		break;
552 	case SCTP_COOKIE_ECHOED:
553 		idx = NETSTAT_SCTP_STATES_COOKIE_ECHOED;
554 		break;
555 	case SCTP_ESTABLISHED:
556 		idx = NETSTAT_SCTP_STATES_ESTABLISHED;
557 		break;
558 	case SCTP_SHUTDOWN_SENT:
559 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_SENT;
560 		break;
561 	case SCTP_SHUTDOWN_RECEIVED:
562 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED;
563 		break;
564 	case SCTP_SHUTDOWN_ACK_SENT:
565 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT;
566 		break;
567 	case SCTP_SHUTDOWN_PENDING:
568 		idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING;
569 		break;
570 	default:
571 		xo_emit("UNKNOWN {:state/0x%08x}", state);
572 		return;
573 	}
574 
575 	xo_emit("{:state/%s}", sctpstates[idx]);
576 }
577 
578 /*
579  * Dump SCTP statistics structure.
580  */
581 void
582 sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
583 {
584 	struct sctpstat sctpstat;
585 
586 	if (fetch_stats("net.inet.sctp.stats", off, &sctpstat,
587 	    sizeof(sctpstat), kread) != 0)
588 		return;
589 
590 	xo_open_container(name);
591 	xo_emit("{T:/%s}:\n", name);
592 
593 #define	p(f, m) if (sctpstat.f || sflag <= 1) \
594 	xo_emit(m, (uintmax_t)sctpstat.f, plural(sctpstat.f))
595 #define	p1a(f, m) if (sctpstat.f || sflag <= 1) \
596 	xo_emit(m, (uintmax_t)sctpstat.f)
597 
598 	/*
599 	 * input statistics
600 	 */
601 	p(sctps_recvpackets, "\t{:received-packets/%ju} "
602 	    "{N:/input packet%s}\n");
603 	p(sctps_recvdatagrams, "\t\t{:received-datagrams/%ju} "
604 	    "{N:/datagram%s}\n");
605 	p(sctps_recvpktwithdata, "\t\t{:received-with-data/%ju} "
606 	    "{N:/packet%s that had data}\n");
607 	p(sctps_recvsacks, "\t\t{:received-sack-chunks/%ju} "
608 	    "{N:/input SACK chunk%s}\n");
609 	p(sctps_recvdata, "\t\t{:received-data-chunks/%ju} "
610 	    "{N:/input DATA chunk%s}\n");
611 	p(sctps_recvdupdata, "\t\t{:received-duplicate-data-chunks/%ju} "
612 	    "{N:/duplicate DATA chunk%s}\n");
613 	p(sctps_recvheartbeat, "\t\t{:received-hb-chunks/%ju} "
614 	    "{N:/input HB chunk%s}\n");
615 	p(sctps_recvheartbeatack, "\t\t{:received-hb-ack-chunks/%ju} "
616 	    "{N:/HB-ACK chunk%s}\n");
617 	p(sctps_recvecne, "\t\t{:received-ecne-chunks/%ju} "
618 	    "{N:/input ECNE chunk%s}\n");
619 	p(sctps_recvauth, "\t\t{:received-auth-chunks/%ju} "
620 	    "{N:/input AUTH chunk%s}\n");
621 	p(sctps_recvauthmissing, "\t\t{:dropped-missing-auth/%ju} "
622 	    "{N:/chunk%s missing AUTH}\n");
623 	p(sctps_recvivalhmacid, "\t\t{:dropped-invalid-hmac/%ju} "
624 	    "{N:/invalid HMAC id%s received}\n");
625 	p(sctps_recvivalkeyid, "\t\t{:dropped-invalid-secret/%ju} "
626 	    "{N:/invalid secret id%s received}\n");
627 	p1a(sctps_recvauthfailed, "\t\t{:dropped-auth-failed/%ju} "
628 	    "{N:/auth failed}\n");
629 	p1a(sctps_recvexpress, "\t\t{:received-fast-path/%ju} "
630 	    "{N:/fast path receives all one chunk}\n");
631 	p1a(sctps_recvexpressm, "\t\t{:receives-fast-path-multipart/%ju} "
632 	    "{N:/fast path multi-part data}\n");
633 
634 	/*
635 	 * output statistics
636 	 */
637 	p(sctps_sendpackets, "\t{:sent-packets/%ju} "
638 	    "{N:/output packet%s}\n");
639 	p(sctps_sendsacks, "\t\t{:sent-sacks/%ju} "
640 	    "{N:/output SACK%s}\n");
641 	p(sctps_senddata, "\t\t{:sent-data-chunks/%ju} "
642 	    "{N:/output DATA chunk%s}\n");
643 	p(sctps_sendretransdata, "\t\t{:sent-retransmitted-data-chunks/%ju} "
644 	    "{N:/retransmitted DATA chunk%s}\n");
645 	p(sctps_sendfastretrans, "\t\t"
646 	    "{:sent-fast-retransmitted-data-chunks/%ju} "
647 	    "{N:/fast retransmitted DATA chunk%s}\n");
648 	p(sctps_sendmultfastretrans, "\t\t"
649 	    "{:sent-fast-retransmitted-data-chunk-multiple-times/%ju} "
650 	    "{N:/FR'%s that happened more than once to same chunk}\n");
651 	p(sctps_sendheartbeat, "\t\t{:sent-hb-chunks/%ju} "
652 	    "{N:/output HB chunk%s}\n");
653 	p(sctps_sendecne, "\t\t{:sent-ecne-chunks/%ju} "
654 	    "{N:/output ECNE chunk%s}\n");
655 	p(sctps_sendauth, "\t\t{:sent-auth-chunks/%ju} "
656 	    "{N:/output AUTH chunk%s}\n");
657 	p1a(sctps_senderrors, "\t\t{:send-errors/%ju} "
658 	    "{N:/ip_output error counter}\n");
659 
660 	/*
661 	 * PCKDROPREP statistics
662 	 */
663 	xo_emit("\t{T:Packet drop statistics}:\n");
664 	xo_open_container("drop-statistics");
665 	p1a(sctps_pdrpfmbox, "\t\t{:middle-box/%ju} "
666 	    "{N:/from middle box}\n");
667 	p1a(sctps_pdrpfehos, "\t\t{:end-host/%ju} "
668 	    "{N:/from end host}\n");
669 	p1a(sctps_pdrpmbda, "\t\t{:with-data/%ju} "
670 	    "{N:/with data}\n");
671 	p1a(sctps_pdrpmbct, "\t\t{:non-data/%ju} "
672 	    "{N:/non-data, non-endhost}\n");
673 	p1a(sctps_pdrpbwrpt, "\t\t{:non-endhost/%ju} "
674 	    "{N:/non-endhost, bandwidth rep only}\n");
675 	p1a(sctps_pdrpcrupt, "\t\t{:short-header/%ju} "
676 	    "{N:/not enough for chunk header}\n");
677 	p1a(sctps_pdrpnedat, "\t\t{:short-data/%ju} "
678 	    "{N:/not enough data to confirm}\n");
679 	p1a(sctps_pdrppdbrk, "\t\t{:chunk-break/%ju} "
680 	    "{N:/where process_chunk_drop said break}\n");
681 	p1a(sctps_pdrptsnnf, "\t\t{:tsn-not-found/%ju} "
682 	    "{N:/failed to find TSN}\n");
683 	p1a(sctps_pdrpdnfnd, "\t\t{:reverse-tsn/%ju} "
684 	    "{N:/attempt reverse TSN lookup}\n");
685 	p1a(sctps_pdrpdiwnp, "\t\t{:confirmed-zero-window/%ju} "
686 	    "{N:/e-host confirms zero-rwnd}\n");
687 	p1a(sctps_pdrpdizrw, "\t\t{:middle-box-no-space/%ju} "
688 	    "{N:/midbox confirms no space}\n");
689 	p1a(sctps_pdrpbadd, "\t\t{:bad-data/%ju} "
690 	    "{N:/data did not match TSN}\n");
691 	p(sctps_pdrpmark, "\t\t{:tsn-marked-fast-retransmission/%ju} "
692 	    "{N:/TSN'%s marked for Fast Retran}\n");
693 	xo_close_container("drop-statistics");
694 
695 	/*
696 	 * Timeouts
697 	 */
698 	xo_emit("\t{T:Timeouts}:\n");
699 	xo_open_container("timeouts");
700 	p(sctps_timoiterator, "\t\t{:iterator/%ju} "
701 	    "{N:/iterator timer%s fired}\n");
702 	p(sctps_timodata, "\t\t{:t3-data/%ju} "
703 	    "{N:/T3 data time out%s}\n");
704 	p(sctps_timowindowprobe, "\t\t{:window-probe/%ju} "
705 	    "{N:/window probe (T3) timer%s fired}\n");
706 	p(sctps_timoinit, "\t\t{:init-timer/%ju} "
707 	    "{N:/INIT timer%s fired}\n");
708 	p(sctps_timosack, "\t\t{:sack-timer/%ju} "
709 	    "{N:/sack timer%s fired}\n");
710 	p(sctps_timoshutdown, "\t\t{:shutdown-timer/%ju} "
711 	    "{N:/shutdown timer%s fired}\n");
712 	p(sctps_timoheartbeat, "\t\t{:heartbeat-timer/%ju} "
713 	    "{N:/heartbeat timer%s fired}\n");
714 	p1a(sctps_timocookie, "\t\t{:cookie-timer/%ju} "
715 	    "{N:/a cookie timeout fired}\n");
716 	p1a(sctps_timosecret, "\t\t{:endpoint-changed-cookie/%ju} "
717 	    "{N:/an endpoint changed its cook}ie"
718 	    "secret\n");
719 	p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} "
720 	    "{N:/PMTU timer%s fired}\n");
721 	p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} "
722 	    "{N:/shutdown ack timer%s fired}\n");
723 	p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} "
724 	    "{N:/shutdown guard timer%s fired}\n");
725 	p(sctps_timostrmrst, "\t\t{:stream-reset-timer/%ju} "
726 	    "{N:/stream reset timer%s fired}\n");
727 	p(sctps_timoearlyfr, "\t\t{:early-fast-retransmission-timer/%ju} "
728 	    "{N:/early FR timer%s fired}\n");
729 	p1a(sctps_timoasconf, "\t\t{:asconf-timer/%ju} "
730 	    "{N:/an asconf timer fired}\n");
731 	p1a(sctps_timoautoclose, "\t\t{:auto-close-timer/%ju} "
732 	    "{N:/auto close timer fired}\n");
733 	p(sctps_timoassockill, "\t\t{:asoc-free-timer/%ju} "
734 	    "{N:/asoc free timer%s expired}\n");
735 	p(sctps_timoinpkill, "\t\t{:input-free-timer/%ju} "
736 	    "{N:/inp free timer%s expired}\n");
737 	xo_close_container("timeouts");
738 
739 #if 0
740 	/*
741 	 * Early fast retransmission counters
742 	 */
743 	p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n");
744 	p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n");
745 	p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n");
746 	p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n");
747 	p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n");
748 	p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n");
749 	p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n");
750 	p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n");
751 	p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n");
752 	p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n");
753 	p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n");
754 #endif
755 
756 	/*
757 	 * Others
758 	 */
759 	p1a(sctps_hdrops, "\t{:dropped-too-short/%ju} "
760 	    "{N:/packet shorter than header}\n");
761 	p1a(sctps_badsum, "\t{:dropped-bad-checksum/%ju} "
762 	    "{N:/checksum error}\n");
763 	p1a(sctps_noport, "\t{:dropped-no-endpoint/%ju} "
764 	    "{N:/no endpoint for port}\n");
765 	p1a(sctps_badvtag, "\t{:dropped-bad-v-tag/%ju} "
766 	    "{N:/bad v-tag}\n");
767 	p1a(sctps_badsid, "\t{:dropped-bad-sid/%ju} "
768 	    "{N:/bad SID}\n");
769 	p1a(sctps_nomem, "\t{:dropped-no-memory/%ju} "
770 	    "{N:/no memory}\n");
771 	p1a(sctps_fastretransinrtt, "\t{:multiple-fast-retransmits-in-rtt/%ju} "
772 	    "{N:/number of multiple FR in a RT}T window\n");
773 #if 0
774 	p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n");
775 #endif
776 	p1a(sctps_naglesent, "\t{:rfc813-sent/%ju} "
777 	    "{N:/RFC813 allowed sending}\n");
778 	p1a(sctps_naglequeued, "\t{:rfc813-queued/%ju} "
779 	    "{N:/RFC813 does not allow sending}\n");
780 	p1a(sctps_maxburstqueued, "\t{:max-burst-queued/%ju} "
781 	    "{N:/times max burst prohibited sending}\n");
782 	p1a(sctps_ifnomemqueued, "\t{:no-memory-in-interface/%ju} "
783 	    "{N:/look ahead tells us no memory in interface}\n");
784 	p(sctps_windowprobed, "\t{:sent-window-probes/%ju} "
785 	    "{N:/number%s of window probes sent}\n");
786 	p(sctps_lowlevelerr, "\t{:low-level-err/%ju} "
787 	    "{N:/time%s an output error to clamp down on next user send}\n");
788 	p(sctps_lowlevelerrusr, "\t{:low-level-user-error/%ju} "
789 	    "{N:/time%s sctp_senderrors were caused from a user}\n");
790 	p(sctps_datadropchklmt, "\t{:dropped-chunk-limit/%ju} "
791 	    "{N:/number of in data drop%s due to chunk limit reached}\n");
792 	p(sctps_datadroprwnd, "\t{:dropped-rwnd-limit/%ju} "
793 	    "{N:/number of in data drop%s due to rwnd limit reached}\n");
794 	p(sctps_ecnereducedcwnd, "\t{:ecn-reduced-cwnd/%ju} "
795 	    "{N:/time%s a ECN reduced the cwnd}\n");
796 	p1a(sctps_vtagexpress, "\t{:v-tag-express-lookup/%ju} "
797 	    "{N:/used express lookup via vtag}\n");
798 	p1a(sctps_vtagbogus, "\t{:v-tag-collision/%ju} "
799 	    "{N:/collision in express lookup}\n");
800 	p(sctps_primary_randry, "\t{:sender-ran-dry/%ju} "
801 	    "{N:/time%s the sender ran dry of user data on primary}\n");
802 	p1a(sctps_cmt_randry, "\t{:cmt-ran-dry/%ju} "
803 	    "{N:/same for above}\n");
804 	p(sctps_slowpath_sack, "\t{:slow-path-sack/%ju} "
805 	    "{N:/sack%s the slow way}\n");
806 	p(sctps_wu_sacks_sent, "\t{:sent-window-update-only-sack/%ju} "
807 	    "{N:/window update only sack%s sent}\n");
808 	p(sctps_sends_with_flags, "\t{:sent-with-sinfo/%ju} "
809 	    "{N:/send%s with sinfo_flags !=0}\n");
810 	p(sctps_sends_with_unord, "\t{:sent-with-unordered/%ju} "
811 	    "{N:/unordered send%s}\n");
812 	p(sctps_sends_with_eof, "\t{:sent-with-eof/%ju} "
813 	    "{N:/send%s with EOF flag set}\n");
814 	p(sctps_sends_with_abort, "\t{:sent-with-abort/%ju} "
815 	    "{N:/send%s with ABORT flag set}\n");
816 	p(sctps_protocol_drain_calls, "\t{:protocol-drain-called/%ju} "
817 	    "{N:/time%s protocol drain called}\n");
818 	p(sctps_protocol_drains_done, "\t{:protocol-drain/%ju} "
819 	    "{N:/time%s we did a protocol drain}\n");
820 	p(sctps_read_peeks, "\t{:read-with-peek/%ju} "
821 	    "{N:/time%s recv was called with peek}\n");
822 	p(sctps_cached_chk, "\t{:cached-chunks/%ju} "
823 	    "{N:/cached chunk%s used}\n");
824 	p1a(sctps_cached_strmoq, "\t{:cached-output-queue-used/%ju} "
825 	    "{N:/cached stream oq's used}\n");
826 	p(sctps_left_abandon, "\t{:messages-abandoned/%ju} "
827 	    "{N:/unread message%s abandonded by close}\n");
828 	p1a(sctps_send_burst_avoid, "\t{:send-burst-avoidance/%ju} "
829 	    "{N:/send burst avoidance, already max burst inflight to net}\n");
830 	p1a(sctps_send_cwnd_avoid, "\t{:send-cwnd-avoidance/%ju} "
831 	    "{N:/send cwnd full avoidance, already max burst inflight "
832 	    "to net}\n");
833 	p(sctps_fwdtsn_map_over, "\t{:tsn-map-overruns/%ju} "
834 	   "{N:/number of map array over-run%s via fwd-tsn's}\n");
835 
836 #undef p
837 #undef p1a
838 	xo_close_container(name);
839 }
840 
841 #endif /* SCTP */
842