11eaf0ac3Slogwang /* $KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $ */
21eaf0ac3Slogwang
31eaf0ac3Slogwang /*-
4*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-3-Clause
5*22ce4affSfengbojiang *
61eaf0ac3Slogwang * Copyright (c) 2005 NTT Multimedia Communications Laboratories, Inc.
71eaf0ac3Slogwang * All rights reserved.
81eaf0ac3Slogwang *
91eaf0ac3Slogwang * Redistribution and use in source and binary forms, with or without
101eaf0ac3Slogwang * modification, are permitted provided that the following conditions
111eaf0ac3Slogwang * are met:
121eaf0ac3Slogwang * 1. Redistributions of source code must retain the above copyright
131eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer.
141eaf0ac3Slogwang * 2. Redistributions in binary form must reproduce the above copyright
151eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer in the
161eaf0ac3Slogwang * documentation and/or other materials provided with the distribution.
171eaf0ac3Slogwang *
181eaf0ac3Slogwang * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
191eaf0ac3Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201eaf0ac3Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211eaf0ac3Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
221eaf0ac3Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231eaf0ac3Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241eaf0ac3Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251eaf0ac3Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261eaf0ac3Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271eaf0ac3Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281eaf0ac3Slogwang * SUCH DAMAGE.
291eaf0ac3Slogwang */
301eaf0ac3Slogwang /*-
311eaf0ac3Slogwang * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
321eaf0ac3Slogwang * All rights reserved.
331eaf0ac3Slogwang *
341eaf0ac3Slogwang * Redistribution and use in source and binary forms, with or without
351eaf0ac3Slogwang * modification, are permitted provided that the following conditions
361eaf0ac3Slogwang * are met:
371eaf0ac3Slogwang * 1. Redistributions of source code must retain the above copyright
381eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer.
391eaf0ac3Slogwang * 2. Redistributions in binary form must reproduce the above copyright
401eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer in the
411eaf0ac3Slogwang * documentation and/or other materials provided with the distribution.
421eaf0ac3Slogwang * 3. Neither the name of the project nor the names of its contributors
431eaf0ac3Slogwang * may be used to endorse or promote products derived from this software
441eaf0ac3Slogwang * without specific prior written permission.
451eaf0ac3Slogwang *
461eaf0ac3Slogwang * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
471eaf0ac3Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
481eaf0ac3Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
491eaf0ac3Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
501eaf0ac3Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
511eaf0ac3Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
521eaf0ac3Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
531eaf0ac3Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
541eaf0ac3Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
551eaf0ac3Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
561eaf0ac3Slogwang * SUCH DAMAGE.
571eaf0ac3Slogwang */
581eaf0ac3Slogwang /*-
591eaf0ac3Slogwang * Copyright (c) 1983, 1988, 1993
601eaf0ac3Slogwang * The Regents of the University of California. All rights reserved.
611eaf0ac3Slogwang *
621eaf0ac3Slogwang * Redistribution and use in source and binary forms, with or without
631eaf0ac3Slogwang * modification, are permitted provided that the following conditions
641eaf0ac3Slogwang * are met:
651eaf0ac3Slogwang * 1. Redistributions of source code must retain the above copyright
661eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer.
671eaf0ac3Slogwang * 2. Redistributions in binary form must reproduce the above copyright
681eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer in the
691eaf0ac3Slogwang * documentation and/or other materials provided with the distribution.
70*22ce4affSfengbojiang * 3. Neither the name of the University nor the names of its contributors
711eaf0ac3Slogwang * may be used to endorse or promote products derived from this software
721eaf0ac3Slogwang * without specific prior written permission.
731eaf0ac3Slogwang *
741eaf0ac3Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
751eaf0ac3Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
761eaf0ac3Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
771eaf0ac3Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
781eaf0ac3Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
791eaf0ac3Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
801eaf0ac3Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
811eaf0ac3Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
821eaf0ac3Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
831eaf0ac3Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
841eaf0ac3Slogwang * SUCH DAMAGE.
851eaf0ac3Slogwang */
861eaf0ac3Slogwang
871eaf0ac3Slogwang #if 0
881eaf0ac3Slogwang #ifndef lint
891eaf0ac3Slogwang static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
901eaf0ac3Slogwang #endif /* not lint */
911eaf0ac3Slogwang #endif
921eaf0ac3Slogwang
931eaf0ac3Slogwang #include <sys/cdefs.h>
941eaf0ac3Slogwang __FBSDID("$FreeBSD$");
951eaf0ac3Slogwang
961eaf0ac3Slogwang #include <sys/param.h>
971eaf0ac3Slogwang #include <sys/queue.h>
981eaf0ac3Slogwang #include <sys/socket.h>
991eaf0ac3Slogwang #include <sys/socketvar.h>
1001eaf0ac3Slogwang
1011eaf0ac3Slogwang #include <netinet/in.h>
1021eaf0ac3Slogwang
1031eaf0ac3Slogwang #ifdef IPSEC
1041eaf0ac3Slogwang #include <netipsec/ipsec.h>
1051eaf0ac3Slogwang #include <netipsec/ah_var.h>
1061eaf0ac3Slogwang #include <netipsec/esp_var.h>
1071eaf0ac3Slogwang #include <netipsec/ipcomp_var.h>
1081eaf0ac3Slogwang #endif
1091eaf0ac3Slogwang
1101eaf0ac3Slogwang #include <stdint.h>
1111eaf0ac3Slogwang #include <stdio.h>
1121eaf0ac3Slogwang #include <stdbool.h>
1131eaf0ac3Slogwang #include <string.h>
1141eaf0ac3Slogwang #include <unistd.h>
1151eaf0ac3Slogwang #include <libxo/xo.h>
1161eaf0ac3Slogwang #include "netstat.h"
1171eaf0ac3Slogwang
1181eaf0ac3Slogwang #ifdef IPSEC
1191eaf0ac3Slogwang struct val2str {
1201eaf0ac3Slogwang int val;
1211eaf0ac3Slogwang const char *str;
1221eaf0ac3Slogwang };
1231eaf0ac3Slogwang
1241eaf0ac3Slogwang static struct val2str ipsec_ahnames[] = {
1251eaf0ac3Slogwang { SADB_AALG_NONE, "none", },
1261eaf0ac3Slogwang { SADB_AALG_SHA1HMAC, "hmac-sha1", },
1271eaf0ac3Slogwang { SADB_X_AALG_NULL, "null", },
1281eaf0ac3Slogwang { SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
1291eaf0ac3Slogwang { SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
1301eaf0ac3Slogwang { SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
1311eaf0ac3Slogwang { SADB_X_AALG_AES_XCBC_MAC, "aes-xcbc-mac", },
132*22ce4affSfengbojiang { SADB_X_AALG_TCP_MD5, "tcp-md5", },
133*22ce4affSfengbojiang { SADB_X_AALG_AES128GMAC, "aes-gmac-128", },
134*22ce4affSfengbojiang { SADB_X_AALG_AES192GMAC, "aes-gmac-192", },
135*22ce4affSfengbojiang { SADB_X_AALG_AES256GMAC, "aes-gmac-256", },
1361eaf0ac3Slogwang { -1, NULL },
1371eaf0ac3Slogwang };
1381eaf0ac3Slogwang
1391eaf0ac3Slogwang static struct val2str ipsec_espnames[] = {
1401eaf0ac3Slogwang { SADB_EALG_NONE, "none", },
1411eaf0ac3Slogwang { SADB_EALG_NULL, "null", },
142*22ce4affSfengbojiang { SADB_X_EALG_AESCBC, "aes-cbc", },
1431eaf0ac3Slogwang { SADB_X_EALG_AESCTR, "aes-ctr", },
1441eaf0ac3Slogwang { SADB_X_EALG_AESGCM16, "aes-gcm-16", },
145*22ce4affSfengbojiang { SADB_X_EALG_AESGMAC, "aes-gmac", },
1461eaf0ac3Slogwang { -1, NULL },
1471eaf0ac3Slogwang };
1481eaf0ac3Slogwang
1491eaf0ac3Slogwang static struct val2str ipsec_compnames[] = {
1501eaf0ac3Slogwang { SADB_X_CALG_NONE, "none", },
1511eaf0ac3Slogwang { SADB_X_CALG_OUI, "oui", },
1521eaf0ac3Slogwang { SADB_X_CALG_DEFLATE, "deflate", },
1531eaf0ac3Slogwang { SADB_X_CALG_LZS, "lzs", },
1541eaf0ac3Slogwang { -1, NULL },
1551eaf0ac3Slogwang };
1561eaf0ac3Slogwang
1571eaf0ac3Slogwang static void print_ipsecstats(const struct ipsecstat *ipsecstat);
1581eaf0ac3Slogwang
1591eaf0ac3Slogwang static void
print_ipsecstats(const struct ipsecstat * ipsecstat)1601eaf0ac3Slogwang print_ipsecstats(const struct ipsecstat *ipsecstat)
1611eaf0ac3Slogwang {
1621eaf0ac3Slogwang xo_open_container("ipsec-statistics");
1631eaf0ac3Slogwang
1641eaf0ac3Slogwang #define p(f, m) if (ipsecstat->f || sflag <= 1) \
1651eaf0ac3Slogwang xo_emit(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f))
166*22ce4affSfengbojiang #define p2(f, m) if (ipsecstat->f || sflag <= 1) \
167*22ce4affSfengbojiang xo_emit(m, (uintmax_t)ipsecstat->f, plurales(ipsecstat->f))
1681eaf0ac3Slogwang
1691eaf0ac3Slogwang p(ips_in_polvio, "\t{:dropped-policy-violation/%ju} "
1701eaf0ac3Slogwang "{N:/inbound packet%s violated process security policy}\n");
1711eaf0ac3Slogwang p(ips_in_nomem, "\t{:dropped-no-memory/%ju} "
1721eaf0ac3Slogwang "{N:/inbound packet%s failed due to insufficient memory}\n");
1731eaf0ac3Slogwang p(ips_in_inval, "\t{:dropped-invalid/%ju} "
1741eaf0ac3Slogwang "{N:/invalid inbound packet%s}\n");
1751eaf0ac3Slogwang p(ips_out_polvio, "\t{:discarded-policy-violation/%ju} "
1761eaf0ac3Slogwang "{N:/outbound packet%s violated process security policy}\n");
1771eaf0ac3Slogwang p(ips_out_nosa, "\t{:discarded-no-sa/%ju} "
1781eaf0ac3Slogwang "{N:/outbound packet%s with no SA available}\n");
1791eaf0ac3Slogwang p(ips_out_nomem, "\t{:discarded-no-memory/%ju} "
1801eaf0ac3Slogwang "{N:/outbound packet%s failed due to insufficient memory}\n");
1811eaf0ac3Slogwang p(ips_out_noroute, "\t{:discarded-no-route/%ju} "
1821eaf0ac3Slogwang "{N:/outbound packet%s with no route available}\n");
1831eaf0ac3Slogwang p(ips_out_inval, "\t{:discarded-invalid/%ju} "
1841eaf0ac3Slogwang "{N:/invalid outbound packet%s}\n");
1851eaf0ac3Slogwang p(ips_out_bundlesa, "\t{:send-bundled-sa/%ju} "
1861eaf0ac3Slogwang "{N:/outbound packet%s with bundled SAs}\n");
187*22ce4affSfengbojiang p(ips_spdcache_hits, "\t{:spdcache-hits/%ju} "
188*22ce4affSfengbojiang "{N:/spd cache hit%s}\n");
189*22ce4affSfengbojiang p2(ips_spdcache_misses, "\t{:spdcache-misses/%ju} "
190*22ce4affSfengbojiang "{N:/spd cache miss%s}\n");
1911eaf0ac3Slogwang p(ips_clcopied, "\t{:clusters-copied-during-clone/%ju} "
1921eaf0ac3Slogwang "{N:/cluster%s copied during clone}\n");
1931eaf0ac3Slogwang p(ips_mbinserted, "\t{:mbufs-inserted/%ju} "
1941eaf0ac3Slogwang "{N:/mbuf%s inserted during makespace}\n");
195*22ce4affSfengbojiang #undef p2
1961eaf0ac3Slogwang #undef p
1971eaf0ac3Slogwang xo_close_container("ipsec-statistics");
1981eaf0ac3Slogwang }
1991eaf0ac3Slogwang
2001eaf0ac3Slogwang void
ipsec_stats(u_long off,const char * name,int af1 __unused,int proto __unused)2011eaf0ac3Slogwang ipsec_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
2021eaf0ac3Slogwang {
2031eaf0ac3Slogwang struct ipsecstat ipsecstat;
2041eaf0ac3Slogwang
2051eaf0ac3Slogwang if (strcmp(name, "ipsec6") == 0) {
2061eaf0ac3Slogwang if (fetch_stats("net.inet6.ipsec6.ipsecstats", off,&ipsecstat,
2071eaf0ac3Slogwang sizeof(ipsecstat), kread_counters) != 0)
2081eaf0ac3Slogwang return;
2091eaf0ac3Slogwang } else {
2101eaf0ac3Slogwang if (fetch_stats("net.inet.ipsec.ipsecstats", off, &ipsecstat,
2111eaf0ac3Slogwang sizeof(ipsecstat), kread_counters) != 0)
2121eaf0ac3Slogwang return;
2131eaf0ac3Slogwang }
2141eaf0ac3Slogwang
2151eaf0ac3Slogwang xo_emit("{T:/%s}:\n", name);
2161eaf0ac3Slogwang
2171eaf0ac3Slogwang print_ipsecstats(&ipsecstat);
2181eaf0ac3Slogwang }
2191eaf0ac3Slogwang
2201eaf0ac3Slogwang
2211eaf0ac3Slogwang static void print_ahstats(const struct ahstat *ahstat);
2221eaf0ac3Slogwang static void print_espstats(const struct espstat *espstat);
2231eaf0ac3Slogwang static void print_ipcompstats(const struct ipcompstat *ipcompstat);
2241eaf0ac3Slogwang
2251eaf0ac3Slogwang /*
2261eaf0ac3Slogwang * Dump IPSEC statistics structure.
2271eaf0ac3Slogwang */
2281eaf0ac3Slogwang static void
ipsec_hist_new(const uint64_t * hist,size_t histmax,const struct val2str * name,const char * title,const char * cname)2291eaf0ac3Slogwang ipsec_hist_new(const uint64_t *hist, size_t histmax,
2301eaf0ac3Slogwang const struct val2str *name, const char *title, const char *cname)
2311eaf0ac3Slogwang {
2321eaf0ac3Slogwang int first;
2331eaf0ac3Slogwang size_t proto;
2341eaf0ac3Slogwang const struct val2str *p;
2351eaf0ac3Slogwang
2361eaf0ac3Slogwang first = 1;
2371eaf0ac3Slogwang for (proto = 0; proto < histmax; proto++) {
2381eaf0ac3Slogwang if (hist[proto] <= 0)
2391eaf0ac3Slogwang continue;
2401eaf0ac3Slogwang if (first) {
2411eaf0ac3Slogwang xo_open_list(cname);
2421eaf0ac3Slogwang xo_emit("\t{T:/%s histogram}:\n", title);
2431eaf0ac3Slogwang first = 0;
2441eaf0ac3Slogwang }
2451eaf0ac3Slogwang xo_open_instance(cname);
2461eaf0ac3Slogwang for (p = name; p && p->str; p++) {
2471eaf0ac3Slogwang if (p->val == (int)proto)
2481eaf0ac3Slogwang break;
2491eaf0ac3Slogwang }
2501eaf0ac3Slogwang if (p && p->str) {
2511eaf0ac3Slogwang xo_emit("\t\t{k:name}: {:count/%ju}\n", p->str,
2521eaf0ac3Slogwang (uintmax_t)hist[proto]);
2531eaf0ac3Slogwang } else {
2541eaf0ac3Slogwang xo_emit("\t\t#{k:name/%lu}: {:count/%ju}\n",
2551eaf0ac3Slogwang (unsigned long)proto, (uintmax_t)hist[proto]);
2561eaf0ac3Slogwang }
2571eaf0ac3Slogwang xo_close_instance(cname);
2581eaf0ac3Slogwang }
2591eaf0ac3Slogwang if (!first)
2601eaf0ac3Slogwang xo_close_list(cname);
2611eaf0ac3Slogwang }
2621eaf0ac3Slogwang
2631eaf0ac3Slogwang static void
print_ahstats(const struct ahstat * ahstat)2641eaf0ac3Slogwang print_ahstats(const struct ahstat *ahstat)
2651eaf0ac3Slogwang {
2661eaf0ac3Slogwang xo_open_container("ah-statictics");
2671eaf0ac3Slogwang
2681eaf0ac3Slogwang #define p(f, n, m) if (ahstat->f || sflag <= 1) \
2691eaf0ac3Slogwang xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
2701eaf0ac3Slogwang (uintmax_t)ahstat->f, plural(ahstat->f))
2711eaf0ac3Slogwang #define hist(f, n, t, c) \
2721eaf0ac3Slogwang ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c))
2731eaf0ac3Slogwang
2741eaf0ac3Slogwang p(ahs_hdrops, "dropped-short-header",
2751eaf0ac3Slogwang "packet%s shorter than header shows");
2761eaf0ac3Slogwang p(ahs_nopf, "dropped-bad-protocol",
2771eaf0ac3Slogwang "packet%s dropped; protocol family not supported");
2781eaf0ac3Slogwang p(ahs_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
2791eaf0ac3Slogwang p(ahs_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
2801eaf0ac3Slogwang p(ahs_qfull, "dropped-queue-full", "packet%s dropped; queue full");
2811eaf0ac3Slogwang p(ahs_noxform, "dropped-no-transform",
2821eaf0ac3Slogwang "packet%s dropped; no transform");
2831eaf0ac3Slogwang p(ahs_wrap, "replay-counter-wraps", "replay counter wrap%s");
2841eaf0ac3Slogwang p(ahs_badauth, "dropped-bad-auth",
2851eaf0ac3Slogwang "packet%s dropped; bad authentication detected");
2861eaf0ac3Slogwang p(ahs_badauthl, "dropped-bad-auth-level",
2871eaf0ac3Slogwang "packet%s dropped; bad authentication length");
2881eaf0ac3Slogwang p(ahs_replay, "possile-replay-detected",
2891eaf0ac3Slogwang "possible replay packet%s detected");
2901eaf0ac3Slogwang p(ahs_input, "received-packets", "packet%s in");
2911eaf0ac3Slogwang p(ahs_output, "send-packets", "packet%s out");
2921eaf0ac3Slogwang p(ahs_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
2931eaf0ac3Slogwang p(ahs_ibytes, "received-bytes", "byte%s in");
2941eaf0ac3Slogwang p(ahs_obytes, "send-bytes", "byte%s out");
2951eaf0ac3Slogwang p(ahs_toobig, "dropped-too-large",
2961eaf0ac3Slogwang "packet%s dropped; larger than IP_MAXPACKET");
2971eaf0ac3Slogwang p(ahs_pdrops, "dropped-policy-violation",
2981eaf0ac3Slogwang "packet%s blocked due to policy");
2991eaf0ac3Slogwang p(ahs_crypto, "crypto-failures", "crypto processing failure%s");
3001eaf0ac3Slogwang p(ahs_tunnel, "tunnel-failures", "tunnel sanity check failure%s");
3011eaf0ac3Slogwang hist(ahstat->ahs_hist, ipsec_ahnames,
3021eaf0ac3Slogwang "AH output", "ah-output-histogram");
3031eaf0ac3Slogwang
3041eaf0ac3Slogwang #undef p
3051eaf0ac3Slogwang #undef hist
3061eaf0ac3Slogwang xo_close_container("ah-statictics");
3071eaf0ac3Slogwang }
3081eaf0ac3Slogwang
3091eaf0ac3Slogwang void
ah_stats(u_long off,const char * name,int family __unused,int proto __unused)3101eaf0ac3Slogwang ah_stats(u_long off, const char *name, int family __unused, int proto __unused)
3111eaf0ac3Slogwang {
3121eaf0ac3Slogwang struct ahstat ahstat;
3131eaf0ac3Slogwang
3141eaf0ac3Slogwang if (fetch_stats("net.inet.ah.stats", off, &ahstat,
3151eaf0ac3Slogwang sizeof(ahstat), kread_counters) != 0)
3161eaf0ac3Slogwang return;
3171eaf0ac3Slogwang
3181eaf0ac3Slogwang xo_emit("{T:/%s}:\n", name);
3191eaf0ac3Slogwang
3201eaf0ac3Slogwang print_ahstats(&ahstat);
3211eaf0ac3Slogwang }
3221eaf0ac3Slogwang
3231eaf0ac3Slogwang static void
print_espstats(const struct espstat * espstat)3241eaf0ac3Slogwang print_espstats(const struct espstat *espstat)
3251eaf0ac3Slogwang {
3261eaf0ac3Slogwang xo_open_container("esp-statictics");
3271eaf0ac3Slogwang #define p(f, n, m) if (espstat->f || sflag <= 1) \
3281eaf0ac3Slogwang xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
3291eaf0ac3Slogwang (uintmax_t)espstat->f, plural(espstat->f))
3301eaf0ac3Slogwang #define hist(f, n, t, c) \
3311eaf0ac3Slogwang ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c));
3321eaf0ac3Slogwang
3331eaf0ac3Slogwang p(esps_hdrops, "dropped-short-header",
3341eaf0ac3Slogwang "packet%s shorter than header shows");
3351eaf0ac3Slogwang p(esps_nopf, "dropped-bad-protocol",
3361eaf0ac3Slogwang "packet%s dropped; protocol family not supported");
3371eaf0ac3Slogwang p(esps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
3381eaf0ac3Slogwang p(esps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
3391eaf0ac3Slogwang p(esps_qfull, "dropped-queue-full", "packet%s dropped; queue full");
3401eaf0ac3Slogwang p(esps_noxform, "dropped-no-transform",
3411eaf0ac3Slogwang "packet%s dropped; no transform");
3421eaf0ac3Slogwang p(esps_badilen, "dropped-bad-length", "packet%s dropped; bad ilen");
3431eaf0ac3Slogwang p(esps_wrap, "replay-counter-wraps", "replay counter wrap%s");
3441eaf0ac3Slogwang p(esps_badenc, "dropped-bad-crypto",
3451eaf0ac3Slogwang "packet%s dropped; bad encryption detected");
3461eaf0ac3Slogwang p(esps_badauth, "dropped-bad-auth",
3471eaf0ac3Slogwang "packet%s dropped; bad authentication detected");
3481eaf0ac3Slogwang p(esps_replay, "possible-replay-detected",
3491eaf0ac3Slogwang "possible replay packet%s detected");
3501eaf0ac3Slogwang p(esps_input, "received-packets", "packet%s in");
3511eaf0ac3Slogwang p(esps_output, "sent-packets", "packet%s out");
3521eaf0ac3Slogwang p(esps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
3531eaf0ac3Slogwang p(esps_ibytes, "receieve-bytes", "byte%s in");
3541eaf0ac3Slogwang p(esps_obytes, "sent-bytes", "byte%s out");
3551eaf0ac3Slogwang p(esps_toobig, "dropped-too-large",
3561eaf0ac3Slogwang "packet%s dropped; larger than IP_MAXPACKET");
3571eaf0ac3Slogwang p(esps_pdrops, "dropped-policy-violation",
3581eaf0ac3Slogwang "packet%s blocked due to policy");
3591eaf0ac3Slogwang p(esps_crypto, "crypto-failures", "crypto processing failure%s");
3601eaf0ac3Slogwang p(esps_tunnel, "tunnel-failures", "tunnel sanity check failure%s");
3611eaf0ac3Slogwang hist(espstat->esps_hist, ipsec_espnames,
3621eaf0ac3Slogwang "ESP output", "esp-output-histogram");
3631eaf0ac3Slogwang
3641eaf0ac3Slogwang #undef p
3651eaf0ac3Slogwang #undef hist
3661eaf0ac3Slogwang xo_close_container("esp-statictics");
3671eaf0ac3Slogwang }
3681eaf0ac3Slogwang
3691eaf0ac3Slogwang void
esp_stats(u_long off,const char * name,int family __unused,int proto __unused)3701eaf0ac3Slogwang esp_stats(u_long off, const char *name, int family __unused, int proto __unused)
3711eaf0ac3Slogwang {
3721eaf0ac3Slogwang struct espstat espstat;
3731eaf0ac3Slogwang
3741eaf0ac3Slogwang if (fetch_stats("net.inet.esp.stats", off, &espstat,
3751eaf0ac3Slogwang sizeof(espstat), kread_counters) != 0)
3761eaf0ac3Slogwang return;
3771eaf0ac3Slogwang
3781eaf0ac3Slogwang xo_emit("{T:/%s}:\n", name);
3791eaf0ac3Slogwang
3801eaf0ac3Slogwang print_espstats(&espstat);
3811eaf0ac3Slogwang }
3821eaf0ac3Slogwang
3831eaf0ac3Slogwang static void
print_ipcompstats(const struct ipcompstat * ipcompstat)3841eaf0ac3Slogwang print_ipcompstats(const struct ipcompstat *ipcompstat)
3851eaf0ac3Slogwang {
3861eaf0ac3Slogwang xo_open_container("ipcomp-statictics");
3871eaf0ac3Slogwang
3881eaf0ac3Slogwang #define p(f, n, m) if (ipcompstat->f || sflag <= 1) \
3891eaf0ac3Slogwang xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
3901eaf0ac3Slogwang (uintmax_t)ipcompstat->f, plural(ipcompstat->f))
3911eaf0ac3Slogwang #define hist(f, n, t, c) \
3921eaf0ac3Slogwang ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c));
3931eaf0ac3Slogwang
3941eaf0ac3Slogwang p(ipcomps_hdrops, "dropped-short-header",
3951eaf0ac3Slogwang "packet%s shorter than header shows");
3961eaf0ac3Slogwang p(ipcomps_nopf, "dropped-bad-protocol",
3971eaf0ac3Slogwang "packet%s dropped; protocol family not supported");
3981eaf0ac3Slogwang p(ipcomps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
3991eaf0ac3Slogwang p(ipcomps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
4001eaf0ac3Slogwang p(ipcomps_qfull, "dropped-queue-full", "packet%s dropped; queue full");
4011eaf0ac3Slogwang p(ipcomps_noxform, "dropped-no-transform",
4021eaf0ac3Slogwang "packet%s dropped; no transform");
4031eaf0ac3Slogwang p(ipcomps_wrap, "replay-counter-wraps", "replay counter wrap%s");
4041eaf0ac3Slogwang p(ipcomps_input, "receieve-packets", "packet%s in");
4051eaf0ac3Slogwang p(ipcomps_output, "sent-packets", "packet%s out");
4061eaf0ac3Slogwang p(ipcomps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
4071eaf0ac3Slogwang p(ipcomps_ibytes, "receieved-bytes", "byte%s in");
4081eaf0ac3Slogwang p(ipcomps_obytes, "sent-bytes", "byte%s out");
4091eaf0ac3Slogwang p(ipcomps_toobig, "dropped-too-large",
4101eaf0ac3Slogwang "packet%s dropped; larger than IP_MAXPACKET");
4111eaf0ac3Slogwang p(ipcomps_pdrops, "dropped-policy-violation",
4121eaf0ac3Slogwang "packet%s blocked due to policy");
4131eaf0ac3Slogwang p(ipcomps_crypto, "crypto-failure", "crypto processing failure%s");
4141eaf0ac3Slogwang hist(ipcompstat->ipcomps_hist, ipsec_compnames,
4151eaf0ac3Slogwang "COMP output", "comp-output-histogram");
4161eaf0ac3Slogwang p(ipcomps_threshold, "sent-uncompressed-small-packets",
4171eaf0ac3Slogwang "packet%s sent uncompressed; size < compr. algo. threshold");
4181eaf0ac3Slogwang p(ipcomps_uncompr, "sent-uncompressed-useless-packets",
4191eaf0ac3Slogwang "packet%s sent uncompressed; compression was useless");
4201eaf0ac3Slogwang
4211eaf0ac3Slogwang #undef p
4221eaf0ac3Slogwang #undef hist
4231eaf0ac3Slogwang xo_close_container("ipcomp-statictics");
4241eaf0ac3Slogwang }
4251eaf0ac3Slogwang
4261eaf0ac3Slogwang void
ipcomp_stats(u_long off,const char * name,int family __unused,int proto __unused)4271eaf0ac3Slogwang ipcomp_stats(u_long off, const char *name, int family __unused,
4281eaf0ac3Slogwang int proto __unused)
4291eaf0ac3Slogwang {
4301eaf0ac3Slogwang struct ipcompstat ipcompstat;
4311eaf0ac3Slogwang
4321eaf0ac3Slogwang if (fetch_stats("net.inet.ipcomp.stats", off, &ipcompstat,
4331eaf0ac3Slogwang sizeof(ipcompstat), kread_counters) != 0)
4341eaf0ac3Slogwang return;
4351eaf0ac3Slogwang
4361eaf0ac3Slogwang xo_emit("{T:/%s}:\n", name);
4371eaf0ac3Slogwang
4381eaf0ac3Slogwang print_ipcompstats(&ipcompstat);
4391eaf0ac3Slogwang }
4401eaf0ac3Slogwang
4411eaf0ac3Slogwang #endif /*IPSEC*/
442