Deleted Added
full compact
ipsec.c (78309) ipsec.c (78314)
1/* $FreeBSD: head/usr.bin/netstat/ipsec.c 78309 2001-06-15 23:07:59Z assar $ */
1/* $FreeBSD: head/usr.bin/netstat/ipsec.c 78314 2001-06-15 23:35:13Z assar $ */
2/* $NetBSD: inet.c,v 1.35.2.1 1999/04/29 14:57:08 perry Exp $ */
3/* $KAME: ipsec.c,v 1.25 2001/03/12 09:04:39 itojun Exp $ */
4
5/*
6 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * Copyright (c) 1983, 1988, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 */
66
67#include <sys/cdefs.h>
68#ifndef lint
69/*
70static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
71*/
72static const char rcsid[] =
2/* $NetBSD: inet.c,v 1.35.2.1 1999/04/29 14:57:08 perry Exp $ */
3/* $KAME: ipsec.c,v 1.25 2001/03/12 09:04:39 itojun Exp $ */
4
5/*
6 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * Copyright (c) 1983, 1988, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 */
66
67#include <sys/cdefs.h>
68#ifndef lint
69/*
70static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
71*/
72static const char rcsid[] =
73 "$FreeBSD: head/usr.bin/netstat/ipsec.c 78309 2001-06-15 23:07:59Z assar $";
73 "$FreeBSD: head/usr.bin/netstat/ipsec.c 78314 2001-06-15 23:35:13Z assar $";
74#endif /* not lint */
75
76#include <sys/param.h>
77#include <sys/queue.h>
78#include <sys/socket.h>
79
80#include <netinet/in.h>
81
82#ifdef IPSEC
83#include <netinet6/ipsec.h>
84#include <netkey/keysock.h>
85#endif
86
87#include <stdio.h>
88#include <string.h>
89#include <unistd.h>
90#include "netstat.h"
91
92/*
93 * portability issues:
94 * - bsdi[34] uses PLURAL(), not plural().
95 * - freebsd2 can't print "unsigned long long" properly.
96 */
97/*
98 * XXX see PORTABILITY for the twist
99 */
100#define LLU "%llu"
101#define CAST unsigned long long
102
103#ifdef IPSEC
104struct val2str {
105 int val;
106 const char *str;
107};
108
109static struct val2str ipsec_ahnames[] = {
110 { SADB_AALG_NONE, "none", },
111 { SADB_AALG_MD5HMAC, "hmac-md5", },
112 { SADB_AALG_SHA1HMAC, "hmac-sha1", },
113 { SADB_X_AALG_MD5, "md5", },
114 { SADB_X_AALG_SHA, "sha", },
115 { SADB_X_AALG_NULL, "null", },
116#ifdef SADB_X_AALG_SHA2_256
117 { SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
118#endif
119#ifdef SADB_X_AALG_SHA2_384
120 { SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
121#endif
122#ifdef SADB_X_AALG_SHA2_512
123 { SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
124#endif
125 { -1, NULL },
126};
127
128static struct val2str ipsec_espnames[] = {
129 { SADB_EALG_NONE, "none", },
130 { SADB_EALG_DESCBC, "des-cbc", },
131 { SADB_EALG_3DESCBC, "3des-cbc", },
132 { SADB_EALG_NULL, "null", },
133#ifdef SADB_X_EALG_RC5CBC
134 { SADB_X_EALG_RC5CBC, "rc5-cbc", },
135#endif
136 { SADB_X_EALG_CAST128CBC, "cast128-cbc", },
137 { SADB_X_EALG_BLOWFISHCBC, "blowfish-cbc", },
138#ifdef SADB_X_EALG_RIJNDAELCBC
139 { SADB_X_EALG_RIJNDAELCBC, "rijndael-cbc", },
140#endif
141 { -1, NULL },
142};
143
144static struct val2str ipsec_compnames[] = {
145 { SADB_X_CALG_NONE, "none", },
146 { SADB_X_CALG_OUI, "oui", },
147 { SADB_X_CALG_DEFLATE, "deflate", },
148 { SADB_X_CALG_LZS, "lzs", },
149 { -1, NULL },
150};
151
152static const char *pfkey_msgtypenames[] = {
153 "reserved", "getspi", "update", "add", "delete",
154 "get", "acquire", "register", "expire", "flush",
155 "dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd",
156 "x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush",
157 "x_spdsetidx", "x_spdexpire", "x_spddelete2"
158};
159
160static struct ipsecstat ipsecstat;
161
74#endif /* not lint */
75
76#include <sys/param.h>
77#include <sys/queue.h>
78#include <sys/socket.h>
79
80#include <netinet/in.h>
81
82#ifdef IPSEC
83#include <netinet6/ipsec.h>
84#include <netkey/keysock.h>
85#endif
86
87#include <stdio.h>
88#include <string.h>
89#include <unistd.h>
90#include "netstat.h"
91
92/*
93 * portability issues:
94 * - bsdi[34] uses PLURAL(), not plural().
95 * - freebsd2 can't print "unsigned long long" properly.
96 */
97/*
98 * XXX see PORTABILITY for the twist
99 */
100#define LLU "%llu"
101#define CAST unsigned long long
102
103#ifdef IPSEC
104struct val2str {
105 int val;
106 const char *str;
107};
108
109static struct val2str ipsec_ahnames[] = {
110 { SADB_AALG_NONE, "none", },
111 { SADB_AALG_MD5HMAC, "hmac-md5", },
112 { SADB_AALG_SHA1HMAC, "hmac-sha1", },
113 { SADB_X_AALG_MD5, "md5", },
114 { SADB_X_AALG_SHA, "sha", },
115 { SADB_X_AALG_NULL, "null", },
116#ifdef SADB_X_AALG_SHA2_256
117 { SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
118#endif
119#ifdef SADB_X_AALG_SHA2_384
120 { SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
121#endif
122#ifdef SADB_X_AALG_SHA2_512
123 { SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
124#endif
125 { -1, NULL },
126};
127
128static struct val2str ipsec_espnames[] = {
129 { SADB_EALG_NONE, "none", },
130 { SADB_EALG_DESCBC, "des-cbc", },
131 { SADB_EALG_3DESCBC, "3des-cbc", },
132 { SADB_EALG_NULL, "null", },
133#ifdef SADB_X_EALG_RC5CBC
134 { SADB_X_EALG_RC5CBC, "rc5-cbc", },
135#endif
136 { SADB_X_EALG_CAST128CBC, "cast128-cbc", },
137 { SADB_X_EALG_BLOWFISHCBC, "blowfish-cbc", },
138#ifdef SADB_X_EALG_RIJNDAELCBC
139 { SADB_X_EALG_RIJNDAELCBC, "rijndael-cbc", },
140#endif
141 { -1, NULL },
142};
143
144static struct val2str ipsec_compnames[] = {
145 { SADB_X_CALG_NONE, "none", },
146 { SADB_X_CALG_OUI, "oui", },
147 { SADB_X_CALG_DEFLATE, "deflate", },
148 { SADB_X_CALG_LZS, "lzs", },
149 { -1, NULL },
150};
151
152static const char *pfkey_msgtypenames[] = {
153 "reserved", "getspi", "update", "add", "delete",
154 "get", "acquire", "register", "expire", "flush",
155 "dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd",
156 "x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush",
157 "x_spdsetidx", "x_spdexpire", "x_spddelete2"
158};
159
160static struct ipsecstat ipsecstat;
161
162static void print_ipsecstats __P((void));
163static const char *pfkey_msgtype_names __P((int));
164static void ipsec_hist __P((const u_quad_t *, size_t, const struct val2str *,
165 size_t, const char *));
162static void print_ipsecstats (void);
163static const char *pfkey_msgtype_names (int);
164static void ipsec_hist (const u_quad_t *, size_t, const struct val2str *,
165 size_t, const char *);
166
167/*
168 * Dump IPSEC statistics structure.
169 */
170static void
166
167/*
168 * Dump IPSEC statistics structure.
169 */
170static void
171ipsec_hist(hist, histmax, name, namemax, title)
172 const u_quad_t *hist;
173 size_t histmax;
174 const struct val2str *name;
175 size_t namemax;
176 const char *title;
171ipsec_hist(const u_quad_t *hist,
172 size_t histmax,
173 const struct val2str *name,
174 size_t namemax,
175 const char *title)
177{
178 int first;
179 size_t proto;
180 const struct val2str *p;
181
182 first = 1;
183 for (proto = 0; proto < histmax; proto++) {
184 if (hist[proto] <= 0)
185 continue;
186 if (first) {
187 printf("\t%s histogram:\n", title);
188 first = 0;
189 }
190 for (p = name; p && p->str; p++) {
191 if (p->val == proto)
192 break;
193 }
194 if (p && p->str) {
195 printf("\t\t%s: " LLU "\n", p->str, (CAST)hist[proto]);
196 } else {
197 printf("\t\t#%ld: " LLU "\n", (long)proto,
198 (CAST)hist[proto]);
199 }
200 }
201}
202
203static void
176{
177 int first;
178 size_t proto;
179 const struct val2str *p;
180
181 first = 1;
182 for (proto = 0; proto < histmax; proto++) {
183 if (hist[proto] <= 0)
184 continue;
185 if (first) {
186 printf("\t%s histogram:\n", title);
187 first = 0;
188 }
189 for (p = name; p && p->str; p++) {
190 if (p->val == proto)
191 break;
192 }
193 if (p && p->str) {
194 printf("\t\t%s: " LLU "\n", p->str, (CAST)hist[proto]);
195 } else {
196 printf("\t\t#%ld: " LLU "\n", (long)proto,
197 (CAST)hist[proto]);
198 }
199 }
200}
201
202static void
204print_ipsecstats()
203print_ipsecstats(void)
205{
206#define p(f, m) if (ipsecstat.f || sflag <= 1) \
207 printf(m, (CAST)ipsecstat.f, plural(ipsecstat.f))
208#define hist(f, n, t) \
209 ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), sizeof(n)/sizeof(n[0]), (t));
210
211 p(in_success, "\t" LLU " inbound packet%s processed successfully\n");
212 p(in_polvio, "\t" LLU " inbound packet%s violated process security "
213 "policy\n");
214 p(in_nosa, "\t" LLU " inbound packet%s with no SA available\n");
215 p(in_inval, "\t" LLU " invalid inbound packet%s\n");
216 p(in_nomem, "\t" LLU " inbound packet%s failed due to insufficient memory\n");
217 p(in_badspi, "\t" LLU " inbound packet%s failed getting SPI\n");
218 p(in_ahreplay, "\t" LLU " inbound packet%s failed on AH replay check\n");
219 p(in_espreplay, "\t" LLU " inbound packet%s failed on ESP replay check\n");
220 p(in_ahauthsucc, "\t" LLU " inbound packet%s considered authentic\n");
221 p(in_ahauthfail, "\t" LLU " inbound packet%s failed on authentication\n");
222 hist(ipsecstat.in_ahhist, ipsec_ahnames, "AH input");
223 hist(ipsecstat.in_esphist, ipsec_espnames, "ESP input");
224 hist(ipsecstat.in_comphist, ipsec_compnames, "IPComp input");
225
226 p(out_success, "\t" LLU " outbound packet%s processed successfully\n");
227 p(out_polvio, "\t" LLU " outbound packet%s violated process security "
228 "policy\n");
229 p(out_nosa, "\t" LLU " outbound packet%s with no SA available\n");
230 p(out_inval, "\t" LLU " invalid outbound packet%s\n");
231 p(out_nomem, "\t" LLU " outbound packet%s failed due to insufficient memory\n");
232 p(out_noroute, "\t" LLU " outbound packet%s with no route\n");
233 hist(ipsecstat.out_ahhist, ipsec_ahnames, "AH output");
234 hist(ipsecstat.out_esphist, ipsec_espnames, "ESP output");
235 hist(ipsecstat.out_comphist, ipsec_compnames, "IPComp output");
236#undef p
237#undef hist
238}
239
240void
204{
205#define p(f, m) if (ipsecstat.f || sflag <= 1) \
206 printf(m, (CAST)ipsecstat.f, plural(ipsecstat.f))
207#define hist(f, n, t) \
208 ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), sizeof(n)/sizeof(n[0]), (t));
209
210 p(in_success, "\t" LLU " inbound packet%s processed successfully\n");
211 p(in_polvio, "\t" LLU " inbound packet%s violated process security "
212 "policy\n");
213 p(in_nosa, "\t" LLU " inbound packet%s with no SA available\n");
214 p(in_inval, "\t" LLU " invalid inbound packet%s\n");
215 p(in_nomem, "\t" LLU " inbound packet%s failed due to insufficient memory\n");
216 p(in_badspi, "\t" LLU " inbound packet%s failed getting SPI\n");
217 p(in_ahreplay, "\t" LLU " inbound packet%s failed on AH replay check\n");
218 p(in_espreplay, "\t" LLU " inbound packet%s failed on ESP replay check\n");
219 p(in_ahauthsucc, "\t" LLU " inbound packet%s considered authentic\n");
220 p(in_ahauthfail, "\t" LLU " inbound packet%s failed on authentication\n");
221 hist(ipsecstat.in_ahhist, ipsec_ahnames, "AH input");
222 hist(ipsecstat.in_esphist, ipsec_espnames, "ESP input");
223 hist(ipsecstat.in_comphist, ipsec_compnames, "IPComp input");
224
225 p(out_success, "\t" LLU " outbound packet%s processed successfully\n");
226 p(out_polvio, "\t" LLU " outbound packet%s violated process security "
227 "policy\n");
228 p(out_nosa, "\t" LLU " outbound packet%s with no SA available\n");
229 p(out_inval, "\t" LLU " invalid outbound packet%s\n");
230 p(out_nomem, "\t" LLU " outbound packet%s failed due to insufficient memory\n");
231 p(out_noroute, "\t" LLU " outbound packet%s with no route\n");
232 hist(ipsecstat.out_ahhist, ipsec_ahnames, "AH output");
233 hist(ipsecstat.out_esphist, ipsec_espnames, "ESP output");
234 hist(ipsecstat.out_comphist, ipsec_compnames, "IPComp output");
235#undef p
236#undef hist
237}
238
239void
241ipsec_stats(off, name)
242 u_long off;
243 char *name;
240ipsec_stats(u_long off, char *name)
244{
245 if (off == 0)
246 return;
247 printf ("%s:\n", name);
248 kread(off, (char *)&ipsecstat, sizeof (ipsecstat));
249
250 print_ipsecstats();
251}
252
253static const char *
241{
242 if (off == 0)
243 return;
244 printf ("%s:\n", name);
245 kread(off, (char *)&ipsecstat, sizeof (ipsecstat));
246
247 print_ipsecstats();
248}
249
250static const char *
254pfkey_msgtype_names(x)
255 int x;
251pfkey_msgtype_names(int x)
256{
257 const int max =
258 sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]);
259 static char buf[10];
260
261 if (x < max && pfkey_msgtypenames[x])
262 return pfkey_msgtypenames[x];
263 snprintf(buf, sizeof(buf), "#%d", x);
264 return buf;
265}
266
267void
252{
253 const int max =
254 sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]);
255 static char buf[10];
256
257 if (x < max && pfkey_msgtypenames[x])
258 return pfkey_msgtypenames[x];
259 snprintf(buf, sizeof(buf), "#%d", x);
260 return buf;
261}
262
263void
268pfkey_stats(off, name)
269 u_long off;
270 char *name;
264pfkey_stats(u_long off, char *name)
271{
272 struct pfkeystat pfkeystat;
273 int first, type;
274
275 if (off == 0)
276 return;
277 printf ("%s:\n", name);
278 kread(off, (char *)&pfkeystat, sizeof(pfkeystat));
279
280#define p(f, m) if (pfkeystat.f || sflag <= 1) \
281 printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f))
282
283 /* kernel -> userland */
284 p(out_total, "\t" LLU " request%s sent to userland\n");
285 p(out_bytes, "\t" LLU " byte%s sent to userland\n");
286 for (first = 1, type = 0;
287 type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
288 type++) {
289 if (pfkeystat.out_msgtype[type] <= 0)
290 continue;
291 if (first) {
292 printf("\thistogram by message type:\n");
293 first = 0;
294 }
295 printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
296 (CAST)pfkeystat.out_msgtype[type]);
297 }
298 p(out_invlen, "\t" LLU " message%s with invalid length field\n");
299 p(out_invver, "\t" LLU " message%s with invalid version field\n");
300 p(out_invmsgtype, "\t" LLU " message%s with invalid message type field\n");
301 p(out_tooshort, "\t" LLU " message%s too short\n");
302 p(out_nomem, "\t" LLU " message%s with memory allocation failure\n");
303 p(out_dupext, "\t" LLU " message%s with duplicate extension\n");
304 p(out_invexttype, "\t" LLU " message%s with invalid extension type\n");
305 p(out_invsatype, "\t" LLU " message%s with invalid sa type\n");
306 p(out_invaddr, "\t" LLU " message%s with invalid address extension\n");
307
308 /* userland -> kernel */
309 p(in_total, "\t" LLU " request%s sent from userland\n");
310 p(in_bytes, "\t" LLU " byte%s sent from userland\n");
311 for (first = 1, type = 0;
312 type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
313 type++) {
314 if (pfkeystat.in_msgtype[type] <= 0)
315 continue;
316 if (first) {
317 printf("\thistogram by message type:\n");
318 first = 0;
319 }
320 printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
321 (CAST)pfkeystat.in_msgtype[type]);
322 }
323 p(in_msgtarget[KEY_SENDUP_ONE],
324 "\t" LLU " message%s toward single socket\n");
325 p(in_msgtarget[KEY_SENDUP_ALL],
326 "\t" LLU " message%s toward all sockets\n");
327 p(in_msgtarget[KEY_SENDUP_REGISTERED],
328 "\t" LLU " message%s toward registered sockets\n");
329 p(in_nomem, "\t" LLU " message%s with memory allocation failure\n");
330#undef p
331}
332#endif /*IPSEC*/
265{
266 struct pfkeystat pfkeystat;
267 int first, type;
268
269 if (off == 0)
270 return;
271 printf ("%s:\n", name);
272 kread(off, (char *)&pfkeystat, sizeof(pfkeystat));
273
274#define p(f, m) if (pfkeystat.f || sflag <= 1) \
275 printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f))
276
277 /* kernel -> userland */
278 p(out_total, "\t" LLU " request%s sent to userland\n");
279 p(out_bytes, "\t" LLU " byte%s sent to userland\n");
280 for (first = 1, type = 0;
281 type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
282 type++) {
283 if (pfkeystat.out_msgtype[type] <= 0)
284 continue;
285 if (first) {
286 printf("\thistogram by message type:\n");
287 first = 0;
288 }
289 printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
290 (CAST)pfkeystat.out_msgtype[type]);
291 }
292 p(out_invlen, "\t" LLU " message%s with invalid length field\n");
293 p(out_invver, "\t" LLU " message%s with invalid version field\n");
294 p(out_invmsgtype, "\t" LLU " message%s with invalid message type field\n");
295 p(out_tooshort, "\t" LLU " message%s too short\n");
296 p(out_nomem, "\t" LLU " message%s with memory allocation failure\n");
297 p(out_dupext, "\t" LLU " message%s with duplicate extension\n");
298 p(out_invexttype, "\t" LLU " message%s with invalid extension type\n");
299 p(out_invsatype, "\t" LLU " message%s with invalid sa type\n");
300 p(out_invaddr, "\t" LLU " message%s with invalid address extension\n");
301
302 /* userland -> kernel */
303 p(in_total, "\t" LLU " request%s sent from userland\n");
304 p(in_bytes, "\t" LLU " byte%s sent from userland\n");
305 for (first = 1, type = 0;
306 type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
307 type++) {
308 if (pfkeystat.in_msgtype[type] <= 0)
309 continue;
310 if (first) {
311 printf("\thistogram by message type:\n");
312 first = 0;
313 }
314 printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
315 (CAST)pfkeystat.in_msgtype[type]);
316 }
317 p(in_msgtarget[KEY_SENDUP_ONE],
318 "\t" LLU " message%s toward single socket\n");
319 p(in_msgtarget[KEY_SENDUP_ALL],
320 "\t" LLU " message%s toward all sockets\n");
321 p(in_msgtarget[KEY_SENDUP_REGISTERED],
322 "\t" LLU " message%s toward registered sockets\n");
323 p(in_nomem, "\t" LLU " message%s with memory allocation failure\n");
324#undef p
325}
326#endif /*IPSEC*/