xref: /freebsd/usr.bin/netstat/ipsec.c (revision 32cd1d9601da09bcc987447711c1b892e9dc57d3)
132cd1d96SJun-ichiro itojun Hagino /*	$FreeBSD$	*/
232cd1d96SJun-ichiro itojun Hagino /*	$NetBSD: inet.c,v 1.35.2.1 1999/04/29 14:57:08 perry Exp $	*/
332cd1d96SJun-ichiro itojun Hagino 
432cd1d96SJun-ichiro itojun Hagino /*
532cd1d96SJun-ichiro itojun Hagino  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
632cd1d96SJun-ichiro itojun Hagino  * All rights reserved.
732cd1d96SJun-ichiro itojun Hagino  *
832cd1d96SJun-ichiro itojun Hagino  * Redistribution and use in source and binary forms, with or without
932cd1d96SJun-ichiro itojun Hagino  * modification, are permitted provided that the following conditions
1032cd1d96SJun-ichiro itojun Hagino  * are met:
1132cd1d96SJun-ichiro itojun Hagino  * 1. Redistributions of source code must retain the above copyright
1232cd1d96SJun-ichiro itojun Hagino  *    notice, this list of conditions and the following disclaimer.
1332cd1d96SJun-ichiro itojun Hagino  * 2. Redistributions in binary form must reproduce the above copyright
1432cd1d96SJun-ichiro itojun Hagino  *    notice, this list of conditions and the following disclaimer in the
1532cd1d96SJun-ichiro itojun Hagino  *    documentation and/or other materials provided with the distribution.
1632cd1d96SJun-ichiro itojun Hagino  * 3. Neither the name of the project nor the names of its contributors
1732cd1d96SJun-ichiro itojun Hagino  *    may be used to endorse or promote products derived from this software
1832cd1d96SJun-ichiro itojun Hagino  *    without specific prior written permission.
1932cd1d96SJun-ichiro itojun Hagino  *
2032cd1d96SJun-ichiro itojun Hagino  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2132cd1d96SJun-ichiro itojun Hagino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2232cd1d96SJun-ichiro itojun Hagino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2332cd1d96SJun-ichiro itojun Hagino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2432cd1d96SJun-ichiro itojun Hagino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2532cd1d96SJun-ichiro itojun Hagino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2632cd1d96SJun-ichiro itojun Hagino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2732cd1d96SJun-ichiro itojun Hagino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2832cd1d96SJun-ichiro itojun Hagino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2932cd1d96SJun-ichiro itojun Hagino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3032cd1d96SJun-ichiro itojun Hagino  * SUCH DAMAGE.
3132cd1d96SJun-ichiro itojun Hagino  */
3232cd1d96SJun-ichiro itojun Hagino 
3332cd1d96SJun-ichiro itojun Hagino /*
3432cd1d96SJun-ichiro itojun Hagino  * Copyright (c) 1983, 1988, 1993
3532cd1d96SJun-ichiro itojun Hagino  *	The Regents of the University of California.  All rights reserved.
3632cd1d96SJun-ichiro itojun Hagino  *
3732cd1d96SJun-ichiro itojun Hagino  * Redistribution and use in source and binary forms, with or without
3832cd1d96SJun-ichiro itojun Hagino  * modification, are permitted provided that the following conditions
3932cd1d96SJun-ichiro itojun Hagino  * are met:
4032cd1d96SJun-ichiro itojun Hagino  * 1. Redistributions of source code must retain the above copyright
4132cd1d96SJun-ichiro itojun Hagino  *    notice, this list of conditions and the following disclaimer.
4232cd1d96SJun-ichiro itojun Hagino  * 2. Redistributions in binary form must reproduce the above copyright
4332cd1d96SJun-ichiro itojun Hagino  *    notice, this list of conditions and the following disclaimer in the
4432cd1d96SJun-ichiro itojun Hagino  *    documentation and/or other materials provided with the distribution.
4532cd1d96SJun-ichiro itojun Hagino  * 3. All advertising materials mentioning features or use of this software
4632cd1d96SJun-ichiro itojun Hagino  *    must display the following acknowledgement:
4732cd1d96SJun-ichiro itojun Hagino  *	This product includes software developed by the University of
4832cd1d96SJun-ichiro itojun Hagino  *	California, Berkeley and its contributors.
4932cd1d96SJun-ichiro itojun Hagino  * 4. Neither the name of the University nor the names of its contributors
5032cd1d96SJun-ichiro itojun Hagino  *    may be used to endorse or promote products derived from this software
5132cd1d96SJun-ichiro itojun Hagino  *    without specific prior written permission.
5232cd1d96SJun-ichiro itojun Hagino  *
5332cd1d96SJun-ichiro itojun Hagino  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5432cd1d96SJun-ichiro itojun Hagino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5532cd1d96SJun-ichiro itojun Hagino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5632cd1d96SJun-ichiro itojun Hagino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5732cd1d96SJun-ichiro itojun Hagino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5832cd1d96SJun-ichiro itojun Hagino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5932cd1d96SJun-ichiro itojun Hagino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6032cd1d96SJun-ichiro itojun Hagino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6132cd1d96SJun-ichiro itojun Hagino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6232cd1d96SJun-ichiro itojun Hagino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6332cd1d96SJun-ichiro itojun Hagino  * SUCH DAMAGE.
6432cd1d96SJun-ichiro itojun Hagino  */
6532cd1d96SJun-ichiro itojun Hagino 
6632cd1d96SJun-ichiro itojun Hagino #ifndef lint
6732cd1d96SJun-ichiro itojun Hagino /*
6832cd1d96SJun-ichiro itojun Hagino static char sccsid[] = "@(#)inet.c	8.5 (Berkeley) 5/24/95";
6932cd1d96SJun-ichiro itojun Hagino */
7032cd1d96SJun-ichiro itojun Hagino static const char rcsid[] =
7132cd1d96SJun-ichiro itojun Hagino   "$FreeBSD$";
7232cd1d96SJun-ichiro itojun Hagino #endif /* not lint */
7332cd1d96SJun-ichiro itojun Hagino 
7432cd1d96SJun-ichiro itojun Hagino #include <sys/param.h>
7532cd1d96SJun-ichiro itojun Hagino #include <sys/queue.h>
7632cd1d96SJun-ichiro itojun Hagino #include <sys/socket.h>
7732cd1d96SJun-ichiro itojun Hagino 
7832cd1d96SJun-ichiro itojun Hagino #include <netinet/in.h>
7932cd1d96SJun-ichiro itojun Hagino 
8032cd1d96SJun-ichiro itojun Hagino #ifdef IPSEC
8132cd1d96SJun-ichiro itojun Hagino #include <netinet6/ipsec.h>
8232cd1d96SJun-ichiro itojun Hagino #include <netkey/keysock.h>
8332cd1d96SJun-ichiro itojun Hagino #endif
8432cd1d96SJun-ichiro itojun Hagino 
8532cd1d96SJun-ichiro itojun Hagino #include <stdio.h>
8632cd1d96SJun-ichiro itojun Hagino #include <string.h>
8732cd1d96SJun-ichiro itojun Hagino #include <unistd.h>
8832cd1d96SJun-ichiro itojun Hagino #include "netstat.h"
8932cd1d96SJun-ichiro itojun Hagino 
9032cd1d96SJun-ichiro itojun Hagino /*
9132cd1d96SJun-ichiro itojun Hagino  * portability issues:
9232cd1d96SJun-ichiro itojun Hagino  * - bsdi[34] uses PLURAL(), not plural().
9332cd1d96SJun-ichiro itojun Hagino  * - freebsd2 can't print "unsigned long long" properly.
9432cd1d96SJun-ichiro itojun Hagino  */
9532cd1d96SJun-ichiro itojun Hagino /*
9632cd1d96SJun-ichiro itojun Hagino  * XXX see PORTABILITY for the twist
9732cd1d96SJun-ichiro itojun Hagino  */
9832cd1d96SJun-ichiro itojun Hagino #define LLU	"%llu"
9932cd1d96SJun-ichiro itojun Hagino #define CAST	unsigned long long
10032cd1d96SJun-ichiro itojun Hagino 
10132cd1d96SJun-ichiro itojun Hagino #ifdef IPSEC
10232cd1d96SJun-ichiro itojun Hagino static const char *ipsec_ahnames[] = {
10332cd1d96SJun-ichiro itojun Hagino 	"none",
10432cd1d96SJun-ichiro itojun Hagino 	"hmac MD5",
10532cd1d96SJun-ichiro itojun Hagino 	"hmac SHA1",
10632cd1d96SJun-ichiro itojun Hagino 	"keyed MD5",
10732cd1d96SJun-ichiro itojun Hagino 	"keyed SHA1",
10832cd1d96SJun-ichiro itojun Hagino 	"null",
10932cd1d96SJun-ichiro itojun Hagino };
11032cd1d96SJun-ichiro itojun Hagino 
11132cd1d96SJun-ichiro itojun Hagino static const char *ipsec_espnames[] = {
11232cd1d96SJun-ichiro itojun Hagino 	"none",
11332cd1d96SJun-ichiro itojun Hagino 	"DES CBC",
11432cd1d96SJun-ichiro itojun Hagino 	"3DES CBC",
11532cd1d96SJun-ichiro itojun Hagino 	"simple",
11632cd1d96SJun-ichiro itojun Hagino 	"blowfish CBC",
11732cd1d96SJun-ichiro itojun Hagino 	"CAST128 CBC",
11832cd1d96SJun-ichiro itojun Hagino 	"DES derived IV",
11932cd1d96SJun-ichiro itojun Hagino };
12032cd1d96SJun-ichiro itojun Hagino 
12132cd1d96SJun-ichiro itojun Hagino static const char *ipsec_compnames[] = {
12232cd1d96SJun-ichiro itojun Hagino 	"none",
12332cd1d96SJun-ichiro itojun Hagino 	"OUI",
12432cd1d96SJun-ichiro itojun Hagino 	"deflate",
12532cd1d96SJun-ichiro itojun Hagino 	"LZS",
12632cd1d96SJun-ichiro itojun Hagino };
12732cd1d96SJun-ichiro itojun Hagino 
12832cd1d96SJun-ichiro itojun Hagino static const char *pfkey_msgtypenames[] = {
12932cd1d96SJun-ichiro itojun Hagino 	"reserved", "getspi", "update", "add", "delete",
13032cd1d96SJun-ichiro itojun Hagino 	"get", "acquire", "register", "expire", "flush",
13132cd1d96SJun-ichiro itojun Hagino 	"dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd",
13232cd1d96SJun-ichiro itojun Hagino 	"x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush",
13332cd1d96SJun-ichiro itojun Hagino 	"x_spdsetidx", "x_spdexpire", "x_spddelete2"
13432cd1d96SJun-ichiro itojun Hagino };
13532cd1d96SJun-ichiro itojun Hagino 
13632cd1d96SJun-ichiro itojun Hagino static struct ipsecstat ipsecstat;
13732cd1d96SJun-ichiro itojun Hagino 
13832cd1d96SJun-ichiro itojun Hagino static void print_ipsecstats __P((void));
13932cd1d96SJun-ichiro itojun Hagino static const char *pfkey_msgtype_names __P((int));
14032cd1d96SJun-ichiro itojun Hagino static void ipsec_hist __P((const u_quad_t *, size_t, const char **, size_t,
14132cd1d96SJun-ichiro itojun Hagino 	const char *));
14232cd1d96SJun-ichiro itojun Hagino 
14332cd1d96SJun-ichiro itojun Hagino /*
14432cd1d96SJun-ichiro itojun Hagino  * Dump IPSEC statistics structure.
14532cd1d96SJun-ichiro itojun Hagino  */
14632cd1d96SJun-ichiro itojun Hagino static void
14732cd1d96SJun-ichiro itojun Hagino ipsec_hist(hist, histmax, name, namemax, title)
14832cd1d96SJun-ichiro itojun Hagino 	const u_quad_t *hist;
14932cd1d96SJun-ichiro itojun Hagino 	size_t histmax;
15032cd1d96SJun-ichiro itojun Hagino 	const char **name;
15132cd1d96SJun-ichiro itojun Hagino 	size_t namemax;
15232cd1d96SJun-ichiro itojun Hagino 	const char *title;
15332cd1d96SJun-ichiro itojun Hagino {
15432cd1d96SJun-ichiro itojun Hagino 	int first;
15532cd1d96SJun-ichiro itojun Hagino 	size_t proto;
15632cd1d96SJun-ichiro itojun Hagino 
15732cd1d96SJun-ichiro itojun Hagino 	for (first = 1, proto = 0; proto < histmax; proto++) {
15832cd1d96SJun-ichiro itojun Hagino 		if (hist[proto] <= 0)
15932cd1d96SJun-ichiro itojun Hagino 			continue;
16032cd1d96SJun-ichiro itojun Hagino 		if (first) {
16132cd1d96SJun-ichiro itojun Hagino 			printf("\t%s histogram:\n", title);
16232cd1d96SJun-ichiro itojun Hagino 			first = 0;
16332cd1d96SJun-ichiro itojun Hagino 		}
16432cd1d96SJun-ichiro itojun Hagino 		if (proto < namemax && name[proto]) {
16532cd1d96SJun-ichiro itojun Hagino 			printf("\t\t%s: " LLU "\n", name[proto],
16632cd1d96SJun-ichiro itojun Hagino 				(CAST)hist[proto]);
16732cd1d96SJun-ichiro itojun Hagino 		} else {
16832cd1d96SJun-ichiro itojun Hagino 			printf("\t\t#%ld: " LLU "\n", (long)proto,
16932cd1d96SJun-ichiro itojun Hagino 				(CAST)hist[proto]);
17032cd1d96SJun-ichiro itojun Hagino 		}
17132cd1d96SJun-ichiro itojun Hagino 	}
17232cd1d96SJun-ichiro itojun Hagino }
17332cd1d96SJun-ichiro itojun Hagino 
17432cd1d96SJun-ichiro itojun Hagino static void
17532cd1d96SJun-ichiro itojun Hagino print_ipsecstats()
17632cd1d96SJun-ichiro itojun Hagino {
17732cd1d96SJun-ichiro itojun Hagino #define	p(f, m) if (ipsecstat.f || sflag <= 1) \
17832cd1d96SJun-ichiro itojun Hagino     printf(m, (CAST)ipsecstat.f, plural(ipsecstat.f))
17932cd1d96SJun-ichiro itojun Hagino #define hist(f, n, t) \
18032cd1d96SJun-ichiro itojun Hagino     ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), sizeof(n)/sizeof(n[0]), (t));
18132cd1d96SJun-ichiro itojun Hagino 
18232cd1d96SJun-ichiro itojun Hagino 	p(in_success, "\t" LLU " inbound packet%s processed successfully\n");
18332cd1d96SJun-ichiro itojun Hagino 	p(in_polvio, "\t" LLU " inbound packet%s violated process security "
18432cd1d96SJun-ichiro itojun Hagino 		"policy\n");
18532cd1d96SJun-ichiro itojun Hagino 	p(in_nosa, "\t" LLU " inbound packet%s with no SA available\n");
18632cd1d96SJun-ichiro itojun Hagino 	p(in_inval, "\t" LLU " invalid inbound packet%s\n");
18732cd1d96SJun-ichiro itojun Hagino 	p(in_nomem, "\t" LLU " inbound packet%s failed due to insufficient memory\n");
18832cd1d96SJun-ichiro itojun Hagino 	p(in_badspi, "\t" LLU " inbound packet%s failed getting SPI\n");
18932cd1d96SJun-ichiro itojun Hagino 	p(in_ahreplay, "\t" LLU " inbound packet%s failed on AH replay check\n");
19032cd1d96SJun-ichiro itojun Hagino 	p(in_espreplay, "\t" LLU " inbound packet%s failed on ESP replay check\n");
19132cd1d96SJun-ichiro itojun Hagino 	p(in_ahauthsucc, "\t" LLU " inbound packet%s considered authentic\n");
19232cd1d96SJun-ichiro itojun Hagino 	p(in_ahauthfail, "\t" LLU " inbound packet%s failed on authentication\n");
19332cd1d96SJun-ichiro itojun Hagino 	hist(ipsecstat.in_ahhist, ipsec_ahnames, "AH input");
19432cd1d96SJun-ichiro itojun Hagino 	hist(ipsecstat.in_esphist, ipsec_espnames, "ESP input");
19532cd1d96SJun-ichiro itojun Hagino 	hist(ipsecstat.in_comphist, ipsec_compnames, "IPComp input");
19632cd1d96SJun-ichiro itojun Hagino 
19732cd1d96SJun-ichiro itojun Hagino 	p(out_success, "\t" LLU " outbound packet%s processed successfully\n");
19832cd1d96SJun-ichiro itojun Hagino 	p(out_polvio, "\t" LLU " outbound packet%s violated process security "
19932cd1d96SJun-ichiro itojun Hagino 		"policy\n");
20032cd1d96SJun-ichiro itojun Hagino 	p(out_nosa, "\t" LLU " outbound packet%s with no SA available\n");
20132cd1d96SJun-ichiro itojun Hagino 	p(out_inval, "\t" LLU " invalid outbound packet%s\n");
20232cd1d96SJun-ichiro itojun Hagino 	p(out_nomem, "\t" LLU " outbound packet%s failed due to insufficient memory\n");
20332cd1d96SJun-ichiro itojun Hagino 	p(out_noroute, "\t" LLU " outbound packet%s with no route\n");
20432cd1d96SJun-ichiro itojun Hagino 	hist(ipsecstat.out_ahhist, ipsec_ahnames, "AH output");
20532cd1d96SJun-ichiro itojun Hagino 	hist(ipsecstat.out_esphist, ipsec_espnames, "ESP output");
20632cd1d96SJun-ichiro itojun Hagino 	hist(ipsecstat.out_comphist, ipsec_compnames, "IPComp output");
20732cd1d96SJun-ichiro itojun Hagino #undef p
20832cd1d96SJun-ichiro itojun Hagino #undef hist
20932cd1d96SJun-ichiro itojun Hagino }
21032cd1d96SJun-ichiro itojun Hagino 
21132cd1d96SJun-ichiro itojun Hagino void
21232cd1d96SJun-ichiro itojun Hagino ipsec_stats(off, name)
21332cd1d96SJun-ichiro itojun Hagino 	u_long off;
21432cd1d96SJun-ichiro itojun Hagino 	char *name;
21532cd1d96SJun-ichiro itojun Hagino {
21632cd1d96SJun-ichiro itojun Hagino 	if (off == 0)
21732cd1d96SJun-ichiro itojun Hagino 		return;
21832cd1d96SJun-ichiro itojun Hagino 	printf ("%s:\n", name);
21932cd1d96SJun-ichiro itojun Hagino 	kread(off, (char *)&ipsecstat, sizeof (ipsecstat));
22032cd1d96SJun-ichiro itojun Hagino 
22132cd1d96SJun-ichiro itojun Hagino 	print_ipsecstats();
22232cd1d96SJun-ichiro itojun Hagino }
22332cd1d96SJun-ichiro itojun Hagino 
22432cd1d96SJun-ichiro itojun Hagino #if defined(__bsdi__) && _BSDI_VERSION >= 199802 /* bsdi4 only */
22532cd1d96SJun-ichiro itojun Hagino void
22632cd1d96SJun-ichiro itojun Hagino ipsec_stats0(name)
22732cd1d96SJun-ichiro itojun Hagino 	char *name;
22832cd1d96SJun-ichiro itojun Hagino {
22932cd1d96SJun-ichiro itojun Hagino 	printf("%s:\n", name);
23032cd1d96SJun-ichiro itojun Hagino 
23132cd1d96SJun-ichiro itojun Hagino 	skread(name, &ipsecstat_info);
23232cd1d96SJun-ichiro itojun Hagino 
23332cd1d96SJun-ichiro itojun Hagino 	print_ipsecstats();
23432cd1d96SJun-ichiro itojun Hagino }
23532cd1d96SJun-ichiro itojun Hagino #endif
23632cd1d96SJun-ichiro itojun Hagino 
23732cd1d96SJun-ichiro itojun Hagino static const char *
23832cd1d96SJun-ichiro itojun Hagino pfkey_msgtype_names(x)
23932cd1d96SJun-ichiro itojun Hagino 	int x;
24032cd1d96SJun-ichiro itojun Hagino {
24132cd1d96SJun-ichiro itojun Hagino 	const int max =
24232cd1d96SJun-ichiro itojun Hagino 	    sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]);
24332cd1d96SJun-ichiro itojun Hagino 	static char buf[10];
24432cd1d96SJun-ichiro itojun Hagino 
24532cd1d96SJun-ichiro itojun Hagino 	if (x < max && pfkey_msgtypenames[x])
24632cd1d96SJun-ichiro itojun Hagino 		return pfkey_msgtypenames[x];
24732cd1d96SJun-ichiro itojun Hagino 	snprintf(buf, sizeof(buf), "#%d", x);
24832cd1d96SJun-ichiro itojun Hagino 	return buf;
24932cd1d96SJun-ichiro itojun Hagino }
25032cd1d96SJun-ichiro itojun Hagino 
25132cd1d96SJun-ichiro itojun Hagino void
25232cd1d96SJun-ichiro itojun Hagino pfkey_stats(off, name)
25332cd1d96SJun-ichiro itojun Hagino 	u_long off;
25432cd1d96SJun-ichiro itojun Hagino 	char *name;
25532cd1d96SJun-ichiro itojun Hagino {
25632cd1d96SJun-ichiro itojun Hagino 	struct pfkeystat pfkeystat;
25732cd1d96SJun-ichiro itojun Hagino 	int first, type;
25832cd1d96SJun-ichiro itojun Hagino 
25932cd1d96SJun-ichiro itojun Hagino 	if (off == 0)
26032cd1d96SJun-ichiro itojun Hagino 		return;
26132cd1d96SJun-ichiro itojun Hagino 	printf ("%s:\n", name);
26232cd1d96SJun-ichiro itojun Hagino 	kread(off, (char *)&pfkeystat, sizeof(pfkeystat));
26332cd1d96SJun-ichiro itojun Hagino 
26432cd1d96SJun-ichiro itojun Hagino #define	p(f, m) if (pfkeystat.f || sflag <= 1) \
26532cd1d96SJun-ichiro itojun Hagino     printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f))
26632cd1d96SJun-ichiro itojun Hagino 
26732cd1d96SJun-ichiro itojun Hagino 	/* kernel -> userland */
26832cd1d96SJun-ichiro itojun Hagino 	p(out_total, "\t" LLU " request%s sent to userland\n");
26932cd1d96SJun-ichiro itojun Hagino 	p(out_bytes, "\t" LLU " byte%s sent to userland\n");
27032cd1d96SJun-ichiro itojun Hagino 	for (first = 1, type = 0;
27132cd1d96SJun-ichiro itojun Hagino 	     type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
27232cd1d96SJun-ichiro itojun Hagino 	     type++) {
27332cd1d96SJun-ichiro itojun Hagino 		if (pfkeystat.out_msgtype[type] <= 0)
27432cd1d96SJun-ichiro itojun Hagino 			continue;
27532cd1d96SJun-ichiro itojun Hagino 		if (first) {
27632cd1d96SJun-ichiro itojun Hagino 			printf("\thistogram by message type:\n");
27732cd1d96SJun-ichiro itojun Hagino 			first = 0;
27832cd1d96SJun-ichiro itojun Hagino 		}
27932cd1d96SJun-ichiro itojun Hagino 		printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
28032cd1d96SJun-ichiro itojun Hagino 			(CAST)pfkeystat.out_msgtype[type]);
28132cd1d96SJun-ichiro itojun Hagino 	}
28232cd1d96SJun-ichiro itojun Hagino 	p(out_invlen, "\t" LLU " message%s with invalid length field\n");
28332cd1d96SJun-ichiro itojun Hagino 	p(out_invver, "\t" LLU " message%s with invalid version field\n");
28432cd1d96SJun-ichiro itojun Hagino 	p(out_invmsgtype, "\t" LLU " message%s with invalid message type field\n");
28532cd1d96SJun-ichiro itojun Hagino 	p(out_tooshort, "\t" LLU " message%s too short\n");
28632cd1d96SJun-ichiro itojun Hagino 	p(out_nomem, "\t" LLU " message%s with memory allocation failure\n");
28732cd1d96SJun-ichiro itojun Hagino 	p(out_dupext, "\t" LLU " message%s with duplicate extension\n");
28832cd1d96SJun-ichiro itojun Hagino 	p(out_invexttype, "\t" LLU " message%s with invalid extension type\n");
28932cd1d96SJun-ichiro itojun Hagino 	p(out_invsatype, "\t" LLU " message%s with invalid sa type\n");
29032cd1d96SJun-ichiro itojun Hagino 	p(out_invaddr, "\t" LLU " message%s with invalid address extension\n");
29132cd1d96SJun-ichiro itojun Hagino 
29232cd1d96SJun-ichiro itojun Hagino 	/* userland -> kernel */
29332cd1d96SJun-ichiro itojun Hagino 	p(in_total, "\t" LLU " request%s sent from userland\n");
29432cd1d96SJun-ichiro itojun Hagino 	p(in_bytes, "\t" LLU " byte%s sent from userland\n");
29532cd1d96SJun-ichiro itojun Hagino 	for (first = 1, type = 0;
29632cd1d96SJun-ichiro itojun Hagino 	     type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
29732cd1d96SJun-ichiro itojun Hagino 	     type++) {
29832cd1d96SJun-ichiro itojun Hagino 		if (pfkeystat.in_msgtype[type] <= 0)
29932cd1d96SJun-ichiro itojun Hagino 			continue;
30032cd1d96SJun-ichiro itojun Hagino 		if (first) {
30132cd1d96SJun-ichiro itojun Hagino 			printf("\thistogram by message type:\n");
30232cd1d96SJun-ichiro itojun Hagino 			first = 0;
30332cd1d96SJun-ichiro itojun Hagino 		}
30432cd1d96SJun-ichiro itojun Hagino 		printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
30532cd1d96SJun-ichiro itojun Hagino 			(CAST)pfkeystat.in_msgtype[type]);
30632cd1d96SJun-ichiro itojun Hagino 	}
30732cd1d96SJun-ichiro itojun Hagino 	p(in_msgtarget[KEY_SENDUP_ONE],
30832cd1d96SJun-ichiro itojun Hagino 	    "\t" LLU " message%s toward single socket\n");
30932cd1d96SJun-ichiro itojun Hagino 	p(in_msgtarget[KEY_SENDUP_ALL],
31032cd1d96SJun-ichiro itojun Hagino 	    "\t" LLU " message%s toward all sockets\n");
31132cd1d96SJun-ichiro itojun Hagino 	p(in_msgtarget[KEY_SENDUP_REGISTERED],
31232cd1d96SJun-ichiro itojun Hagino 	    "\t" LLU " message%s toward registered sockets\n");
31332cd1d96SJun-ichiro itojun Hagino 	p(in_nomem, "\t" LLU " message%s with memory allocation failure\n");
31432cd1d96SJun-ichiro itojun Hagino #undef p
31532cd1d96SJun-ichiro itojun Hagino }
31632cd1d96SJun-ichiro itojun Hagino #endif /*IPSEC*/
317