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