Source-Changes-HG archive

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

[src/trunk]: src/sys Do ND in L2_output in the same manner as arpresolve



details:   https://anonhg.NetBSD.org/src/rev/6dcf86a3f8a3
branches:  trunk
changeset: 351460:6dcf86a3f8a3
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Feb 14 03:05:06 2017 +0000

description:
Do ND in L2_output in the same manner as arpresolve

The benefits of this change are:
- The flow is consistent with IPv4 (and FreeBSD and OpenBSD)
  - old: ip6_output => nd6_output (do ND if needed) => L2_output (lookup a stored cache)
  - new: ip6_output => L2_output (lookup a cache. Do ND if cache not found)
- We can remove some workarounds in nd6_output
- We can move L2 specific operations to their own place
- The performance slightly improves because one cache lookup is reduced

diffstat:

 sys/dist/pf/net/pf.c                         |    6 +-
 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c |    6 +-
 sys/net/if_arcsubr.c                         |   14 +-
 sys/net/if_ethersubr.c                       |   17 +-
 sys/net/if_fddisubr.c                        |   19 +-
 sys/net/if_ieee1394subr.c                    |   23 ++-
 sys/net/if_srt.c                             |    7 +-
 sys/netinet6/in6_offload.c                   |    7 +-
 sys/netinet6/ip6_forward.c                   |    6 +-
 sys/netinet6/ip6_mroute.c                    |   11 +-
 sys/netinet6/ip6_output.c                    |   33 ++++-
 sys/netinet6/ip6_var.h                       |    5 +-
 sys/netinet6/nd6.c                           |  194 +++++---------------------
 sys/netinet6/nd6.h                           |   10 +-
 14 files changed, 145 insertions(+), 213 deletions(-)

diffs (truncated from 720 to 300 lines):

diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/dist/pf/net/pf.c
--- a/sys/dist/pf/net/pf.c      Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/dist/pf/net/pf.c      Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pf.c,v 1.75 2016/12/08 05:16:33 ozaki-r Exp $  */
+/*     $NetBSD: pf.c,v 1.76 2017/02/14 03:05:06 ozaki-r Exp $  */
 /*     $OpenBSD: pf.c,v 1.552.2.1 2007/11/27 16:37:57 henning Exp $ */
 
 /*
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pf.c,v 1.75 2016/12/08 05:16:33 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pf.c,v 1.76 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #include "pflog.h"
 
@@ -5553,7 +5553,7 @@
        if (IN6_IS_SCOPE_EMBEDDABLE(&dst.sin6_addr))
                dst.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
        if ((u_long)m0->m_pkthdr.len <= ifp->if_mtu) {
-               (void)nd6_output(ifp, ifp, m0, &dst, NULL);
+               (void)ip6_if_output(ifp, ifp, m0, &dst, NULL);
        } else {
                in6_ifstat_inc(ifp, ifs6_in_toobig);
                if (r->rt != PF_DUPTO)
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c
--- a/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c      Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c      Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_fil_netbsd.c,v 1.21 2016/12/28 19:53:02 christos Exp $      */
+/*     $NetBSD: ip_fil_netbsd.c,v 1.22 2017/02/14 03:05:06 ozaki-r Exp $       */
 
 /*
  * Copyright (C) 2012 by Darren Reed.
@@ -8,7 +8,7 @@
 #if !defined(lint)
 #if defined(__NetBSD__)
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_fil_netbsd.c,v 1.21 2016/12/28 19:53:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_fil_netbsd.c,v 1.22 2017/02/14 03:05:06 ozaki-r Exp $");
 #else
 static const char sccsid[] = "@(#)ip_fil.c     2.41 6/5/96 (C) 1993-2000 Darren Reed";
 static const char rcsid[] = "@(#)Id: ip_fil_netbsd.c,v 1.1.1.2 2012/07/22 13:45:17 darrenr Exp";
@@ -1478,7 +1478,7 @@
 # endif
                if ((error == 0) && (m0->m_pkthdr.len <= mtu)) {
 # if __NetBSD_Version__ >= 499001100
-                       error = nd6_output(ifp, ifp, m0, satocsin6(dst), rt);
+                       error = ip6_if_output(ifp, ifp, m0, satocsin6(dst), rt);
 # else
                        error = nd6_output(ifp, ifp, m0, dst6, rt);
 # endif
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/net/if_arcsubr.c
--- a/sys/net/if_arcsubr.c      Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/net/if_arcsubr.c      Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arcsubr.c,v 1.76 2017/01/24 18:37:20 maxv Exp $     */
+/*     $NetBSD: if_arcsubr.c,v 1.77 2017/02/14 03:05:06 ozaki-r Exp $  */
 
 /*
  * Copyright (c) 1994, 1995 Ignatios Souvatzis
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.76 2017/01/24 18:37:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.77 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -218,8 +218,14 @@
 #endif
 #ifdef INET6
        case AF_INET6:
-               if (!nd6_storelladdr(ifp, rt, m, dst, &adst, sizeof(adst)))
-                       return (0); /* it must be impossible, but... */
+               if (m->m_flags & M_MCAST) {
+                       adst = 0;
+               } else {
+                       error = nd6_resolve(ifp, rt, m, dst, &adst,
+                           sizeof(adst));
+                       if (error != 0)
+                               return error == EWOULDBLOCK ? 0 : error;
+               }
                atype = htons(ARCTYPE_INET6);
                newencoding = 1;
                break;
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/net/if_ethersubr.c    Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.237 2017/02/12 09:36:05 skrll Exp $ */
+/*     $NetBSD: if_ethersubr.c,v 1.238 2017/02/14 03:05:06 ozaki-r Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.237 2017/02/12 09:36:05 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.238 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -303,9 +303,16 @@
 #endif
 #ifdef INET6
        case AF_INET6:
-               if (!nd6_storelladdr(ifp, rt, m, dst, edst, sizeof(edst))){
-                       /* something bad happened */
-                       return (0);
+               if (m->m_flags & M_BCAST)
+                       (void)memcpy(edst, etherbroadcastaddr, sizeof(edst));
+               else if (m->m_flags & M_MCAST) {
+                       ETHER_MAP_IPV6_MULTICAST(&satocsin6(dst)->sin6_addr,
+                           edst);
+               } else {
+                       error = nd6_resolve(ifp, rt, m, dst, edst,
+                           sizeof(edst));
+                       if (error != 0)
+                               return error == EWOULDBLOCK ? 0 : error;
                }
                etype = htons(ETHERTYPE_IPV6);
                break;
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/net/if_fddisubr.c
--- a/sys/net/if_fddisubr.c     Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/net/if_fddisubr.c     Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_fddisubr.c,v 1.104 2017/01/24 18:37:20 maxv Exp $   */
+/*     $NetBSD: if_fddisubr.c,v 1.105 2017/02/14 03:05:06 ozaki-r Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_fddisubr.c,v 1.104 2017/01/24 18:37:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_fddisubr.c,v 1.105 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -250,9 +250,18 @@
 #endif
 #ifdef INET6
        case AF_INET6:
-               if (!nd6_storelladdr(ifp, rt, m, dst, edst, sizeof(edst))){
-                       /* something bad happened */
-                       return (0);
+               if (m->m_flags & M_BCAST)
+                       (void)memcpy(edst, fddibroadcastaddr, sizeof(edst));
+               else if (m->m_flags & M_MCAST) {
+                       ETHER_MAP_IPV6_MULTICAST(&satocsin6(dst)->sin6_addr,
+                           edst);
+               } else {
+                       error = nd6_resolve(ifp, rt, m, dst, edst,
+                           sizeof(edst));
+                       if (error != 0) {
+                               error = error == EWOULDBLOCK ? 0 : error;
+                               return error;
+                       }
                }
                etype = htons(ETHERTYPE_IPV6);
                break;
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/net/if_ieee1394subr.c
--- a/sys/net/if_ieee1394subr.c Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/net/if_ieee1394subr.c Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ieee1394subr.c,v 1.58 2016/10/03 11:06:06 ozaki-r Exp $     */
+/*     $NetBSD: if_ieee1394subr.c,v 1.59 2017/02/14 03:05:06 ozaki-r Exp $     */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.58 2016/10/03 11:06:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.59 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -154,10 +154,21 @@
 #endif /* INET */
 #ifdef INET6
        case AF_INET6:
-               if (unicast && (!nd6_storelladdr(ifp, rt, m0, dst,
-                   hwdst->iha_uid, IEEE1394_ADDR_LEN))) {
-                       /* something bad happened */
-                       return 0;
+#if 0
+               /*
+                * XXX This code was in nd6_storelladdr, which was replaced with
+                * nd6_resolve, but it never be used because nd6_storelladdr was
+                * called only if unicast. Should it be enabled?
+                */
+               if (m0->m_flags & M_BCAST)
+                       memcpy(hwdst->iha_uid, ifp->if_broadcastaddr,
+                           MIN(IEEE1394_ADDR_LEN, ifp->if_addrlen));
+#endif
+               if (unicast) {
+                       error = nd6_resolve(ifp, rt, m0, dst, hwdst->iha_uid,
+                           IEEE1394_ADDR_LEN);
+                       if (error != 0)
+                               return error == EWOULDBLOCK ? 0 : error;
                }
                etype = htons(ETHERTYPE_IPV6);
                break;
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/net/if_srt.c
--- a/sys/net/if_srt.c  Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/net/if_srt.c  Tue Feb 14 03:05:06 2017 +0000
@@ -1,8 +1,8 @@
-/* $NetBSD: if_srt.c,v 1.25 2017/02/09 11:43:32 kre Exp $ */
+/* $NetBSD: if_srt.c,v 1.26 2017/02/14 03:05:06 ozaki-r Exp $ */
 /* This file is in the public domain. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.25 2017/02/09 11:43:32 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.26 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -36,6 +36,7 @@
 #include <netinet/ip.h>
 #include <netinet/ip6.h>
 #include <netinet6/in6_var.h>
+#include <netinet6/ip6_var.h>
 #include <netinet6/nd6.h>
 #include <netinet6/scope6_var.h>
 #include <net/if_types.h>
@@ -240,7 +241,7 @@
        }
        /* XXX is 0 the right last arg here? */
        if (to->sa_family == AF_INET6)
-               return nd6_output(r->u.dstifp, r->u.dstifp, m, &r->dst.sin6, 0);
+               return ip6_if_output(r->u.dstifp, r->u.dstifp, m, &r->dst.sin6, 0);
        return if_output_lock(r->u.dstifp, r->u.dstifp, m, &r->dst.sa, 0);
 }
 
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/netinet6/in6_offload.c
--- a/sys/netinet6/in6_offload.c        Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/netinet6/in6_offload.c        Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_offload.c,v 1.6 2011/04/25 22:07:57 yamt Exp $     */
+/*     $NetBSD: in6_offload.c,v 1.7 2017/02/14 03:05:06 ozaki-r Exp $  */
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_offload.c,v 1.6 2011/04/25 22:07:57 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_offload.c,v 1.7 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -39,6 +39,7 @@
 #include <netinet/ip6.h>
 #include <netinet/tcp.h>
 #include <netinet6/in6_var.h>
+#include <netinet6/ip6_var.h>
 #include <netinet6/nd6.h>
 #include <netinet6/in6_offload.h>
 
@@ -56,7 +57,7 @@
 {
        struct ip6_tso_output_args *args = vp;
 
-       return nd6_output(args->ifp, args->origifp, m, args->dst, args->rt);
+       return ip6_if_output(args->ifp, args->origifp, m, args->dst, args->rt);
 }
 
 int
diff -r e08dafb3740c -r 6dcf86a3f8a3 sys/netinet6/ip6_forward.c
--- a/sys/netinet6/ip6_forward.c        Tue Feb 14 01:18:39 2017 +0000
+++ b/sys/netinet6/ip6_forward.c        Tue Feb 14 03:05:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_forward.c,v 1.85 2017/01/16 15:44:47 christos Exp $        */
+/*     $NetBSD: ip6_forward.c,v 1.86 2017/02/14 03:05:06 ozaki-r Exp $ */
 /*     $KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $   */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.85 2017/01/16 15:44:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.86 2017/02/14 03:05:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -401,7 +401,7 @@
                goto freecopy;
        ip6 = mtod(m, struct ip6_hdr *);
 
-       error = nd6_output(rt->rt_ifp, origifp, m, dst, rt);



Home | Main Index | Thread Index | Old Index