1 /* $NetBSD: ipsec.c,v 1.9 2006/10/22 16:43:24 christos Exp $ */
4 * Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: ipsec.c,v 1.9 2006/10/22 16:43:24 christos Exp $");
35 #include <sys/param.h>
36 #include <sys/sysctl.h>
38 #include <netinet/in.h>
39 #include <netinet6/ipsec.h>
46 #define LHD(row, str) mvwprintw(wnd, row, 10, str)
47 #define RHD(row, str) mvwprintw(wnd, row, 45, str);
48 #define SHOW(stat, row, col) \
49 mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.stat)
52 uint64_t i4
[IPSEC_NSTATS
];
54 uint64_t i6
[IPSEC_NSTATS
];
64 static enum update update
= UPDATE_TIME
;
65 static struct mystat curstat
;
66 static struct mystat newstat
;
67 static struct mystat oldstat
;
69 static struct nlist namelist
[] = {
70 { .n_name
= "_ipsecstat" },
72 { .n_name
= "_ipsec6stat" },
81 return (subwin(stdscr
, -1, 0, 5, 0));
99 wmove(wnd
, 0, 0); wclrtoeol(wnd
);
101 if (namelist
[0].n_type
) {
102 mvwprintw(wnd
, 0, 0, "------ IPv4 IPsec input ------");
103 LHD(1, "processed successfully");
104 LHD(2, "violated process policy");
105 LHD(3, "with no SA available");
106 LHD(4, "failed due to EINVAL");
107 LHD(5, "failed getting SPI");
108 LHD(6, "failed on AH replay check");
109 LHD(7, "failed on ESP replay check");
110 LHD(8, "considered authentic");
111 LHD(9, "failed on authentication");
113 mvwprintw(wnd
, 11, 0, "------ IPv4 IPsec output ------");
114 LHD(12, "processed successfully");
115 LHD(13, "violated process policy");
116 LHD(14, "with no SA available");
117 LHD(15, "failed processing due to EINVAL");
118 LHD(16, "with no route");
122 if (namelist
[1].n_type
) {
123 mvwprintw(wnd
, 0, 35, "------ IPv6 IPsec input ------");
124 RHD(1, "processed successfully");
125 RHD(2, "violated process policy");
126 RHD(3, "with no SA available");
127 RHD(4, "failed due to EINVAL");
128 RHD(5, "failed getting SPI");
129 RHD(6, "failed on AH replay check");
130 RHD(7, "failed on ESP replay check");
131 RHD(8, "considered authentic");
132 RHD(9, "failed on authentication");
134 mvwprintw(wnd
, 11, 35, "------ IPv6 IPsec output ------");
135 RHD(12, "processed successfully");
136 RHD(13, "violated process policy");
137 RHD(14, "with no SA available");
138 RHD(15, "failed due to EINVAL");
139 RHD(16, "with no route");
148 if (namelist
[0].n_type
) {
149 SHOW(i4
[IPSEC_STAT_IN_SUCCESS
], 1, 0);
150 SHOW(i4
[IPSEC_STAT_IN_POLVIO
], 2, 0);
151 SHOW(i4
[IPSEC_STAT_IN_NOSA
], 3, 0);
152 SHOW(i4
[IPSEC_STAT_IN_INVAL
], 4, 0);
153 SHOW(i4
[IPSEC_STAT_IN_BADSPI
], 5, 0);
154 SHOW(i4
[IPSEC_STAT_IN_AHREPLAY
], 6, 0);
155 SHOW(i4
[IPSEC_STAT_IN_ESPREPLAY
], 7, 0);
156 SHOW(i4
[IPSEC_STAT_IN_AHAUTHSUCC
], 8, 0);
157 SHOW(i4
[IPSEC_STAT_IN_AHAUTHFAIL
], 9, 0);
159 SHOW(i4
[IPSEC_STAT_OUT_SUCCESS
], 12, 0);
160 SHOW(i4
[IPSEC_STAT_OUT_POLVIO
], 13, 0);
161 SHOW(i4
[IPSEC_STAT_OUT_NOSA
], 14, 0);
162 SHOW(i4
[IPSEC_STAT_OUT_INVAL
], 15, 0);
163 SHOW(i4
[IPSEC_STAT_OUT_NOROUTE
], 16, 0);
167 if (namelist
[1].n_type
) {
168 SHOW(i6
[IPSEC_STAT_IN_SUCCESS
], 1, 35);
169 SHOW(i6
[IPSEC_STAT_IN_POLVIO
], 2, 35);
170 SHOW(i6
[IPSEC_STAT_IN_NOSA
], 3, 35);
171 SHOW(i6
[IPSEC_STAT_IN_INVAL
], 4, 35);
172 SHOW(i6
[IPSEC_STAT_IN_BADSPI
], 5, 35);
173 SHOW(i6
[IPSEC_STAT_IN_AHREPLAY
], 6, 35);
174 SHOW(i6
[IPSEC_STAT_IN_ESPREPLAY
], 7, 35);
175 SHOW(i6
[IPSEC_STAT_IN_AHAUTHSUCC
], 8, 35);
176 SHOW(i6
[IPSEC_STAT_IN_AHAUTHFAIL
], 9, 35);
178 SHOW(i6
[IPSEC_STAT_OUT_SUCCESS
], 12, 35);
179 SHOW(i6
[IPSEC_STAT_OUT_POLVIO
], 13, 35);
180 SHOW(i6
[IPSEC_STAT_OUT_NOSA
], 14, 35);
181 SHOW(i6
[IPSEC_STAT_OUT_INVAL
], 15, 35);
182 SHOW(i6
[IPSEC_STAT_OUT_NOROUTE
], 16, 35);
194 if (namelist
[0].n_type
== 0) {
195 n
= kvm_nlist(kd
, namelist
);
199 } else if (n
== sizeof(namelist
) /
200 sizeof(namelist
[0]) - 1) {
201 error("No namelist");
212 bool do_ipsec4
= false;
214 bool do_ipsec6
= false;
219 size_t size
= sizeof(newstat
.i4
);
221 if (sysctlbyname("net.inet.ipsec.stats", newstat
.i4
, &size
,
226 if (namelist
[0].n_type
) {
227 KREAD((void *)namelist
[0].n_value
, &newstat
.i4
,
234 for (i
= 0; i
< IPSEC_NSTATS
; i
++) {
235 ADJINETCTR(curstat
, oldstat
, newstat
, i4
[i
]);
241 size_t size
= sizeof(newstat
.i6
);
243 if (sysctlbyname("net.inet6.ipsec6.stats", newstat
.i6
, &size
,
248 if (namelist
[1].n_type
) {
249 KREAD((void *)namelist
[1].n_value
, &newstat
.i6
,
256 for (i
= 0; i
< IPSEC_NSTATS
; i
++) {
257 ADJINETCTR(curstat
, oldstat
, newstat
, i6
[i
]);
262 if (update
== UPDATE_TIME
)
263 memcpy(&oldstat
, &newstat
, sizeof(oldstat
));
267 ipsec_boot(char *args
)
270 memset(&oldstat
, 0, sizeof(oldstat
));
271 update
= UPDATE_BOOT
;
275 ipsec_run(char *args
)
278 if (update
!= UPDATE_RUN
) {
279 memcpy(&oldstat
, &newstat
, sizeof(oldstat
));
285 ipsec_time(char *args
)
288 if (update
!= UPDATE_TIME
) {
289 memcpy(&oldstat
, &newstat
, sizeof(oldstat
));
290 update
= UPDATE_TIME
;
295 ipsec_zero(char *args
)
298 if (update
== UPDATE_RUN
)
299 memcpy(&oldstat
, &newstat
, sizeof(oldstat
));