diff options
Diffstat (limited to 'tools/testing/selftests/net')
| -rw-r--r-- | tools/testing/selftests/net/config | 1 | ||||
| -rwxr-xr-x | tools/testing/selftests/net/fcnal-test.sh | 63 | ||||
| -rw-r--r-- | tools/testing/selftests/net/forwarding/Makefile | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/net/forwarding/forwarding.config.sample | 2 | ||||
| -rwxr-xr-x | tools/testing/selftests/net/forwarding/ip6_forward_instats_vrf.sh | 172 | ||||
| -rw-r--r-- | tools/testing/selftests/net/forwarding/lib.sh | 8 | ||||
| -rw-r--r-- | tools/testing/selftests/net/nettest.c | 28 | 
7 files changed, 273 insertions, 2 deletions
| diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index 21b646d10b88..86ab429fe7f3 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -43,3 +43,4 @@ CONFIG_NET_ACT_TUNNEL_KEY=m  CONFIG_NET_ACT_MIRRED=m  CONFIG_BAREUDP=m  CONFIG_IPV6_IOAM6_LWTUNNEL=y +CONFIG_CRYPTO_SM4=y diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh index 13350cd5c8ac..3313566ce906 100755 --- a/tools/testing/selftests/net/fcnal-test.sh +++ b/tools/testing/selftests/net/fcnal-test.sh @@ -289,6 +289,12 @@ set_sysctl()  	run_cmd sysctl -q -w $*  } +# get sysctl values in NS-A +get_sysctl() +{ +	${NSA_CMD} sysctl -n $* +} +  ################################################################################  # Setup for tests @@ -439,10 +445,13 @@ cleanup()  		ip -netns ${NSA} link set dev ${NSA_DEV} down  		ip -netns ${NSA} link del dev ${NSA_DEV} +		ip netns pids ${NSA} | xargs kill 2>/dev/null  		ip netns del ${NSA}  	fi +	ip netns pids ${NSB} | xargs kill 2>/dev/null  	ip netns del ${NSB} +	ip netns pids ${NSC} | xargs kill 2>/dev/null  	ip netns del ${NSC} >/dev/null 2>&1  } @@ -1003,6 +1012,60 @@ ipv4_tcp_md5()  	run_cmd nettest -s -I ${NSA_DEV} -M ${MD5_PW} -m ${NS_NET}  	log_test $? 1 "MD5: VRF: Device must be a VRF - prefix" +	test_ipv4_md5_vrf__vrf_server__no_bind_ifindex +	test_ipv4_md5_vrf__global_server__bind_ifindex0 +} + +test_ipv4_md5_vrf__vrf_server__no_bind_ifindex() +{ +	log_start +	show_hint "Simulates applications using VRF without TCP_MD5SIG_FLAG_IFINDEX" +	run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} --no-bind-key-ifindex & +	sleep 1 +	run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW} +	log_test $? 0 "MD5: VRF: VRF-bound server, unbound key accepts connection" + +	log_start +	show_hint "Binding both the socket and the key is not required but it works" +	run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} --force-bind-key-ifindex & +	sleep 1 +	run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW} +	log_test $? 0 "MD5: VRF: VRF-bound server, bound key accepts connection" +} + +test_ipv4_md5_vrf__global_server__bind_ifindex0() +{ +	# This particular test needs tcp_l3mdev_accept=1 for Global server to accept VRF connections +	local old_tcp_l3mdev_accept +	old_tcp_l3mdev_accept=$(get_sysctl net.ipv4.tcp_l3mdev_accept) +	set_sysctl net.ipv4.tcp_l3mdev_accept=1 + +	log_start +	run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --force-bind-key-ifindex & +	sleep 1 +	run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW} +	log_test $? 2 "MD5: VRF: Global server, Key bound to ifindex=0 rejects VRF connection" + +	log_start +	run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --force-bind-key-ifindex & +	sleep 1 +	run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_PW} +	log_test $? 0 "MD5: VRF: Global server, key bound to ifindex=0 accepts non-VRF connection" +	log_start + +	run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --no-bind-key-ifindex & +	sleep 1 +	run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW} +	log_test $? 0 "MD5: VRF: Global server, key not bound to ifindex accepts VRF connection" + +	log_start +	run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --no-bind-key-ifindex & +	sleep 1 +	run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_PW} +	log_test $? 0 "MD5: VRF: Global server, key not bound to ifindex accepts non-VRF connection" + +	# restore value +	set_sysctl net.ipv4.tcp_l3mdev_accept="$old_tcp_l3mdev_accept"  }  ipv4_tcp_novrf() diff --git a/tools/testing/selftests/net/forwarding/Makefile b/tools/testing/selftests/net/forwarding/Makefile index d97bd6889446..72ee644d47bf 100644 --- a/tools/testing/selftests/net/forwarding/Makefile +++ b/tools/testing/selftests/net/forwarding/Makefile @@ -9,6 +9,7 @@ TEST_PROGS = bridge_igmp.sh \  	gre_inner_v4_multipath.sh \  	gre_inner_v6_multipath.sh \  	gre_multipath.sh \ +	ip6_forward_instats_vrf.sh \  	ip6gre_inner_v4_multipath.sh \  	ip6gre_inner_v6_multipath.sh \  	ipip_flat_gre_key.sh \ diff --git a/tools/testing/selftests/net/forwarding/forwarding.config.sample b/tools/testing/selftests/net/forwarding/forwarding.config.sample index b802c14d2950..e5e2fbeca22e 100644 --- a/tools/testing/selftests/net/forwarding/forwarding.config.sample +++ b/tools/testing/selftests/net/forwarding/forwarding.config.sample @@ -39,3 +39,5 @@ NETIF_CREATE=yes  # Timeout (in seconds) before ping exits regardless of how many packets have  # been sent or received  PING_TIMEOUT=5 +# IPv6 traceroute utility name. +TROUTE6=traceroute6 diff --git a/tools/testing/selftests/net/forwarding/ip6_forward_instats_vrf.sh b/tools/testing/selftests/net/forwarding/ip6_forward_instats_vrf.sh new file mode 100755 index 000000000000..9f5b3e2e5e95 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/ip6_forward_instats_vrf.sh @@ -0,0 +1,172 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# Test ipv6 stats on the incoming if when forwarding with VRF + +ALL_TESTS=" +	ipv6_ping +	ipv6_in_too_big_err +	ipv6_in_hdr_err +	ipv6_in_addr_err +	ipv6_in_discard +" + +NUM_NETIFS=4 +source lib.sh + +h1_create() +{ +	simple_if_init $h1 2001:1:1::2/64 +	ip -6 route add vrf v$h1 2001:1:2::/64 via 2001:1:1::1 +} + +h1_destroy() +{ +	ip -6 route del vrf v$h1 2001:1:2::/64 via 2001:1:1::1 +	simple_if_fini $h1 2001:1:1::2/64 +} + +router_create() +{ +	vrf_create router +	__simple_if_init $rtr1 router 2001:1:1::1/64 +	__simple_if_init $rtr2 router 2001:1:2::1/64 +	mtu_set $rtr2 1280 +} + +router_destroy() +{ +	mtu_restore $rtr2 +	__simple_if_fini $rtr2 2001:1:2::1/64 +	__simple_if_fini $rtr1 2001:1:1::1/64 +	vrf_destroy router +} + +h2_create() +{ +	simple_if_init $h2 2001:1:2::2/64 +	ip -6 route add vrf v$h2 2001:1:1::/64 via 2001:1:2::1 +	mtu_set $h2 1280 +} + +h2_destroy() +{ +	mtu_restore $h2 +	ip -6 route del vrf v$h2 2001:1:1::/64 via 2001:1:2::1 +	simple_if_fini $h2 2001:1:2::2/64 +} + +setup_prepare() +{ +	h1=${NETIFS[p1]} +	rtr1=${NETIFS[p2]} + +	rtr2=${NETIFS[p3]} +	h2=${NETIFS[p4]} + +	vrf_prepare +	h1_create +	router_create +	h2_create + +	forwarding_enable +} + +cleanup() +{ +	pre_cleanup + +	forwarding_restore + +	h2_destroy +	router_destroy +	h1_destroy +	vrf_cleanup +} + +ipv6_in_too_big_err() +{ +	RET=0 + +	local t0=$(ipv6_stats_get $rtr1 Ip6InTooBigErrors) +	local vrf_name=$(master_name_get $h1) + +	# Send too big packets +	ip vrf exec $vrf_name \ +		$PING6 -s 1300 2001:1:2::2 -c 1 -w $PING_TIMEOUT &> /dev/null + +	local t1=$(ipv6_stats_get $rtr1 Ip6InTooBigErrors) +	test "$((t1 - t0))" -ne 0 +	check_err $? +	log_test "Ip6InTooBigErrors" +} + +ipv6_in_hdr_err() +{ +	RET=0 + +	local t0=$(ipv6_stats_get $rtr1 Ip6InHdrErrors) +	local vrf_name=$(master_name_get $h1) + +	# Send packets with hop limit 1, easiest with traceroute6 as some ping6 +	# doesn't allow hop limit to be specified +	ip vrf exec $vrf_name \ +		$TROUTE6 2001:1:2::2 &> /dev/null + +	local t1=$(ipv6_stats_get $rtr1 Ip6InHdrErrors) +	test "$((t1 - t0))" -ne 0 +	check_err $? +	log_test "Ip6InHdrErrors" +} + +ipv6_in_addr_err() +{ +	RET=0 + +	local t0=$(ipv6_stats_get $rtr1 Ip6InAddrErrors) +	local vrf_name=$(master_name_get $h1) + +	# Disable forwarding temporary while sending the packet +	sysctl -qw net.ipv6.conf.all.forwarding=0 +	ip vrf exec $vrf_name \ +		$PING6 2001:1:2::2 -c 1 -w $PING_TIMEOUT &> /dev/null +	sysctl -qw net.ipv6.conf.all.forwarding=1 + +	local t1=$(ipv6_stats_get $rtr1 Ip6InAddrErrors) +	test "$((t1 - t0))" -ne 0 +	check_err $? +	log_test "Ip6InAddrErrors" +} + +ipv6_in_discard() +{ +	RET=0 + +	local t0=$(ipv6_stats_get $rtr1 Ip6InDiscards) +	local vrf_name=$(master_name_get $h1) + +	# Add a policy to discard +	ip xfrm policy add dst 2001:1:2::2/128 dir fwd action block +	ip vrf exec $vrf_name \ +		$PING6 2001:1:2::2 -c 1 -w $PING_TIMEOUT &> /dev/null +	ip xfrm policy del dst 2001:1:2::2/128 dir fwd + +	local t1=$(ipv6_stats_get $rtr1 Ip6InDiscards) +	test "$((t1 - t0))" -ne 0 +	check_err $? +	log_test "Ip6InDiscards" +} +ipv6_ping() +{ +	RET=0 + +	ping6_test $h1 2001:1:2::2 +} + +trap cleanup EXIT + +setup_prepare +setup_wait +tests_run + +exit $EXIT_STATUS diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index e7fc5c35b569..92087d423bcf 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -751,6 +751,14 @@ qdisc_parent_stats_get()  	    | jq '.[] | select(.parent == "'"$parent"'") | '"$selector"  } +ipv6_stats_get() +{ +	local dev=$1; shift +	local stat=$1; shift + +	cat /proc/net/dev_snmp6/$dev | grep "^$stat" | cut -f2 +} +  humanize()  {  	local speed=$1; shift diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c index bd6288302094..b599003eb5ba 100644 --- a/tools/testing/selftests/net/nettest.c +++ b/tools/testing/selftests/net/nettest.c @@ -28,6 +28,7 @@  #include <unistd.h>  #include <time.h>  #include <errno.h> +#include <getopt.h>  #include <linux/xfrm.h>  #include <linux/ipsec.h> @@ -101,6 +102,8 @@ struct sock_args {  		struct sockaddr_in6 v6;  	} md5_prefix;  	unsigned int prefix_len; +	/* 0: default, -1: force off, +1: force on */ +	int bind_key_ifindex;  	/* expected addresses and device index for connection */  	const char *expected_dev; @@ -271,11 +274,14 @@ static int tcp_md5sig(int sd, void *addr, socklen_t alen, struct sock_args *args  	}  	memcpy(&md5sig.tcpm_addr, addr, alen); -	if (args->ifindex) { +	if ((args->ifindex && args->bind_key_ifindex >= 0) || args->bind_key_ifindex >= 1) {  		opt = TCP_MD5SIG_EXT;  		md5sig.tcpm_flags |= TCP_MD5SIG_FLAG_IFINDEX;  		md5sig.tcpm_ifindex = args->ifindex; +		log_msg("TCP_MD5SIG_FLAG_IFINDEX set tcpm_ifindex=%d\n", md5sig.tcpm_ifindex); +	} else { +		log_msg("TCP_MD5SIG_FLAG_IFINDEX off\n", md5sig.tcpm_ifindex);  	}  	rc = setsockopt(sd, IPPROTO_TCP, opt, &md5sig, sizeof(md5sig)); @@ -1822,6 +1828,14 @@ static int ipc_parent(int cpid, int fd, struct sock_args *args)  }  #define GETOPT_STR  "sr:l:c:p:t:g:P:DRn:M:X:m:d:I:BN:O:SCi6xL:0:1:2:3:Fbq" +#define OPT_FORCE_BIND_KEY_IFINDEX 1001 +#define OPT_NO_BIND_KEY_IFINDEX 1002 + +static struct option long_opts[] = { +	{"force-bind-key-ifindex", 0, 0, OPT_FORCE_BIND_KEY_IFINDEX}, +	{"no-bind-key-ifindex", 0, 0, OPT_NO_BIND_KEY_IFINDEX}, +	{0, 0, 0, 0} +};  static void print_usage(char *prog)  { @@ -1858,6 +1872,10 @@ static void print_usage(char *prog)  	"    -M password   use MD5 sum protection\n"  	"    -X password   MD5 password for client mode\n"  	"    -m prefix/len prefix and length to use for MD5 key\n" +	"    --no-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX off\n" +	"    --force-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX on\n" +	"        (default: only if -I is passed)\n" +	"\n"  	"    -g grp        multicast group (e.g., 239.1.1.1)\n"  	"    -i            interactive mode (default is echo and terminate)\n"  	"\n" @@ -1893,7 +1911,7 @@ int main(int argc, char *argv[])  	 * process input args  	 */ -	while ((rc = getopt(argc, argv, GETOPT_STR)) != -1) { +	while ((rc = getopt_long(argc, argv, GETOPT_STR, long_opts, NULL)) != -1) {  		switch (rc) {  		case 'B':  			both_mode = 1; @@ -1966,6 +1984,12 @@ int main(int argc, char *argv[])  		case 'M':  			args.password = optarg;  			break; +		case OPT_FORCE_BIND_KEY_IFINDEX: +			args.bind_key_ifindex = 1; +			break; +		case OPT_NO_BIND_KEY_IFINDEX: +			args.bind_key_ifindex = -1; +			break;  		case 'X':  			args.client_pw = optarg;  			break; |