Skip to content

Commit 3be42c3

Browse files
Vadim FedorenkoPaolo Abeni
authored andcommitted
selftests: fib_test: Add test case for ipv4 multi nexthops
The test checks that with multi nexthops route the preferred route is the one which matches source ip. In case when source ip is on dummy interface, it checks that the routes are balanced. Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Link: https://patch.msgid.link/20251221192639.3911901-2-vadim.fedorenko@linux.dev Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 6e17474 commit 3be42c3

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

tools/testing/selftests/net/fib_tests.sh

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
1212
ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \
1313
ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \
1414
ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \
15-
fib6_ra_to_static"
15+
ipv4_mpath_balance_preferred fib6_ra_to_static"
1616

1717
VERBOSE=0
1818
PAUSE_ON_FAIL=no
@@ -2751,6 +2751,73 @@ ipv4_mpath_balance_test()
27512751
forwarding_cleanup
27522752
}
27532753

2754+
get_route_dev_src()
2755+
{
2756+
local pfx="$1"
2757+
local src="$2"
2758+
local out
2759+
2760+
if out=$($IP -j route get "$pfx" from "$src" | jq -re ".[0].dev"); then
2761+
echo "$out"
2762+
fi
2763+
}
2764+
2765+
ipv4_mpath_preferred()
2766+
{
2767+
local src_ip=$1
2768+
local pref_dev=$2
2769+
local dev routes
2770+
local route0=0
2771+
local route1=0
2772+
local pref_route=0
2773+
num_routes=254
2774+
2775+
for i in $(seq 1 $num_routes) ; do
2776+
dev=$(get_route_dev_src 172.16.105.$i $src_ip)
2777+
if [ "$dev" = "$pref_dev" ]; then
2778+
pref_route=$((pref_route+1))
2779+
elif [ "$dev" = "veth1" ]; then
2780+
route0=$((route0+1))
2781+
elif [ "$dev" = "veth3" ]; then
2782+
route1=$((route1+1))
2783+
fi
2784+
done
2785+
2786+
routes=$((route0+route1))
2787+
2788+
[ "$VERBOSE" = "1" ] && echo "multipath: routes seen: ($route0,$route1,$pref_route)"
2789+
2790+
if [ x"$pref_dev" = x"" ]; then
2791+
[[ $routes -ge $num_routes ]] && [[ $route0 -gt 0 ]] && [[ $route1 -gt 0 ]]
2792+
else
2793+
[[ $pref_route -ge $num_routes ]]
2794+
fi
2795+
2796+
}
2797+
2798+
ipv4_mpath_balance_preferred_test()
2799+
{
2800+
echo
2801+
echo "IPv4 multipath load balance preferred route"
2802+
2803+
forwarding_setup
2804+
2805+
$IP route add 172.16.105.0/24 \
2806+
nexthop via 172.16.101.2 \
2807+
nexthop via 172.16.103.2
2808+
2809+
ipv4_mpath_preferred 172.16.101.1 veth1
2810+
log_test $? 0 "IPv4 multipath loadbalance from veth1"
2811+
2812+
ipv4_mpath_preferred 172.16.103.1 veth3
2813+
log_test $? 0 "IPv4 multipath loadbalance from veth3"
2814+
2815+
ipv4_mpath_preferred 198.51.100.1
2816+
log_test $? 0 "IPv4 multipath loadbalance from dummy"
2817+
2818+
forwarding_cleanup
2819+
}
2820+
27542821
ipv6_mpath_balance_test()
27552822
{
27562823
echo
@@ -2861,6 +2928,7 @@ do
28612928
ipv6_mpath_list) ipv6_mpath_list_test;;
28622929
ipv4_mpath_balance) ipv4_mpath_balance_test;;
28632930
ipv6_mpath_balance) ipv6_mpath_balance_test;;
2931+
ipv4_mpath_balance_preferred) ipv4_mpath_balance_preferred_test;;
28642932
fib6_ra_to_static) fib6_ra_to_static;;
28652933

28662934
help) echo "Test names: $TESTS"; exit 0;;

0 commit comments

Comments
 (0)