[net,v2,2/2] selftests: fib_tests: Add test cases for IPv4/IPv6 in route notify

Message ID 20230216042624.4069910-3-luwei32@huawei.com
State New
Headers
Series Fix a fib6 info notification bug |

Commit Message

Lu Wei Feb. 16, 2023, 4:26 a.m. UTC
  Add tests to check whether the total fib info length is calculated
corretly in route notify process.

Signed-off-by: Lu Wei <luwei32@huawei.com>
---
 tools/testing/selftests/net/fib_tests.sh | 92 +++++++++++++++++++++++-
 1 file changed, 91 insertions(+), 1 deletion(-)
  

Comments

David Ahern Feb. 16, 2023, 5:52 a.m. UTC | #1
On 2/15/23 9:26 PM, Lu Wei wrote:
> diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
> index 5637b5dadabd..4e48154bd195 100755
> --- a/tools/testing/selftests/net/fib_tests.sh
> +++ b/tools/testing/selftests/net/fib_tests.sh
> @@ -9,7 +9,7 @@ ret=0
>  ksft_skip=4
>  
>  # all tests in this script. Can be overridden with -t option
> -TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
> +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
>  
>  VERBOSE=0
>  PAUSE_ON_FAIL=no
> @@ -655,6 +655,94 @@ fib_nexthop_test()
>  	cleanup
>  }
>  
> +fib6_notify_test()
> +{
> +	setup
> +
> +	echo
> +	echo "Fib6 info length calculation in route notify test"
> +	set -e
> +
> +	for i in 10 20 30 40 50 60 70;
> +	do
> +		$IP link add dummy$i type dummy
> +		$IP link set dev dummy$i up
> +		$IP -6 addr add 2002::$i/64 dev dummy$i
> +	done
> +
> +	for i in 10 20 30 40 50 60;
> +	do
> +		$IP -6 route append 100::/64 encap ip6 dst 2002::$i via \
> +		2002::1 dev dummy$i metric 100
> +	done

That creates a multipath route because of a quirk with IPv6. It would be
better to make this explicit by

	nexthops=
	for i in 10 20 30 40 50 60;
	do
		nexthops="$nexthops nexthop encap ip6 dst 2002::$i via 2002::1 dev
dummy$i metric 100"
	done

	$IP -6 route add 100::/64 ${nexthops}

> +
> +fib_notify_test()
> +{
> +	setup
> +
> +	echo
> +	echo "Fib4 info length calculation in route notify test"
> +
> +	set -e
> +
> +	for i in 10 20 30 40 50 60 70;
> +	do
> +		$IP link add dummy$i type dummy
> +		$IP link set dev dummy$i up
> +		$IP addr add 192.168.100.$i/24 dev dummy$i
> +	done
> +
> +	for i in 10 20 30 40 50 60;
> +	do
> +		$IP route append 10.0.0.0/24 encap ip dst 192.168.100.$i via \
> +		192.168.100.1 dev dummy$i metric 100
> +	done

With IPv4 that is not a multipath route but a series of independent
routes. Hence, doing the loop here like I showed above makes sure this
is a proper multipath route.

Thank you for adding the tests.
  

Patch

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index 5637b5dadabd..4e48154bd195 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -9,7 +9,7 @@  ret=0
 ksft_skip=4
 
 # all tests in this script. Can be overridden with -t option
-TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
+TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
 
 VERBOSE=0
 PAUSE_ON_FAIL=no
@@ -655,6 +655,94 @@  fib_nexthop_test()
 	cleanup
 }
 
+fib6_notify_test()
+{
+	setup
+
+	echo
+	echo "Fib6 info length calculation in route notify test"
+	set -e
+
+	for i in 10 20 30 40 50 60 70;
+	do
+		$IP link add dummy$i type dummy
+		$IP link set dev dummy$i up
+		$IP -6 addr add 2002::$i/64 dev dummy$i
+	done
+
+	for i in 10 20 30 40 50 60;
+	do
+		$IP -6 route append 100::/64 encap ip6 dst 2002::$i via \
+		2002::1 dev dummy$i metric 100
+	done
+
+	set +e
+
+	$NS_EXEC ip monitor route 2> errors.txt &
+
+	$IP -6 route append 100::/64 via 2002::1 dev dummy70 metric 100
+
+	err=`cat errors.txt |grep "Message too long"`
+	if [ -z "$err" ];then
+		ret=0
+	else
+		ret=1
+	fi
+
+	log_test $ret 0 "ipv6 route add notify"
+
+	{ kill %% && wait %%; } 2>/dev/null
+
+	rm errors.txt
+
+	cleanup &> /dev/null
+}
+
+
+fib_notify_test()
+{
+	setup
+
+	echo
+	echo "Fib4 info length calculation in route notify test"
+
+	set -e
+
+	for i in 10 20 30 40 50 60 70;
+	do
+		$IP link add dummy$i type dummy
+		$IP link set dev dummy$i up
+		$IP addr add 192.168.100.$i/24 dev dummy$i
+	done
+
+	for i in 10 20 30 40 50 60;
+	do
+		$IP route append 10.0.0.0/24 encap ip dst 192.168.100.$i via \
+		192.168.100.1 dev dummy$i metric 100
+	done
+
+	$NS_EXEC ip monitor route 2> errors.txt &
+
+	set +e
+
+	$IP route append 10.0.0.0/24 via 192.168.100.1 dev dummy70 metric 100
+
+	err=`cat errors.txt |grep "Message too long"`
+	if [ -z "$err" ];then
+		ret=0
+	else
+		ret=1
+	fi
+
+	log_test $ret 0 "ipv4 route add notify"
+
+	{ kill %% && wait %%; } 2>/dev/null
+
+	rm errors.txt
+
+	cleanup &> /dev/null
+}
+
 fib_suppress_test()
 {
 	echo
@@ -2109,6 +2197,8 @@  do
 	fib_carrier_test|carrier)	fib_carrier_test;;
 	fib_rp_filter_test|rp_filter)	fib_rp_filter_test;;
 	fib_nexthop_test|nexthop)	fib_nexthop_test;;
+	fib_notify_test|ipv4_notify)	fib_notify_test;;
+	fib6_notify_test|ipv6_notify)	fib6_notify_test;;
 	fib_suppress_test|suppress)	fib_suppress_test;;
 	ipv6_route_test|ipv6_rt)	ipv6_route_test;;
 	ipv4_route_test|ipv4_rt)	ipv4_route_test;;