udp6_usrreq.c revision 1.2.2.2 1 1.2.2.2 thorpej /*
2 1.2.2.2 thorpej * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 1.2.2.2 thorpej * All rights reserved.
4 1.2.2.2 thorpej *
5 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
6 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
7 1.2.2.2 thorpej * are met:
8 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
9 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
10 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
11 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
12 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
13 1.2.2.2 thorpej * 3. Neither the name of the project nor the names of its contributors
14 1.2.2.2 thorpej * may be used to endorse or promote products derived from this software
15 1.2.2.2 thorpej * without specific prior written permission.
16 1.2.2.2 thorpej *
17 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.2.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.2.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 1.2.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.2.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.2.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.2.2.2 thorpej * SUCH DAMAGE.
28 1.2.2.2 thorpej */
29 1.2.2.2 thorpej
30 1.2.2.2 thorpej /*
31 1.2.2.2 thorpej * Copyright (c) 1982, 1986, 1989, 1993
32 1.2.2.2 thorpej * The Regents of the University of California. All rights reserved.
33 1.2.2.2 thorpej *
34 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
35 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
36 1.2.2.2 thorpej * are met:
37 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
38 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
39 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
40 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
41 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
42 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
43 1.2.2.2 thorpej * must display the following acknowledgement:
44 1.2.2.2 thorpej * This product includes software developed by the University of
45 1.2.2.2 thorpej * California, Berkeley and its contributors.
46 1.2.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
47 1.2.2.2 thorpej * may be used to endorse or promote products derived from this software
48 1.2.2.2 thorpej * without specific prior written permission.
49 1.2.2.2 thorpej *
50 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 1.2.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 1.2.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 1.2.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 1.2.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 1.2.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 1.2.2.2 thorpej * SUCH DAMAGE.
61 1.2.2.2 thorpej *
62 1.2.2.2 thorpej * @(#)udp_var.h 8.1 (Berkeley) 6/10/93
63 1.2.2.2 thorpej */
64 1.2.2.2 thorpej
65 1.2.2.2 thorpej #include <sys/param.h>
66 1.2.2.2 thorpej #include <sys/malloc.h>
67 1.2.2.2 thorpej #include <sys/mbuf.h>
68 1.2.2.2 thorpej #include <sys/protosw.h>
69 1.2.2.2 thorpej #include <sys/socket.h>
70 1.2.2.2 thorpej #include <sys/socketvar.h>
71 1.2.2.2 thorpej #include <sys/errno.h>
72 1.2.2.2 thorpej #include <sys/stat.h>
73 1.2.2.2 thorpej #include <sys/systm.h>
74 1.2.2.2 thorpej #ifdef __NetBSD__
75 1.2.2.2 thorpej #include <sys/proc.h>
76 1.2.2.2 thorpej #endif
77 1.2.2.2 thorpej
78 1.2.2.2 thorpej #include <net/if.h>
79 1.2.2.2 thorpej #include <net/route.h>
80 1.2.2.2 thorpej #include <net/if_types.h>
81 1.2.2.2 thorpej
82 1.2.2.2 thorpej #include <netinet/in.h>
83 1.2.2.2 thorpej #include <netinet/in_var.h>
84 1.2.2.2 thorpej #include <netinet6/in6_systm.h>
85 1.2.2.2 thorpej #include <netinet6/ip6.h>
86 1.2.2.2 thorpej #include <netinet6/in6_pcb.h>
87 1.2.2.2 thorpej #include <netinet6/ip6_var.h>
88 1.2.2.2 thorpej #include <netinet6/icmp6.h>
89 1.2.2.2 thorpej #include <netinet6/udp6.h>
90 1.2.2.2 thorpej #include <netinet6/udp6_var.h>
91 1.2.2.2 thorpej
92 1.2.2.2 thorpej #ifdef IPSEC
93 1.2.2.2 thorpej #include <netinet6/ipsec.h>
94 1.2.2.2 thorpej #endif /*IPSEC*/
95 1.2.2.2 thorpej
96 1.2.2.2 thorpej #include "faith.h"
97 1.2.2.2 thorpej
98 1.2.2.2 thorpej /*
99 1.2.2.2 thorpej * UDP protocol inplementation.
100 1.2.2.2 thorpej * Per RFC 768, August, 1980.
101 1.2.2.2 thorpej */
102 1.2.2.2 thorpej
103 1.2.2.2 thorpej struct in6pcb *udp6_last_in6pcb = &udb6;
104 1.2.2.2 thorpej
105 1.2.2.2 thorpej static int in6_mcmatch __P((struct in6pcb *, struct in6_addr *, struct ifnet *));
106 1.2.2.2 thorpej static void udp6_detach __P((struct in6pcb *));
107 1.2.2.2 thorpej static void udp6_notify __P((struct in6pcb *, int));
108 1.2.2.2 thorpej
109 1.2.2.2 thorpej void
110 1.2.2.2 thorpej udp6_init()
111 1.2.2.2 thorpej {
112 1.2.2.2 thorpej udb6.in6p_next = udb6.in6p_prev = &udb6;
113 1.2.2.2 thorpej }
114 1.2.2.2 thorpej
115 1.2.2.2 thorpej static int
116 1.2.2.2 thorpej in6_mcmatch(in6p, ia6, ifp)
117 1.2.2.2 thorpej struct in6pcb *in6p;
118 1.2.2.2 thorpej register struct in6_addr *ia6;
119 1.2.2.2 thorpej struct ifnet *ifp;
120 1.2.2.2 thorpej {
121 1.2.2.2 thorpej struct ip6_moptions *im6o = in6p->in6p_moptions;
122 1.2.2.2 thorpej struct in6_multi_mship *imm;
123 1.2.2.2 thorpej
124 1.2.2.2 thorpej if (im6o == NULL)
125 1.2.2.2 thorpej return 0;
126 1.2.2.2 thorpej
127 1.2.2.2 thorpej for (imm = im6o->im6o_memberships.lh_first; imm != NULL;
128 1.2.2.2 thorpej imm = imm->i6mm_chain.le_next) {
129 1.2.2.2 thorpej if ((ifp == NULL ||
130 1.2.2.2 thorpej imm->i6mm_maddr->in6m_ifp == ifp) &&
131 1.2.2.2 thorpej IN6_ARE_ADDR_EQUAL(&imm->i6mm_maddr->in6m_addr,
132 1.2.2.2 thorpej ia6))
133 1.2.2.2 thorpej return 1;
134 1.2.2.2 thorpej }
135 1.2.2.2 thorpej return 0;
136 1.2.2.2 thorpej }
137 1.2.2.2 thorpej
138 1.2.2.2 thorpej int
139 1.2.2.2 thorpej udp6_input(mp, offp, proto)
140 1.2.2.2 thorpej struct mbuf **mp;
141 1.2.2.2 thorpej int *offp, proto;
142 1.2.2.2 thorpej {
143 1.2.2.2 thorpej struct mbuf *m = *mp;
144 1.2.2.2 thorpej register struct ip6_hdr *ip6;
145 1.2.2.2 thorpej register struct udphdr *uh;
146 1.2.2.2 thorpej register struct in6pcb *in6p;
147 1.2.2.2 thorpej struct mbuf *opts = 0;
148 1.2.2.2 thorpej int off = *offp;
149 1.2.2.2 thorpej int plen, ulen;
150 1.2.2.2 thorpej struct sockaddr_in6 udp_in6;
151 1.2.2.2 thorpej
152 1.2.2.2 thorpej #if defined(NFAITH) && 0 < NFAITH
153 1.2.2.2 thorpej if (m->m_pkthdr.rcvif) {
154 1.2.2.2 thorpej if (m->m_pkthdr.rcvif->if_type == IFT_FAITH) {
155 1.2.2.2 thorpej /* send icmp6 host unreach? */
156 1.2.2.2 thorpej m_freem(m);
157 1.2.2.2 thorpej return IPPROTO_DONE;
158 1.2.2.2 thorpej }
159 1.2.2.2 thorpej }
160 1.2.2.2 thorpej #endif
161 1.2.2.2 thorpej udp6stat.udp6s_ipackets++;
162 1.2.2.2 thorpej
163 1.2.2.2 thorpej IP6_EXTHDR_CHECK(m, off, sizeof(struct udphdr), IPPROTO_DONE);
164 1.2.2.2 thorpej
165 1.2.2.2 thorpej ip6 = mtod(m, struct ip6_hdr *);
166 1.2.2.2 thorpej plen = ntohs(ip6->ip6_plen) - off + sizeof(*ip6);
167 1.2.2.2 thorpej uh = (struct udphdr *)((caddr_t)ip6 + off);
168 1.2.2.2 thorpej ulen = ntohs((u_short)uh->uh_ulen);
169 1.2.2.2 thorpej
170 1.2.2.2 thorpej if (plen != ulen) {
171 1.2.2.2 thorpej udp6stat.udp6s_badlen++;
172 1.2.2.2 thorpej goto bad;
173 1.2.2.2 thorpej }
174 1.2.2.2 thorpej
175 1.2.2.2 thorpej /*
176 1.2.2.2 thorpej * Checksum extended UDP header and data.
177 1.2.2.2 thorpej */
178 1.2.2.2 thorpej if (uh->uh_sum == 0)
179 1.2.2.2 thorpej udp6stat.udp6s_nosum++;
180 1.2.2.2 thorpej else if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) {
181 1.2.2.2 thorpej udp6stat.udp6s_badsum++;
182 1.2.2.2 thorpej goto bad;
183 1.2.2.2 thorpej }
184 1.2.2.2 thorpej
185 1.2.2.2 thorpej if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
186 1.2.2.2 thorpej struct in6pcb *last;
187 1.2.2.2 thorpej
188 1.2.2.2 thorpej /*
189 1.2.2.2 thorpej * Deliver a multicast datagram to all sockets
190 1.2.2.2 thorpej * for which the local and remote addresses and ports match
191 1.2.2.2 thorpej * those of the incoming datagram. This allows more than
192 1.2.2.2 thorpej * one process to receive multicasts on the same port.
193 1.2.2.2 thorpej * (This really ought to be done for unicast datagrams as
194 1.2.2.2 thorpej * well, but that would cause problems with existing
195 1.2.2.2 thorpej * applications that open both address-specific sockets and
196 1.2.2.2 thorpej * a wildcard socket listening to the same port -- they would
197 1.2.2.2 thorpej * end up receiving duplicates of every unicast datagram.
198 1.2.2.2 thorpej * Those applications open the multiple sockets to overcome an
199 1.2.2.2 thorpej * inadequacy of the UDP socket interface, but for backwards
200 1.2.2.2 thorpej * compatibility we avoid the problem here rather than
201 1.2.2.2 thorpej * fixing the interface. Maybe 4.5BSD will remedy this?)
202 1.2.2.2 thorpej */
203 1.2.2.2 thorpej
204 1.2.2.2 thorpej /*
205 1.2.2.2 thorpej * In a case that laddr should be set to the link-local
206 1.2.2.2 thorpej * address (this happens in RIPng), the multicast address
207 1.2.2.2 thorpej * specified in the received packet does not match with
208 1.2.2.2 thorpej * laddr. To cure this situation, the matching is relaxed
209 1.2.2.2 thorpej * if the receiving interface is the same as one specified
210 1.2.2.2 thorpej * in the socket and if the destination multicast address
211 1.2.2.2 thorpej * matches one of the multicast groups specified in the socket.
212 1.2.2.2 thorpej */
213 1.2.2.2 thorpej
214 1.2.2.2 thorpej /*
215 1.2.2.2 thorpej * Construct sockaddr format source address.
216 1.2.2.2 thorpej */
217 1.2.2.2 thorpej bzero(&udp_in6, sizeof(udp_in6));
218 1.2.2.2 thorpej udp_in6.sin6_len = sizeof(struct sockaddr_in6);
219 1.2.2.2 thorpej udp_in6.sin6_family = AF_INET6;
220 1.2.2.2 thorpej udp_in6.sin6_port = uh->uh_sport;
221 1.2.2.2 thorpej udp_in6.sin6_addr = ip6->ip6_src;
222 1.2.2.2 thorpej if (IN6_IS_SCOPE_LINKLOCAL(&udp_in6.sin6_addr))
223 1.2.2.2 thorpej udp_in6.sin6_addr.s6_addr16[1] = 0;
224 1.2.2.2 thorpej if (m->m_pkthdr.rcvif) {
225 1.2.2.2 thorpej if (IN6_IS_SCOPE_LINKLOCAL(&udp_in6.sin6_addr)) {
226 1.2.2.2 thorpej udp_in6.sin6_scope_id =
227 1.2.2.2 thorpej m->m_pkthdr.rcvif->if_index;
228 1.2.2.2 thorpej } else
229 1.2.2.2 thorpej udp_in6.sin6_scope_id = 0;
230 1.2.2.2 thorpej } else
231 1.2.2.2 thorpej udp_in6.sin6_scope_id = 0;
232 1.2.2.2 thorpej /*
233 1.2.2.2 thorpej * KAME note: usually we drop udphdr from mbuf here.
234 1.2.2.2 thorpej * We need udphdr for IPsec processing so we do that later.
235 1.2.2.2 thorpej */
236 1.2.2.2 thorpej
237 1.2.2.2 thorpej /*
238 1.2.2.2 thorpej * Locate pcb(s) for datagram.
239 1.2.2.2 thorpej * (Algorithm copied from raw_intr().)
240 1.2.2.2 thorpej */
241 1.2.2.2 thorpej last = NULL;
242 1.2.2.2 thorpej for (in6p = udb6.in6p_next;
243 1.2.2.2 thorpej in6p != &udb6;
244 1.2.2.2 thorpej in6p = in6p->in6p_next) {
245 1.2.2.2 thorpej if (in6p->in6p_lport != uh->uh_dport)
246 1.2.2.2 thorpej continue;
247 1.2.2.2 thorpej if (!IN6_IS_ADDR_ANY(&in6p->in6p_laddr)) {
248 1.2.2.2 thorpej if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr,
249 1.2.2.2 thorpej &ip6->ip6_dst) &&
250 1.2.2.2 thorpej !in6_mcmatch(in6p, &ip6->ip6_dst,
251 1.2.2.2 thorpej m->m_pkthdr.rcvif))
252 1.2.2.2 thorpej continue;
253 1.2.2.2 thorpej }
254 1.2.2.2 thorpej if (!IN6_IS_ADDR_ANY(&in6p->in6p_faddr)) {
255 1.2.2.2 thorpej if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr,
256 1.2.2.2 thorpej &ip6->ip6_src) ||
257 1.2.2.2 thorpej in6p->in6p_fport != uh->uh_sport)
258 1.2.2.2 thorpej continue;
259 1.2.2.2 thorpej }
260 1.2.2.2 thorpej
261 1.2.2.2 thorpej if (last != NULL) {
262 1.2.2.2 thorpej struct mbuf *n;
263 1.2.2.2 thorpej
264 1.2.2.2 thorpej #ifdef IPSEC
265 1.2.2.2 thorpej /*
266 1.2.2.2 thorpej * Check AH/ESP integrity.
267 1.2.2.2 thorpej */
268 1.2.2.2 thorpej if (last != NULL && ipsec6_in_reject(m, last)) {
269 1.2.2.2 thorpej ipsec6stat.in_polvio++;
270 1.2.2.2 thorpej /* do not inject data into pcb */
271 1.2.2.2 thorpej } else
272 1.2.2.2 thorpej #endif /*IPSEC*/
273 1.2.2.2 thorpej if ((n = m_copy(m, 0, M_COPYALL)) != NULL) {
274 1.2.2.2 thorpej /*
275 1.2.2.2 thorpej * KAME NOTE: do not
276 1.2.2.2 thorpej * m_copy(m, offset, ...) above.
277 1.2.2.2 thorpej * sbappendaddr() expects M_PKTHDR,
278 1.2.2.2 thorpej * and m_copy() will copy M_PKTHDR
279 1.2.2.2 thorpej * only if offset is 0.
280 1.2.2.2 thorpej */
281 1.2.2.2 thorpej if (last->in6p_flags & IN6P_CONTROLOPTS) {
282 1.2.2.2 thorpej ip6_savecontrol(last, &opts,
283 1.2.2.2 thorpej ip6, n);
284 1.2.2.2 thorpej }
285 1.2.2.2 thorpej
286 1.2.2.2 thorpej m_adj(m, off + sizeof(struct udphdr));
287 1.2.2.2 thorpej if (sbappendaddr(&last->in6p_socket->so_rcv,
288 1.2.2.2 thorpej (struct sockaddr *)&udp_in6,
289 1.2.2.2 thorpej n, opts) == 0) {
290 1.2.2.2 thorpej m_freem(n);
291 1.2.2.2 thorpej if (opts)
292 1.2.2.2 thorpej m_freem(opts);
293 1.2.2.2 thorpej udp6stat.udp6s_fullsock++;
294 1.2.2.2 thorpej } else
295 1.2.2.2 thorpej sorwakeup(last->in6p_socket);
296 1.2.2.2 thorpej opts = 0;
297 1.2.2.2 thorpej }
298 1.2.2.2 thorpej }
299 1.2.2.2 thorpej last = in6p;
300 1.2.2.2 thorpej /*
301 1.2.2.2 thorpej * Don't look for additional matches if this one does
302 1.2.2.2 thorpej * not have either the SO_REUSEPORT or SO_REUSEADDR
303 1.2.2.2 thorpej * socket options set. This heuristic avoids searching
304 1.2.2.2 thorpej * through all pcbs in the common case of a non-shared
305 1.2.2.2 thorpej * port. It assumes that an application will never
306 1.2.2.2 thorpej * clear these options after setting them.
307 1.2.2.2 thorpej */
308 1.2.2.2 thorpej if ((last->in6p_socket->so_options &
309 1.2.2.2 thorpej (SO_REUSEPORT|SO_REUSEADDR)) == 0)
310 1.2.2.2 thorpej break;
311 1.2.2.2 thorpej }
312 1.2.2.2 thorpej
313 1.2.2.2 thorpej if (last == NULL) {
314 1.2.2.2 thorpej /*
315 1.2.2.2 thorpej * No matching pcb found; discard datagram.
316 1.2.2.2 thorpej * (No need to send an ICMP Port Unreachable
317 1.2.2.2 thorpej * for a broadcast or multicast datgram.)
318 1.2.2.2 thorpej */
319 1.2.2.2 thorpej udp6stat.udp6s_noport++;
320 1.2.2.2 thorpej udp6stat.udp6s_noportmcast++;
321 1.2.2.2 thorpej goto bad;
322 1.2.2.2 thorpej }
323 1.2.2.2 thorpej #ifdef IPSEC
324 1.2.2.2 thorpej /*
325 1.2.2.2 thorpej * Check AH/ESP integrity.
326 1.2.2.2 thorpej */
327 1.2.2.2 thorpej if (last != NULL && ipsec6_in_reject(m, last)) {
328 1.2.2.2 thorpej ipsec6stat.in_polvio++;
329 1.2.2.2 thorpej goto bad;
330 1.2.2.2 thorpej }
331 1.2.2.2 thorpej #endif /*IPSEC*/
332 1.2.2.2 thorpej if (last->in6p_flags & IN6P_CONTROLOPTS)
333 1.2.2.2 thorpej ip6_savecontrol(last, &opts, ip6, m);
334 1.2.2.2 thorpej
335 1.2.2.2 thorpej m_adj(m, off + sizeof(struct udphdr));
336 1.2.2.2 thorpej if (sbappendaddr(&last->in6p_socket->so_rcv,
337 1.2.2.2 thorpej (struct sockaddr *)&udp_in6,
338 1.2.2.2 thorpej m, opts) == 0) {
339 1.2.2.2 thorpej udp6stat.udp6s_fullsock++;
340 1.2.2.2 thorpej goto bad;
341 1.2.2.2 thorpej }
342 1.2.2.2 thorpej sorwakeup(last->in6p_socket);
343 1.2.2.2 thorpej return IPPROTO_DONE;
344 1.2.2.2 thorpej }
345 1.2.2.2 thorpej /*
346 1.2.2.2 thorpej * Locate pcb for datagram.
347 1.2.2.2 thorpej */
348 1.2.2.2 thorpej in6p = udp6_last_in6pcb;
349 1.2.2.2 thorpej if (in6p->in6p_lport != uh->uh_dport ||
350 1.2.2.2 thorpej in6p->in6p_fport != uh->uh_sport ||
351 1.2.2.2 thorpej !IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &ip6->ip6_src) ||
352 1.2.2.2 thorpej !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &ip6->ip6_dst)) {
353 1.2.2.2 thorpej in6p = in6_pcblookup(&udb6,
354 1.2.2.2 thorpej &ip6->ip6_src, uh->uh_sport,
355 1.2.2.2 thorpej &ip6->ip6_dst, uh->uh_dport,
356 1.2.2.2 thorpej IN6PLOOKUP_WILDCARD);
357 1.2.2.2 thorpej if (in6p)
358 1.2.2.2 thorpej udp6_last_in6pcb = in6p;
359 1.2.2.2 thorpej udp6stat.udp6ps_pcbcachemiss++;
360 1.2.2.2 thorpej }
361 1.2.2.2 thorpej if (in6p == 0) {
362 1.2.2.2 thorpej udp6stat.udp6s_noport++;
363 1.2.2.2 thorpej if (m->m_flags & M_MCAST) {
364 1.2.2.2 thorpej printf("UDP6: M_MCAST is set in a unicast packet.\n");
365 1.2.2.2 thorpej udp6stat.udp6s_noportmcast++;
366 1.2.2.2 thorpej goto bad;
367 1.2.2.2 thorpej }
368 1.2.2.2 thorpej icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
369 1.2.2.2 thorpej return IPPROTO_DONE;
370 1.2.2.2 thorpej }
371 1.2.2.2 thorpej #ifdef IPSEC
372 1.2.2.2 thorpej /*
373 1.2.2.2 thorpej * Check AH/ESP integrity.
374 1.2.2.2 thorpej */
375 1.2.2.2 thorpej if (in6p != NULL && ipsec6_in_reject(m, in6p)) {
376 1.2.2.2 thorpej ipsec6stat.in_polvio++;
377 1.2.2.2 thorpej goto bad;
378 1.2.2.2 thorpej }
379 1.2.2.2 thorpej #endif /*IPSEC*/
380 1.2.2.2 thorpej
381 1.2.2.2 thorpej /*
382 1.2.2.2 thorpej * Construct sockaddr format source address.
383 1.2.2.2 thorpej * Stuff source address and datagram in user buffer.
384 1.2.2.2 thorpej */
385 1.2.2.2 thorpej bzero(&udp_in6, sizeof(udp_in6));
386 1.2.2.2 thorpej udp_in6.sin6_len = sizeof(struct sockaddr_in6);
387 1.2.2.2 thorpej udp_in6.sin6_family = AF_INET6;
388 1.2.2.2 thorpej udp_in6.sin6_port = uh->uh_sport;
389 1.2.2.2 thorpej udp_in6.sin6_addr = ip6->ip6_src;
390 1.2.2.2 thorpej if (IN6_IS_SCOPE_LINKLOCAL(&udp_in6.sin6_addr))
391 1.2.2.2 thorpej udp_in6.sin6_addr.s6_addr16[1] = 0;
392 1.2.2.2 thorpej if (m->m_pkthdr.rcvif) {
393 1.2.2.2 thorpej if (IN6_IS_SCOPE_LINKLOCAL(&udp_in6.sin6_addr))
394 1.2.2.2 thorpej udp_in6.sin6_scope_id = m->m_pkthdr.rcvif->if_index;
395 1.2.2.2 thorpej else
396 1.2.2.2 thorpej udp_in6.sin6_scope_id = 0;
397 1.2.2.2 thorpej } else
398 1.2.2.2 thorpej udp_in6.sin6_scope_id = 0;
399 1.2.2.2 thorpej if (in6p->in6p_flags & IN6P_CONTROLOPTS)
400 1.2.2.2 thorpej ip6_savecontrol(in6p, &opts, ip6, m);
401 1.2.2.2 thorpej
402 1.2.2.2 thorpej m_adj(m, off + sizeof(struct udphdr));
403 1.2.2.2 thorpej if (sbappendaddr(&in6p->in6p_socket->so_rcv,
404 1.2.2.2 thorpej (struct sockaddr *)&udp_in6,
405 1.2.2.2 thorpej m, opts) == 0) {
406 1.2.2.2 thorpej udp6stat.udp6s_fullsock++;
407 1.2.2.2 thorpej goto bad;
408 1.2.2.2 thorpej }
409 1.2.2.2 thorpej sorwakeup(in6p->in6p_socket);
410 1.2.2.2 thorpej return IPPROTO_DONE;
411 1.2.2.2 thorpej bad:
412 1.2.2.2 thorpej if (m)
413 1.2.2.2 thorpej m_freem(m);
414 1.2.2.2 thorpej if (opts)
415 1.2.2.2 thorpej m_freem(opts);
416 1.2.2.2 thorpej return IPPROTO_DONE;
417 1.2.2.2 thorpej }
418 1.2.2.2 thorpej
419 1.2.2.2 thorpej /*
420 1.2.2.2 thorpej * Notify a udp user of an asynchronous error;
421 1.2.2.2 thorpej * just wake up so tat he can collect error status.
422 1.2.2.2 thorpej */
423 1.2.2.2 thorpej static void
424 1.2.2.2 thorpej udp6_notify(in6p, errno)
425 1.2.2.2 thorpej register struct in6pcb *in6p;
426 1.2.2.2 thorpej int errno;
427 1.2.2.2 thorpej {
428 1.2.2.2 thorpej in6p->in6p_socket->so_error = errno;
429 1.2.2.2 thorpej sorwakeup(in6p->in6p_socket);
430 1.2.2.2 thorpej sowwakeup(in6p->in6p_socket);
431 1.2.2.2 thorpej }
432 1.2.2.2 thorpej
433 1.2.2.2 thorpej void
434 1.2.2.2 thorpej udp6_ctlinput(cmd, sa, ip6, m, off)
435 1.2.2.2 thorpej int cmd;
436 1.2.2.2 thorpej struct sockaddr *sa;
437 1.2.2.2 thorpej register struct ip6_hdr *ip6;
438 1.2.2.2 thorpej struct mbuf *m;
439 1.2.2.2 thorpej int off;
440 1.2.2.2 thorpej {
441 1.2.2.2 thorpej register struct udphdr *uhp;
442 1.2.2.2 thorpej struct udphdr uh;
443 1.2.2.2 thorpej
444 1.2.2.2 thorpej #if 0
445 1.2.2.2 thorpej if (cmd == PRC_IFNEWADDR)
446 1.2.2.2 thorpej in6_mrejoin(&udb6);
447 1.2.2.2 thorpej else
448 1.2.2.2 thorpej #endif
449 1.2.2.2 thorpej if (!PRC_IS_REDIRECT(cmd) &&
450 1.2.2.2 thorpej ((unsigned)cmd >= PRC_NCMDS || inet6ctlerrmap[cmd] == 0))
451 1.2.2.2 thorpej return;
452 1.2.2.2 thorpej if (ip6) {
453 1.2.2.2 thorpej /*
454 1.2.2.2 thorpej * XXX: We assume that when IPV6 is non NULL,
455 1.2.2.2 thorpej * M and OFF are valid.
456 1.2.2.2 thorpej */
457 1.2.2.2 thorpej if (m->m_len < off + sizeof(uh)) {
458 1.2.2.2 thorpej /*
459 1.2.2.2 thorpej * this should be rare case,
460 1.2.2.2 thorpej * so we compromise on this copy...
461 1.2.2.2 thorpej */
462 1.2.2.2 thorpej m_copydata(m, off, sizeof(uh), (caddr_t)&uh);
463 1.2.2.2 thorpej uhp = &uh;
464 1.2.2.2 thorpej } else
465 1.2.2.2 thorpej uhp = (struct udphdr *)(mtod(m, caddr_t) + off);
466 1.2.2.2 thorpej (void) in6_pcbnotify(&udb6, sa, uhp->uh_dport, &ip6->ip6_src,
467 1.2.2.2 thorpej uhp->uh_sport, cmd, udp6_notify);
468 1.2.2.2 thorpej } else {
469 1.2.2.2 thorpej (void) in6_pcbnotify(&udb6, sa, 0, &zeroin6_addr, 0, cmd,
470 1.2.2.2 thorpej udp6_notify);
471 1.2.2.2 thorpej }
472 1.2.2.2 thorpej }
473 1.2.2.2 thorpej
474 1.2.2.2 thorpej int
475 1.2.2.2 thorpej udp6_output(in6p, m, addr6, control)
476 1.2.2.2 thorpej register struct in6pcb *in6p;
477 1.2.2.2 thorpej register struct mbuf *m;
478 1.2.2.2 thorpej struct mbuf *addr6, *control;
479 1.2.2.2 thorpej {
480 1.2.2.2 thorpej register int ulen = m->m_pkthdr.len;
481 1.2.2.2 thorpej int plen = sizeof(struct udphdr) + ulen;
482 1.2.2.2 thorpej struct ip6_hdr *ip6;
483 1.2.2.2 thorpej struct udphdr *udp6;
484 1.2.2.2 thorpej struct in6_addr laddr6;
485 1.2.2.2 thorpej int s = 0, error = 0;
486 1.2.2.2 thorpej struct ip6_pktopts opt, *stickyopt = in6p->in6p_outputopts;
487 1.2.2.2 thorpej int priv = 0;
488 1.2.2.2 thorpej struct proc *p = curproc; /* XXX */
489 1.2.2.2 thorpej
490 1.2.2.2 thorpej if (p && !suser(p->p_ucred, &p->p_acflag))
491 1.2.2.2 thorpej priv = 1;
492 1.2.2.2 thorpej if (control) {
493 1.2.2.2 thorpej if ((error = ip6_setpktoptions(control, &opt, priv)) != 0)
494 1.2.2.2 thorpej goto release;
495 1.2.2.2 thorpej in6p->in6p_outputopts = &opt;
496 1.2.2.2 thorpej }
497 1.2.2.2 thorpej
498 1.2.2.2 thorpej if (addr6) {
499 1.2.2.2 thorpej laddr6 = in6p->in6p_laddr;
500 1.2.2.2 thorpej if (!IN6_IS_ADDR_ANY(&in6p->in6p_faddr)) {
501 1.2.2.2 thorpej error = EISCONN;
502 1.2.2.2 thorpej goto release;
503 1.2.2.2 thorpej }
504 1.2.2.2 thorpej /*
505 1.2.2.2 thorpej * Must block input while temporarily connected.
506 1.2.2.2 thorpej */
507 1.2.2.2 thorpej s = splnet();
508 1.2.2.2 thorpej error = in6_pcbconnect(in6p, addr6);
509 1.2.2.2 thorpej if (error) {
510 1.2.2.2 thorpej splx(s);
511 1.2.2.2 thorpej goto release;
512 1.2.2.2 thorpej }
513 1.2.2.2 thorpej } else {
514 1.2.2.2 thorpej if (IN6_IS_ADDR_ANY(&in6p->in6p_faddr)) {
515 1.2.2.2 thorpej error = ENOTCONN;
516 1.2.2.2 thorpej goto release;
517 1.2.2.2 thorpej }
518 1.2.2.2 thorpej }
519 1.2.2.2 thorpej /*
520 1.2.2.2 thorpej * Calculate data length and get a mbuf
521 1.2.2.2 thorpej * for UDP and IP6 headers.
522 1.2.2.2 thorpej */
523 1.2.2.2 thorpej M_PREPEND(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr), M_DONTWAIT);
524 1.2.2.2 thorpej if (m == 0) {
525 1.2.2.2 thorpej error = ENOBUFS;
526 1.2.2.2 thorpej goto release;
527 1.2.2.2 thorpej }
528 1.2.2.2 thorpej
529 1.2.2.2 thorpej /*
530 1.2.2.2 thorpej * Stuff checksum and output datagram.
531 1.2.2.2 thorpej */
532 1.2.2.2 thorpej ip6 = mtod(m, struct ip6_hdr *);
533 1.2.2.2 thorpej ip6->ip6_flow = in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK;
534 1.2.2.2 thorpej ip6->ip6_vfc = IPV6_VERSION;
535 1.2.2.2 thorpej #if 0 /* ip6_plen will be filled in ip6_output. */
536 1.2.2.2 thorpej ip6->ip6_plen = htons((u_short)plen);
537 1.2.2.2 thorpej #endif
538 1.2.2.2 thorpej ip6->ip6_nxt = IPPROTO_UDP;
539 1.2.2.2 thorpej ip6->ip6_hlim = in6p->in6p_ip6.ip6_hlim; /* XXX */
540 1.2.2.2 thorpej ip6->ip6_src = in6p->in6p_laddr;
541 1.2.2.2 thorpej ip6->ip6_dst = in6p->in6p_faddr;
542 1.2.2.2 thorpej
543 1.2.2.2 thorpej udp6 = (struct udphdr *)(ip6 + 1);
544 1.2.2.2 thorpej udp6->uh_sport = in6p->in6p_lport;
545 1.2.2.2 thorpej udp6->uh_dport = in6p->in6p_fport;
546 1.2.2.2 thorpej udp6->uh_ulen = htons((u_short)plen);
547 1.2.2.2 thorpej udp6->uh_sum = 0;
548 1.2.2.2 thorpej
549 1.2.2.2 thorpej if ((udp6->uh_sum = in6_cksum(m, IPPROTO_UDP,
550 1.2.2.2 thorpej sizeof(struct ip6_hdr), plen)) == 0) {
551 1.2.2.2 thorpej udp6->uh_sum = 0xffff;
552 1.2.2.2 thorpej }
553 1.2.2.2 thorpej
554 1.2.2.2 thorpej udp6stat.udp6s_opackets++;
555 1.2.2.2 thorpej
556 1.2.2.2 thorpej #ifdef IPSEC
557 1.2.2.2 thorpej m->m_pkthdr.rcvif = (struct ifnet *)in6p->in6p_socket;
558 1.2.2.2 thorpej #endif /*IPSEC*/
559 1.2.2.2 thorpej error = ip6_output(m, in6p->in6p_outputopts, &in6p->in6p_route,
560 1.2.2.2 thorpej 0, in6p->in6p_moptions);
561 1.2.2.2 thorpej
562 1.2.2.2 thorpej if (addr6) {
563 1.2.2.2 thorpej in6_pcbdisconnect(in6p);
564 1.2.2.2 thorpej in6p->in6p_laddr = laddr6;
565 1.2.2.2 thorpej splx(s);
566 1.2.2.2 thorpej }
567 1.2.2.2 thorpej goto releaseopt;
568 1.2.2.2 thorpej
569 1.2.2.2 thorpej release:
570 1.2.2.2 thorpej m_freem(m);
571 1.2.2.2 thorpej
572 1.2.2.2 thorpej releaseopt:
573 1.2.2.2 thorpej if (control) {
574 1.2.2.2 thorpej in6p->in6p_outputopts = stickyopt;
575 1.2.2.2 thorpej m_freem(control);
576 1.2.2.2 thorpej }
577 1.2.2.2 thorpej return(error);
578 1.2.2.2 thorpej }
579 1.2.2.2 thorpej
580 1.2.2.2 thorpej extern int udp6_sendspace;
581 1.2.2.2 thorpej extern int udp6_recvspace;
582 1.2.2.2 thorpej
583 1.2.2.2 thorpej int
584 1.2.2.2 thorpej udp6_usrreq(so, req, m, addr6, control, p)
585 1.2.2.2 thorpej struct socket *so;
586 1.2.2.2 thorpej int req;
587 1.2.2.2 thorpej struct mbuf *m, *addr6, *control;
588 1.2.2.2 thorpej struct proc *p;
589 1.2.2.2 thorpej {
590 1.2.2.2 thorpej struct in6pcb *in6p = sotoin6pcb(so);
591 1.2.2.2 thorpej int error = 0;
592 1.2.2.2 thorpej int s;
593 1.2.2.2 thorpej
594 1.2.2.2 thorpej /*
595 1.2.2.2 thorpej * MAPPED_ADDR implementation info:
596 1.2.2.2 thorpej * Mapped addr support for PRU_CONTROL is not necessary.
597 1.2.2.2 thorpej * Because typical user of PRU_CONTROL is such as ifconfig,
598 1.2.2.2 thorpej * and they don't associate any addr to their socket. Then
599 1.2.2.2 thorpej * socket family is only hint about the PRU_CONTROL'ed address
600 1.2.2.2 thorpej * family, especially when getting addrs from kernel.
601 1.2.2.2 thorpej * So AF_INET socket need to be used to control AF_INET addrs,
602 1.2.2.2 thorpej * and AF_INET6 socket for AF_INET6 addrs.
603 1.2.2.2 thorpej */
604 1.2.2.2 thorpej if (req == PRU_CONTROL)
605 1.2.2.2 thorpej return(in6_control(so, (u_long)m, (caddr_t)addr6,
606 1.2.2.2 thorpej (struct ifnet *)control, p));
607 1.2.2.2 thorpej
608 1.2.2.2 thorpej if (in6p == NULL && req != PRU_ATTACH) {
609 1.2.2.2 thorpej error = EINVAL;
610 1.2.2.2 thorpej goto release;
611 1.2.2.2 thorpej }
612 1.2.2.2 thorpej
613 1.2.2.2 thorpej switch (req) {
614 1.2.2.2 thorpej case PRU_ATTACH:
615 1.2.2.2 thorpej /*
616 1.2.2.2 thorpej * MAPPED_ADDR implementation spec:
617 1.2.2.2 thorpej * Always attach for IPv6,
618 1.2.2.2 thorpej * and only when necessary for IPv4.
619 1.2.2.2 thorpej */
620 1.2.2.2 thorpej if (in6p != NULL) {
621 1.2.2.2 thorpej error = EINVAL;
622 1.2.2.2 thorpej break;
623 1.2.2.2 thorpej }
624 1.2.2.2 thorpej s = splnet();
625 1.2.2.2 thorpej error = in6_pcballoc(so, &udb6);
626 1.2.2.2 thorpej splx(s);
627 1.2.2.2 thorpej if (error)
628 1.2.2.2 thorpej break;
629 1.2.2.2 thorpej error = soreserve(so, udp6_sendspace, udp6_recvspace);
630 1.2.2.2 thorpej if (error)
631 1.2.2.2 thorpej break;
632 1.2.2.2 thorpej in6p = sotoin6pcb(so);
633 1.2.2.2 thorpej in6p->in6p_ip6.ip6_hlim = ip6_defhlim;
634 1.2.2.2 thorpej in6p->in6p_cksum = -1; /* just to be sure */
635 1.2.2.2 thorpej #ifdef IPSEC
636 1.2.2.2 thorpej error = ipsec_init_policy(&in6p->in6p_sp);
637 1.2.2.2 thorpej #endif /*IPSEC*/
638 1.2.2.2 thorpej break;
639 1.2.2.2 thorpej
640 1.2.2.2 thorpej case PRU_DETACH:
641 1.2.2.2 thorpej udp6_detach(in6p);
642 1.2.2.2 thorpej break;
643 1.2.2.2 thorpej
644 1.2.2.2 thorpej case PRU_BIND:
645 1.2.2.2 thorpej s = splnet();
646 1.2.2.2 thorpej error = in6_pcbbind(in6p, addr6);
647 1.2.2.2 thorpej splx(s);
648 1.2.2.2 thorpej break;
649 1.2.2.2 thorpej
650 1.2.2.2 thorpej case PRU_LISTEN:
651 1.2.2.2 thorpej error = EOPNOTSUPP;
652 1.2.2.2 thorpej break;
653 1.2.2.2 thorpej
654 1.2.2.2 thorpej case PRU_CONNECT:
655 1.2.2.2 thorpej if (!IN6_IS_ADDR_ANY(&in6p->in6p_faddr)) {
656 1.2.2.2 thorpej error = EISCONN;
657 1.2.2.2 thorpej break;
658 1.2.2.2 thorpej }
659 1.2.2.2 thorpej s = splnet();
660 1.2.2.2 thorpej error = in6_pcbconnect(in6p, addr6);
661 1.2.2.2 thorpej if (ip6_auto_flowlabel) {
662 1.2.2.2 thorpej in6p->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
663 1.2.2.2 thorpej in6p->in6p_flowinfo |=
664 1.2.2.2 thorpej (htonl(ip6_flow_seq++) & IPV6_FLOWLABEL_MASK);
665 1.2.2.2 thorpej }
666 1.2.2.2 thorpej splx(s);
667 1.2.2.2 thorpej if (error == 0)
668 1.2.2.2 thorpej soisconnected(so);
669 1.2.2.2 thorpej break;
670 1.2.2.2 thorpej
671 1.2.2.2 thorpej case PRU_CONNECT2:
672 1.2.2.2 thorpej error = EOPNOTSUPP;
673 1.2.2.2 thorpej break;
674 1.2.2.2 thorpej
675 1.2.2.2 thorpej case PRU_ACCEPT:
676 1.2.2.2 thorpej error = EOPNOTSUPP;
677 1.2.2.2 thorpej break;
678 1.2.2.2 thorpej
679 1.2.2.2 thorpej case PRU_DISCONNECT:
680 1.2.2.2 thorpej if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
681 1.2.2.2 thorpej error = ENOTCONN;
682 1.2.2.2 thorpej break;
683 1.2.2.2 thorpej }
684 1.2.2.2 thorpej s = splnet();
685 1.2.2.2 thorpej in6_pcbdisconnect(in6p);
686 1.2.2.2 thorpej bzero((caddr_t)&in6p->in6p_laddr, sizeof(in6p->in6p_laddr));
687 1.2.2.2 thorpej splx(s);
688 1.2.2.2 thorpej so->so_state &= ~SS_ISCONNECTED; /* XXX */
689 1.2.2.2 thorpej break;
690 1.2.2.2 thorpej
691 1.2.2.2 thorpej case PRU_SHUTDOWN:
692 1.2.2.2 thorpej socantsendmore(so);
693 1.2.2.2 thorpej break;
694 1.2.2.2 thorpej
695 1.2.2.2 thorpej case PRU_SEND:
696 1.2.2.2 thorpej return(udp6_output(in6p, m, addr6, control));
697 1.2.2.2 thorpej
698 1.2.2.2 thorpej case PRU_ABORT:
699 1.2.2.2 thorpej soisdisconnected(so);
700 1.2.2.2 thorpej udp6_detach(in6p);
701 1.2.2.2 thorpej break;
702 1.2.2.2 thorpej
703 1.2.2.2 thorpej case PRU_SOCKADDR:
704 1.2.2.2 thorpej in6_setsockaddr(in6p, addr6);
705 1.2.2.2 thorpej break;
706 1.2.2.2 thorpej
707 1.2.2.2 thorpej case PRU_PEERADDR:
708 1.2.2.2 thorpej in6_setpeeraddr(in6p, addr6);
709 1.2.2.2 thorpej break;
710 1.2.2.2 thorpej
711 1.2.2.2 thorpej case PRU_SENSE:
712 1.2.2.2 thorpej /*
713 1.2.2.2 thorpej * stat: don't bother with a blocksize
714 1.2.2.2 thorpej */
715 1.2.2.2 thorpej return(0);
716 1.2.2.2 thorpej
717 1.2.2.2 thorpej case PRU_SENDOOB:
718 1.2.2.2 thorpej case PRU_FASTTIMO:
719 1.2.2.2 thorpej case PRU_SLOWTIMO:
720 1.2.2.2 thorpej case PRU_PROTORCV:
721 1.2.2.2 thorpej case PRU_PROTOSEND:
722 1.2.2.2 thorpej error = EOPNOTSUPP;
723 1.2.2.2 thorpej break;
724 1.2.2.2 thorpej
725 1.2.2.2 thorpej case PRU_RCVD:
726 1.2.2.2 thorpej case PRU_RCVOOB:
727 1.2.2.2 thorpej return(EOPNOTSUPP); /* do not free mbuf's */
728 1.2.2.2 thorpej
729 1.2.2.2 thorpej default:
730 1.2.2.2 thorpej panic("udp6_usrreq");
731 1.2.2.2 thorpej }
732 1.2.2.2 thorpej
733 1.2.2.2 thorpej release:
734 1.2.2.2 thorpej if (control) {
735 1.2.2.2 thorpej printf("udp control data unexpectedly retained\n");
736 1.2.2.2 thorpej m_freem(control);
737 1.2.2.2 thorpej }
738 1.2.2.2 thorpej if (m)
739 1.2.2.2 thorpej m_freem(m);
740 1.2.2.2 thorpej return(error);
741 1.2.2.2 thorpej }
742 1.2.2.2 thorpej
743 1.2.2.2 thorpej static void
744 1.2.2.2 thorpej udp6_detach(in6p)
745 1.2.2.2 thorpej struct in6pcb *in6p;
746 1.2.2.2 thorpej {
747 1.2.2.2 thorpej int s = splnet();
748 1.2.2.2 thorpej
749 1.2.2.2 thorpej if (in6p == udp6_last_in6pcb)
750 1.2.2.2 thorpej udp6_last_in6pcb = &udb6;
751 1.2.2.2 thorpej in6_pcbdetach(in6p);
752 1.2.2.2 thorpej splx(s);
753 1.2.2.2 thorpej }
754 1.2.2.2 thorpej
755 1.2.2.2 thorpej #ifdef __bsdi__
756 1.2.2.2 thorpej int *udp6_sysvars[] = UDP6CTL_VARS;
757 1.2.2.2 thorpej
758 1.2.2.2 thorpej int
759 1.2.2.2 thorpej udp6_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
760 1.2.2.2 thorpej int *name;
761 1.2.2.2 thorpej u_int namelen;
762 1.2.2.2 thorpej void *oldp;
763 1.2.2.2 thorpej size_t *oldlenp;
764 1.2.2.2 thorpej void *newp;
765 1.2.2.2 thorpej size_t newlen;
766 1.2.2.2 thorpej {
767 1.2.2.2 thorpej if (name[0] >= UDP6CTL_MAXID)
768 1.2.2.2 thorpej return (EOPNOTSUPP);
769 1.2.2.2 thorpej switch (name[0]) {
770 1.2.2.2 thorpej case UDP6CTL_STATS:
771 1.2.2.2 thorpej return sysctl_rdtrunc(oldp, oldlenp, newp, &udp6stat,
772 1.2.2.2 thorpej sizeof(udp6stat));
773 1.2.2.2 thorpej
774 1.2.2.2 thorpej default:
775 1.2.2.2 thorpej return (sysctl_int_arr(udp6_sysvars, name, namelen,
776 1.2.2.2 thorpej oldp, oldlenp, newp, newlen));
777 1.2.2.2 thorpej }
778 1.2.2.2 thorpej }
779 1.2.2.2 thorpej #endif /*__bsdi__*/
780 1.2.2.2 thorpej
781 1.2.2.2 thorpej #ifdef __NetBSD__
782 1.2.2.2 thorpej #include <vm/vm.h>
783 1.2.2.2 thorpej #include <sys/sysctl.h>
784 1.2.2.2 thorpej
785 1.2.2.2 thorpej int
786 1.2.2.2 thorpej udp6_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
787 1.2.2.2 thorpej int *name;
788 1.2.2.2 thorpej u_int namelen;
789 1.2.2.2 thorpej void *oldp;
790 1.2.2.2 thorpej size_t *oldlenp;
791 1.2.2.2 thorpej void *newp;
792 1.2.2.2 thorpej size_t newlen;
793 1.2.2.2 thorpej {
794 1.2.2.2 thorpej /* All sysctl names at this level are terminal. */
795 1.2.2.2 thorpej if (namelen != 1)
796 1.2.2.2 thorpej return ENOTDIR;
797 1.2.2.2 thorpej
798 1.2.2.2 thorpej switch (name[0]) {
799 1.2.2.2 thorpej
800 1.2.2.2 thorpej case UDP6CTL_SENDMAX:
801 1.2.2.2 thorpej return sysctl_int(oldp, oldlenp, newp, newlen,
802 1.2.2.2 thorpej &udp6_sendspace);
803 1.2.2.2 thorpej case UDP6CTL_RECVSPACE:
804 1.2.2.2 thorpej return sysctl_int(oldp, oldlenp, newp, newlen,
805 1.2.2.2 thorpej &udp6_recvspace);
806 1.2.2.2 thorpej default:
807 1.2.2.2 thorpej return ENOPROTOOPT;
808 1.2.2.2 thorpej }
809 1.2.2.2 thorpej /* NOTREACHED */
810 1.2.2.2 thorpej }
811 1.2.2.2 thorpej #endif
812