udp6_usrreq.c revision 272404
1/*-
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * Copyright (c) 2010-2011 Juniper Networks, Inc.
4 * Copyright (c) 2014 Kevin Lo
5 * All rights reserved.
6 *
7 * Portions of this software were developed by Robert N. M. Watson under
8 * contract to Juniper Networks, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
21 *
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
32 * SUCH DAMAGE.
33 *
34 *	$KAME: udp6_usrreq.c,v 1.27 2001/05/21 05:45:10 jinmei Exp $
35 *	$KAME: udp6_output.c,v 1.31 2001/05/21 16:39:15 jinmei Exp $
36 */
37
38/*-
39 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
40 *	The Regents of the University of California.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 *    notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 *    notice, this list of conditions and the following disclaimer in the
50 *    documentation and/or other materials provided with the distribution.
51 * 4. Neither the name of the University nor the names of its contributors
52 *    may be used to endorse or promote products derived from this software
53 *    without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 *	@(#)udp_usrreq.c	8.6 (Berkeley) 5/23/95
68 */
69
70#include <sys/cdefs.h>
71__FBSDID("$FreeBSD: head/sys/netinet6/udp6_usrreq.c 272404 2014-10-02 10:32:24Z tuexen $");
72
73#include "opt_inet.h"
74#include "opt_inet6.h"
75#include "opt_ipfw.h"
76#include "opt_ipsec.h"
77#include "opt_rss.h"
78
79#include <sys/param.h>
80#include <sys/jail.h>
81#include <sys/kernel.h>
82#include <sys/lock.h>
83#include <sys/mbuf.h>
84#include <sys/priv.h>
85#include <sys/proc.h>
86#include <sys/protosw.h>
87#include <sys/sdt.h>
88#include <sys/signalvar.h>
89#include <sys/socket.h>
90#include <sys/socketvar.h>
91#include <sys/sx.h>
92#include <sys/sysctl.h>
93#include <sys/syslog.h>
94#include <sys/systm.h>
95
96#include <net/if.h>
97#include <net/if_var.h>
98#include <net/if_types.h>
99#include <net/route.h>
100
101#include <netinet/in.h>
102#include <netinet/in_kdtrace.h>
103#include <netinet/in_pcb.h>
104#include <netinet/in_systm.h>
105#include <netinet/in_var.h>
106#include <netinet/ip.h>
107#include <netinet/ip_icmp.h>
108#include <netinet/ip6.h>
109#include <netinet/icmp_var.h>
110#include <netinet/icmp6.h>
111#include <netinet/ip_var.h>
112#include <netinet/udp.h>
113#include <netinet/udp_var.h>
114#include <netinet/udplite.h>
115#include <netinet/in_rss.h>
116
117#include <netinet6/ip6protosw.h>
118#include <netinet6/ip6_var.h>
119#include <netinet6/in6_pcb.h>
120#include <netinet6/udp6_var.h>
121#include <netinet6/scope6_var.h>
122
123#ifdef IPSEC
124#include <netipsec/ipsec.h>
125#include <netipsec/ipsec6.h>
126#endif /* IPSEC */
127
128#include <security/mac/mac_framework.h>
129
130/*
131 * UDP protocol implementation.
132 * Per RFC 768, August, 1980.
133 */
134
135extern struct protosw	inetsw[];
136static void		udp6_detach(struct socket *so);
137
138static void
139udp6_append(struct inpcb *inp, struct mbuf *n, int off,
140    struct sockaddr_in6 *fromsa)
141{
142	struct socket *so;
143	struct mbuf *opts;
144
145	INP_LOCK_ASSERT(inp);
146
147#ifdef IPSEC
148	/* Check AH/ESP integrity. */
149	if (ipsec6_in_reject(n, inp)) {
150		m_freem(n);
151		IPSEC6STAT_INC(ips_in_polvio);
152		return;
153	}
154#endif /* IPSEC */
155#ifdef MAC
156	if (mac_inpcb_check_deliver(inp, n) != 0) {
157		m_freem(n);
158		return;
159	}
160#endif
161	opts = NULL;
162	if (inp->inp_flags & INP_CONTROLOPTS ||
163	    inp->inp_socket->so_options & SO_TIMESTAMP)
164		ip6_savecontrol(inp, n, &opts);
165	m_adj(n, off + sizeof(struct udphdr));
166
167	so = inp->inp_socket;
168	SOCKBUF_LOCK(&so->so_rcv);
169	if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)fromsa, n,
170	    opts) == 0) {
171		SOCKBUF_UNLOCK(&so->so_rcv);
172		m_freem(n);
173		if (opts)
174			m_freem(opts);
175		UDPSTAT_INC(udps_fullsock);
176	} else
177		sorwakeup_locked(so);
178}
179
180int
181udp6_input(struct mbuf **mp, int *offp, int proto)
182{
183	struct mbuf *m = *mp;
184	struct ifnet *ifp;
185	struct ip6_hdr *ip6;
186	struct udphdr *uh;
187	struct inpcb *inp;
188	struct inpcbinfo *pcbinfo;
189	struct udpcb *up;
190	int off = *offp;
191	int cscov_partial;
192	int plen, ulen;
193	struct sockaddr_in6 fromsa;
194	struct m_tag *fwd_tag;
195	uint16_t uh_sum;
196	uint8_t nxt;
197
198	ifp = m->m_pkthdr.rcvif;
199	ip6 = mtod(m, struct ip6_hdr *);
200
201	if (faithprefix_p != NULL && (*faithprefix_p)(&ip6->ip6_dst)) {
202		/* XXX send icmp6 host/port unreach? */
203		m_freem(m);
204		return (IPPROTO_DONE);
205	}
206
207#ifndef PULLDOWN_TEST
208	IP6_EXTHDR_CHECK(m, off, sizeof(struct udphdr), IPPROTO_DONE);
209	ip6 = mtod(m, struct ip6_hdr *);
210	uh = (struct udphdr *)((caddr_t)ip6 + off);
211#else
212	IP6_EXTHDR_GET(uh, struct udphdr *, m, off, sizeof(*uh));
213	if (!uh)
214		return (IPPROTO_DONE);
215#endif
216
217	UDPSTAT_INC(udps_ipackets);
218
219	/*
220	 * Destination port of 0 is illegal, based on RFC768.
221	 */
222	if (uh->uh_dport == 0)
223		goto badunlocked;
224
225	plen = ntohs(ip6->ip6_plen) - off + sizeof(*ip6);
226	ulen = ntohs((u_short)uh->uh_ulen);
227
228	nxt = ip6->ip6_nxt;
229	cscov_partial = (nxt == IPPROTO_UDPLITE) ? 1 : 0;
230	if (nxt == IPPROTO_UDPLITE) {
231		/* Zero means checksum over the complete packet. */
232		if (ulen == 0)
233			ulen = plen;
234		if (ulen == plen)
235			cscov_partial = 0;
236		if ((ulen < sizeof(struct udphdr)) || (ulen > plen)) {
237			/* XXX: What is the right UDPLite MIB counter? */
238			goto badunlocked;
239		}
240	}
241	if (nxt == IPPROTO_UDP && plen != ulen) {
242		UDPSTAT_INC(udps_badlen);
243		goto badunlocked;
244	}
245
246	/*
247	 * Checksum extended UDP header and data.
248	 */
249	if (uh->uh_sum == 0) {
250		if (ulen > plen || ulen < sizeof(struct udphdr)) {
251			UDPSTAT_INC(udps_nosum);
252			goto badunlocked;
253		}
254	}
255
256	if ((m->m_pkthdr.csum_flags & CSUM_DATA_VALID_IPV6) &&
257	    !cscov_partial) {
258		if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR)
259			uh_sum = m->m_pkthdr.csum_data;
260		else
261			uh_sum = in6_cksum_pseudo(ip6, ulen, nxt,
262			    m->m_pkthdr.csum_data);
263		uh_sum ^= 0xffff;
264	} else
265		uh_sum = in6_cksum_partial(m, nxt, off, plen, ulen);
266
267	if (uh_sum != 0) {
268		UDPSTAT_INC(udps_badsum);
269		/*goto badunlocked;*/
270	}
271
272	/*
273	 * Construct sockaddr format source address.
274	 */
275	init_sin6(&fromsa, m);
276	fromsa.sin6_port = uh->uh_sport;
277
278	pcbinfo = get_inpcbinfo(nxt);
279	if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
280		struct inpcb *last;
281		struct inpcbhead *pcblist;
282		struct ip6_moptions *imo;
283
284		INP_INFO_RLOCK(pcbinfo);
285		/*
286		 * In the event that laddr should be set to the link-local
287		 * address (this happens in RIPng), the multicast address
288		 * specified in the received packet will not match laddr.  To
289		 * handle this situation, matching is relaxed if the
290		 * receiving interface is the same as one specified in the
291		 * socket and if the destination multicast address matches
292		 * one of the multicast groups specified in the socket.
293		 */
294
295		/*
296		 * KAME note: traditionally we dropped udpiphdr from mbuf
297		 * here.  We need udphdr for IPsec processing so we do that
298		 * later.
299		 */
300		pcblist = get_pcblist(nxt);
301		last = NULL;
302		LIST_FOREACH(inp, pcblist, inp_list) {
303			if ((inp->inp_vflag & INP_IPV6) == 0)
304				continue;
305			if (inp->inp_lport != uh->uh_dport)
306				continue;
307			if (inp->inp_fport != 0 &&
308			    inp->inp_fport != uh->uh_sport)
309				continue;
310			if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) {
311				if (!IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr,
312							&ip6->ip6_dst))
313					continue;
314			}
315			if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
316				if (!IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr,
317							&ip6->ip6_src) ||
318				    inp->inp_fport != uh->uh_sport)
319					continue;
320			}
321
322			/*
323			 * XXXRW: Because we weren't holding either the inpcb
324			 * or the hash lock when we checked for a match
325			 * before, we should probably recheck now that the
326			 * inpcb lock is (supposed to be) held.
327			 */
328
329			/*
330			 * Handle socket delivery policy for any-source
331			 * and source-specific multicast. [RFC3678]
332			 */
333			imo = inp->in6p_moptions;
334			if (imo && IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
335				struct sockaddr_in6	 mcaddr;
336				int			 blocked;
337
338				INP_RLOCK(inp);
339
340				bzero(&mcaddr, sizeof(struct sockaddr_in6));
341				mcaddr.sin6_len = sizeof(struct sockaddr_in6);
342				mcaddr.sin6_family = AF_INET6;
343				mcaddr.sin6_addr = ip6->ip6_dst;
344
345				blocked = im6o_mc_filter(imo, ifp,
346					(struct sockaddr *)&mcaddr,
347					(struct sockaddr *)&fromsa);
348				if (blocked != MCAST_PASS) {
349					if (blocked == MCAST_NOTGMEMBER)
350						IP6STAT_INC(ip6s_notmember);
351					if (blocked == MCAST_NOTSMEMBER ||
352					    blocked == MCAST_MUTED)
353						UDPSTAT_INC(udps_filtermcast);
354					INP_RUNLOCK(inp); /* XXX */
355					continue;
356				}
357
358				INP_RUNLOCK(inp);
359			}
360			if (last != NULL) {
361				struct mbuf *n;
362
363				if ((n = m_copy(m, 0, M_COPYALL)) != NULL) {
364					INP_RLOCK(last);
365					up = intoudpcb(last);
366					if (up->u_tun_func == NULL) {
367						udp6_append(last, n, off, &fromsa);
368					} else {
369						/*
370						 * Engage the tunneling
371						 * protocol we will have to
372						 * leave the info_lock up,
373						 * since we are hunting
374						 * through multiple UDP's.
375						 *
376						 */
377						(*up->u_tun_func)(n, off, last);
378					}
379					INP_RUNLOCK(last);
380				}
381			}
382			last = inp;
383			/*
384			 * Don't look for additional matches if this one does
385			 * not have either the SO_REUSEPORT or SO_REUSEADDR
386			 * socket options set.  This heuristic avoids
387			 * searching through all pcbs in the common case of a
388			 * non-shared port.  It assumes that an application
389			 * will never clear these options after setting them.
390			 */
391			if ((last->inp_socket->so_options &
392			     (SO_REUSEPORT|SO_REUSEADDR)) == 0)
393				break;
394		}
395
396		if (last == NULL) {
397			/*
398			 * No matching pcb found; discard datagram.  (No need
399			 * to send an ICMP Port Unreachable for a broadcast
400			 * or multicast datgram.)
401			 */
402			UDPSTAT_INC(udps_noport);
403			UDPSTAT_INC(udps_noportmcast);
404			goto badheadlocked;
405		}
406		INP_RLOCK(last);
407		INP_INFO_RUNLOCK(pcbinfo);
408		up = intoudpcb(last);
409		UDP_PROBE(receive, NULL, last, ip6, last, uh);
410		if (up->u_tun_func == NULL) {
411			udp6_append(last, m, off, &fromsa);
412		} else {
413			/*
414			 * Engage the tunneling protocol.
415			 */
416			(*up->u_tun_func)(m, off, last);
417		}
418		INP_RUNLOCK(last);
419		return (IPPROTO_DONE);
420	}
421	/*
422	 * Locate pcb for datagram.
423	 */
424
425	/*
426	 * Grab info from PACKET_TAG_IPFORWARD tag prepended to the chain.
427	 */
428	if ((m->m_flags & M_IP6_NEXTHOP) &&
429	    (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) {
430		struct sockaddr_in6 *next_hop6;
431
432		next_hop6 = (struct sockaddr_in6 *)(fwd_tag + 1);
433
434		/*
435		 * Transparently forwarded. Pretend to be the destination.
436		 * Already got one like this?
437		 */
438		inp = in6_pcblookup_mbuf(pcbinfo, &ip6->ip6_src,
439		    uh->uh_sport, &ip6->ip6_dst, uh->uh_dport,
440		    INPLOOKUP_RLOCKPCB, m->m_pkthdr.rcvif, m);
441		if (!inp) {
442			/*
443			 * It's new.  Try to find the ambushing socket.
444			 * Because we've rewritten the destination address,
445			 * any hardware-generated hash is ignored.
446			 */
447			inp = in6_pcblookup(pcbinfo, &ip6->ip6_src,
448			    uh->uh_sport, &next_hop6->sin6_addr,
449			    next_hop6->sin6_port ? htons(next_hop6->sin6_port) :
450			    uh->uh_dport, INPLOOKUP_WILDCARD |
451			    INPLOOKUP_RLOCKPCB, m->m_pkthdr.rcvif);
452		}
453		/* Remove the tag from the packet. We don't need it anymore. */
454		m_tag_delete(m, fwd_tag);
455		m->m_flags &= ~M_IP6_NEXTHOP;
456	} else
457		inp = in6_pcblookup_mbuf(pcbinfo, &ip6->ip6_src,
458		    uh->uh_sport, &ip6->ip6_dst, uh->uh_dport,
459		    INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB,
460		    m->m_pkthdr.rcvif, m);
461	if (inp == NULL) {
462		if (udp_log_in_vain) {
463			char ip6bufs[INET6_ADDRSTRLEN];
464			char ip6bufd[INET6_ADDRSTRLEN];
465
466			log(LOG_INFO,
467			    "Connection attempt to UDP [%s]:%d from [%s]:%d\n",
468			    ip6_sprintf(ip6bufd, &ip6->ip6_dst),
469			    ntohs(uh->uh_dport),
470			    ip6_sprintf(ip6bufs, &ip6->ip6_src),
471			    ntohs(uh->uh_sport));
472		}
473		UDPSTAT_INC(udps_noport);
474		if (m->m_flags & M_MCAST) {
475			printf("UDP6: M_MCAST is set in a unicast packet.\n");
476			UDPSTAT_INC(udps_noportmcast);
477			goto badunlocked;
478		}
479		if (V_udp_blackhole)
480			goto badunlocked;
481		if (badport_bandlim(BANDLIM_ICMP6_UNREACH) < 0)
482			goto badunlocked;
483		icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
484		return (IPPROTO_DONE);
485	}
486	INP_RLOCK_ASSERT(inp);
487	up = intoudpcb(inp);
488	if (cscov_partial) {
489		if (up->u_rxcslen == 0 || up->u_rxcslen > ulen) {
490			INP_RUNLOCK(inp);
491			m_freem(m);
492			return (IPPROTO_DONE);
493		}
494	}
495	UDP_PROBE(receive, NULL, inp, ip6, inp, uh);
496	if (up->u_tun_func == NULL) {
497		udp6_append(inp, m, off, &fromsa);
498	} else {
499		/*
500		 * Engage the tunneling protocol.
501		 */
502
503		(*up->u_tun_func)(m, off, inp);
504	}
505	INP_RUNLOCK(inp);
506	return (IPPROTO_DONE);
507
508badheadlocked:
509	INP_INFO_RUNLOCK(pcbinfo);
510badunlocked:
511	if (m)
512		m_freem(m);
513	return (IPPROTO_DONE);
514}
515
516static void
517udp6_common_ctlinput(int cmd, struct sockaddr *sa, void *d,
518    struct inpcbinfo *pcbinfo)
519{
520	struct udphdr uh;
521	struct ip6_hdr *ip6;
522	struct mbuf *m;
523	int off = 0;
524	struct ip6ctlparam *ip6cp = NULL;
525	const struct sockaddr_in6 *sa6_src = NULL;
526	void *cmdarg;
527	struct inpcb *(*notify)(struct inpcb *, int) = udp_notify;
528	struct udp_portonly {
529		u_int16_t uh_sport;
530		u_int16_t uh_dport;
531	} *uhp;
532
533	if (sa->sa_family != AF_INET6 ||
534	    sa->sa_len != sizeof(struct sockaddr_in6))
535		return;
536
537	if ((unsigned)cmd >= PRC_NCMDS)
538		return;
539	if (PRC_IS_REDIRECT(cmd))
540		notify = in6_rtchange, d = NULL;
541	else if (cmd == PRC_HOSTDEAD)
542		d = NULL;
543	else if (inet6ctlerrmap[cmd] == 0)
544		return;
545
546	/* if the parameter is from icmp6, decode it. */
547	if (d != NULL) {
548		ip6cp = (struct ip6ctlparam *)d;
549		m = ip6cp->ip6c_m;
550		ip6 = ip6cp->ip6c_ip6;
551		off = ip6cp->ip6c_off;
552		cmdarg = ip6cp->ip6c_cmdarg;
553		sa6_src = ip6cp->ip6c_src;
554	} else {
555		m = NULL;
556		ip6 = NULL;
557		cmdarg = NULL;
558		sa6_src = &sa6_any;
559	}
560
561	if (ip6) {
562		/*
563		 * XXX: We assume that when IPV6 is non NULL,
564		 * M and OFF are valid.
565		 */
566
567		/* Check if we can safely examine src and dst ports. */
568		if (m->m_pkthdr.len < off + sizeof(*uhp))
569			return;
570
571		bzero(&uh, sizeof(uh));
572		m_copydata(m, off, sizeof(*uhp), (caddr_t)&uh);
573
574		(void)in6_pcbnotify(pcbinfo, sa, uh.uh_dport,
575		    (struct sockaddr *)ip6cp->ip6c_src, uh.uh_sport, cmd,
576		    cmdarg, notify);
577	} else
578		(void)in6_pcbnotify(pcbinfo, sa, 0,
579		    (const struct sockaddr *)sa6_src, 0, cmd, cmdarg, notify);
580}
581
582void
583udp6_ctlinput(int cmd, struct sockaddr *sa, void *d)
584{
585
586	return (udp6_common_ctlinput(cmd, sa, d, &V_udbinfo));
587}
588
589void
590udplite6_ctlinput(int cmd, struct sockaddr *sa, void *d)
591{
592
593	return (udp6_common_ctlinput(cmd, sa, d, &V_ulitecbinfo));
594}
595
596static int
597udp6_getcred(SYSCTL_HANDLER_ARGS)
598{
599	struct xucred xuc;
600	struct sockaddr_in6 addrs[2];
601	struct inpcb *inp;
602	int error;
603
604	error = priv_check(req->td, PRIV_NETINET_GETCRED);
605	if (error)
606		return (error);
607
608	if (req->newlen != sizeof(addrs))
609		return (EINVAL);
610	if (req->oldlen != sizeof(struct xucred))
611		return (EINVAL);
612	error = SYSCTL_IN(req, addrs, sizeof(addrs));
613	if (error)
614		return (error);
615	if ((error = sa6_embedscope(&addrs[0], V_ip6_use_defzone)) != 0 ||
616	    (error = sa6_embedscope(&addrs[1], V_ip6_use_defzone)) != 0) {
617		return (error);
618	}
619	inp = in6_pcblookup(&V_udbinfo, &addrs[1].sin6_addr,
620	    addrs[1].sin6_port, &addrs[0].sin6_addr, addrs[0].sin6_port,
621	    INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB, NULL);
622	if (inp != NULL) {
623		INP_RLOCK_ASSERT(inp);
624		if (inp->inp_socket == NULL)
625			error = ENOENT;
626		if (error == 0)
627			error = cr_canseesocket(req->td->td_ucred,
628			    inp->inp_socket);
629		if (error == 0)
630			cru2x(inp->inp_cred, &xuc);
631		INP_RUNLOCK(inp);
632	} else
633		error = ENOENT;
634	if (error == 0)
635		error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
636	return (error);
637}
638
639SYSCTL_PROC(_net_inet6_udp6, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW, 0,
640    0, udp6_getcred, "S,xucred", "Get the xucred of a UDP6 connection");
641
642static int
643udp6_output(struct inpcb *inp, struct mbuf *m, struct sockaddr *addr6,
644    struct mbuf *control, struct thread *td)
645{
646	u_int32_t ulen = m->m_pkthdr.len;
647	u_int32_t plen = sizeof(struct udphdr) + ulen;
648	struct ip6_hdr *ip6;
649	struct udphdr *udp6;
650	struct in6_addr *laddr, *faddr, in6a;
651	struct sockaddr_in6 *sin6 = NULL;
652	struct ifnet *oifp = NULL;
653	int cscov_partial = 0;
654	int scope_ambiguous = 0;
655	u_short fport;
656	int error = 0;
657	uint8_t nxt;
658	uint16_t cscov = 0;
659	struct ip6_pktopts *optp, opt;
660	int af = AF_INET6, hlen = sizeof(struct ip6_hdr);
661	int flags;
662	struct sockaddr_in6 tmp;
663
664	INP_WLOCK_ASSERT(inp);
665	INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
666
667	if (addr6) {
668		/* addr6 has been validated in udp6_send(). */
669		sin6 = (struct sockaddr_in6 *)addr6;
670
671		/* protect *sin6 from overwrites */
672		tmp = *sin6;
673		sin6 = &tmp;
674
675		/*
676		 * Application should provide a proper zone ID or the use of
677		 * default zone IDs should be enabled.  Unfortunately, some
678		 * applications do not behave as it should, so we need a
679		 * workaround.  Even if an appropriate ID is not determined,
680		 * we'll see if we can determine the outgoing interface.  If we
681		 * can, determine the zone ID based on the interface below.
682		 */
683		if (sin6->sin6_scope_id == 0 && !V_ip6_use_defzone)
684			scope_ambiguous = 1;
685		if ((error = sa6_embedscope(sin6, V_ip6_use_defzone)) != 0)
686			return (error);
687	}
688
689	if (control) {
690		if ((error = ip6_setpktopts(control, &opt,
691		    inp->in6p_outputopts, td->td_ucred, IPPROTO_UDP)) != 0)
692			goto release;
693		optp = &opt;
694	} else
695		optp = inp->in6p_outputopts;
696
697	if (sin6) {
698		faddr = &sin6->sin6_addr;
699
700		/*
701		 * Since we saw no essential reason for calling in_pcbconnect,
702		 * we get rid of such kind of logic, and call in6_selectsrc
703		 * and in6_pcbsetport in order to fill in the local address
704		 * and the local port.
705		 */
706		if (sin6->sin6_port == 0) {
707			error = EADDRNOTAVAIL;
708			goto release;
709		}
710
711		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
712			/* how about ::ffff:0.0.0.0 case? */
713			error = EISCONN;
714			goto release;
715		}
716
717		fport = sin6->sin6_port; /* allow 0 port */
718
719		if (IN6_IS_ADDR_V4MAPPED(faddr)) {
720			if ((inp->inp_flags & IN6P_IPV6_V6ONLY)) {
721				/*
722				 * I believe we should explicitly discard the
723				 * packet when mapped addresses are disabled,
724				 * rather than send the packet as an IPv6 one.
725				 * If we chose the latter approach, the packet
726				 * might be sent out on the wire based on the
727				 * default route, the situation which we'd
728				 * probably want to avoid.
729				 * (20010421 jinmei@kame.net)
730				 */
731				error = EINVAL;
732				goto release;
733			}
734			if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) &&
735			    !IN6_IS_ADDR_V4MAPPED(&inp->in6p_laddr)) {
736				/*
737				 * when remote addr is an IPv4-mapped address,
738				 * local addr should not be an IPv6 address,
739				 * since you cannot determine how to map IPv6
740				 * source address to IPv4.
741				 */
742				error = EINVAL;
743				goto release;
744			}
745
746			af = AF_INET;
747		}
748
749		if (!IN6_IS_ADDR_V4MAPPED(faddr)) {
750			error = in6_selectsrc(sin6, optp, inp, NULL,
751			    td->td_ucred, &oifp, &in6a);
752			if (error)
753				goto release;
754			if (oifp && scope_ambiguous &&
755			    (error = in6_setscope(&sin6->sin6_addr,
756			    oifp, NULL))) {
757				goto release;
758			}
759			laddr = &in6a;
760		} else
761			laddr = &inp->in6p_laddr;	/* XXX */
762		if (laddr == NULL) {
763			if (error == 0)
764				error = EADDRNOTAVAIL;
765			goto release;
766		}
767		if (inp->inp_lport == 0 &&
768		    (error = in6_pcbsetport(laddr, inp, td->td_ucred)) != 0) {
769			/* Undo an address bind that may have occurred. */
770			inp->in6p_laddr = in6addr_any;
771			goto release;
772		}
773	} else {
774		if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
775			error = ENOTCONN;
776			goto release;
777		}
778		if (IN6_IS_ADDR_V4MAPPED(&inp->in6p_faddr)) {
779			if ((inp->inp_flags & IN6P_IPV6_V6ONLY)) {
780				/*
781				 * XXX: this case would happen when the
782				 * application sets the V6ONLY flag after
783				 * connecting the foreign address.
784				 * Such applications should be fixed,
785				 * so we bark here.
786				 */
787				log(LOG_INFO, "udp6_output: IPV6_V6ONLY "
788				    "option was set for a connected socket\n");
789				error = EINVAL;
790				goto release;
791			} else
792				af = AF_INET;
793		}
794		laddr = &inp->in6p_laddr;
795		faddr = &inp->in6p_faddr;
796		fport = inp->inp_fport;
797	}
798
799	if (af == AF_INET)
800		hlen = sizeof(struct ip);
801
802	/*
803	 * Calculate data length and get a mbuf
804	 * for UDP and IP6 headers.
805	 */
806	M_PREPEND(m, hlen + sizeof(struct udphdr), M_NOWAIT);
807	if (m == 0) {
808		error = ENOBUFS;
809		goto release;
810	}
811
812	/*
813	 * Stuff checksum and output datagram.
814	 */
815	nxt = (inp->inp_socket->so_proto->pr_protocol == IPPROTO_UDP) ?
816	    IPPROTO_UDP : IPPROTO_UDPLITE;
817	udp6 = (struct udphdr *)(mtod(m, caddr_t) + hlen);
818	udp6->uh_sport = inp->inp_lport; /* lport is always set in the PCB */
819	udp6->uh_dport = fport;
820	if (nxt == IPPROTO_UDPLITE) {
821		struct udpcb *up;
822
823		up = intoudpcb(inp);
824		cscov = up->u_txcslen;
825		if (cscov >= plen)
826			cscov = 0;
827		udp6->uh_ulen = htons(cscov);
828		/*
829		 * For UDP-Lite, checksum coverage length of zero means
830		 * the entire UDPLite packet is covered by the checksum.
831		 */
832		cscov_partial = (cscov == 0) ? 0 : 1;
833	} else if (plen <= 0xffff)
834		udp6->uh_ulen = htons((u_short)plen);
835	else
836		udp6->uh_ulen = 0;
837	udp6->uh_sum = 0;
838
839	switch (af) {
840	case AF_INET6:
841		ip6 = mtod(m, struct ip6_hdr *);
842		ip6->ip6_flow	= inp->inp_flow & IPV6_FLOWINFO_MASK;
843		ip6->ip6_vfc	&= ~IPV6_VERSION_MASK;
844		ip6->ip6_vfc	|= IPV6_VERSION;
845		ip6->ip6_plen	= htons((u_short)plen);
846		ip6->ip6_nxt	= nxt;
847		ip6->ip6_hlim	= in6_selecthlim(inp, NULL);
848		ip6->ip6_src	= *laddr;
849		ip6->ip6_dst	= *faddr;
850
851		if (cscov_partial) {
852			if ((udp6->uh_sum = in6_cksum_partial(m, nxt,
853			    sizeof(struct ip6_hdr), plen, cscov)) == 0)
854				udp6->uh_sum = 0xffff;
855		} else {
856			udp6->uh_sum = in6_cksum_pseudo(ip6, plen, nxt, 0);
857			m->m_pkthdr.csum_flags = CSUM_UDP_IPV6;
858			m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
859		}
860
861		/*
862		 * XXX for now assume UDP is 2-tuple.
863		 * Later on this may become configurable as 4-tuple;
864		 * we should support that.
865		 *
866		 * XXX .. and we should likely cache this in the inpcb.
867		 */
868#ifdef	RSS
869		m->m_pkthdr.flowid = rss_hash_ip6_2tuple(*faddr, *laddr);
870		m->m_flags |= M_FLOWID;
871		M_HASHTYPE_SET(m, M_HASHTYPE_RSS_IPV6);
872#endif
873		flags = 0;
874
875#ifdef	RSS
876		/*
877		 * Don't override with the inp cached flowid.
878		 *
879		 * Until the whole UDP path is vetted, it may actually
880		 * be incorrect.
881		 */
882		flags |= IP_NODEFAULTFLOWID;
883#endif
884
885		UDP_PROBE(send, NULL, inp, ip6, inp, udp6);
886		UDPSTAT_INC(udps_opackets);
887		error = ip6_output(m, optp, NULL, flags, inp->in6p_moptions,
888		    NULL, inp);
889		break;
890	case AF_INET:
891		error = EAFNOSUPPORT;
892		goto release;
893	}
894	goto releaseopt;
895
896release:
897	m_freem(m);
898
899releaseopt:
900	if (control) {
901		ip6_clearpktopts(&opt, -1);
902		m_freem(control);
903	}
904	return (error);
905}
906
907static void
908udp6_abort(struct socket *so)
909{
910	struct inpcb *inp;
911	struct inpcbinfo *pcbinfo;
912
913	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
914	inp = sotoinpcb(so);
915	KASSERT(inp != NULL, ("udp6_abort: inp == NULL"));
916
917#ifdef INET
918	if (inp->inp_vflag & INP_IPV4) {
919		struct pr_usrreqs *pru;
920
921		pru = inetsw[ip_protox[IPPROTO_UDP]].pr_usrreqs;
922		(*pru->pru_abort)(so);
923		return;
924	}
925#endif
926
927	INP_WLOCK(inp);
928	if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
929		INP_HASH_WLOCK(pcbinfo);
930		in6_pcbdisconnect(inp);
931		inp->in6p_laddr = in6addr_any;
932		INP_HASH_WUNLOCK(pcbinfo);
933		soisdisconnected(so);
934	}
935	INP_WUNLOCK(inp);
936}
937
938static int
939udp6_attach(struct socket *so, int proto, struct thread *td)
940{
941	struct inpcb *inp;
942	struct inpcbinfo *pcbinfo;
943	int error;
944
945	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
946	inp = sotoinpcb(so);
947	KASSERT(inp == NULL, ("udp6_attach: inp != NULL"));
948
949	if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
950		error = soreserve(so, udp_sendspace, udp_recvspace);
951		if (error)
952			return (error);
953	}
954	INP_INFO_WLOCK(pcbinfo);
955	error = in_pcballoc(so, pcbinfo);
956	if (error) {
957		INP_INFO_WUNLOCK(pcbinfo);
958		return (error);
959	}
960	inp = (struct inpcb *)so->so_pcb;
961	inp->inp_vflag |= INP_IPV6;
962	if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
963		inp->inp_vflag |= INP_IPV4;
964	inp->in6p_hops = -1;	/* use kernel default */
965	inp->in6p_cksum = -1;	/* just to be sure */
966	/*
967	 * XXX: ugly!!
968	 * IPv4 TTL initialization is necessary for an IPv6 socket as well,
969	 * because the socket may be bound to an IPv6 wildcard address,
970	 * which may match an IPv4-mapped IPv6 address.
971	 */
972	inp->inp_ip_ttl = V_ip_defttl;
973
974	error = udp_newudpcb(inp);
975	if (error) {
976		in_pcbdetach(inp);
977		in_pcbfree(inp);
978		INP_INFO_WUNLOCK(pcbinfo);
979		return (error);
980	}
981	INP_WUNLOCK(inp);
982	INP_INFO_WUNLOCK(pcbinfo);
983	return (0);
984}
985
986static int
987udp6_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
988{
989	struct inpcb *inp;
990	struct inpcbinfo *pcbinfo;
991	int error;
992
993	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
994	inp = sotoinpcb(so);
995	KASSERT(inp != NULL, ("udp6_bind: inp == NULL"));
996
997	INP_WLOCK(inp);
998	INP_HASH_WLOCK(pcbinfo);
999	inp->inp_vflag &= ~INP_IPV4;
1000	inp->inp_vflag |= INP_IPV6;
1001	if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
1002		struct sockaddr_in6 *sin6_p;
1003
1004		sin6_p = (struct sockaddr_in6 *)nam;
1005
1006		if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr))
1007			inp->inp_vflag |= INP_IPV4;
1008#ifdef INET
1009		else if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
1010			struct sockaddr_in sin;
1011
1012			in6_sin6_2_sin(&sin, sin6_p);
1013			inp->inp_vflag |= INP_IPV4;
1014			inp->inp_vflag &= ~INP_IPV6;
1015			error = in_pcbbind(inp, (struct sockaddr *)&sin,
1016			    td->td_ucred);
1017			goto out;
1018		}
1019#endif
1020	}
1021
1022	error = in6_pcbbind(inp, nam, td->td_ucred);
1023#ifdef INET
1024out:
1025#endif
1026	INP_HASH_WUNLOCK(pcbinfo);
1027	INP_WUNLOCK(inp);
1028	return (error);
1029}
1030
1031static void
1032udp6_close(struct socket *so)
1033{
1034	struct inpcb *inp;
1035	struct inpcbinfo *pcbinfo;
1036
1037	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
1038	inp = sotoinpcb(so);
1039	KASSERT(inp != NULL, ("udp6_close: inp == NULL"));
1040
1041#ifdef INET
1042	if (inp->inp_vflag & INP_IPV4) {
1043		struct pr_usrreqs *pru;
1044
1045		pru = inetsw[ip_protox[IPPROTO_UDP]].pr_usrreqs;
1046		(*pru->pru_disconnect)(so);
1047		return;
1048	}
1049#endif
1050	INP_WLOCK(inp);
1051	if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
1052		INP_HASH_WLOCK(pcbinfo);
1053		in6_pcbdisconnect(inp);
1054		inp->in6p_laddr = in6addr_any;
1055		INP_HASH_WUNLOCK(pcbinfo);
1056		soisdisconnected(so);
1057	}
1058	INP_WUNLOCK(inp);
1059}
1060
1061static int
1062udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
1063{
1064	struct inpcb *inp;
1065	struct inpcbinfo *pcbinfo;
1066	struct sockaddr_in6 *sin6;
1067	int error;
1068
1069	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
1070	inp = sotoinpcb(so);
1071	sin6 = (struct sockaddr_in6 *)nam;
1072	KASSERT(inp != NULL, ("udp6_connect: inp == NULL"));
1073
1074	/*
1075	 * XXXRW: Need to clarify locking of v4/v6 flags.
1076	 */
1077	INP_WLOCK(inp);
1078#ifdef INET
1079	if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1080		struct sockaddr_in sin;
1081
1082		if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1083			error = EINVAL;
1084			goto out;
1085		}
1086		if (inp->inp_faddr.s_addr != INADDR_ANY) {
1087			error = EISCONN;
1088			goto out;
1089		}
1090		in6_sin6_2_sin(&sin, sin6);
1091		inp->inp_vflag |= INP_IPV4;
1092		inp->inp_vflag &= ~INP_IPV6;
1093		error = prison_remote_ip4(td->td_ucred, &sin.sin_addr);
1094		if (error != 0)
1095			goto out;
1096		INP_HASH_WLOCK(pcbinfo);
1097		error = in_pcbconnect(inp, (struct sockaddr *)&sin,
1098		    td->td_ucred);
1099		INP_HASH_WUNLOCK(pcbinfo);
1100		if (error == 0)
1101			soisconnected(so);
1102		goto out;
1103	}
1104#endif
1105	if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
1106		error = EISCONN;
1107		goto out;
1108	}
1109	inp->inp_vflag &= ~INP_IPV4;
1110	inp->inp_vflag |= INP_IPV6;
1111	error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr);
1112	if (error != 0)
1113		goto out;
1114	INP_HASH_WLOCK(pcbinfo);
1115	error = in6_pcbconnect(inp, nam, td->td_ucred);
1116	INP_HASH_WUNLOCK(pcbinfo);
1117	if (error == 0)
1118		soisconnected(so);
1119out:
1120	INP_WUNLOCK(inp);
1121	return (error);
1122}
1123
1124static void
1125udp6_detach(struct socket *so)
1126{
1127	struct inpcb *inp;
1128	struct inpcbinfo *pcbinfo;
1129	struct udpcb *up;
1130
1131	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
1132	inp = sotoinpcb(so);
1133	KASSERT(inp != NULL, ("udp6_detach: inp == NULL"));
1134
1135	INP_INFO_WLOCK(pcbinfo);
1136	INP_WLOCK(inp);
1137	up = intoudpcb(inp);
1138	KASSERT(up != NULL, ("%s: up == NULL", __func__));
1139	in_pcbdetach(inp);
1140	in_pcbfree(inp);
1141	INP_INFO_WUNLOCK(pcbinfo);
1142	udp_discardcb(up);
1143}
1144
1145static int
1146udp6_disconnect(struct socket *so)
1147{
1148	struct inpcb *inp;
1149	struct inpcbinfo *pcbinfo;
1150	int error;
1151
1152	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
1153	inp = sotoinpcb(so);
1154	KASSERT(inp != NULL, ("udp6_disconnect: inp == NULL"));
1155
1156#ifdef INET
1157	if (inp->inp_vflag & INP_IPV4) {
1158		struct pr_usrreqs *pru;
1159
1160		pru = inetsw[ip_protox[IPPROTO_UDP]].pr_usrreqs;
1161		(void)(*pru->pru_disconnect)(so);
1162		return (0);
1163	}
1164#endif
1165
1166	INP_WLOCK(inp);
1167
1168	if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
1169		error = ENOTCONN;
1170		goto out;
1171	}
1172
1173	INP_HASH_WLOCK(pcbinfo);
1174	in6_pcbdisconnect(inp);
1175	inp->in6p_laddr = in6addr_any;
1176	INP_HASH_WUNLOCK(pcbinfo);
1177	SOCK_LOCK(so);
1178	so->so_state &= ~SS_ISCONNECTED;		/* XXX */
1179	SOCK_UNLOCK(so);
1180out:
1181	INP_WUNLOCK(inp);
1182	return (0);
1183}
1184
1185static int
1186udp6_send(struct socket *so, int flags, struct mbuf *m,
1187    struct sockaddr *addr, struct mbuf *control, struct thread *td)
1188{
1189	struct inpcb *inp;
1190	struct inpcbinfo *pcbinfo;
1191	int error = 0;
1192
1193	pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
1194	inp = sotoinpcb(so);
1195	KASSERT(inp != NULL, ("udp6_send: inp == NULL"));
1196
1197	INP_WLOCK(inp);
1198	if (addr) {
1199		if (addr->sa_len != sizeof(struct sockaddr_in6)) {
1200			error = EINVAL;
1201			goto bad;
1202		}
1203		if (addr->sa_family != AF_INET6) {
1204			error = EAFNOSUPPORT;
1205			goto bad;
1206		}
1207	}
1208
1209#ifdef INET
1210	if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
1211		int hasv4addr;
1212		struct sockaddr_in6 *sin6 = 0;
1213
1214		if (addr == 0)
1215			hasv4addr = (inp->inp_vflag & INP_IPV4);
1216		else {
1217			sin6 = (struct sockaddr_in6 *)addr;
1218			hasv4addr = IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)
1219			    ? 1 : 0;
1220		}
1221		if (hasv4addr) {
1222			struct pr_usrreqs *pru;
1223
1224			/*
1225			 * XXXRW: We release UDP-layer locks before calling
1226			 * udp_send() in order to avoid recursion.  However,
1227			 * this does mean there is a short window where inp's
1228			 * fields are unstable.  Could this lead to a
1229			 * potential race in which the factors causing us to
1230			 * select the UDPv4 output routine are invalidated?
1231			 */
1232			INP_WUNLOCK(inp);
1233			if (sin6)
1234				in6_sin6_2_sin_in_sock(addr);
1235			pru = inetsw[ip_protox[IPPROTO_UDP]].pr_usrreqs;
1236			/* addr will just be freed in sendit(). */
1237			return ((*pru->pru_send)(so, flags, m, addr, control,
1238			    td));
1239		}
1240	}
1241#endif
1242#ifdef MAC
1243	mac_inpcb_create_mbuf(inp, m);
1244#endif
1245	INP_HASH_WLOCK(pcbinfo);
1246	error = udp6_output(inp, m, addr, control, td);
1247	INP_HASH_WUNLOCK(pcbinfo);
1248#ifdef INET
1249#endif
1250	INP_WUNLOCK(inp);
1251	return (error);
1252
1253bad:
1254	INP_WUNLOCK(inp);
1255	m_freem(m);
1256	return (error);
1257}
1258
1259struct pr_usrreqs udp6_usrreqs = {
1260	.pru_abort =		udp6_abort,
1261	.pru_attach =		udp6_attach,
1262	.pru_bind =		udp6_bind,
1263	.pru_connect =		udp6_connect,
1264	.pru_control =		in6_control,
1265	.pru_detach =		udp6_detach,
1266	.pru_disconnect =	udp6_disconnect,
1267	.pru_peeraddr =		in6_mapped_peeraddr,
1268	.pru_send =		udp6_send,
1269	.pru_shutdown =		udp_shutdown,
1270	.pru_sockaddr =		in6_mapped_sockaddr,
1271	.pru_soreceive =	soreceive_dgram,
1272	.pru_sosend =		sosend_dgram,
1273	.pru_sosetlabel =	in_pcbsosetlabel,
1274	.pru_close =		udp6_close
1275};
1276