Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vadim Fedorenko and committed by
Paolo Abeni
3be42c3b 6e17474a

+69 -1
+69 -1
tools/testing/selftests/net/fib_tests.sh
··· 12 12 ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \ 13 13 ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \ 14 14 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" 16 16 17 17 VERBOSE=0 18 18 PAUSE_ON_FAIL=no ··· 2751 2751 forwarding_cleanup 2752 2752 } 2753 2753 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 + 2754 2821 ipv6_mpath_balance_test() 2755 2822 { 2756 2823 echo ··· 2928 2861 ipv6_mpath_list) ipv6_mpath_list_test;; 2929 2862 ipv4_mpath_balance) ipv4_mpath_balance_test;; 2930 2863 ipv6_mpath_balance) ipv6_mpath_balance_test;; 2864 + ipv4_mpath_balance_preferred) ipv4_mpath_balance_preferred_test;; 2931 2865 fib6_ra_to_static) fib6_ra_to_static;; 2932 2866 2933 2867 help) echo "Test names: $TESTS"; exit 0;;