2 * Copyright (c) 2016 Andrey V. Elsukov <ae@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "opt_inet6.h"
29 #include "opt_ipsec.h"
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/malloc.h>
40 #include <sys/module.h>
42 #include <sys/rmlock.h>
43 #include <sys/socket.h>
44 #include <sys/sockopt.h>
45 #include <sys/syslog.h>
48 #include <netinet/in.h>
49 #include <netinet/in_pcb.h>
51 #include <netipsec/ipsec.h>
52 #include <netipsec/ipsec6.h>
53 #include <netipsec/key.h>
54 #include <netipsec/key_debug.h>
56 #include <netipsec/ipsec_support.h>
59 static const struct ipsec_methods ipv4_methods = {
60 .input = ipsec4_input,
61 .forward = ipsec4_forward,
62 .output = ipsec4_output,
63 .pcbctl = ipsec4_pcbctl,
64 .capability = ipsec4_capability,
65 .check_policy = ipsec4_in_reject,
66 .ctlinput = ipsec4_ctlinput,
67 .hdrsize = ipsec_hdrsiz_inpcb,
68 .udp_input = udp_ipsec_input,
69 .udp_pcbctl = udp_ipsec_pcbctl,
72 static const struct ipsec_support ipv4_ipsec = {
73 .enabled = IPSEC_MODULE_ENABLED,
74 .methods = &ipv4_methods
76 const struct ipsec_support * const ipv4_ipsec_support = &ipv4_ipsec;
77 #endif /* !KLD_MODULE */
81 static const struct ipsec_methods ipv6_methods = {
82 .input = ipsec6_input,
83 .forward = ipsec6_forward,
84 .output = ipsec6_output,
85 .pcbctl = ipsec6_pcbctl,
86 .capability = ipsec6_capability,
87 .check_policy = ipsec6_in_reject,
88 .ctlinput = ipsec6_ctlinput,
89 .hdrsize = ipsec_hdrsiz_inpcb,
92 static const struct ipsec_support ipv6_ipsec = {
93 .enabled = IPSEC_MODULE_ENABLED,
94 .methods = &ipv6_methods
96 const struct ipsec_support * const ipv6_ipsec_support = &ipv6_ipsec;
97 #endif /* !KLD_MODULE */
101 * Always register ipsec module.
102 * Even when IPsec is build in the kernel, we need to have
103 * module registered. This will prevent to load ipsec.ko.
106 ipsec_modevent(module_t mod, int type, void *data)
111 /* All xforms are registered via SYSINIT */
112 if (!ipsec_initialized())
116 ipsec_support_enable(ipv4_ipsec_support, &ipv4_methods);
119 ipsec_support_enable(ipv6_ipsec_support, &ipv6_methods);
121 #endif /* KLD_MODULE */
124 /* All xforms are unregistered via SYSUNINIT */
127 ipsec_support_disable(ipv4_ipsec_support);
130 ipsec_support_disable(ipv6_ipsec_support);
132 #endif /* KLD_MODULE */
140 static moduledata_t ipsec_mod = {
146 DECLARE_MODULE(ipsec, ipsec_mod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
147 MODULE_VERSION(ipsec, 1);
149 MODULE_DEPEND(ipsec, ipsec_support, 1, 1, 1);