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