122a4e209SHajimu UMEMOTO /* $KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $ */
232cd1d96SJun-ichiro itojun Hagino
365475bc8SDavid E. O'Brien /*-
48a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
58a16b7a1SPedro F. Giffuni *
6100b98dbSKelly Yancey * Copyright (c) 2005 NTT Multimedia Communications Laboratories, Inc.
7100b98dbSKelly Yancey * All rights reserved.
8100b98dbSKelly Yancey *
9100b98dbSKelly Yancey * Redistribution and use in source and binary forms, with or without
10100b98dbSKelly Yancey * modification, are permitted provided that the following conditions
11100b98dbSKelly Yancey * are met:
12100b98dbSKelly Yancey * 1. Redistributions of source code must retain the above copyright
13100b98dbSKelly Yancey * notice, this list of conditions and the following disclaimer.
14100b98dbSKelly Yancey * 2. Redistributions in binary form must reproduce the above copyright
15100b98dbSKelly Yancey * notice, this list of conditions and the following disclaimer in the
16100b98dbSKelly Yancey * documentation and/or other materials provided with the distribution.
17100b98dbSKelly Yancey *
18100b98dbSKelly Yancey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19100b98dbSKelly Yancey * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20100b98dbSKelly Yancey * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21100b98dbSKelly Yancey * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22100b98dbSKelly Yancey * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23100b98dbSKelly Yancey * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24100b98dbSKelly Yancey * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25100b98dbSKelly Yancey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26100b98dbSKelly Yancey * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27100b98dbSKelly Yancey * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28100b98dbSKelly Yancey * SUCH DAMAGE.
29100b98dbSKelly Yancey */
3065475bc8SDavid E. O'Brien /*-
3132cd1d96SJun-ichiro itojun Hagino * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
3232cd1d96SJun-ichiro itojun Hagino * All rights reserved.
3332cd1d96SJun-ichiro itojun Hagino *
3432cd1d96SJun-ichiro itojun Hagino * Redistribution and use in source and binary forms, with or without
3532cd1d96SJun-ichiro itojun Hagino * modification, are permitted provided that the following conditions
3632cd1d96SJun-ichiro itojun Hagino * are met:
3732cd1d96SJun-ichiro itojun Hagino * 1. Redistributions of source code must retain the above copyright
3832cd1d96SJun-ichiro itojun Hagino * notice, this list of conditions and the following disclaimer.
3932cd1d96SJun-ichiro itojun Hagino * 2. Redistributions in binary form must reproduce the above copyright
4032cd1d96SJun-ichiro itojun Hagino * notice, this list of conditions and the following disclaimer in the
4132cd1d96SJun-ichiro itojun Hagino * documentation and/or other materials provided with the distribution.
4232cd1d96SJun-ichiro itojun Hagino * 3. Neither the name of the project nor the names of its contributors
4332cd1d96SJun-ichiro itojun Hagino * may be used to endorse or promote products derived from this software
4432cd1d96SJun-ichiro itojun Hagino * without specific prior written permission.
4532cd1d96SJun-ichiro itojun Hagino *
4632cd1d96SJun-ichiro itojun Hagino * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
4732cd1d96SJun-ichiro itojun Hagino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4832cd1d96SJun-ichiro itojun Hagino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4932cd1d96SJun-ichiro itojun Hagino * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
5032cd1d96SJun-ichiro itojun Hagino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5132cd1d96SJun-ichiro itojun Hagino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5232cd1d96SJun-ichiro itojun Hagino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5332cd1d96SJun-ichiro itojun Hagino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5432cd1d96SJun-ichiro itojun Hagino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5532cd1d96SJun-ichiro itojun Hagino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5632cd1d96SJun-ichiro itojun Hagino * SUCH DAMAGE.
5732cd1d96SJun-ichiro itojun Hagino */
5865475bc8SDavid E. O'Brien /*-
5932cd1d96SJun-ichiro itojun Hagino * Copyright (c) 1983, 1988, 1993
6032cd1d96SJun-ichiro itojun Hagino * The Regents of the University of California. All rights reserved.
6132cd1d96SJun-ichiro itojun Hagino *
6232cd1d96SJun-ichiro itojun Hagino * Redistribution and use in source and binary forms, with or without
6332cd1d96SJun-ichiro itojun Hagino * modification, are permitted provided that the following conditions
6432cd1d96SJun-ichiro itojun Hagino * are met:
6532cd1d96SJun-ichiro itojun Hagino * 1. Redistributions of source code must retain the above copyright
6632cd1d96SJun-ichiro itojun Hagino * notice, this list of conditions and the following disclaimer.
6732cd1d96SJun-ichiro itojun Hagino * 2. Redistributions in binary form must reproduce the above copyright
6832cd1d96SJun-ichiro itojun Hagino * notice, this list of conditions and the following disclaimer in the
6932cd1d96SJun-ichiro itojun Hagino * documentation and/or other materials provided with the distribution.
70fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
7132cd1d96SJun-ichiro itojun Hagino * may be used to endorse or promote products derived from this software
7232cd1d96SJun-ichiro itojun Hagino * without specific prior written permission.
7332cd1d96SJun-ichiro itojun Hagino *
7432cd1d96SJun-ichiro itojun Hagino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
7532cd1d96SJun-ichiro itojun Hagino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7632cd1d96SJun-ichiro itojun Hagino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7732cd1d96SJun-ichiro itojun Hagino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
7832cd1d96SJun-ichiro itojun Hagino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7932cd1d96SJun-ichiro itojun Hagino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8032cd1d96SJun-ichiro itojun Hagino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8132cd1d96SJun-ichiro itojun Hagino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
8232cd1d96SJun-ichiro itojun Hagino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
8332cd1d96SJun-ichiro itojun Hagino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
8432cd1d96SJun-ichiro itojun Hagino * SUCH DAMAGE.
8532cd1d96SJun-ichiro itojun Hagino */
8632cd1d96SJun-ichiro itojun Hagino
8732cd1d96SJun-ichiro itojun Hagino #include <sys/param.h>
8832cd1d96SJun-ichiro itojun Hagino #include <sys/queue.h>
8932cd1d96SJun-ichiro itojun Hagino #include <sys/socket.h>
90feda1a43SJohn Baldwin #include <sys/socketvar.h>
9132cd1d96SJun-ichiro itojun Hagino
9232cd1d96SJun-ichiro itojun Hagino #include <netinet/in.h>
9332cd1d96SJun-ichiro itojun Hagino
948409aedfSGeorge V. Neville-Neil #ifdef IPSEC
95100b98dbSKelly Yancey #include <netipsec/ipsec.h>
96100b98dbSKelly Yancey #include <netipsec/ah_var.h>
97100b98dbSKelly Yancey #include <netipsec/esp_var.h>
98100b98dbSKelly Yancey #include <netipsec/ipcomp_var.h>
9932cd1d96SJun-ichiro itojun Hagino #endif
10032cd1d96SJun-ichiro itojun Hagino
1017b95a1ebSYaroslav Tykhiy #include <stdint.h>
10232cd1d96SJun-ichiro itojun Hagino #include <stdio.h>
103ade9ccfeSMarcel Moolenaar #include <stdbool.h>
104821df508SXin LI #include <string.h>
105821df508SXin LI #include <unistd.h>
106ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
10732cd1d96SJun-ichiro itojun Hagino #include "netstat.h"
10832cd1d96SJun-ichiro itojun Hagino
10932cd1d96SJun-ichiro itojun Hagino #ifdef IPSEC
11033841545SHajimu UMEMOTO struct val2str {
11133841545SHajimu UMEMOTO int val;
11233841545SHajimu UMEMOTO const char *str;
11332cd1d96SJun-ichiro itojun Hagino };
11432cd1d96SJun-ichiro itojun Hagino
11533841545SHajimu UMEMOTO static struct val2str ipsec_ahnames[] = {
11633841545SHajimu UMEMOTO { SADB_AALG_NONE, "none", },
11733841545SHajimu UMEMOTO { SADB_AALG_SHA1HMAC, "hmac-sha1", },
11833841545SHajimu UMEMOTO { SADB_X_AALG_NULL, "null", },
11933841545SHajimu UMEMOTO { SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
12033841545SHajimu UMEMOTO { SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
12133841545SHajimu UMEMOTO { SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
12222a4e209SHajimu UMEMOTO { SADB_X_AALG_AES_XCBC_MAC, "aes-xcbc-mac", },
12367b3fe8eSJohn Baldwin { SADB_X_AALG_TCP_MD5, "tcp-md5", },
124708e72dcSJohn Baldwin { SADB_X_AALG_AES128GMAC, "aes-gmac-128", },
125708e72dcSJohn Baldwin { SADB_X_AALG_AES192GMAC, "aes-gmac-192", },
126708e72dcSJohn Baldwin { SADB_X_AALG_AES256GMAC, "aes-gmac-256", },
12733841545SHajimu UMEMOTO { -1, NULL },
12832cd1d96SJun-ichiro itojun Hagino };
12932cd1d96SJun-ichiro itojun Hagino
13033841545SHajimu UMEMOTO static struct val2str ipsec_espnames[] = {
13133841545SHajimu UMEMOTO { SADB_EALG_NONE, "none", },
13233841545SHajimu UMEMOTO { SADB_EALG_NULL, "null", },
13300a4311aSJohn Baldwin { SADB_X_EALG_AESCBC, "aes-cbc", },
13422a4e209SHajimu UMEMOTO { SADB_X_EALG_AESCTR, "aes-ctr", },
135987de844SGeorge V. Neville-Neil { SADB_X_EALG_AESGCM16, "aes-gcm-16", },
13667b3fe8eSJohn Baldwin { SADB_X_EALG_AESGMAC, "aes-gmac", },
13733841545SHajimu UMEMOTO { -1, NULL },
13833841545SHajimu UMEMOTO };
13933841545SHajimu UMEMOTO
14033841545SHajimu UMEMOTO static struct val2str ipsec_compnames[] = {
14133841545SHajimu UMEMOTO { SADB_X_CALG_NONE, "none", },
14233841545SHajimu UMEMOTO { SADB_X_CALG_OUI, "oui", },
14333841545SHajimu UMEMOTO { SADB_X_CALG_DEFLATE, "deflate", },
14433841545SHajimu UMEMOTO { SADB_X_CALG_LZS, "lzs", },
14533841545SHajimu UMEMOTO { -1, NULL },
14632cd1d96SJun-ichiro itojun Hagino };
14732cd1d96SJun-ichiro itojun Hagino
14832cd1d96SJun-ichiro itojun Hagino static void
print_ipsecstats(const char * tag,const struct ipsecstat * ipsecstat)149ae4fb190SMateusz Guzik print_ipsecstats(const char *tag, const struct ipsecstat *ipsecstat)
15032cd1d96SJun-ichiro itojun Hagino {
151ae4fb190SMateusz Guzik xo_open_container(tag);
152ade9ccfeSMarcel Moolenaar
153100b98dbSKelly Yancey #define p(f, m) if (ipsecstat->f || sflag <= 1) \
154ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f))
155f8e73c47SFabien Thomas #define p2(f, m) if (ipsecstat->f || sflag <= 1) \
156f8e73c47SFabien Thomas xo_emit(m, (uintmax_t)ipsecstat->f, plurales(ipsecstat->f))
157ade9ccfeSMarcel Moolenaar
158ade9ccfeSMarcel Moolenaar p(ips_in_polvio, "\t{:dropped-policy-violation/%ju} "
159ade9ccfeSMarcel Moolenaar "{N:/inbound packet%s violated process security policy}\n");
160ade9ccfeSMarcel Moolenaar p(ips_in_nomem, "\t{:dropped-no-memory/%ju} "
161ade9ccfeSMarcel Moolenaar "{N:/inbound packet%s failed due to insufficient memory}\n");
162ade9ccfeSMarcel Moolenaar p(ips_in_inval, "\t{:dropped-invalid/%ju} "
163ade9ccfeSMarcel Moolenaar "{N:/invalid inbound packet%s}\n");
164ade9ccfeSMarcel Moolenaar p(ips_out_polvio, "\t{:discarded-policy-violation/%ju} "
165ade9ccfeSMarcel Moolenaar "{N:/outbound packet%s violated process security policy}\n");
166ade9ccfeSMarcel Moolenaar p(ips_out_nosa, "\t{:discarded-no-sa/%ju} "
167ade9ccfeSMarcel Moolenaar "{N:/outbound packet%s with no SA available}\n");
168ade9ccfeSMarcel Moolenaar p(ips_out_nomem, "\t{:discarded-no-memory/%ju} "
169ade9ccfeSMarcel Moolenaar "{N:/outbound packet%s failed due to insufficient memory}\n");
170ade9ccfeSMarcel Moolenaar p(ips_out_noroute, "\t{:discarded-no-route/%ju} "
171ade9ccfeSMarcel Moolenaar "{N:/outbound packet%s with no route available}\n");
172ade9ccfeSMarcel Moolenaar p(ips_out_inval, "\t{:discarded-invalid/%ju} "
173ade9ccfeSMarcel Moolenaar "{N:/invalid outbound packet%s}\n");
174ade9ccfeSMarcel Moolenaar p(ips_out_bundlesa, "\t{:send-bundled-sa/%ju} "
175ade9ccfeSMarcel Moolenaar "{N:/outbound packet%s with bundled SAs}\n");
176f8e73c47SFabien Thomas p(ips_spdcache_hits, "\t{:spdcache-hits/%ju} "
177f8e73c47SFabien Thomas "{N:/spd cache hit%s}\n");
178f8e73c47SFabien Thomas p2(ips_spdcache_misses, "\t{:spdcache-misses/%ju} "
179f8e73c47SFabien Thomas "{N:/spd cache miss%s}\n");
180ade9ccfeSMarcel Moolenaar p(ips_clcopied, "\t{:clusters-copied-during-clone/%ju} "
181ade9ccfeSMarcel Moolenaar "{N:/cluster%s copied during clone}\n");
182ade9ccfeSMarcel Moolenaar p(ips_mbinserted, "\t{:mbufs-inserted/%ju} "
183ade9ccfeSMarcel Moolenaar "{N:/mbuf%s inserted during makespace}\n");
184f8e73c47SFabien Thomas #undef p2
1858409aedfSGeorge V. Neville-Neil #undef p
186ae4fb190SMateusz Guzik xo_close_container(tag);
18732cd1d96SJun-ichiro itojun Hagino }
18832cd1d96SJun-ichiro itojun Hagino
18932cd1d96SJun-ichiro itojun Hagino void
ipsec_stats(u_long off,const char * name,int af1 __unused,int proto __unused)190feda1a43SJohn Baldwin ipsec_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
19132cd1d96SJun-ichiro itojun Hagino {
192100b98dbSKelly Yancey struct ipsecstat ipsecstat;
193ae4fb190SMateusz Guzik const char *tag;
194100b98dbSKelly Yancey
1959d2d8e7bSGeorge V. Neville-Neil if (strcmp(name, "ipsec6") == 0) {
1969d2d8e7bSGeorge V. Neville-Neil if (fetch_stats("net.inet6.ipsec6.ipsecstats", off,&ipsecstat,
1979d2d8e7bSGeorge V. Neville-Neil sizeof(ipsecstat), kread_counters) != 0)
19832cd1d96SJun-ichiro itojun Hagino return;
199ae4fb190SMateusz Guzik tag = "ipsec6-statistics";
2009d2d8e7bSGeorge V. Neville-Neil } else {
2019d2d8e7bSGeorge V. Neville-Neil if (fetch_stats("net.inet.ipsec.ipsecstats", off, &ipsecstat,
2029d2d8e7bSGeorge V. Neville-Neil sizeof(ipsecstat), kread_counters) != 0)
2039d2d8e7bSGeorge V. Neville-Neil return;
204ae4fb190SMateusz Guzik tag = "ipsec-statistics";
2059d2d8e7bSGeorge V. Neville-Neil }
2069d2d8e7bSGeorge V. Neville-Neil
207ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name);
20832cd1d96SJun-ichiro itojun Hagino
209ae4fb190SMateusz Guzik print_ipsecstats(tag, &ipsecstat);
21032cd1d96SJun-ichiro itojun Hagino }
21132cd1d96SJun-ichiro itojun Hagino
21232cd1d96SJun-ichiro itojun Hagino
213100b98dbSKelly Yancey static void print_ahstats(const struct ahstat *ahstat);
214100b98dbSKelly Yancey static void print_espstats(const struct espstat *espstat);
215100b98dbSKelly Yancey static void print_ipcompstats(const struct ipcompstat *ipcompstat);
216100b98dbSKelly Yancey
217100b98dbSKelly Yancey /*
218100b98dbSKelly Yancey * Dump IPSEC statistics structure.
219100b98dbSKelly Yancey */
220100b98dbSKelly Yancey static void
ipsec_hist_new(const uint64_t * hist,size_t histmax,const struct val2str * name,const char * title,const char * cname)221c80211e3SAndrey V. Elsukov ipsec_hist_new(const uint64_t *hist, size_t histmax,
222ade9ccfeSMarcel Moolenaar const struct val2str *name, const char *title, const char *cname)
223100b98dbSKelly Yancey {
224100b98dbSKelly Yancey int first;
225100b98dbSKelly Yancey size_t proto;
226100b98dbSKelly Yancey const struct val2str *p;
227100b98dbSKelly Yancey
228100b98dbSKelly Yancey first = 1;
229100b98dbSKelly Yancey for (proto = 0; proto < histmax; proto++) {
230100b98dbSKelly Yancey if (hist[proto] <= 0)
231100b98dbSKelly Yancey continue;
232100b98dbSKelly Yancey if (first) {
233ade9ccfeSMarcel Moolenaar xo_open_list(cname);
234ade9ccfeSMarcel Moolenaar xo_emit("\t{T:/%s histogram}:\n", title);
235100b98dbSKelly Yancey first = 0;
236100b98dbSKelly Yancey }
237ade9ccfeSMarcel Moolenaar xo_open_instance(cname);
238100b98dbSKelly Yancey for (p = name; p && p->str; p++) {
239100b98dbSKelly Yancey if (p->val == (int)proto)
240100b98dbSKelly Yancey break;
241100b98dbSKelly Yancey }
242100b98dbSKelly Yancey if (p && p->str) {
243ade9ccfeSMarcel Moolenaar xo_emit("\t\t{k:name}: {:count/%ju}\n", p->str,
244c80211e3SAndrey V. Elsukov (uintmax_t)hist[proto]);
245100b98dbSKelly Yancey } else {
246ade9ccfeSMarcel Moolenaar xo_emit("\t\t#{k:name/%lu}: {:count/%ju}\n",
247ade9ccfeSMarcel Moolenaar (unsigned long)proto, (uintmax_t)hist[proto]);
248100b98dbSKelly Yancey }
249ade9ccfeSMarcel Moolenaar xo_close_instance(cname);
250100b98dbSKelly Yancey }
251ade9ccfeSMarcel Moolenaar if (!first)
252ade9ccfeSMarcel Moolenaar xo_close_list(cname);
253100b98dbSKelly Yancey }
254100b98dbSKelly Yancey
255100b98dbSKelly Yancey static void
print_ahstats(const struct ahstat * ahstat)256100b98dbSKelly Yancey print_ahstats(const struct ahstat *ahstat)
257100b98dbSKelly Yancey {
258ade9ccfeSMarcel Moolenaar xo_open_container("ah-statictics");
25932cd1d96SJun-ichiro itojun Hagino
260ade9ccfeSMarcel Moolenaar #define p(f, n, m) if (ahstat->f || sflag <= 1) \
261ade9ccfeSMarcel Moolenaar xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
262ade9ccfeSMarcel Moolenaar (uintmax_t)ahstat->f, plural(ahstat->f))
263ade9ccfeSMarcel Moolenaar #define hist(f, n, t, c) \
264ade9ccfeSMarcel Moolenaar ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c))
265ade9ccfeSMarcel Moolenaar
266ade9ccfeSMarcel Moolenaar p(ahs_hdrops, "dropped-short-header",
267ade9ccfeSMarcel Moolenaar "packet%s shorter than header shows");
268ade9ccfeSMarcel Moolenaar p(ahs_nopf, "dropped-bad-protocol",
269ade9ccfeSMarcel Moolenaar "packet%s dropped; protocol family not supported");
270ade9ccfeSMarcel Moolenaar p(ahs_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
271ade9ccfeSMarcel Moolenaar p(ahs_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
272ade9ccfeSMarcel Moolenaar p(ahs_qfull, "dropped-queue-full", "packet%s dropped; queue full");
273ade9ccfeSMarcel Moolenaar p(ahs_noxform, "dropped-no-transform",
274ade9ccfeSMarcel Moolenaar "packet%s dropped; no transform");
275ade9ccfeSMarcel Moolenaar p(ahs_wrap, "replay-counter-wraps", "replay counter wrap%s");
276ade9ccfeSMarcel Moolenaar p(ahs_badauth, "dropped-bad-auth",
277ade9ccfeSMarcel Moolenaar "packet%s dropped; bad authentication detected");
278ade9ccfeSMarcel Moolenaar p(ahs_badauthl, "dropped-bad-auth-level",
279ade9ccfeSMarcel Moolenaar "packet%s dropped; bad authentication length");
280ade9ccfeSMarcel Moolenaar p(ahs_replay, "possile-replay-detected",
281ade9ccfeSMarcel Moolenaar "possible replay packet%s detected");
282ade9ccfeSMarcel Moolenaar p(ahs_input, "received-packets", "packet%s in");
283ade9ccfeSMarcel Moolenaar p(ahs_output, "send-packets", "packet%s out");
284ade9ccfeSMarcel Moolenaar p(ahs_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
285ade9ccfeSMarcel Moolenaar p(ahs_ibytes, "received-bytes", "byte%s in");
286ade9ccfeSMarcel Moolenaar p(ahs_obytes, "send-bytes", "byte%s out");
287ade9ccfeSMarcel Moolenaar p(ahs_toobig, "dropped-too-large",
288ade9ccfeSMarcel Moolenaar "packet%s dropped; larger than IP_MAXPACKET");
289ade9ccfeSMarcel Moolenaar p(ahs_pdrops, "dropped-policy-violation",
290ade9ccfeSMarcel Moolenaar "packet%s blocked due to policy");
291ade9ccfeSMarcel Moolenaar p(ahs_crypto, "crypto-failures", "crypto processing failure%s");
292ade9ccfeSMarcel Moolenaar p(ahs_tunnel, "tunnel-failures", "tunnel sanity check failure%s");
293ade9ccfeSMarcel Moolenaar hist(ahstat->ahs_hist, ipsec_ahnames,
294ade9ccfeSMarcel Moolenaar "AH output", "ah-output-histogram");
295100b98dbSKelly Yancey
296c80211e3SAndrey V. Elsukov #undef p
297100b98dbSKelly Yancey #undef hist
298ade9ccfeSMarcel Moolenaar xo_close_container("ah-statictics");
29932cd1d96SJun-ichiro itojun Hagino }
300100b98dbSKelly Yancey
301100b98dbSKelly Yancey void
ah_stats(u_long off,const char * name,int family __unused,int proto __unused)302feda1a43SJohn Baldwin ah_stats(u_long off, const char *name, int family __unused, int proto __unused)
303100b98dbSKelly Yancey {
304100b98dbSKelly Yancey struct ahstat ahstat;
305100b98dbSKelly Yancey
3069d2d8e7bSGeorge V. Neville-Neil if (fetch_stats("net.inet.ah.stats", off, &ahstat,
3079d2d8e7bSGeorge V. Neville-Neil sizeof(ahstat), kread_counters) != 0)
308100b98dbSKelly Yancey return;
3099d2d8e7bSGeorge V. Neville-Neil
310ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name);
311100b98dbSKelly Yancey
312100b98dbSKelly Yancey print_ahstats(&ahstat);
31332cd1d96SJun-ichiro itojun Hagino }
314100b98dbSKelly Yancey
315100b98dbSKelly Yancey static void
print_espstats(const struct espstat * espstat)316100b98dbSKelly Yancey print_espstats(const struct espstat *espstat)
317100b98dbSKelly Yancey {
318ade9ccfeSMarcel Moolenaar xo_open_container("esp-statictics");
319ade9ccfeSMarcel Moolenaar #define p(f, n, m) if (espstat->f || sflag <= 1) \
320ade9ccfeSMarcel Moolenaar xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
321ade9ccfeSMarcel Moolenaar (uintmax_t)espstat->f, plural(espstat->f))
322ade9ccfeSMarcel Moolenaar #define hist(f, n, t, c) \
323ade9ccfeSMarcel Moolenaar ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c));
324100b98dbSKelly Yancey
325ade9ccfeSMarcel Moolenaar p(esps_hdrops, "dropped-short-header",
326ade9ccfeSMarcel Moolenaar "packet%s shorter than header shows");
327ade9ccfeSMarcel Moolenaar p(esps_nopf, "dropped-bad-protocol",
328ade9ccfeSMarcel Moolenaar "packet%s dropped; protocol family not supported");
329ade9ccfeSMarcel Moolenaar p(esps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
330ade9ccfeSMarcel Moolenaar p(esps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
331ade9ccfeSMarcel Moolenaar p(esps_qfull, "dropped-queue-full", "packet%s dropped; queue full");
332ade9ccfeSMarcel Moolenaar p(esps_noxform, "dropped-no-transform",
333ade9ccfeSMarcel Moolenaar "packet%s dropped; no transform");
334ade9ccfeSMarcel Moolenaar p(esps_badilen, "dropped-bad-length", "packet%s dropped; bad ilen");
335ade9ccfeSMarcel Moolenaar p(esps_wrap, "replay-counter-wraps", "replay counter wrap%s");
336ade9ccfeSMarcel Moolenaar p(esps_badenc, "dropped-bad-crypto",
337ade9ccfeSMarcel Moolenaar "packet%s dropped; bad encryption detected");
338ade9ccfeSMarcel Moolenaar p(esps_badauth, "dropped-bad-auth",
339ade9ccfeSMarcel Moolenaar "packet%s dropped; bad authentication detected");
340ade9ccfeSMarcel Moolenaar p(esps_replay, "possible-replay-detected",
341ade9ccfeSMarcel Moolenaar "possible replay packet%s detected");
342ade9ccfeSMarcel Moolenaar p(esps_input, "received-packets", "packet%s in");
343ade9ccfeSMarcel Moolenaar p(esps_output, "sent-packets", "packet%s out");
344ade9ccfeSMarcel Moolenaar p(esps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
345*ecc467ebSGordon Bergling p(esps_ibytes, "receive-bytes", "byte%s in");
346ade9ccfeSMarcel Moolenaar p(esps_obytes, "sent-bytes", "byte%s out");
347ade9ccfeSMarcel Moolenaar p(esps_toobig, "dropped-too-large",
348ade9ccfeSMarcel Moolenaar "packet%s dropped; larger than IP_MAXPACKET");
349ade9ccfeSMarcel Moolenaar p(esps_pdrops, "dropped-policy-violation",
350ade9ccfeSMarcel Moolenaar "packet%s blocked due to policy");
351ade9ccfeSMarcel Moolenaar p(esps_crypto, "crypto-failures", "crypto processing failure%s");
352ade9ccfeSMarcel Moolenaar p(esps_tunnel, "tunnel-failures", "tunnel sanity check failure%s");
353ade9ccfeSMarcel Moolenaar hist(espstat->esps_hist, ipsec_espnames,
354ade9ccfeSMarcel Moolenaar "ESP output", "esp-output-histogram");
355100b98dbSKelly Yancey
356c80211e3SAndrey V. Elsukov #undef p
357100b98dbSKelly Yancey #undef hist
358ade9ccfeSMarcel Moolenaar xo_close_container("esp-statictics");
35932cd1d96SJun-ichiro itojun Hagino }
360100b98dbSKelly Yancey
361100b98dbSKelly Yancey void
esp_stats(u_long off,const char * name,int family __unused,int proto __unused)362feda1a43SJohn Baldwin esp_stats(u_long off, const char *name, int family __unused, int proto __unused)
363100b98dbSKelly Yancey {
364100b98dbSKelly Yancey struct espstat espstat;
365100b98dbSKelly Yancey
3669d2d8e7bSGeorge V. Neville-Neil if (fetch_stats("net.inet.esp.stats", off, &espstat,
3679d2d8e7bSGeorge V. Neville-Neil sizeof(espstat), kread_counters) != 0)
368100b98dbSKelly Yancey return;
3699d2d8e7bSGeorge V. Neville-Neil
370ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name);
371100b98dbSKelly Yancey
372100b98dbSKelly Yancey print_espstats(&espstat);
373100b98dbSKelly Yancey }
374100b98dbSKelly Yancey
375100b98dbSKelly Yancey static void
print_ipcompstats(const struct ipcompstat * ipcompstat)376100b98dbSKelly Yancey print_ipcompstats(const struct ipcompstat *ipcompstat)
377100b98dbSKelly Yancey {
378ade9ccfeSMarcel Moolenaar xo_open_container("ipcomp-statictics");
379100b98dbSKelly Yancey
380ade9ccfeSMarcel Moolenaar #define p(f, n, m) if (ipcompstat->f || sflag <= 1) \
381ade9ccfeSMarcel Moolenaar xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
382ade9ccfeSMarcel Moolenaar (uintmax_t)ipcompstat->f, plural(ipcompstat->f))
383ade9ccfeSMarcel Moolenaar #define hist(f, n, t, c) \
384ade9ccfeSMarcel Moolenaar ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c));
385ade9ccfeSMarcel Moolenaar
386ade9ccfeSMarcel Moolenaar p(ipcomps_hdrops, "dropped-short-header",
387ade9ccfeSMarcel Moolenaar "packet%s shorter than header shows");
388ade9ccfeSMarcel Moolenaar p(ipcomps_nopf, "dropped-bad-protocol",
389ade9ccfeSMarcel Moolenaar "packet%s dropped; protocol family not supported");
390ade9ccfeSMarcel Moolenaar p(ipcomps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
391ade9ccfeSMarcel Moolenaar p(ipcomps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
392ade9ccfeSMarcel Moolenaar p(ipcomps_qfull, "dropped-queue-full", "packet%s dropped; queue full");
393ade9ccfeSMarcel Moolenaar p(ipcomps_noxform, "dropped-no-transform",
394ade9ccfeSMarcel Moolenaar "packet%s dropped; no transform");
395ade9ccfeSMarcel Moolenaar p(ipcomps_wrap, "replay-counter-wraps", "replay counter wrap%s");
396*ecc467ebSGordon Bergling p(ipcomps_input, "receive-packets", "packet%s in");
397ade9ccfeSMarcel Moolenaar p(ipcomps_output, "sent-packets", "packet%s out");
398ade9ccfeSMarcel Moolenaar p(ipcomps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
399*ecc467ebSGordon Bergling p(ipcomps_ibytes, "received-bytes", "byte%s in");
400ade9ccfeSMarcel Moolenaar p(ipcomps_obytes, "sent-bytes", "byte%s out");
401ade9ccfeSMarcel Moolenaar p(ipcomps_toobig, "dropped-too-large",
402ade9ccfeSMarcel Moolenaar "packet%s dropped; larger than IP_MAXPACKET");
403ade9ccfeSMarcel Moolenaar p(ipcomps_pdrops, "dropped-policy-violation",
404ade9ccfeSMarcel Moolenaar "packet%s blocked due to policy");
405ade9ccfeSMarcel Moolenaar p(ipcomps_crypto, "crypto-failure", "crypto processing failure%s");
406ade9ccfeSMarcel Moolenaar hist(ipcompstat->ipcomps_hist, ipsec_compnames,
407ade9ccfeSMarcel Moolenaar "COMP output", "comp-output-histogram");
408ade9ccfeSMarcel Moolenaar p(ipcomps_threshold, "sent-uncompressed-small-packets",
409ade9ccfeSMarcel Moolenaar "packet%s sent uncompressed; size < compr. algo. threshold");
410ade9ccfeSMarcel Moolenaar p(ipcomps_uncompr, "sent-uncompressed-useless-packets",
411ade9ccfeSMarcel Moolenaar "packet%s sent uncompressed; compression was useless");
412100b98dbSKelly Yancey
413c80211e3SAndrey V. Elsukov #undef p
414100b98dbSKelly Yancey #undef hist
415ade9ccfeSMarcel Moolenaar xo_close_container("ipcomp-statictics");
416100b98dbSKelly Yancey }
417100b98dbSKelly Yancey
418100b98dbSKelly Yancey void
ipcomp_stats(u_long off,const char * name,int family __unused,int proto __unused)419feda1a43SJohn Baldwin ipcomp_stats(u_long off, const char *name, int family __unused,
420feda1a43SJohn Baldwin int proto __unused)
421100b98dbSKelly Yancey {
422100b98dbSKelly Yancey struct ipcompstat ipcompstat;
423100b98dbSKelly Yancey
4249d2d8e7bSGeorge V. Neville-Neil if (fetch_stats("net.inet.ipcomp.stats", off, &ipcompstat,
4259d2d8e7bSGeorge V. Neville-Neil sizeof(ipcompstat), kread_counters) != 0)
426100b98dbSKelly Yancey return;
4279d2d8e7bSGeorge V. Neville-Neil
428ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name);
429100b98dbSKelly Yancey
430100b98dbSKelly Yancey print_ipcompstats(&ipcompstat);
431100b98dbSKelly Yancey }
432100b98dbSKelly Yancey
43332cd1d96SJun-ichiro itojun Hagino #endif /*IPSEC*/
434