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