2 /* $KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the project nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * IPsec controller part.
40 #include "opt_inet6.h"
41 #include "opt_ipsec.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
47 #include <sys/domain.h>
49 #include <sys/protosw.h>
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
52 #include <sys/errno.h>
53 #include <sys/hhook.h>
55 #include <sys/kernel.h>
56 #include <sys/syslog.h>
57 #include <sys/sysctl.h>
61 #include <net/if_enc.h>
62 #include <net/if_var.h>
65 #include <netinet/in.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/ip.h>
68 #include <netinet/ip_var.h>
69 #include <netinet/in_var.h>
70 #include <netinet/udp.h>
71 #include <netinet/udp_var.h>
72 #include <netinet/tcp.h>
73 #include <netinet/udp.h>
75 #include <netinet/ip6.h>
77 #include <netinet6/ip6_var.h>
79 #include <netinet/in_pcb.h>
81 #include <netinet/icmp6.h>
84 #include <sys/types.h>
85 #include <netipsec/ipsec.h>
87 #include <netipsec/ipsec6.h>
89 #include <netipsec/ah_var.h>
90 #include <netipsec/esp_var.h>
91 #include <netipsec/ipcomp.h> /*XXX*/
92 #include <netipsec/ipcomp_var.h>
93 #include <netipsec/ipsec_support.h>
95 #include <netipsec/key.h>
96 #include <netipsec/keydb.h>
97 #include <netipsec/key_debug.h>
99 #include <netipsec/xform.h>
101 #include <machine/in_cksum.h>
103 #include <opencrypto/cryptodev.h>
105 /* NB: name changed so netstat doesn't use it. */
106 VNET_PCPUSTAT_DEFINE(struct ipsecstat, ipsec4stat);
107 VNET_PCPUSTAT_SYSINIT(ipsec4stat);
110 VNET_PCPUSTAT_SYSUNINIT(ipsec4stat);
113 /* DF bit on encap. 0: clear 1: set 2: copy */
114 VNET_DEFINE(int, ip4_ipsec_dfbit) = 0;
115 VNET_DEFINE(int, ip4_esp_trans_deflev) = IPSEC_LEVEL_USE;
116 VNET_DEFINE(int, ip4_esp_net_deflev) = IPSEC_LEVEL_USE;
117 VNET_DEFINE(int, ip4_ah_trans_deflev) = IPSEC_LEVEL_USE;
118 VNET_DEFINE(int, ip4_ah_net_deflev) = IPSEC_LEVEL_USE;
119 /* ECN ignore(-1)/forbidden(0)/allowed(1) */
120 VNET_DEFINE(int, ip4_ipsec_ecn) = 0;
122 VNET_DEFINE_STATIC(int, ip4_filtertunnel) = 0;
123 #define V_ip4_filtertunnel VNET(ip4_filtertunnel)
124 VNET_DEFINE_STATIC(int, check_policy_history) = 0;
125 #define V_check_policy_history VNET(check_policy_history)
126 VNET_DEFINE_STATIC(struct secpolicy *, def_policy) = NULL;
127 #define V_def_policy VNET(def_policy)
129 sysctl_def_policy(SYSCTL_HANDLER_ARGS)
133 value = V_def_policy->policy;
134 error = sysctl_handle_int(oidp, &value, 0, req);
136 if (value != IPSEC_POLICY_DISCARD &&
137 value != IPSEC_POLICY_NONE)
139 V_def_policy->policy = value;
145 * Crypto support requirements:
147 * 1 require hardware support
148 * -1 require software support
151 VNET_DEFINE(int, crypto_support) = CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE;
154 * Use asynchronous mode to parallelize crypto jobs:
159 VNET_DEFINE(int, async_crypto) = 0;
162 * TCP/UDP checksum handling policy for transport mode NAT-T (RFC3948)
164 * 0 - auto: incrementally recompute, when checksum delta is known;
165 * if checksum delta isn't known, reset checksum to zero for UDP,
166 * and mark csum_flags as valid for TCP.
167 * 1 - fully recompute TCP/UDP checksum.
169 VNET_DEFINE(int, natt_cksum_policy) = 0;
171 FEATURE(ipsec, "Internet Protocol Security (IPsec)");
172 FEATURE(ipsec_natt, "UDP Encapsulation of IPsec ESP Packets ('NAT-T')");
174 SYSCTL_DECL(_net_inet_ipsec);
177 SYSCTL_PROC(_net_inet_ipsec, IPSECCTL_DEF_POLICY, def_policy,
178 CTLTYPE_INT | CTLFLAG_VNET | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
179 0, 0, sysctl_def_policy, "I",
180 "IPsec default policy.");
181 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_ESP_TRANSLEV, esp_trans_deflev,
182 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_esp_trans_deflev), 0,
183 "Default ESP transport mode level");
184 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_ESP_NETLEV, esp_net_deflev,
185 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_esp_net_deflev), 0,
186 "Default ESP tunnel mode level.");
187 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_AH_TRANSLEV, ah_trans_deflev,
188 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_ah_trans_deflev), 0,
189 "AH transfer mode default level.");
190 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_AH_NETLEV, ah_net_deflev,
191 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_ah_net_deflev), 0,
192 "AH tunnel mode default level.");
193 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_AH_CLEARTOS, ah_cleartos,
194 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ah_cleartos), 0,
195 "If set, clear type-of-service field when doing AH computation.");
196 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DFBIT, dfbit,
197 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_ipsec_dfbit), 0,
198 "Do not fragment bit on encap.");
199 SYSCTL_INT(_net_inet_ipsec, IPSECCTL_ECN, ecn,
200 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_ipsec_ecn), 0,
201 "Explicit Congestion Notification handling.");
202 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, crypto_support,
203 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(crypto_support), 0,
204 "Crypto driver selection.");
205 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, async_crypto,
206 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(async_crypto), 0,
207 "Use asynchronous mode to parallelize crypto jobs.");
208 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, check_policy_history,
209 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(check_policy_history), 0,
210 "Use strict check of inbound packets to security policy compliance.");
211 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, natt_cksum_policy,
212 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(natt_cksum_policy), 0,
213 "Method to fix TCP/UDP checksum for transport mode IPsec after NAT.");
214 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, filtertunnel,
215 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip4_filtertunnel), 0,
216 "If set, filter packets from an IPsec tunnel.");
217 SYSCTL_VNET_PCPUSTAT(_net_inet_ipsec, OID_AUTO, ipsecstats, struct ipsecstat,
218 ipsec4stat, "IPsec IPv4 statistics.");
222 * When set to 1, IPsec will send packets with the same sequence number.
223 * This allows to verify if the other side has proper replay attacks detection.
225 VNET_DEFINE(int, ipsec_replay) = 0;
226 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, test_replay,
227 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ipsec_replay), 0,
228 "Emulate replay attack");
230 * When set 1, IPsec will send packets with corrupted HMAC.
231 * This allows to verify if the other side properly detects modified packets.
233 VNET_DEFINE(int, ipsec_integrity) = 0;
234 SYSCTL_INT(_net_inet_ipsec, OID_AUTO, test_integrity,
235 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ipsec_integrity), 0,
236 "Emulate man-in-the-middle attack");
240 VNET_PCPUSTAT_DEFINE(struct ipsecstat, ipsec6stat);
241 VNET_PCPUSTAT_SYSINIT(ipsec6stat);
244 VNET_PCPUSTAT_SYSUNINIT(ipsec6stat);
247 VNET_DEFINE(int, ip6_esp_trans_deflev) = IPSEC_LEVEL_USE;
248 VNET_DEFINE(int, ip6_esp_net_deflev) = IPSEC_LEVEL_USE;
249 VNET_DEFINE(int, ip6_ah_trans_deflev) = IPSEC_LEVEL_USE;
250 VNET_DEFINE(int, ip6_ah_net_deflev) = IPSEC_LEVEL_USE;
251 VNET_DEFINE(int, ip6_ipsec_ecn) = 0; /* ECN ignore(-1)/forbidden(0)/allowed(1) */
253 VNET_DEFINE_STATIC(int, ip6_filtertunnel) = 0;
254 #define V_ip6_filtertunnel VNET(ip6_filtertunnel)
256 SYSCTL_DECL(_net_inet6_ipsec6);
258 /* net.inet6.ipsec6 */
259 SYSCTL_PROC(_net_inet6_ipsec6, IPSECCTL_DEF_POLICY, def_policy,
260 CTLTYPE_INT | CTLFLAG_VNET | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
261 0, 0, sysctl_def_policy, "I",
262 "IPsec default policy.");
263 SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_ESP_TRANSLEV, esp_trans_deflev,
264 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_esp_trans_deflev), 0,
265 "Default ESP transport mode level.");
266 SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_ESP_NETLEV, esp_net_deflev,
267 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_esp_net_deflev), 0,
268 "Default ESP tunnel mode level.");
269 SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_AH_TRANSLEV, ah_trans_deflev,
270 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_ah_trans_deflev), 0,
271 "AH transfer mode default level.");
272 SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_AH_NETLEV, ah_net_deflev,
273 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_ah_net_deflev), 0,
274 "AH tunnel mode default level.");
275 SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_ECN, ecn,
276 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_ipsec_ecn), 0,
277 "Explicit Congestion Notification handling.");
278 SYSCTL_INT(_net_inet6_ipsec6, OID_AUTO, filtertunnel,
279 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_filtertunnel), 0,
280 "If set, filter packets from an IPsec tunnel.");
281 SYSCTL_VNET_PCPUSTAT(_net_inet6_ipsec6, IPSECCTL_STATS, ipsecstats,
282 struct ipsecstat, ipsec6stat, "IPsec IPv6 statistics.");
285 static int ipsec_in_reject(struct secpolicy *, struct inpcb *,
286 const struct mbuf *);
289 static void ipsec4_get_ulp(const struct mbuf *, struct secpolicyindex *, int);
290 static void ipsec4_setspidx_ipaddr(const struct mbuf *,
291 struct secpolicyindex *);
294 static void ipsec6_get_ulp(const struct mbuf *m, struct secpolicyindex *, int);
295 static void ipsec6_setspidx_ipaddr(const struct mbuf *,
296 struct secpolicyindex *);
300 * Return a held reference to the default SP.
302 static struct secpolicy *
303 key_allocsp_default(void)
306 key_addref(V_def_policy);
307 return (V_def_policy);
311 ipsec_invalidate_cache(struct inpcb *inp, u_int dir)
313 struct secpolicy *sp;
315 INP_WLOCK_ASSERT(inp);
316 if (dir == IPSEC_DIR_OUTBOUND) {
317 if (inp->inp_sp->flags & INP_INBOUND_POLICY)
319 sp = inp->inp_sp->sp_in;
320 inp->inp_sp->sp_in = NULL;
322 if (inp->inp_sp->flags & INP_OUTBOUND_POLICY)
324 sp = inp->inp_sp->sp_out;
325 inp->inp_sp->sp_out = NULL;
328 key_freesp(&sp); /* release extra reference */
332 ipsec_cachepolicy(struct inpcb *inp, struct secpolicy *sp, u_int dir)
337 INP_LOCK_ASSERT(inp);
339 if (dir == IPSEC_DIR_OUTBOUND) {
340 /* Do we have configured PCB policy? */
341 if (inp->inp_sp->flags & INP_OUTBOUND_POLICY)
343 /* Another thread has already set cached policy */
344 if (inp->inp_sp->sp_out != NULL)
347 * Do not cache OUTBOUND policy if PCB isn't connected,
348 * i.e. foreign address is INADDR_ANY/UNSPECIFIED.
351 if ((inp->inp_vflag & INP_IPV4) != 0 &&
352 inp->inp_faddr.s_addr == INADDR_ANY)
356 if ((inp->inp_vflag & INP_IPV6) != 0 &&
357 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr))
361 /* Do we have configured PCB policy? */
362 if (inp->inp_sp->flags & INP_INBOUND_POLICY)
364 /* Another thread has already set cached policy */
365 if (inp->inp_sp->sp_in != NULL)
368 * Do not cache INBOUND policy for listen socket,
369 * that is bound to INADDR_ANY/UNSPECIFIED address.
372 if ((inp->inp_vflag & INP_IPV4) != 0 &&
373 inp->inp_faddr.s_addr == INADDR_ANY)
377 if ((inp->inp_vflag & INP_IPV6) != 0 &&
378 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr))
383 if (!INP_WLOCKED(inp)) {
384 if ((downgrade = INP_TRY_UPGRADE(inp)) == 0)
387 if (dir == IPSEC_DIR_OUTBOUND)
388 inp->inp_sp->sp_out = sp;
390 inp->inp_sp->sp_in = sp;
392 * SP is already referenced by the lookup code.
393 * We take extra reference here to avoid race in the
394 * ipsec_getpcbpolicy() function - SP will not be freed in the
395 * time between we take SP pointer from the cache and key_addref()
399 genid = key_getspgen();
400 if (genid != inp->inp_sp->genid) {
401 ipsec_invalidate_cache(inp, dir);
402 inp->inp_sp->genid = genid;
405 printf("%s: PCB(%p): cached %s SP(%p)\n",
406 __func__, inp, dir == IPSEC_DIR_OUTBOUND ? "OUTBOUND":
412 static struct secpolicy *
413 ipsec_checkpolicy(struct secpolicy *sp, struct inpcb *inp, int *error)
416 /* Save found OUTBOUND policy into PCB SP cache. */
417 if (inp != NULL && inp->inp_sp != NULL && inp->inp_sp->sp_out == NULL)
418 ipsec_cachepolicy(inp, sp, IPSEC_DIR_OUTBOUND);
420 switch (sp->policy) {
422 printf("%s: invalid policy %u\n", __func__, sp->policy);
424 case IPSEC_POLICY_DISCARD:
425 *error = -EINVAL; /* Packet is discarded by caller. */
427 case IPSEC_POLICY_BYPASS:
428 case IPSEC_POLICY_NONE:
430 sp = NULL; /* NB: force NULL result. */
432 case IPSEC_POLICY_IPSEC:
433 /* XXXAE: handle LARVAL SP */
437 printf("%s: get SP(%p), error %d\n", __func__, sp, *error));
441 static struct secpolicy *
442 ipsec_getpcbpolicy(struct inpcb *inp, u_int dir)
444 struct secpolicy *sp;
445 int flags, downgrade;
447 if (inp == NULL || inp->inp_sp == NULL)
450 INP_LOCK_ASSERT(inp);
452 flags = inp->inp_sp->flags;
453 if (dir == IPSEC_DIR_OUTBOUND) {
454 sp = inp->inp_sp->sp_out;
455 flags &= INP_OUTBOUND_POLICY;
457 sp = inp->inp_sp->sp_in;
458 flags &= INP_INBOUND_POLICY;
461 * Check flags. If we have PCB SP, just return it.
462 * Otherwise we need to check that cached SP entry isn't stale.
467 if (inp->inp_sp->genid != key_getspgen()) {
468 /* Invalidate the cache. */
470 if (!INP_WLOCKED(inp)) {
471 if ((downgrade = INP_TRY_UPGRADE(inp)) == 0)
474 ipsec_invalidate_cache(inp, IPSEC_DIR_OUTBOUND);
475 ipsec_invalidate_cache(inp, IPSEC_DIR_INBOUND);
481 printf("%s: PCB(%p): cache hit SP(%p)\n",
483 /* Return referenced cached policy */
491 ipsec4_get_ulp(const struct mbuf *m, struct secpolicyindex *spidx,
498 IPSEC_ASSERT(m->m_pkthdr.len >= sizeof(struct ip),
499 ("packet too short"));
501 if (m->m_len >= sizeof (struct ip)) {
502 const struct ip *ip = mtod(m, const struct ip *);
503 if (ip->ip_off & htons(IP_MF | IP_OFFMASK))
505 off = ip->ip_hl << 2;
510 m_copydata(m, 0, sizeof (struct ip), (caddr_t) &ih);
511 if (ih.ip_off & htons(IP_MF | IP_OFFMASK))
517 while (off < m->m_pkthdr.len) {
524 spidx->ul_proto = nxt;
527 if (off + sizeof(struct tcphdr) > m->m_pkthdr.len)
529 m_copydata(m, off, sizeof (th), (caddr_t) &th);
530 spidx->src.sin.sin_port = th.th_sport;
531 spidx->dst.sin.sin_port = th.th_dport;
534 spidx->ul_proto = nxt;
537 if (off + sizeof(struct udphdr) > m->m_pkthdr.len)
539 m_copydata(m, off, sizeof (uh), (caddr_t) &uh);
540 spidx->src.sin.sin_port = uh.uh_sport;
541 spidx->dst.sin.sin_port = uh.uh_dport;
544 if (off + sizeof(ip6e) > m->m_pkthdr.len)
546 /* XXX Sigh, this works but is totally bogus. */
547 m_copydata(m, off, sizeof(ip6e), (caddr_t) &ip6e);
548 off += (ip6e.ip6e_len + 2) << 2;
553 /* XXX Intermediate headers??? */
554 spidx->ul_proto = nxt;
559 spidx->ul_proto = IPSEC_ULPROTO_ANY;
561 spidx->src.sin.sin_port = IPSEC_PORT_ANY;
562 spidx->dst.sin.sin_port = IPSEC_PORT_ANY;
564 printf("%s: ", __func__); kdebug_secpolicyindex(spidx, NULL));
568 ipsec4_setspidx_ipaddr(const struct mbuf *m, struct secpolicyindex *spidx)
571 ipsec4_setsockaddrs(m, &spidx->src, &spidx->dst);
572 spidx->prefs = sizeof(struct in_addr) << 3;
573 spidx->prefd = sizeof(struct in_addr) << 3;
576 static struct secpolicy *
577 ipsec4_getpolicy(const struct mbuf *m, struct inpcb *inp, u_int dir,
580 struct secpolicyindex spidx;
581 struct secpolicy *sp;
583 sp = ipsec_getpcbpolicy(inp, dir);
584 if (sp == NULL && key_havesp(dir)) {
585 /* Make an index to look for a policy. */
586 ipsec4_setspidx_ipaddr(m, &spidx);
587 ipsec4_get_ulp(m, &spidx, needport);
589 sp = key_allocsp(&spidx, dir);
591 if (sp == NULL) /* No SP found, use system default. */
592 sp = key_allocsp_default();
597 * Check security policy for *OUTBOUND* IPv4 packet.
600 ipsec4_checkpolicy(const struct mbuf *m, struct inpcb *inp, int *error,
603 struct secpolicy *sp;
606 sp = ipsec4_getpolicy(m, inp, IPSEC_DIR_OUTBOUND, needport);
608 sp = ipsec_checkpolicy(sp, inp, error);
611 case 0: /* No IPsec required: BYPASS or NONE */
614 IPSECSTAT_INC(ips_out_polvio);
617 IPSECSTAT_INC(ips_out_inval);
621 printf("%s: using SP(%p), error %d\n", __func__, sp, *error));
623 KEYDBG(IPSEC_DATA, kdebug_secpolicy(sp));
628 * Check IPv4 packet against *INBOUND* security policy.
629 * This function is called from tcp_input(), udp_input(),
630 * rip_input() and sctp_input().
633 ipsec4_in_reject(const struct mbuf *m, struct inpcb *inp)
635 struct secpolicy *sp;
638 sp = ipsec4_getpolicy(m, inp, IPSEC_DIR_INBOUND, 0);
639 result = ipsec_in_reject(sp, inp, m);
642 IPSECSTAT_INC(ips_in_polvio);
647 * IPSEC_CAP() method implementation for IPv4.
650 ipsec4_capability(struct mbuf *m, u_int cap)
654 case IPSEC_CAP_BYPASS_FILTER:
656 * Bypass packet filtering for packets previously handled
659 if (!V_ip4_filtertunnel &&
660 m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL) != NULL)
663 case IPSEC_CAP_OPERABLE:
664 /* Do we have active security policies? */
665 if (key_havesp(IPSEC_DIR_INBOUND) != 0 ||
666 key_havesp(IPSEC_DIR_OUTBOUND) != 0)
677 ipsec6_get_ulp(const struct mbuf *m, struct secpolicyindex *spidx,
685 IPSEC_ASSERT(m->m_pkthdr.len >= sizeof(struct ip6_hdr),
686 ("packet too short"));
689 spidx->ul_proto = IPSEC_ULPROTO_ANY;
690 spidx->src.sin6.sin6_port = IPSEC_PORT_ANY;
691 spidx->dst.sin6.sin6_port = IPSEC_PORT_ANY;
694 off = ip6_lasthdr(m, 0, IPPROTO_IPV6, &nxt);
695 if (off < 0 || m->m_pkthdr.len < off)
700 spidx->ul_proto = nxt;
703 if (off + sizeof(struct tcphdr) > m->m_pkthdr.len)
705 m_copydata(m, off, sizeof(th), (caddr_t)&th);
706 spidx->src.sin6.sin6_port = th.th_sport;
707 spidx->dst.sin6.sin6_port = th.th_dport;
710 spidx->ul_proto = nxt;
713 if (off + sizeof(struct udphdr) > m->m_pkthdr.len)
715 m_copydata(m, off, sizeof(uh), (caddr_t)&uh);
716 spidx->src.sin6.sin6_port = uh.uh_sport;
717 spidx->dst.sin6.sin6_port = uh.uh_dport;
720 spidx->ul_proto = nxt;
721 if (off + sizeof(struct icmp6_hdr) > m->m_pkthdr.len)
723 m_copydata(m, off, sizeof(ih), (caddr_t)&ih);
724 spidx->src.sin6.sin6_port = htons((uint16_t)ih.icmp6_type);
725 spidx->dst.sin6.sin6_port = htons((uint16_t)ih.icmp6_code);
728 /* XXX Intermediate headers??? */
729 spidx->ul_proto = nxt;
733 printf("%s: ", __func__); kdebug_secpolicyindex(spidx, NULL));
737 ipsec6_setspidx_ipaddr(const struct mbuf *m, struct secpolicyindex *spidx)
740 ipsec6_setsockaddrs(m, &spidx->src, &spidx->dst);
741 spidx->prefs = sizeof(struct in6_addr) << 3;
742 spidx->prefd = sizeof(struct in6_addr) << 3;
745 static struct secpolicy *
746 ipsec6_getpolicy(const struct mbuf *m, struct inpcb *inp, u_int dir,
749 struct secpolicyindex spidx;
750 struct secpolicy *sp;
752 sp = ipsec_getpcbpolicy(inp, dir);
753 if (sp == NULL && key_havesp(dir)) {
754 /* Make an index to look for a policy. */
755 ipsec6_setspidx_ipaddr(m, &spidx);
756 ipsec6_get_ulp(m, &spidx, needport);
758 sp = key_allocsp(&spidx, dir);
760 if (sp == NULL) /* No SP found, use system default. */
761 sp = key_allocsp_default();
766 * Check security policy for *OUTBOUND* IPv6 packet.
769 ipsec6_checkpolicy(const struct mbuf *m, struct inpcb *inp, int *error,
772 struct secpolicy *sp;
775 sp = ipsec6_getpolicy(m, inp, IPSEC_DIR_OUTBOUND, needport);
777 sp = ipsec_checkpolicy(sp, inp, error);
780 case 0: /* No IPsec required: BYPASS or NONE */
783 IPSEC6STAT_INC(ips_out_polvio);
786 IPSEC6STAT_INC(ips_out_inval);
790 printf("%s: using SP(%p), error %d\n", __func__, sp, *error));
792 KEYDBG(IPSEC_DATA, kdebug_secpolicy(sp));
797 * Check IPv6 packet against inbound security policy.
798 * This function is called from tcp6_input(), udp6_input(),
799 * rip6_input() and sctp_input().
802 ipsec6_in_reject(const struct mbuf *m, struct inpcb *inp)
804 struct secpolicy *sp;
807 sp = ipsec6_getpolicy(m, inp, IPSEC_DIR_INBOUND, 0);
808 result = ipsec_in_reject(sp, inp, m);
811 IPSEC6STAT_INC(ips_in_polvio);
816 * IPSEC_CAP() method implementation for IPv6.
819 ipsec6_capability(struct mbuf *m, u_int cap)
823 case IPSEC_CAP_BYPASS_FILTER:
825 * Bypass packet filtering for packets previously handled
828 if (!V_ip6_filtertunnel &&
829 m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL) != NULL)
832 case IPSEC_CAP_OPERABLE:
833 /* Do we have active security policies? */
834 if (key_havesp(IPSEC_DIR_INBOUND) != 0 ||
835 key_havesp(IPSEC_DIR_OUTBOUND) != 0)
844 ipsec_run_hhooks(struct ipsec_ctx_data *ctx, int type)
851 idx = HHOOK_IPSEC_INET;
856 idx = HHOOK_IPSEC_INET6;
860 return (EPFNOSUPPORT);
862 if (type == HHOOK_TYPE_IPSEC_IN)
863 HHOOKS_RUN_IF(V_ipsec_hhh_in[idx], ctx, NULL);
865 HHOOKS_RUN_IF(V_ipsec_hhh_out[idx], ctx, NULL);
866 if (*ctx->mp == NULL)
872 * Return current level.
873 * Either IPSEC_LEVEL_USE or IPSEC_LEVEL_REQUIRE are always returned.
876 ipsec_get_reqlevel(struct secpolicy *sp, u_int idx)
878 struct ipsecrequest *isr;
879 u_int esp_trans_deflev, esp_net_deflev;
880 u_int ah_trans_deflev, ah_net_deflev;
883 IPSEC_ASSERT(idx < sp->tcount, ("Wrong IPsec request index %d", idx));
884 /* XXX Note that we have ipseclog() expanded here - code sync issue. */
885 #define IPSEC_CHECK_DEFAULT(lev) \
886 (((lev) != IPSEC_LEVEL_USE && (lev) != IPSEC_LEVEL_REQUIRE && \
887 (lev) != IPSEC_LEVEL_UNIQUE) \
889 log(LOG_INFO, "fixed system default level " #lev ":%d->%d\n",\
890 (lev), IPSEC_LEVEL_REQUIRE) : 0), \
891 (lev) = IPSEC_LEVEL_REQUIRE, (lev) : (lev))
894 * IPsec VTI uses unique security policy with fake spidx filled
895 * with zeroes. Just return IPSEC_LEVEL_REQUIRE instead of doing
896 * full level lookup for such policies.
898 if (sp->state == IPSEC_SPSTATE_IFNET) {
899 IPSEC_ASSERT(sp->req[idx]->level == IPSEC_LEVEL_UNIQUE,
900 ("Wrong IPsec request level %d", sp->req[idx]->level));
901 return (IPSEC_LEVEL_REQUIRE);
904 /* Set default level. */
905 switch (sp->spidx.src.sa.sa_family) {
908 esp_trans_deflev = IPSEC_CHECK_DEFAULT(V_ip4_esp_trans_deflev);
909 esp_net_deflev = IPSEC_CHECK_DEFAULT(V_ip4_esp_net_deflev);
910 ah_trans_deflev = IPSEC_CHECK_DEFAULT(V_ip4_ah_trans_deflev);
911 ah_net_deflev = IPSEC_CHECK_DEFAULT(V_ip4_ah_net_deflev);
916 esp_trans_deflev = IPSEC_CHECK_DEFAULT(V_ip6_esp_trans_deflev);
917 esp_net_deflev = IPSEC_CHECK_DEFAULT(V_ip6_esp_net_deflev);
918 ah_trans_deflev = IPSEC_CHECK_DEFAULT(V_ip6_ah_trans_deflev);
919 ah_net_deflev = IPSEC_CHECK_DEFAULT(V_ip6_ah_net_deflev);
923 panic("%s: unknown af %u",
924 __func__, sp->spidx.src.sa.sa_family);
927 #undef IPSEC_CHECK_DEFAULT
931 switch (isr->level) {
932 case IPSEC_LEVEL_DEFAULT:
933 switch (isr->saidx.proto) {
935 if (isr->saidx.mode == IPSEC_MODE_TUNNEL)
936 level = esp_net_deflev;
938 level = esp_trans_deflev;
941 if (isr->saidx.mode == IPSEC_MODE_TUNNEL)
942 level = ah_net_deflev;
944 level = ah_trans_deflev;
948 * We don't really care, as IPcomp document says that
949 * we shouldn't compress small packets.
951 level = IPSEC_LEVEL_USE;
954 panic("%s: Illegal protocol defined %u\n", __func__,
959 case IPSEC_LEVEL_USE:
960 case IPSEC_LEVEL_REQUIRE:
963 case IPSEC_LEVEL_UNIQUE:
964 level = IPSEC_LEVEL_REQUIRE;
968 panic("%s: Illegal IPsec level %u\n", __func__, isr->level);
975 ipsec_check_history(const struct mbuf *m, struct secpolicy *sp, u_int idx)
977 struct xform_history *xh;
981 while ((mtag = m_tag_find(__DECONST(struct mbuf *, m),
982 PACKET_TAG_IPSEC_IN_DONE, mtag)) != NULL) {
983 xh = (struct xform_history *)(mtag + 1);
985 char buf[IPSEC_ADDRSTRLEN];
986 printf("%s: mode %s proto %u dst %s\n", __func__,
987 kdebug_secasindex_mode(xh->mode), xh->proto,
988 ipsec_address(&xh->dst, buf, sizeof(buf))));
989 if (xh->proto != sp->req[idx]->saidx.proto)
991 /* If SA had IPSEC_MODE_ANY, consider this as match. */
992 if (xh->mode != sp->req[idx]->saidx.mode &&
993 xh->mode != IPSEC_MODE_ANY)
996 * For transport mode IPsec request doesn't contain
997 * addresses. We need to use address from spidx.
999 if (sp->req[idx]->saidx.mode == IPSEC_MODE_TRANSPORT) {
1000 if (key_sockaddrcmp_withmask(&xh->dst.sa,
1001 &sp->spidx.dst.sa, sp->spidx.prefd) != 0)
1004 if (key_sockaddrcmp(&xh->dst.sa,
1005 &sp->req[idx]->saidx.dst.sa, 0) != 0)
1008 return (0); /* matched */
1014 * Check security policy requirements against the actual
1015 * packet contents. Return one if the packet should be
1016 * reject as "invalid"; otherwiser return zero to have the
1017 * packet treated as "valid".
1024 ipsec_in_reject(struct secpolicy *sp, struct inpcb *inp, const struct mbuf *m)
1029 printf("%s: PCB(%p): using SP(%p)\n", __func__, inp, sp));
1030 KEYDBG(IPSEC_DATA, kdebug_secpolicy(sp));
1032 if (inp != NULL && inp->inp_sp != NULL && inp->inp_sp->sp_in == NULL)
1033 ipsec_cachepolicy(inp, sp, IPSEC_DIR_INBOUND);
1036 switch (sp->policy) {
1037 case IPSEC_POLICY_DISCARD:
1039 case IPSEC_POLICY_BYPASS:
1040 case IPSEC_POLICY_NONE:
1044 IPSEC_ASSERT(sp->policy == IPSEC_POLICY_IPSEC,
1045 ("invalid policy %u", sp->policy));
1048 * ipsec[46]_common_input_cb after each transform adds
1049 * PACKET_TAG_IPSEC_IN_DONE mbuf tag. It contains SPI, proto, mode
1050 * and destination address from saidx. We can compare info from
1051 * these tags with requirements in SP.
1053 for (i = 0; i < sp->tcount; i++) {
1055 * Do not check IPcomp, since IPcomp document
1056 * says that we shouldn't compress small packets.
1057 * IPComp policy should always be treated as being
1060 if (sp->req[i]->saidx.proto == IPPROTO_IPCOMP ||
1061 ipsec_get_reqlevel(sp, i) != IPSEC_LEVEL_REQUIRE)
1063 if (V_check_policy_history != 0 &&
1064 ipsec_check_history(m, sp, i) != 0)
1066 else switch (sp->req[i]->saidx.proto) {
1068 if ((m->m_flags & M_DECRYPTED) == 0) {
1070 printf("%s: ESP m_flags:%x\n", __func__,
1076 if ((m->m_flags & M_AUTHIPHDR) == 0) {
1078 printf("%s: AH m_flags:%x\n", __func__,
1085 return (0); /* Valid. */
1089 * Compute the byte size to be occupied by IPsec header.
1090 * In case it is tunnelled, it includes the size of outer IP header.
1093 ipsec_hdrsiz_internal(struct secpolicy *sp)
1098 KEYDBG(IPSEC_STAMP, printf("%s: using SP(%p)\n", __func__, sp));
1099 KEYDBG(IPSEC_DATA, kdebug_secpolicy(sp));
1101 switch (sp->policy) {
1102 case IPSEC_POLICY_DISCARD:
1103 case IPSEC_POLICY_BYPASS:
1104 case IPSEC_POLICY_NONE:
1108 IPSEC_ASSERT(sp->policy == IPSEC_POLICY_IPSEC,
1109 ("invalid policy %u", sp->policy));
1112 * XXX: for each transform we need to lookup suitable SA
1113 * and use info from SA to calculate headers size.
1114 * XXX: for NAT-T we need to cosider UDP header size.
1117 for (i = 0; i < sp->tcount; i++) {
1118 switch (sp->req[i]->saidx.proto) {
1120 size += esp_hdrsiz(NULL);
1123 size += ah_hdrsiz(NULL);
1125 case IPPROTO_IPCOMP:
1126 size += sizeof(struct ipcomp);
1130 if (sp->req[i]->saidx.mode == IPSEC_MODE_TUNNEL) {
1131 switch (sp->req[i]->saidx.dst.sa.sa_family) {
1134 size += sizeof(struct ip);
1139 size += sizeof(struct ip6_hdr);
1143 ipseclog((LOG_ERR, "%s: unknown AF %d in "
1144 "IPsec tunnel SA\n", __func__,
1145 sp->req[i]->saidx.dst.sa.sa_family));
1154 * Compute ESP/AH header size for protocols with PCB, including
1155 * outer IP header. Currently only tcp_output() uses it.
1158 ipsec_hdrsiz_inpcb(struct inpcb *inp)
1160 struct secpolicyindex spidx;
1161 struct secpolicy *sp;
1164 sp = ipsec_getpcbpolicy(inp, IPSEC_DIR_OUTBOUND);
1165 if (sp == NULL && key_havesp(IPSEC_DIR_OUTBOUND)) {
1166 ipsec_setspidx_inpcb(inp, &spidx, IPSEC_DIR_OUTBOUND);
1167 sp = key_allocsp(&spidx, IPSEC_DIR_OUTBOUND);
1170 sp = key_allocsp_default();
1171 sz = ipsec_hdrsiz_internal(sp);
1177 #define IPSEC_BITMAP_INDEX_MASK(w) (w - 1)
1178 #define IPSEC_REDUNDANT_BIT_SHIFTS 5
1179 #define IPSEC_REDUNDANT_BITS (1 << IPSEC_REDUNDANT_BIT_SHIFTS)
1180 #define IPSEC_BITMAP_LOC_MASK (IPSEC_REDUNDANT_BITS - 1)
1183 * Functions below are responsible for checking and updating bitmap.
1184 * These are used to separate ipsec_chkreplay() and ipsec_updatereplay()
1185 * from window implementation
1187 * Based on RFC 6479. Blocks are 32 bits unsigned integers
1191 check_window(const struct secreplay *replay, uint64_t seq)
1193 int index, bit_location;
1195 bit_location = seq & IPSEC_BITMAP_LOC_MASK;
1196 index = (seq >> IPSEC_REDUNDANT_BIT_SHIFTS)
1197 & IPSEC_BITMAP_INDEX_MASK(replay->bitmap_size);
1199 /* This packet already seen? */
1200 return ((replay->bitmap)[index] & (1 << bit_location));
1204 advance_window(const struct secreplay *replay, uint64_t seq)
1207 uint64_t index, index_cur, diff;
1209 index_cur = replay->last >> IPSEC_REDUNDANT_BIT_SHIFTS;
1210 index = seq >> IPSEC_REDUNDANT_BIT_SHIFTS;
1211 diff = index - index_cur;
1213 if (diff > replay->bitmap_size) {
1214 /* something unusual in this case */
1215 diff = replay->bitmap_size;
1218 for (i = 0; i < diff; i++) {
1219 replay->bitmap[(i + index_cur + 1)
1220 & IPSEC_BITMAP_INDEX_MASK(replay->bitmap_size)] = 0;
1225 set_window(const struct secreplay *replay, uint64_t seq)
1227 int index, bit_location;
1229 bit_location = seq & IPSEC_BITMAP_LOC_MASK;
1230 index = (seq >> IPSEC_REDUNDANT_BIT_SHIFTS)
1231 & IPSEC_BITMAP_INDEX_MASK(replay->bitmap_size);
1233 replay->bitmap[index] |= (1 << bit_location);
1237 * Check the variable replay window.
1238 * ipsec_chkreplay() performs replay check before ICV verification.
1239 * ipsec_updatereplay() updates replay bitmap. This must be called after
1240 * ICV verification (it also performs replay check, which is usually done
1242 * 0 (zero) is returned if packet disallowed, 1 if packet permitted.
1248 ipsec_chkreplay(uint32_t seq, uint32_t *seqhigh, struct secasvar *sav)
1251 struct secreplay *replay;
1253 uint32_t tl, th, bl;
1256 IPSEC_ASSERT(sav != NULL, ("Null SA"));
1257 IPSEC_ASSERT(sav->replay != NULL, ("Null replay state"));
1259 replay = sav->replay;
1261 /* No need to check replay if disabled. */
1262 if (replay->wsize == 0)
1265 /* Zero sequence number is not allowed. */
1266 if (seq == 0 && replay->last == 0)
1269 window = replay->wsize << 3; /* Size of window */
1270 tl = (uint32_t)replay->last; /* Top of window, lower part */
1271 th = (uint32_t)(replay->last >> 32); /* Top of window, high part */
1272 bl = tl - window + 1; /* Bottom of window, lower part */
1275 * We keep the high part intact when:
1276 * 1) the seq is within [bl, 0xffffffff] and the whole window is
1277 * within one subspace;
1278 * 2) the seq is within [0, bl) and window spans two subspaces.
1280 if ((tl >= window - 1 && seq >= bl) ||
1281 (tl < window - 1 && seq < bl)) {
1284 /* Sequence number inside window - check against replay */
1285 if (check_window(replay, seq))
1289 /* Sequence number above top of window or not found in bitmap */
1294 * If ESN is not enabled and packet with highest sequence number
1295 * was received we should report overflow
1297 if (tl == 0xffffffff && !(sav->flags & SADB_X_SAFLAGS_ESN)) {
1298 /* Set overflow flag. */
1301 if ((sav->flags & SADB_X_EXT_CYCSEQ) == 0) {
1302 if (sav->sah->saidx.proto == IPPROTO_ESP)
1303 ESPSTAT_INC(esps_wrap);
1304 else if (sav->sah->saidx.proto == IPPROTO_AH)
1305 AHSTAT_INC(ahs_wrap);
1309 ipseclog((LOG_WARNING, "%s: replay counter made %d cycle. %s\n",
1310 __func__, replay->overflow,
1311 ipsec_sa2str(sav, buf, sizeof(buf))));
1315 * Seq is within [bl, 0xffffffff] and bl is within
1316 * [0xffffffff-window, 0xffffffff]. This means we got a seq
1317 * which is within our replay window, but in the previous
1320 if (tl < window - 1 && seq >= bl) {
1325 if (check_window(replay, seq))
1331 * Seq is within [0, bl) but the whole window is within one subspace.
1332 * This means that seq has wrapped and is in next subspace
1337 /* Don't let high part wrap. */
1339 /* Set overflow flag. */
1342 if ((sav->flags & SADB_X_EXT_CYCSEQ) == 0) {
1343 if (sav->sah->saidx.proto == IPPROTO_ESP)
1344 ESPSTAT_INC(esps_wrap);
1345 else if (sav->sah->saidx.proto == IPPROTO_AH)
1346 AHSTAT_INC(ahs_wrap);
1350 ipseclog((LOG_WARNING, "%s: replay counter made %d cycle. %s\n",
1351 __func__, replay->overflow,
1352 ipsec_sa2str(sav, buf, sizeof(buf))));
1359 * Check replay counter whether to update or not.
1364 ipsec_updatereplay(uint32_t seq, struct secasvar *sav)
1366 struct secreplay *replay;
1368 uint32_t tl, th, bl;
1371 IPSEC_ASSERT(sav != NULL, ("Null SA"));
1372 IPSEC_ASSERT(sav->replay != NULL, ("Null replay state"));
1374 replay = sav->replay;
1376 /* No need to check replay if disabled. */
1377 if (replay->wsize == 0)
1380 /* Zero sequence number is not allowed. */
1381 if (seq == 0 && replay->last == 0)
1384 window = replay->wsize << 3; /* Size of window */
1385 tl = (uint32_t)replay->last; /* Top of window, lower part */
1386 th = (uint32_t)(replay->last >> 32); /* Top of window, high part */
1387 bl = tl - window + 1; /* Bottom of window, lower part */
1390 * We keep the high part intact when:
1391 * 1) the seq is within [bl, 0xffffffff] and the whole window is
1392 * within one subspace;
1393 * 2) the seq is within [0, bl) and window spans two subspaces.
1395 if ((tl >= window - 1 && seq >= bl) ||
1396 (tl < window - 1 && seq < bl)) {
1399 /* Sequence number inside window - check against replay */
1400 if (check_window(replay, seq))
1402 set_window(replay, seq);
1404 advance_window(replay, ((uint64_t)seqh << 32) | seq);
1405 set_window(replay, seq);
1406 replay->last = ((uint64_t)seqh << 32) | seq;
1409 /* Sequence number above top of window or not found in bitmap */
1414 if (!(sav->flags & SADB_X_SAFLAGS_ESN))
1418 * Seq is within [bl, 0xffffffff] and bl is within
1419 * [0xffffffff-window, 0xffffffff]. This means we got a seq
1420 * which is within our replay window, but in the previous
1423 if (tl < window - 1 && seq >= bl) {
1426 if (check_window(replay, seq))
1429 set_window(replay, seq);
1435 * Seq is within [0, bl) but the whole window is within one subspace.
1436 * This means that seq has wrapped and is in next subspace
1440 /* Don't let high part wrap. */
1444 advance_window(replay, ((uint64_t)seqh << 32) | seq);
1445 set_window(replay, seq);
1446 replay->last = ((uint64_t)seqh << 32) | seq;
1451 ipsec_updateid(struct secasvar *sav, crypto_session_t *new,
1452 crypto_session_t *old)
1454 crypto_session_t tmp;
1457 * tdb_cryptoid is initialized by xform_init().
1458 * Then it can be changed only when some crypto error occurred or
1459 * when SA is deleted. We stored used cryptoid in the xform_data
1460 * structure. In case when crypto error occurred and crypto
1461 * subsystem has reinited the session, it returns new cryptoid
1462 * and EAGAIN error code.
1464 * This function will be called when we got EAGAIN from crypto
1466 * *new is cryptoid that was returned by crypto subsystem in
1468 * *old is the original cryptoid that we stored in xform_data.
1470 * For first failed request *old == sav->tdb_cryptoid, then
1471 * we update sav->tdb_cryptoid and redo crypto_dispatch().
1472 * For next failed request *old != sav->tdb_cryptoid, then
1473 * we store cryptoid from first request into the *new variable
1474 * and crp_sid from this second session will be returned via
1475 * *old pointer, so caller can release second session.
1477 * XXXAE: check this more carefully.
1480 printf("%s: SA(%p) moves cryptoid %p -> %p\n",
1481 __func__, sav, *old, *new));
1482 KEYDBG(IPSEC_DATA, kdebug_secasv(sav));
1484 if (sav->tdb_cryptoid != *old) {
1485 /* cryptoid was already updated */
1487 *new = sav->tdb_cryptoid;
1489 SECASVAR_UNLOCK(sav);
1492 sav->tdb_cryptoid = *new;
1493 SECASVAR_UNLOCK(sav);
1498 ipsec_initialized(void)
1501 return (V_def_policy != NULL);
1505 def_policy_init(const void *unused __unused)
1508 V_def_policy = key_newsp();
1509 if (V_def_policy != NULL) {
1510 V_def_policy->policy = IPSEC_POLICY_NONE;
1511 /* Force INPCB SP cache invalidation */
1514 printf("%s: failed to initialize default policy\n", __func__);
1518 def_policy_uninit(const void *unused __unused)
1521 if (V_def_policy != NULL) {
1522 key_freesp(&V_def_policy);
1527 VNET_SYSINIT(def_policy_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST,
1528 def_policy_init, NULL);
1529 VNET_SYSUNINIT(def_policy_uninit, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST,
1530 def_policy_uninit, NULL);