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