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