Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move udp6_output() into udp6_usrreq.c, and remove udp6_o...



details:   https://anonhg.NetBSD.org/src/rev/2a1cc77ad7fa
branches:  trunk
changeset: 829680:2a1cc77ad7fa
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Feb 08 11:34:35 2018 +0000

description:
Move udp6_output() into udp6_usrreq.c, and remove udp6_output.c. This is
more consistent with IPv4, and there is no good reason for keeping a
separate file only for one function. FreeBSD did the same.

diffstat:

 sys/netinet6/files.netinet6               |    3 +-
 sys/netinet6/udp6_output.c                |  433 ------------------------------
 sys/netinet6/udp6_usrreq.c                |  328 ++++++++++++++++++++++-
 sys/rump/net/lib/libnetinet6/Makefile.inc |    4 +-
 4 files changed, 328 insertions(+), 440 deletions(-)

diffs (truncated from 821 to 300 lines):

diff -r 28ea3bb37c29 -r 2a1cc77ad7fa sys/netinet6/files.netinet6
--- a/sys/netinet6/files.netinet6       Thu Feb 08 11:13:20 2018 +0000
+++ b/sys/netinet6/files.netinet6       Thu Feb 08 11:34:35 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.netinet6,v 1.12 2016/08/02 04:50:16 knakahara Exp $
+#      $NetBSD: files.netinet6,v 1.13 2018/02/08 11:34:35 maxv Exp $
 
 defflag        opt_inet6.h     RFC2292 
 
@@ -29,7 +29,6 @@
 file   netinet6/route6.c               inet6
 file   netinet6/scope6.c               inet6
 
-file   netinet6/udp6_output.c          inet6
 file   netinet6/udp6_usrreq.c          inet6
 
 file   netinet6/dccp6_usrreq.c         inet6 & dccp
diff -r 28ea3bb37c29 -r 2a1cc77ad7fa sys/netinet6/udp6_output.c
--- a/sys/netinet6/udp6_output.c        Thu Feb 08 11:13:20 2018 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,433 +0,0 @@
-/*     $NetBSD: udp6_output.c,v 1.56 2018/02/08 11:13:20 maxv Exp $    */
-/*     $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $    */
-
-/*
- * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 1982, 1986, 1989, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     @(#)udp_var.h   8.1 (Berkeley) 6/10/93
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.56 2018/02/08 11:13:20 maxv Exp $");
-
-#ifdef _KERNEL_OPT
-#include "opt_inet.h"
-#endif
-
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/protosw.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/errno.h>
-#include <sys/stat.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/syslog.h>
-#include <sys/kauth.h>
-#include <sys/domain.h>
-
-#include <net/if.h>
-#include <net/if_types.h>
-
-#include <netinet/in.h>
-#include <netinet/in_var.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/in_pcb.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/udp_private.h>
-#include <netinet/ip6.h>
-#include <netinet6/ip6_var.h>
-#include <netinet6/in6_pcb.h>
-#include <netinet6/udp6_var.h>
-#include <netinet6/udp6_private.h>
-#include <netinet/icmp6.h>
-#include <netinet6/ip6protosw.h>
-#include <netinet6/scope6_var.h>
-
-#include "faith.h"
-
-#include <net/net_osdep.h>
-
-/*
- * UDP protocol inplementation.
- * Per RFC 768, August, 1980.
- */
-
-int
-udp6_output(struct in6pcb * const in6p, struct mbuf *m,
-    struct sockaddr_in6 * const addr6, struct mbuf * const control,
-    struct lwp * const l)
-{
-       u_int32_t ulen = m->m_pkthdr.len;
-       u_int32_t plen = sizeof(struct udphdr) + ulen;
-       struct ip6_hdr *ip6;
-       struct udphdr *udp6;
-       struct in6_addr _laddr, *laddr, *faddr;
-       struct in6_addr laddr_mapped; /* XXX ugly */
-       struct sockaddr_in6 *sin6 = NULL;
-       struct ifnet *oifp = NULL;
-       int scope_ambiguous = 0;
-       u_int16_t fport;
-       int error = 0;
-       struct ip6_pktopts *optp = NULL;
-       struct ip6_pktopts opt;
-       int af = AF_INET6, hlen = sizeof(struct ip6_hdr);
-#ifdef INET
-       struct ip *ip;
-       struct udpiphdr *ui;
-       int flags = 0;
-#endif
-       struct sockaddr_in6 tmp;
-
-       if (addr6) {
-               sin6 = addr6;
-               if (sin6->sin6_family != AF_INET6) {
-                       error = EAFNOSUPPORT;
-                       goto release;
-               }
-
-               /* protect *sin6 from overwrites */
-               tmp = *sin6;
-               sin6 = &tmp;
-
-               /*
-                * Application should provide a proper zone ID or the use of
-                * default zone IDs should be enabled.  Unfortunately, some
-                * applications do not behave as it should, so we need a
-                * workaround.  Even if an appropriate ID is not determined,
-                * we'll see if we can determine the outgoing interface.  If we
-                * can, determine the zone ID based on the interface below.
-                */
-               if (sin6->sin6_scope_id == 0 && !ip6_use_defzone)
-                       scope_ambiguous = 1;
-               if ((error = sa6_embedscope(sin6, ip6_use_defzone)) != 0)
-                       goto release;
-       }
-
-       if (control) {
-               if ((error = ip6_setpktopts(control, &opt,
-                   in6p->in6p_outputopts, l->l_cred, IPPROTO_UDP)) != 0)
-                       goto release;
-               optp = &opt;
-       } else
-               optp = in6p->in6p_outputopts;
-
-
-       if (sin6) {
-               /*
-                * Slightly different than v4 version in that we call
-                * in6_selectsrc and in6_pcbsetport to fill in the local
-                * address and port rather than in_pcbconnect. in_pcbconnect
-                * sets in6p_faddr which causes EISCONN below to be hit on
-                * subsequent sendto.
-                */
-               if (sin6->sin6_port == 0) {
-                       error = EADDRNOTAVAIL;
-                       goto release;
-               }
-
-               if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
-                       /* how about ::ffff:0.0.0.0 case? */
-                       error = EISCONN;
-                       goto release;
-               }
-
-               faddr = &sin6->sin6_addr;
-               fport = sin6->sin6_port; /* allow 0 port */
-
-               if (IN6_IS_ADDR_V4MAPPED(faddr)) {
-                       if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY)) {
-                               /*
-                                * I believe we should explicitly discard the
-                                * packet when mapped addresses are disabled,
-                                * rather than send the packet as an IPv6 one.
-                                * If we chose the latter approach, the packet
-                                * might be sent out on the wire based on the
-                                * default route, the situation which we'd
-                                * probably want to avoid.
-                                * (20010421 jinmei%kame.net@localhost)
-                                */
-                               error = EINVAL;
-                               goto release;
-                       }
-                       if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) &&
-                           !IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)) {
-                               /*
-                                * when remote addr is an IPv4-mapped address,
-                                * local addr should not be an IPv6 address,
-                                * since you cannot determine how to map IPv6
-                                * source address to IPv4.
-                                */
-                               error = EINVAL;
-                               goto release;
-                       }
-
-                       af = AF_INET;
-               }
-
-               if (!IN6_IS_ADDR_V4MAPPED(faddr)) {
-                       struct psref psref;
-                       int bound = curlwp_bind();
-
-                       error = in6_selectsrc(sin6, optp,
-                           in6p->in6p_moptions,
-                           &in6p->in6p_route,
-                           &in6p->in6p_laddr, &oifp, &psref, &_laddr);
-                       /* XXX need error check? */
-                       if (oifp && scope_ambiguous &&
-                           (error = in6_setscope(&sin6->sin6_addr,
-                           oifp, NULL))) {
-                               if_put(oifp, &psref);
-                               curlwp_bindx(bound);
-                               goto release;
-                       }
-                       if_put(oifp, &psref);
-                       curlwp_bindx(bound);
-                       laddr = &_laddr;
-               } else {
-                       /*
-                        * XXX: freebsd[34] does not have in_selectsrc, but
-                        * we can omit the whole part because freebsd4 calls
-                        * udp_output() directly in this case, and thus we'll
-                        * never see this path.
-                        */
-                       if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) {
-                               struct sockaddr_in sin_dst;
-                               struct in_addr ina;
-                               struct in_ifaddr *ia4;
-                               struct psref _psref;
-                               int bound;
-
-                               memcpy(&ina, &faddr->s6_addr[12], sizeof(ina));
-                               sockaddr_in_init(&sin_dst, &ina, 0);
-                               bound = curlwp_bind();
-                               ia4 = in_selectsrc(&sin_dst, &in6p->in6p_route,
-                                   in6p->in6p_socket->so_options, NULL,
-                                   &error, &_psref);
-                               if (ia4 == NULL) {
-                                       curlwp_bindx(bound);
-                                       if (error == 0)
-                                               error = EADDRNOTAVAIL;
-                                       goto release;
-                               }
-                               memset(&laddr_mapped, 0, sizeof(laddr_mapped));
-                               laddr_mapped.s6_addr16[5] = 0xffff; /* ugly */
-                               memcpy(&laddr_mapped.s6_addr[12],
-                                     &IA_SIN(ia4)->sin_addr,
-                                     sizeof(IA_SIN(ia4)->sin_addr));
-                               ia4_release(ia4, &_psref);
-                               curlwp_bindx(bound);
-                               laddr = &laddr_mapped;
-                       } else



Home | Main Index | Thread Index | Old Index