udp6_usrreq.c revision 1.96 1 1.96 rmind /* $NetBSD: udp6_usrreq.c,v 1.96 2014/05/20 19:04:00 rmind Exp $ */
2 1.43 itojun /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
3 1.3 thorpej
4 1.2 itojun /*
5 1.2 itojun * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 1.2 itojun * All rights reserved.
7 1.27 itojun *
8 1.2 itojun * Redistribution and use in source and binary forms, with or without
9 1.2 itojun * modification, are permitted provided that the following conditions
10 1.2 itojun * are met:
11 1.2 itojun * 1. Redistributions of source code must retain the above copyright
12 1.2 itojun * notice, this list of conditions and the following disclaimer.
13 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
14 1.2 itojun * notice, this list of conditions and the following disclaimer in the
15 1.2 itojun * documentation and/or other materials provided with the distribution.
16 1.2 itojun * 3. Neither the name of the project nor the names of its contributors
17 1.2 itojun * may be used to endorse or promote products derived from this software
18 1.2 itojun * without specific prior written permission.
19 1.27 itojun *
20 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.2 itojun * SUCH DAMAGE.
31 1.2 itojun */
32 1.2 itojun
33 1.2 itojun /*
34 1.2 itojun * Copyright (c) 1982, 1986, 1989, 1993
35 1.2 itojun * The Regents of the University of California. All rights reserved.
36 1.2 itojun *
37 1.2 itojun * Redistribution and use in source and binary forms, with or without
38 1.2 itojun * modification, are permitted provided that the following conditions
39 1.2 itojun * are met:
40 1.2 itojun * 1. Redistributions of source code must retain the above copyright
41 1.2 itojun * notice, this list of conditions and the following disclaimer.
42 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
43 1.2 itojun * notice, this list of conditions and the following disclaimer in the
44 1.2 itojun * documentation and/or other materials provided with the distribution.
45 1.56 agc * 3. Neither the name of the University nor the names of its contributors
46 1.2 itojun * may be used to endorse or promote products derived from this software
47 1.2 itojun * without specific prior written permission.
48 1.2 itojun *
49 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 1.2 itojun * SUCH DAMAGE.
60 1.2 itojun *
61 1.2 itojun * @(#)udp_var.h 8.1 (Berkeley) 6/10/93
62 1.2 itojun */
63 1.51 lukem
64 1.51 lukem #include <sys/cdefs.h>
65 1.96 rmind __KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.96 2014/05/20 19:04:00 rmind Exp $");
66 1.90 christos
67 1.90 christos #include "opt_inet.h"
68 1.2 itojun
69 1.2 itojun #include <sys/param.h>
70 1.2 itojun #include <sys/malloc.h>
71 1.2 itojun #include <sys/mbuf.h>
72 1.2 itojun #include <sys/protosw.h>
73 1.2 itojun #include <sys/socket.h>
74 1.2 itojun #include <sys/socketvar.h>
75 1.2 itojun #include <sys/errno.h>
76 1.2 itojun #include <sys/stat.h>
77 1.2 itojun #include <sys/systm.h>
78 1.2 itojun #include <sys/proc.h>
79 1.8 itojun #include <sys/syslog.h>
80 1.90 christos #include <sys/domain.h>
81 1.50 simonb #include <sys/sysctl.h>
82 1.2 itojun
83 1.2 itojun #include <net/if.h>
84 1.2 itojun #include <net/route.h>
85 1.2 itojun #include <net/if_types.h>
86 1.2 itojun
87 1.2 itojun #include <netinet/in.h>
88 1.2 itojun #include <netinet/in_var.h>
89 1.14 itojun #include <netinet/in_systm.h>
90 1.14 itojun #include <netinet/ip.h>
91 1.14 itojun #include <netinet/ip_var.h>
92 1.14 itojun #include <netinet/in_pcb.h>
93 1.14 itojun #include <netinet/udp.h>
94 1.14 itojun #include <netinet/udp_var.h>
95 1.23 itojun #include <netinet/ip6.h>
96 1.27 itojun #include <netinet6/ip6_var.h>
97 1.2 itojun #include <netinet6/in6_pcb.h>
98 1.23 itojun #include <netinet/icmp6.h>
99 1.2 itojun #include <netinet6/udp6_var.h>
100 1.82 thorpej #include <netinet6/udp6_private.h>
101 1.14 itojun #include <netinet6/ip6protosw.h>
102 1.69 yamt #include <netinet/in_offload.h>
103 1.2 itojun
104 1.2 itojun #include "faith.h"
105 1.41 itojun #if defined(NFAITH) && NFAITH > 0
106 1.41 itojun #include <net/if_faith.h>
107 1.41 itojun #endif
108 1.2 itojun
109 1.2 itojun /*
110 1.73 rpaulo * UDP protocol implementation.
111 1.2 itojun * Per RFC 768, August, 1980.
112 1.2 itojun */
113 1.2 itojun
114 1.58 itojun extern struct inpcbtable udbtable;
115 1.82 thorpej
116 1.82 thorpej percpu_t *udp6stat_percpu;
117 1.2 itojun
118 1.78 dyoung static void udp6_notify(struct in6pcb *, int);
119 1.88 pooka static void sysctl_net_inet6_udp6_setup(struct sysctllog **);
120 1.2 itojun
121 1.2 itojun void
122 1.81 matt udp6_init(void)
123 1.2 itojun {
124 1.88 pooka
125 1.88 pooka sysctl_net_inet6_udp6_setup(NULL);
126 1.92 pooka udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS);
127 1.92 pooka
128 1.92 pooka udp_init_common();
129 1.2 itojun }
130 1.2 itojun
131 1.2 itojun /*
132 1.2 itojun * Notify a udp user of an asynchronous error;
133 1.27 itojun * just wake up so that he can collect error status.
134 1.2 itojun */
135 1.2 itojun static void
136 1.76 dyoung udp6_notify(struct in6pcb *in6p, int errno)
137 1.2 itojun {
138 1.2 itojun in6p->in6p_socket->so_error = errno;
139 1.2 itojun sorwakeup(in6p->in6p_socket);
140 1.2 itojun sowwakeup(in6p->in6p_socket);
141 1.2 itojun }
142 1.2 itojun
143 1.84 ad void *
144 1.76 dyoung udp6_ctlinput(int cmd, const struct sockaddr *sa, void *d)
145 1.2 itojun {
146 1.2 itojun struct udphdr uh;
147 1.39 itojun struct ip6_hdr *ip6;
148 1.76 dyoung const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *)sa;
149 1.14 itojun struct mbuf *m;
150 1.14 itojun int off;
151 1.40 itojun void *cmdarg;
152 1.40 itojun struct ip6ctlparam *ip6cp = NULL;
153 1.40 itojun const struct sockaddr_in6 *sa6_src = NULL;
154 1.76 dyoung void (*notify)(struct in6pcb *, int) = udp6_notify;
155 1.40 itojun struct udp_portonly {
156 1.40 itojun u_int16_t uh_sport;
157 1.40 itojun u_int16_t uh_dport;
158 1.40 itojun } *uhp;
159 1.2 itojun
160 1.10 itojun if (sa->sa_family != AF_INET6 ||
161 1.10 itojun sa->sa_len != sizeof(struct sockaddr_in6))
162 1.84 ad return NULL;
163 1.14 itojun
164 1.25 itojun if ((unsigned)cmd >= PRC_NCMDS)
165 1.84 ad return NULL;
166 1.25 itojun if (PRC_IS_REDIRECT(cmd))
167 1.25 itojun notify = in6_rtchange, d = NULL;
168 1.25 itojun else if (cmd == PRC_HOSTDEAD)
169 1.25 itojun d = NULL;
170 1.47 itojun else if (cmd == PRC_MSGSIZE) {
171 1.47 itojun /* special code is present, see below */
172 1.47 itojun notify = in6_rtchange;
173 1.47 itojun }
174 1.25 itojun else if (inet6ctlerrmap[cmd] == 0)
175 1.84 ad return NULL;
176 1.7 itojun
177 1.14 itojun /* if the parameter is from icmp6, decode it. */
178 1.14 itojun if (d != NULL) {
179 1.40 itojun ip6cp = (struct ip6ctlparam *)d;
180 1.14 itojun m = ip6cp->ip6c_m;
181 1.14 itojun ip6 = ip6cp->ip6c_ip6;
182 1.14 itojun off = ip6cp->ip6c_off;
183 1.40 itojun cmdarg = ip6cp->ip6c_cmdarg;
184 1.40 itojun sa6_src = ip6cp->ip6c_src;
185 1.14 itojun } else {
186 1.14 itojun m = NULL;
187 1.14 itojun ip6 = NULL;
188 1.40 itojun cmdarg = NULL;
189 1.40 itojun sa6_src = &sa6_any;
190 1.60 christos off = 0;
191 1.14 itojun }
192 1.14 itojun
193 1.2 itojun if (ip6) {
194 1.2 itojun /*
195 1.2 itojun * XXX: We assume that when IPV6 is non NULL,
196 1.2 itojun * M and OFF are valid.
197 1.2 itojun */
198 1.33 itojun
199 1.33 itojun /* check if we can safely examine src and dst ports */
200 1.42 itojun if (m->m_pkthdr.len < off + sizeof(*uhp)) {
201 1.42 itojun if (cmd == PRC_MSGSIZE)
202 1.42 itojun icmp6_mtudisc_update((struct ip6ctlparam *)d, 0);
203 1.84 ad return NULL;
204 1.42 itojun }
205 1.7 itojun
206 1.87 cegger memset(&uh, 0, sizeof(uh));
207 1.77 christos m_copydata(m, off, sizeof(*uhp), (void *)&uh);
208 1.34 itojun
209 1.34 itojun if (cmd == PRC_MSGSIZE) {
210 1.36 itojun int valid = 0;
211 1.40 itojun
212 1.34 itojun /*
213 1.34 itojun * Check to see if we have a valid UDP socket
214 1.34 itojun * corresponding to the address in the ICMPv6 message
215 1.34 itojun * payload.
216 1.34 itojun */
217 1.58 itojun if (in6_pcblookup_connect(&udbtable, &sa6->sin6_addr,
218 1.68 christos uh.uh_dport, (const struct in6_addr *)&sa6_src->sin6_addr,
219 1.89 dyoung uh.uh_sport, 0, 0))
220 1.36 itojun valid++;
221 1.34 itojun #if 0
222 1.34 itojun /*
223 1.34 itojun * As the use of sendto(2) is fairly popular,
224 1.34 itojun * we may want to allow non-connected pcb too.
225 1.34 itojun * But it could be too weak against attacks...
226 1.34 itojun * We should at least check if the local address (= s)
227 1.34 itojun * is really ours.
228 1.34 itojun */
229 1.58 itojun else if (in6_pcblookup_bind(&udbtable, &sa6->sin6_addr,
230 1.58 itojun uh.uh_dport, 0))
231 1.36 itojun valid++;
232 1.34 itojun #endif
233 1.34 itojun
234 1.34 itojun /*
235 1.40 itojun * Depending on the value of "valid" and routing table
236 1.40 itojun * size (mtudisc_{hi,lo}wat), we will:
237 1.46 itojun * - recalculate the new MTU and create the
238 1.40 itojun * corresponding routing entry, or
239 1.40 itojun * - ignore the MTU change notification.
240 1.34 itojun */
241 1.36 itojun icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
242 1.34 itojun
243 1.40 itojun /*
244 1.74 rpaulo * regardless of if we called
245 1.74 rpaulo * icmp6_mtudisc_update(), we need to call
246 1.74 rpaulo * in6_pcbnotify(), to notify path MTU change
247 1.74 rpaulo * to the userland (RFC3542), because some
248 1.74 rpaulo * unconnected sockets may share the same
249 1.40 itojun * destination and want to know the path MTU.
250 1.40 itojun */
251 1.34 itojun }
252 1.34 itojun
253 1.58 itojun (void) in6_pcbnotify(&udbtable, sa, uh.uh_dport,
254 1.68 christos (const struct sockaddr *)sa6_src, uh.uh_sport, cmd, cmdarg,
255 1.40 itojun notify);
256 1.2 itojun } else {
257 1.58 itojun (void) in6_pcbnotify(&udbtable, sa, 0,
258 1.68 christos (const struct sockaddr *)sa6_src, 0, cmd, cmdarg, notify);
259 1.2 itojun }
260 1.84 ad return NULL;
261 1.2 itojun }
262 1.2 itojun
263 1.90 christos int
264 1.90 christos udp6_ctloutput(int op, struct socket *so, struct sockopt *sopt)
265 1.90 christos {
266 1.90 christos int s;
267 1.90 christos int error = 0;
268 1.90 christos int family;
269 1.90 christos
270 1.90 christos family = so->so_proto->pr_domain->dom_family;
271 1.90 christos
272 1.90 christos s = splsoftnet();
273 1.90 christos switch (family) {
274 1.90 christos #ifdef INET
275 1.90 christos case PF_INET:
276 1.90 christos if (sopt->sopt_level != IPPROTO_UDP) {
277 1.90 christos error = ip_ctloutput(op, so, sopt);
278 1.90 christos goto end;
279 1.90 christos }
280 1.90 christos break;
281 1.90 christos #endif
282 1.90 christos #ifdef INET6
283 1.90 christos case PF_INET6:
284 1.90 christos if (sopt->sopt_level != IPPROTO_UDP) {
285 1.90 christos error = ip6_ctloutput(op, so, sopt);
286 1.90 christos goto end;
287 1.90 christos }
288 1.90 christos break;
289 1.90 christos #endif
290 1.90 christos default:
291 1.90 christos error = EAFNOSUPPORT;
292 1.90 christos goto end;
293 1.90 christos }
294 1.91 christos error = EINVAL;
295 1.90 christos
296 1.90 christos end:
297 1.90 christos splx(s);
298 1.90 christos return error;
299 1.90 christos }
300 1.90 christos
301 1.90 christos
302 1.2 itojun extern int udp6_sendspace;
303 1.2 itojun extern int udp6_recvspace;
304 1.2 itojun
305 1.95 rmind static int
306 1.95 rmind udp6_attach(struct socket *so, int proto)
307 1.95 rmind {
308 1.95 rmind struct in6pcb *in6p;
309 1.95 rmind int s, error;
310 1.95 rmind
311 1.95 rmind KASSERT(sotoin6pcb(so) == NULL);
312 1.95 rmind sosetlock(so);
313 1.95 rmind
314 1.95 rmind /*
315 1.95 rmind * MAPPED_ADDR implementation spec:
316 1.95 rmind * Always attach for IPv6, and only when necessary for IPv4.
317 1.95 rmind */
318 1.95 rmind s = splsoftnet();
319 1.95 rmind error = in6_pcballoc(so, &udbtable);
320 1.95 rmind splx(s);
321 1.95 rmind if (error) {
322 1.95 rmind return error;
323 1.95 rmind }
324 1.95 rmind error = soreserve(so, udp6_sendspace, udp6_recvspace);
325 1.95 rmind if (error) {
326 1.95 rmind return error;
327 1.95 rmind }
328 1.95 rmind in6p = sotoin6pcb(so);
329 1.95 rmind in6p->in6p_cksum = -1; /* just to be sure */
330 1.95 rmind
331 1.95 rmind KASSERT(solocked(so));
332 1.95 rmind return 0;
333 1.95 rmind }
334 1.95 rmind
335 1.95 rmind static void
336 1.95 rmind udp6_detach(struct socket *so)
337 1.95 rmind {
338 1.95 rmind struct in6pcb *in6p = sotoin6pcb(so);
339 1.95 rmind int s;
340 1.95 rmind
341 1.95 rmind KASSERT(solocked(so));
342 1.95 rmind KASSERT(in6p != NULL);
343 1.95 rmind
344 1.95 rmind s = splsoftnet();
345 1.95 rmind in6_pcbdetach(in6p);
346 1.95 rmind splx(s);
347 1.95 rmind }
348 1.95 rmind
349 1.2 itojun int
350 1.76 dyoung udp6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr6,
351 1.76 dyoung struct mbuf *control, struct lwp *l)
352 1.2 itojun {
353 1.95 rmind struct in6pcb *in6p = sotoin6pcb(so);
354 1.95 rmind int s, error = 0;
355 1.95 rmind
356 1.95 rmind KASSERT(req != PRU_ATTACH);
357 1.95 rmind KASSERT(req != PRU_DETACH);
358 1.2 itojun
359 1.27 itojun /*
360 1.2 itojun * MAPPED_ADDR implementation info:
361 1.2 itojun * Mapped addr support for PRU_CONTROL is not necessary.
362 1.2 itojun * Because typical user of PRU_CONTROL is such as ifconfig,
363 1.2 itojun * and they don't associate any addr to their socket. Then
364 1.2 itojun * socket family is only hint about the PRU_CONTROL'ed address
365 1.2 itojun * family, especially when getting addrs from kernel.
366 1.2 itojun * So AF_INET socket need to be used to control AF_INET addrs,
367 1.2 itojun * and AF_INET6 socket for AF_INET6 addrs.
368 1.2 itojun */
369 1.95 rmind if (req == PRU_CONTROL) {
370 1.80 dyoung return in6_control(so, (u_long)m, (void *)addr6,
371 1.80 dyoung (struct ifnet *)control, l);
372 1.95 rmind }
373 1.21 thorpej if (req == PRU_PURGEIF) {
374 1.84 ad mutex_enter(softnet_lock);
375 1.58 itojun in6_pcbpurgeif0(&udbtable, (struct ifnet *)control);
376 1.21 thorpej in6_purgeif((struct ifnet *)control);
377 1.58 itojun in6_pcbpurgeif(&udbtable, (struct ifnet *)control);
378 1.84 ad mutex_exit(softnet_lock);
379 1.80 dyoung return 0;
380 1.20 thorpej }
381 1.95 rmind if (in6p == NULL) {
382 1.2 itojun error = EINVAL;
383 1.2 itojun goto release;
384 1.2 itojun }
385 1.2 itojun
386 1.2 itojun switch (req) {
387 1.2 itojun
388 1.2 itojun case PRU_BIND:
389 1.4 itojun s = splsoftnet();
390 1.75 ad error = in6_pcbbind(in6p, addr6, l);
391 1.2 itojun splx(s);
392 1.2 itojun break;
393 1.2 itojun
394 1.2 itojun case PRU_CONNECT:
395 1.14 itojun if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
396 1.2 itojun error = EISCONN;
397 1.2 itojun break;
398 1.2 itojun }
399 1.4 itojun s = splsoftnet();
400 1.75 ad error = in6_pcbconnect(in6p, addr6, l);
401 1.2 itojun splx(s);
402 1.2 itojun if (error == 0)
403 1.2 itojun soisconnected(so);
404 1.2 itojun break;
405 1.2 itojun
406 1.2 itojun case PRU_DISCONNECT:
407 1.2 itojun if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
408 1.2 itojun error = ENOTCONN;
409 1.2 itojun break;
410 1.2 itojun }
411 1.4 itojun s = splsoftnet();
412 1.2 itojun in6_pcbdisconnect(in6p);
413 1.87 cegger memset((void *)&in6p->in6p_laddr, 0, sizeof(in6p->in6p_laddr));
414 1.2 itojun splx(s);
415 1.2 itojun so->so_state &= ~SS_ISCONNECTED; /* XXX */
416 1.58 itojun in6_pcbstate(in6p, IN6P_BOUND); /* XXX */
417 1.2 itojun break;
418 1.2 itojun
419 1.2 itojun case PRU_SHUTDOWN:
420 1.2 itojun socantsendmore(so);
421 1.2 itojun break;
422 1.2 itojun
423 1.2 itojun case PRU_SEND:
424 1.79 dyoung s = splsoftnet();
425 1.79 dyoung error = udp6_output(in6p, m, addr6, control, l);
426 1.79 dyoung splx(s);
427 1.79 dyoung return error;
428 1.2 itojun
429 1.2 itojun case PRU_ABORT:
430 1.2 itojun soisdisconnected(so);
431 1.58 itojun in6_pcbdetach(in6p);
432 1.2 itojun break;
433 1.2 itojun
434 1.2 itojun case PRU_SOCKADDR:
435 1.2 itojun in6_setsockaddr(in6p, addr6);
436 1.2 itojun break;
437 1.2 itojun
438 1.2 itojun case PRU_PEERADDR:
439 1.2 itojun in6_setpeeraddr(in6p, addr6);
440 1.2 itojun break;
441 1.2 itojun
442 1.2 itojun case PRU_SENSE:
443 1.2 itojun /*
444 1.2 itojun * stat: don't bother with a blocksize
445 1.2 itojun */
446 1.80 dyoung return 0;
447 1.2 itojun
448 1.80 dyoung case PRU_LISTEN:
449 1.80 dyoung case PRU_CONNECT2:
450 1.80 dyoung case PRU_ACCEPT:
451 1.2 itojun case PRU_SENDOOB:
452 1.2 itojun case PRU_FASTTIMO:
453 1.2 itojun case PRU_SLOWTIMO:
454 1.2 itojun case PRU_PROTORCV:
455 1.2 itojun case PRU_PROTOSEND:
456 1.2 itojun error = EOPNOTSUPP;
457 1.2 itojun break;
458 1.2 itojun
459 1.2 itojun case PRU_RCVD:
460 1.2 itojun case PRU_RCVOOB:
461 1.80 dyoung return EOPNOTSUPP; /* do not free mbuf's */
462 1.2 itojun
463 1.2 itojun default:
464 1.2 itojun panic("udp6_usrreq");
465 1.2 itojun }
466 1.2 itojun
467 1.2 itojun release:
468 1.80 dyoung if (control != NULL)
469 1.2 itojun m_freem(control);
470 1.80 dyoung if (m != NULL)
471 1.2 itojun m_freem(m);
472 1.80 dyoung return error;
473 1.2 itojun }
474 1.2 itojun
475 1.82 thorpej static int
476 1.82 thorpej sysctl_net_inet6_udp6_stats(SYSCTLFN_ARGS)
477 1.82 thorpej {
478 1.82 thorpej
479 1.86 thorpej return (NETSTAT_SYSCTL(udp6stat_percpu, UDP6_NSTATS));
480 1.82 thorpej }
481 1.82 thorpej
482 1.88 pooka static void
483 1.88 pooka sysctl_net_inet6_udp6_setup(struct sysctllog **clog)
484 1.2 itojun {
485 1.93 pooka
486 1.62 atatat sysctl_createv(clog, 0, NULL, NULL,
487 1.62 atatat CTLFLAG_PERMANENT,
488 1.61 atatat CTLTYPE_NODE, "inet6", NULL,
489 1.61 atatat NULL, 0, NULL, 0,
490 1.61 atatat CTL_NET, PF_INET6, CTL_EOL);
491 1.62 atatat sysctl_createv(clog, 0, NULL, NULL,
492 1.62 atatat CTLFLAG_PERMANENT,
493 1.63 atatat CTLTYPE_NODE, "udp6",
494 1.63 atatat SYSCTL_DESCR("UDPv6 related settings"),
495 1.61 atatat NULL, 0, NULL, 0,
496 1.61 atatat CTL_NET, PF_INET6, IPPROTO_UDP, CTL_EOL);
497 1.61 atatat
498 1.62 atatat sysctl_createv(clog, 0, NULL, NULL,
499 1.62 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
500 1.63 atatat CTLTYPE_INT, "sendspace",
501 1.63 atatat SYSCTL_DESCR("Default UDP send buffer size"),
502 1.61 atatat NULL, 0, &udp6_sendspace, 0,
503 1.61 atatat CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_SENDSPACE,
504 1.61 atatat CTL_EOL);
505 1.62 atatat sysctl_createv(clog, 0, NULL, NULL,
506 1.62 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
507 1.63 atatat CTLTYPE_INT, "recvspace",
508 1.63 atatat SYSCTL_DESCR("Default UDP receive buffer size"),
509 1.61 atatat NULL, 0, &udp6_recvspace, 0,
510 1.61 atatat CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_RECVSPACE,
511 1.61 atatat CTL_EOL);
512 1.64 thorpej sysctl_createv(clog, 0, NULL, NULL,
513 1.64 thorpej CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
514 1.64 thorpej CTLTYPE_INT, "do_loopback_cksum",
515 1.64 thorpej SYSCTL_DESCR("Perform UDP checksum on loopback"),
516 1.64 thorpej NULL, 0, &udp_do_loopback_cksum, 0,
517 1.64 thorpej CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_LOOPBACKCKSUM,
518 1.64 thorpej CTL_EOL);
519 1.65 atatat sysctl_createv(clog, 0, NULL, NULL,
520 1.65 atatat CTLFLAG_PERMANENT,
521 1.67 atatat CTLTYPE_STRUCT, "pcblist",
522 1.65 atatat SYSCTL_DESCR("UDP protocol control block list"),
523 1.65 atatat sysctl_inpcblist, 0, &udbtable, 0,
524 1.65 atatat CTL_NET, PF_INET6, IPPROTO_UDP, CTL_CREATE,
525 1.65 atatat CTL_EOL);
526 1.70 rpaulo sysctl_createv(clog, 0, NULL, NULL,
527 1.70 rpaulo CTLFLAG_PERMANENT,
528 1.70 rpaulo CTLTYPE_STRUCT, "stats",
529 1.70 rpaulo SYSCTL_DESCR("UDPv6 statistics"),
530 1.82 thorpej sysctl_net_inet6_udp6_stats, 0, NULL, 0,
531 1.70 rpaulo CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_STATS,
532 1.70 rpaulo CTL_EOL);
533 1.2 itojun }
534 1.82 thorpej
535 1.82 thorpej void
536 1.82 thorpej udp6_statinc(u_int stat)
537 1.82 thorpej {
538 1.82 thorpej
539 1.82 thorpej KASSERT(stat < UDP6_NSTATS);
540 1.82 thorpej UDP6_STATINC(stat);
541 1.82 thorpej }
542 1.94 rmind
543 1.96 rmind PR_WRAP_USRREQS(udp6)
544 1.96 rmind #define udp6_attach udp6_attach_wrapper
545 1.96 rmind #define udp6_detach udp6_detach_wrapper
546 1.94 rmind #define udp6_usrreq udp6_usrreq_wrapper
547 1.94 rmind
548 1.94 rmind const struct pr_usrreqs udp6_usrreqs = {
549 1.95 rmind .pr_attach = udp6_attach,
550 1.95 rmind .pr_detach = udp6_detach,
551 1.94 rmind .pr_generic = udp6_usrreq,
552 1.94 rmind };
553