ipsec_netbsd.c revision 1.48 1 /* $NetBSD: ipsec_netbsd.c,v 1.48 2018/04/18 06:03:36 maxv Exp $ */
2 /* $KAME: esp_input.c,v 1.60 2001/09/04 08:43:19 itojun Exp $ */
3 /* $KAME: ah_input.c,v 1.64 2001/09/04 08:43:19 itojun Exp $ */
4
5 /*
6 * Copyright (C) 1995, 1996, 1997, and 1998 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 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: ipsec_netbsd.c,v 1.48 2018/04/18 06:03:36 maxv Exp $");
36
37 #if defined(_KERNEL_OPT)
38 #include "opt_inet.h"
39 #include "opt_ipsec.h"
40 #endif
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <sys/mbuf.h>
46 #include <sys/domain.h>
47 #include <sys/protosw.h>
48 #include <sys/socket.h>
49 #include <sys/errno.h>
50 #include <sys/time.h>
51 #include <sys/kernel.h>
52 #include <sys/sysctl.h>
53
54 #include <net/if.h>
55 #include <net/route.h>
56 #include <net/netisr.h>
57 #include <sys/cpu.h>
58
59 #include <netinet/in.h>
60 #include <netinet/in_systm.h>
61 #include <netinet/in_var.h>
62 #include <netinet/ip.h>
63 #include <netinet/ip_var.h>
64 #include <netinet/ip_ecn.h>
65 #include <netinet/ip_icmp.h>
66
67 #include <netipsec/ipsec.h>
68 #include <netipsec/ipsec_var.h>
69 #include <netipsec/ipsec_private.h>
70 #include <netipsec/key.h>
71 #include <netipsec/keydb.h>
72 #include <netipsec/key_debug.h>
73 #include <netipsec/ah.h>
74 #include <netipsec/ah_var.h>
75 #include <netipsec/esp.h>
76 #include <netipsec/esp_var.h>
77 #include <netipsec/ipip_var.h>
78 #include <netipsec/ipcomp_var.h>
79
80 #ifdef INET6
81 #include <netipsec/ipsec6.h>
82 #include <netinet6/ip6protosw.h>
83 #include <netinet/icmp6.h>
84 #endif
85
86 #include <netipsec/key.h>
87
88 /* assumes that ip header and ah header are contiguous on mbuf */
89 void *
90 ah4_ctlinput(int cmd, const struct sockaddr *sa, void *v)
91 {
92 struct ip *ip = v;
93 struct ah *ah;
94 struct icmp *icp;
95 struct secasvar *sav;
96
97 if (sa->sa_family != AF_INET ||
98 sa->sa_len != sizeof(struct sockaddr_in))
99 return NULL;
100 if ((unsigned)cmd >= PRC_NCMDS)
101 return NULL;
102
103 if (cmd == PRC_MSGSIZE && ip_mtudisc && ip && ip->ip_v == 4) {
104 /*
105 * Check to see if we have a valid SA corresponding to
106 * the address in the ICMP message payload.
107 */
108 ah = (struct ah *)((char *)ip + (ip->ip_hl << 2));
109 sav = KEY_LOOKUP_SA((const union sockaddr_union *)sa,
110 IPPROTO_AH, ah->ah_spi, 0, 0);
111
112 if (sav) {
113 if (SADB_SASTATE_USABLE_P(sav)) {
114 /*
115 * Now that we've validated that we are actually
116 * communicating with the host indicated in the
117 * ICMP message, locate the ICMP header,
118 * recalculate the new MTU, and create the
119 * corresponding routing entry.
120 */
121 icp = (struct icmp *)((char *)ip -
122 offsetof(struct icmp, icmp_ip));
123 icmp_mtudisc(icp, ip->ip_dst);
124 }
125 KEY_SA_UNREF(&sav);
126 }
127 }
128 return NULL;
129 }
130
131 /* assumes that ip header and esp header are contiguous on mbuf */
132 void *
133 esp4_ctlinput(int cmd, const struct sockaddr *sa, void *v)
134 {
135 struct ip *ip = v;
136 struct esp *esp;
137 struct icmp *icp;
138 struct secasvar *sav;
139
140 if (sa->sa_family != AF_INET ||
141 sa->sa_len != sizeof(struct sockaddr_in))
142 return NULL;
143 if ((unsigned)cmd >= PRC_NCMDS)
144 return NULL;
145
146 if (cmd == PRC_MSGSIZE && ip_mtudisc && ip && ip->ip_v == 4) {
147 /*
148 * Check to see if we have a valid SA corresponding to
149 * the address in the ICMP message payload.
150 */
151 esp = (struct esp *)((char *)ip + (ip->ip_hl << 2));
152 sav = KEY_LOOKUP_SA((const union sockaddr_union *)sa,
153 IPPROTO_ESP, esp->esp_spi, 0, 0);
154
155 if (sav) {
156 if (SADB_SASTATE_USABLE_P(sav)) {
157 /*
158 * Now that we've validated that we are actually
159 * communicating with the host indicated in the
160 * ICMP message, locate the ICMP header,
161 * recalculate the new MTU, and create the
162 * corresponding routing entry.
163 */
164 icp = (struct icmp *)((char *)ip -
165 offsetof(struct icmp, icmp_ip));
166 icmp_mtudisc(icp, ip->ip_dst);
167 }
168 KEY_SA_UNREF(&sav);
169 }
170 }
171 return NULL;
172 }
173
174 #ifdef INET6
175 void *
176 ah6_ctlinput(int cmd, const struct sockaddr *sa, void *d)
177 {
178 const struct newah *ahp;
179 struct newah ah;
180 struct secasvar *sav;
181 struct ip6_hdr *ip6;
182 struct mbuf *m;
183 struct ip6ctlparam *ip6cp = NULL;
184 int off;
185
186 if (sa->sa_family != AF_INET6 ||
187 sa->sa_len != sizeof(struct sockaddr_in6))
188 return NULL;
189 if ((unsigned)cmd >= PRC_NCMDS)
190 return NULL;
191
192 /* if the parameter is from icmp6, decode it. */
193 if (d != NULL) {
194 ip6cp = (struct ip6ctlparam *)d;
195 m = ip6cp->ip6c_m;
196 ip6 = ip6cp->ip6c_ip6;
197 off = ip6cp->ip6c_off;
198 } else {
199 m = NULL;
200 ip6 = NULL;
201 off = 0;
202 }
203
204 if (ip6) {
205 /*
206 * XXX: We assume that when ip6 is non NULL,
207 * M and OFF are valid.
208 */
209
210 /* check if we can safely examine src and dst ports */
211 if (m->m_pkthdr.len < off + sizeof(ah))
212 return NULL;
213
214 if (m->m_len < off + sizeof(ah)) {
215 /*
216 * this should be rare case,
217 * so we compromise on this copy...
218 */
219 m_copydata(m, off, sizeof(ah), &ah);
220 ahp = &ah;
221 } else
222 ahp = (struct newah *)(mtod(m, char *) + off);
223
224 if (cmd == PRC_MSGSIZE) {
225 int valid = 0;
226
227 /*
228 * Check to see if we have a valid SA corresponding
229 * to the address in the ICMP message payload.
230 */
231 sav = KEY_LOOKUP_SA((const union sockaddr_union*)sa,
232 IPPROTO_AH, ahp->ah_spi, 0, 0);
233
234 if (sav) {
235 if (SADB_SASTATE_USABLE_P(sav))
236 valid++;
237 KEY_SA_UNREF(&sav);
238 }
239
240 /* XXX Further validation? */
241
242 /*
243 * Depending on the value of "valid" and routing
244 * table size (mtudisc_{hi,lo}wat), we will:
245 * - recalculate the new MTU and create the
246 * corresponding routing entry, or
247 * - ignore the MTU change notification.
248 */
249 icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
250 }
251
252 /* we normally notify single pcb here */
253 } else {
254 /* we normally notify any pcb here */
255 }
256 return NULL;
257 }
258
259 void *
260 esp6_ctlinput(int cmd, const struct sockaddr *sa, void *d)
261 {
262 const struct newesp *espp;
263 struct newesp esp;
264 struct ip6ctlparam *ip6cp = NULL, ip6cp1;
265 struct secasvar *sav;
266 struct ip6_hdr *ip6;
267 struct mbuf *m;
268 int off;
269
270 if (sa->sa_family != AF_INET6 ||
271 sa->sa_len != sizeof(struct sockaddr_in6))
272 return NULL;
273 if ((unsigned)cmd >= PRC_NCMDS)
274 return NULL;
275
276 /* if the parameter is from icmp6, decode it. */
277 if (d != NULL) {
278 ip6cp = (struct ip6ctlparam *)d;
279 m = ip6cp->ip6c_m;
280 ip6 = ip6cp->ip6c_ip6;
281 off = ip6cp->ip6c_off;
282 } else {
283 m = NULL;
284 ip6 = NULL;
285 off = 0;
286 }
287
288 if (ip6) {
289 /*
290 * Notify the error to all possible sockets via pfctlinput2.
291 * Since the upper layer information (such as protocol type,
292 * source and destination ports) is embedded in the encrypted
293 * data and might have been cut, we can't directly call
294 * an upper layer ctlinput function. However, the pcbnotify
295 * function will consider source and destination addresses
296 * as well as the flow info value, and may be able to find
297 * some PCB that should be notified.
298 * Although pfctlinput2 will call esp6_ctlinput(), there is
299 * no possibility of an infinite loop of function calls,
300 * because we don't pass the inner IPv6 header.
301 */
302 memset(&ip6cp1, 0, sizeof(ip6cp1));
303 ip6cp1.ip6c_src = ip6cp->ip6c_src;
304 pfctlinput2(cmd, sa, &ip6cp1);
305
306 /*
307 * Then go to special cases that need ESP header information.
308 * XXX: We assume that when ip6 is non NULL,
309 * M and OFF are valid.
310 */
311
312 /* check if we can safely examine src and dst ports */
313 if (m->m_pkthdr.len < off + sizeof(esp))
314 return NULL;
315
316 if (m->m_len < off + sizeof(esp)) {
317 /*
318 * this should be rare case,
319 * so we compromise on this copy...
320 */
321 m_copydata(m, off, sizeof(esp), &esp);
322 espp = &esp;
323 } else
324 espp = (struct newesp*)(mtod(m, char *) + off);
325
326 if (cmd == PRC_MSGSIZE) {
327 int valid = 0;
328
329 /*
330 * Check to see if we have a valid SA corresponding to
331 * the address in the ICMP message payload.
332 */
333
334 sav = KEY_LOOKUP_SA((const union sockaddr_union*)sa,
335 IPPROTO_ESP, espp->esp_spi, 0, 0);
336
337 if (sav) {
338 if (SADB_SASTATE_USABLE_P(sav))
339 valid++;
340 KEY_SA_UNREF(&sav);
341 }
342
343 /* XXX Further validation? */
344
345 /*
346 * Depending on the value of "valid" and routing table
347 * size (mtudisc_{hi,lo}wat), we will:
348 * - recalcurate the new MTU and create the
349 * corresponding routing entry, or
350 * - ignore the MTU change notification.
351 */
352 icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
353 }
354 } else {
355 /* we normally notify any pcb here */
356 }
357 return NULL;
358 }
359 #endif /* INET6 */
360
361 static int
362 sysctl_ipsec(SYSCTLFN_ARGS)
363 {
364 int error, t;
365 struct sysctlnode node;
366
367 node = *rnode;
368 t = *(int*)rnode->sysctl_data;
369 node.sysctl_data = &t;
370 error = sysctl_lookup(SYSCTLFN_CALL(&node));
371 if (error || newp == NULL)
372 return (error);
373
374 switch (rnode->sysctl_num) {
375 case IPSECCTL_DEF_ESP_TRANSLEV:
376 case IPSECCTL_DEF_ESP_NETLEV:
377 case IPSECCTL_DEF_AH_TRANSLEV:
378 case IPSECCTL_DEF_AH_NETLEV:
379 if (t != IPSEC_LEVEL_USE &&
380 t != IPSEC_LEVEL_REQUIRE)
381 return (EINVAL);
382 ipsec_invalpcbcacheall();
383 break;
384 case IPSECCTL_DEF_POLICY:
385 if (t != IPSEC_POLICY_DISCARD &&
386 t != IPSEC_POLICY_NONE)
387 return (EINVAL);
388 ipsec_invalpcbcacheall();
389 break;
390 default:
391 return (EINVAL);
392 }
393
394 *(int*)rnode->sysctl_data = t;
395
396 return (0);
397 }
398
399 #ifdef IPSEC_DEBUG
400 static int
401 sysctl_ipsec_test(SYSCTLFN_ARGS)
402 {
403 int t, error;
404 struct sysctlnode node;
405
406 node = *rnode;
407 t = *(int*)rnode->sysctl_data;
408 node.sysctl_data = &t;
409 error = sysctl_lookup(SYSCTLFN_CALL(&node));
410 if (error || newp == NULL)
411 return (error);
412
413 if (t < 0 || t > 1)
414 return EINVAL;
415
416 if (rnode->sysctl_data == &ipsec_replay)
417 printf("ipsec: Anti-Replay service %s\n",
418 (t == 1) ? "deactivated" : "activated");
419 else if (rnode->sysctl_data == &ipsec_integrity)
420 printf("ipsec: HMAC corruption %s\n",
421 (t == 0) ? "deactivated" : "activated");
422
423 *(int*)rnode->sysctl_data = t;
424
425 return 0;
426 }
427 #endif
428
429 static int
430 sysctl_net_inet_ipsec_stats(SYSCTLFN_ARGS)
431 {
432
433 return (NETSTAT_SYSCTL(ipsecstat_percpu, IPSEC_NSTATS));
434 }
435
436 static int
437 sysctl_net_inet_ah_stats(SYSCTLFN_ARGS)
438 {
439
440 return (NETSTAT_SYSCTL(ahstat_percpu, AH_NSTATS));
441 }
442
443 static int
444 sysctl_net_inet_esp_stats(SYSCTLFN_ARGS)
445 {
446
447 return (NETSTAT_SYSCTL(espstat_percpu, ESP_NSTATS));
448 }
449
450 static int
451 sysctl_net_inet_ipcomp_stats(SYSCTLFN_ARGS)
452 {
453
454 return (NETSTAT_SYSCTL(ipcompstat_percpu, IPCOMP_NSTATS));
455 }
456
457 static int
458 sysctl_net_inet_ipip_stats(SYSCTLFN_ARGS)
459 {
460
461 return (NETSTAT_SYSCTL(ipipstat_percpu, IPIP_NSTATS));
462 }
463
464 static int
465 sysctl_net_ipsec_enabled(SYSCTLFN_ARGS)
466 {
467 int newenabled, error;
468 struct sysctlnode node;
469 node = *rnode;
470 node.sysctl_data = &newenabled;
471
472 newenabled = ipsec_enabled;
473 error = sysctl_lookup(SYSCTLFN_CALL(&node));
474 if (error || newp == NULL)
475 return error;
476
477 switch (newenabled) {
478 case 0:
479 if (key_get_used())
480 return EBUSY;
481 /*FALLTHROUGH*/
482 case 1:
483 case 2:
484 ipsec_enabled = newenabled;
485 key_update_used();
486 return 0;
487 default:
488 return EINVAL;
489 }
490 }
491
492 /* XXX will need a different oid at parent */
493 void
494 sysctl_net_inet_ipsec_setup(struct sysctllog **clog)
495 {
496 const struct sysctlnode *_ipsec;
497 int ipproto_ipsec;
498
499 sysctl_createv(clog, 0, NULL, NULL,
500 CTLFLAG_PERMANENT,
501 CTLTYPE_NODE, "inet", NULL,
502 NULL, 0, NULL, 0,
503 CTL_NET, PF_INET, CTL_EOL);
504
505 /*
506 * in numerical order:
507 *
508 * net.inet.ipip: CTL_NET.PF_INET.IPPROTO_IPIP
509 * net.inet.esp: CTL_NET.PF_INET.IPPROTO_ESP
510 * net.inet.ah: CTL_NET.PF_INET.IPPROTO_AH
511 * net.inet.ipcomp: CTL_NET.PF_INET.IPPROTO_IPCOMP
512 * net.inet.ipsec: CTL_NET.PF_INET.CTL_CREATE
513 *
514 * this creates separate trees by name, but maintains that the
515 * ipsec name leads to all the old leaves.
516 */
517
518 /* create net.inet.ipip */
519 sysctl_createv(clog, 0, NULL, NULL,
520 CTLFLAG_PERMANENT,
521 CTLTYPE_NODE, "ipip", NULL,
522 NULL, 0, NULL, 0,
523 CTL_NET, PF_INET, IPPROTO_IPIP, CTL_EOL);
524 sysctl_createv(clog, 0, NULL, NULL,
525 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
526 CTLTYPE_STRUCT, "ipip_stats", NULL,
527 sysctl_net_inet_ipip_stats, 0, NULL, 0,
528 CTL_NET, PF_INET, IPPROTO_IPIP,
529 CTL_CREATE, CTL_EOL);
530
531 /* create net.inet.esp subtree under IPPROTO_ESP */
532 sysctl_createv(clog, 0, NULL, NULL,
533 CTLFLAG_PERMANENT,
534 CTLTYPE_NODE, "esp", NULL,
535 NULL, 0, NULL, 0,
536 CTL_NET, PF_INET, IPPROTO_ESP, CTL_EOL);
537 sysctl_createv(clog, 0, NULL, NULL,
538 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
539 CTLTYPE_STRUCT, "esp_stats", NULL,
540 sysctl_net_inet_esp_stats, 0, NULL, 0,
541 CTL_NET, PF_INET, IPPROTO_ESP,
542 CTL_CREATE, CTL_EOL);
543
544 /* create net.inet.ah subtree under IPPROTO_AH */
545 sysctl_createv(clog, 0, NULL, NULL,
546 CTLFLAG_PERMANENT,
547 CTLTYPE_NODE, "ah", NULL,
548 NULL, 0, NULL, 0,
549 CTL_NET, PF_INET, IPPROTO_AH, CTL_EOL);
550 sysctl_createv(clog, 0, NULL, NULL,
551 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
552 CTLTYPE_STRUCT, "ah_stats", NULL,
553 sysctl_net_inet_ah_stats, 0, NULL, 0,
554 CTL_NET, PF_INET, IPPROTO_AH,
555 CTL_CREATE, CTL_EOL);
556
557 /* create net.inet.ipcomp */
558 sysctl_createv(clog, 0, NULL, NULL,
559 CTLFLAG_PERMANENT,
560 CTLTYPE_NODE, "ipcomp", NULL,
561 NULL, 0, NULL, 0,
562 CTL_NET, PF_INET, IPPROTO_IPCOMP, CTL_EOL);
563 sysctl_createv(clog, 0, NULL, NULL,
564 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
565 CTLTYPE_STRUCT, "ipcomp_stats", NULL,
566 sysctl_net_inet_ipcomp_stats, 0, NULL, 0,
567 CTL_NET, PF_INET, IPPROTO_IPCOMP,
568 CTL_CREATE, CTL_EOL);
569
570 /* create net.inet.ipsec subtree under dynamic oid */
571 sysctl_createv(clog, 0, NULL, &_ipsec,
572 CTLFLAG_PERMANENT,
573 CTLTYPE_NODE, "ipsec", NULL,
574 NULL, 0, NULL, 0,
575 CTL_NET, PF_INET, CTL_CREATE, CTL_EOL);
576 ipproto_ipsec = (_ipsec != NULL) ? _ipsec->sysctl_num : 0;
577
578 sysctl_createv(clog, 0, NULL, NULL,
579 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
580 CTLTYPE_INT, "def_policy", NULL,
581 sysctl_ipsec, 0, &ip4_def_policy.policy, 0,
582 CTL_NET, PF_INET, ipproto_ipsec,
583 IPSECCTL_DEF_POLICY, CTL_EOL);
584 sysctl_createv(clog, 0, NULL, NULL,
585 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
586 CTLTYPE_INT, "esp_trans_deflev", NULL,
587 sysctl_ipsec, 0, &ip4_esp_trans_deflev, 0,
588 CTL_NET, PF_INET, ipproto_ipsec,
589 IPSECCTL_DEF_ESP_TRANSLEV, CTL_EOL);
590 sysctl_createv(clog, 0, NULL, NULL,
591 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
592 CTLTYPE_INT, "esp_net_deflev", NULL,
593 sysctl_ipsec, 0, &ip4_esp_net_deflev, 0,
594 CTL_NET, PF_INET, ipproto_ipsec,
595 IPSECCTL_DEF_ESP_NETLEV, CTL_EOL);
596 sysctl_createv(clog, 0, NULL, NULL,
597 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
598 CTLTYPE_INT, "ah_trans_deflev", NULL,
599 sysctl_ipsec, 0, &ip4_ah_trans_deflev, 0,
600 CTL_NET, PF_INET, ipproto_ipsec,
601 IPSECCTL_DEF_AH_TRANSLEV, CTL_EOL);
602 sysctl_createv(clog, 0, NULL, NULL,
603 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
604 CTLTYPE_INT, "ah_net_deflev", NULL,
605 sysctl_ipsec, 0, &ip4_ah_net_deflev, 0,
606 CTL_NET, PF_INET, ipproto_ipsec,
607 IPSECCTL_DEF_AH_NETLEV, CTL_EOL);
608 sysctl_createv(clog, 0, NULL, NULL,
609 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
610 CTLTYPE_INT, "ah_cleartos", NULL,
611 NULL, 0, &ip4_ah_cleartos, 0,
612 CTL_NET, PF_INET, ipproto_ipsec,
613 IPSECCTL_AH_CLEARTOS, CTL_EOL);
614 sysctl_createv(clog, 0, NULL, NULL,
615 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
616 CTLTYPE_INT, "ah_offsetmask", NULL,
617 NULL, 0, &ip4_ah_offsetmask, 0,
618 CTL_NET, PF_INET, ipproto_ipsec,
619 IPSECCTL_AH_OFFSETMASK, CTL_EOL);
620 sysctl_createv(clog, 0, NULL, NULL,
621 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
622 CTLTYPE_INT, "dfbit", NULL,
623 NULL, 0, &ip4_ipsec_dfbit, 0,
624 CTL_NET, PF_INET, ipproto_ipsec,
625 IPSECCTL_DFBIT, CTL_EOL);
626 sysctl_createv(clog, 0, NULL, NULL,
627 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
628 CTLTYPE_INT, "ecn", NULL,
629 NULL, 0, &ip4_ipsec_ecn, 0,
630 CTL_NET, PF_INET, ipproto_ipsec,
631 IPSECCTL_ECN, CTL_EOL);
632 sysctl_createv(clog, 0, NULL, NULL,
633 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
634 CTLTYPE_INT, "debug", NULL,
635 NULL, 0, &ipsec_debug, 0,
636 CTL_NET, PF_INET, ipproto_ipsec,
637 IPSECCTL_DEBUG, CTL_EOL);
638 sysctl_createv(clog, 0, NULL, NULL,
639 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
640 CTLTYPE_STRUCT, "ipsecstats", NULL,
641 sysctl_net_inet_ipsec_stats, 0, NULL, 0,
642 CTL_NET, PF_INET, ipproto_ipsec,
643 CTL_CREATE, CTL_EOL);
644 sysctl_createv(clog, 0, NULL, NULL,
645 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
646 CTLTYPE_INT, "enabled",
647 SYSCTL_DESCR("Enable IPSec processing"),
648 sysctl_net_ipsec_enabled, 0, NULL, 0,
649 CTL_NET, PF_INET, ipproto_ipsec,
650 CTL_CREATE, CTL_EOL);
651 sysctl_createv(clog, 0, NULL, NULL,
652 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
653 CTLTYPE_INT, "used",
654 SYSCTL_DESCR("Is IPSec active?"),
655 NULL, 0, &ipsec_used, 0,
656 CTL_NET, PF_INET, ipproto_ipsec,
657 CTL_CREATE, CTL_EOL);
658 sysctl_createv(clog, 0, NULL, NULL,
659 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
660 CTLTYPE_INT, "ah_enable", NULL,
661 NULL, 0, &ah_enable, 0,
662 CTL_NET, PF_INET, ipproto_ipsec,
663 CTL_CREATE, CTL_EOL);
664 sysctl_createv(clog, 0, NULL, NULL,
665 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
666 CTLTYPE_INT, "esp_enable", NULL,
667 NULL, 0, &esp_enable, 0,
668 CTL_NET, PF_INET, ipproto_ipsec,
669 CTL_CREATE, CTL_EOL);
670 sysctl_createv(clog, 0, NULL, NULL,
671 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
672 CTLTYPE_INT, "ipcomp_enable", NULL,
673 NULL, 0, &ipcomp_enable, 0,
674 CTL_NET, PF_INET, ipproto_ipsec,
675 CTL_CREATE, CTL_EOL);
676 sysctl_createv(clog, 0, NULL, NULL,
677 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
678 CTLTYPE_INT, "crypto_support", NULL,
679 NULL, 0, &crypto_support, 0,
680 CTL_NET, PF_INET, ipproto_ipsec,
681 CTL_CREATE, CTL_EOL);
682
683 #ifdef IPSEC_DEBUG
684 sysctl_createv(clog, 0, NULL, NULL,
685 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
686 CTLTYPE_INT, "test_replay",
687 SYSCTL_DESCR("Emulate replay attack"),
688 sysctl_ipsec_test, 0, &ipsec_replay, 0,
689 CTL_NET, PF_INET, ipproto_ipsec,
690 CTL_CREATE, CTL_EOL);
691 sysctl_createv(clog, 0, NULL, NULL,
692 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
693 CTLTYPE_INT, "test_integrity",
694 SYSCTL_DESCR("Emulate man-in-the-middle attack"),
695 sysctl_ipsec_test, 0, &ipsec_integrity, 0,
696 CTL_NET, PF_INET, ipproto_ipsec,
697 CTL_CREATE, CTL_EOL);
698 #endif
699 }
700
701 #ifdef INET6
702 void
703 sysctl_net_inet6_ipsec6_setup(struct sysctllog **clog)
704 {
705
706 sysctl_createv(clog, 0, NULL, NULL,
707 CTLFLAG_PERMANENT,
708 CTLTYPE_NODE, "inet6", NULL,
709 NULL, 0, NULL, 0,
710 CTL_NET, PF_INET6, CTL_EOL);
711 sysctl_createv(clog, 0, NULL, NULL,
712 CTLFLAG_PERMANENT,
713 CTLTYPE_NODE, "ipsec6",
714 SYSCTL_DESCR("IPv6 related IPSec settings"),
715 NULL, 0, NULL, 0,
716 CTL_NET, PF_INET6, IPPROTO_AH, CTL_EOL);
717
718 sysctl_createv(clog, 0, NULL, NULL,
719 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
720 CTLTYPE_STRUCT, "stats",
721 SYSCTL_DESCR("IPSec statistics and counters"),
722 sysctl_net_inet_ipsec_stats, 0, NULL, 0,
723 CTL_NET, PF_INET6, IPPROTO_AH,
724 IPSECCTL_STATS, CTL_EOL);
725 sysctl_createv(clog, 0, NULL, NULL,
726 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
727 CTLTYPE_INT, "def_policy",
728 SYSCTL_DESCR("Default action for non-IPSec packets"),
729 sysctl_ipsec, 0, (void *)&ip6_def_policy, 0,
730 CTL_NET, PF_INET6, IPPROTO_AH,
731 IPSECCTL_DEF_POLICY, CTL_EOL);
732 sysctl_createv(clog, 0, NULL, NULL,
733 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
734 CTLTYPE_INT, "esp_trans_deflev",
735 SYSCTL_DESCR("Default required security level for "
736 "transport mode traffic"),
737 sysctl_ipsec, 0, &ip6_esp_trans_deflev, 0,
738 CTL_NET, PF_INET6, IPPROTO_AH,
739 IPSECCTL_DEF_ESP_TRANSLEV, CTL_EOL);
740 sysctl_createv(clog, 0, NULL, NULL,
741 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
742 CTLTYPE_INT, "esp_net_deflev",
743 SYSCTL_DESCR("Default required security level for "
744 "tunneled traffic"),
745 sysctl_ipsec, 0, &ip6_esp_net_deflev, 0,
746 CTL_NET, PF_INET6, IPPROTO_AH,
747 IPSECCTL_DEF_ESP_NETLEV, CTL_EOL);
748 sysctl_createv(clog, 0, NULL, NULL,
749 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
750 CTLTYPE_INT, "ah_trans_deflev",
751 SYSCTL_DESCR("Default required security level for "
752 "transport mode headers"),
753 sysctl_ipsec, 0, &ip6_ah_trans_deflev, 0,
754 CTL_NET, PF_INET6, IPPROTO_AH,
755 IPSECCTL_DEF_AH_TRANSLEV, CTL_EOL);
756 sysctl_createv(clog, 0, NULL, NULL,
757 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
758 CTLTYPE_INT, "ah_net_deflev",
759 SYSCTL_DESCR("Default required security level for "
760 "tunneled headers"),
761 sysctl_ipsec, 0, &ip6_ah_net_deflev, 0,
762 CTL_NET, PF_INET6, IPPROTO_AH,
763 IPSECCTL_DEF_AH_NETLEV, CTL_EOL);
764 sysctl_createv(clog, 0, NULL, NULL,
765 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
766 CTLTYPE_INT, "ecn",
767 SYSCTL_DESCR("Behavior of ECN for tunneled traffic"),
768 NULL, 0, &ip6_ipsec_ecn, 0,
769 CTL_NET, PF_INET6, IPPROTO_AH,
770 IPSECCTL_ECN, CTL_EOL);
771 sysctl_createv(clog, 0, NULL, NULL,
772 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
773 CTLTYPE_INT, "debug",
774 SYSCTL_DESCR("Enable IPSec debugging output"),
775 NULL, 0, &ipsec_debug, 0,
776 CTL_NET, PF_INET6, IPPROTO_AH,
777 IPSECCTL_DEBUG, CTL_EOL);
778 sysctl_createv(clog, 0, NULL, NULL,
779 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
780 CTLTYPE_INT, "enabled",
781 SYSCTL_DESCR("Enable IPSec processing"),
782 sysctl_net_ipsec_enabled, 0, NULL, 0,
783 CTL_NET, PF_INET6, IPPROTO_AH,
784 CTL_CREATE, CTL_EOL);
785 sysctl_createv(clog, 0, NULL, NULL,
786 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
787 CTLTYPE_INT, "used",
788 SYSCTL_DESCR("Is IPSec active?"),
789 NULL, 0, &ipsec_used, 0,
790 CTL_NET, PF_INET6, IPPROTO_AH,
791 CTL_CREATE, CTL_EOL);
792 /*
793 * "aliases" for the ipsec6 subtree
794 */
795 sysctl_createv(clog, 0, NULL, NULL,
796 CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
797 CTLTYPE_NODE, "esp6", NULL,
798 NULL, IPPROTO_AH, NULL, 0,
799 CTL_NET, PF_INET6, IPPROTO_ESP, CTL_EOL);
800 sysctl_createv(clog, 0, NULL, NULL,
801 CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
802 CTLTYPE_NODE, "ipcomp6", NULL,
803 NULL, IPPROTO_AH, NULL, 0,
804 CTL_NET, PF_INET6, IPPROTO_IPCOMP, CTL_EOL);
805 sysctl_createv(clog, 0, NULL, NULL,
806 CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
807 CTLTYPE_NODE, "ah6", NULL,
808 NULL, IPPROTO_AH, NULL, 0,
809 CTL_NET, PF_INET6, CTL_CREATE, CTL_EOL);
810 }
811 #endif /* INET6 */
812