selftests: netdevsim: Add test cases for route deletion failure

Add IPv4 and IPv6 test cases that ensure that we are not leaking a
reference on the nexthop device when we are unable to delete its
associated route.

Without the fix in a previous patch ("netdevsim: fib: Fix reference
count leak on route deletion failure") both test cases get stuck,
waiting for the reference to be released from the dummy device [1][2].

[1]
unregister_netdevice: waiting for dummy1 to become free. Usage count = 5
leaked reference.
 fib_check_nh+0x275/0x620
 fib_create_info+0x237c/0x4d30
 fib_table_insert+0x1dd/0x1d20
 inet_rtm_newroute+0x11b/0x200
 rtnetlink_rcv_msg+0x43b/0xd20
 netlink_rcv_skb+0x15e/0x430
 netlink_unicast+0x53b/0x800
 netlink_sendmsg+0x945/0xe40
 ____sys_sendmsg+0x747/0x960
 ___sys_sendmsg+0x11d/0x190
 __sys_sendmsg+0x118/0x1e0
 do_syscall_64+0x34/0x80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

[2]
unregister_netdevice: waiting for dummy1 to become free. Usage count = 5
leaked reference.
 fib6_nh_init+0xc46/0x1ca0
 ip6_route_info_create+0x1167/0x19a0
 ip6_route_add+0x27/0x150
 inet6_rtm_newroute+0x161/0x170
 rtnetlink_rcv_msg+0x43b/0xd20
 netlink_rcv_skb+0x15e/0x430
 netlink_unicast+0x53b/0x800
 netlink_sendmsg+0x945/0xe40
 ____sys_sendmsg+0x747/0x960
 ___sys_sendmsg+0x11d/0x190
 __sys_sendmsg+0x118/0x1e0
 do_syscall_64+0x34/0x80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Amit Cohen <amcohen@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Ido Schimmel 2022-07-28 14:45:35 +03:00 committed by David S. Miller
parent 974be75f25
commit 40823f3ee0
1 changed files with 45 additions and 0 deletions

View File

@ -16,6 +16,7 @@ ALL_TESTS="
ipv4_replay
ipv4_flush
ipv4_error_path
ipv4_delete_fail
ipv6_add
ipv6_metric
ipv6_append_single
@ -29,11 +30,13 @@ ALL_TESTS="
ipv6_replay_single
ipv6_replay_multipath
ipv6_error_path
ipv6_delete_fail
"
NETDEVSIM_PATH=/sys/bus/netdevsim/
DEV_ADDR=1337
DEV=netdevsim${DEV_ADDR}
SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV/
NUM_NETIFS=0
source $lib_dir/lib.sh
source $lib_dir/fib_offload_lib.sh
@ -157,6 +160,27 @@ ipv4_error_path()
ipv4_error_path_replay
}
ipv4_delete_fail()
{
RET=0
echo "y" > $DEBUGFS_DIR/fib/fail_route_delete
ip -n testns1 link add name dummy1 type dummy
ip -n testns1 link set dev dummy1 up
ip -n testns1 route add 192.0.2.0/24 dev dummy1
ip -n testns1 route del 192.0.2.0/24 dev dummy1 &> /dev/null
# We should not be able to delete the netdev if we are leaking a
# reference.
ip -n testns1 link del dev dummy1
log_test "IPv4 route delete failure"
echo "n" > $DEBUGFS_DIR/fib/fail_route_delete
}
ipv6_add()
{
fib_ipv6_add_test "testns1"
@ -304,6 +328,27 @@ ipv6_error_path()
ipv6_error_path_replay
}
ipv6_delete_fail()
{
RET=0
echo "y" > $DEBUGFS_DIR/fib/fail_route_delete
ip -n testns1 link add name dummy1 type dummy
ip -n testns1 link set dev dummy1 up
ip -n testns1 route add 2001:db8:1::/64 dev dummy1
ip -n testns1 route del 2001:db8:1::/64 dev dummy1 &> /dev/null
# We should not be able to delete the netdev if we are leaking a
# reference.
ip -n testns1 link del dev dummy1
log_test "IPv6 route delete failure"
echo "n" > $DEBUGFS_DIR/fib/fail_route_delete
}
fib_notify_on_flag_change_set()
{
local notify=$1; shift