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

Requested by dyoung@ some time ago
This commit is contained in:
ozaki-r 2017-06-28 04:14:53 +00:00
parent fcbd6bf4fa
commit da803ed70d
7 changed files with 123 additions and 27 deletions

View File

@ -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 $ */ /* $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $ */
/* /*
@ -59,6 +59,11 @@
#include "prog_ops.h" #include "prog_ops.h"
#include "rtutil.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 PLEN (LONG_BIT / 4 + 2)
#define PFKEYV2_CHUNK sizeof(u_int64_t) #define PFKEYV2_CHUNK sizeof(u_int64_t)
@ -84,7 +89,7 @@ static const struct bits bits[] = {
/* { RTF_CLONING, 'C' }, */ /* { RTF_CLONING, 'C' }, */
{ RTF_CONNECTED, 'C' }, { RTF_CONNECTED, 'C' },
/* { RTF_XRESOLVE, 'X' }, */ /* { RTF_XRESOLVE, 'X' }, */
/* { RTF_LLINFO, 'L' }, */ { RTF_LLINFO, 'L' },
{ RTF_STATIC, 'S' }, { RTF_STATIC, 'S' },
{ RTF_PROTO1, '1' }, { RTF_PROTO1, '1' },
{ RTF_PROTO2, '2' }, { RTF_PROTO2, '2' },
@ -263,6 +268,9 @@ p_rtentry(struct rt_msghdr *rtm, int flags, int interesting)
char ifbuf[IF_NAMESIZE]; char ifbuf[IF_NAMESIZE];
#endif #endif
if ((flags & RT_LFLAG) && (rtm->rtm_flags & RTF_LLINFO))
return;
if (old_af != sa->sa_family) { if (old_af != sa->sa_family) {
old_af = sa->sa_family; old_af = sa->sa_family;
p_family(sa->sa_family); p_family(sa->sa_family);

View File

@ -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 Luigi Rizzo, Alessandro Cerri. All rights reserved.
* Copyright (c) 2004-2008 Qing Li. All rights reserved. * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@ -80,6 +80,8 @@ int
lltable_dump_entry(struct lltable *llt, struct llentry *lle, lltable_dump_entry(struct lltable *llt, struct llentry *lle,
struct rt_walkarg *w, struct sockaddr *sa) struct rt_walkarg *w, struct sockaddr *sa)
{ {
#define RTF_LLINFO 0x400
#define RTF_CLONED 0x2000
struct ifnet *ifp = llt->llt_ifp; struct ifnet *ifp = llt->llt_ifp;
int error; int error;
void *a; void *a;
@ -107,9 +109,14 @@ lltable_dump_entry(struct lltable *llt, struct llentry *lle,
struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem; struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
/* Need to copy by myself */ /* Need to copy by myself */
rtm->rtm_index = ifp->if_index;
rtm->rtm_rmx.rmx_mtu = 0;
rtm->rtm_rmx.rmx_expire = rtm->rtm_rmx.rmx_expire =
(lle->la_flags & LLE_STATIC) ? 0 : lle->la_expire; (lle->la_flags & LLE_STATIC) ? 0 : lle->la_expire;
rtm->rtm_flags = RTF_UP;
rtm->rtm_flags |= RTF_HOST; /* For ndp */ 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; rtm->rtm_flags |= (lle->la_flags & LLE_STATIC) ? RTF_STATIC : 0;
if (lle->la_flags & LLE_PUB) if (lle->la_flags & LLE_PUB)
rtm->rtm_flags |= RTF_ANNOUNCE; rtm->rtm_flags |= RTF_ANNOUNCE;
@ -121,6 +128,8 @@ lltable_dump_entry(struct lltable *llt, struct llentry *lle,
} }
return error; return error;
#undef RTF_LLINFO
#undef RTF_CLONED
} }
/* /*

View File

@ -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. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/ */
#include <sys/cdefs.h> #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 #ifdef _KERNEL_OPT
#include "opt_inet.h" #include "opt_inet.h"
@ -1932,10 +1932,22 @@ again:
} }
#endif #endif
for (i = 1; i <= AF_MAX; i++) for (i = 1; i <= AF_MAX; i++) {
if ((af == 0 || af == i) && if (af == 0 || af == i) {
(error = rt_walktree(i, sysctl_dumpentry, &w))) error = rt_walktree(i, sysctl_dumpentry, &w);
break; 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; break;
#ifdef COMPAT_14 #ifdef COMPAT_14

View File

@ -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. # Copyright (c) 2015 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -113,6 +113,7 @@ setup_dst_server()
$DEBUG && rump.ifconfig shmif0 $DEBUG && rump.ifconfig shmif0
$DEBUG && rump.arp -n -a $DEBUG && rump.arp -n -a
$DEBUG && rump.netstat -nr -f inet
} }
setup_src_server() setup_src_server()
@ -136,6 +137,7 @@ setup_src_server()
# Sanity check # Sanity check
$DEBUG && rump.ifconfig shmif0 $DEBUG && rump.ifconfig shmif0
$DEBUG && rump.arp -n -a $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 $IP4SRC
atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
} }
@ -161,6 +163,8 @@ test_cache_expiration()
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 $IP4SRC
# Should be cached # Should be cached
atf_check -s exit:0 -o ignore rump.arp -n $IP4DST 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)) atf_check -s exit:0 sleep $(($arp_keep + $bonus))
@ -184,6 +188,23 @@ arp_cache_expiration_10s_body()
rump_server_destroy_ifaces 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() arp_command_body()
{ {
local arp_keep=5 local arp_keep=5
@ -201,11 +222,13 @@ arp_command_body()
$DEBUG && rump.arp -n -a $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 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 $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 $DEBUG && rump.netstat -nr -f inet
atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10 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 atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
$DEBUG && rump.arp -n -a $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 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 # Add multiple entries via a file
cat - > ./list <<-EOF cat - > ./list <<-EOF
@ -216,18 +239,15 @@ arp_command_body()
10.0.1.15 b2:a0:20:00:00:15 10.0.1.15 b2:a0:20:00:00:15
EOF EOF
$DEBUG && rump.arp -n -a $DEBUG && rump.arp -n -a
$DEBUG && rump.netstat -nr -f inet
atf_check -s exit:0 -o ignore rump.arp -f ./list atf_check -s exit:0 -o ignore rump.arp -f ./list
$DEBUG && rump.arp -n -a $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 $DEBUG && rump.netstat -nr -f inet
atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11 check_arp_static_entry 10.0.1.11 'b2:a0:20:00:00:11' permanent
atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12 check_arp_static_entry 10.0.1.12 'b2:a0:20:00:00:12' permanent
atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12 check_arp_static_entry 10.0.1.13 'b2:a0:20:00:00:13' permanent
atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13 check_arp_static_entry 10.0.1.14 'b2:a0:20:00:00:14' permanent
atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13 check_arp_static_entry 10.0.1.15 'b2:a0:20:00:00:15' permanent
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
# Test arp -a # Test arp -a
atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
@ -238,6 +258,7 @@ arp_command_body()
# Flush all entries # Flush all entries
$DEBUG && rump.arp -n -a $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 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.11
atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
@ -245,17 +266,23 @@ arp_command_body()
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.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.15
atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1 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 # Test temp option
$DEBUG && rump.arp -n -a $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 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 $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 $DEBUG && rump.netstat -nr -f inet
atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10 check_arp_static_entry 10.0.1.10 'b2:a0:20:00:00:10' temp
# Hm? the cache doesn't expire... # Hm? the cache doesn't expire...
atf_check -s exit:0 sleep $(($arp_keep + $bonus)) atf_check -s exit:0 sleep $(($arp_keep + $bonus))
$DEBUG && rump.arp -n -a $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 #atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
rump_server_destroy_ifaces rump_server_destroy_ifaces

View File

@ -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. # Copyright (c) 2015 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -167,9 +167,11 @@ ndp_commands_body()
atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
$DEBUG && rump.ndp -n -a $DEBUG && rump.ndp -n -a
atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10 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 atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10
$DEBUG && rump.ndp -n -a $DEBUG && rump.ndp -n -a
atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10 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) # Add multiple entries via a file (XXX not implemented)
#cat - > ./list <<-EOF #cat - > ./list <<-EOF
@ -190,6 +192,9 @@ ndp_commands_body()
atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST 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::11
atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12 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 # Test ndp -a
atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
@ -203,15 +208,20 @@ ndp_commands_body()
atf_check -s exit:0 -o ignore rump.ndp -c 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 $IP6SRC
atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST 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 # Only the static caches are not deleted
atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11
atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12
check_route_flags fc00::11 UHLS
check_route_flags fc00::12 UHLS
$DEBUG && rump.ndp -n -a $DEBUG && rump.ndp -n -a
atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
$DEBUG && rump.ndp -n -a $DEBUG && rump.ndp -n -a
atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
check_route fc00::10 'b2:a0:20:00:00:10' UHL shmif0
rump_server_destroy_ifaces rump_server_destroy_ifaces
} }

View File

@ -1,4 +1,4 @@
# $NetBSD: t_flags.sh,v 1.17 2017/06/27 04:56:13 ozaki-r Exp $ # $NetBSD: t_flags.sh,v 1.18 2017/06/28 04:14:53 ozaki-r Exp $
# #
# Copyright (c) 2015 The NetBSD Foundation, Inc. # Copyright (c) 2015 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -300,6 +300,20 @@ test_announce()
# TODO test its behavior # TODO test its behavior
} }
test_llinfo()
{
local peer_macaddr=
peer_macaddr=$(get_macaddr $SOCK_PEER shmif0)
export RUMP_SERVER=$SOCK_LOCAL
atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
# Up, Host, LLINFO
check_route 10.0.0.1 $peer_macaddr UHL shmif0
}
add_test() add_test()
{ {
local name=$1 local name=$1
@ -334,4 +348,5 @@ atf_init_test_cases()
add_test reject "Tests route flags: reject route" add_test reject "Tests route flags: reject route"
add_test icmp_redirect "Tests route flags: icmp redirect" add_test icmp_redirect "Tests route flags: icmp redirect"
add_test announce "Tests route flags: announce flag" add_test announce "Tests route flags: announce flag"
add_test llinfo "Tests route flags: ARP caches"
} }

View File

@ -1,4 +1,4 @@
# $NetBSD: t_flags6.sh,v 1.13 2017/06/27 04:52:45 ozaki-r Exp $ # $NetBSD: t_flags6.sh,v 1.14 2017/06/28 04:14:53 ozaki-r Exp $
# #
# Copyright (c) 2016 Internet Initiative Japan Inc. # Copyright (c) 2016 Internet Initiative Japan Inc.
# All rights reserved. # All rights reserved.
@ -238,6 +238,20 @@ test_announce6()
# TODO test its behavior # TODO test its behavior
} }
test_llinfo6()
{
local peer_macaddr=
peer_macaddr=$(get_macaddr $SOCK_PEER shmif0)
export RUMP_SERVER=$SOCK_LOCAL
atf_check -s exit:0 -o ignore rump.ping6 -n -X 1 -c 1 $IP6_PEER
# Up, Host, LLINFO
check_route $IP6_PEER $peer_macaddr UHL shmif0
}
add_test() add_test()
{ {
local name=$1 local name=$1
@ -271,4 +285,5 @@ atf_init_test_cases()
add_test blackhole6 "Tests route flags: blackhole route" add_test blackhole6 "Tests route flags: blackhole route"
add_test reject6 "Tests route flags: reject route" add_test reject6 "Tests route flags: reject route"
add_test announce6 "Tests route flags: announce flag" add_test announce6 "Tests route flags: announce flag"
add_test llinfo6 "Tests route flags: announce llinfo"
} }