Source-Changes-HG archive

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

[src/trunk]: src Restore ARP/NDP entries to route show and netstat -r



details:   https://anonhg.NetBSD.org/src/rev/a95e2550c761
branches:  trunk
changeset: 825056:a95e2550c761
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Jun 28 04:14:53 2017 +0000

description:
Restore ARP/NDP entries to route show and netstat -r

Requested by dyoung@ some time ago

diffstat:

 sbin/route/rtutil.c         |  12 +++++++-
 sys/net/if_llatbl.c         |  11 +++++++-
 sys/net/rtsock.c            |  24 ++++++++++++++----
 tests/net/arp/t_arp.sh      |  57 +++++++++++++++++++++++++++++++++-----------
 tests/net/ndp/t_ndp.sh      |  12 ++++++++-
 tests/net/route/t_flags.sh  |  17 ++++++++++++-
 tests/net/route/t_flags6.sh |  17 ++++++++++++-
 7 files changed, 123 insertions(+), 27 deletions(-)

diffs (truncated from 385 to 300 lines):

diff -r 7044725fdcaa -r a95e2550c761 sbin/route/rtutil.c
--- a/sbin/route/rtutil.c       Wed Jun 28 04:10:47 2017 +0000
+++ b/sbin/route/rtutil.c       Wed Jun 28 04:14:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtutil.c,v 1.8 2016/04/04 07:37:07 ozaki-r Exp $       */
+/*     $NetBSD: rtutil.c,v 1.9 2017/06/28 04:14:53 ozaki-r Exp $       */
 /*     $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $        */
 
 /*
@@ -59,6 +59,11 @@
 #include "prog_ops.h"
 #include "rtutil.h"
 
+/*
+ * Keep to handle ARP/NDP entries (fake routes)
+ * for backward compatibility.
+ */
+#define RTF_LLINFO     0x400
 
 #define PLEN    (LONG_BIT / 4 + 2)
 #define PFKEYV2_CHUNK sizeof(u_int64_t)
@@ -84,7 +89,7 @@
        /* { RTF_CLONING,       'C' }, */
        { RTF_CONNECTED, 'C' },
        /* { RTF_XRESOLVE,      'X' }, */
-       /* { RTF_LLINFO,        'L' }, */
+       { RTF_LLINFO,   'L' },
        { RTF_STATIC,   'S' },
        { RTF_PROTO1,   '1' },
        { RTF_PROTO2,   '2' },
@@ -263,6 +268,9 @@
        char             ifbuf[IF_NAMESIZE];
 #endif
 
+       if ((flags & RT_LFLAG) && (rtm->rtm_flags & RTF_LLINFO))
+               return;
+
        if (old_af != sa->sa_family) {
                old_af = sa->sa_family;
                p_family(sa->sa_family);
diff -r 7044725fdcaa -r a95e2550c761 sys/net/if_llatbl.c
--- a/sys/net/if_llatbl.c       Wed Jun 28 04:10:47 2017 +0000
+++ b/sys/net/if_llatbl.c       Wed Jun 28 04:14:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_llatbl.c,v 1.20 2017/06/23 05:46:10 ozaki-r Exp $   */
+/*     $NetBSD: if_llatbl.c,v 1.21 2017/06/28 04:14:53 ozaki-r Exp $   */
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -80,6 +80,8 @@
 lltable_dump_entry(struct lltable *llt, struct llentry *lle,
     struct rt_walkarg *w, struct sockaddr *sa)
 {
+#define RTF_LLINFO     0x400
+#define RTF_CLONED     0x2000
        struct ifnet *ifp = llt->llt_ifp;
        int error;
        void *a;
@@ -107,9 +109,14 @@
                struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
 
                /* Need to copy by myself */
+               rtm->rtm_index = ifp->if_index;
+               rtm->rtm_rmx.rmx_mtu = 0;
                rtm->rtm_rmx.rmx_expire =
                    (lle->la_flags & LLE_STATIC) ? 0 : lle->la_expire;
+               rtm->rtm_flags = RTF_UP;
                rtm->rtm_flags |= RTF_HOST; /* For ndp */
+               /* For backward compatibility */
+               rtm->rtm_flags |= RTF_LLINFO | RTF_CLONED;
                rtm->rtm_flags |= (lle->la_flags & LLE_STATIC) ? RTF_STATIC : 0;
                if (lle->la_flags & LLE_PUB)
                        rtm->rtm_flags |= RTF_ANNOUNCE;
@@ -121,6 +128,8 @@
        }
 
        return error;
+#undef RTF_LLINFO
+#undef RTF_CLONED
 }
 
 /*
diff -r 7044725fdcaa -r a95e2550c761 sys/net/rtsock.c
--- a/sys/net/rtsock.c  Wed Jun 28 04:10:47 2017 +0000
+++ b/sys/net/rtsock.c  Wed Jun 28 04:14:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.223 2017/06/26 06:59:56 ozaki-r Exp $     */
+/*     $NetBSD: rtsock.c,v 1.224 2017/06/28 04:14:53 ozaki-r Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.223 2017/06/26 06:59:56 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.224 2017/06/28 04:14:53 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1932,10 +1932,22 @@
                }
 #endif
 
-               for (i = 1; i <= AF_MAX; i++)
-                       if ((af == 0 || af == i) &&
-                           (error = rt_walktree(i, sysctl_dumpentry, &w)))
-                               break;
+               for (i = 1; i <= AF_MAX; i++) {
+                       if (af == 0 || af == i) {
+                               error = rt_walktree(i, sysctl_dumpentry, &w);
+                               if (error != 0)
+                                       break;
+#if defined(INET) || defined(INET6)
+                               /*
+                                * Return ARP/NDP entries too for
+                                * backward compatibility.
+                                */
+                               error = lltable_sysctl_dump(i, &w);
+                               if (error != 0)
+                                       break;
+#endif
+                       }
+               }
                break;
 
 #ifdef COMPAT_14
diff -r 7044725fdcaa -r a95e2550c761 tests/net/arp/t_arp.sh
--- a/tests/net/arp/t_arp.sh    Wed Jun 28 04:10:47 2017 +0000
+++ b/tests/net/arp/t_arp.sh    Wed Jun 28 04:14:53 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_arp.sh,v 1.31 2017/06/28 04:10:47 ozaki-r Exp $
+#      $NetBSD: t_arp.sh,v 1.32 2017/06/28 04:14:53 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -113,6 +113,7 @@
 
        $DEBUG && rump.ifconfig shmif0
        $DEBUG && rump.arp -n -a
+       $DEBUG && rump.netstat -nr -f inet
 }
 
 setup_src_server()
@@ -136,6 +137,7 @@
        # Sanity check
        $DEBUG && rump.ifconfig shmif0
        $DEBUG && rump.arp -n -a
+       $DEBUG && rump.netstat -nr -f inet
        atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
        atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
 }
@@ -161,6 +163,8 @@
        atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
        # Should be cached
        atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
+       $DEBUG && rump.netstat -nr -f inet
+       atf_check -s exit:0 -o match:"$IP4DST" rump.netstat -nr -f inet
 
        atf_check -s exit:0 sleep $(($arp_keep + $bonus))
 
@@ -184,6 +188,23 @@
        rump_server_destroy_ifaces
 }
 
+check_arp_static_entry()
+{
+       local ip=$1
+       local mac=$2
+       local type=$3
+       local flags=
+
+       atf_check -s exit:0 -o match:"$mac" rump.arp -n $ip
+       if [ $type = 'permanent' ]; then
+               atf_check -s exit:0 -o match:'permanent' rump.arp -n $ip
+               check_route $ip "$mac" UHLS shmif0
+       else
+               atf_check -s exit:0 -o not-match:'permanent' rump.arp -n $ip
+               check_route $ip "$mac" UHL shmif0
+       fi
+}
+
 arp_command_body()
 {
        local arp_keep=5
@@ -201,11 +222,13 @@
        $DEBUG && rump.arp -n -a
        atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
        $DEBUG && rump.arp -n -a
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
-       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
+       $DEBUG && rump.netstat -nr -f inet
+       check_arp_static_entry 10.0.1.10 'b2:a0:20:00:00:10' permanent
        atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
        $DEBUG && rump.arp -n -a
+       $DEBUG && rump.netstat -nr -f inet
        atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
+       check_route_no_entry 10.0.1.10
 
        # Add multiple entries via a file
        cat - > ./list <<-EOF
@@ -216,18 +239,15 @@
        10.0.1.15 b2:a0:20:00:00:15
        EOF
        $DEBUG && rump.arp -n -a
+       $DEBUG && rump.netstat -nr -f inet
        atf_check -s exit:0 -o ignore rump.arp -f ./list
        $DEBUG && rump.arp -n -a
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
-       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
-       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
-       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
-       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
-       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
+       $DEBUG && rump.netstat -nr -f inet
+       check_arp_static_entry 10.0.1.11 'b2:a0:20:00:00:11' permanent
+       check_arp_static_entry 10.0.1.12 'b2:a0:20:00:00:12' permanent
+       check_arp_static_entry 10.0.1.13 'b2:a0:20:00:00:13' permanent
+       check_arp_static_entry 10.0.1.14 'b2:a0:20:00:00:14' permanent
+       check_arp_static_entry 10.0.1.15 'b2:a0:20:00:00:15' permanent
 
        # Test arp -a
        atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
@@ -238,6 +258,7 @@
 
        # Flush all entries
        $DEBUG && rump.arp -n -a
+       $DEBUG && rump.netstat -nr -f inet
        atf_check -s exit:0 -o ignore rump.arp -d -a
        atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
        atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
@@ -245,17 +266,23 @@
        atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
        atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
        atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
+       check_route_no_entry 10.0.1.11
+       check_route_no_entry 10.0.1.12
+       check_route_no_entry 10.0.1.13
+       check_route_no_entry 10.0.1.14
+       check_route_no_entry 10.0.1.15
 
        # Test temp option
        $DEBUG && rump.arp -n -a
        atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
        $DEBUG && rump.arp -n -a
-       atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
-       atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
+       $DEBUG && rump.netstat -nr -f inet
+       check_arp_static_entry 10.0.1.10 'b2:a0:20:00:00:10' temp
 
        # Hm? the cache doesn't expire...
        atf_check -s exit:0 sleep $(($arp_keep + $bonus))
        $DEBUG && rump.arp -n -a
+       $DEBUG && rump.netstat -nr -f inet
        #atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
 
        rump_server_destroy_ifaces
diff -r 7044725fdcaa -r a95e2550c761 tests/net/ndp/t_ndp.sh
--- a/tests/net/ndp/t_ndp.sh    Wed Jun 28 04:10:47 2017 +0000
+++ b/tests/net/ndp/t_ndp.sh    Wed Jun 28 04:14:53 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_ndp.sh,v 1.27 2017/06/26 06:59:57 ozaki-r Exp $
+#      $NetBSD: t_ndp.sh,v 1.28 2017/06/28 04:14:53 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -167,9 +167,11 @@
        atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
        $DEBUG && rump.ndp -n -a
        atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10
+       check_route fc00::10 'b2:a0:20:00:00:10' UHLS shmif0
        atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10
        $DEBUG && rump.ndp -n -a
        atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10
+       check_route_no_entry fc00::10
 
        # Add multiple entries via a file (XXX not implemented)
        #cat - > ./list <<-EOF
@@ -190,6 +192,9 @@
        atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
        atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11
        atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12
+       check_route_flags $IP6DST UHL
+       check_route_flags fc00::11 UHLS
+       check_route_flags fc00::12 UHLS
 
        # Test ndp -a
        atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
@@ -203,15 +208,20 @@
        atf_check -s exit:0 -o ignore rump.ndp -c
        atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6SRC
        atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
+       #check_route_no_entry $IP6SRC
+       check_route_no_entry $IP6DST
        # Only the static caches are not deleted
        atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11



Home | Main Index | Thread Index | Old Index