2 # SPDX-License-Identifier: GPL-2.0
4 # Copyright (c) 2019 David Ahern <dsahern@gmail.com>. All rights reserved.
6 # IPv4 and IPv6 functional tests focusing on VRF and routing lookups
7 # for various permutations:
8 # 1. icmp, tcp, udp and netfilter
9 # 2. client, server, no-server
10 # 3. global address on interface
11 # 4. global address on 'lo'
12 # 5. remote and local traffic
13 # 6. VRF and non-VRF permutations
18 # [ lo ] [ eth1 ]---|---[ eth1 ] [ lo ]
21 # [ red ]---[ eth1 ]---|---[ eth1 ] [ lo ]
24 # eth1: 172.16.1.1/24, 2001:db8:1::1/64
25 # lo: 127.0.0.1/8, ::1/128
26 # 172.16.2.1/32, 2001:db8:2::1/128
27 # red: 127.0.0.1/8, ::1/128
28 # 172.16.3.1/32, 2001:db8:3::1/128
31 # eth1: 172.16.1.2/24, 2001:db8:1::2/64
32 # lo2: 127.0.0.1/8, ::1/128
33 # 172.16.2.2/32, 2001:db8:2::2/128
35 # ns-A to ns-C connection - only for VRF and same config
38 # server / client nomenclature relative to ns-A
59 NS_NET6=2001:db8:1::/120
63 NSA_LO_IP6=2001:db8:2::1
64 NSB_LO_IP6=2001:db8:2::2
70 # set after namespace create
78 NSA_CMD="ip netns exec ${NSA}"
79 NSB_CMD="ip netns exec ${NSB}"
80 NSC_CMD="ip netns exec ${NSC}"
82 which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
84 ################################################################################
93 [ "${VERBOSE}" = "1" ] && echo
95 if [ ${rc} -eq ${expected} ]; then
96 nsuccess=$((nsuccess+1))
97 printf "TEST: %-70s [ OK ]\n" "${msg}"
100 printf "TEST: %-70s [FAIL]\n" "${msg}"
101 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
103 echo "hit enter to continue, 'q' to quit"
105 [ "$a" = "q" ] && exit 1
109 if [ "${PAUSE}" = "yes" ]; then
111 echo "hit enter to continue, 'q' to quit"
113 [ "$a" = "q" ] && exit 1
127 astr=$(addr2str ${addr})
128 log_test $rc $expected "$msg - ${astr}"
134 echo "###########################################################################"
136 echo "###########################################################################"
143 echo "#################################################################"
150 # make sure we have no test instances running
153 if [ "${VERBOSE}" = "1" ]; then
155 echo "#######################################################"
161 if [ "${VERBOSE}" = "1" ]; then
170 if [ "${VERBOSE}" = "1" ]; then
178 killall nettest ping ping6 >/dev/null 2>&1
187 if [ "$VERBOSE" = "1" ]; then
188 echo "COMMAND: ${cmd}"
193 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
202 do_run_cmd ${NSA_CMD} $*
207 do_run_cmd ${NSB_CMD} $*
212 do_run_cmd ${NSC_CMD} $*
222 if [ $rc -ne 0 ]; then
223 # show user the command if not done so already
224 if [ "$VERBOSE" = "0" ]; then
225 echo "setup command: $cmd"
227 echo "failed. stopping tests"
228 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
230 echo "hit enter to continue"
244 if [ $rc -ne 0 ]; then
245 # show user the command if not done so already
246 if [ "$VERBOSE" = "0" ]; then
247 echo "setup command: $cmd"
249 echo "failed. stopping tests"
250 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
252 echo "hit enter to continue"
266 if [ $rc -ne 0 ]; then
267 # show user the command if not done so already
268 if [ "$VERBOSE" = "0" ]; then
269 echo "setup command: $cmd"
271 echo "failed. stopping tests"
272 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
274 echo "hit enter to continue"
281 # set sysctl values in NS-A
286 run_cmd sysctl -q -w $*
289 ################################################################################
295 127.0.0.1) echo "loopback";;
296 ::1) echo "IPv6 loopback";;
298 ${NSA_IP}) echo "ns-A IP";;
299 ${NSA_IP6}) echo "ns-A IPv6";;
300 ${NSA_LO_IP}) echo "ns-A loopback IP";;
301 ${NSA_LO_IP6}) echo "ns-A loopback IPv6";;
302 ${NSA_LINKIP6}|${NSA_LINKIP6}%*) echo "ns-A IPv6 LLA";;
304 ${NSB_IP}) echo "ns-B IP";;
305 ${NSB_IP6}) echo "ns-B IPv6";;
306 ${NSB_LO_IP}) echo "ns-B loopback IP";;
307 ${NSB_LO_IP6}) echo "ns-B loopback IPv6";;
308 ${NSB_LINKIP6}|${NSB_LINKIP6}%*) echo "ns-B IPv6 LLA";;
310 ${VRF_IP}) echo "VRF IP";;
311 ${VRF_IP6}) echo "VRF IPv6";;
313 ${MCAST}%*) echo "multicast IP";;
325 addr=$(ip -netns ${ns} -6 -br addr show dev ${dev} | \
327 for (i = 3; i <= NF; ++i) {
335 [ -z "$addr" ] && return 1
342 ################################################################################
343 # create namespaces and vrf
353 ip -netns ${ns} link add ${vrf} type vrf table ${table}
354 ip -netns ${ns} link set ${vrf} up
355 ip -netns ${ns} route add vrf ${vrf} unreachable default metric 8192
356 ip -netns ${ns} -6 route add vrf ${vrf} unreachable default metric 8192
358 ip -netns ${ns} addr add 127.0.0.1/8 dev ${vrf}
359 ip -netns ${ns} -6 addr add ::1 dev ${vrf} nodad
360 if [ "${addr}" != "-" ]; then
361 ip -netns ${ns} addr add dev ${vrf} ${addr}
363 if [ "${addr6}" != "-" ]; then
364 ip -netns ${ns} -6 addr add dev ${vrf} ${addr6}
367 ip -netns ${ns} ru del pref 0
368 ip -netns ${ns} ru add pref 32765 from all lookup local
369 ip -netns ${ns} -6 ru del pref 0
370 ip -netns ${ns} -6 ru add pref 32765 from all lookup local
381 ip -netns ${ns} link set lo up
382 if [ "${addr}" != "-" ]; then
383 ip -netns ${ns} addr add dev lo ${addr}
385 if [ "${addr6}" != "-" ]; then
386 ip -netns ${ns} -6 addr add dev lo ${addr6}
389 ip -netns ${ns} ro add unreachable default metric 8192
390 ip -netns ${ns} -6 ro add unreachable default metric 8192
392 ip netns exec ${ns} sysctl -qw net.ipv4.ip_forward=1
393 ip netns exec ${ns} sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1
394 ip netns exec ${ns} sysctl -qw net.ipv6.conf.all.forwarding=1
395 ip netns exec ${ns} sysctl -qw net.ipv6.conf.default.forwarding=1
398 # create veth pair to connect namespaces and apply addresses.
410 ip -netns ${ns1} li add ${ns1_dev} type veth peer name tmp
411 ip -netns ${ns1} li set ${ns1_dev} up
412 ip -netns ${ns1} li set tmp netns ${ns2} name ${ns2_dev}
413 ip -netns ${ns2} li set ${ns2_dev} up
415 if [ "${ns1_addr}" != "-" ]; then
416 ip -netns ${ns1} addr add dev ${ns1_dev} ${ns1_addr}
417 ip -netns ${ns2} addr add dev ${ns2_dev} ${ns2_addr}
420 if [ "${ns1_addr6}" != "-" ]; then
421 ip -netns ${ns1} addr add dev ${ns1_dev} ${ns1_addr6}
422 ip -netns ${ns2} addr add dev ${ns2_dev} ${ns2_addr6}
428 # explicit cleanups to check those code paths
429 ip netns | grep -q ${NSA}
430 if [ $? -eq 0 ]; then
431 ip -netns ${NSA} link delete ${VRF}
432 ip -netns ${NSA} ro flush table ${VRF_TABLE}
434 ip -netns ${NSA} addr flush dev ${NSA_DEV}
435 ip -netns ${NSA} -6 addr flush dev ${NSA_DEV}
436 ip -netns ${NSA} link set dev ${NSA_DEV} down
437 ip -netns ${NSA} link del dev ${NSA_DEV}
443 ip netns del ${NSC} >/dev/null 2>&1
450 # make sure we are starting with a clean slate
454 log_debug "Configuring network namespaces"
457 create_ns ${NSA} ${NSA_LO_IP}/32 ${NSA_LO_IP6}/128
458 create_ns ${NSB} ${NSB_LO_IP}/32 ${NSB_LO_IP6}/128
459 connect_ns ${NSA} ${NSA_DEV} ${NSA_IP}/24 ${NSA_IP6}/64 \
460 ${NSB} ${NSB_DEV} ${NSB_IP}/24 ${NSB_IP6}/64
462 NSA_LINKIP6=$(get_linklocal ${NSA} ${NSA_DEV})
463 NSB_LINKIP6=$(get_linklocal ${NSB} ${NSB_DEV})
465 # tell ns-A how to get to remote addresses of ns-B
466 if [ "${with_vrf}" = "yes" ]; then
467 create_vrf ${NSA} ${VRF} ${VRF_TABLE} ${VRF_IP} ${VRF_IP6}
469 ip -netns ${NSA} link set dev ${NSA_DEV} vrf ${VRF}
470 ip -netns ${NSA} ro add vrf ${VRF} ${NSB_LO_IP}/32 via ${NSB_IP} dev ${NSA_DEV}
471 ip -netns ${NSA} -6 ro add vrf ${VRF} ${NSB_LO_IP6}/128 via ${NSB_IP6} dev ${NSA_DEV}
473 ip -netns ${NSB} ro add ${VRF_IP}/32 via ${NSA_IP} dev ${NSB_DEV}
474 ip -netns ${NSB} -6 ro add ${VRF_IP6}/128 via ${NSA_IP6} dev ${NSB_DEV}
476 # some VRF tests use ns-C which has the same config as
477 # ns-B but for a device NOT in the VRF
478 create_ns ${NSC} "-" "-"
479 connect_ns ${NSA} ${NSA_DEV2} ${NSA_IP}/24 ${NSA_IP6}/64 \
480 ${NSC} ${NSC_DEV} ${NSB_IP}/24 ${NSB_IP6}/64
482 ip -netns ${NSA} ro add ${NSB_LO_IP}/32 via ${NSB_IP} dev ${NSA_DEV}
483 ip -netns ${NSA} ro add ${NSB_LO_IP6}/128 via ${NSB_IP6} dev ${NSA_DEV}
487 # tell ns-B how to get to remote addresses of ns-A
488 ip -netns ${NSB} ro add ${NSA_LO_IP}/32 via ${NSA_IP} dev ${NSB_DEV}
489 ip -netns ${NSB} ro add ${NSA_LO_IP6}/128 via ${NSA_IP6} dev ${NSB_DEV}
498 # make sure we are starting with a clean slate
502 log_debug "Configuring network namespaces"
505 create_ns ${NSA} "-" "-"
506 create_ns ${NSB} "-" "-"
507 create_ns ${NSC} "-" "-"
508 connect_ns ${NSA} ${NSA_DEV} "-" "-" \
509 ${NSB} ${NSB_DEV} "-" "-"
510 connect_ns ${NSA} ${NSA_DEV2} "-" "-" \
511 ${NSC} ${NSC_DEV} "-" "-"
513 NSA_LINKIP6=$(get_linklocal ${NSA} ${NSA_DEV})
514 NSB_LINKIP6=$(get_linklocal ${NSB} ${NSB_DEV})
515 NSC_LINKIP6=$(get_linklocal ${NSC} ${NSC_DEV})
517 create_vrf ${NSA} ${VRF} ${VRF_TABLE} "-" "-"
518 ip -netns ${NSA} link set dev ${NSA_DEV} vrf ${VRF}
519 ip -netns ${NSA} link set dev ${NSA_DEV2} vrf ${VRF}
526 ################################################################################
536 for a in ${NSB_IP} ${NSB_LO_IP}
539 run_cmd ping -c1 -w1 ${a}
540 log_test_addr ${a} $? 0 "ping out"
543 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
544 log_test_addr ${a} $? 0 "ping out, device bind"
547 run_cmd ping -c1 -w1 -I ${NSA_LO_IP} ${a}
548 log_test_addr ${a} $? 0 "ping out, address bind"
554 for a in ${NSA_IP} ${NSA_LO_IP}
557 run_cmd_nsb ping -c1 -w1 ${a}
558 log_test_addr ${a} $? 0 "ping in"
564 for a in ${NSA_IP} ${NSA_LO_IP} 127.0.0.1
567 run_cmd ping -c1 -w1 ${a}
568 log_test_addr ${a} $? 0 "ping local"
572 # local traffic, socket bound to device
577 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
578 log_test_addr ${a} $? 0 "ping local, device bind"
580 # loopback addresses not reachable from device bind
581 # fails in a really weird way though because ipv4 special cases
582 # route lookups with oif set.
583 for a in ${NSA_LO_IP} 127.0.0.1
586 show_hint "Fails since address on loopback device is out of device scope"
587 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
588 log_test_addr ${a} $? 1 "ping local, device bind"
592 # ip rule blocks reachability to remote address
595 setup_cmd ip rule add pref 32765 from all lookup local
596 setup_cmd ip rule del pref 0 from all lookup local
597 setup_cmd ip rule add pref 50 to ${NSB_LO_IP} prohibit
598 setup_cmd ip rule add pref 51 from ${NSB_IP} prohibit
601 run_cmd ping -c1 -w1 ${a}
602 log_test_addr ${a} $? 2 "ping out, blocked by rule"
604 # NOTE: ipv4 actually allows the lookup to fail and yet still create
605 # a viable rtable if the oif (e.g., bind to device) is set, so this
606 # case succeeds despite the rule
607 # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
611 show_hint "Response generates ICMP (or arp request is ignored) due to ip rule"
612 run_cmd_nsb ping -c1 -w1 ${a}
613 log_test_addr ${a} $? 1 "ping in, blocked by rule"
615 [ "$VERBOSE" = "1" ] && echo
616 setup_cmd ip rule del pref 32765 from all lookup local
617 setup_cmd ip rule add pref 0 from all lookup local
618 setup_cmd ip rule del pref 50 to ${NSB_LO_IP} prohibit
619 setup_cmd ip rule del pref 51 from ${NSB_IP} prohibit
622 # route blocks reachability to remote address
625 setup_cmd ip route replace unreachable ${NSB_LO_IP}
626 setup_cmd ip route replace unreachable ${NSB_IP}
629 run_cmd ping -c1 -w1 ${a}
630 log_test_addr ${a} $? 2 "ping out, blocked by route"
632 # NOTE: ipv4 actually allows the lookup to fail and yet still create
633 # a viable rtable if the oif (e.g., bind to device) is set, so this
634 # case succeeds despite not having a route for the address
635 # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
639 show_hint "Response is dropped (or arp request is ignored) due to ip route"
640 run_cmd_nsb ping -c1 -w1 ${a}
641 log_test_addr ${a} $? 1 "ping in, blocked by route"
644 # remove 'remote' routes; fallback to default
647 setup_cmd ip ro del ${NSB_LO_IP}
650 run_cmd ping -c1 -w1 ${a}
651 log_test_addr ${a} $? 2 "ping out, unreachable default route"
653 # NOTE: ipv4 actually allows the lookup to fail and yet still create
654 # a viable rtable if the oif (e.g., bind to device) is set, so this
655 # case succeeds despite not having a route for the address
656 # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
663 # should default on; does not exist on older kernels
664 set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
669 for a in ${NSB_IP} ${NSB_LO_IP}
672 run_cmd ping -c1 -w1 -I ${VRF} ${a}
673 log_test_addr ${a} $? 0 "ping out, VRF bind"
676 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
677 log_test_addr ${a} $? 0 "ping out, device bind"
680 run_cmd ip vrf exec ${VRF} ping -c1 -w1 -I ${NSA_IP} ${a}
681 log_test_addr ${a} $? 0 "ping out, vrf device + dev address bind"
684 run_cmd ip vrf exec ${VRF} ping -c1 -w1 -I ${VRF_IP} ${a}
685 log_test_addr ${a} $? 0 "ping out, vrf device + vrf address bind"
691 for a in ${NSA_IP} ${VRF_IP}
694 run_cmd_nsb ping -c1 -w1 ${a}
695 log_test_addr ${a} $? 0 "ping in"
699 # local traffic, local address
701 for a in ${NSA_IP} ${VRF_IP} 127.0.0.1
704 show_hint "Source address should be ${a}"
705 run_cmd ping -c1 -w1 -I ${VRF} ${a}
706 log_test_addr ${a} $? 0 "ping local, VRF bind"
710 # local traffic, socket bound to device
715 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
716 log_test_addr ${a} $? 0 "ping local, device bind"
718 # vrf device is out of scope
719 for a in ${VRF_IP} 127.0.0.1
722 show_hint "Fails since address on vrf device is out of device scope"
723 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
724 log_test_addr ${a} $? 1 "ping local, device bind"
728 # ip rule blocks address
731 setup_cmd ip rule add pref 50 to ${NSB_LO_IP} prohibit
732 setup_cmd ip rule add pref 51 from ${NSB_IP} prohibit
735 run_cmd ping -c1 -w1 -I ${VRF} ${a}
736 log_test_addr ${a} $? 2 "ping out, vrf bind, blocked by rule"
739 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
740 log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
744 show_hint "Response lost due to ip rule"
745 run_cmd_nsb ping -c1 -w1 ${a}
746 log_test_addr ${a} $? 1 "ping in, blocked by rule"
748 [ "$VERBOSE" = "1" ] && echo
749 setup_cmd ip rule del pref 50 to ${NSB_LO_IP} prohibit
750 setup_cmd ip rule del pref 51 from ${NSB_IP} prohibit
753 # remove 'remote' routes; fallback to default
756 setup_cmd ip ro del vrf ${VRF} ${NSB_LO_IP}
759 run_cmd ping -c1 -w1 -I ${VRF} ${a}
760 log_test_addr ${a} $? 2 "ping out, vrf bind, unreachable route"
763 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
764 log_test_addr ${a} $? 2 "ping out, device bind, unreachable route"
768 show_hint "Response lost by unreachable route"
769 run_cmd_nsb ping -c1 -w1 ${a}
770 log_test_addr ${a} $? 1 "ping in, unreachable route"
775 log_section "IPv4 ping"
777 log_subsection "No VRF"
779 set_sysctl net.ipv4.raw_l3mdev_accept=0 2>/dev/null
782 set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
785 log_subsection "With VRF"
790 ################################################################################
794 # MD5 tests without VRF
804 run_cmd nettest -s -M ${MD5_PW} -r ${NSB_IP} &
806 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
807 log_test $? 0 "MD5: Single address config"
809 # client sends MD5, server not configured
811 show_hint "Should timeout due to MD5 mismatch"
814 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
815 log_test $? 2 "MD5: Server no config, client uses password"
819 show_hint "Should timeout since client uses wrong password"
820 run_cmd nettest -s -M ${MD5_PW} -r ${NSB_IP} &
822 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
823 log_test $? 2 "MD5: Client uses wrong password"
825 # client from different address
827 show_hint "Should timeout due to MD5 mismatch"
828 run_cmd nettest -s -M ${MD5_PW} -r ${NSB_LO_IP} &
830 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
831 log_test $? 2 "MD5: Client address does not match address configured with password"
834 # MD5 extension - prefix length
839 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
841 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
842 log_test $? 0 "MD5: Prefix config"
844 # client in prefix, wrong password
846 show_hint "Should timeout since client uses wrong password"
847 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
849 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
850 log_test $? 2 "MD5: Prefix config, client uses wrong password"
852 # client outside of prefix
854 show_hint "Should timeout due to MD5 mismatch"
855 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
857 run_cmd_nsb nettest -l ${NSB_LO_IP} -r ${NSA_IP} -M ${MD5_PW}
858 log_test $? 2 "MD5: Prefix config, client address not in configured prefix"
872 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP} &
874 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
875 log_test $? 0 "MD5: VRF: Single address config"
877 # client sends MD5, server not configured
879 show_hint "Should timeout since server does not have MD5 auth"
880 run_cmd nettest -s -d ${VRF} &
882 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
883 log_test $? 2 "MD5: VRF: Server no config, client uses password"
887 show_hint "Should timeout since client uses wrong password"
888 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP} &
890 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
891 log_test $? 2 "MD5: VRF: Client uses wrong password"
893 # client from different address
895 show_hint "Should timeout since server config differs from client"
896 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_LO_IP} &
898 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
899 log_test $? 2 "MD5: VRF: Client address does not match address configured with password"
902 # MD5 extension - prefix length
907 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
909 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
910 log_test $? 0 "MD5: VRF: Prefix config"
912 # client in prefix, wrong password
914 show_hint "Should timeout since client uses wrong password"
915 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
917 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
918 log_test $? 2 "MD5: VRF: Prefix config, client uses wrong password"
920 # client outside of prefix
922 show_hint "Should timeout since client address is outside of prefix"
923 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
925 run_cmd_nsb nettest -l ${NSB_LO_IP} -r ${NSA_IP} -M ${MD5_PW}
926 log_test $? 2 "MD5: VRF: Prefix config, client address not in configured prefix"
929 # duplicate config between default VRF and a VRF
933 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP} &
934 run_cmd nettest -s -M ${MD5_WRONG_PW} -r ${NSB_IP} &
936 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
937 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF"
940 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP} &
941 run_cmd nettest -s -M ${MD5_WRONG_PW} -r ${NSB_IP} &
943 run_cmd_nsc nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
944 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF"
947 show_hint "Should timeout since client in default VRF uses VRF password"
948 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP} &
949 run_cmd nettest -s -M ${MD5_WRONG_PW} -r ${NSB_IP} &
951 run_cmd_nsc nettest -r ${NSA_IP} -M ${MD5_PW}
952 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF with VRF pw"
955 show_hint "Should timeout since client in VRF uses default VRF password"
956 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP} &
957 run_cmd nettest -s -M ${MD5_WRONG_PW} -r ${NSB_IP} &
959 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
960 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF with default VRF pw"
963 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
964 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
966 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_PW}
967 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF"
970 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
971 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
973 run_cmd_nsc nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
974 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF"
977 show_hint "Should timeout since client in default VRF uses VRF password"
978 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
979 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
981 run_cmd_nsc nettest -r ${NSA_IP} -M ${MD5_PW}
982 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF with VRF pw"
985 show_hint "Should timeout since client in VRF uses default VRF password"
986 run_cmd nettest -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET} &
987 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
989 run_cmd_nsb nettest -r ${NSA_IP} -M ${MD5_WRONG_PW}
990 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF with default VRF pw"
996 run_cmd nettest -s -d ${NSA_DEV} -M ${MD5_PW} -r ${NSB_IP}
997 log_test $? 1 "MD5: VRF: Device must be a VRF - single address"
1000 run_cmd nettest -s -d ${NSA_DEV} -M ${MD5_PW} -m ${NS_NET}
1001 log_test $? 1 "MD5: VRF: Device must be a VRF - prefix"
1012 for a in ${NSA_IP} ${NSA_LO_IP}
1015 run_cmd nettest -s &
1017 run_cmd_nsb nettest -r ${a}
1018 log_test_addr ${a} $? 0 "Global server"
1023 run_cmd nettest -s -d ${NSA_DEV} &
1025 run_cmd_nsb nettest -r ${a}
1026 log_test_addr ${a} $? 0 "Device server"
1028 # verify TCP reset sent and received
1029 for a in ${NSA_IP} ${NSA_LO_IP}
1032 show_hint "Should fail 'Connection refused' since there is no server"
1033 run_cmd_nsb nettest -r ${a}
1034 log_test_addr ${a} $? 1 "No server"
1040 for a in ${NSB_IP} ${NSB_LO_IP}
1043 run_cmd_nsb nettest -s &
1045 run_cmd nettest -r ${a} -0 ${NSA_IP}
1046 log_test_addr ${a} $? 0 "Client"
1049 run_cmd_nsb nettest -s &
1051 run_cmd nettest -r ${a} -d ${NSA_DEV}
1052 log_test_addr ${a} $? 0 "Client, device bind"
1055 show_hint "Should fail 'Connection refused'"
1056 run_cmd nettest -r ${a}
1057 log_test_addr ${a} $? 1 "No server, unbound client"
1060 show_hint "Should fail 'Connection refused'"
1061 run_cmd nettest -r ${a} -d ${NSA_DEV}
1062 log_test_addr ${a} $? 1 "No server, device client"
1066 # local address tests
1068 for a in ${NSA_IP} ${NSA_LO_IP} 127.0.0.1
1071 run_cmd nettest -s &
1073 run_cmd nettest -r ${a} -0 ${a} -1 ${a}
1074 log_test_addr ${a} $? 0 "Global server, local connection"
1079 run_cmd nettest -s -d ${NSA_DEV} &
1081 run_cmd nettest -r ${a} -0 ${a}
1082 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
1084 for a in ${NSA_LO_IP} 127.0.0.1
1087 show_hint "Should fail 'Connection refused' since addresses on loopback are out of device scope"
1088 run_cmd nettest -s -d ${NSA_DEV} &
1090 run_cmd nettest -r ${a}
1091 log_test_addr ${a} $? 1 "Device server, unbound client, local connection"
1096 run_cmd nettest -s &
1098 run_cmd nettest -r ${a} -0 ${a} -d ${NSA_DEV}
1099 log_test_addr ${a} $? 0 "Global server, device client, local connection"
1101 for a in ${NSA_LO_IP} 127.0.0.1
1104 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
1105 run_cmd nettest -s &
1107 run_cmd nettest -r ${a} -d ${NSA_DEV}
1108 log_test_addr ${a} $? 1 "Global server, device client, local connection"
1113 run_cmd nettest -s -d ${NSA_DEV} -2 ${NSA_DEV} &
1115 run_cmd nettest -d ${NSA_DEV} -r ${a} -0 ${a}
1116 log_test_addr ${a} $? 0 "Device server, device client, local connection"
1119 show_hint "Should fail 'Connection refused'"
1120 run_cmd nettest -d ${NSA_DEV} -r ${a}
1121 log_test_addr ${a} $? 1 "No server, device client, local conn"
1130 # disable global server
1131 log_subsection "Global server disabled"
1133 set_sysctl net.ipv4.tcp_l3mdev_accept=0
1138 for a in ${NSA_IP} ${VRF_IP}
1141 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
1142 run_cmd nettest -s &
1144 run_cmd_nsb nettest -r ${a}
1145 log_test_addr ${a} $? 1 "Global server"
1148 run_cmd nettest -s -d ${VRF} -2 ${VRF} &
1150 run_cmd_nsb nettest -r ${a}
1151 log_test_addr ${a} $? 0 "VRF server"
1154 run_cmd nettest -s -d ${NSA_DEV} -2 ${NSA_DEV} &
1156 run_cmd_nsb nettest -r ${a}
1157 log_test_addr ${a} $? 0 "Device server"
1159 # verify TCP reset received
1161 show_hint "Should fail 'Connection refused' since there is no server"
1162 run_cmd_nsb nettest -r ${a}
1163 log_test_addr ${a} $? 1 "No server"
1166 # local address tests
1167 # (${VRF_IP} and 127.0.0.1 both timeout)
1170 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
1171 run_cmd nettest -s &
1173 run_cmd nettest -r ${a} -d ${NSA_DEV}
1174 log_test_addr ${a} $? 1 "Global server, local connection"
1180 # enable VRF global server
1182 log_subsection "VRF Global server enabled"
1183 set_sysctl net.ipv4.tcp_l3mdev_accept=1
1185 for a in ${NSA_IP} ${VRF_IP}
1188 show_hint "client socket should be bound to VRF"
1189 run_cmd nettest -s -2 ${VRF} &
1191 run_cmd_nsb nettest -r ${a}
1192 log_test_addr ${a} $? 0 "Global server"
1195 show_hint "client socket should be bound to VRF"
1196 run_cmd nettest -s -d ${VRF} -2 ${VRF} &
1198 run_cmd_nsb nettest -r ${a}
1199 log_test_addr ${a} $? 0 "VRF server"
1201 # verify TCP reset received
1203 show_hint "Should fail 'Connection refused'"
1204 run_cmd_nsb nettest -r ${a}
1205 log_test_addr ${a} $? 1 "No server"
1210 show_hint "client socket should be bound to device"
1211 run_cmd nettest -s -d ${NSA_DEV} -2 ${NSA_DEV} &
1213 run_cmd_nsb nettest -r ${a}
1214 log_test_addr ${a} $? 0 "Device server"
1216 # local address tests
1217 for a in ${NSA_IP} ${VRF_IP}
1220 show_hint "Should fail 'Connection refused' since client is not bound to VRF"
1221 run_cmd nettest -s -d ${VRF} &
1223 run_cmd nettest -r ${a}
1224 log_test_addr ${a} $? 1 "Global server, local connection"
1230 for a in ${NSB_IP} ${NSB_LO_IP}
1233 run_cmd_nsb nettest -s &
1235 run_cmd nettest -r ${a} -d ${VRF}
1236 log_test_addr ${a} $? 0 "Client, VRF bind"
1239 run_cmd_nsb nettest -s &
1241 run_cmd nettest -r ${a} -d ${NSA_DEV}
1242 log_test_addr ${a} $? 0 "Client, device bind"
1245 show_hint "Should fail 'Connection refused'"
1246 run_cmd nettest -r ${a} -d ${VRF}
1247 log_test_addr ${a} $? 1 "No server, VRF client"
1250 show_hint "Should fail 'Connection refused'"
1251 run_cmd nettest -r ${a} -d ${NSA_DEV}
1252 log_test_addr ${a} $? 1 "No server, device client"
1255 for a in ${NSA_IP} ${VRF_IP} 127.0.0.1
1258 run_cmd nettest -s -d ${VRF} -2 ${VRF} &
1260 run_cmd nettest -r ${a} -d ${VRF} -0 ${a}
1261 log_test_addr ${a} $? 0 "VRF server, VRF client, local connection"
1266 run_cmd nettest -s -d ${VRF} -2 ${VRF} &
1268 run_cmd nettest -r ${a} -d ${NSA_DEV} -0 ${a}
1269 log_test_addr ${a} $? 0 "VRF server, device client, local connection"
1272 show_hint "Should fail 'No route to host' since client is out of VRF scope"
1273 run_cmd nettest -s -d ${VRF} &
1275 run_cmd nettest -r ${a}
1276 log_test_addr ${a} $? 1 "VRF server, unbound client, local connection"
1279 run_cmd nettest -s -d ${NSA_DEV} -2 ${NSA_DEV} &
1281 run_cmd nettest -r ${a} -d ${VRF} -0 ${a}
1282 log_test_addr ${a} $? 0 "Device server, VRF client, local connection"
1285 run_cmd nettest -s -d ${NSA_DEV} -2 ${NSA_DEV} &
1287 run_cmd nettest -r ${a} -d ${NSA_DEV} -0 ${a}
1288 log_test_addr ${a} $? 0 "Device server, device client, local connection"
1293 log_section "IPv4/TCP"
1294 log_subsection "No VRF"
1297 # tcp_l3mdev_accept should have no affect without VRF;
1298 # run tests with it enabled and disabled to verify
1299 log_subsection "tcp_l3mdev_accept disabled"
1300 set_sysctl net.ipv4.tcp_l3mdev_accept=0
1302 log_subsection "tcp_l3mdev_accept enabled"
1303 set_sysctl net.ipv4.tcp_l3mdev_accept=1
1306 log_subsection "With VRF"
1311 ################################################################################
1321 for a in ${NSA_IP} ${NSA_LO_IP}
1324 run_cmd nettest -D -s -2 ${NSA_DEV} &
1326 run_cmd_nsb nettest -D -r ${a}
1327 log_test_addr ${a} $? 0 "Global server"
1330 show_hint "Should fail 'Connection refused' since there is no server"
1331 run_cmd_nsb nettest -D -r ${a}
1332 log_test_addr ${a} $? 1 "No server"
1337 run_cmd nettest -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
1339 run_cmd_nsb nettest -D -r ${a}
1340 log_test_addr ${a} $? 0 "Device server"
1345 for a in ${NSB_IP} ${NSB_LO_IP}
1348 run_cmd_nsb nettest -D -s &
1350 run_cmd nettest -D -r ${a} -0 ${NSA_IP}
1351 log_test_addr ${a} $? 0 "Client"
1354 run_cmd_nsb nettest -D -s &
1356 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -0 ${NSA_IP}
1357 log_test_addr ${a} $? 0 "Client, device bind"
1360 run_cmd_nsb nettest -D -s &
1362 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -C -0 ${NSA_IP}
1363 log_test_addr ${a} $? 0 "Client, device send via cmsg"
1366 run_cmd_nsb nettest -D -s &
1368 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -S -0 ${NSA_IP}
1369 log_test_addr ${a} $? 0 "Client, device bind via IP_UNICAST_IF"
1372 show_hint "Should fail 'Connection refused'"
1373 run_cmd nettest -D -r ${a}
1374 log_test_addr ${a} $? 1 "No server, unbound client"
1377 show_hint "Should fail 'Connection refused'"
1378 run_cmd nettest -D -r ${a} -d ${NSA_DEV}
1379 log_test_addr ${a} $? 1 "No server, device client"
1383 # local address tests
1385 for a in ${NSA_IP} ${NSA_LO_IP} 127.0.0.1
1388 run_cmd nettest -D -s &
1390 run_cmd nettest -D -r ${a} -0 ${a} -1 ${a}
1391 log_test_addr ${a} $? 0 "Global server, local connection"
1396 run_cmd nettest -s -D -d ${NSA_DEV} -2 ${NSA_DEV} &
1398 run_cmd nettest -D -r ${a}
1399 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
1401 for a in ${NSA_LO_IP} 127.0.0.1
1404 show_hint "Should fail 'Connection refused' since address is out of device scope"
1405 run_cmd nettest -s -D -d ${NSA_DEV} &
1407 run_cmd nettest -D -r ${a}
1408 log_test_addr ${a} $? 1 "Device server, unbound client, local connection"
1413 run_cmd nettest -s -D &
1415 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1416 log_test_addr ${a} $? 0 "Global server, device client, local connection"
1419 run_cmd nettest -s -D &
1421 run_cmd nettest -D -d ${NSA_DEV} -C -r ${a}
1422 log_test_addr ${a} $? 0 "Global server, device send via cmsg, local connection"
1425 run_cmd nettest -s -D &
1427 run_cmd nettest -D -d ${NSA_DEV} -S -r ${a}
1428 log_test_addr ${a} $? 0 "Global server, device client via IP_UNICAST_IF, local connection"
1430 # IPv4 with device bind has really weird behavior - it overrides the
1431 # fib lookup, generates an rtable and tries to send the packet. This
1432 # causes failures for local traffic at different places
1433 for a in ${NSA_LO_IP} 127.0.0.1
1436 show_hint "Should fail since addresses on loopback are out of device scope"
1437 run_cmd nettest -D -s &
1439 run_cmd nettest -D -r ${a} -d ${NSA_DEV}
1440 log_test_addr ${a} $? 2 "Global server, device client, local connection"
1443 show_hint "Should fail since addresses on loopback are out of device scope"
1444 run_cmd nettest -D -s &
1446 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -C
1447 log_test_addr ${a} $? 1 "Global server, device send via cmsg, local connection"
1450 show_hint "Should fail since addresses on loopback are out of device scope"
1451 run_cmd nettest -D -s &
1453 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -S
1454 log_test_addr ${a} $? 1 "Global server, device client via IP_UNICAST_IF, local connection"
1459 run_cmd nettest -D -s -d ${NSA_DEV} -2 ${NSA_DEV} &
1461 run_cmd nettest -D -d ${NSA_DEV} -r ${a} -0 ${a}
1462 log_test_addr ${a} $? 0 "Device server, device client, local conn"
1465 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1466 log_test_addr ${a} $? 2 "No server, device client, local conn"
1473 # disable global server
1474 log_subsection "Global server disabled"
1475 set_sysctl net.ipv4.udp_l3mdev_accept=0
1480 for a in ${NSA_IP} ${VRF_IP}
1483 show_hint "Fails because ingress is in a VRF and global server is disabled"
1484 run_cmd nettest -D -s &
1486 run_cmd_nsb nettest -D -r ${a}
1487 log_test_addr ${a} $? 1 "Global server"
1490 run_cmd nettest -D -d ${VRF} -s -2 ${NSA_DEV} &
1492 run_cmd_nsb nettest -D -r ${a}
1493 log_test_addr ${a} $? 0 "VRF server"
1496 run_cmd nettest -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
1498 run_cmd_nsb nettest -D -r ${a}
1499 log_test_addr ${a} $? 0 "Enslaved device server"
1502 show_hint "Should fail 'Connection refused' since there is no server"
1503 run_cmd_nsb nettest -D -r ${a}
1504 log_test_addr ${a} $? 1 "No server"
1507 show_hint "Should fail 'Connection refused' since global server is out of scope"
1508 run_cmd nettest -D -s &
1510 run_cmd nettest -D -d ${VRF} -r ${a}
1511 log_test_addr ${a} $? 1 "Global server, VRF client, local connection"
1516 run_cmd nettest -s -D -d ${VRF} -2 ${NSA_DEV} &
1518 run_cmd nettest -D -d ${VRF} -r ${a}
1519 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
1522 run_cmd nettest -s -D -d ${VRF} -2 ${NSA_DEV} &
1524 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1525 log_test_addr ${a} $? 0 "VRF server, enslaved device client, local connection"
1529 run_cmd nettest -s -D -d ${NSA_DEV} -2 ${NSA_DEV} &
1531 run_cmd nettest -D -d ${VRF} -r ${a}
1532 log_test_addr ${a} $? 0 "Enslaved device server, VRF client, local conn"
1535 run_cmd nettest -s -D -d ${NSA_DEV} -2 ${NSA_DEV} &
1537 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1538 log_test_addr ${a} $? 0 "Enslaved device server, device client, local conn"
1540 # enable global server
1541 log_subsection "Global server enabled"
1542 set_sysctl net.ipv4.udp_l3mdev_accept=1
1547 for a in ${NSA_IP} ${VRF_IP}
1550 run_cmd nettest -D -s -2 ${NSA_DEV} &
1552 run_cmd_nsb nettest -D -r ${a}
1553 log_test_addr ${a} $? 0 "Global server"
1556 run_cmd nettest -D -d ${VRF} -s -2 ${NSA_DEV} &
1558 run_cmd_nsb nettest -D -r ${a}
1559 log_test_addr ${a} $? 0 "VRF server"
1562 run_cmd nettest -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
1564 run_cmd_nsb nettest -D -r ${a}
1565 log_test_addr ${a} $? 0 "Enslaved device server"
1568 show_hint "Should fail 'Connection refused'"
1569 run_cmd_nsb nettest -D -r ${a}
1570 log_test_addr ${a} $? 1 "No server"
1577 run_cmd_nsb nettest -D -s &
1579 run_cmd nettest -d ${VRF} -D -r ${NSB_IP} -1 ${NSA_IP}
1580 log_test $? 0 "VRF client"
1583 run_cmd_nsb nettest -D -s &
1585 run_cmd nettest -d ${NSA_DEV} -D -r ${NSB_IP} -1 ${NSA_IP}
1586 log_test $? 0 "Enslaved device client"
1588 # negative test - should fail
1590 show_hint "Should fail 'Connection refused'"
1591 run_cmd nettest -D -d ${VRF} -r ${NSB_IP}
1592 log_test $? 1 "No server, VRF client"
1595 show_hint "Should fail 'Connection refused'"
1596 run_cmd nettest -D -d ${NSA_DEV} -r ${NSB_IP}
1597 log_test $? 1 "No server, enslaved device client"
1600 # local address tests
1604 run_cmd nettest -D -s -2 ${NSA_DEV} &
1606 run_cmd nettest -D -d ${VRF} -r ${a}
1607 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
1610 run_cmd nettest -s -D -d ${VRF} -2 ${NSA_DEV} &
1612 run_cmd nettest -D -d ${VRF} -r ${a}
1613 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
1616 run_cmd nettest -s -D -d ${VRF} -2 ${NSA_DEV} &
1618 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1619 log_test_addr ${a} $? 0 "VRF server, device client, local conn"
1622 run_cmd nettest -s -D -d ${NSA_DEV} -2 ${NSA_DEV} &
1624 run_cmd nettest -D -d ${VRF} -r ${a}
1625 log_test_addr ${a} $? 0 "Enslaved device server, VRF client, local conn"
1628 run_cmd nettest -s -D -d ${NSA_DEV} -2 ${NSA_DEV} &
1630 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1631 log_test_addr ${a} $? 0 "Enslaved device server, device client, local conn"
1633 for a in ${VRF_IP} 127.0.0.1
1636 run_cmd nettest -D -s -2 ${VRF} &
1638 run_cmd nettest -D -d ${VRF} -r ${a}
1639 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
1642 for a in ${VRF_IP} 127.0.0.1
1645 run_cmd nettest -s -D -d ${VRF} -2 ${VRF} &
1647 run_cmd nettest -D -d ${VRF} -r ${a}
1648 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
1651 # negative test - should fail
1652 # verifies ECONNREFUSED
1653 for a in ${NSA_IP} ${VRF_IP} 127.0.0.1
1656 show_hint "Should fail 'Connection refused'"
1657 run_cmd nettest -D -d ${VRF} -r ${a}
1658 log_test_addr ${a} $? 1 "No server, VRF client, local conn"
1664 log_section "IPv4/UDP"
1665 log_subsection "No VRF"
1669 # udp_l3mdev_accept should have no affect without VRF;
1670 # run tests with it enabled and disabled to verify
1671 log_subsection "udp_l3mdev_accept disabled"
1672 set_sysctl net.ipv4.udp_l3mdev_accept=0
1674 log_subsection "udp_l3mdev_accept enabled"
1675 set_sysctl net.ipv4.udp_l3mdev_accept=1
1678 log_subsection "With VRF"
1683 ################################################################################
1686 # verifies ability or inability to bind to an address / device
1688 ipv4_addr_bind_novrf()
1693 for a in ${NSA_IP} ${NSA_LO_IP}
1696 run_cmd nettest -s -R -P icmp -l ${a} -b
1697 log_test_addr ${a} $? 0 "Raw socket bind to local address"
1700 run_cmd nettest -s -R -P icmp -l ${a} -d ${NSA_DEV} -b
1701 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
1709 run_cmd nettest -l ${a} -r ${NSB_IP} -t1 -b
1710 log_test_addr ${a} $? 0 "TCP socket bind to local address"
1713 run_cmd nettest -l ${a} -r ${NSB_IP} -d ${NSA_DEV} -t1 -b
1714 log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"
1716 # Sadly, the kernel allows binding a socket to a device and then
1717 # binding to an address not on the device. The only restriction
1718 # is that the address is valid in the L3 domain. So this test
1719 # passes when it really should not
1722 #show_hint "Should fail with 'Cannot assign requested address'"
1723 #run_cmd nettest -s -l ${a} -d ${NSA_DEV} -t1 -b
1724 #log_test_addr ${a} $? 1 "TCP socket bind to out of scope local address"
1727 ipv4_addr_bind_vrf()
1732 for a in ${NSA_IP} ${VRF_IP}
1735 run_cmd nettest -s -R -P icmp -l ${a} -b
1736 log_test_addr ${a} $? 0 "Raw socket bind to local address"
1739 run_cmd nettest -s -R -P icmp -l ${a} -d ${NSA_DEV} -b
1740 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
1742 run_cmd nettest -s -R -P icmp -l ${a} -d ${VRF} -b
1743 log_test_addr ${a} $? 0 "Raw socket bind to local address after VRF bind"
1748 show_hint "Address on loopback is out of VRF scope"
1749 run_cmd nettest -s -R -P icmp -l ${a} -d ${VRF} -b
1750 log_test_addr ${a} $? 1 "Raw socket bind to out of scope address after VRF bind"
1755 for a in ${NSA_IP} ${VRF_IP}
1758 run_cmd nettest -s -l ${a} -d ${VRF} -t1 -b
1759 log_test_addr ${a} $? 0 "TCP socket bind to local address"
1762 run_cmd nettest -s -l ${a} -d ${NSA_DEV} -t1 -b
1763 log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"
1768 show_hint "Address on loopback out of scope for VRF"
1769 run_cmd nettest -s -l ${a} -d ${VRF} -t1 -b
1770 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for VRF"
1773 show_hint "Address on loopback out of scope for device in VRF"
1774 run_cmd nettest -s -l ${a} -d ${NSA_DEV} -t1 -b
1775 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for device bind"
1780 log_section "IPv4 address binds"
1782 log_subsection "No VRF"
1784 ipv4_addr_bind_novrf
1786 log_subsection "With VRF"
1791 ################################################################################
1792 # IPv4 runtime tests
1798 local with_vrf="yes"
1804 for a in ${NSA_IP} ${VRF_IP}
1807 run_cmd nettest ${varg} -s &
1809 run_cmd_nsb nettest ${varg} -r ${a} &
1811 run_cmd ip link del ${VRF}
1813 log_test_addr ${a} 0 0 "${desc}, global server"
1818 for a in ${NSA_IP} ${VRF_IP}
1821 run_cmd nettest ${varg} -s -d ${VRF} &
1823 run_cmd_nsb nettest ${varg} -r ${a} &
1825 run_cmd ip link del ${VRF}
1827 log_test_addr ${a} 0 0 "${desc}, VRF server"
1834 run_cmd nettest ${varg} -s -d ${NSA_DEV} &
1836 run_cmd_nsb nettest ${varg} -r ${a} &
1838 run_cmd ip link del ${VRF}
1840 log_test_addr ${a} 0 0 "${desc}, enslaved device server"
1848 run_cmd_nsb nettest ${varg} -s &
1850 run_cmd nettest ${varg} -d ${VRF} -r ${NSB_IP} &
1852 run_cmd ip link del ${VRF}
1854 log_test_addr ${a} 0 0 "${desc}, VRF client"
1859 run_cmd_nsb nettest ${varg} -s &
1861 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${NSB_IP} &
1863 run_cmd ip link del ${VRF}
1865 log_test_addr ${a} 0 0 "${desc}, enslaved device client"
1870 # local address tests
1872 for a in ${NSA_IP} ${VRF_IP}
1875 run_cmd nettest ${varg} -s &
1877 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
1879 run_cmd ip link del ${VRF}
1881 log_test_addr ${a} 0 0 "${desc}, global server, VRF client, local"
1886 for a in ${NSA_IP} ${VRF_IP}
1889 run_cmd nettest ${varg} -d ${VRF} -s &
1891 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
1893 run_cmd ip link del ${VRF}
1895 log_test_addr ${a} 0 0 "${desc}, VRF server and client, local"
1902 run_cmd nettest ${varg} -s &
1904 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
1906 run_cmd ip link del ${VRF}
1908 log_test_addr ${a} 0 0 "${desc}, global server, enslaved device client, local"
1913 run_cmd nettest ${varg} -d ${VRF} -s &
1915 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
1917 run_cmd ip link del ${VRF}
1919 log_test_addr ${a} 0 0 "${desc}, VRF server, enslaved device client, local"
1924 run_cmd nettest ${varg} -d ${NSA_DEV} -s &
1926 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
1928 run_cmd ip link del ${VRF}
1930 log_test_addr ${a} 0 0 "${desc}, enslaved device server and client, local"
1935 local with_vrf="yes"
1938 for a in ${NSA_IP} ${VRF_IP}
1941 run_cmd_nsb ping -f ${a} &
1943 run_cmd ip link del ${VRF}
1945 log_test_addr ${a} 0 0 "Device delete with active traffic - ping in"
1952 run_cmd ping -f -I ${VRF} ${a} &
1954 run_cmd ip link del ${VRF}
1956 log_test_addr ${a} 0 0 "Device delete with active traffic - ping out"
1961 log_section "Run time tests - ipv4"
1967 ipv4_rt "TCP active socket" "-n -1"
1970 ipv4_rt "TCP passive socket" "-i"
1973 ################################################################################
1980 # should not have an impact, but make a known state
1981 set_sysctl net.ipv4.raw_l3mdev_accept=0 2>/dev/null
1986 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
1989 run_cmd ${ping6} -c1 -w1 ${a}
1990 log_test_addr ${a} $? 0 "ping out"
1993 for a in ${NSB_IP6} ${NSB_LO_IP6}
1996 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
1997 log_test_addr ${a} $? 0 "ping out, device bind"
2000 run_cmd ${ping6} -c1 -w1 -I ${NSA_LO_IP6} ${a}
2001 log_test_addr ${a} $? 0 "ping out, loopback address bind"
2007 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV} ${MCAST}%${NSB_DEV}
2010 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2011 log_test_addr ${a} $? 0 "ping in"
2015 # local traffic, local address
2017 for a in ${NSA_IP6} ${NSA_LO_IP6} ::1 ${NSA_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2020 run_cmd ${ping6} -c1 -w1 ${a}
2021 log_test_addr ${a} $? 0 "ping local, no bind"
2024 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2027 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2028 log_test_addr ${a} $? 0 "ping local, device bind"
2031 for a in ${NSA_LO_IP6} ::1
2034 show_hint "Fails since address on loopback is out of device scope"
2035 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2036 log_test_addr ${a} $? 2 "ping local, device bind"
2040 # ip rule blocks address
2043 setup_cmd ip -6 rule add pref 32765 from all lookup local
2044 setup_cmd ip -6 rule del pref 0 from all lookup local
2045 setup_cmd ip -6 rule add pref 50 to ${NSB_LO_IP6} prohibit
2046 setup_cmd ip -6 rule add pref 51 from ${NSB_IP6} prohibit
2049 run_cmd ${ping6} -c1 -w1 ${a}
2050 log_test_addr ${a} $? 2 "ping out, blocked by rule"
2053 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2054 log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
2058 show_hint "Response lost due to ip rule"
2059 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2060 log_test_addr ${a} $? 1 "ping in, blocked by rule"
2062 setup_cmd ip -6 rule add pref 0 from all lookup local
2063 setup_cmd ip -6 rule del pref 32765 from all lookup local
2064 setup_cmd ip -6 rule del pref 50 to ${NSB_LO_IP6} prohibit
2065 setup_cmd ip -6 rule del pref 51 from ${NSB_IP6} prohibit
2068 # route blocks reachability to remote address
2071 setup_cmd ip -6 route del ${NSB_LO_IP6}
2072 setup_cmd ip -6 route add unreachable ${NSB_LO_IP6} metric 10
2073 setup_cmd ip -6 route add unreachable ${NSB_IP6} metric 10
2076 run_cmd ${ping6} -c1 -w1 ${a}
2077 log_test_addr ${a} $? 2 "ping out, blocked by route"
2080 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2081 log_test_addr ${a} $? 2 "ping out, device bind, blocked by route"
2085 show_hint "Response lost due to ip route"
2086 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2087 log_test_addr ${a} $? 1 "ping in, blocked by route"
2091 # remove 'remote' routes; fallback to default
2094 setup_cmd ip -6 ro del unreachable ${NSB_LO_IP6}
2095 setup_cmd ip -6 ro del unreachable ${NSB_IP6}
2098 run_cmd ${ping6} -c1 -w1 ${a}
2099 log_test_addr ${a} $? 2 "ping out, unreachable route"
2102 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2103 log_test_addr ${a} $? 2 "ping out, device bind, unreachable route"
2110 # should default on; does not exist on older kernels
2111 set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
2116 for a in ${NSB_IP6} ${NSB_LO_IP6}
2119 run_cmd ${ping6} -c1 -w1 -I ${VRF} ${a}
2120 log_test_addr ${a} $? 0 "ping out, VRF bind"
2123 for a in ${NSB_LINKIP6}%${VRF} ${MCAST}%${VRF}
2126 show_hint "Fails since VRF device does not support linklocal or multicast"
2127 run_cmd ${ping6} -c1 -w1 ${a}
2128 log_test_addr ${a} $? 2 "ping out, VRF bind"
2131 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2134 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2135 log_test_addr ${a} $? 0 "ping out, device bind"
2138 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2141 run_cmd ip vrf exec ${VRF} ${ping6} -c1 -w1 -I ${VRF_IP6} ${a}
2142 log_test_addr ${a} $? 0 "ping out, vrf device+address bind"
2148 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV} ${MCAST}%${NSB_DEV}
2151 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2152 log_test_addr ${a} $? 0 "ping in"
2157 show_hint "Fails since loopback address is out of VRF scope"
2158 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2159 log_test_addr ${a} $? 1 "ping in"
2162 # local traffic, local address
2164 for a in ${NSA_IP6} ${VRF_IP6} ::1
2167 show_hint "Source address should be ${a}"
2168 run_cmd ${ping6} -c1 -w1 -I ${VRF} ${a}
2169 log_test_addr ${a} $? 0 "ping local, VRF bind"
2172 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2175 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2176 log_test_addr ${a} $? 0 "ping local, device bind"
2179 # LLA to GUA - remove ipv6 global addresses from ns-B
2180 setup_cmd_nsb ip -6 addr del ${NSB_IP6}/64 dev ${NSB_DEV}
2181 setup_cmd_nsb ip -6 addr del ${NSB_LO_IP6}/128 dev lo
2182 setup_cmd_nsb ip -6 ro add ${NSA_IP6}/128 via ${NSA_LINKIP6} dev ${NSB_DEV}
2184 for a in ${NSA_IP6} ${VRF_IP6}
2187 run_cmd_nsb ${ping6} -c1 -w1 ${NSA_IP6}
2188 log_test_addr ${a} $? 0 "ping in, LLA to GUA"
2191 setup_cmd_nsb ip -6 ro del ${NSA_IP6}/128 via ${NSA_LINKIP6} dev ${NSB_DEV}
2192 setup_cmd_nsb ip -6 addr add ${NSB_IP6}/64 dev ${NSB_DEV}
2193 setup_cmd_nsb ip -6 addr add ${NSB_LO_IP6}/128 dev lo
2196 # ip rule blocks address
2199 setup_cmd ip -6 rule add pref 50 to ${NSB_LO_IP6} prohibit
2200 setup_cmd ip -6 rule add pref 51 from ${NSB_IP6} prohibit
2203 run_cmd ${ping6} -c1 -w1 ${a}
2204 log_test_addr ${a} $? 2 "ping out, blocked by rule"
2207 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2208 log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
2212 show_hint "Response lost due to ip rule"
2213 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2214 log_test_addr ${a} $? 1 "ping in, blocked by rule"
2217 setup_cmd ip -6 rule del pref 50 to ${NSB_LO_IP6} prohibit
2218 setup_cmd ip -6 rule del pref 51 from ${NSB_IP6} prohibit
2221 # remove 'remote' routes; fallback to default
2224 setup_cmd ip -6 ro del ${NSB_LO_IP6} vrf ${VRF}
2227 run_cmd ${ping6} -c1 -w1 ${a}
2228 log_test_addr ${a} $? 2 "ping out, unreachable route"
2231 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2232 log_test_addr ${a} $? 2 "ping out, device bind, unreachable route"
2234 ip -netns ${NSB} -6 ro del ${NSA_LO_IP6}
2237 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2238 log_test_addr ${a} $? 2 "ping in, unreachable route"
2243 log_section "IPv6 ping"
2245 log_subsection "No VRF"
2249 log_subsection "With VRF"
2254 ################################################################################
2258 # MD5 tests without VRF
2260 ipv6_tcp_md5_novrf()
2268 run_cmd nettest -6 -s -M ${MD5_PW} -r ${NSB_IP6} &
2270 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2271 log_test $? 0 "MD5: Single address config"
2273 # client sends MD5, server not configured
2275 show_hint "Should timeout due to MD5 mismatch"
2276 run_cmd nettest -6 -s &
2278 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2279 log_test $? 2 "MD5: Server no config, client uses password"
2283 show_hint "Should timeout since client uses wrong password"
2284 run_cmd nettest -6 -s -M ${MD5_PW} -r ${NSB_IP6} &
2286 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2287 log_test $? 2 "MD5: Client uses wrong password"
2289 # client from different address
2291 show_hint "Should timeout due to MD5 mismatch"
2292 run_cmd nettest -6 -s -M ${MD5_PW} -r ${NSB_LO_IP6} &
2294 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2295 log_test $? 2 "MD5: Client address does not match address configured with password"
2298 # MD5 extension - prefix length
2303 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
2305 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2306 log_test $? 0 "MD5: Prefix config"
2308 # client in prefix, wrong password
2310 show_hint "Should timeout since client uses wrong password"
2311 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
2313 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2314 log_test $? 2 "MD5: Prefix config, client uses wrong password"
2316 # client outside of prefix
2318 show_hint "Should timeout due to MD5 mismatch"
2319 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
2321 run_cmd_nsb nettest -6 -l ${NSB_LO_IP6} -r ${NSA_IP6} -M ${MD5_PW}
2322 log_test $? 2 "MD5: Prefix config, client address not in configured prefix"
2326 # MD5 tests with VRF
2336 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP6} &
2338 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2339 log_test $? 0 "MD5: VRF: Single address config"
2341 # client sends MD5, server not configured
2343 show_hint "Should timeout since server does not have MD5 auth"
2344 run_cmd nettest -6 -s -d ${VRF} &
2346 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2347 log_test $? 2 "MD5: VRF: Server no config, client uses password"
2351 show_hint "Should timeout since client uses wrong password"
2352 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP6} &
2354 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2355 log_test $? 2 "MD5: VRF: Client uses wrong password"
2357 # client from different address
2359 show_hint "Should timeout since server config differs from client"
2360 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_LO_IP6} &
2362 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2363 log_test $? 2 "MD5: VRF: Client address does not match address configured with password"
2366 # MD5 extension - prefix length
2371 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2373 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2374 log_test $? 0 "MD5: VRF: Prefix config"
2376 # client in prefix, wrong password
2378 show_hint "Should timeout since client uses wrong password"
2379 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2381 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2382 log_test $? 2 "MD5: VRF: Prefix config, client uses wrong password"
2384 # client outside of prefix
2386 show_hint "Should timeout since client address is outside of prefix"
2387 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2389 run_cmd_nsb nettest -6 -l ${NSB_LO_IP6} -r ${NSA_IP6} -M ${MD5_PW}
2390 log_test $? 2 "MD5: VRF: Prefix config, client address not in configured prefix"
2393 # duplicate config between default VRF and a VRF
2397 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP6} &
2398 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -r ${NSB_IP6} &
2400 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2401 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF"
2404 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP6} &
2405 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -r ${NSB_IP6} &
2407 run_cmd_nsc nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2408 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF"
2411 show_hint "Should timeout since client in default VRF uses VRF password"
2412 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP6} &
2413 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -r ${NSB_IP6} &
2415 run_cmd_nsc nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2416 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF with VRF pw"
2419 show_hint "Should timeout since client in VRF uses default VRF password"
2420 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -r ${NSB_IP6} &
2421 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -r ${NSB_IP6} &
2423 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2424 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF with default VRF pw"
2427 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2428 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2430 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2431 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF"
2434 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2435 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2437 run_cmd_nsc nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2438 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF"
2441 show_hint "Should timeout since client in default VRF uses VRF password"
2442 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2443 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2445 run_cmd_nsc nettest -6 -r ${NSA_IP6} -M ${MD5_PW}
2446 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF with VRF pw"
2449 show_hint "Should timeout since client in VRF uses default VRF password"
2450 run_cmd nettest -6 -s -d ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2451 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2453 run_cmd_nsb nettest -6 -r ${NSA_IP6} -M ${MD5_WRONG_PW}
2454 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF with default VRF pw"
2460 run_cmd nettest -6 -s -d ${NSA_DEV} -M ${MD5_PW} -r ${NSB_IP6}
2461 log_test $? 1 "MD5: VRF: Device must be a VRF - single address"
2464 run_cmd nettest -6 -s -d ${NSA_DEV} -M ${MD5_PW} -m ${NS_NET6}
2465 log_test $? 1 "MD5: VRF: Device must be a VRF - prefix"
2476 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2479 run_cmd nettest -6 -s &
2481 run_cmd_nsb nettest -6 -r ${a}
2482 log_test_addr ${a} $? 0 "Global server"
2485 # verify TCP reset received
2486 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2489 show_hint "Should fail 'Connection refused'"
2490 run_cmd_nsb nettest -6 -r ${a}
2491 log_test_addr ${a} $? 1 "No server"
2497 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2500 run_cmd_nsb nettest -6 -s &
2502 run_cmd nettest -6 -r ${a}
2503 log_test_addr ${a} $? 0 "Client"
2506 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2509 run_cmd_nsb nettest -6 -s &
2511 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2512 log_test_addr ${a} $? 0 "Client, device bind"
2515 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2518 show_hint "Should fail 'Connection refused'"
2519 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2520 log_test_addr ${a} $? 1 "No server, device client"
2524 # local address tests
2526 for a in ${NSA_IP6} ${NSA_LO_IP6} ::1
2529 run_cmd nettest -6 -s &
2531 run_cmd nettest -6 -r ${a}
2532 log_test_addr ${a} $? 0 "Global server, local connection"
2537 run_cmd nettest -6 -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2539 run_cmd nettest -6 -r ${a} -0 ${a}
2540 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
2542 for a in ${NSA_LO_IP6} ::1
2545 show_hint "Should fail 'Connection refused' since addresses on loopback are out of device scope"
2546 run_cmd nettest -6 -s -d ${NSA_DEV} &
2548 run_cmd nettest -6 -r ${a}
2549 log_test_addr ${a} $? 1 "Device server, unbound client, local connection"
2554 run_cmd nettest -6 -s &
2556 run_cmd nettest -6 -r ${a} -d ${NSA_DEV} -0 ${a}
2557 log_test_addr ${a} $? 0 "Global server, device client, local connection"
2559 for a in ${NSA_LO_IP6} ::1
2562 show_hint "Should fail 'Connection refused' since addresses on loopback are out of device scope"
2563 run_cmd nettest -6 -s &
2565 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2566 log_test_addr ${a} $? 1 "Global server, device client, local connection"
2569 for a in ${NSA_IP6} ${NSA_LINKIP6}
2572 run_cmd nettest -6 -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2574 run_cmd nettest -6 -d ${NSA_DEV} -r ${a}
2575 log_test_addr ${a} $? 0 "Device server, device client, local conn"
2578 for a in ${NSA_IP6} ${NSA_LINKIP6}
2581 show_hint "Should fail 'Connection refused'"
2582 run_cmd nettest -6 -d ${NSA_DEV} -r ${a}
2583 log_test_addr ${a} $? 1 "No server, device client, local conn"
2593 # disable global server
2594 log_subsection "Global server disabled"
2596 set_sysctl net.ipv4.tcp_l3mdev_accept=0
2601 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2604 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
2605 run_cmd nettest -6 -s &
2607 run_cmd_nsb nettest -6 -r ${a}
2608 log_test_addr ${a} $? 1 "Global server"
2611 for a in ${NSA_IP6} ${VRF_IP6}
2614 run_cmd nettest -6 -s -d ${VRF} -2 ${VRF} &
2616 run_cmd_nsb nettest -6 -r ${a}
2617 log_test_addr ${a} $? 0 "VRF server"
2620 # link local is always bound to ingress device
2621 a=${NSA_LINKIP6}%${NSB_DEV}
2623 run_cmd nettest -6 -s -d ${VRF} -2 ${NSA_DEV} &
2625 run_cmd_nsb nettest -6 -r ${a}
2626 log_test_addr ${a} $? 0 "VRF server"
2628 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2631 run_cmd nettest -6 -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2633 run_cmd_nsb nettest -6 -r ${a}
2634 log_test_addr ${a} $? 0 "Device server"
2637 # verify TCP reset received
2638 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2641 show_hint "Should fail 'Connection refused'"
2642 run_cmd_nsb nettest -6 -r ${a}
2643 log_test_addr ${a} $? 1 "No server"
2646 # local address tests
2649 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
2650 run_cmd nettest -6 -s &
2652 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2653 log_test_addr ${a} $? 1 "Global server, local connection"
2659 # enable VRF global server
2661 log_subsection "VRF Global server enabled"
2662 set_sysctl net.ipv4.tcp_l3mdev_accept=1
2664 for a in ${NSA_IP6} ${VRF_IP6}
2667 run_cmd nettest -6 -s -2 ${VRF} &
2669 run_cmd_nsb nettest -6 -r ${a}
2670 log_test_addr ${a} $? 0 "Global server"
2673 for a in ${NSA_IP6} ${VRF_IP6}
2676 run_cmd nettest -6 -s -d ${VRF} -2 ${VRF} &
2678 run_cmd_nsb nettest -6 -r ${a}
2679 log_test_addr ${a} $? 0 "VRF server"
2682 # For LLA, child socket is bound to device
2683 a=${NSA_LINKIP6}%${NSB_DEV}
2685 run_cmd nettest -6 -s -2 ${NSA_DEV} &
2687 run_cmd_nsb nettest -6 -r ${a}
2688 log_test_addr ${a} $? 0 "Global server"
2691 run_cmd nettest -6 -s -d ${VRF} -2 ${NSA_DEV} &
2693 run_cmd_nsb nettest -6 -r ${a}
2694 log_test_addr ${a} $? 0 "VRF server"
2696 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2699 run_cmd nettest -6 -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2701 run_cmd_nsb nettest -6 -r ${a}
2702 log_test_addr ${a} $? 0 "Device server"
2705 # verify TCP reset received
2706 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2709 show_hint "Should fail 'Connection refused'"
2710 run_cmd_nsb nettest -6 -r ${a}
2711 log_test_addr ${a} $? 1 "No server"
2714 # local address tests
2715 for a in ${NSA_IP6} ${VRF_IP6}
2718 show_hint "Fails 'Connection refused' since client is not in VRF"
2719 run_cmd nettest -6 -s -d ${VRF} &
2721 run_cmd nettest -6 -r ${a}
2722 log_test_addr ${a} $? 1 "Global server, local connection"
2729 for a in ${NSB_IP6} ${NSB_LO_IP6}
2732 run_cmd_nsb nettest -6 -s &
2734 run_cmd nettest -6 -r ${a} -d ${VRF}
2735 log_test_addr ${a} $? 0 "Client, VRF bind"
2740 show_hint "Fails since VRF device does not allow linklocal addresses"
2741 run_cmd_nsb nettest -6 -s &
2743 run_cmd nettest -6 -r ${a} -d ${VRF}
2744 log_test_addr ${a} $? 1 "Client, VRF bind"
2746 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}
2749 run_cmd_nsb nettest -6 -s &
2751 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2752 log_test_addr ${a} $? 0 "Client, device bind"
2755 for a in ${NSB_IP6} ${NSB_LO_IP6}
2758 show_hint "Should fail 'Connection refused'"
2759 run_cmd nettest -6 -r ${a} -d ${VRF}
2760 log_test_addr ${a} $? 1 "No server, VRF client"
2763 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}
2766 show_hint "Should fail 'Connection refused'"
2767 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2768 log_test_addr ${a} $? 1 "No server, device client"
2771 for a in ${NSA_IP6} ${VRF_IP6} ::1
2774 run_cmd nettest -6 -s -d ${VRF} -2 ${VRF} &
2776 run_cmd nettest -6 -r ${a} -d ${VRF} -0 ${a}
2777 log_test_addr ${a} $? 0 "VRF server, VRF client, local connection"
2782 run_cmd nettest -6 -s -d ${VRF} -2 ${VRF} &
2784 run_cmd nettest -6 -r ${a} -d ${NSA_DEV} -0 ${a}
2785 log_test_addr ${a} $? 0 "VRF server, device client, local connection"
2789 show_hint "Should fail since unbound client is out of VRF scope"
2790 run_cmd nettest -6 -s -d ${VRF} &
2792 run_cmd nettest -6 -r ${a}
2793 log_test_addr ${a} $? 1 "VRF server, unbound client, local connection"
2796 run_cmd nettest -6 -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2798 run_cmd nettest -6 -r ${a} -d ${VRF} -0 ${a}
2799 log_test_addr ${a} $? 0 "Device server, VRF client, local connection"
2801 for a in ${NSA_IP6} ${NSA_LINKIP6}
2804 run_cmd nettest -6 -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2806 run_cmd nettest -6 -r ${a} -d ${NSA_DEV} -0 ${a}
2807 log_test_addr ${a} $? 0 "Device server, device client, local connection"
2813 log_section "IPv6/TCP"
2814 log_subsection "No VRF"
2817 # tcp_l3mdev_accept should have no affect without VRF;
2818 # run tests with it enabled and disabled to verify
2819 log_subsection "tcp_l3mdev_accept disabled"
2820 set_sysctl net.ipv4.tcp_l3mdev_accept=0
2822 log_subsection "tcp_l3mdev_accept enabled"
2823 set_sysctl net.ipv4.tcp_l3mdev_accept=1
2826 log_subsection "With VRF"
2831 ################################################################################
2841 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2844 run_cmd nettest -6 -D -s -2 ${NSA_DEV} &
2846 run_cmd_nsb nettest -6 -D -r ${a}
2847 log_test_addr ${a} $? 0 "Global server"
2850 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
2852 run_cmd_nsb nettest -6 -D -r ${a}
2853 log_test_addr ${a} $? 0 "Device server"
2858 run_cmd nettest -6 -D -s -2 ${NSA_DEV} &
2860 run_cmd_nsb nettest -6 -D -r ${a}
2861 log_test_addr ${a} $? 0 "Global server"
2863 # should fail since loopback address is out of scope for a device
2864 # bound server, but it does not - hence this is more documenting
2867 #show_hint "Should fail since loopback address is out of scope"
2868 #run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
2870 #run_cmd_nsb nettest -6 -D -r ${a}
2871 #log_test_addr ${a} $? 1 "Device server"
2873 # negative test - should fail
2874 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2877 show_hint "Should fail 'Connection refused' since there is no server"
2878 run_cmd_nsb nettest -6 -D -r ${a}
2879 log_test_addr ${a} $? 1 "No server"
2885 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2888 run_cmd_nsb nettest -6 -D -s &
2890 run_cmd nettest -6 -D -r ${a} -0 ${NSA_IP6}
2891 log_test_addr ${a} $? 0 "Client"
2894 run_cmd_nsb nettest -6 -D -s &
2896 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -0 ${NSA_IP6}
2897 log_test_addr ${a} $? 0 "Client, device bind"
2900 run_cmd_nsb nettest -6 -D -s &
2902 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -C -0 ${NSA_IP6}
2903 log_test_addr ${a} $? 0 "Client, device send via cmsg"
2906 run_cmd_nsb nettest -6 -D -s &
2908 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -S -0 ${NSA_IP6}
2909 log_test_addr ${a} $? 0 "Client, device bind via IPV6_UNICAST_IF"
2912 show_hint "Should fail 'Connection refused'"
2913 run_cmd nettest -6 -D -r ${a}
2914 log_test_addr ${a} $? 1 "No server, unbound client"
2917 show_hint "Should fail 'Connection refused'"
2918 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV}
2919 log_test_addr ${a} $? 1 "No server, device client"
2923 # local address tests
2925 for a in ${NSA_IP6} ${NSA_LO_IP6} ::1
2928 run_cmd nettest -6 -D -s &
2930 run_cmd nettest -6 -D -r ${a} -0 ${a} -1 ${a}
2931 log_test_addr ${a} $? 0 "Global server, local connection"
2936 run_cmd nettest -6 -s -D -d ${NSA_DEV} -2 ${NSA_DEV} &
2938 run_cmd nettest -6 -D -r ${a}
2939 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
2941 for a in ${NSA_LO_IP6} ::1
2944 show_hint "Should fail 'Connection refused' since address is out of device scope"
2945 run_cmd nettest -6 -s -D -d ${NSA_DEV} &
2947 run_cmd nettest -6 -D -r ${a}
2948 log_test_addr ${a} $? 1 "Device server, local connection"
2953 run_cmd nettest -6 -s -D &
2955 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
2956 log_test_addr ${a} $? 0 "Global server, device client, local connection"
2959 run_cmd nettest -6 -s -D &
2961 run_cmd nettest -6 -D -d ${NSA_DEV} -C -r ${a}
2962 log_test_addr ${a} $? 0 "Global server, device send via cmsg, local connection"
2965 run_cmd nettest -6 -s -D &
2967 run_cmd nettest -6 -D -d ${NSA_DEV} -S -r ${a}
2968 log_test_addr ${a} $? 0 "Global server, device client via IPV6_UNICAST_IF, local connection"
2970 for a in ${NSA_LO_IP6} ::1
2973 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
2974 run_cmd nettest -6 -D -s &
2976 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV}
2977 log_test_addr ${a} $? 1 "Global server, device client, local connection"
2980 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
2981 run_cmd nettest -6 -D -s &
2983 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -C
2984 log_test_addr ${a} $? 1 "Global server, device send via cmsg, local connection"
2987 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
2988 run_cmd nettest -6 -D -s &
2990 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -S
2991 log_test_addr ${a} $? 1 "Global server, device client via IP_UNICAST_IF, local connection"
2996 run_cmd nettest -6 -D -s -d ${NSA_DEV} -2 ${NSA_DEV} &
2998 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a} -0 ${a}
2999 log_test_addr ${a} $? 0 "Device server, device client, local conn"
3002 show_hint "Should fail 'Connection refused'"
3003 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3004 log_test_addr ${a} $? 1 "No server, device client, local conn"
3007 run_cmd_nsb ip -6 addr del ${NSB_IP6}/64 dev ${NSB_DEV}
3008 run_cmd_nsb ip -6 ro add ${NSA_IP6}/128 dev ${NSB_DEV}
3010 run_cmd nettest -6 -s -D &
3012 run_cmd_nsb nettest -6 -D -r ${NSA_IP6}
3013 log_test $? 0 "UDP in - LLA to GUA"
3015 run_cmd_nsb ip -6 ro del ${NSA_IP6}/128 dev ${NSB_DEV}
3016 run_cmd_nsb ip -6 addr add ${NSB_IP6}/64 dev ${NSB_DEV} nodad
3023 # disable global server
3024 log_subsection "Global server disabled"
3025 set_sysctl net.ipv4.udp_l3mdev_accept=0
3030 for a in ${NSA_IP6} ${VRF_IP6}
3033 show_hint "Should fail 'Connection refused' since global server is disabled"
3034 run_cmd nettest -6 -D -s &
3036 run_cmd_nsb nettest -6 -D -r ${a}
3037 log_test_addr ${a} $? 1 "Global server"
3040 for a in ${NSA_IP6} ${VRF_IP6}
3043 run_cmd nettest -6 -D -d ${VRF} -s -2 ${NSA_DEV} &
3045 run_cmd_nsb nettest -6 -D -r ${a}
3046 log_test_addr ${a} $? 0 "VRF server"
3049 for a in ${NSA_IP6} ${VRF_IP6}
3052 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
3054 run_cmd_nsb nettest -6 -D -r ${a}
3055 log_test_addr ${a} $? 0 "Enslaved device server"
3058 # negative test - should fail
3059 for a in ${NSA_IP6} ${VRF_IP6}
3062 show_hint "Should fail 'Connection refused' since there is no server"
3063 run_cmd_nsb nettest -6 -D -r ${a}
3064 log_test_addr ${a} $? 1 "No server"
3068 # local address tests
3070 for a in ${NSA_IP6} ${VRF_IP6}
3073 show_hint "Should fail 'Connection refused' since global server is disabled"
3074 run_cmd nettest -6 -D -s &
3076 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3077 log_test_addr ${a} $? 1 "Global server, VRF client, local conn"
3080 for a in ${NSA_IP6} ${VRF_IP6}
3083 run_cmd nettest -6 -D -d ${VRF} -s &
3085 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3086 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
3091 show_hint "Should fail 'Connection refused' since global server is disabled"
3092 run_cmd nettest -6 -D -s &
3094 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3095 log_test_addr ${a} $? 1 "Global server, device client, local conn"
3098 run_cmd nettest -6 -D -d ${VRF} -s -2 ${NSA_DEV} &
3100 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3101 log_test_addr ${a} $? 0 "VRF server, device client, local conn"
3104 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
3106 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3107 log_test_addr ${a} $? 0 "Enslaved device server, VRF client, local conn"
3110 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
3112 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3113 log_test_addr ${a} $? 0 "Enslaved device server, device client, local conn"
3115 # disable global server
3116 log_subsection "Global server enabled"
3117 set_sysctl net.ipv4.udp_l3mdev_accept=1
3122 for a in ${NSA_IP6} ${VRF_IP6}
3125 run_cmd nettest -6 -D -s -2 ${NSA_DEV} &
3127 run_cmd_nsb nettest -6 -D -r ${a}
3128 log_test_addr ${a} $? 0 "Global server"
3131 for a in ${NSA_IP6} ${VRF_IP6}
3134 run_cmd nettest -6 -D -d ${VRF} -s -2 ${NSA_DEV} &
3136 run_cmd_nsb nettest -6 -D -r ${a}
3137 log_test_addr ${a} $? 0 "VRF server"
3140 for a in ${NSA_IP6} ${VRF_IP6}
3143 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
3145 run_cmd_nsb nettest -6 -D -r ${a}
3146 log_test_addr ${a} $? 0 "Enslaved device server"
3149 # negative test - should fail
3150 for a in ${NSA_IP6} ${VRF_IP6}
3153 run_cmd_nsb nettest -6 -D -r ${a}
3154 log_test_addr ${a} $? 1 "No server"
3161 run_cmd_nsb nettest -6 -D -s &
3163 run_cmd nettest -6 -D -d ${VRF} -r ${NSB_IP6}
3164 log_test $? 0 "VRF client"
3166 # negative test - should fail
3168 run_cmd nettest -6 -D -d ${VRF} -r ${NSB_IP6}
3169 log_test $? 1 "No server, VRF client"
3172 run_cmd_nsb nettest -6 -D -s &
3174 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_IP6}
3175 log_test $? 0 "Enslaved device client"
3177 # negative test - should fail
3179 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_IP6}
3180 log_test $? 1 "No server, enslaved device client"
3183 # local address tests
3187 run_cmd nettest -6 -D -s -2 ${NSA_DEV} &
3189 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3190 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
3193 run_cmd nettest -6 -D -d ${VRF} -s -2 ${NSA_DEV} &
3195 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3196 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
3201 run_cmd nettest -6 -D -s -2 ${VRF} &
3203 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3204 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
3207 run_cmd nettest -6 -D -d ${VRF} -s -2 ${VRF} &
3209 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3210 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
3212 # negative test - should fail
3213 for a in ${NSA_IP6} ${VRF_IP6}
3216 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3217 log_test_addr ${a} $? 1 "No server, VRF client, local conn"
3220 # device to global IP
3223 run_cmd nettest -6 -D -s -2 ${NSA_DEV} &
3225 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3226 log_test_addr ${a} $? 0 "Global server, device client, local conn"
3229 run_cmd nettest -6 -D -d ${VRF} -s -2 ${NSA_DEV} &
3231 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3232 log_test_addr ${a} $? 0 "VRF server, device client, local conn"
3235 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
3237 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3238 log_test_addr ${a} $? 0 "Device server, VRF client, local conn"
3241 run_cmd nettest -6 -D -d ${NSA_DEV} -s -2 ${NSA_DEV} &
3243 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3244 log_test_addr ${a} $? 0 "Device server, device client, local conn"
3247 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3248 log_test_addr ${a} $? 1 "No server, device client, local conn"
3251 # link local addresses
3253 run_cmd nettest -6 -D -s &
3255 run_cmd_nsb nettest -6 -D -d ${NSB_DEV} -r ${NSA_LINKIP6}
3256 log_test $? 0 "Global server, linklocal IP"
3259 run_cmd_nsb nettest -6 -D -d ${NSB_DEV} -r ${NSA_LINKIP6}
3260 log_test $? 1 "No server, linklocal IP"
3264 run_cmd_nsb nettest -6 -D -s &
3266 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_LINKIP6}
3267 log_test $? 0 "Enslaved device client, linklocal IP"
3270 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_LINKIP6}
3271 log_test $? 1 "No server, device client, peer linklocal IP"
3275 run_cmd nettest -6 -D -s &
3277 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSA_LINKIP6}
3278 log_test $? 0 "Enslaved device client, local conn - linklocal IP"
3281 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSA_LINKIP6}
3282 log_test $? 1 "No server, device client, local conn - linklocal IP"
3285 run_cmd_nsb ip -6 addr del ${NSB_IP6}/64 dev ${NSB_DEV}
3286 run_cmd_nsb ip -6 ro add ${NSA_IP6}/128 dev ${NSB_DEV}
3288 run_cmd nettest -6 -s -D &
3290 run_cmd_nsb nettest -6 -D -r ${NSA_IP6}
3291 log_test $? 0 "UDP in - LLA to GUA"
3293 run_cmd_nsb ip -6 ro del ${NSA_IP6}/128 dev ${NSB_DEV}
3294 run_cmd_nsb ip -6 addr add ${NSB_IP6}/64 dev ${NSB_DEV} nodad
3299 # should not matter, but set to known state
3300 set_sysctl net.ipv4.udp_early_demux=1
3302 log_section "IPv6/UDP"
3303 log_subsection "No VRF"
3306 # udp_l3mdev_accept should have no affect without VRF;
3307 # run tests with it enabled and disabled to verify
3308 log_subsection "udp_l3mdev_accept disabled"
3309 set_sysctl net.ipv4.udp_l3mdev_accept=0
3311 log_subsection "udp_l3mdev_accept enabled"
3312 set_sysctl net.ipv4.udp_l3mdev_accept=1
3315 log_subsection "With VRF"
3320 ################################################################################
3323 ipv6_addr_bind_novrf()
3328 for a in ${NSA_IP6} ${NSA_LO_IP6}
3331 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -b
3332 log_test_addr ${a} $? 0 "Raw socket bind to local address"
3335 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -d ${NSA_DEV} -b
3336 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
3344 run_cmd nettest -6 -s -l ${a} -t1 -b
3345 log_test_addr ${a} $? 0 "TCP socket bind to local address"
3348 run_cmd nettest -6 -s -l ${a} -d ${NSA_DEV} -t1 -b
3349 log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"
3353 show_hint "Should fail with 'Cannot assign requested address'"
3354 run_cmd nettest -6 -s -l ${a} -d ${NSA_DEV} -t1 -b
3355 log_test_addr ${a} $? 1 "TCP socket bind to out of scope local address"
3358 ipv6_addr_bind_vrf()
3363 for a in ${NSA_IP6} ${VRF_IP6}
3366 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -d ${VRF} -b
3367 log_test_addr ${a} $? 0 "Raw socket bind to local address after vrf bind"
3370 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -d ${NSA_DEV} -b
3371 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
3376 show_hint "Address on loopback is out of VRF scope"
3377 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -d ${VRF} -b
3378 log_test_addr ${a} $? 1 "Raw socket bind to invalid local address after vrf bind"
3383 # address on enslaved device is valid for the VRF or device in a VRF
3384 for a in ${NSA_IP6} ${VRF_IP6}
3387 run_cmd nettest -6 -s -l ${a} -d ${VRF} -t1 -b
3388 log_test_addr ${a} $? 0 "TCP socket bind to local address with VRF bind"
3393 run_cmd nettest -6 -s -l ${a} -d ${NSA_DEV} -t1 -b
3394 log_test_addr ${a} $? 0 "TCP socket bind to local address with device bind"
3398 run_cmd nettest -6 -s -l ${a} -d ${NSA_DEV} -t1 -b
3399 log_test_addr ${a} $? 1 "TCP socket bind to VRF address with device bind"
3403 show_hint "Address on loopback out of scope for VRF"
3404 run_cmd nettest -6 -s -l ${a} -d ${VRF} -t1 -b
3405 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for VRF"
3408 show_hint "Address on loopback out of scope for device in VRF"
3409 run_cmd nettest -6 -s -l ${a} -d ${NSA_DEV} -t1 -b
3410 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for device bind"
3416 log_section "IPv6 address binds"
3418 log_subsection "No VRF"
3420 ipv6_addr_bind_novrf
3422 log_subsection "With VRF"
3427 ################################################################################
3428 # IPv6 runtime tests
3434 local with_vrf="yes"
3440 for a in ${NSA_IP6} ${VRF_IP6}
3443 run_cmd nettest ${varg} -s &
3445 run_cmd_nsb nettest ${varg} -r ${a} &
3447 run_cmd ip link del ${VRF}
3449 log_test_addr ${a} 0 0 "${desc}, global server"
3454 for a in ${NSA_IP6} ${VRF_IP6}
3457 run_cmd nettest ${varg} -d ${VRF} -s &
3459 run_cmd_nsb nettest ${varg} -r ${a} &
3461 run_cmd ip link del ${VRF}
3463 log_test_addr ${a} 0 0 "${desc}, VRF server"
3468 for a in ${NSA_IP6} ${VRF_IP6}
3471 run_cmd nettest ${varg} -d ${NSA_DEV} -s &
3473 run_cmd_nsb nettest ${varg} -r ${a} &
3475 run_cmd ip link del ${VRF}
3477 log_test_addr ${a} 0 0 "${desc}, enslaved device server"
3486 run_cmd_nsb nettest ${varg} -s &
3488 run_cmd nettest ${varg} -d ${VRF} -r ${NSB_IP6} &
3490 run_cmd ip link del ${VRF}
3492 log_test 0 0 "${desc}, VRF client"
3497 run_cmd_nsb nettest ${varg} -s &
3499 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${NSB_IP6} &
3501 run_cmd ip link del ${VRF}
3503 log_test 0 0 "${desc}, enslaved device client"
3509 # local address tests
3511 for a in ${NSA_IP6} ${VRF_IP6}
3514 run_cmd nettest ${varg} -s &
3516 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
3518 run_cmd ip link del ${VRF}
3520 log_test_addr ${a} 0 0 "${desc}, global server, VRF client"
3525 for a in ${NSA_IP6} ${VRF_IP6}
3528 run_cmd nettest ${varg} -d ${VRF} -s &
3530 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
3532 run_cmd ip link del ${VRF}
3534 log_test_addr ${a} 0 0 "${desc}, VRF server and client"
3541 run_cmd nettest ${varg} -s &
3543 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
3545 run_cmd ip link del ${VRF}
3547 log_test_addr ${a} 0 0 "${desc}, global server, device client"
3552 run_cmd nettest ${varg} -d ${VRF} -s &
3554 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
3556 run_cmd ip link del ${VRF}
3558 log_test_addr ${a} 0 0 "${desc}, VRF server, device client"
3563 run_cmd nettest ${varg} -d ${NSA_DEV} -s &
3565 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
3567 run_cmd ip link del ${VRF}
3569 log_test_addr ${a} 0 0 "${desc}, device server, device client"
3574 local with_vrf="yes"
3579 run_cmd_nsb ${ping6} -f ${a} &
3581 run_cmd ip link del ${VRF}
3583 log_test_addr ${a} 0 0 "Device delete with active traffic - ping in"
3588 run_cmd ${ping6} -f ${NSB_IP6} -I ${VRF} &
3590 run_cmd ip link del ${VRF}
3592 log_test_addr ${a} 0 0 "Device delete with active traffic - ping out"
3597 log_section "Run time tests - ipv6"
3603 ipv6_rt "TCP active socket" "-n -1"
3606 ipv6_rt "TCP passive socket" "-i"
3609 ipv6_rt "UDP active socket" "-D -n -1"
3612 ################################################################################
3613 # netfilter blocking connections
3615 netfilter_tcp_reset()
3619 for a in ${NSA_IP} ${VRF_IP}
3622 run_cmd nettest -s &
3624 run_cmd_nsb nettest -r ${a}
3625 log_test_addr ${a} $? 1 "Global server, reject with TCP-reset on Rx"
3635 [ "${stype}" = "UDP" ] && arg="-D"
3637 for a in ${NSA_IP} ${VRF_IP}
3640 run_cmd nettest ${arg} -s &
3642 run_cmd_nsb nettest ${arg} -r ${a}
3643 log_test_addr ${a} $? 1 "Global ${stype} server, Rx reject icmp-port-unreach"
3649 log_section "IPv4 Netfilter"
3650 log_subsection "TCP reset"
3653 run_cmd iptables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
3658 log_subsection "ICMP unreachable"
3662 run_cmd iptables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with icmp-port-unreachable
3663 run_cmd iptables -A INPUT -p udp --dport 12345 -j REJECT --reject-with icmp-port-unreachable
3665 netfilter_icmp "TCP"
3666 netfilter_icmp "UDP"
3672 netfilter_tcp6_reset()
3676 for a in ${NSA_IP6} ${VRF_IP6}
3679 run_cmd nettest -6 -s &
3681 run_cmd_nsb nettest -6 -r ${a}
3682 log_test_addr ${a} $? 1 "Global server, reject with TCP-reset on Rx"
3692 [ "${stype}" = "UDP" ] && arg="$arg -D"
3694 for a in ${NSA_IP6} ${VRF_IP6}
3697 run_cmd nettest -6 -s ${arg} &
3699 run_cmd_nsb nettest -6 ${arg} -r ${a}
3700 log_test_addr ${a} $? 1 "Global ${stype} server, Rx reject icmp-port-unreach"
3706 log_section "IPv6 Netfilter"
3707 log_subsection "TCP reset"
3710 run_cmd ip6tables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
3712 netfilter_tcp6_reset
3714 log_subsection "ICMP unreachable"
3717 run_cmd ip6tables -F
3718 run_cmd ip6tables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with icmp6-port-unreachable
3719 run_cmd ip6tables -A INPUT -p udp --dport 12345 -j REJECT --reject-with icmp6-port-unreachable
3721 netfilter_icmp6 "TCP"
3722 netfilter_icmp6 "UDP"
3728 ################################################################################
3729 # specific use cases
3732 # ns-A device enslaved to bridge. Verify traffic with and without
3733 # br_netfilter module loaded. Repeat with SVI on bridge.
3738 setup_cmd ip link set ${NSA_DEV} down
3739 setup_cmd ip addr del dev ${NSA_DEV} ${NSA_IP}/24
3740 setup_cmd ip -6 addr del dev ${NSA_DEV} ${NSA_IP6}/64
3742 setup_cmd ip link add br0 type bridge
3743 setup_cmd ip addr add dev br0 ${NSA_IP}/24
3744 setup_cmd ip -6 addr add dev br0 ${NSA_IP6}/64 nodad
3746 setup_cmd ip li set ${NSA_DEV} master br0
3747 setup_cmd ip li set ${NSA_DEV} up
3748 setup_cmd ip li set br0 up
3749 setup_cmd ip li set br0 vrf ${VRF}
3751 rmmod br_netfilter 2>/dev/null
3754 run_cmd ip neigh flush all
3755 run_cmd ping -c1 -w1 -I br0 ${NSB_IP}
3756 log_test $? 0 "Bridge into VRF - IPv4 ping out"
3758 run_cmd ip neigh flush all
3759 run_cmd ${ping6} -c1 -w1 -I br0 ${NSB_IP6}
3760 log_test $? 0 "Bridge into VRF - IPv6 ping out"
3762 run_cmd ip neigh flush all
3763 run_cmd_nsb ping -c1 -w1 ${NSA_IP}
3764 log_test $? 0 "Bridge into VRF - IPv4 ping in"
3766 run_cmd ip neigh flush all
3767 run_cmd_nsb ${ping6} -c1 -w1 ${NSA_IP6}
3768 log_test $? 0 "Bridge into VRF - IPv6 ping in"
3770 modprobe br_netfilter
3771 if [ $? -eq 0 ]; then
3772 run_cmd ip neigh flush all
3773 run_cmd ping -c1 -w1 -I br0 ${NSB_IP}
3774 log_test $? 0 "Bridge into VRF with br_netfilter - IPv4 ping out"
3776 run_cmd ip neigh flush all
3777 run_cmd ${ping6} -c1 -w1 -I br0 ${NSB_IP6}
3778 log_test $? 0 "Bridge into VRF with br_netfilter - IPv6 ping out"
3780 run_cmd ip neigh flush all
3781 run_cmd_nsb ping -c1 -w1 ${NSA_IP}
3782 log_test $? 0 "Bridge into VRF with br_netfilter - IPv4 ping in"
3784 run_cmd ip neigh flush all
3785 run_cmd_nsb ${ping6} -c1 -w1 ${NSA_IP6}
3786 log_test $? 0 "Bridge into VRF with br_netfilter - IPv6 ping in"
3789 setup_cmd ip li set br0 nomaster
3790 setup_cmd ip li add br0.100 link br0 type vlan id 100
3791 setup_cmd ip li set br0.100 vrf ${VRF} up
3792 setup_cmd ip addr add dev br0.100 172.16.101.1/24
3793 setup_cmd ip -6 addr add dev br0.100 2001:db8:101::1/64 nodad
3795 setup_cmd_nsb ip li add vlan100 link ${NSB_DEV} type vlan id 100
3796 setup_cmd_nsb ip addr add dev vlan100 172.16.101.2/24
3797 setup_cmd_nsb ip -6 addr add dev vlan100 2001:db8:101::2/64 nodad
3798 setup_cmd_nsb ip li set vlan100 up
3801 rmmod br_netfilter 2>/dev/null
3803 run_cmd ip neigh flush all
3804 run_cmd ping -c1 -w1 -I br0.100 172.16.101.2
3805 log_test $? 0 "Bridge vlan into VRF - IPv4 ping out"
3807 run_cmd ip neigh flush all
3808 run_cmd ${ping6} -c1 -w1 -I br0.100 2001:db8:101::2
3809 log_test $? 0 "Bridge vlan into VRF - IPv6 ping out"
3811 run_cmd ip neigh flush all
3812 run_cmd_nsb ping -c1 -w1 172.16.101.1
3813 log_test $? 0 "Bridge vlan into VRF - IPv4 ping in"
3815 run_cmd ip neigh flush all
3816 run_cmd_nsb ${ping6} -c1 -w1 2001:db8:101::1
3817 log_test $? 0 "Bridge vlan into VRF - IPv6 ping in"
3819 modprobe br_netfilter
3820 if [ $? -eq 0 ]; then
3821 run_cmd ip neigh flush all
3822 run_cmd ping -c1 -w1 -I br0.100 172.16.101.2
3823 log_test $? 0 "Bridge vlan into VRF with br_netfilter - IPv4 ping out"
3825 run_cmd ip neigh flush all
3826 run_cmd ${ping6} -c1 -w1 -I br0.100 2001:db8:101::2
3827 log_test $? 0 "Bridge vlan into VRF with br_netfilter - IPv6 ping out"
3829 run_cmd ip neigh flush all
3830 run_cmd_nsb ping -c1 -w1 172.16.101.1
3831 log_test $? 0 "Bridge vlan into VRF - IPv4 ping in"
3833 run_cmd ip neigh flush all
3834 run_cmd_nsb ${ping6} -c1 -w1 2001:db8:101::1
3835 log_test $? 0 "Bridge vlan into VRF - IPv6 ping in"
3838 setup_cmd ip li del br0 2>/dev/null
3839 setup_cmd_nsb ip li del vlan100 2>/dev/null
3843 # ns-A device is connected to both ns-B and ns-C on a single VRF but only has
3844 # LLA on the interfaces
3845 use_case_ping_lla_multi()
3848 # only want reply from ns-A
3849 setup_cmd_nsb sysctl -qw net.ipv6.icmp.echo_ignore_multicast=1
3850 setup_cmd_nsc sysctl -qw net.ipv6.icmp.echo_ignore_multicast=1
3853 run_cmd_nsb ping -c1 -w1 ${MCAST}%${NSB_DEV}
3854 log_test_addr ${MCAST}%${NSB_DEV} $? 0 "Pre cycle, ping out ns-B"
3856 run_cmd_nsc ping -c1 -w1 ${MCAST}%${NSC_DEV}
3857 log_test_addr ${MCAST}%${NSC_DEV} $? 0 "Pre cycle, ping out ns-C"
3859 # cycle/flap the first ns-A interface
3860 setup_cmd ip link set ${NSA_DEV} down
3861 setup_cmd ip link set ${NSA_DEV} up
3865 run_cmd_nsb ping -c1 -w1 ${MCAST}%${NSB_DEV}
3866 log_test_addr ${MCAST}%${NSB_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV}, ping out ns-B"
3867 run_cmd_nsc ping -c1 -w1 ${MCAST}%${NSC_DEV}
3868 log_test_addr ${MCAST}%${NSC_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV}, ping out ns-C"
3870 # cycle/flap the second ns-A interface
3871 setup_cmd ip link set ${NSA_DEV2} down
3872 setup_cmd ip link set ${NSA_DEV2} up
3876 run_cmd_nsb ping -c1 -w1 ${MCAST}%${NSB_DEV}
3877 log_test_addr ${MCAST}%${NSB_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV2}, ping out ns-B"
3878 run_cmd_nsc ping -c1 -w1 ${MCAST}%${NSC_DEV}
3879 log_test_addr ${MCAST}%${NSC_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV2}, ping out ns-C"
3884 log_section "Use cases"
3885 log_subsection "Device enslaved to bridge"
3887 log_subsection "Ping LLA with multiple interfaces"
3888 use_case_ping_lla_multi
3891 ################################################################################
3897 usage: ${0##*/} OPTS
3901 -t <test> Test name/set to run
3903 -P Pause after each test
3908 ################################################################################
3911 TESTS_IPV4="ipv4_ping ipv4_tcp ipv4_udp ipv4_addr_bind ipv4_runtime ipv4_netfilter"
3912 TESTS_IPV6="ipv6_ping ipv6_tcp ipv6_udp ipv6_addr_bind ipv6_runtime ipv6_netfilter"
3913 TESTS_OTHER="use_cases"
3918 while getopts :46t:pPvh o
3924 p) PAUSE_ON_FAIL=yes;;
3932 # make sure we don't pause twice
3933 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
3936 # show user test config
3938 if [ -z "$TESTS" ]; then
3939 TESTS="$TESTS_IPV4 $TESTS_IPV6 $TESTS_OTHER"
3940 elif [ "$TESTS" = "ipv4" ]; then
3942 elif [ "$TESTS" = "ipv6" ]; then
3946 which nettest >/dev/null
3947 if [ $? -ne 0 ]; then
3948 echo "'nettest' command not found; skipping tests"
3953 declare -i nsuccess=0
3958 ipv4_ping|ping) ipv4_ping;;
3959 ipv4_tcp|tcp) ipv4_tcp;;
3960 ipv4_udp|udp) ipv4_udp;;
3961 ipv4_bind|bind) ipv4_addr_bind;;
3962 ipv4_runtime) ipv4_runtime;;
3963 ipv4_netfilter) ipv4_netfilter;;
3965 ipv6_ping|ping6) ipv6_ping;;
3966 ipv6_tcp|tcp6) ipv6_tcp;;
3967 ipv6_udp|udp6) ipv6_udp;;
3968 ipv6_bind|bind6) ipv6_addr_bind;;
3969 ipv6_runtime) ipv6_runtime;;
3970 ipv6_netfilter) ipv6_netfilter;;
3972 use_cases) use_cases;;
3974 # setup namespaces and config, but do not run any tests
3975 setup) setup; exit 0;;
3976 vrf_setup) setup "yes"; exit 0;;
3978 help) echo "Test names: $TESTS"; exit 0;;
3984 printf "\nTests passed: %3d\n" ${nsuccess}
3985 printf "Tests failed: %3d\n" ${nfail}