Deleted Added
full compact
send.c (254523) send.c (254889)
1/*-
2 * Copyright (c) 2009-2010 Ana Kukec <anchie@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009-2010 Ana Kukec <anchie@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/netinet6/send.c 254523 2013-08-19 13:27:32Z andre $");
28__FBSDID("$FreeBSD: head/sys/netinet6/send.c 254889 2013-08-25 21:54:41Z markj $");
29
29
30#include "opt_kdtrace.h"
31
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/mbuf.h>
33#include <sys/module.h>
34#include <sys/priv.h>
35#include <sys/protosw.h>
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/mbuf.h>
35#include <sys/module.h>
36#include <sys/priv.h>
37#include <sys/protosw.h>
38#include <sys/sdt.h>
36#include <sys/systm.h>
37#include <sys/socket.h>
38#include <sys/sockstate.h>
39#include <sys/sockbuf.h>
40#include <sys/socketvar.h>
41#include <sys/types.h>
42
43#include <net/route.h>
44#include <net/if.h>
45#include <net/if_var.h>
46#include <net/vnet.h>
47
48#include <netinet/in.h>
39#include <sys/systm.h>
40#include <sys/socket.h>
41#include <sys/sockstate.h>
42#include <sys/sockbuf.h>
43#include <sys/socketvar.h>
44#include <sys/types.h>
45
46#include <net/route.h>
47#include <net/if.h>
48#include <net/if_var.h>
49#include <net/vnet.h>
50
51#include <netinet/in.h>
52#include <netinet/in_kdtrace.h>
49#include <netinet/ip_var.h>
50#include <netinet/ip6.h>
51#include <netinet/icmp6.h>
52
53#include <netinet6/in6_var.h>
54#include <netinet6/nd6.h>
55#include <netinet6/scope6_var.h>
56#include <netinet6/send.h>
57
58static MALLOC_DEFINE(M_SEND, "send", "Secure Neighbour Discovery");
59
60/*
61 * The socket used to communicate with the SeND daemon.
62 */
63static VNET_DEFINE(struct socket *, send_so);
64#define V_send_so VNET(send_so)
65
66u_long send_sendspace = 8 * (1024 + sizeof(struct sockaddr_send));
67u_long send_recvspace = 9216;
68
69struct mtx send_mtx;
70#define SEND_LOCK_INIT() mtx_init(&send_mtx, "send_mtx", NULL, MTX_DEF)
71#define SEND_LOCK() mtx_lock(&send_mtx)
72#define SEND_UNLOCK() mtx_unlock(&send_mtx)
73#define SEND_LOCK_DESTROY() mtx_destroy(&send_mtx)
74
75static int
76send_attach(struct socket *so, int proto, struct thread *td)
77{
78 int error;
79
80 SEND_LOCK();
81 if (V_send_so != NULL) {
82 SEND_UNLOCK();
83 return (EEXIST);
84 }
85
86 error = priv_check(td, PRIV_NETINET_RAW);
87 if (error) {
88 SEND_UNLOCK();
89 return(error);
90 }
91
92 if (proto != IPPROTO_SEND) {
93 SEND_UNLOCK();
94 return (EPROTONOSUPPORT);
95 }
96 error = soreserve(so, send_sendspace, send_recvspace);
97 if (error) {
98 SEND_UNLOCK();
99 return(error);
100 }
101
102 V_send_so = so;
103 SEND_UNLOCK();
104
105 return (0);
106}
107
108static int
109send_output(struct mbuf *m, struct ifnet *ifp, int direction)
110{
111 struct ip6_hdr *ip6;
112 struct sockaddr_in6 dst;
113 struct icmp6_hdr *icmp6;
114 int icmp6len;
115
116 /*
117 * Receive incoming (SeND-protected) or outgoing traffic
118 * (SeND-validated) from the SeND user space application.
119 */
120
121 switch (direction) {
122 case SND_IN:
123 if (m->m_len < (sizeof(struct ip6_hdr) +
124 sizeof(struct icmp6_hdr))) {
125 m = m_pullup(m, sizeof(struct ip6_hdr) +
126 sizeof(struct icmp6_hdr));
127 if (!m)
128 return (ENOBUFS);
129 }
130
131 /* Before passing off the mbuf record the proper interface. */
132 m->m_pkthdr.rcvif = ifp;
133
134 if (m->m_flags & M_PKTHDR)
135 icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);
136 else
137 panic("Doh! not the first mbuf.");
138
139 ip6 = mtod(m, struct ip6_hdr *);
140 icmp6 = (struct icmp6_hdr *)(ip6 + 1);
141
142 /*
143 * Output the packet as icmp6.c:icpm6_input() would do.
144 * The mbuf is always consumed, so we do not have to
145 * care about that.
146 */
147 switch (icmp6->icmp6_type) {
148 case ND_NEIGHBOR_SOLICIT:
149 nd6_ns_input(m, sizeof(struct ip6_hdr), icmp6len);
150 break;
151 case ND_NEIGHBOR_ADVERT:
152 nd6_na_input(m, sizeof(struct ip6_hdr), icmp6len);
153 break;
154 case ND_REDIRECT:
155 icmp6_redirect_input(m, sizeof(struct ip6_hdr));
156 break;
157 case ND_ROUTER_SOLICIT:
158 nd6_rs_input(m, sizeof(struct ip6_hdr), icmp6len);
159 break;
160 case ND_ROUTER_ADVERT:
161 nd6_ra_input(m, sizeof(struct ip6_hdr), icmp6len);
162 break;
163 default:
164 return (ENOSYS);
165 }
166 return (0);
167
168 case SND_OUT:
169 if (m->m_len < sizeof(struct ip6_hdr)) {
170 m = m_pullup(m, sizeof(struct ip6_hdr));
171 if (!m)
172 return (ENOBUFS);
173 }
174 ip6 = mtod(m, struct ip6_hdr *);
175 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst))
176 m->m_flags |= M_MCAST;
177
178 bzero(&dst, sizeof(dst));
179 dst.sin6_family = AF_INET6;
180 dst.sin6_len = sizeof(dst);
181 dst.sin6_addr = ip6->ip6_dst;
182
183 m_clrprotoflags(m); /* Avoid confusing lower layers. */
184
53#include <netinet/ip_var.h>
54#include <netinet/ip6.h>
55#include <netinet/icmp6.h>
56
57#include <netinet6/in6_var.h>
58#include <netinet6/nd6.h>
59#include <netinet6/scope6_var.h>
60#include <netinet6/send.h>
61
62static MALLOC_DEFINE(M_SEND, "send", "Secure Neighbour Discovery");
63
64/*
65 * The socket used to communicate with the SeND daemon.
66 */
67static VNET_DEFINE(struct socket *, send_so);
68#define V_send_so VNET(send_so)
69
70u_long send_sendspace = 8 * (1024 + sizeof(struct sockaddr_send));
71u_long send_recvspace = 9216;
72
73struct mtx send_mtx;
74#define SEND_LOCK_INIT() mtx_init(&send_mtx, "send_mtx", NULL, MTX_DEF)
75#define SEND_LOCK() mtx_lock(&send_mtx)
76#define SEND_UNLOCK() mtx_unlock(&send_mtx)
77#define SEND_LOCK_DESTROY() mtx_destroy(&send_mtx)
78
79static int
80send_attach(struct socket *so, int proto, struct thread *td)
81{
82 int error;
83
84 SEND_LOCK();
85 if (V_send_so != NULL) {
86 SEND_UNLOCK();
87 return (EEXIST);
88 }
89
90 error = priv_check(td, PRIV_NETINET_RAW);
91 if (error) {
92 SEND_UNLOCK();
93 return(error);
94 }
95
96 if (proto != IPPROTO_SEND) {
97 SEND_UNLOCK();
98 return (EPROTONOSUPPORT);
99 }
100 error = soreserve(so, send_sendspace, send_recvspace);
101 if (error) {
102 SEND_UNLOCK();
103 return(error);
104 }
105
106 V_send_so = so;
107 SEND_UNLOCK();
108
109 return (0);
110}
111
112static int
113send_output(struct mbuf *m, struct ifnet *ifp, int direction)
114{
115 struct ip6_hdr *ip6;
116 struct sockaddr_in6 dst;
117 struct icmp6_hdr *icmp6;
118 int icmp6len;
119
120 /*
121 * Receive incoming (SeND-protected) or outgoing traffic
122 * (SeND-validated) from the SeND user space application.
123 */
124
125 switch (direction) {
126 case SND_IN:
127 if (m->m_len < (sizeof(struct ip6_hdr) +
128 sizeof(struct icmp6_hdr))) {
129 m = m_pullup(m, sizeof(struct ip6_hdr) +
130 sizeof(struct icmp6_hdr));
131 if (!m)
132 return (ENOBUFS);
133 }
134
135 /* Before passing off the mbuf record the proper interface. */
136 m->m_pkthdr.rcvif = ifp;
137
138 if (m->m_flags & M_PKTHDR)
139 icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);
140 else
141 panic("Doh! not the first mbuf.");
142
143 ip6 = mtod(m, struct ip6_hdr *);
144 icmp6 = (struct icmp6_hdr *)(ip6 + 1);
145
146 /*
147 * Output the packet as icmp6.c:icpm6_input() would do.
148 * The mbuf is always consumed, so we do not have to
149 * care about that.
150 */
151 switch (icmp6->icmp6_type) {
152 case ND_NEIGHBOR_SOLICIT:
153 nd6_ns_input(m, sizeof(struct ip6_hdr), icmp6len);
154 break;
155 case ND_NEIGHBOR_ADVERT:
156 nd6_na_input(m, sizeof(struct ip6_hdr), icmp6len);
157 break;
158 case ND_REDIRECT:
159 icmp6_redirect_input(m, sizeof(struct ip6_hdr));
160 break;
161 case ND_ROUTER_SOLICIT:
162 nd6_rs_input(m, sizeof(struct ip6_hdr), icmp6len);
163 break;
164 case ND_ROUTER_ADVERT:
165 nd6_ra_input(m, sizeof(struct ip6_hdr), icmp6len);
166 break;
167 default:
168 return (ENOSYS);
169 }
170 return (0);
171
172 case SND_OUT:
173 if (m->m_len < sizeof(struct ip6_hdr)) {
174 m = m_pullup(m, sizeof(struct ip6_hdr));
175 if (!m)
176 return (ENOBUFS);
177 }
178 ip6 = mtod(m, struct ip6_hdr *);
179 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst))
180 m->m_flags |= M_MCAST;
181
182 bzero(&dst, sizeof(dst));
183 dst.sin6_family = AF_INET6;
184 dst.sin6_len = sizeof(dst);
185 dst.sin6_addr = ip6->ip6_dst;
186
187 m_clrprotoflags(m); /* Avoid confusing lower layers. */
188
189 IP_PROBE(send, NULL, NULL, ip6, ifp, NULL, ip6);
190
185 /*
186 * Output the packet as nd6.c:nd6_output_lle() would do.
187 * The mbuf is always consumed, so we do not have to care
188 * about that.
189 * XXX-BZ as we added data, what about fragmenting,
190 * if now needed?
191 */
192 int error;
193 error = ((*ifp->if_output)(ifp, m, (struct sockaddr *)&dst,
194 NULL));
195 if (error)
196 error = ENOENT;
197 return (error);
198
199 default:
200 panic("%s: direction %d neither SND_IN nor SND_OUT.",
201 __func__, direction);
202 }
203}
204
205/*
206 * Receive a SeND message from user space to be either send out by the kernel
207 * or, with SeND ICMPv6 options removed, to be further processed by the icmp6
208 * input path.
209 */
210static int
211send_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
212 struct mbuf *control, struct thread *td)
213{
214 struct sockaddr_send *sendsrc;
215 struct ifnet *ifp;
216 int error;
217
218 KASSERT(V_send_so == so, ("%s: socket %p not send socket %p",
219 __func__, so, V_send_so));
220
221 sendsrc = (struct sockaddr_send *)nam;
222 ifp = ifnet_byindex_ref(sendsrc->send_ifidx);
223 if (ifp == NULL) {
224 error = ENETUNREACH;
225 goto err;
226 }
227
228 error = send_output(m, ifp, sendsrc->send_direction);
229 if_rele(ifp);
230 m = NULL;
231
232err:
233 if (m != NULL)
234 m_freem(m);
235 return (error);
236}
237
238static void
239send_close(struct socket *so)
240{
241
242 SEND_LOCK();
243 if (V_send_so)
244 V_send_so = NULL;
245 SEND_UNLOCK();
246}
247
248/*
249 * Send a SeND message to user space, that was either received and has to be
250 * validated or was about to be send out and has to be handled by the SEND
251 * daemon adding SeND ICMPv6 options.
252 */
253static int
254send_input(struct mbuf *m, struct ifnet *ifp, int direction, int msglen __unused)
255{
256 struct ip6_hdr *ip6;
257 struct sockaddr_send sendsrc;
258
259 SEND_LOCK();
260 if (V_send_so == NULL) {
261 SEND_UNLOCK();
262 return (-1);
263 }
264
265 /*
266 * Make sure to clear any possible internally embedded scope before
267 * passing the packet to user space for SeND cryptographic signature
268 * validation to succeed.
269 */
270 ip6 = mtod(m, struct ip6_hdr *);
271 in6_clearscope(&ip6->ip6_src);
272 in6_clearscope(&ip6->ip6_dst);
273
274 bzero(&sendsrc, sizeof(sendsrc));
275 sendsrc.send_len = sizeof(sendsrc);
276 sendsrc.send_family = AF_INET6;
277 sendsrc.send_direction = direction;
278 sendsrc.send_ifidx = ifp->if_index;
279
280 /*
281 * Send incoming or outgoing traffic to user space either to be
282 * protected (outgoing) or validated (incoming) according to rfc3971.
283 */
284 SOCKBUF_LOCK(&V_send_so->so_rcv);
285 if (sbappendaddr_locked(&V_send_so->so_rcv,
286 (struct sockaddr *)&sendsrc, m, NULL) == 0) {
287 SOCKBUF_UNLOCK(&V_send_so->so_rcv);
288 /* XXX stats. */
289 m_freem(m);
290 } else {
291 sorwakeup_locked(V_send_so);
292 }
293
294 SEND_UNLOCK();
295 return (0);
296}
297
298struct pr_usrreqs send_usrreqs = {
299 .pru_attach = send_attach,
300 .pru_send = send_send,
301 .pru_detach = send_close
302};
303struct protosw send_protosw = {
304 .pr_type = SOCK_RAW,
305 .pr_flags = PR_ATOMIC|PR_ADDR,
306 .pr_protocol = IPPROTO_SEND,
307 .pr_usrreqs = &send_usrreqs
308};
309
310static int
311send_modevent(module_t mod, int type, void *unused)
312{
313#ifdef __notyet__
314 VNET_ITERATOR_DECL(vnet_iter);
315#endif
316 int error;
317
318 switch (type) {
319 case MOD_LOAD:
320 SEND_LOCK_INIT();
321
322 error = pf_proto_register(PF_INET6, &send_protosw);
323 if (error != 0) {
324 printf("%s:%d: MOD_LOAD pf_proto_register(): %d\n",
325 __func__, __LINE__, error);
326 SEND_LOCK_DESTROY();
327 break;
328 }
329 send_sendso_input_hook = send_input;
330 break;
331 case MOD_UNLOAD:
332 /* Do not allow unloading w/o locking. */
333 return (EBUSY);
334#ifdef __notyet__
335 VNET_LIST_RLOCK_NOSLEEP();
336 SEND_LOCK();
337 VNET_FOREACH(vnet_iter) {
338 CURVNET_SET(vnet_iter);
339 if (V_send_so != NULL) {
340 CURVNET_RESTORE();
341 SEND_UNLOCK();
342 VNET_LIST_RUNLOCK_NOSLEEP();
343 return (EBUSY);
344 }
345 CURVNET_RESTORE();
346 }
347 SEND_UNLOCK();
348 VNET_LIST_RUNLOCK_NOSLEEP();
349 error = pf_proto_unregister(PF_INET6, IPPROTO_SEND, SOCK_RAW);
350 if (error == 0)
351 SEND_LOCK_DESTROY();
352 send_sendso_input_hook = NULL;
353 break;
354#endif
355 default:
356 error = 0;
357 break;
358 }
359
360 return (error);
361}
362
363static moduledata_t sendmod = {
364 "send",
365 send_modevent,
366 0
367};
368
369DECLARE_MODULE(send, sendmod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
191 /*
192 * Output the packet as nd6.c:nd6_output_lle() would do.
193 * The mbuf is always consumed, so we do not have to care
194 * about that.
195 * XXX-BZ as we added data, what about fragmenting,
196 * if now needed?
197 */
198 int error;
199 error = ((*ifp->if_output)(ifp, m, (struct sockaddr *)&dst,
200 NULL));
201 if (error)
202 error = ENOENT;
203 return (error);
204
205 default:
206 panic("%s: direction %d neither SND_IN nor SND_OUT.",
207 __func__, direction);
208 }
209}
210
211/*
212 * Receive a SeND message from user space to be either send out by the kernel
213 * or, with SeND ICMPv6 options removed, to be further processed by the icmp6
214 * input path.
215 */
216static int
217send_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
218 struct mbuf *control, struct thread *td)
219{
220 struct sockaddr_send *sendsrc;
221 struct ifnet *ifp;
222 int error;
223
224 KASSERT(V_send_so == so, ("%s: socket %p not send socket %p",
225 __func__, so, V_send_so));
226
227 sendsrc = (struct sockaddr_send *)nam;
228 ifp = ifnet_byindex_ref(sendsrc->send_ifidx);
229 if (ifp == NULL) {
230 error = ENETUNREACH;
231 goto err;
232 }
233
234 error = send_output(m, ifp, sendsrc->send_direction);
235 if_rele(ifp);
236 m = NULL;
237
238err:
239 if (m != NULL)
240 m_freem(m);
241 return (error);
242}
243
244static void
245send_close(struct socket *so)
246{
247
248 SEND_LOCK();
249 if (V_send_so)
250 V_send_so = NULL;
251 SEND_UNLOCK();
252}
253
254/*
255 * Send a SeND message to user space, that was either received and has to be
256 * validated or was about to be send out and has to be handled by the SEND
257 * daemon adding SeND ICMPv6 options.
258 */
259static int
260send_input(struct mbuf *m, struct ifnet *ifp, int direction, int msglen __unused)
261{
262 struct ip6_hdr *ip6;
263 struct sockaddr_send sendsrc;
264
265 SEND_LOCK();
266 if (V_send_so == NULL) {
267 SEND_UNLOCK();
268 return (-1);
269 }
270
271 /*
272 * Make sure to clear any possible internally embedded scope before
273 * passing the packet to user space for SeND cryptographic signature
274 * validation to succeed.
275 */
276 ip6 = mtod(m, struct ip6_hdr *);
277 in6_clearscope(&ip6->ip6_src);
278 in6_clearscope(&ip6->ip6_dst);
279
280 bzero(&sendsrc, sizeof(sendsrc));
281 sendsrc.send_len = sizeof(sendsrc);
282 sendsrc.send_family = AF_INET6;
283 sendsrc.send_direction = direction;
284 sendsrc.send_ifidx = ifp->if_index;
285
286 /*
287 * Send incoming or outgoing traffic to user space either to be
288 * protected (outgoing) or validated (incoming) according to rfc3971.
289 */
290 SOCKBUF_LOCK(&V_send_so->so_rcv);
291 if (sbappendaddr_locked(&V_send_so->so_rcv,
292 (struct sockaddr *)&sendsrc, m, NULL) == 0) {
293 SOCKBUF_UNLOCK(&V_send_so->so_rcv);
294 /* XXX stats. */
295 m_freem(m);
296 } else {
297 sorwakeup_locked(V_send_so);
298 }
299
300 SEND_UNLOCK();
301 return (0);
302}
303
304struct pr_usrreqs send_usrreqs = {
305 .pru_attach = send_attach,
306 .pru_send = send_send,
307 .pru_detach = send_close
308};
309struct protosw send_protosw = {
310 .pr_type = SOCK_RAW,
311 .pr_flags = PR_ATOMIC|PR_ADDR,
312 .pr_protocol = IPPROTO_SEND,
313 .pr_usrreqs = &send_usrreqs
314};
315
316static int
317send_modevent(module_t mod, int type, void *unused)
318{
319#ifdef __notyet__
320 VNET_ITERATOR_DECL(vnet_iter);
321#endif
322 int error;
323
324 switch (type) {
325 case MOD_LOAD:
326 SEND_LOCK_INIT();
327
328 error = pf_proto_register(PF_INET6, &send_protosw);
329 if (error != 0) {
330 printf("%s:%d: MOD_LOAD pf_proto_register(): %d\n",
331 __func__, __LINE__, error);
332 SEND_LOCK_DESTROY();
333 break;
334 }
335 send_sendso_input_hook = send_input;
336 break;
337 case MOD_UNLOAD:
338 /* Do not allow unloading w/o locking. */
339 return (EBUSY);
340#ifdef __notyet__
341 VNET_LIST_RLOCK_NOSLEEP();
342 SEND_LOCK();
343 VNET_FOREACH(vnet_iter) {
344 CURVNET_SET(vnet_iter);
345 if (V_send_so != NULL) {
346 CURVNET_RESTORE();
347 SEND_UNLOCK();
348 VNET_LIST_RUNLOCK_NOSLEEP();
349 return (EBUSY);
350 }
351 CURVNET_RESTORE();
352 }
353 SEND_UNLOCK();
354 VNET_LIST_RUNLOCK_NOSLEEP();
355 error = pf_proto_unregister(PF_INET6, IPPROTO_SEND, SOCK_RAW);
356 if (error == 0)
357 SEND_LOCK_DESTROY();
358 send_sendso_input_hook = NULL;
359 break;
360#endif
361 default:
362 error = 0;
363 break;
364 }
365
366 return (error);
367}
368
369static moduledata_t sendmod = {
370 "send",
371 send_modevent,
372 0
373};
374
375DECLARE_MODULE(send, sendmod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);