Home | History | Annotate | Line # | Download | only in netinet6
udp6_usrreq.c revision 1.91.4.3
      1  1.91.4.3     rmind /*	$NetBSD: udp6_usrreq.c,v 1.91.4.3 2014/05/18 17:46:13 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.91.4.3     rmind __KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.91.4.3 2014/05/18 17:46:13 rmind Exp $");
     66      1.90  christos 
     67      1.90  christos #include "opt_inet.h"
     68  1.91.4.1     rmind #include "opt_inet_csum.h"
     69       1.2    itojun 
     70       1.2    itojun #include <sys/param.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/systm.h>
     76       1.2    itojun #include <sys/proc.h>
     77       1.8    itojun #include <sys/syslog.h>
     78      1.90  christos #include <sys/domain.h>
     79      1.50    simonb #include <sys/sysctl.h>
     80       1.2    itojun 
     81       1.2    itojun #include <net/if.h>
     82       1.2    itojun #include <net/route.h>
     83       1.2    itojun #include <net/if_types.h>
     84       1.2    itojun 
     85       1.2    itojun #include <netinet/in.h>
     86       1.2    itojun #include <netinet/in_var.h>
     87      1.14    itojun #include <netinet/in_systm.h>
     88  1.91.4.1     rmind #include <netinet/in_offload.h>
     89      1.14    itojun #include <netinet/ip.h>
     90      1.14    itojun #include <netinet/ip_var.h>
     91  1.91.4.1     rmind #define __INPCB_PRIVATE
     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.91.4.1     rmind #include <netinet/udp_private.h>
     96  1.91.4.1     rmind 
     97      1.23    itojun #include <netinet/ip6.h>
     98  1.91.4.1     rmind #include <netinet/icmp6.h>
     99      1.27    itojun #include <netinet6/ip6_var.h>
    100  1.91.4.1     rmind #include <netinet6/ip6_private.h>
    101       1.2    itojun #include <netinet6/in6_pcb.h>
    102       1.2    itojun #include <netinet6/udp6_var.h>
    103      1.82   thorpej #include <netinet6/udp6_private.h>
    104      1.14    itojun #include <netinet6/ip6protosw.h>
    105  1.91.4.1     rmind #include <netinet6/scope6_var.h>
    106       1.2    itojun 
    107       1.2    itojun #include "faith.h"
    108      1.41    itojun #if defined(NFAITH) && NFAITH > 0
    109      1.41    itojun #include <net/if_faith.h>
    110      1.41    itojun #endif
    111       1.2    itojun 
    112       1.2    itojun /*
    113      1.73    rpaulo  * UDP protocol implementation.
    114       1.2    itojun  * Per RFC 768, August, 1980.
    115       1.2    itojun  */
    116       1.2    itojun 
    117  1.91.4.1     rmind extern inpcbtable_t *	udbtable;
    118      1.82   thorpej 
    119  1.91.4.1     rmind percpu_t *		udp6stat_percpu;
    120       1.2    itojun 
    121      1.78    dyoung static	void udp6_notify(struct in6pcb *, int);
    122      1.88     pooka static	void sysctl_net_inet6_udp6_setup(struct sysctllog **);
    123       1.2    itojun 
    124  1.91.4.1     rmind #ifdef UDP_CSUM_COUNTERS
    125  1.91.4.1     rmind #include <sys/device.h>
    126  1.91.4.1     rmind 
    127  1.91.4.1     rmind struct evcnt udp6_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
    128  1.91.4.1     rmind     NULL, "udp6", "hwcsum bad");
    129  1.91.4.1     rmind struct evcnt udp6_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
    130  1.91.4.1     rmind     NULL, "udp6", "hwcsum ok");
    131  1.91.4.1     rmind struct evcnt udp6_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
    132  1.91.4.1     rmind     NULL, "udp6", "hwcsum data");
    133  1.91.4.1     rmind struct evcnt udp6_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
    134  1.91.4.1     rmind     NULL, "udp6", "swcsum");
    135  1.91.4.1     rmind 
    136  1.91.4.1     rmind EVCNT_ATTACH_STATIC(udp6_hwcsum_bad);
    137  1.91.4.1     rmind EVCNT_ATTACH_STATIC(udp6_hwcsum_ok);
    138  1.91.4.1     rmind EVCNT_ATTACH_STATIC(udp6_hwcsum_data);
    139  1.91.4.1     rmind EVCNT_ATTACH_STATIC(udp6_swcsum);
    140  1.91.4.1     rmind 
    141  1.91.4.1     rmind #define	UDP_CSUM_COUNTER_INCR(ev)	(ev)->ev_count++
    142  1.91.4.1     rmind #else
    143  1.91.4.1     rmind #define	UDP_CSUM_COUNTER_INCR(ev)	/* nothing */
    144  1.91.4.1     rmind #endif /* UDP_CSUM_COUNTERS */
    145  1.91.4.1     rmind 
    146       1.2    itojun void
    147      1.81      matt udp6_init(void)
    148       1.2    itojun {
    149      1.88     pooka 	sysctl_net_inet6_udp6_setup(NULL);
    150  1.91.4.1     rmind 	udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS);
    151  1.91.4.3     rmind 
    152  1.91.4.3     rmind 	udp_init_common();
    153       1.2    itojun }
    154       1.2    itojun 
    155       1.2    itojun /*
    156       1.2    itojun  * Notify a udp user of an asynchronous error;
    157      1.27    itojun  * just wake up so that he can collect error status.
    158       1.2    itojun  */
    159       1.2    itojun static	void
    160      1.76    dyoung udp6_notify(struct in6pcb *in6p, int errno)
    161       1.2    itojun {
    162       1.2    itojun 	in6p->in6p_socket->so_error = errno;
    163       1.2    itojun 	sorwakeup(in6p->in6p_socket);
    164       1.2    itojun 	sowwakeup(in6p->in6p_socket);
    165       1.2    itojun }
    166       1.2    itojun 
    167      1.84        ad void *
    168      1.76    dyoung udp6_ctlinput(int cmd, const struct sockaddr *sa, void *d)
    169       1.2    itojun {
    170       1.2    itojun 	struct udphdr uh;
    171      1.39    itojun 	struct ip6_hdr *ip6;
    172      1.76    dyoung 	const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *)sa;
    173      1.14    itojun 	struct mbuf *m;
    174      1.14    itojun 	int off;
    175      1.40    itojun 	void *cmdarg;
    176      1.40    itojun 	struct ip6ctlparam *ip6cp = NULL;
    177      1.40    itojun 	const struct sockaddr_in6 *sa6_src = NULL;
    178      1.76    dyoung 	void (*notify)(struct in6pcb *, int) = udp6_notify;
    179      1.40    itojun 	struct udp_portonly {
    180      1.40    itojun 		u_int16_t uh_sport;
    181      1.40    itojun 		u_int16_t uh_dport;
    182      1.40    itojun 	} *uhp;
    183       1.2    itojun 
    184      1.10    itojun 	if (sa->sa_family != AF_INET6 ||
    185      1.10    itojun 	    sa->sa_len != sizeof(struct sockaddr_in6))
    186      1.84        ad 		return NULL;
    187      1.14    itojun 
    188      1.25    itojun 	if ((unsigned)cmd >= PRC_NCMDS)
    189      1.84        ad 		return NULL;
    190      1.25    itojun 	if (PRC_IS_REDIRECT(cmd))
    191      1.25    itojun 		notify = in6_rtchange, d = NULL;
    192      1.25    itojun 	else if (cmd == PRC_HOSTDEAD)
    193      1.25    itojun 		d = NULL;
    194      1.47    itojun 	else if (cmd == PRC_MSGSIZE) {
    195      1.47    itojun 		/* special code is present, see below */
    196      1.47    itojun 		notify = in6_rtchange;
    197      1.47    itojun 	}
    198      1.25    itojun 	else if (inet6ctlerrmap[cmd] == 0)
    199      1.84        ad 		return NULL;
    200       1.7    itojun 
    201      1.14    itojun 	/* if the parameter is from icmp6, decode it. */
    202      1.14    itojun 	if (d != NULL) {
    203      1.40    itojun 		ip6cp = (struct ip6ctlparam *)d;
    204      1.14    itojun 		m = ip6cp->ip6c_m;
    205      1.14    itojun 		ip6 = ip6cp->ip6c_ip6;
    206      1.14    itojun 		off = ip6cp->ip6c_off;
    207      1.40    itojun 		cmdarg = ip6cp->ip6c_cmdarg;
    208      1.40    itojun 		sa6_src = ip6cp->ip6c_src;
    209      1.14    itojun 	} else {
    210      1.14    itojun 		m = NULL;
    211      1.14    itojun 		ip6 = NULL;
    212      1.40    itojun 		cmdarg = NULL;
    213      1.40    itojun 		sa6_src = &sa6_any;
    214      1.60  christos 		off = 0;
    215      1.14    itojun 	}
    216      1.14    itojun 
    217       1.2    itojun 	if (ip6) {
    218       1.2    itojun 		/*
    219       1.2    itojun 		 * XXX: We assume that when IPV6 is non NULL,
    220       1.2    itojun 		 * M and OFF are valid.
    221       1.2    itojun 		 */
    222      1.33    itojun 
    223      1.33    itojun 		/* check if we can safely examine src and dst ports */
    224      1.42    itojun 		if (m->m_pkthdr.len < off + sizeof(*uhp)) {
    225      1.42    itojun 			if (cmd == PRC_MSGSIZE)
    226      1.42    itojun 				icmp6_mtudisc_update((struct ip6ctlparam *)d, 0);
    227      1.84        ad 			return NULL;
    228      1.42    itojun 		}
    229       1.7    itojun 
    230      1.87    cegger 		memset(&uh, 0, sizeof(uh));
    231      1.77  christos 		m_copydata(m, off, sizeof(*uhp), (void *)&uh);
    232      1.34    itojun 
    233      1.34    itojun 		if (cmd == PRC_MSGSIZE) {
    234      1.36    itojun 			int valid = 0;
    235      1.40    itojun 
    236      1.34    itojun 			/*
    237      1.34    itojun 			 * Check to see if we have a valid UDP socket
    238      1.34    itojun 			 * corresponding to the address in the ICMPv6 message
    239      1.34    itojun 			 * payload.
    240      1.34    itojun 			 */
    241  1.91.4.1     rmind 			if (in6_pcblookup_connect(udbtable, &sa6->sin6_addr,
    242      1.68  christos 			    uh.uh_dport, (const struct in6_addr *)&sa6_src->sin6_addr,
    243      1.89    dyoung 						  uh.uh_sport, 0, 0))
    244      1.36    itojun 				valid++;
    245      1.34    itojun #if 0
    246      1.34    itojun 			/*
    247      1.34    itojun 			 * As the use of sendto(2) is fairly popular,
    248      1.34    itojun 			 * we may want to allow non-connected pcb too.
    249      1.34    itojun 			 * But it could be too weak against attacks...
    250      1.34    itojun 			 * We should at least check if the local address (= s)
    251      1.34    itojun 			 * is really ours.
    252      1.34    itojun 			 */
    253  1.91.4.1     rmind 			else if (in6_pcblookup_bind(udbtable, &sa6->sin6_addr,
    254      1.58    itojun 			    uh.uh_dport, 0))
    255      1.36    itojun 				valid++;
    256      1.34    itojun #endif
    257      1.34    itojun 
    258      1.34    itojun 			/*
    259      1.40    itojun 			 * Depending on the value of "valid" and routing table
    260      1.40    itojun 			 * size (mtudisc_{hi,lo}wat), we will:
    261      1.46    itojun 			 * - recalculate the new MTU and create the
    262      1.40    itojun 			 *   corresponding routing entry, or
    263      1.40    itojun 			 * - ignore the MTU change notification.
    264      1.34    itojun 			 */
    265      1.36    itojun 			icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
    266      1.34    itojun 
    267      1.40    itojun 			/*
    268      1.74    rpaulo 			 * regardless of if we called
    269      1.74    rpaulo 			 * icmp6_mtudisc_update(), we need to call
    270      1.74    rpaulo 			 * in6_pcbnotify(), to notify path MTU change
    271      1.74    rpaulo 			 * to the userland (RFC3542), because some
    272      1.74    rpaulo 			 * unconnected sockets may share the same
    273      1.40    itojun 			 * destination and want to know the path MTU.
    274      1.40    itojun 			 */
    275      1.34    itojun 		}
    276      1.34    itojun 
    277  1.91.4.1     rmind 		(void) in6_pcbnotify(udbtable, sa, uh.uh_dport,
    278      1.68  christos 		    (const struct sockaddr *)sa6_src, uh.uh_sport, cmd, cmdarg,
    279      1.40    itojun 		    notify);
    280       1.2    itojun 	} else {
    281  1.91.4.1     rmind 		(void) in6_pcbnotify(udbtable, sa, 0,
    282      1.68  christos 		    (const struct sockaddr *)sa6_src, 0, cmd, cmdarg, notify);
    283       1.2    itojun 	}
    284      1.84        ad 	return NULL;
    285       1.2    itojun }
    286       1.2    itojun 
    287      1.90  christos int
    288      1.90  christos udp6_ctloutput(int op, struct socket *so, struct sockopt *sopt)
    289      1.90  christos {
    290      1.90  christos 	int s;
    291      1.90  christos 	int error = 0;
    292      1.90  christos 	int family;
    293      1.90  christos 
    294      1.90  christos 	family = so->so_proto->pr_domain->dom_family;
    295      1.90  christos 
    296      1.90  christos 	s = splsoftnet();
    297      1.90  christos 	switch (family) {
    298      1.90  christos #ifdef INET
    299      1.90  christos 	case PF_INET:
    300      1.90  christos 		if (sopt->sopt_level != IPPROTO_UDP) {
    301      1.90  christos 			error = ip_ctloutput(op, so, sopt);
    302      1.90  christos 			goto end;
    303      1.90  christos 		}
    304      1.90  christos 		break;
    305      1.90  christos #endif
    306      1.90  christos #ifdef INET6
    307      1.90  christos 	case PF_INET6:
    308      1.90  christos 		if (sopt->sopt_level != IPPROTO_UDP) {
    309      1.90  christos 			error = ip6_ctloutput(op, so, sopt);
    310      1.90  christos 			goto end;
    311      1.90  christos 		}
    312      1.90  christos 		break;
    313      1.90  christos #endif
    314      1.90  christos 	default:
    315      1.90  christos 		error = EAFNOSUPPORT;
    316      1.90  christos 		goto end;
    317      1.90  christos 	}
    318      1.91  christos 	error = EINVAL;
    319      1.90  christos 
    320      1.90  christos end:
    321      1.90  christos 	splx(s);
    322      1.90  christos 	return error;
    323      1.90  christos }
    324      1.90  christos 
    325  1.91.4.1     rmind static void
    326  1.91.4.1     rmind udp6_sendup(struct mbuf *m, int off /* offset of data portion */,
    327  1.91.4.1     rmind 	struct sockaddr *src, struct socket *so)
    328  1.91.4.1     rmind {
    329  1.91.4.1     rmind 	struct mbuf *opts = NULL;
    330  1.91.4.1     rmind 	struct mbuf *n;
    331  1.91.4.1     rmind 	struct in6pcb *in6p = NULL;
    332  1.91.4.1     rmind 
    333  1.91.4.1     rmind 	if (!so)
    334  1.91.4.1     rmind 		return;
    335  1.91.4.1     rmind 	if (so->so_proto->pr_domain->dom_family != AF_INET6)
    336  1.91.4.1     rmind 		return;
    337  1.91.4.1     rmind 	in6p = sotoin6pcb(so);
    338  1.91.4.1     rmind 
    339  1.91.4.1     rmind #if defined(IPSEC)
    340  1.91.4.1     rmind 	/* check AH/ESP integrity. */
    341  1.91.4.1     rmind 	if (so != NULL && ipsec6_in_reject_so(m, so)) {
    342  1.91.4.1     rmind 		IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO);
    343  1.91.4.1     rmind 		if ((n = m_copypacket(m, M_DONTWAIT)) != NULL)
    344  1.91.4.1     rmind 			icmp6_error(n, ICMP6_DST_UNREACH,
    345  1.91.4.1     rmind 			    ICMP6_DST_UNREACH_ADMIN, 0);
    346  1.91.4.1     rmind 		return;
    347  1.91.4.1     rmind 	}
    348  1.91.4.1     rmind #endif /*IPSEC*/
    349  1.91.4.1     rmind 
    350  1.91.4.1     rmind 	if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
    351  1.91.4.1     rmind 		if (in6p && (in6p->in6p_flags & IN6P_CONTROLOPTS
    352  1.91.4.1     rmind #ifdef SO_OTIMESTAMP
    353  1.91.4.1     rmind 		    || in6p->in6p_socket->so_options & SO_OTIMESTAMP
    354  1.91.4.1     rmind #endif
    355  1.91.4.1     rmind 		    || in6p->in6p_socket->so_options & SO_TIMESTAMP)) {
    356  1.91.4.1     rmind 			struct ip6_hdr *ip6 = mtod(n, struct ip6_hdr *);
    357  1.91.4.1     rmind 			ip6_savecontrol(in6p, &opts, ip6, n);
    358  1.91.4.1     rmind 		}
    359  1.91.4.1     rmind 
    360  1.91.4.1     rmind 		m_adj(n, off);
    361  1.91.4.1     rmind 		if (sbappendaddr(&so->so_rcv, src, n, opts) == 0) {
    362  1.91.4.1     rmind 			m_freem(n);
    363  1.91.4.1     rmind 			if (opts)
    364  1.91.4.1     rmind 				m_freem(opts);
    365  1.91.4.1     rmind 			so->so_rcv.sb_overflowed++;
    366  1.91.4.1     rmind 			UDP6_STATINC(UDP6_STAT_FULLSOCK);
    367  1.91.4.1     rmind 		} else
    368  1.91.4.1     rmind 			sorwakeup(so);
    369  1.91.4.1     rmind 	}
    370  1.91.4.1     rmind }
    371  1.91.4.1     rmind 
    372  1.91.4.1     rmind int
    373  1.91.4.1     rmind udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst,
    374  1.91.4.1     rmind 	struct mbuf *m, int off)
    375  1.91.4.1     rmind {
    376  1.91.4.1     rmind 	u_int16_t sport, dport;
    377  1.91.4.1     rmind 	int rcvcnt;
    378  1.91.4.1     rmind 	struct in6_addr src6, *dst6;
    379  1.91.4.1     rmind 	const struct in_addr *dst4;
    380  1.91.4.1     rmind 	struct inpcb_hdr *inph;
    381  1.91.4.1     rmind 	struct in6pcb *in6p;
    382  1.91.4.1     rmind 
    383  1.91.4.1     rmind 	rcvcnt = 0;
    384  1.91.4.1     rmind 	off += sizeof(struct udphdr);	/* now, offset of payload */
    385  1.91.4.1     rmind 
    386  1.91.4.1     rmind 	if (af != AF_INET && af != AF_INET6)
    387  1.91.4.1     rmind 		goto bad;
    388  1.91.4.1     rmind 	if (src->sin6_family != AF_INET6 || dst->sin6_family != AF_INET6)
    389  1.91.4.1     rmind 		goto bad;
    390  1.91.4.1     rmind 
    391  1.91.4.1     rmind 	src6 = src->sin6_addr;
    392  1.91.4.1     rmind 	if (sa6_recoverscope(src) != 0) {
    393  1.91.4.1     rmind 		/* XXX: should be impossible. */
    394  1.91.4.1     rmind 		goto bad;
    395  1.91.4.1     rmind 	}
    396  1.91.4.1     rmind 	sport = src->sin6_port;
    397  1.91.4.1     rmind 
    398  1.91.4.1     rmind 	dport = dst->sin6_port;
    399  1.91.4.1     rmind 	dst4 = (struct in_addr *)&dst->sin6_addr.s6_addr[12];
    400  1.91.4.1     rmind 	dst6 = &dst->sin6_addr;
    401  1.91.4.1     rmind 
    402  1.91.4.1     rmind 	if (IN6_IS_ADDR_MULTICAST(dst6) ||
    403  1.91.4.1     rmind 	    (af == AF_INET && IN_MULTICAST(dst4->s_addr))) {
    404  1.91.4.1     rmind 		/*
    405  1.91.4.1     rmind 		 * Deliver a multicast or broadcast datagram to *all* sockets
    406  1.91.4.1     rmind 		 * for which the local and remote addresses and ports match
    407  1.91.4.1     rmind 		 * those of the incoming datagram.  This allows more than
    408  1.91.4.1     rmind 		 * one process to receive multi/broadcasts on the same port.
    409  1.91.4.1     rmind 		 * (This really ought to be done for unicast datagrams as
    410  1.91.4.1     rmind 		 * well, but that would cause problems with existing
    411  1.91.4.1     rmind 		 * applications that open both address-specific sockets and
    412  1.91.4.1     rmind 		 * a wildcard socket listening to the same port -- they would
    413  1.91.4.1     rmind 		 * end up receiving duplicates of every unicast datagram.
    414  1.91.4.1     rmind 		 * Those applications open the multiple sockets to overcome an
    415  1.91.4.1     rmind 		 * inadequacy of the UDP socket interface, but for backwards
    416  1.91.4.1     rmind 		 * compatibility we avoid the problem here rather than
    417  1.91.4.1     rmind 		 * fixing the interface.  Maybe 4.5BSD will remedy this?)
    418  1.91.4.1     rmind 		 */
    419  1.91.4.1     rmind 
    420  1.91.4.1     rmind 		/*
    421  1.91.4.1     rmind 		 * KAME note: traditionally we dropped udpiphdr from mbuf here.
    422  1.91.4.1     rmind 		 * we need udpiphdr for IPsec processing so we do that later.
    423  1.91.4.1     rmind 		 */
    424  1.91.4.1     rmind 		/*
    425  1.91.4.1     rmind 		 * Locate pcb(s) for datagram.
    426  1.91.4.1     rmind 		 */
    427  1.91.4.1     rmind 		CIRCLEQ_FOREACH(inph, &udbtable->inpt_queue, inph_queue) {
    428  1.91.4.1     rmind 			in6p = (struct in6pcb *)inph;
    429  1.91.4.1     rmind 			if (in6p->in6p_af != AF_INET6)
    430  1.91.4.1     rmind 				continue;
    431  1.91.4.1     rmind 
    432  1.91.4.1     rmind 			if (in6p->in6p_lport != dport)
    433  1.91.4.1     rmind 				continue;
    434  1.91.4.1     rmind 			if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) {
    435  1.91.4.1     rmind 				if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr,
    436  1.91.4.1     rmind 				    dst6))
    437  1.91.4.1     rmind 					continue;
    438  1.91.4.1     rmind 			} else {
    439  1.91.4.1     rmind 				if (IN6_IS_ADDR_V4MAPPED(dst6) &&
    440  1.91.4.1     rmind 				    (in6p->in6p_flags & IN6P_IPV6_V6ONLY))
    441  1.91.4.1     rmind 					continue;
    442  1.91.4.1     rmind 			}
    443  1.91.4.1     rmind 			if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
    444  1.91.4.1     rmind 				if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr,
    445  1.91.4.1     rmind 				    &src6) || in6p->in6p_fport != sport)
    446  1.91.4.1     rmind 					continue;
    447  1.91.4.1     rmind 			} else {
    448  1.91.4.1     rmind 				if (IN6_IS_ADDR_V4MAPPED(&src6) &&
    449  1.91.4.1     rmind 				    (in6p->in6p_flags & IN6P_IPV6_V6ONLY))
    450  1.91.4.1     rmind 					continue;
    451  1.91.4.1     rmind 			}
    452  1.91.4.1     rmind 
    453  1.91.4.1     rmind 			udp6_sendup(m, off, (struct sockaddr *)src,
    454  1.91.4.1     rmind 				in6p->in6p_socket);
    455  1.91.4.1     rmind 			rcvcnt++;
    456  1.91.4.1     rmind 
    457  1.91.4.1     rmind 			/*
    458  1.91.4.1     rmind 			 * Don't look for additional matches if this one does
    459  1.91.4.1     rmind 			 * not have either the SO_REUSEPORT or SO_REUSEADDR
    460  1.91.4.1     rmind 			 * socket options set.  This heuristic avoids searching
    461  1.91.4.1     rmind 			 * through all pcbs in the common case of a non-shared
    462  1.91.4.1     rmind 			 * port.  It assumes that an application will never
    463  1.91.4.1     rmind 			 * clear these options after setting them.
    464  1.91.4.1     rmind 			 */
    465  1.91.4.1     rmind 			if ((in6p->in6p_socket->so_options &
    466  1.91.4.1     rmind 			    (SO_REUSEPORT|SO_REUSEADDR)) == 0)
    467  1.91.4.1     rmind 				break;
    468  1.91.4.1     rmind 		}
    469  1.91.4.1     rmind 	} else {
    470  1.91.4.1     rmind 		/*
    471  1.91.4.1     rmind 		 * Locate pcb for datagram.
    472  1.91.4.1     rmind 		 */
    473  1.91.4.1     rmind 		in6p = in6_pcblookup_connect(udbtable, &src6, sport, dst6,
    474  1.91.4.1     rmind 					     dport, 0, 0);
    475  1.91.4.1     rmind 		if (in6p == 0) {
    476  1.91.4.1     rmind 			UDP_STATINC(UDP_STAT_PCBHASHMISS);
    477  1.91.4.1     rmind 			in6p = in6_pcblookup_bind(udbtable, dst6, dport, 0);
    478  1.91.4.1     rmind 			if (in6p == 0)
    479  1.91.4.1     rmind 				return rcvcnt;
    480  1.91.4.1     rmind 		}
    481  1.91.4.1     rmind 
    482  1.91.4.1     rmind 		udp6_sendup(m, off, (struct sockaddr *)src, in6p->in6p_socket);
    483  1.91.4.1     rmind 		rcvcnt++;
    484  1.91.4.1     rmind 	}
    485  1.91.4.1     rmind 
    486  1.91.4.1     rmind bad:
    487  1.91.4.1     rmind 	return rcvcnt;
    488  1.91.4.1     rmind }
    489  1.91.4.1     rmind 
    490  1.91.4.1     rmind int
    491  1.91.4.1     rmind udp6_input_checksum(struct mbuf *m, const struct udphdr *uh, int off, int len)
    492  1.91.4.1     rmind {
    493  1.91.4.1     rmind 	/*
    494  1.91.4.1     rmind 	 * XXX it's better to record and check if this mbuf is
    495  1.91.4.1     rmind 	 * already checked.
    496  1.91.4.1     rmind 	 */
    497  1.91.4.1     rmind 
    498  1.91.4.1     rmind 	if (__predict_false((m->m_flags & M_LOOP) && !udp_do_loopback_cksum)) {
    499  1.91.4.1     rmind 		goto good;
    500  1.91.4.1     rmind 	}
    501  1.91.4.1     rmind 	if (uh->uh_sum == 0) {
    502  1.91.4.1     rmind 		UDP6_STATINC(UDP6_STAT_NOSUM);
    503  1.91.4.1     rmind 		goto bad;
    504  1.91.4.1     rmind 	}
    505  1.91.4.1     rmind 
    506  1.91.4.1     rmind 	switch (m->m_pkthdr.csum_flags &
    507  1.91.4.1     rmind 	    ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv6) |
    508  1.91.4.1     rmind 	    M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) {
    509  1.91.4.1     rmind 	case M_CSUM_UDPv6|M_CSUM_TCP_UDP_BAD:
    510  1.91.4.1     rmind 		UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_bad);
    511  1.91.4.1     rmind 		UDP6_STATINC(UDP6_STAT_BADSUM);
    512  1.91.4.1     rmind 		goto bad;
    513  1.91.4.1     rmind 
    514  1.91.4.1     rmind #if 0 /* notyet */
    515  1.91.4.1     rmind 	case M_CSUM_UDPv6|M_CSUM_DATA:
    516  1.91.4.1     rmind #endif
    517  1.91.4.1     rmind 
    518  1.91.4.1     rmind 	case M_CSUM_UDPv6:
    519  1.91.4.1     rmind 		/* Checksum was okay. */
    520  1.91.4.1     rmind 		UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_ok);
    521  1.91.4.1     rmind 		break;
    522  1.91.4.1     rmind 
    523  1.91.4.1     rmind 	default:
    524  1.91.4.1     rmind 		/*
    525  1.91.4.1     rmind 		 * Need to compute it ourselves.  Maybe skip checksum
    526  1.91.4.1     rmind 		 * on loopback interfaces.
    527  1.91.4.1     rmind 		 */
    528  1.91.4.1     rmind 		UDP_CSUM_COUNTER_INCR(&udp6_swcsum);
    529  1.91.4.1     rmind 		if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) {
    530  1.91.4.1     rmind 			UDP6_STATINC(UDP6_STAT_BADSUM);
    531  1.91.4.1     rmind 			goto bad;
    532  1.91.4.1     rmind 		}
    533  1.91.4.1     rmind 	}
    534  1.91.4.1     rmind 
    535  1.91.4.1     rmind good:
    536  1.91.4.1     rmind 	return 0;
    537  1.91.4.1     rmind bad:
    538  1.91.4.1     rmind 	return -1;
    539  1.91.4.1     rmind }
    540  1.91.4.1     rmind 
    541  1.91.4.1     rmind int
    542  1.91.4.1     rmind udp6_input(struct mbuf **mp, int *offp, int proto)
    543  1.91.4.1     rmind {
    544  1.91.4.1     rmind 	struct mbuf *m = *mp;
    545  1.91.4.1     rmind 	int off = *offp;
    546  1.91.4.1     rmind 	struct sockaddr_in6 src, dst;
    547  1.91.4.1     rmind 	struct ip6_hdr *ip6;
    548  1.91.4.1     rmind 	struct udphdr *uh;
    549  1.91.4.1     rmind 	u_int32_t plen, ulen;
    550  1.91.4.1     rmind 
    551  1.91.4.1     rmind 	ip6 = mtod(m, struct ip6_hdr *);
    552  1.91.4.1     rmind 
    553  1.91.4.1     rmind #if defined(NFAITH) && 0 < NFAITH
    554  1.91.4.1     rmind 	if (faithprefix(&ip6->ip6_dst)) {
    555  1.91.4.1     rmind 		/* send icmp6 host unreach? */
    556  1.91.4.1     rmind 		m_freem(m);
    557  1.91.4.1     rmind 		return IPPROTO_DONE;
    558  1.91.4.1     rmind 	}
    559  1.91.4.1     rmind #endif
    560  1.91.4.1     rmind 
    561  1.91.4.1     rmind 	UDP6_STATINC(UDP6_STAT_IPACKETS);
    562  1.91.4.1     rmind 
    563  1.91.4.1     rmind 	/* check for jumbogram is done in ip6_input.  we can trust pkthdr.len */
    564  1.91.4.1     rmind 	plen = m->m_pkthdr.len - off;
    565  1.91.4.1     rmind 	IP6_EXTHDR_GET(uh, struct udphdr *, m, off, sizeof(struct udphdr));
    566  1.91.4.1     rmind 	if (uh == NULL) {
    567  1.91.4.1     rmind 		IP6_STATINC(IP6_STAT_TOOSHORT);
    568  1.91.4.1     rmind 		return IPPROTO_DONE;
    569  1.91.4.1     rmind 	}
    570  1.91.4.1     rmind 	KASSERT(UDP_HDR_ALIGNED_P(uh));
    571  1.91.4.1     rmind 	ulen = ntohs((u_short)uh->uh_ulen);
    572  1.91.4.1     rmind 	/*
    573  1.91.4.1     rmind 	 * RFC2675 section 4: jumbograms will have 0 in the UDP header field,
    574  1.91.4.1     rmind 	 * iff payload length > 0xffff.
    575  1.91.4.1     rmind 	 */
    576  1.91.4.1     rmind 	if (ulen == 0 && plen > 0xffff)
    577  1.91.4.1     rmind 		ulen = plen;
    578  1.91.4.1     rmind 
    579  1.91.4.1     rmind 	if (plen != ulen) {
    580  1.91.4.1     rmind 		UDP6_STATINC(UDP6_STAT_BADLEN);
    581  1.91.4.1     rmind 		goto bad;
    582  1.91.4.1     rmind 	}
    583  1.91.4.1     rmind 
    584  1.91.4.1     rmind 	/* destination port of 0 is illegal, based on RFC768. */
    585  1.91.4.1     rmind 	if (uh->uh_dport == 0)
    586  1.91.4.1     rmind 		goto bad;
    587  1.91.4.1     rmind 
    588  1.91.4.1     rmind 	/* Be proactive about malicious use of IPv4 mapped address */
    589  1.91.4.1     rmind 	if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
    590  1.91.4.1     rmind 	    IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
    591  1.91.4.1     rmind 		/* XXX stat */
    592  1.91.4.1     rmind 		goto bad;
    593  1.91.4.1     rmind 	}
    594  1.91.4.1     rmind 
    595  1.91.4.1     rmind 	/*
    596  1.91.4.1     rmind 	 * Checksum extended UDP header and data.  Maybe skip checksum
    597  1.91.4.1     rmind 	 * on loopback interfaces.
    598  1.91.4.1     rmind 	 */
    599  1.91.4.1     rmind 	if (udp6_input_checksum(m, uh, off, ulen))
    600  1.91.4.1     rmind 		goto bad;
    601  1.91.4.1     rmind 
    602  1.91.4.1     rmind 	/*
    603  1.91.4.1     rmind 	 * Construct source and dst sockaddrs.
    604  1.91.4.1     rmind 	 */
    605  1.91.4.1     rmind 	memset(&src, 0, sizeof(src));
    606  1.91.4.1     rmind 	src.sin6_family = AF_INET6;
    607  1.91.4.1     rmind 	src.sin6_len = sizeof(struct sockaddr_in6);
    608  1.91.4.1     rmind 	src.sin6_addr = ip6->ip6_src;
    609  1.91.4.1     rmind 	src.sin6_port = uh->uh_sport;
    610  1.91.4.1     rmind 	memset(&dst, 0, sizeof(dst));
    611  1.91.4.1     rmind 	dst.sin6_family = AF_INET6;
    612  1.91.4.1     rmind 	dst.sin6_len = sizeof(struct sockaddr_in6);
    613  1.91.4.1     rmind 	dst.sin6_addr = ip6->ip6_dst;
    614  1.91.4.1     rmind 	dst.sin6_port = uh->uh_dport;
    615  1.91.4.1     rmind 
    616  1.91.4.1     rmind 	if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) {
    617  1.91.4.1     rmind 		if (m->m_flags & M_MCAST) {
    618  1.91.4.1     rmind 			UDP6_STATINC(UDP6_STAT_NOPORTMCAST);
    619  1.91.4.1     rmind 			goto bad;
    620  1.91.4.1     rmind 		}
    621  1.91.4.1     rmind 		UDP6_STATINC(UDP6_STAT_NOPORT);
    622  1.91.4.1     rmind 		icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
    623  1.91.4.1     rmind 		m = NULL;
    624  1.91.4.1     rmind 	}
    625  1.91.4.1     rmind 
    626  1.91.4.1     rmind bad:
    627  1.91.4.1     rmind 	if (m)
    628  1.91.4.1     rmind 		m_freem(m);
    629  1.91.4.1     rmind 	return IPPROTO_DONE;
    630  1.91.4.1     rmind }
    631      1.90  christos 
    632       1.2    itojun extern	int udp6_sendspace;
    633       1.2    itojun extern	int udp6_recvspace;
    634       1.2    itojun 
    635  1.91.4.2     rmind static int
    636  1.91.4.2     rmind udp6_attach(struct socket *so, int proto)
    637  1.91.4.2     rmind {
    638  1.91.4.2     rmind 	struct in6pcb *in6p;
    639  1.91.4.2     rmind 	int s, error = 0;
    640  1.91.4.2     rmind 
    641  1.91.4.2     rmind 	KASSERT(sotoin6pcb(so) == NULL);
    642  1.91.4.2     rmind 	sosetlock(so);
    643  1.91.4.2     rmind 	solock(so);
    644  1.91.4.2     rmind 
    645  1.91.4.2     rmind 	/*
    646  1.91.4.2     rmind 	 * MAPPED_ADDR implementation spec:
    647  1.91.4.2     rmind 	 *  Always attach for IPv6, and only when necessary for IPv4.
    648  1.91.4.2     rmind 	 */
    649  1.91.4.2     rmind 	s = splsoftnet();
    650  1.91.4.2     rmind 	error = in6_pcballoc(so, udbtable);
    651  1.91.4.2     rmind 	splx(s);
    652  1.91.4.2     rmind 	if (error) {
    653  1.91.4.2     rmind 		sounlock(so);
    654  1.91.4.2     rmind 		return error;
    655  1.91.4.2     rmind 	}
    656  1.91.4.2     rmind 	error = soreserve(so, udp6_sendspace, udp6_recvspace);
    657  1.91.4.2     rmind 	if (error) {
    658  1.91.4.2     rmind 		sounlock(so);
    659  1.91.4.2     rmind 		return error;
    660  1.91.4.2     rmind 	}
    661  1.91.4.2     rmind 	in6p = sotoin6pcb(so);
    662  1.91.4.2     rmind 	in6p->in6p_cksum = -1;	/* just to be sure */
    663  1.91.4.2     rmind 	sounlock(so);
    664  1.91.4.2     rmind 	return 0;
    665  1.91.4.2     rmind }
    666  1.91.4.2     rmind 
    667  1.91.4.2     rmind static void
    668  1.91.4.2     rmind udp6_detach(struct socket *so)
    669  1.91.4.2     rmind {
    670  1.91.4.2     rmind 	struct in6pcb *in6p = sotoin6pcb(so);
    671  1.91.4.2     rmind 	int s;
    672  1.91.4.2     rmind 
    673  1.91.4.2     rmind 	KASSERT(solocked(so));
    674  1.91.4.2     rmind 
    675  1.91.4.2     rmind 	s = splsoftnet();
    676  1.91.4.2     rmind 	KASSERT(in6p != NULL);
    677  1.91.4.2     rmind 	in6_pcbdetach(in6p);
    678  1.91.4.2     rmind 	splx(s);
    679  1.91.4.2     rmind }
    680  1.91.4.2     rmind 
    681       1.2    itojun int
    682      1.76    dyoung udp6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr6,
    683      1.76    dyoung     struct mbuf *control, struct lwp *l)
    684       1.2    itojun {
    685       1.2    itojun 	struct	in6pcb *in6p = sotoin6pcb(so);
    686       1.2    itojun 	int	error = 0;
    687       1.2    itojun 	int	s;
    688       1.2    itojun 
    689  1.91.4.2     rmind 	KASSERT(req != PRU_ATTACH);
    690  1.91.4.2     rmind 	KASSERT(req != PRU_DETACH);
    691  1.91.4.2     rmind 
    692      1.27    itojun 	/*
    693       1.2    itojun 	 * MAPPED_ADDR implementation info:
    694       1.2    itojun 	 *  Mapped addr support for PRU_CONTROL is not necessary.
    695       1.2    itojun 	 *  Because typical user of PRU_CONTROL is such as ifconfig,
    696       1.2    itojun 	 *  and they don't associate any addr to their socket.  Then
    697       1.2    itojun 	 *  socket family is only hint about the PRU_CONTROL'ed address
    698       1.2    itojun 	 *  family, especially when getting addrs from kernel.
    699       1.2    itojun 	 *  So AF_INET socket need to be used to control AF_INET addrs,
    700       1.2    itojun 	 *  and AF_INET6 socket for AF_INET6 addrs.
    701       1.2    itojun 	 */
    702       1.2    itojun 	if (req == PRU_CONTROL)
    703      1.80    dyoung 		return in6_control(so, (u_long)m, (void *)addr6,
    704      1.80    dyoung 				   (struct ifnet *)control, l);
    705      1.20   thorpej 
    706      1.21   thorpej 	if (req == PRU_PURGEIF) {
    707      1.84        ad 		mutex_enter(softnet_lock);
    708  1.91.4.1     rmind 		in6_pcbpurgeif0(udbtable, (struct ifnet *)control);
    709      1.21   thorpej 		in6_purgeif((struct ifnet *)control);
    710  1.91.4.1     rmind 		in6_pcbpurgeif(udbtable, (struct ifnet *)control);
    711      1.84        ad 		mutex_exit(softnet_lock);
    712      1.80    dyoung 		return 0;
    713      1.20   thorpej 	}
    714       1.2    itojun 
    715  1.91.4.2     rmind 	if (in6p == NULL) {
    716       1.2    itojun 		error = EINVAL;
    717       1.2    itojun 		goto release;
    718       1.2    itojun 	}
    719       1.2    itojun 
    720       1.2    itojun 	switch (req) {
    721       1.2    itojun 	case PRU_BIND:
    722       1.4    itojun 		s = splsoftnet();
    723      1.75        ad 		error = in6_pcbbind(in6p, addr6, l);
    724       1.2    itojun 		splx(s);
    725       1.2    itojun 		break;
    726       1.2    itojun 
    727       1.2    itojun 	case PRU_CONNECT:
    728      1.14    itojun 		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
    729       1.2    itojun 			error = EISCONN;
    730       1.2    itojun 			break;
    731       1.2    itojun 		}
    732       1.4    itojun 		s = splsoftnet();
    733      1.75        ad 		error = in6_pcbconnect(in6p, addr6, l);
    734       1.2    itojun 		splx(s);
    735       1.2    itojun 		if (error == 0)
    736       1.2    itojun 			soisconnected(so);
    737       1.2    itojun 		break;
    738       1.2    itojun 
    739       1.2    itojun 	case PRU_DISCONNECT:
    740       1.2    itojun 		if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
    741       1.2    itojun 			error = ENOTCONN;
    742       1.2    itojun 			break;
    743       1.2    itojun 		}
    744       1.4    itojun 		s = splsoftnet();
    745       1.2    itojun 		in6_pcbdisconnect(in6p);
    746      1.87    cegger 		memset((void *)&in6p->in6p_laddr, 0, sizeof(in6p->in6p_laddr));
    747       1.2    itojun 		splx(s);
    748       1.2    itojun 		so->so_state &= ~SS_ISCONNECTED;		/* XXX */
    749      1.58    itojun 		in6_pcbstate(in6p, IN6P_BOUND);		/* XXX */
    750       1.2    itojun 		break;
    751       1.2    itojun 
    752       1.2    itojun 	case PRU_SHUTDOWN:
    753       1.2    itojun 		socantsendmore(so);
    754       1.2    itojun 		break;
    755       1.2    itojun 
    756       1.2    itojun 	case PRU_SEND:
    757      1.79    dyoung 		s = splsoftnet();
    758      1.79    dyoung 		error = udp6_output(in6p, m, addr6, control, l);
    759      1.79    dyoung 		splx(s);
    760      1.79    dyoung 		return error;
    761       1.2    itojun 
    762       1.2    itojun 	case PRU_ABORT:
    763       1.2    itojun 		soisdisconnected(so);
    764      1.58    itojun 		in6_pcbdetach(in6p);
    765       1.2    itojun 		break;
    766       1.2    itojun 
    767       1.2    itojun 	case PRU_SOCKADDR:
    768       1.2    itojun 		in6_setsockaddr(in6p, addr6);
    769       1.2    itojun 		break;
    770       1.2    itojun 
    771       1.2    itojun 	case PRU_PEERADDR:
    772       1.2    itojun 		in6_setpeeraddr(in6p, addr6);
    773       1.2    itojun 		break;
    774       1.2    itojun 
    775       1.2    itojun 	case PRU_SENSE:
    776       1.2    itojun 		/*
    777       1.2    itojun 		 * stat: don't bother with a blocksize
    778       1.2    itojun 		 */
    779      1.80    dyoung 		return 0;
    780       1.2    itojun 
    781      1.80    dyoung 	case PRU_LISTEN:
    782      1.80    dyoung 	case PRU_CONNECT2:
    783      1.80    dyoung 	case PRU_ACCEPT:
    784       1.2    itojun 	case PRU_SENDOOB:
    785       1.2    itojun 	case PRU_FASTTIMO:
    786       1.2    itojun 	case PRU_SLOWTIMO:
    787       1.2    itojun 	case PRU_PROTORCV:
    788       1.2    itojun 	case PRU_PROTOSEND:
    789       1.2    itojun 		error = EOPNOTSUPP;
    790       1.2    itojun 		break;
    791       1.2    itojun 
    792       1.2    itojun 	case PRU_RCVD:
    793       1.2    itojun 	case PRU_RCVOOB:
    794      1.80    dyoung 		return EOPNOTSUPP;	/* do not free mbuf's */
    795       1.2    itojun 
    796       1.2    itojun 	default:
    797       1.2    itojun 		panic("udp6_usrreq");
    798       1.2    itojun 	}
    799       1.2    itojun 
    800       1.2    itojun release:
    801      1.80    dyoung 	if (control != NULL)
    802       1.2    itojun 		m_freem(control);
    803      1.80    dyoung 	if (m != NULL)
    804       1.2    itojun 		m_freem(m);
    805      1.80    dyoung 	return error;
    806       1.2    itojun }
    807       1.2    itojun 
    808  1.91.4.2     rmind PR_WRAP_USRREQ(udp6_usrreq)
    809  1.91.4.2     rmind 
    810  1.91.4.2     rmind #define	udp6_usrreq	udp6_usrreq_wrapper
    811  1.91.4.2     rmind 
    812  1.91.4.2     rmind const struct pr_usrreqs udp6_usrreqs = {
    813  1.91.4.2     rmind 	.pr_attach	= udp6_attach,
    814  1.91.4.2     rmind 	.pr_detach	= udp6_detach,
    815  1.91.4.2     rmind 	.pr_generic	= udp6_usrreq,
    816  1.91.4.2     rmind };
    817  1.91.4.2     rmind 
    818      1.82   thorpej static int
    819      1.82   thorpej sysctl_net_inet6_udp6_stats(SYSCTLFN_ARGS)
    820      1.82   thorpej {
    821      1.82   thorpej 
    822      1.86   thorpej 	return (NETSTAT_SYSCTL(udp6stat_percpu, UDP6_NSTATS));
    823      1.82   thorpej }
    824      1.82   thorpej 
    825      1.88     pooka static void
    826      1.88     pooka sysctl_net_inet6_udp6_setup(struct sysctllog **clog)
    827       1.2    itojun {
    828  1.91.4.3     rmind 
    829      1.62    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    830      1.62    atatat 		       CTLFLAG_PERMANENT,
    831      1.61    atatat 		       CTLTYPE_NODE, "inet6", NULL,
    832      1.61    atatat 		       NULL, 0, NULL, 0,
    833      1.61    atatat 		       CTL_NET, PF_INET6, CTL_EOL);
    834      1.62    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    835      1.62    atatat 		       CTLFLAG_PERMANENT,
    836      1.63    atatat 		       CTLTYPE_NODE, "udp6",
    837      1.63    atatat 		       SYSCTL_DESCR("UDPv6 related settings"),
    838      1.61    atatat 		       NULL, 0, NULL, 0,
    839      1.61    atatat 		       CTL_NET, PF_INET6, IPPROTO_UDP, CTL_EOL);
    840      1.61    atatat 
    841      1.62    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    842      1.62    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    843      1.63    atatat 		       CTLTYPE_INT, "sendspace",
    844      1.63    atatat 		       SYSCTL_DESCR("Default UDP send buffer size"),
    845      1.61    atatat 		       NULL, 0, &udp6_sendspace, 0,
    846      1.61    atatat 		       CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_SENDSPACE,
    847      1.61    atatat 		       CTL_EOL);
    848      1.62    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    849      1.62    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    850      1.63    atatat 		       CTLTYPE_INT, "recvspace",
    851      1.63    atatat 		       SYSCTL_DESCR("Default UDP receive buffer size"),
    852      1.61    atatat 		       NULL, 0, &udp6_recvspace, 0,
    853      1.61    atatat 		       CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_RECVSPACE,
    854      1.61    atatat 		       CTL_EOL);
    855      1.64   thorpej 	sysctl_createv(clog, 0, NULL, NULL,
    856      1.64   thorpej 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    857      1.64   thorpej 		       CTLTYPE_INT, "do_loopback_cksum",
    858      1.64   thorpej 		       SYSCTL_DESCR("Perform UDP checksum on loopback"),
    859      1.64   thorpej 		       NULL, 0, &udp_do_loopback_cksum, 0,
    860      1.64   thorpej 		       CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_LOOPBACKCKSUM,
    861      1.64   thorpej 		       CTL_EOL);
    862      1.65    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    863      1.65    atatat 		       CTLFLAG_PERMANENT,
    864      1.67    atatat 		       CTLTYPE_STRUCT, "pcblist",
    865      1.65    atatat 		       SYSCTL_DESCR("UDP protocol control block list"),
    866  1.91.4.1     rmind 		       sysctl_inpcblist, 0, udbtable, 0,
    867      1.65    atatat 		       CTL_NET, PF_INET6, IPPROTO_UDP, CTL_CREATE,
    868      1.65    atatat 		       CTL_EOL);
    869      1.70    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
    870      1.70    rpaulo 		       CTLFLAG_PERMANENT,
    871      1.70    rpaulo 		       CTLTYPE_STRUCT, "stats",
    872      1.70    rpaulo 		       SYSCTL_DESCR("UDPv6 statistics"),
    873      1.82   thorpej 		       sysctl_net_inet6_udp6_stats, 0, NULL, 0,
    874      1.70    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_UDP, UDP6CTL_STATS,
    875      1.70    rpaulo 		       CTL_EOL);
    876       1.2    itojun }
    877      1.82   thorpej 
    878      1.82   thorpej void
    879      1.82   thorpej udp6_statinc(u_int stat)
    880      1.82   thorpej {
    881      1.82   thorpej 
    882      1.82   thorpej 	KASSERT(stat < UDP6_NSTATS);
    883      1.82   thorpej 	UDP6_STATINC(stat);
    884      1.82   thorpej }
    885  1.91.4.3     rmind 
    886  1.91.4.3     rmind PR_WRAP_USRREQ(udp6_usrreq)
    887  1.91.4.3     rmind 
    888  1.91.4.3     rmind #define	udp6_usrreq	udp6_usrreq_wrapper
    889  1.91.4.3     rmind 
    890  1.91.4.3     rmind const struct pr_usrreqs udp6_usrreqs = {
    891  1.91.4.3     rmind 	.pr_generic	= udp6_usrreq,
    892  1.91.4.3     rmind };
    893