2 # SPDX-License-Identifier: GPL-2.0
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
40 # Kselftest framework requirement - SKIP code is 4.
62 NS_NET6=2001:db8:1::/120
66 NSA_LO_IP6=2001:db8:2::1
67 NSB_LO_IP6=2001:db8:2::2
69 # non-local addresses for freebind tests
73 # multicast and broadcast addresses
75 BCAST_IP=255.255.255.255
81 # set after namespace create
89 NSA_CMD="ip netns exec ${NSA}"
90 NSB_CMD="ip netns exec ${NSB}"
91 NSC_CMD="ip netns exec ${NSC}"
93 which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
95 ################################################################################
104 [ "${VERBOSE}" = "1" ] && echo
106 if [ ${rc} -eq ${expected} ]; then
107 nsuccess=$((nsuccess+1))
108 printf "TEST: %-70s [ OK ]\n" "${msg}"
111 printf "TEST: %-70s [FAIL]\n" "${msg}"
112 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
114 echo "hit enter to continue, 'q' to quit"
116 [ "$a" = "q" ] && exit 1
120 if [ "${PAUSE}" = "yes" ]; then
122 echo "hit enter to continue, 'q' to quit"
124 [ "$a" = "q" ] && exit 1
138 astr=$(addr2str ${addr})
139 log_test $rc $expected "$msg - ${astr}"
145 echo "###########################################################################"
147 echo "###########################################################################"
154 echo "#################################################################"
161 # make sure we have no test instances running
164 if [ "${VERBOSE}" = "1" ]; then
166 echo "#######################################################"
172 if [ "${VERBOSE}" = "1" ]; then
181 if [ "${VERBOSE}" = "1" ]; then
189 killall nettest ping ping6 >/dev/null 2>&1
198 if [ "$VERBOSE" = "1" ]; then
199 echo "COMMAND: ${cmd}"
204 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
213 do_run_cmd ${NSA_CMD} $*
218 do_run_cmd ${NSB_CMD} $*
223 do_run_cmd ${NSC_CMD} $*
233 if [ $rc -ne 0 ]; then
234 # show user the command if not done so already
235 if [ "$VERBOSE" = "0" ]; then
236 echo "setup command: $cmd"
238 echo "failed. stopping tests"
239 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
241 echo "hit enter to continue"
255 if [ $rc -ne 0 ]; then
256 # show user the command if not done so already
257 if [ "$VERBOSE" = "0" ]; then
258 echo "setup command: $cmd"
260 echo "failed. stopping tests"
261 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
263 echo "hit enter to continue"
277 if [ $rc -ne 0 ]; then
278 # show user the command if not done so already
279 if [ "$VERBOSE" = "0" ]; then
280 echo "setup command: $cmd"
282 echo "failed. stopping tests"
283 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
285 echo "hit enter to continue"
292 # set sysctl values in NS-A
297 run_cmd sysctl -q -w $*
300 # get sysctl values in NS-A
303 ${NSA_CMD} sysctl -n $*
306 ################################################################################
312 127.0.0.1) echo "loopback";;
313 ::1) echo "IPv6 loopback";;
315 ${BCAST_IP}) echo "broadcast";;
316 ${MCAST_IP}) echo "multicast";;
318 ${NSA_IP}) echo "ns-A IP";;
319 ${NSA_IP6}) echo "ns-A IPv6";;
320 ${NSA_LO_IP}) echo "ns-A loopback IP";;
321 ${NSA_LO_IP6}) echo "ns-A loopback IPv6";;
322 ${NSA_LINKIP6}|${NSA_LINKIP6}%*) echo "ns-A IPv6 LLA";;
324 ${NSB_IP}) echo "ns-B IP";;
325 ${NSB_IP6}) echo "ns-B IPv6";;
326 ${NSB_LO_IP}) echo "ns-B loopback IP";;
327 ${NSB_LO_IP6}) echo "ns-B loopback IPv6";;
328 ${NSB_LINKIP6}|${NSB_LINKIP6}%*) echo "ns-B IPv6 LLA";;
330 ${NL_IP}) echo "nonlocal IP";;
331 ${NL_IP6}) echo "nonlocal IPv6";;
333 ${VRF_IP}) echo "VRF IP";;
334 ${VRF_IP6}) echo "VRF IPv6";;
336 ${MCAST}%*) echo "multicast IP";;
348 addr=$(ip -netns ${ns} -6 -br addr show dev ${dev} | \
350 for (i = 3; i <= NF; ++i) {
358 [ -z "$addr" ] && return 1
365 ################################################################################
366 # create namespaces and vrf
376 ip -netns ${ns} link add ${vrf} type vrf table ${table}
377 ip -netns ${ns} link set ${vrf} up
378 ip -netns ${ns} route add vrf ${vrf} unreachable default metric 8192
379 ip -netns ${ns} -6 route add vrf ${vrf} unreachable default metric 8192
381 ip -netns ${ns} addr add 127.0.0.1/8 dev ${vrf}
382 ip -netns ${ns} -6 addr add ::1 dev ${vrf} nodad
383 if [ "${addr}" != "-" ]; then
384 ip -netns ${ns} addr add dev ${vrf} ${addr}
386 if [ "${addr6}" != "-" ]; then
387 ip -netns ${ns} -6 addr add dev ${vrf} ${addr6}
390 ip -netns ${ns} ru del pref 0
391 ip -netns ${ns} ru add pref 32765 from all lookup local
392 ip -netns ${ns} -6 ru del pref 0
393 ip -netns ${ns} -6 ru add pref 32765 from all lookup local
404 ip -netns ${ns} link set lo up
405 if [ "${addr}" != "-" ]; then
406 ip -netns ${ns} addr add dev lo ${addr}
408 if [ "${addr6}" != "-" ]; then
409 ip -netns ${ns} -6 addr add dev lo ${addr6}
412 ip -netns ${ns} ro add unreachable default metric 8192
413 ip -netns ${ns} -6 ro add unreachable default metric 8192
415 ip netns exec ${ns} sysctl -qw net.ipv4.ip_forward=1
416 ip netns exec ${ns} sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1
417 ip netns exec ${ns} sysctl -qw net.ipv6.conf.all.forwarding=1
418 ip netns exec ${ns} sysctl -qw net.ipv6.conf.default.forwarding=1
421 # create veth pair to connect namespaces and apply addresses.
433 ip -netns ${ns1} li add ${ns1_dev} type veth peer name tmp
434 ip -netns ${ns1} li set ${ns1_dev} up
435 ip -netns ${ns1} li set tmp netns ${ns2} name ${ns2_dev}
436 ip -netns ${ns2} li set ${ns2_dev} up
438 if [ "${ns1_addr}" != "-" ]; then
439 ip -netns ${ns1} addr add dev ${ns1_dev} ${ns1_addr}
440 ip -netns ${ns2} addr add dev ${ns2_dev} ${ns2_addr}
443 if [ "${ns1_addr6}" != "-" ]; then
444 ip -netns ${ns1} addr add dev ${ns1_dev} ${ns1_addr6}
445 ip -netns ${ns2} addr add dev ${ns2_dev} ${ns2_addr6}
451 # explicit cleanups to check those code paths
452 ip netns | grep -q ${NSA}
453 if [ $? -eq 0 ]; then
454 ip -netns ${NSA} link delete ${VRF}
455 ip -netns ${NSA} ro flush table ${VRF_TABLE}
457 ip -netns ${NSA} addr flush dev ${NSA_DEV}
458 ip -netns ${NSA} -6 addr flush dev ${NSA_DEV}
459 ip -netns ${NSA} link set dev ${NSA_DEV} down
460 ip -netns ${NSA} link del dev ${NSA_DEV}
462 ip netns pids ${NSA} | xargs kill 2>/dev/null
466 ip netns pids ${NSB} | xargs kill 2>/dev/null
468 ip netns pids ${NSC} | xargs kill 2>/dev/null
469 ip netns del ${NSC} >/dev/null 2>&1
474 ip link del ${NSA_DEV2} >/dev/null 2>&1
475 ip netns pids ${NSC} | xargs kill 2>/dev/null
476 ip netns del ${NSC} >/dev/null 2>&1
481 # some VRF tests use ns-C which has the same config as
482 # ns-B but for a device NOT in the VRF
483 create_ns ${NSC} "-" "-"
484 connect_ns ${NSA} ${NSA_DEV2} ${NSA_IP}/24 ${NSA_IP6}/64 \
485 ${NSC} ${NSC_DEV} ${NSB_IP}/24 ${NSB_IP6}/64
492 # make sure we are starting with a clean slate
496 log_debug "Configuring network namespaces"
499 create_ns ${NSA} ${NSA_LO_IP}/32 ${NSA_LO_IP6}/128
500 create_ns ${NSB} ${NSB_LO_IP}/32 ${NSB_LO_IP6}/128
501 connect_ns ${NSA} ${NSA_DEV} ${NSA_IP}/24 ${NSA_IP6}/64 \
502 ${NSB} ${NSB_DEV} ${NSB_IP}/24 ${NSB_IP6}/64
504 NSA_LINKIP6=$(get_linklocal ${NSA} ${NSA_DEV})
505 NSB_LINKIP6=$(get_linklocal ${NSB} ${NSB_DEV})
507 # tell ns-A how to get to remote addresses of ns-B
508 if [ "${with_vrf}" = "yes" ]; then
509 create_vrf ${NSA} ${VRF} ${VRF_TABLE} ${VRF_IP} ${VRF_IP6}
511 ip -netns ${NSA} link set dev ${NSA_DEV} vrf ${VRF}
512 ip -netns ${NSA} ro add vrf ${VRF} ${NSB_LO_IP}/32 via ${NSB_IP} dev ${NSA_DEV}
513 ip -netns ${NSA} -6 ro add vrf ${VRF} ${NSB_LO_IP6}/128 via ${NSB_IP6} dev ${NSA_DEV}
515 ip -netns ${NSB} ro add ${VRF_IP}/32 via ${NSA_IP} dev ${NSB_DEV}
516 ip -netns ${NSB} -6 ro add ${VRF_IP6}/128 via ${NSA_IP6} dev ${NSB_DEV}
518 ip -netns ${NSA} ro add ${NSB_LO_IP}/32 via ${NSB_IP} dev ${NSA_DEV}
519 ip -netns ${NSA} ro add ${NSB_LO_IP6}/128 via ${NSB_IP6} dev ${NSA_DEV}
523 # tell ns-B how to get to remote addresses of ns-A
524 ip -netns ${NSB} ro add ${NSA_LO_IP}/32 via ${NSA_IP} dev ${NSB_DEV}
525 ip -netns ${NSB} ro add ${NSA_LO_IP6}/128 via ${NSA_IP6} dev ${NSB_DEV}
534 # make sure we are starting with a clean slate
538 log_debug "Configuring network namespaces"
541 create_ns ${NSA} "-" "-"
542 create_ns ${NSB} "-" "-"
543 create_ns ${NSC} "-" "-"
544 connect_ns ${NSA} ${NSA_DEV} "-" "-" \
545 ${NSB} ${NSB_DEV} "-" "-"
546 connect_ns ${NSA} ${NSA_DEV2} "-" "-" \
547 ${NSC} ${NSC_DEV} "-" "-"
549 NSA_LINKIP6=$(get_linklocal ${NSA} ${NSA_DEV})
550 NSB_LINKIP6=$(get_linklocal ${NSB} ${NSB_DEV})
551 NSC_LINKIP6=$(get_linklocal ${NSC} ${NSC_DEV})
553 create_vrf ${NSA} ${VRF} ${VRF_TABLE} "-" "-"
554 ip -netns ${NSA} link set dev ${NSA_DEV} vrf ${VRF}
555 ip -netns ${NSA} link set dev ${NSA_DEV2} vrf ${VRF}
562 ################################################################################
572 for a in ${NSB_IP} ${NSB_LO_IP}
575 run_cmd ping -c1 -w1 ${a}
576 log_test_addr ${a} $? 0 "ping out"
579 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
580 log_test_addr ${a} $? 0 "ping out, device bind"
583 run_cmd ping -c1 -w1 -I ${NSA_LO_IP} ${a}
584 log_test_addr ${a} $? 0 "ping out, address bind"
590 for a in ${NSA_IP} ${NSA_LO_IP}
593 run_cmd_nsb ping -c1 -w1 ${a}
594 log_test_addr ${a} $? 0 "ping in"
600 for a in ${NSA_IP} ${NSA_LO_IP} 127.0.0.1
603 run_cmd ping -c1 -w1 ${a}
604 log_test_addr ${a} $? 0 "ping local"
608 # local traffic, socket bound to device
613 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
614 log_test_addr ${a} $? 0 "ping local, device bind"
616 # loopback addresses not reachable from device bind
617 # fails in a really weird way though because ipv4 special cases
618 # route lookups with oif set.
619 for a in ${NSA_LO_IP} 127.0.0.1
622 show_hint "Fails since address on loopback device is out of device scope"
623 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
624 log_test_addr ${a} $? 1 "ping local, device bind"
628 # ip rule blocks reachability to remote address
631 setup_cmd ip rule add pref 32765 from all lookup local
632 setup_cmd ip rule del pref 0 from all lookup local
633 setup_cmd ip rule add pref 50 to ${NSB_LO_IP} prohibit
634 setup_cmd ip rule add pref 51 from ${NSB_IP} prohibit
637 run_cmd ping -c1 -w1 ${a}
638 log_test_addr ${a} $? 2 "ping out, blocked by rule"
640 # NOTE: ipv4 actually allows the lookup to fail and yet still create
641 # a viable rtable if the oif (e.g., bind to device) is set, so this
642 # case succeeds despite the rule
643 # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
647 show_hint "Response generates ICMP (or arp request is ignored) due to ip rule"
648 run_cmd_nsb ping -c1 -w1 ${a}
649 log_test_addr ${a} $? 1 "ping in, blocked by rule"
651 [ "$VERBOSE" = "1" ] && echo
652 setup_cmd ip rule del pref 32765 from all lookup local
653 setup_cmd ip rule add pref 0 from all lookup local
654 setup_cmd ip rule del pref 50 to ${NSB_LO_IP} prohibit
655 setup_cmd ip rule del pref 51 from ${NSB_IP} prohibit
658 # route blocks reachability to remote address
661 setup_cmd ip route replace unreachable ${NSB_LO_IP}
662 setup_cmd ip route replace unreachable ${NSB_IP}
665 run_cmd ping -c1 -w1 ${a}
666 log_test_addr ${a} $? 2 "ping out, blocked by route"
668 # NOTE: ipv4 actually allows the lookup to fail and yet still create
669 # a viable rtable if the oif (e.g., bind to device) is set, so this
670 # case succeeds despite not having a route for the address
671 # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
675 show_hint "Response is dropped (or arp request is ignored) due to ip route"
676 run_cmd_nsb ping -c1 -w1 ${a}
677 log_test_addr ${a} $? 1 "ping in, blocked by route"
680 # remove 'remote' routes; fallback to default
683 setup_cmd ip ro del ${NSB_LO_IP}
686 run_cmd ping -c1 -w1 ${a}
687 log_test_addr ${a} $? 2 "ping out, unreachable default route"
689 # NOTE: ipv4 actually allows the lookup to fail and yet still create
690 # a viable rtable if the oif (e.g., bind to device) is set, so this
691 # case succeeds despite not having a route for the address
692 # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
699 # should default on; does not exist on older kernels
700 set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
705 for a in ${NSB_IP} ${NSB_LO_IP}
708 run_cmd ping -c1 -w1 -I ${VRF} ${a}
709 log_test_addr ${a} $? 0 "ping out, VRF bind"
712 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
713 log_test_addr ${a} $? 0 "ping out, device bind"
716 run_cmd ip vrf exec ${VRF} ping -c1 -w1 -I ${NSA_IP} ${a}
717 log_test_addr ${a} $? 0 "ping out, vrf device + dev address bind"
720 run_cmd ip vrf exec ${VRF} ping -c1 -w1 -I ${VRF_IP} ${a}
721 log_test_addr ${a} $? 0 "ping out, vrf device + vrf address bind"
727 for a in ${NSA_IP} ${VRF_IP}
730 run_cmd_nsb ping -c1 -w1 ${a}
731 log_test_addr ${a} $? 0 "ping in"
735 # local traffic, local address
737 for a in ${NSA_IP} ${VRF_IP} 127.0.0.1
740 show_hint "Source address should be ${a}"
741 run_cmd ping -c1 -w1 -I ${VRF} ${a}
742 log_test_addr ${a} $? 0 "ping local, VRF bind"
746 # local traffic, socket bound to device
751 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
752 log_test_addr ${a} $? 0 "ping local, device bind"
754 # vrf device is out of scope
755 for a in ${VRF_IP} 127.0.0.1
758 show_hint "Fails since address on vrf device is out of device scope"
759 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
760 log_test_addr ${a} $? 2 "ping local, device bind"
764 # ip rule blocks address
767 setup_cmd ip rule add pref 50 to ${NSB_LO_IP} prohibit
768 setup_cmd ip rule add pref 51 from ${NSB_IP} prohibit
771 run_cmd ping -c1 -w1 -I ${VRF} ${a}
772 log_test_addr ${a} $? 2 "ping out, vrf bind, blocked by rule"
775 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
776 log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
780 show_hint "Response lost due to ip rule"
781 run_cmd_nsb ping -c1 -w1 ${a}
782 log_test_addr ${a} $? 1 "ping in, blocked by rule"
784 [ "$VERBOSE" = "1" ] && echo
785 setup_cmd ip rule del pref 50 to ${NSB_LO_IP} prohibit
786 setup_cmd ip rule del pref 51 from ${NSB_IP} prohibit
789 # remove 'remote' routes; fallback to default
792 setup_cmd ip ro del vrf ${VRF} ${NSB_LO_IP}
795 run_cmd ping -c1 -w1 -I ${VRF} ${a}
796 log_test_addr ${a} $? 2 "ping out, vrf bind, unreachable route"
799 run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
800 log_test_addr ${a} $? 2 "ping out, device bind, unreachable route"
804 show_hint "Response lost by unreachable route"
805 run_cmd_nsb ping -c1 -w1 ${a}
806 log_test_addr ${a} $? 1 "ping in, unreachable route"
811 log_section "IPv4 ping"
813 log_subsection "No VRF"
815 set_sysctl net.ipv4.raw_l3mdev_accept=0 2>/dev/null
818 set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
821 set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
824 log_subsection "With VRF"
828 set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
832 ################################################################################
836 # MD5 tests without VRF
846 run_cmd nettest -s -M ${MD5_PW} -m ${NSB_IP} &
848 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
849 log_test $? 0 "MD5: Single address config"
851 # client sends MD5, server not configured
853 show_hint "Should timeout due to MD5 mismatch"
856 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
857 log_test $? 2 "MD5: Server no config, client uses password"
861 show_hint "Should timeout since client uses wrong password"
862 run_cmd nettest -s -M ${MD5_PW} -m ${NSB_IP} &
864 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
865 log_test $? 2 "MD5: Client uses wrong password"
867 # client from different address
869 show_hint "Should timeout due to MD5 mismatch"
870 run_cmd nettest -s -M ${MD5_PW} -m ${NSB_LO_IP} &
872 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
873 log_test $? 2 "MD5: Client address does not match address configured with password"
876 # MD5 extension - prefix length
881 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
883 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
884 log_test $? 0 "MD5: Prefix config"
886 # client in prefix, wrong password
888 show_hint "Should timeout since client uses wrong password"
889 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
891 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
892 log_test $? 2 "MD5: Prefix config, client uses wrong password"
894 # client outside of prefix
896 show_hint "Should timeout due to MD5 mismatch"
897 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
899 run_cmd_nsb nettest -c ${NSB_LO_IP} -r ${NSA_IP} -X ${MD5_PW}
900 log_test $? 2 "MD5: Prefix config, client address not in configured prefix"
914 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP} &
916 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
917 log_test $? 0 "MD5: VRF: Single address config"
919 # client sends MD5, server not configured
921 show_hint "Should timeout since server does not have MD5 auth"
922 run_cmd nettest -s -I ${VRF} &
924 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
925 log_test $? 2 "MD5: VRF: Server no config, client uses password"
929 show_hint "Should timeout since client uses wrong password"
930 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP} &
932 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
933 log_test $? 2 "MD5: VRF: Client uses wrong password"
935 # client from different address
937 show_hint "Should timeout since server config differs from client"
938 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_LO_IP} &
940 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
941 log_test $? 2 "MD5: VRF: Client address does not match address configured with password"
944 # MD5 extension - prefix length
949 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
951 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
952 log_test $? 0 "MD5: VRF: Prefix config"
954 # client in prefix, wrong password
956 show_hint "Should timeout since client uses wrong password"
957 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
959 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
960 log_test $? 2 "MD5: VRF: Prefix config, client uses wrong password"
962 # client outside of prefix
964 show_hint "Should timeout since client address is outside of prefix"
965 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
967 run_cmd_nsb nettest -c ${NSB_LO_IP} -r ${NSA_IP} -X ${MD5_PW}
968 log_test $? 2 "MD5: VRF: Prefix config, client address not in configured prefix"
971 # duplicate config between default VRF and a VRF
975 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP} &
976 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NSB_IP} &
978 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
979 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF"
982 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP} &
983 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NSB_IP} &
985 run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
986 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF"
989 show_hint "Should timeout since client in default VRF uses VRF password"
990 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP} &
991 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NSB_IP} &
993 run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_PW}
994 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF with VRF pw"
997 show_hint "Should timeout since client in VRF uses default VRF password"
998 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP} &
999 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NSB_IP} &
1001 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
1002 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF with default VRF pw"
1005 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
1006 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
1008 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
1009 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF"
1012 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
1013 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
1015 run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
1016 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF"
1019 show_hint "Should timeout since client in default VRF uses VRF password"
1020 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
1021 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
1023 run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_PW}
1024 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF with VRF pw"
1027 show_hint "Should timeout since client in VRF uses default VRF password"
1028 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
1029 run_cmd nettest -s -M ${MD5_WRONG_PW} -m ${NS_NET} &
1031 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_WRONG_PW}
1032 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF with default VRF pw"
1038 run_cmd nettest -s -I ${NSA_DEV} -M ${MD5_PW} -m ${NSB_IP}
1039 log_test $? 1 "MD5: VRF: Device must be a VRF - single address"
1042 run_cmd nettest -s -I ${NSA_DEV} -M ${MD5_PW} -m ${NS_NET}
1043 log_test $? 1 "MD5: VRF: Device must be a VRF - prefix"
1045 test_ipv4_md5_vrf__vrf_server__no_bind_ifindex
1046 test_ipv4_md5_vrf__global_server__bind_ifindex0
1049 test_ipv4_md5_vrf__vrf_server__no_bind_ifindex()
1052 show_hint "Simulates applications using VRF without TCP_MD5SIG_FLAG_IFINDEX"
1053 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} --no-bind-key-ifindex &
1055 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
1056 log_test $? 0 "MD5: VRF: VRF-bound server, unbound key accepts connection"
1059 show_hint "Binding both the socket and the key is not required but it works"
1060 run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} --force-bind-key-ifindex &
1062 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
1063 log_test $? 0 "MD5: VRF: VRF-bound server, bound key accepts connection"
1066 test_ipv4_md5_vrf__global_server__bind_ifindex0()
1068 # This particular test needs tcp_l3mdev_accept=1 for Global server to accept VRF connections
1069 local old_tcp_l3mdev_accept
1070 old_tcp_l3mdev_accept=$(get_sysctl net.ipv4.tcp_l3mdev_accept)
1071 set_sysctl net.ipv4.tcp_l3mdev_accept=1
1074 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --force-bind-key-ifindex &
1076 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
1077 log_test $? 2 "MD5: VRF: Global server, Key bound to ifindex=0 rejects VRF connection"
1080 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --force-bind-key-ifindex &
1082 run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_PW}
1083 log_test $? 0 "MD5: VRF: Global server, key bound to ifindex=0 accepts non-VRF connection"
1086 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --no-bind-key-ifindex &
1088 run_cmd_nsb nettest -r ${NSA_IP} -X ${MD5_PW}
1089 log_test $? 0 "MD5: VRF: Global server, key not bound to ifindex accepts VRF connection"
1092 run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} --no-bind-key-ifindex &
1094 run_cmd_nsc nettest -r ${NSA_IP} -X ${MD5_PW}
1095 log_test $? 0 "MD5: VRF: Global server, key not bound to ifindex accepts non-VRF connection"
1098 set_sysctl net.ipv4.tcp_l3mdev_accept="$old_tcp_l3mdev_accept"
1108 for a in ${NSA_IP} ${NSA_LO_IP}
1111 run_cmd nettest -s &
1113 run_cmd_nsb nettest -r ${a}
1114 log_test_addr ${a} $? 0 "Global server"
1119 run_cmd nettest -s -I ${NSA_DEV} &
1121 run_cmd_nsb nettest -r ${a}
1122 log_test_addr ${a} $? 0 "Device server"
1124 # verify TCP reset sent and received
1125 for a in ${NSA_IP} ${NSA_LO_IP}
1128 show_hint "Should fail 'Connection refused' since there is no server"
1129 run_cmd_nsb nettest -r ${a}
1130 log_test_addr ${a} $? 1 "No server"
1136 for a in ${NSB_IP} ${NSB_LO_IP}
1139 run_cmd_nsb nettest -s &
1141 run_cmd nettest -r ${a} -0 ${NSA_IP}
1142 log_test_addr ${a} $? 0 "Client"
1145 run_cmd_nsb nettest -s &
1147 run_cmd nettest -r ${a} -d ${NSA_DEV}
1148 log_test_addr ${a} $? 0 "Client, device bind"
1151 show_hint "Should fail 'Connection refused'"
1152 run_cmd nettest -r ${a}
1153 log_test_addr ${a} $? 1 "No server, unbound client"
1156 show_hint "Should fail 'Connection refused'"
1157 run_cmd nettest -r ${a} -d ${NSA_DEV}
1158 log_test_addr ${a} $? 1 "No server, device client"
1162 # local address tests
1164 for a in ${NSA_IP} ${NSA_LO_IP} 127.0.0.1
1167 run_cmd nettest -s &
1169 run_cmd nettest -r ${a} -0 ${a} -1 ${a}
1170 log_test_addr ${a} $? 0 "Global server, local connection"
1175 run_cmd nettest -s -I ${NSA_DEV} &
1177 run_cmd nettest -r ${a} -0 ${a}
1178 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
1180 for a in ${NSA_LO_IP} 127.0.0.1
1183 show_hint "Should fail 'Connection refused' since addresses on loopback are out of device scope"
1184 run_cmd nettest -s -I ${NSA_DEV} &
1186 run_cmd nettest -r ${a}
1187 log_test_addr ${a} $? 1 "Device server, unbound client, local connection"
1192 run_cmd nettest -s &
1194 run_cmd nettest -r ${a} -0 ${a} -d ${NSA_DEV}
1195 log_test_addr ${a} $? 0 "Global server, device client, local connection"
1197 for a in ${NSA_LO_IP} 127.0.0.1
1200 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
1201 run_cmd nettest -s &
1203 run_cmd nettest -r ${a} -d ${NSA_DEV}
1204 log_test_addr ${a} $? 1 "Global server, device client, local connection"
1209 run_cmd nettest -s -I ${NSA_DEV} -3 ${NSA_DEV} &
1211 run_cmd nettest -d ${NSA_DEV} -r ${a} -0 ${a}
1212 log_test_addr ${a} $? 0 "Device server, device client, local connection"
1215 show_hint "Should fail 'Connection refused'"
1216 run_cmd nettest -d ${NSA_DEV} -r ${a}
1217 log_test_addr ${a} $? 1 "No server, device client, local conn"
1226 # disable global server
1227 log_subsection "Global server disabled"
1229 set_sysctl net.ipv4.tcp_l3mdev_accept=0
1234 for a in ${NSA_IP} ${VRF_IP}
1237 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
1238 run_cmd nettest -s &
1240 run_cmd_nsb nettest -r ${a}
1241 log_test_addr ${a} $? 1 "Global server"
1244 run_cmd nettest -s -I ${VRF} -3 ${VRF} &
1246 run_cmd_nsb nettest -r ${a}
1247 log_test_addr ${a} $? 0 "VRF server"
1250 run_cmd nettest -s -I ${NSA_DEV} -3 ${NSA_DEV} &
1252 run_cmd_nsb nettest -r ${a}
1253 log_test_addr ${a} $? 0 "Device server"
1255 # verify TCP reset received
1257 show_hint "Should fail 'Connection refused' since there is no server"
1258 run_cmd_nsb nettest -r ${a}
1259 log_test_addr ${a} $? 1 "No server"
1262 # local address tests
1263 # (${VRF_IP} and 127.0.0.1 both timeout)
1266 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
1267 run_cmd nettest -s &
1269 run_cmd nettest -r ${a} -d ${NSA_DEV}
1270 log_test_addr ${a} $? 1 "Global server, local connection"
1278 # enable VRF global server
1280 log_subsection "VRF Global server enabled"
1281 set_sysctl net.ipv4.tcp_l3mdev_accept=1
1283 for a in ${NSA_IP} ${VRF_IP}
1286 show_hint "client socket should be bound to VRF"
1287 run_cmd nettest -s -3 ${VRF} &
1289 run_cmd_nsb nettest -r ${a}
1290 log_test_addr ${a} $? 0 "Global server"
1293 show_hint "client socket should be bound to VRF"
1294 run_cmd nettest -s -I ${VRF} -3 ${VRF} &
1296 run_cmd_nsb nettest -r ${a}
1297 log_test_addr ${a} $? 0 "VRF server"
1299 # verify TCP reset received
1301 show_hint "Should fail 'Connection refused'"
1302 run_cmd_nsb nettest -r ${a}
1303 log_test_addr ${a} $? 1 "No server"
1308 show_hint "client socket should be bound to device"
1309 run_cmd nettest -s -I ${NSA_DEV} -3 ${NSA_DEV} &
1311 run_cmd_nsb nettest -r ${a}
1312 log_test_addr ${a} $? 0 "Device server"
1314 # local address tests
1315 for a in ${NSA_IP} ${VRF_IP}
1318 show_hint "Should fail 'Connection refused' since client is not bound to VRF"
1319 run_cmd nettest -s -I ${VRF} &
1321 run_cmd nettest -r ${a}
1322 log_test_addr ${a} $? 1 "Global server, local connection"
1328 for a in ${NSB_IP} ${NSB_LO_IP}
1331 run_cmd_nsb nettest -s &
1333 run_cmd nettest -r ${a} -d ${VRF}
1334 log_test_addr ${a} $? 0 "Client, VRF bind"
1337 run_cmd_nsb nettest -s &
1339 run_cmd nettest -r ${a} -d ${NSA_DEV}
1340 log_test_addr ${a} $? 0 "Client, device bind"
1343 show_hint "Should fail 'Connection refused'"
1344 run_cmd nettest -r ${a} -d ${VRF}
1345 log_test_addr ${a} $? 1 "No server, VRF client"
1348 show_hint "Should fail 'Connection refused'"
1349 run_cmd nettest -r ${a} -d ${NSA_DEV}
1350 log_test_addr ${a} $? 1 "No server, device client"
1353 for a in ${NSA_IP} ${VRF_IP} 127.0.0.1
1356 run_cmd nettest -s -I ${VRF} -3 ${VRF} &
1358 run_cmd nettest -r ${a} -d ${VRF} -0 ${a}
1359 log_test_addr ${a} $? 0 "VRF server, VRF client, local connection"
1364 run_cmd nettest -s -I ${VRF} -3 ${VRF} &
1366 run_cmd nettest -r ${a} -d ${NSA_DEV} -0 ${a}
1367 log_test_addr ${a} $? 0 "VRF server, device client, local connection"
1370 show_hint "Should fail 'No route to host' since client is out of VRF scope"
1371 run_cmd nettest -s -I ${VRF} &
1373 run_cmd nettest -r ${a}
1374 log_test_addr ${a} $? 1 "VRF server, unbound client, local connection"
1377 run_cmd nettest -s -I ${NSA_DEV} -3 ${NSA_DEV} &
1379 run_cmd nettest -r ${a} -d ${VRF} -0 ${a}
1380 log_test_addr ${a} $? 0 "Device server, VRF client, local connection"
1383 run_cmd nettest -s -I ${NSA_DEV} -3 ${NSA_DEV} &
1385 run_cmd nettest -r ${a} -d ${NSA_DEV} -0 ${a}
1386 log_test_addr ${a} $? 0 "Device server, device client, local connection"
1391 log_section "IPv4/TCP"
1392 log_subsection "No VRF"
1395 # tcp_l3mdev_accept should have no affect without VRF;
1396 # run tests with it enabled and disabled to verify
1397 log_subsection "tcp_l3mdev_accept disabled"
1398 set_sysctl net.ipv4.tcp_l3mdev_accept=0
1400 log_subsection "tcp_l3mdev_accept enabled"
1401 set_sysctl net.ipv4.tcp_l3mdev_accept=1
1404 log_subsection "With VRF"
1409 ################################################################################
1419 for a in ${NSA_IP} ${NSA_LO_IP}
1422 run_cmd nettest -D -s -3 ${NSA_DEV} &
1424 run_cmd_nsb nettest -D -r ${a}
1425 log_test_addr ${a} $? 0 "Global server"
1428 show_hint "Should fail 'Connection refused' since there is no server"
1429 run_cmd_nsb nettest -D -r ${a}
1430 log_test_addr ${a} $? 1 "No server"
1435 run_cmd nettest -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
1437 run_cmd_nsb nettest -D -r ${a}
1438 log_test_addr ${a} $? 0 "Device server"
1443 for a in ${NSB_IP} ${NSB_LO_IP}
1446 run_cmd_nsb nettest -D -s &
1448 run_cmd nettest -D -r ${a} -0 ${NSA_IP}
1449 log_test_addr ${a} $? 0 "Client"
1452 run_cmd_nsb nettest -D -s &
1454 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -0 ${NSA_IP}
1455 log_test_addr ${a} $? 0 "Client, device bind"
1458 run_cmd_nsb nettest -D -s &
1460 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -C -0 ${NSA_IP}
1461 log_test_addr ${a} $? 0 "Client, device send via cmsg"
1464 run_cmd_nsb nettest -D -s &
1466 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -S -0 ${NSA_IP}
1467 log_test_addr ${a} $? 0 "Client, device bind via IP_UNICAST_IF"
1470 run_cmd_nsb nettest -D -s &
1472 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -S -0 ${NSA_IP} -U
1473 log_test_addr ${a} $? 0 "Client, device bind via IP_UNICAST_IF, with connect()"
1477 show_hint "Should fail 'Connection refused'"
1478 run_cmd nettest -D -r ${a}
1479 log_test_addr ${a} $? 1 "No server, unbound client"
1482 show_hint "Should fail 'Connection refused'"
1483 run_cmd nettest -D -r ${a} -d ${NSA_DEV}
1484 log_test_addr ${a} $? 1 "No server, device client"
1488 # local address tests
1490 for a in ${NSA_IP} ${NSA_LO_IP} 127.0.0.1
1493 run_cmd nettest -D -s &
1495 run_cmd nettest -D -r ${a} -0 ${a} -1 ${a}
1496 log_test_addr ${a} $? 0 "Global server, local connection"
1501 run_cmd nettest -s -D -I ${NSA_DEV} -3 ${NSA_DEV} &
1503 run_cmd nettest -D -r ${a}
1504 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
1506 for a in ${NSA_LO_IP} 127.0.0.1
1509 show_hint "Should fail 'Connection refused' since address is out of device scope"
1510 run_cmd nettest -s -D -I ${NSA_DEV} &
1512 run_cmd nettest -D -r ${a}
1513 log_test_addr ${a} $? 1 "Device server, unbound client, local connection"
1518 run_cmd nettest -s -D &
1520 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1521 log_test_addr ${a} $? 0 "Global server, device client, local connection"
1524 run_cmd nettest -s -D &
1526 run_cmd nettest -D -d ${NSA_DEV} -C -r ${a}
1527 log_test_addr ${a} $? 0 "Global server, device send via cmsg, local connection"
1530 run_cmd nettest -s -D &
1532 run_cmd nettest -D -d ${NSA_DEV} -S -r ${a}
1533 log_test_addr ${a} $? 0 "Global server, device client via IP_UNICAST_IF, local connection"
1536 run_cmd nettest -s -D &
1538 run_cmd nettest -D -d ${NSA_DEV} -S -r ${a} -U
1539 log_test_addr ${a} $? 0 "Global server, device client via IP_UNICAST_IF, local connection, with connect()"
1542 # IPv4 with device bind has really weird behavior - it overrides the
1543 # fib lookup, generates an rtable and tries to send the packet. This
1544 # causes failures for local traffic at different places
1545 for a in ${NSA_LO_IP} 127.0.0.1
1548 show_hint "Should fail since addresses on loopback are out of device scope"
1549 run_cmd nettest -D -s &
1551 run_cmd nettest -D -r ${a} -d ${NSA_DEV}
1552 log_test_addr ${a} $? 2 "Global server, device client, local connection"
1555 show_hint "Should fail since addresses on loopback are out of device scope"
1556 run_cmd nettest -D -s &
1558 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -C
1559 log_test_addr ${a} $? 1 "Global server, device send via cmsg, local connection"
1562 show_hint "Should fail since addresses on loopback are out of device scope"
1563 run_cmd nettest -D -s &
1565 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -S
1566 log_test_addr ${a} $? 1 "Global server, device client via IP_UNICAST_IF, local connection"
1569 show_hint "Should fail since addresses on loopback are out of device scope"
1570 run_cmd nettest -D -s &
1572 run_cmd nettest -D -r ${a} -d ${NSA_DEV} -S -U
1573 log_test_addr ${a} $? 1 "Global server, device client via IP_UNICAST_IF, local connection, with connect()"
1580 run_cmd nettest -D -s -I ${NSA_DEV} -3 ${NSA_DEV} &
1582 run_cmd nettest -D -d ${NSA_DEV} -r ${a} -0 ${a}
1583 log_test_addr ${a} $? 0 "Device server, device client, local conn"
1586 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1587 log_test_addr ${a} $? 2 "No server, device client, local conn"
1594 # disable global server
1595 log_subsection "Global server disabled"
1596 set_sysctl net.ipv4.udp_l3mdev_accept=0
1601 for a in ${NSA_IP} ${VRF_IP}
1604 show_hint "Fails because ingress is in a VRF and global server is disabled"
1605 run_cmd nettest -D -s &
1607 run_cmd_nsb nettest -D -r ${a}
1608 log_test_addr ${a} $? 1 "Global server"
1611 run_cmd nettest -D -I ${VRF} -s -3 ${NSA_DEV} &
1613 run_cmd_nsb nettest -D -r ${a}
1614 log_test_addr ${a} $? 0 "VRF server"
1617 run_cmd nettest -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
1619 run_cmd_nsb nettest -D -r ${a}
1620 log_test_addr ${a} $? 0 "Enslaved device server"
1623 show_hint "Should fail 'Connection refused' since there is no server"
1624 run_cmd_nsb nettest -D -r ${a}
1625 log_test_addr ${a} $? 1 "No server"
1628 show_hint "Should fail 'Connection refused' since global server is out of scope"
1629 run_cmd nettest -D -s &
1631 run_cmd nettest -D -d ${VRF} -r ${a}
1632 log_test_addr ${a} $? 1 "Global server, VRF client, local connection"
1637 run_cmd nettest -s -D -I ${VRF} -3 ${NSA_DEV} &
1639 run_cmd nettest -D -d ${VRF} -r ${a}
1640 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
1643 run_cmd nettest -s -D -I ${VRF} -3 ${NSA_DEV} &
1645 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1646 log_test_addr ${a} $? 0 "VRF server, enslaved device client, local connection"
1650 run_cmd nettest -s -D -I ${NSA_DEV} -3 ${NSA_DEV} &
1652 run_cmd nettest -D -d ${VRF} -r ${a}
1653 log_test_addr ${a} $? 0 "Enslaved device server, VRF client, local conn"
1656 run_cmd nettest -s -D -I ${NSA_DEV} -3 ${NSA_DEV} &
1658 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1659 log_test_addr ${a} $? 0 "Enslaved device server, device client, local conn"
1661 # enable global server
1662 log_subsection "Global server enabled"
1663 set_sysctl net.ipv4.udp_l3mdev_accept=1
1668 for a in ${NSA_IP} ${VRF_IP}
1671 run_cmd nettest -D -s -3 ${NSA_DEV} &
1673 run_cmd_nsb nettest -D -r ${a}
1674 log_test_addr ${a} $? 0 "Global server"
1677 run_cmd nettest -D -I ${VRF} -s -3 ${NSA_DEV} &
1679 run_cmd_nsb nettest -D -r ${a}
1680 log_test_addr ${a} $? 0 "VRF server"
1683 run_cmd nettest -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
1685 run_cmd_nsb nettest -D -r ${a}
1686 log_test_addr ${a} $? 0 "Enslaved device server"
1689 show_hint "Should fail 'Connection refused'"
1690 run_cmd_nsb nettest -D -r ${a}
1691 log_test_addr ${a} $? 1 "No server"
1698 run_cmd_nsb nettest -D -s &
1700 run_cmd nettest -d ${VRF} -D -r ${NSB_IP} -1 ${NSA_IP}
1701 log_test $? 0 "VRF client"
1704 run_cmd_nsb nettest -D -s &
1706 run_cmd nettest -d ${NSA_DEV} -D -r ${NSB_IP} -1 ${NSA_IP}
1707 log_test $? 0 "Enslaved device client"
1709 # negative test - should fail
1711 show_hint "Should fail 'Connection refused'"
1712 run_cmd nettest -D -d ${VRF} -r ${NSB_IP}
1713 log_test $? 1 "No server, VRF client"
1716 show_hint "Should fail 'Connection refused'"
1717 run_cmd nettest -D -d ${NSA_DEV} -r ${NSB_IP}
1718 log_test $? 1 "No server, enslaved device client"
1721 # local address tests
1725 run_cmd nettest -D -s -3 ${NSA_DEV} &
1727 run_cmd nettest -D -d ${VRF} -r ${a}
1728 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
1731 run_cmd nettest -s -D -I ${VRF} -3 ${NSA_DEV} &
1733 run_cmd nettest -D -d ${VRF} -r ${a}
1734 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
1737 run_cmd nettest -s -D -I ${VRF} -3 ${NSA_DEV} &
1739 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1740 log_test_addr ${a} $? 0 "VRF server, device client, local conn"
1743 run_cmd nettest -s -D -I ${NSA_DEV} -3 ${NSA_DEV} &
1745 run_cmd nettest -D -d ${VRF} -r ${a}
1746 log_test_addr ${a} $? 0 "Enslaved device server, VRF client, local conn"
1749 run_cmd nettest -s -D -I ${NSA_DEV} -3 ${NSA_DEV} &
1751 run_cmd nettest -D -d ${NSA_DEV} -r ${a}
1752 log_test_addr ${a} $? 0 "Enslaved device server, device client, local conn"
1754 for a in ${VRF_IP} 127.0.0.1
1757 run_cmd nettest -D -s -3 ${VRF} &
1759 run_cmd nettest -D -d ${VRF} -r ${a}
1760 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
1763 for a in ${VRF_IP} 127.0.0.1
1766 run_cmd nettest -s -D -I ${VRF} -3 ${VRF} &
1768 run_cmd nettest -D -d ${VRF} -r ${a}
1769 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
1772 # negative test - should fail
1773 # verifies ECONNREFUSED
1774 for a in ${NSA_IP} ${VRF_IP} 127.0.0.1
1777 show_hint "Should fail 'Connection refused'"
1778 run_cmd nettest -D -d ${VRF} -r ${a}
1779 log_test_addr ${a} $? 1 "No server, VRF client, local conn"
1785 log_section "IPv4/UDP"
1786 log_subsection "No VRF"
1790 # udp_l3mdev_accept should have no affect without VRF;
1791 # run tests with it enabled and disabled to verify
1792 log_subsection "udp_l3mdev_accept disabled"
1793 set_sysctl net.ipv4.udp_l3mdev_accept=0
1795 log_subsection "udp_l3mdev_accept enabled"
1796 set_sysctl net.ipv4.udp_l3mdev_accept=1
1799 log_subsection "With VRF"
1804 ################################################################################
1807 # verifies ability or inability to bind to an address / device
1809 ipv4_addr_bind_novrf()
1814 for a in ${NSA_IP} ${NSA_LO_IP}
1817 run_cmd nettest -s -R -P icmp -l ${a} -b
1818 log_test_addr ${a} $? 0 "Raw socket bind to local address"
1821 run_cmd nettest -s -R -P icmp -l ${a} -I ${NSA_DEV} -b
1822 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
1826 # tests for nonlocal bind
1830 run_cmd nettest -s -R -f -l ${a} -b
1831 log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address"
1834 run_cmd nettest -s -f -l ${a} -b
1835 log_test_addr ${a} $? 0 "TCP socket bind to nonlocal address"
1838 run_cmd nettest -s -D -P icmp -f -l ${a} -b
1839 log_test_addr ${a} $? 0 "ICMP socket bind to nonlocal address"
1842 # check that ICMP sockets cannot bind to broadcast and multicast addresses
1846 run_cmd nettest -s -D -P icmp -l ${a} -b
1847 log_test_addr ${a} $? 1 "ICMP socket bind to broadcast address"
1851 run_cmd nettest -s -D -P icmp -l ${a} -b
1852 log_test_addr ${a} $? 1 "ICMP socket bind to multicast address"
1859 run_cmd nettest -c ${a} -r ${NSB_IP} -t1 -b
1860 log_test_addr ${a} $? 0 "TCP socket bind to local address"
1863 run_cmd nettest -c ${a} -r ${NSB_IP} -d ${NSA_DEV} -t1 -b
1864 log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"
1866 # Sadly, the kernel allows binding a socket to a device and then
1867 # binding to an address not on the device. The only restriction
1868 # is that the address is valid in the L3 domain. So this test
1869 # passes when it really should not
1872 #show_hint "Should fail with 'Cannot assign requested address'"
1873 #run_cmd nettest -s -l ${a} -I ${NSA_DEV} -t1 -b
1874 #log_test_addr ${a} $? 1 "TCP socket bind to out of scope local address"
1877 ipv4_addr_bind_vrf()
1882 for a in ${NSA_IP} ${VRF_IP}
1885 show_hint "Socket not bound to VRF, but address is in VRF"
1886 run_cmd nettest -s -R -P icmp -l ${a} -b
1887 log_test_addr ${a} $? 1 "Raw socket bind to local address"
1890 run_cmd nettest -s -R -P icmp -l ${a} -I ${NSA_DEV} -b
1891 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
1893 run_cmd nettest -s -R -P icmp -l ${a} -I ${VRF} -b
1894 log_test_addr ${a} $? 0 "Raw socket bind to local address after VRF bind"
1899 show_hint "Address on loopback is out of VRF scope"
1900 run_cmd nettest -s -R -P icmp -l ${a} -I ${VRF} -b
1901 log_test_addr ${a} $? 1 "Raw socket bind to out of scope address after VRF bind"
1904 # tests for nonlocal bind
1908 run_cmd nettest -s -R -f -l ${a} -I ${VRF} -b
1909 log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address after VRF bind"
1912 run_cmd nettest -s -f -l ${a} -I ${VRF} -b
1913 log_test_addr ${a} $? 0 "TCP socket bind to nonlocal address after VRF bind"
1916 run_cmd nettest -s -D -P icmp -f -l ${a} -I ${VRF} -b
1917 log_test_addr ${a} $? 0 "ICMP socket bind to nonlocal address after VRF bind"
1920 # check that ICMP sockets cannot bind to broadcast and multicast addresses
1924 run_cmd nettest -s -D -P icmp -l ${a} -I ${VRF} -b
1925 log_test_addr ${a} $? 1 "ICMP socket bind to broadcast address after VRF bind"
1929 run_cmd nettest -s -D -P icmp -l ${a} -I ${VRF} -b
1930 log_test_addr ${a} $? 1 "ICMP socket bind to multicast address after VRF bind"
1935 for a in ${NSA_IP} ${VRF_IP}
1938 run_cmd nettest -s -l ${a} -I ${VRF} -t1 -b
1939 log_test_addr ${a} $? 0 "TCP socket bind to local address"
1942 run_cmd nettest -s -l ${a} -I ${NSA_DEV} -t1 -b
1943 log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"
1948 show_hint "Address on loopback out of scope for VRF"
1949 run_cmd nettest -s -l ${a} -I ${VRF} -t1 -b
1950 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for VRF"
1953 show_hint "Address on loopback out of scope for device in VRF"
1954 run_cmd nettest -s -l ${a} -I ${NSA_DEV} -t1 -b
1955 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for device bind"
1960 log_section "IPv4 address binds"
1962 log_subsection "No VRF"
1964 set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
1965 ipv4_addr_bind_novrf
1967 log_subsection "With VRF"
1969 set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
1973 ################################################################################
1974 # IPv4 runtime tests
1980 local with_vrf="yes"
1986 for a in ${NSA_IP} ${VRF_IP}
1989 run_cmd nettest ${varg} -s &
1991 run_cmd_nsb nettest ${varg} -r ${a} &
1993 run_cmd ip link del ${VRF}
1995 log_test_addr ${a} 0 0 "${desc}, global server"
2000 for a in ${NSA_IP} ${VRF_IP}
2003 run_cmd nettest ${varg} -s -I ${VRF} &
2005 run_cmd_nsb nettest ${varg} -r ${a} &
2007 run_cmd ip link del ${VRF}
2009 log_test_addr ${a} 0 0 "${desc}, VRF server"
2016 run_cmd nettest ${varg} -s -I ${NSA_DEV} &
2018 run_cmd_nsb nettest ${varg} -r ${a} &
2020 run_cmd ip link del ${VRF}
2022 log_test_addr ${a} 0 0 "${desc}, enslaved device server"
2030 run_cmd_nsb nettest ${varg} -s &
2032 run_cmd nettest ${varg} -d ${VRF} -r ${NSB_IP} &
2034 run_cmd ip link del ${VRF}
2036 log_test_addr ${a} 0 0 "${desc}, VRF client"
2041 run_cmd_nsb nettest ${varg} -s &
2043 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${NSB_IP} &
2045 run_cmd ip link del ${VRF}
2047 log_test_addr ${a} 0 0 "${desc}, enslaved device client"
2052 # local address tests
2054 for a in ${NSA_IP} ${VRF_IP}
2057 run_cmd nettest ${varg} -s &
2059 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
2061 run_cmd ip link del ${VRF}
2063 log_test_addr ${a} 0 0 "${desc}, global server, VRF client, local"
2068 for a in ${NSA_IP} ${VRF_IP}
2071 run_cmd nettest ${varg} -I ${VRF} -s &
2073 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
2075 run_cmd ip link del ${VRF}
2077 log_test_addr ${a} 0 0 "${desc}, VRF server and client, local"
2085 run_cmd nettest ${varg} -s &
2087 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
2089 run_cmd ip link del ${VRF}
2091 log_test_addr ${a} 0 0 "${desc}, global server, enslaved device client, local"
2096 run_cmd nettest ${varg} -I ${VRF} -s &
2098 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
2100 run_cmd ip link del ${VRF}
2102 log_test_addr ${a} 0 0 "${desc}, VRF server, enslaved device client, local"
2107 run_cmd nettest ${varg} -I ${NSA_DEV} -s &
2109 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
2111 run_cmd ip link del ${VRF}
2113 log_test_addr ${a} 0 0 "${desc}, enslaved device server and client, local"
2118 local with_vrf="yes"
2121 for a in ${NSA_IP} ${VRF_IP}
2124 run_cmd_nsb ping -f ${a} &
2126 run_cmd ip link del ${VRF}
2128 log_test_addr ${a} 0 0 "Device delete with active traffic - ping in"
2135 run_cmd ping -f -I ${VRF} ${a} &
2137 run_cmd ip link del ${VRF}
2139 log_test_addr ${a} 0 0 "Device delete with active traffic - ping out"
2144 log_section "Run time tests - ipv4"
2150 ipv4_rt "TCP active socket" "-n -1"
2153 ipv4_rt "TCP passive socket" "-i"
2156 ################################################################################
2163 # should not have an impact, but make a known state
2164 set_sysctl net.ipv4.raw_l3mdev_accept=0 2>/dev/null
2169 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2172 run_cmd ${ping6} -c1 -w1 ${a}
2173 log_test_addr ${a} $? 0 "ping out"
2176 for a in ${NSB_IP6} ${NSB_LO_IP6}
2179 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2180 log_test_addr ${a} $? 0 "ping out, device bind"
2183 run_cmd ${ping6} -c1 -w1 -I ${NSA_LO_IP6} ${a}
2184 log_test_addr ${a} $? 0 "ping out, loopback address bind"
2190 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV} ${MCAST}%${NSB_DEV}
2193 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2194 log_test_addr ${a} $? 0 "ping in"
2198 # local traffic, local address
2200 for a in ${NSA_IP6} ${NSA_LO_IP6} ::1 ${NSA_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2203 run_cmd ${ping6} -c1 -w1 ${a}
2204 log_test_addr ${a} $? 0 "ping local, no bind"
2207 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2210 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2211 log_test_addr ${a} $? 0 "ping local, device bind"
2214 for a in ${NSA_LO_IP6} ::1
2217 show_hint "Fails since address on loopback is out of device scope"
2218 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2219 log_test_addr ${a} $? 2 "ping local, device bind"
2223 # ip rule blocks address
2226 setup_cmd ip -6 rule add pref 32765 from all lookup local
2227 setup_cmd ip -6 rule del pref 0 from all lookup local
2228 setup_cmd ip -6 rule add pref 50 to ${NSB_LO_IP6} prohibit
2229 setup_cmd ip -6 rule add pref 51 from ${NSB_IP6} prohibit
2232 run_cmd ${ping6} -c1 -w1 ${a}
2233 log_test_addr ${a} $? 2 "ping out, blocked by rule"
2236 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2237 log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
2241 show_hint "Response lost due to ip rule"
2242 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2243 log_test_addr ${a} $? 1 "ping in, blocked by rule"
2245 setup_cmd ip -6 rule add pref 0 from all lookup local
2246 setup_cmd ip -6 rule del pref 32765 from all lookup local
2247 setup_cmd ip -6 rule del pref 50 to ${NSB_LO_IP6} prohibit
2248 setup_cmd ip -6 rule del pref 51 from ${NSB_IP6} prohibit
2251 # route blocks reachability to remote address
2254 setup_cmd ip -6 route del ${NSB_LO_IP6}
2255 setup_cmd ip -6 route add unreachable ${NSB_LO_IP6} metric 10
2256 setup_cmd ip -6 route add unreachable ${NSB_IP6} metric 10
2259 run_cmd ${ping6} -c1 -w1 ${a}
2260 log_test_addr ${a} $? 2 "ping out, blocked by route"
2263 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2264 log_test_addr ${a} $? 2 "ping out, device bind, blocked by route"
2268 show_hint "Response lost due to ip route"
2269 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2270 log_test_addr ${a} $? 1 "ping in, blocked by route"
2274 # remove 'remote' routes; fallback to default
2277 setup_cmd ip -6 ro del unreachable ${NSB_LO_IP6}
2278 setup_cmd ip -6 ro del unreachable ${NSB_IP6}
2281 run_cmd ${ping6} -c1 -w1 ${a}
2282 log_test_addr ${a} $? 2 "ping out, unreachable route"
2285 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2286 log_test_addr ${a} $? 2 "ping out, device bind, unreachable route"
2293 # should default on; does not exist on older kernels
2294 set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
2299 for a in ${NSB_IP6} ${NSB_LO_IP6}
2302 run_cmd ${ping6} -c1 -w1 -I ${VRF} ${a}
2303 log_test_addr ${a} $? 0 "ping out, VRF bind"
2306 for a in ${NSB_LINKIP6}%${VRF} ${MCAST}%${VRF}
2309 show_hint "Fails since VRF device does not support linklocal or multicast"
2310 run_cmd ${ping6} -c1 -w1 ${a}
2311 log_test_addr ${a} $? 1 "ping out, VRF bind"
2314 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2317 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2318 log_test_addr ${a} $? 0 "ping out, device bind"
2321 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2324 run_cmd ip vrf exec ${VRF} ${ping6} -c1 -w1 -I ${VRF_IP6} ${a}
2325 log_test_addr ${a} $? 0 "ping out, vrf device+address bind"
2331 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV} ${MCAST}%${NSB_DEV}
2334 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2335 log_test_addr ${a} $? 0 "ping in"
2340 show_hint "Fails since loopback address is out of VRF scope"
2341 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2342 log_test_addr ${a} $? 1 "ping in"
2345 # local traffic, local address
2347 for a in ${NSA_IP6} ${VRF_IP6} ::1
2350 show_hint "Source address should be ${a}"
2351 run_cmd ${ping6} -c1 -w1 -I ${VRF} ${a}
2352 log_test_addr ${a} $? 0 "ping local, VRF bind"
2355 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSA_DEV} ${MCAST}%${NSA_DEV}
2358 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2359 log_test_addr ${a} $? 0 "ping local, device bind"
2362 # LLA to GUA - remove ipv6 global addresses from ns-B
2363 setup_cmd_nsb ip -6 addr del ${NSB_IP6}/64 dev ${NSB_DEV}
2364 setup_cmd_nsb ip -6 addr del ${NSB_LO_IP6}/128 dev lo
2365 setup_cmd_nsb ip -6 ro add ${NSA_IP6}/128 via ${NSA_LINKIP6} dev ${NSB_DEV}
2367 for a in ${NSA_IP6} ${VRF_IP6}
2370 run_cmd_nsb ${ping6} -c1 -w1 ${NSA_IP6}
2371 log_test_addr ${a} $? 0 "ping in, LLA to GUA"
2374 setup_cmd_nsb ip -6 ro del ${NSA_IP6}/128 via ${NSA_LINKIP6} dev ${NSB_DEV}
2375 setup_cmd_nsb ip -6 addr add ${NSB_IP6}/64 dev ${NSB_DEV}
2376 setup_cmd_nsb ip -6 addr add ${NSB_LO_IP6}/128 dev lo
2379 # ip rule blocks address
2382 setup_cmd ip -6 rule add pref 50 to ${NSB_LO_IP6} prohibit
2383 setup_cmd ip -6 rule add pref 51 from ${NSB_IP6} prohibit
2386 run_cmd ${ping6} -c1 -w1 ${a}
2387 log_test_addr ${a} $? 2 "ping out, blocked by rule"
2390 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2391 log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
2395 show_hint "Response lost due to ip rule"
2396 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2397 log_test_addr ${a} $? 1 "ping in, blocked by rule"
2400 setup_cmd ip -6 rule del pref 50 to ${NSB_LO_IP6} prohibit
2401 setup_cmd ip -6 rule del pref 51 from ${NSB_IP6} prohibit
2404 # remove 'remote' routes; fallback to default
2407 setup_cmd ip -6 ro del ${NSB_LO_IP6} vrf ${VRF}
2410 run_cmd ${ping6} -c1 -w1 ${a}
2411 log_test_addr ${a} $? 2 "ping out, unreachable route"
2414 run_cmd ${ping6} -c1 -w1 -I ${NSA_DEV} ${a}
2415 log_test_addr ${a} $? 2 "ping out, device bind, unreachable route"
2417 ip -netns ${NSB} -6 ro del ${NSA_LO_IP6}
2420 run_cmd_nsb ${ping6} -c1 -w1 ${a}
2421 log_test_addr ${a} $? 2 "ping in, unreachable route"
2426 log_section "IPv6 ping"
2428 log_subsection "No VRF"
2432 set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
2435 log_subsection "With VRF"
2439 set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
2443 ################################################################################
2447 # MD5 tests without VRF
2449 ipv6_tcp_md5_novrf()
2457 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NSB_IP6} &
2459 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2460 log_test $? 0 "MD5: Single address config"
2462 # client sends MD5, server not configured
2464 show_hint "Should timeout due to MD5 mismatch"
2465 run_cmd nettest -6 -s &
2467 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2468 log_test $? 2 "MD5: Server no config, client uses password"
2472 show_hint "Should timeout since client uses wrong password"
2473 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NSB_IP6} &
2475 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2476 log_test $? 2 "MD5: Client uses wrong password"
2478 # client from different address
2480 show_hint "Should timeout due to MD5 mismatch"
2481 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NSB_LO_IP6} &
2483 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2484 log_test $? 2 "MD5: Client address does not match address configured with password"
2487 # MD5 extension - prefix length
2492 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
2494 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2495 log_test $? 0 "MD5: Prefix config"
2497 # client in prefix, wrong password
2499 show_hint "Should timeout since client uses wrong password"
2500 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
2502 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2503 log_test $? 2 "MD5: Prefix config, client uses wrong password"
2505 # client outside of prefix
2507 show_hint "Should timeout due to MD5 mismatch"
2508 run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
2510 run_cmd_nsb nettest -6 -c ${NSB_LO_IP6} -r ${NSA_IP6} -X ${MD5_PW}
2511 log_test $? 2 "MD5: Prefix config, client address not in configured prefix"
2515 # MD5 tests with VRF
2525 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP6} &
2527 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2528 log_test $? 0 "MD5: VRF: Single address config"
2530 # client sends MD5, server not configured
2532 show_hint "Should timeout since server does not have MD5 auth"
2533 run_cmd nettest -6 -s -I ${VRF} &
2535 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2536 log_test $? 2 "MD5: VRF: Server no config, client uses password"
2540 show_hint "Should timeout since client uses wrong password"
2541 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP6} &
2543 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2544 log_test $? 2 "MD5: VRF: Client uses wrong password"
2546 # client from different address
2548 show_hint "Should timeout since server config differs from client"
2549 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_LO_IP6} &
2551 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2552 log_test $? 2 "MD5: VRF: Client address does not match address configured with password"
2555 # MD5 extension - prefix length
2560 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2562 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2563 log_test $? 0 "MD5: VRF: Prefix config"
2565 # client in prefix, wrong password
2567 show_hint "Should timeout since client uses wrong password"
2568 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2570 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2571 log_test $? 2 "MD5: VRF: Prefix config, client uses wrong password"
2573 # client outside of prefix
2575 show_hint "Should timeout since client address is outside of prefix"
2576 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2578 run_cmd_nsb nettest -6 -c ${NSB_LO_IP6} -r ${NSA_IP6} -X ${MD5_PW}
2579 log_test $? 2 "MD5: VRF: Prefix config, client address not in configured prefix"
2582 # duplicate config between default VRF and a VRF
2586 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP6} &
2587 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NSB_IP6} &
2589 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2590 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF"
2593 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP6} &
2594 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NSB_IP6} &
2596 run_cmd_nsc nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2597 log_test $? 0 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF"
2600 show_hint "Should timeout since client in default VRF uses VRF password"
2601 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP6} &
2602 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NSB_IP6} &
2604 run_cmd_nsc nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2605 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in default VRF with VRF pw"
2608 show_hint "Should timeout since client in VRF uses default VRF password"
2609 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NSB_IP6} &
2610 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NSB_IP6} &
2612 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2613 log_test $? 2 "MD5: VRF: Single address config in default VRF and VRF, conn in VRF with default VRF pw"
2616 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2617 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2619 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2620 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF"
2623 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2624 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2626 run_cmd_nsc nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2627 log_test $? 0 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF"
2630 show_hint "Should timeout since client in default VRF uses VRF password"
2631 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2632 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2634 run_cmd_nsc nettest -6 -r ${NSA_IP6} -X ${MD5_PW}
2635 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in default VRF with VRF pw"
2638 show_hint "Should timeout since client in VRF uses default VRF password"
2639 run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
2640 run_cmd nettest -6 -s -M ${MD5_WRONG_PW} -m ${NS_NET6} &
2642 run_cmd_nsb nettest -6 -r ${NSA_IP6} -X ${MD5_WRONG_PW}
2643 log_test $? 2 "MD5: VRF: Prefix config in default VRF and VRF, conn in VRF with default VRF pw"
2649 run_cmd nettest -6 -s -I ${NSA_DEV} -M ${MD5_PW} -m ${NSB_IP6}
2650 log_test $? 1 "MD5: VRF: Device must be a VRF - single address"
2653 run_cmd nettest -6 -s -I ${NSA_DEV} -M ${MD5_PW} -m ${NS_NET6}
2654 log_test $? 1 "MD5: VRF: Device must be a VRF - prefix"
2665 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2668 run_cmd nettest -6 -s &
2670 run_cmd_nsb nettest -6 -r ${a}
2671 log_test_addr ${a} $? 0 "Global server"
2674 # verify TCP reset received
2675 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2678 show_hint "Should fail 'Connection refused'"
2679 run_cmd_nsb nettest -6 -r ${a}
2680 log_test_addr ${a} $? 1 "No server"
2686 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2689 run_cmd_nsb nettest -6 -s &
2691 run_cmd nettest -6 -r ${a}
2692 log_test_addr ${a} $? 0 "Client"
2695 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2698 run_cmd_nsb nettest -6 -s &
2700 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2701 log_test_addr ${a} $? 0 "Client, device bind"
2704 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
2707 show_hint "Should fail 'Connection refused'"
2708 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2709 log_test_addr ${a} $? 1 "No server, device client"
2713 # local address tests
2715 for a in ${NSA_IP6} ${NSA_LO_IP6} ::1
2718 run_cmd nettest -6 -s &
2720 run_cmd nettest -6 -r ${a}
2721 log_test_addr ${a} $? 0 "Global server, local connection"
2726 run_cmd nettest -6 -s -I ${NSA_DEV} -3 ${NSA_DEV} &
2728 run_cmd nettest -6 -r ${a} -0 ${a}
2729 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
2731 for a in ${NSA_LO_IP6} ::1
2734 show_hint "Should fail 'Connection refused' since addresses on loopback are out of device scope"
2735 run_cmd nettest -6 -s -I ${NSA_DEV} &
2737 run_cmd nettest -6 -r ${a}
2738 log_test_addr ${a} $? 1 "Device server, unbound client, local connection"
2743 run_cmd nettest -6 -s &
2745 run_cmd nettest -6 -r ${a} -d ${NSA_DEV} -0 ${a}
2746 log_test_addr ${a} $? 0 "Global server, device client, local connection"
2748 for a in ${NSA_LO_IP6} ::1
2751 show_hint "Should fail 'Connection refused' since addresses on loopback are out of device scope"
2752 run_cmd nettest -6 -s &
2754 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2755 log_test_addr ${a} $? 1 "Global server, device client, local connection"
2758 for a in ${NSA_IP6} ${NSA_LINKIP6}
2761 run_cmd nettest -6 -s -I ${NSA_DEV} -3 ${NSA_DEV} &
2763 run_cmd nettest -6 -d ${NSA_DEV} -r ${a}
2764 log_test_addr ${a} $? 0 "Device server, device client, local conn"
2767 for a in ${NSA_IP6} ${NSA_LINKIP6}
2770 show_hint "Should fail 'Connection refused'"
2771 run_cmd nettest -6 -d ${NSA_DEV} -r ${a}
2772 log_test_addr ${a} $? 1 "No server, device client, local conn"
2782 # disable global server
2783 log_subsection "Global server disabled"
2785 set_sysctl net.ipv4.tcp_l3mdev_accept=0
2790 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2793 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
2794 run_cmd nettest -6 -s &
2796 run_cmd_nsb nettest -6 -r ${a}
2797 log_test_addr ${a} $? 1 "Global server"
2800 for a in ${NSA_IP6} ${VRF_IP6}
2803 run_cmd nettest -6 -s -I ${VRF} -3 ${VRF} &
2805 run_cmd_nsb nettest -6 -r ${a}
2806 log_test_addr ${a} $? 0 "VRF server"
2809 # link local is always bound to ingress device
2810 a=${NSA_LINKIP6}%${NSB_DEV}
2812 run_cmd nettest -6 -s -I ${VRF} -3 ${NSA_DEV} &
2814 run_cmd_nsb nettest -6 -r ${a}
2815 log_test_addr ${a} $? 0 "VRF server"
2817 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2820 run_cmd nettest -6 -s -I ${NSA_DEV} -3 ${NSA_DEV} &
2822 run_cmd_nsb nettest -6 -r ${a}
2823 log_test_addr ${a} $? 0 "Device server"
2826 # verify TCP reset received
2827 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2830 show_hint "Should fail 'Connection refused'"
2831 run_cmd_nsb nettest -6 -r ${a}
2832 log_test_addr ${a} $? 1 "No server"
2835 # local address tests
2838 show_hint "Should fail 'Connection refused' since global server with VRF is disabled"
2839 run_cmd nettest -6 -s &
2841 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2842 log_test_addr ${a} $? 1 "Global server, local connection"
2850 # enable VRF global server
2852 log_subsection "VRF Global server enabled"
2853 set_sysctl net.ipv4.tcp_l3mdev_accept=1
2855 for a in ${NSA_IP6} ${VRF_IP6}
2858 run_cmd nettest -6 -s -3 ${VRF} &
2860 run_cmd_nsb nettest -6 -r ${a}
2861 log_test_addr ${a} $? 0 "Global server"
2864 for a in ${NSA_IP6} ${VRF_IP6}
2867 run_cmd nettest -6 -s -I ${VRF} -3 ${VRF} &
2869 run_cmd_nsb nettest -6 -r ${a}
2870 log_test_addr ${a} $? 0 "VRF server"
2873 # For LLA, child socket is bound to device
2874 a=${NSA_LINKIP6}%${NSB_DEV}
2876 run_cmd nettest -6 -s -3 ${NSA_DEV} &
2878 run_cmd_nsb nettest -6 -r ${a}
2879 log_test_addr ${a} $? 0 "Global server"
2882 run_cmd nettest -6 -s -I ${VRF} -3 ${NSA_DEV} &
2884 run_cmd_nsb nettest -6 -r ${a}
2885 log_test_addr ${a} $? 0 "VRF server"
2887 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2890 run_cmd nettest -6 -s -I ${NSA_DEV} -3 ${NSA_DEV} &
2892 run_cmd_nsb nettest -6 -r ${a}
2893 log_test_addr ${a} $? 0 "Device server"
2896 # verify TCP reset received
2897 for a in ${NSA_IP6} ${VRF_IP6} ${NSA_LINKIP6}%${NSB_DEV}
2900 show_hint "Should fail 'Connection refused'"
2901 run_cmd_nsb nettest -6 -r ${a}
2902 log_test_addr ${a} $? 1 "No server"
2905 # local address tests
2906 for a in ${NSA_IP6} ${VRF_IP6}
2909 show_hint "Fails 'Connection refused' since client is not in VRF"
2910 run_cmd nettest -6 -s -I ${VRF} &
2912 run_cmd nettest -6 -r ${a}
2913 log_test_addr ${a} $? 1 "Global server, local connection"
2920 for a in ${NSB_IP6} ${NSB_LO_IP6}
2923 run_cmd_nsb nettest -6 -s &
2925 run_cmd nettest -6 -r ${a} -d ${VRF}
2926 log_test_addr ${a} $? 0 "Client, VRF bind"
2931 show_hint "Fails since VRF device does not allow linklocal addresses"
2932 run_cmd_nsb nettest -6 -s &
2934 run_cmd nettest -6 -r ${a} -d ${VRF}
2935 log_test_addr ${a} $? 1 "Client, VRF bind"
2937 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}
2940 run_cmd_nsb nettest -6 -s &
2942 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2943 log_test_addr ${a} $? 0 "Client, device bind"
2946 for a in ${NSB_IP6} ${NSB_LO_IP6}
2949 show_hint "Should fail 'Connection refused'"
2950 run_cmd nettest -6 -r ${a} -d ${VRF}
2951 log_test_addr ${a} $? 1 "No server, VRF client"
2954 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}
2957 show_hint "Should fail 'Connection refused'"
2958 run_cmd nettest -6 -r ${a} -d ${NSA_DEV}
2959 log_test_addr ${a} $? 1 "No server, device client"
2962 for a in ${NSA_IP6} ${VRF_IP6} ::1
2965 run_cmd nettest -6 -s -I ${VRF} -3 ${VRF} &
2967 run_cmd nettest -6 -r ${a} -d ${VRF} -0 ${a}
2968 log_test_addr ${a} $? 0 "VRF server, VRF client, local connection"
2973 run_cmd nettest -6 -s -I ${VRF} -3 ${VRF} &
2975 run_cmd nettest -6 -r ${a} -d ${NSA_DEV} -0 ${a}
2976 log_test_addr ${a} $? 0 "VRF server, device client, local connection"
2980 show_hint "Should fail since unbound client is out of VRF scope"
2981 run_cmd nettest -6 -s -I ${VRF} &
2983 run_cmd nettest -6 -r ${a}
2984 log_test_addr ${a} $? 1 "VRF server, unbound client, local connection"
2987 run_cmd nettest -6 -s -I ${NSA_DEV} -3 ${NSA_DEV} &
2989 run_cmd nettest -6 -r ${a} -d ${VRF} -0 ${a}
2990 log_test_addr ${a} $? 0 "Device server, VRF client, local connection"
2992 for a in ${NSA_IP6} ${NSA_LINKIP6}
2995 run_cmd nettest -6 -s -I ${NSA_DEV} -3 ${NSA_DEV} &
2997 run_cmd nettest -6 -r ${a} -d ${NSA_DEV} -0 ${a}
2998 log_test_addr ${a} $? 0 "Device server, device client, local connection"
3004 log_section "IPv6/TCP"
3005 log_subsection "No VRF"
3008 # tcp_l3mdev_accept should have no affect without VRF;
3009 # run tests with it enabled and disabled to verify
3010 log_subsection "tcp_l3mdev_accept disabled"
3011 set_sysctl net.ipv4.tcp_l3mdev_accept=0
3013 log_subsection "tcp_l3mdev_accept enabled"
3014 set_sysctl net.ipv4.tcp_l3mdev_accept=1
3017 log_subsection "With VRF"
3022 ################################################################################
3032 for a in ${NSA_IP6} ${NSA_LINKIP6}%${NSB_DEV}
3035 run_cmd nettest -6 -D -s -3 ${NSA_DEV} &
3037 run_cmd_nsb nettest -6 -D -r ${a}
3038 log_test_addr ${a} $? 0 "Global server"
3041 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3043 run_cmd_nsb nettest -6 -D -r ${a}
3044 log_test_addr ${a} $? 0 "Device server"
3049 run_cmd nettest -6 -D -s -3 ${NSA_DEV} &
3051 run_cmd_nsb nettest -6 -D -r ${a}
3052 log_test_addr ${a} $? 0 "Global server"
3054 # should fail since loopback address is out of scope for a device
3055 # bound server, but it does not - hence this is more documenting
3058 #show_hint "Should fail since loopback address is out of scope"
3059 #run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3061 #run_cmd_nsb nettest -6 -D -r ${a}
3062 #log_test_addr ${a} $? 1 "Device server"
3064 # negative test - should fail
3065 for a in ${NSA_IP6} ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSB_DEV}
3068 show_hint "Should fail 'Connection refused' since there is no server"
3069 run_cmd_nsb nettest -6 -D -r ${a}
3070 log_test_addr ${a} $? 1 "No server"
3076 for a in ${NSB_IP6} ${NSB_LO_IP6} ${NSB_LINKIP6}%${NSA_DEV}
3079 run_cmd_nsb nettest -6 -D -s &
3081 run_cmd nettest -6 -D -r ${a} -0 ${NSA_IP6}
3082 log_test_addr ${a} $? 0 "Client"
3085 run_cmd_nsb nettest -6 -D -s &
3087 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -0 ${NSA_IP6}
3088 log_test_addr ${a} $? 0 "Client, device bind"
3091 run_cmd_nsb nettest -6 -D -s &
3093 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -C -0 ${NSA_IP6}
3094 log_test_addr ${a} $? 0 "Client, device send via cmsg"
3097 run_cmd_nsb nettest -6 -D -s &
3099 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -S -0 ${NSA_IP6}
3100 log_test_addr ${a} $? 0 "Client, device bind via IPV6_UNICAST_IF"
3103 show_hint "Should fail 'Connection refused'"
3104 run_cmd nettest -6 -D -r ${a}
3105 log_test_addr ${a} $? 1 "No server, unbound client"
3108 show_hint "Should fail 'Connection refused'"
3109 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV}
3110 log_test_addr ${a} $? 1 "No server, device client"
3114 # local address tests
3116 for a in ${NSA_IP6} ${NSA_LO_IP6} ::1
3119 run_cmd nettest -6 -D -s &
3121 run_cmd nettest -6 -D -r ${a} -0 ${a} -1 ${a}
3122 log_test_addr ${a} $? 0 "Global server, local connection"
3127 run_cmd nettest -6 -s -D -I ${NSA_DEV} -3 ${NSA_DEV} &
3129 run_cmd nettest -6 -D -r ${a}
3130 log_test_addr ${a} $? 0 "Device server, unbound client, local connection"
3132 for a in ${NSA_LO_IP6} ::1
3135 show_hint "Should fail 'Connection refused' since address is out of device scope"
3136 run_cmd nettest -6 -s -D -I ${NSA_DEV} &
3138 run_cmd nettest -6 -D -r ${a}
3139 log_test_addr ${a} $? 1 "Device server, local connection"
3144 run_cmd nettest -6 -s -D &
3146 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3147 log_test_addr ${a} $? 0 "Global server, device client, local connection"
3150 run_cmd nettest -6 -s -D &
3152 run_cmd nettest -6 -D -d ${NSA_DEV} -C -r ${a}
3153 log_test_addr ${a} $? 0 "Global server, device send via cmsg, local connection"
3156 run_cmd nettest -6 -s -D &
3158 run_cmd nettest -6 -D -d ${NSA_DEV} -S -r ${a}
3159 log_test_addr ${a} $? 0 "Global server, device client via IPV6_UNICAST_IF, local connection"
3161 for a in ${NSA_LO_IP6} ::1
3164 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
3165 run_cmd nettest -6 -D -s &
3167 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV}
3168 log_test_addr ${a} $? 1 "Global server, device client, local connection"
3171 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
3172 run_cmd nettest -6 -D -s &
3174 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -C
3175 log_test_addr ${a} $? 1 "Global server, device send via cmsg, local connection"
3178 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
3179 run_cmd nettest -6 -D -s &
3181 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -S
3182 log_test_addr ${a} $? 1 "Global server, device client via IP_UNICAST_IF, local connection"
3185 show_hint "Should fail 'No route to host' since addresses on loopback are out of device scope"
3186 run_cmd nettest -6 -D -s &
3188 run_cmd nettest -6 -D -r ${a} -d ${NSA_DEV} -S -U
3189 log_test_addr ${a} $? 1 "Global server, device client via IP_UNICAST_IF, local connection, with connect()"
3194 run_cmd nettest -6 -D -s -I ${NSA_DEV} -3 ${NSA_DEV} &
3196 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a} -0 ${a}
3197 log_test_addr ${a} $? 0 "Device server, device client, local conn"
3200 show_hint "Should fail 'Connection refused'"
3201 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3202 log_test_addr ${a} $? 1 "No server, device client, local conn"
3205 run_cmd_nsb ip -6 addr del ${NSB_IP6}/64 dev ${NSB_DEV}
3206 run_cmd_nsb ip -6 ro add ${NSA_IP6}/128 dev ${NSB_DEV}
3208 run_cmd nettest -6 -s -D &
3210 run_cmd_nsb nettest -6 -D -r ${NSA_IP6}
3211 log_test $? 0 "UDP in - LLA to GUA"
3213 run_cmd_nsb ip -6 ro del ${NSA_IP6}/128 dev ${NSB_DEV}
3214 run_cmd_nsb ip -6 addr add ${NSB_IP6}/64 dev ${NSB_DEV} nodad
3221 # disable global server
3222 log_subsection "Global server disabled"
3223 set_sysctl net.ipv4.udp_l3mdev_accept=0
3228 for a in ${NSA_IP6} ${VRF_IP6}
3231 show_hint "Should fail 'Connection refused' since global server is disabled"
3232 run_cmd nettest -6 -D -s &
3234 run_cmd_nsb nettest -6 -D -r ${a}
3235 log_test_addr ${a} $? 1 "Global server"
3238 for a in ${NSA_IP6} ${VRF_IP6}
3241 run_cmd nettest -6 -D -I ${VRF} -s -3 ${NSA_DEV} &
3243 run_cmd_nsb nettest -6 -D -r ${a}
3244 log_test_addr ${a} $? 0 "VRF server"
3247 for a in ${NSA_IP6} ${VRF_IP6}
3250 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3252 run_cmd_nsb nettest -6 -D -r ${a}
3253 log_test_addr ${a} $? 0 "Enslaved device server"
3256 # negative test - should fail
3257 for a in ${NSA_IP6} ${VRF_IP6}
3260 show_hint "Should fail 'Connection refused' since there is no server"
3261 run_cmd_nsb nettest -6 -D -r ${a}
3262 log_test_addr ${a} $? 1 "No server"
3266 # local address tests
3268 for a in ${NSA_IP6} ${VRF_IP6}
3271 show_hint "Should fail 'Connection refused' since global server is disabled"
3272 run_cmd nettest -6 -D -s &
3274 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3275 log_test_addr ${a} $? 1 "Global server, VRF client, local conn"
3278 for a in ${NSA_IP6} ${VRF_IP6}
3281 run_cmd nettest -6 -D -I ${VRF} -s &
3283 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3284 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
3289 show_hint "Should fail 'Connection refused' since global server is disabled"
3290 run_cmd nettest -6 -D -s &
3292 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3293 log_test_addr ${a} $? 1 "Global server, device client, local conn"
3296 run_cmd nettest -6 -D -I ${VRF} -s -3 ${NSA_DEV} &
3298 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3299 log_test_addr ${a} $? 0 "VRF server, device client, local conn"
3302 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3304 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3305 log_test_addr ${a} $? 0 "Enslaved device server, VRF client, local conn"
3308 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3310 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3311 log_test_addr ${a} $? 0 "Enslaved device server, device client, local conn"
3313 # disable global server
3314 log_subsection "Global server enabled"
3315 set_sysctl net.ipv4.udp_l3mdev_accept=1
3320 for a in ${NSA_IP6} ${VRF_IP6}
3323 run_cmd nettest -6 -D -s -3 ${NSA_DEV} &
3325 run_cmd_nsb nettest -6 -D -r ${a}
3326 log_test_addr ${a} $? 0 "Global server"
3329 for a in ${NSA_IP6} ${VRF_IP6}
3332 run_cmd nettest -6 -D -I ${VRF} -s -3 ${NSA_DEV} &
3334 run_cmd_nsb nettest -6 -D -r ${a}
3335 log_test_addr ${a} $? 0 "VRF server"
3338 for a in ${NSA_IP6} ${VRF_IP6}
3341 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3343 run_cmd_nsb nettest -6 -D -r ${a}
3344 log_test_addr ${a} $? 0 "Enslaved device server"
3347 # negative test - should fail
3348 for a in ${NSA_IP6} ${VRF_IP6}
3351 run_cmd_nsb nettest -6 -D -r ${a}
3352 log_test_addr ${a} $? 1 "No server"
3359 run_cmd_nsb nettest -6 -D -s &
3361 run_cmd nettest -6 -D -d ${VRF} -r ${NSB_IP6}
3362 log_test $? 0 "VRF client"
3364 # negative test - should fail
3366 run_cmd nettest -6 -D -d ${VRF} -r ${NSB_IP6}
3367 log_test $? 1 "No server, VRF client"
3370 run_cmd_nsb nettest -6 -D -s &
3372 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_IP6}
3373 log_test $? 0 "Enslaved device client"
3375 # negative test - should fail
3377 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_IP6}
3378 log_test $? 1 "No server, enslaved device client"
3381 # local address tests
3385 run_cmd nettest -6 -D -s -3 ${NSA_DEV} &
3387 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3388 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
3391 run_cmd nettest -6 -D -I ${VRF} -s -3 ${NSA_DEV} &
3393 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3394 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
3399 run_cmd nettest -6 -D -s -3 ${VRF} &
3401 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3402 log_test_addr ${a} $? 0 "Global server, VRF client, local conn"
3405 run_cmd nettest -6 -D -I ${VRF} -s -3 ${VRF} &
3407 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3408 log_test_addr ${a} $? 0 "VRF server, VRF client, local conn"
3410 # negative test - should fail
3411 for a in ${NSA_IP6} ${VRF_IP6}
3414 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3415 log_test_addr ${a} $? 1 "No server, VRF client, local conn"
3418 # device to global IP
3421 run_cmd nettest -6 -D -s -3 ${NSA_DEV} &
3423 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3424 log_test_addr ${a} $? 0 "Global server, device client, local conn"
3427 run_cmd nettest -6 -D -I ${VRF} -s -3 ${NSA_DEV} &
3429 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3430 log_test_addr ${a} $? 0 "VRF server, device client, local conn"
3433 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3435 run_cmd nettest -6 -D -d ${VRF} -r ${a}
3436 log_test_addr ${a} $? 0 "Device server, VRF client, local conn"
3439 run_cmd nettest -6 -D -I ${NSA_DEV} -s -3 ${NSA_DEV} &
3441 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3442 log_test_addr ${a} $? 0 "Device server, device client, local conn"
3445 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${a}
3446 log_test_addr ${a} $? 1 "No server, device client, local conn"
3449 # link local addresses
3451 run_cmd nettest -6 -D -s &
3453 run_cmd_nsb nettest -6 -D -d ${NSB_DEV} -r ${NSA_LINKIP6}
3454 log_test $? 0 "Global server, linklocal IP"
3457 run_cmd_nsb nettest -6 -D -d ${NSB_DEV} -r ${NSA_LINKIP6}
3458 log_test $? 1 "No server, linklocal IP"
3462 run_cmd_nsb nettest -6 -D -s &
3464 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_LINKIP6}
3465 log_test $? 0 "Enslaved device client, linklocal IP"
3468 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSB_LINKIP6}
3469 log_test $? 1 "No server, device client, peer linklocal IP"
3473 run_cmd nettest -6 -D -s &
3475 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSA_LINKIP6}
3476 log_test $? 0 "Enslaved device client, local conn - linklocal IP"
3479 run_cmd nettest -6 -D -d ${NSA_DEV} -r ${NSA_LINKIP6}
3480 log_test $? 1 "No server, device client, local conn - linklocal IP"
3483 run_cmd_nsb ip -6 addr del ${NSB_IP6}/64 dev ${NSB_DEV}
3484 run_cmd_nsb ip -6 ro add ${NSA_IP6}/128 dev ${NSB_DEV}
3486 run_cmd nettest -6 -s -D &
3488 run_cmd_nsb nettest -6 -D -r ${NSA_IP6}
3489 log_test $? 0 "UDP in - LLA to GUA"
3491 run_cmd_nsb ip -6 ro del ${NSA_IP6}/128 dev ${NSB_DEV}
3492 run_cmd_nsb ip -6 addr add ${NSB_IP6}/64 dev ${NSB_DEV} nodad
3497 # should not matter, but set to known state
3498 set_sysctl net.ipv4.udp_early_demux=1
3500 log_section "IPv6/UDP"
3501 log_subsection "No VRF"
3504 # udp_l3mdev_accept should have no affect without VRF;
3505 # run tests with it enabled and disabled to verify
3506 log_subsection "udp_l3mdev_accept disabled"
3507 set_sysctl net.ipv4.udp_l3mdev_accept=0
3509 log_subsection "udp_l3mdev_accept enabled"
3510 set_sysctl net.ipv4.udp_l3mdev_accept=1
3513 log_subsection "With VRF"
3518 ################################################################################
3521 ipv6_addr_bind_novrf()
3526 for a in ${NSA_IP6} ${NSA_LO_IP6}
3529 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -b
3530 log_test_addr ${a} $? 0 "Raw socket bind to local address"
3533 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -I ${NSA_DEV} -b
3534 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
3538 # raw socket with nonlocal bind
3542 run_cmd nettest -6 -s -R -P icmp -f -l ${a} -I ${NSA_DEV} -b
3543 log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address"
3550 run_cmd nettest -6 -s -l ${a} -t1 -b
3551 log_test_addr ${a} $? 0 "TCP socket bind to local address"
3554 run_cmd nettest -6 -s -l ${a} -I ${NSA_DEV} -t1 -b
3555 log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"
3557 # Sadly, the kernel allows binding a socket to a device and then
3558 # binding to an address not on the device. So this test passes
3559 # when it really should not
3562 show_hint "Tecnically should fail since address is not on device but kernel allows"
3563 run_cmd nettest -6 -s -l ${a} -I ${NSA_DEV} -t1 -b
3564 log_test_addr ${a} $? 0 "TCP socket bind to out of scope local address"
3567 ipv6_addr_bind_vrf()
3572 for a in ${NSA_IP6} ${VRF_IP6}
3575 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -I ${VRF} -b
3576 log_test_addr ${a} $? 0 "Raw socket bind to local address after vrf bind"
3579 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -I ${NSA_DEV} -b
3580 log_test_addr ${a} $? 0 "Raw socket bind to local address after device bind"
3585 show_hint "Address on loopback is out of VRF scope"
3586 run_cmd nettest -6 -s -R -P ipv6-icmp -l ${a} -I ${VRF} -b
3587 log_test_addr ${a} $? 1 "Raw socket bind to invalid local address after vrf bind"
3590 # raw socket with nonlocal bind
3594 run_cmd nettest -6 -s -R -P icmp -f -l ${a} -I ${VRF} -b
3595 log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address after VRF bind"
3600 # address on enslaved device is valid for the VRF or device in a VRF
3601 for a in ${NSA_IP6} ${VRF_IP6}
3604 run_cmd nettest -6 -s -l ${a} -I ${VRF} -t1 -b
3605 log_test_addr ${a} $? 0 "TCP socket bind to local address with VRF bind"
3610 run_cmd nettest -6 -s -l ${a} -I ${NSA_DEV} -t1 -b
3611 log_test_addr ${a} $? 0 "TCP socket bind to local address with device bind"
3613 # Sadly, the kernel allows binding a socket to a device and then
3614 # binding to an address not on the device. The only restriction
3615 # is that the address is valid in the L3 domain. So this test
3616 # passes when it really should not
3619 show_hint "Tecnically should fail since address is not on device but kernel allows"
3620 run_cmd nettest -6 -s -l ${a} -I ${NSA_DEV} -t1 -b
3621 log_test_addr ${a} $? 0 "TCP socket bind to VRF address with device bind"
3625 show_hint "Address on loopback out of scope for VRF"
3626 run_cmd nettest -6 -s -l ${a} -I ${VRF} -t1 -b
3627 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for VRF"
3630 show_hint "Address on loopback out of scope for device in VRF"
3631 run_cmd nettest -6 -s -l ${a} -I ${NSA_DEV} -t1 -b
3632 log_test_addr ${a} $? 1 "TCP socket bind to invalid local address for device bind"
3638 log_section "IPv6 address binds"
3640 log_subsection "No VRF"
3642 ipv6_addr_bind_novrf
3644 log_subsection "With VRF"
3649 ################################################################################
3650 # IPv6 runtime tests
3656 local with_vrf="yes"
3662 for a in ${NSA_IP6} ${VRF_IP6}
3665 run_cmd nettest ${varg} -s &
3667 run_cmd_nsb nettest ${varg} -r ${a} &
3669 run_cmd ip link del ${VRF}
3671 log_test_addr ${a} 0 0 "${desc}, global server"
3676 for a in ${NSA_IP6} ${VRF_IP6}
3679 run_cmd nettest ${varg} -I ${VRF} -s &
3681 run_cmd_nsb nettest ${varg} -r ${a} &
3683 run_cmd ip link del ${VRF}
3685 log_test_addr ${a} 0 0 "${desc}, VRF server"
3690 for a in ${NSA_IP6} ${VRF_IP6}
3693 run_cmd nettest ${varg} -I ${NSA_DEV} -s &
3695 run_cmd_nsb nettest ${varg} -r ${a} &
3697 run_cmd ip link del ${VRF}
3699 log_test_addr ${a} 0 0 "${desc}, enslaved device server"
3708 run_cmd_nsb nettest ${varg} -s &
3710 run_cmd nettest ${varg} -d ${VRF} -r ${NSB_IP6} &
3712 run_cmd ip link del ${VRF}
3714 log_test 0 0 "${desc}, VRF client"
3719 run_cmd_nsb nettest ${varg} -s &
3721 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${NSB_IP6} &
3723 run_cmd ip link del ${VRF}
3725 log_test 0 0 "${desc}, enslaved device client"
3731 # local address tests
3733 for a in ${NSA_IP6} ${VRF_IP6}
3736 run_cmd nettest ${varg} -s &
3738 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
3740 run_cmd ip link del ${VRF}
3742 log_test_addr ${a} 0 0 "${desc}, global server, VRF client"
3747 for a in ${NSA_IP6} ${VRF_IP6}
3750 run_cmd nettest ${varg} -I ${VRF} -s &
3752 run_cmd nettest ${varg} -d ${VRF} -r ${a} &
3754 run_cmd ip link del ${VRF}
3756 log_test_addr ${a} 0 0 "${desc}, VRF server and client"
3763 run_cmd nettest ${varg} -s &
3765 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
3767 run_cmd ip link del ${VRF}
3769 log_test_addr ${a} 0 0 "${desc}, global server, device client"
3774 run_cmd nettest ${varg} -I ${VRF} -s &
3776 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
3778 run_cmd ip link del ${VRF}
3780 log_test_addr ${a} 0 0 "${desc}, VRF server, device client"
3785 run_cmd nettest ${varg} -I ${NSA_DEV} -s &
3787 run_cmd nettest ${varg} -d ${NSA_DEV} -r ${a} &
3789 run_cmd ip link del ${VRF}
3791 log_test_addr ${a} 0 0 "${desc}, device server, device client"
3796 local with_vrf="yes"
3801 run_cmd_nsb ${ping6} -f ${a} &
3803 run_cmd ip link del ${VRF}
3805 log_test_addr ${a} 0 0 "Device delete with active traffic - ping in"
3810 run_cmd ${ping6} -f ${NSB_IP6} -I ${VRF} &
3812 run_cmd ip link del ${VRF}
3814 log_test_addr ${a} 0 0 "Device delete with active traffic - ping out"
3819 log_section "Run time tests - ipv6"
3825 ipv6_rt "TCP active socket" "-n -1"
3828 ipv6_rt "TCP passive socket" "-i"
3831 ipv6_rt "UDP active socket" "-D -n -1"
3834 ################################################################################
3835 # netfilter blocking connections
3837 netfilter_tcp_reset()
3841 for a in ${NSA_IP} ${VRF_IP}
3844 run_cmd nettest -s &
3846 run_cmd_nsb nettest -r ${a}
3847 log_test_addr ${a} $? 1 "Global server, reject with TCP-reset on Rx"
3857 [ "${stype}" = "UDP" ] && arg="-D"
3859 for a in ${NSA_IP} ${VRF_IP}
3862 run_cmd nettest ${arg} -s &
3864 run_cmd_nsb nettest ${arg} -r ${a}
3865 log_test_addr ${a} $? 1 "Global ${stype} server, Rx reject icmp-port-unreach"
3871 log_section "IPv4 Netfilter"
3872 log_subsection "TCP reset"
3875 run_cmd iptables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
3880 log_subsection "ICMP unreachable"
3884 run_cmd iptables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with icmp-port-unreachable
3885 run_cmd iptables -A INPUT -p udp --dport 12345 -j REJECT --reject-with icmp-port-unreachable
3887 netfilter_icmp "TCP"
3888 netfilter_icmp "UDP"
3894 netfilter_tcp6_reset()
3898 for a in ${NSA_IP6} ${VRF_IP6}
3901 run_cmd nettest -6 -s &
3903 run_cmd_nsb nettest -6 -r ${a}
3904 log_test_addr ${a} $? 1 "Global server, reject with TCP-reset on Rx"
3914 [ "${stype}" = "UDP" ] && arg="$arg -D"
3916 for a in ${NSA_IP6} ${VRF_IP6}
3919 run_cmd nettest -6 -s ${arg} &
3921 run_cmd_nsb nettest -6 ${arg} -r ${a}
3922 log_test_addr ${a} $? 1 "Global ${stype} server, Rx reject icmp-port-unreach"
3928 log_section "IPv6 Netfilter"
3929 log_subsection "TCP reset"
3932 run_cmd ip6tables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
3934 netfilter_tcp6_reset
3936 log_subsection "ICMP unreachable"
3939 run_cmd ip6tables -F
3940 run_cmd ip6tables -A INPUT -p tcp --dport 12345 -j REJECT --reject-with icmp6-port-unreachable
3941 run_cmd ip6tables -A INPUT -p udp --dport 12345 -j REJECT --reject-with icmp6-port-unreachable
3943 netfilter_icmp6 "TCP"
3944 netfilter_icmp6 "UDP"
3950 ################################################################################
3951 # specific use cases
3954 # ns-A device enslaved to bridge. Verify traffic with and without
3955 # br_netfilter module loaded. Repeat with SVI on bridge.
3960 setup_cmd ip link set ${NSA_DEV} down
3961 setup_cmd ip addr del dev ${NSA_DEV} ${NSA_IP}/24
3962 setup_cmd ip -6 addr del dev ${NSA_DEV} ${NSA_IP6}/64
3964 setup_cmd ip link add br0 type bridge
3965 setup_cmd ip addr add dev br0 ${NSA_IP}/24
3966 setup_cmd ip -6 addr add dev br0 ${NSA_IP6}/64 nodad
3968 setup_cmd ip li set ${NSA_DEV} master br0
3969 setup_cmd ip li set ${NSA_DEV} up
3970 setup_cmd ip li set br0 up
3971 setup_cmd ip li set br0 vrf ${VRF}
3973 rmmod br_netfilter 2>/dev/null
3976 run_cmd ip neigh flush all
3977 run_cmd ping -c1 -w1 -I br0 ${NSB_IP}
3978 log_test $? 0 "Bridge into VRF - IPv4 ping out"
3980 run_cmd ip neigh flush all
3981 run_cmd ${ping6} -c1 -w1 -I br0 ${NSB_IP6}
3982 log_test $? 0 "Bridge into VRF - IPv6 ping out"
3984 run_cmd ip neigh flush all
3985 run_cmd_nsb ping -c1 -w1 ${NSA_IP}
3986 log_test $? 0 "Bridge into VRF - IPv4 ping in"
3988 run_cmd ip neigh flush all
3989 run_cmd_nsb ${ping6} -c1 -w1 ${NSA_IP6}
3990 log_test $? 0 "Bridge into VRF - IPv6 ping in"
3992 modprobe br_netfilter
3993 if [ $? -eq 0 ]; then
3994 run_cmd ip neigh flush all
3995 run_cmd ping -c1 -w1 -I br0 ${NSB_IP}
3996 log_test $? 0 "Bridge into VRF with br_netfilter - IPv4 ping out"
3998 run_cmd ip neigh flush all
3999 run_cmd ${ping6} -c1 -w1 -I br0 ${NSB_IP6}
4000 log_test $? 0 "Bridge into VRF with br_netfilter - IPv6 ping out"
4002 run_cmd ip neigh flush all
4003 run_cmd_nsb ping -c1 -w1 ${NSA_IP}
4004 log_test $? 0 "Bridge into VRF with br_netfilter - IPv4 ping in"
4006 run_cmd ip neigh flush all
4007 run_cmd_nsb ${ping6} -c1 -w1 ${NSA_IP6}
4008 log_test $? 0 "Bridge into VRF with br_netfilter - IPv6 ping in"
4011 setup_cmd ip li set br0 nomaster
4012 setup_cmd ip li add br0.100 link br0 type vlan id 100
4013 setup_cmd ip li set br0.100 vrf ${VRF} up
4014 setup_cmd ip addr add dev br0.100 172.16.101.1/24
4015 setup_cmd ip -6 addr add dev br0.100 2001:db8:101::1/64 nodad
4017 setup_cmd_nsb ip li add vlan100 link ${NSB_DEV} type vlan id 100
4018 setup_cmd_nsb ip addr add dev vlan100 172.16.101.2/24
4019 setup_cmd_nsb ip -6 addr add dev vlan100 2001:db8:101::2/64 nodad
4020 setup_cmd_nsb ip li set vlan100 up
4023 rmmod br_netfilter 2>/dev/null
4025 run_cmd ip neigh flush all
4026 run_cmd ping -c1 -w1 -I br0.100 172.16.101.2
4027 log_test $? 0 "Bridge vlan into VRF - IPv4 ping out"
4029 run_cmd ip neigh flush all
4030 run_cmd ${ping6} -c1 -w1 -I br0.100 2001:db8:101::2
4031 log_test $? 0 "Bridge vlan into VRF - IPv6 ping out"
4033 run_cmd ip neigh flush all
4034 run_cmd_nsb ping -c1 -w1 172.16.101.1
4035 log_test $? 0 "Bridge vlan into VRF - IPv4 ping in"
4037 run_cmd ip neigh flush all
4038 run_cmd_nsb ${ping6} -c1 -w1 2001:db8:101::1
4039 log_test $? 0 "Bridge vlan into VRF - IPv6 ping in"
4041 modprobe br_netfilter
4042 if [ $? -eq 0 ]; then
4043 run_cmd ip neigh flush all
4044 run_cmd ping -c1 -w1 -I br0.100 172.16.101.2
4045 log_test $? 0 "Bridge vlan into VRF with br_netfilter - IPv4 ping out"
4047 run_cmd ip neigh flush all
4048 run_cmd ${ping6} -c1 -w1 -I br0.100 2001:db8:101::2
4049 log_test $? 0 "Bridge vlan into VRF with br_netfilter - IPv6 ping out"
4051 run_cmd ip neigh flush all
4052 run_cmd_nsb ping -c1 -w1 172.16.101.1
4053 log_test $? 0 "Bridge vlan into VRF - IPv4 ping in"
4055 run_cmd ip neigh flush all
4056 run_cmd_nsb ${ping6} -c1 -w1 2001:db8:101::1
4057 log_test $? 0 "Bridge vlan into VRF - IPv6 ping in"
4060 setup_cmd ip li del br0 2>/dev/null
4061 setup_cmd_nsb ip li del vlan100 2>/dev/null
4065 # ns-A device is connected to both ns-B and ns-C on a single VRF but only has
4066 # LLA on the interfaces
4067 use_case_ping_lla_multi()
4070 # only want reply from ns-A
4071 setup_cmd_nsb sysctl -qw net.ipv6.icmp.echo_ignore_multicast=1
4072 setup_cmd_nsc sysctl -qw net.ipv6.icmp.echo_ignore_multicast=1
4075 run_cmd_nsb ping -c1 -w1 ${MCAST}%${NSB_DEV}
4076 log_test_addr ${MCAST}%${NSB_DEV} $? 0 "Pre cycle, ping out ns-B"
4078 run_cmd_nsc ping -c1 -w1 ${MCAST}%${NSC_DEV}
4079 log_test_addr ${MCAST}%${NSC_DEV} $? 0 "Pre cycle, ping out ns-C"
4081 # cycle/flap the first ns-A interface
4082 setup_cmd ip link set ${NSA_DEV} down
4083 setup_cmd ip link set ${NSA_DEV} up
4087 run_cmd_nsb ping -c1 -w1 ${MCAST}%${NSB_DEV}
4088 log_test_addr ${MCAST}%${NSB_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV}, ping out ns-B"
4089 run_cmd_nsc ping -c1 -w1 ${MCAST}%${NSC_DEV}
4090 log_test_addr ${MCAST}%${NSC_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV}, ping out ns-C"
4092 # cycle/flap the second ns-A interface
4093 setup_cmd ip link set ${NSA_DEV2} down
4094 setup_cmd ip link set ${NSA_DEV2} up
4098 run_cmd_nsb ping -c1 -w1 ${MCAST}%${NSB_DEV}
4099 log_test_addr ${MCAST}%${NSB_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV2}, ping out ns-B"
4100 run_cmd_nsc ping -c1 -w1 ${MCAST}%${NSC_DEV}
4101 log_test_addr ${MCAST}%${NSC_DEV} $? 0 "Post cycle ${NSA} ${NSA_DEV2}, ping out ns-C"
4104 # Perform IPv{4,6} SNAT on ns-A, and verify TCP connection is successfully
4105 # established with ns-B.
4106 use_case_snat_on_vrf()
4112 run_cmd iptables -t nat -A POSTROUTING -p tcp -m tcp --dport ${port} -j SNAT --to-source ${NSA_LO_IP} -o ${VRF}
4113 run_cmd ip6tables -t nat -A POSTROUTING -p tcp -m tcp --dport ${port} -j SNAT --to-source ${NSA_LO_IP6} -o ${VRF}
4115 run_cmd_nsb nettest -s -l ${NSB_IP} -p ${port} &
4117 run_cmd nettest -d ${VRF} -r ${NSB_IP} -p ${port}
4118 log_test $? 0 "IPv4 TCP connection over VRF with SNAT"
4120 run_cmd_nsb nettest -6 -s -l ${NSB_IP6} -p ${port} &
4122 run_cmd nettest -6 -d ${VRF} -r ${NSB_IP6} -p ${port}
4123 log_test $? 0 "IPv6 TCP connection over VRF with SNAT"
4126 run_cmd iptables -t nat -D POSTROUTING -p tcp -m tcp --dport ${port} -j SNAT --to-source ${NSA_LO_IP} -o ${VRF}
4127 run_cmd ip6tables -t nat -D POSTROUTING -p tcp -m tcp --dport ${port} -j SNAT --to-source ${NSA_LO_IP6} -o ${VRF}
4132 log_section "Use cases"
4133 log_subsection "Device enslaved to bridge"
4135 log_subsection "Ping LLA with multiple interfaces"
4136 use_case_ping_lla_multi
4137 log_subsection "SNAT on VRF"
4138 use_case_snat_on_vrf
4141 ################################################################################
4147 usage: ${0##*/} OPTS
4151 -t <test> Test name/set to run
4153 -P Pause after each test
4157 $TESTS_IPV4 $TESTS_IPV6 $TESTS_OTHER
4161 ################################################################################
4164 TESTS_IPV4="ipv4_ping ipv4_tcp ipv4_udp ipv4_bind ipv4_runtime ipv4_netfilter"
4165 TESTS_IPV6="ipv6_ping ipv6_tcp ipv6_udp ipv6_bind ipv6_runtime ipv6_netfilter"
4166 TESTS_OTHER="use_cases"
4171 while getopts :46t:pPvh o
4177 p) PAUSE_ON_FAIL=yes;;
4185 # make sure we don't pause twice
4186 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
4189 # show user test config
4191 if [ -z "$TESTS" ]; then
4192 TESTS="$TESTS_IPV4 $TESTS_IPV6 $TESTS_OTHER"
4193 elif [ "$TESTS" = "ipv4" ]; then
4195 elif [ "$TESTS" = "ipv6" ]; then
4199 # nettest can be run from PATH or from same directory as this selftest
4200 if ! which nettest >/dev/null; then
4202 if ! which nettest >/dev/null; then
4203 echo "'nettest' command not found; skipping tests"
4209 declare -i nsuccess=0
4214 ipv4_ping|ping) ipv4_ping;;
4215 ipv4_tcp|tcp) ipv4_tcp;;
4216 ipv4_udp|udp) ipv4_udp;;
4217 ipv4_bind|bind) ipv4_addr_bind;;
4218 ipv4_runtime) ipv4_runtime;;
4219 ipv4_netfilter) ipv4_netfilter;;
4221 ipv6_ping|ping6) ipv6_ping;;
4222 ipv6_tcp|tcp6) ipv6_tcp;;
4223 ipv6_udp|udp6) ipv6_udp;;
4224 ipv6_bind|bind6) ipv6_addr_bind;;
4225 ipv6_runtime) ipv6_runtime;;
4226 ipv6_netfilter) ipv6_netfilter;;
4228 use_cases) use_cases;;
4230 # setup namespaces and config, but do not run any tests
4231 setup) setup; exit 0;;
4232 vrf_setup) setup "yes"; exit 0;;
4238 printf "\nTests passed: %3d\n" ${nsuccess}
4239 printf "Tests failed: %3d\n" ${nfail}
4241 if [ $nfail -ne 0 ]; then
4243 elif [ $nsuccess -eq 0 ]; then