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