1*a61bd7b9SXin Long#!/bin/bash 2*a61bd7b9SXin Long# SPDX-License-Identifier: GPL-2.0 3*a61bd7b9SXin Long# 4*a61bd7b9SXin Long# Testing For SCTP VRF. 5*a61bd7b9SXin Long# TOPO: CLIENT_NS1 (veth1) <---> (veth1) -> vrf_s1 6*a61bd7b9SXin Long# SERVER_NS 7*a61bd7b9SXin Long# CLIENT_NS2 (veth1) <---> (veth2) -> vrf_s2 8*a61bd7b9SXin Long 9*a61bd7b9SXin LongCLIENT_NS1="client-ns1" 10*a61bd7b9SXin LongCLIENT_NS2="client-ns2" 11*a61bd7b9SXin LongCLIENT_IP4="10.0.0.1" 12*a61bd7b9SXin LongCLIENT_IP6="2000::1" 13*a61bd7b9SXin LongCLIENT_PORT=1234 14*a61bd7b9SXin Long 15*a61bd7b9SXin LongSERVER_NS="server-ns" 16*a61bd7b9SXin LongSERVER_IP4="10.0.0.2" 17*a61bd7b9SXin LongSERVER_IP6="2000::2" 18*a61bd7b9SXin LongSERVER_PORT=1234 19*a61bd7b9SXin Long 20*a61bd7b9SXin Longsetup() { 21*a61bd7b9SXin Long modprobe sctp 22*a61bd7b9SXin Long modprobe sctp_diag 23*a61bd7b9SXin Long ip netns add $CLIENT_NS1 24*a61bd7b9SXin Long ip netns add $CLIENT_NS2 25*a61bd7b9SXin Long ip netns add $SERVER_NS 26*a61bd7b9SXin Long 27*a61bd7b9SXin Long ip net exec $CLIENT_NS1 sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null 28*a61bd7b9SXin Long ip net exec $CLIENT_NS2 sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null 29*a61bd7b9SXin Long ip net exec $SERVER_NS sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null 30*a61bd7b9SXin Long 31*a61bd7b9SXin Long ip -n $SERVER_NS link add veth1 type veth peer name veth1 netns $CLIENT_NS1 32*a61bd7b9SXin Long ip -n $SERVER_NS link add veth2 type veth peer name veth1 netns $CLIENT_NS2 33*a61bd7b9SXin Long 34*a61bd7b9SXin Long ip -n $CLIENT_NS1 link set veth1 up 35*a61bd7b9SXin Long ip -n $CLIENT_NS1 addr add $CLIENT_IP4/24 dev veth1 36*a61bd7b9SXin Long ip -n $CLIENT_NS1 addr add $CLIENT_IP6/24 dev veth1 37*a61bd7b9SXin Long 38*a61bd7b9SXin Long ip -n $CLIENT_NS2 link set veth1 up 39*a61bd7b9SXin Long ip -n $CLIENT_NS2 addr add $CLIENT_IP4/24 dev veth1 40*a61bd7b9SXin Long ip -n $CLIENT_NS2 addr add $CLIENT_IP6/24 dev veth1 41*a61bd7b9SXin Long 42*a61bd7b9SXin Long ip -n $SERVER_NS link add dummy1 type dummy 43*a61bd7b9SXin Long ip -n $SERVER_NS link set dummy1 up 44*a61bd7b9SXin Long ip -n $SERVER_NS link add vrf-1 type vrf table 10 45*a61bd7b9SXin Long ip -n $SERVER_NS link add vrf-2 type vrf table 20 46*a61bd7b9SXin Long ip -n $SERVER_NS link set vrf-1 up 47*a61bd7b9SXin Long ip -n $SERVER_NS link set vrf-2 up 48*a61bd7b9SXin Long ip -n $SERVER_NS link set veth1 master vrf-1 49*a61bd7b9SXin Long ip -n $SERVER_NS link set veth2 master vrf-2 50*a61bd7b9SXin Long 51*a61bd7b9SXin Long ip -n $SERVER_NS addr add $SERVER_IP4/24 dev dummy1 52*a61bd7b9SXin Long ip -n $SERVER_NS addr add $SERVER_IP4/24 dev veth1 53*a61bd7b9SXin Long ip -n $SERVER_NS addr add $SERVER_IP4/24 dev veth2 54*a61bd7b9SXin Long ip -n $SERVER_NS addr add $SERVER_IP6/24 dev dummy1 55*a61bd7b9SXin Long ip -n $SERVER_NS addr add $SERVER_IP6/24 dev veth1 56*a61bd7b9SXin Long ip -n $SERVER_NS addr add $SERVER_IP6/24 dev veth2 57*a61bd7b9SXin Long 58*a61bd7b9SXin Long ip -n $SERVER_NS link set veth1 up 59*a61bd7b9SXin Long ip -n $SERVER_NS link set veth2 up 60*a61bd7b9SXin Long ip -n $SERVER_NS route add table 10 $CLIENT_IP4 dev veth1 src $SERVER_IP4 61*a61bd7b9SXin Long ip -n $SERVER_NS route add table 20 $CLIENT_IP4 dev veth2 src $SERVER_IP4 62*a61bd7b9SXin Long ip -n $SERVER_NS route add $CLIENT_IP4 dev veth1 src $SERVER_IP4 63*a61bd7b9SXin Long ip -n $SERVER_NS route add table 10 $CLIENT_IP6 dev veth1 src $SERVER_IP6 64*a61bd7b9SXin Long ip -n $SERVER_NS route add table 20 $CLIENT_IP6 dev veth2 src $SERVER_IP6 65*a61bd7b9SXin Long ip -n $SERVER_NS route add $CLIENT_IP6 dev veth1 src $SERVER_IP6 66*a61bd7b9SXin Long} 67*a61bd7b9SXin Long 68*a61bd7b9SXin Longcleanup() { 69*a61bd7b9SXin Long ip netns exec $SERVER_NS pkill sctp_hello 2>&1 >/dev/null 70*a61bd7b9SXin Long ip netns del "$CLIENT_NS1" 71*a61bd7b9SXin Long ip netns del "$CLIENT_NS2" 72*a61bd7b9SXin Long ip netns del "$SERVER_NS" 73*a61bd7b9SXin Long} 74*a61bd7b9SXin Long 75*a61bd7b9SXin Longwait_server() { 76*a61bd7b9SXin Long local IFACE=$1 77*a61bd7b9SXin Long local CNT=0 78*a61bd7b9SXin Long 79*a61bd7b9SXin Long until ip netns exec $SERVER_NS ss -lS src $SERVER_IP:$SERVER_PORT | \ 80*a61bd7b9SXin Long grep LISTEN | grep "$IFACE" 2>&1 >/dev/null; do 81*a61bd7b9SXin Long [ $((CNT++)) = "20" ] && { RET=3; return $RET; } 82*a61bd7b9SXin Long sleep 0.1 83*a61bd7b9SXin Long done 84*a61bd7b9SXin Long} 85*a61bd7b9SXin Long 86*a61bd7b9SXin Longdo_test() { 87*a61bd7b9SXin Long local CLIENT_NS=$1 88*a61bd7b9SXin Long local IFACE=$2 89*a61bd7b9SXin Long 90*a61bd7b9SXin Long ip netns exec $SERVER_NS pkill sctp_hello 2>&1 >/dev/null 91*a61bd7b9SXin Long ip netns exec $SERVER_NS ./sctp_hello server $AF $SERVER_IP \ 92*a61bd7b9SXin Long $SERVER_PORT $IFACE 2>&1 >/dev/null & 93*a61bd7b9SXin Long disown 94*a61bd7b9SXin Long wait_server $IFACE || return $RET 95*a61bd7b9SXin Long timeout 3 ip netns exec $CLIENT_NS ./sctp_hello client $AF \ 96*a61bd7b9SXin Long $SERVER_IP $SERVER_PORT $CLIENT_IP $CLIENT_PORT 2>&1 >/dev/null 97*a61bd7b9SXin Long RET=$? 98*a61bd7b9SXin Long return $RET 99*a61bd7b9SXin Long} 100*a61bd7b9SXin Long 101*a61bd7b9SXin Longdo_testx() { 102*a61bd7b9SXin Long local IFACE1=$1 103*a61bd7b9SXin Long local IFACE2=$2 104*a61bd7b9SXin Long 105*a61bd7b9SXin Long ip netns exec $SERVER_NS pkill sctp_hello 2>&1 >/dev/null 106*a61bd7b9SXin Long ip netns exec $SERVER_NS ./sctp_hello server $AF $SERVER_IP \ 107*a61bd7b9SXin Long $SERVER_PORT $IFACE1 2>&1 >/dev/null & 108*a61bd7b9SXin Long disown 109*a61bd7b9SXin Long wait_server $IFACE1 || return $RET 110*a61bd7b9SXin Long ip netns exec $SERVER_NS ./sctp_hello server $AF $SERVER_IP \ 111*a61bd7b9SXin Long $SERVER_PORT $IFACE2 2>&1 >/dev/null & 112*a61bd7b9SXin Long disown 113*a61bd7b9SXin Long wait_server $IFACE2 || return $RET 114*a61bd7b9SXin Long timeout 3 ip netns exec $CLIENT_NS1 ./sctp_hello client $AF \ 115*a61bd7b9SXin Long $SERVER_IP $SERVER_PORT $CLIENT_IP $CLIENT_PORT 2>&1 >/dev/null && \ 116*a61bd7b9SXin Long timeout 3 ip netns exec $CLIENT_NS2 ./sctp_hello client $AF \ 117*a61bd7b9SXin Long $SERVER_IP $SERVER_PORT $CLIENT_IP $CLIENT_PORT 2>&1 >/dev/null 118*a61bd7b9SXin Long RET=$? 119*a61bd7b9SXin Long return $RET 120*a61bd7b9SXin Long} 121*a61bd7b9SXin Long 122*a61bd7b9SXin Longtestup() { 123*a61bd7b9SXin Long ip netns exec $SERVER_NS sysctl -w net.sctp.l3mdev_accept=1 2>&1 >/dev/null 124*a61bd7b9SXin Long echo -n "TEST 01: nobind, connect from client 1, l3mdev_accept=1, Y " 125*a61bd7b9SXin Long do_test $CLIENT_NS1 || { echo "[FAIL]"; return $RET; } 126*a61bd7b9SXin Long echo "[PASS]" 127*a61bd7b9SXin Long 128*a61bd7b9SXin Long echo -n "TEST 02: nobind, connect from client 2, l3mdev_accept=1, N " 129*a61bd7b9SXin Long do_test $CLIENT_NS2 && { echo "[FAIL]"; return $RET; } 130*a61bd7b9SXin Long echo "[PASS]" 131*a61bd7b9SXin Long 132*a61bd7b9SXin Long ip netns exec $SERVER_NS sysctl -w net.sctp.l3mdev_accept=0 2>&1 >/dev/null 133*a61bd7b9SXin Long echo -n "TEST 03: nobind, connect from client 1, l3mdev_accept=0, N " 134*a61bd7b9SXin Long do_test $CLIENT_NS1 && { echo "[FAIL]"; return $RET; } 135*a61bd7b9SXin Long echo "[PASS]" 136*a61bd7b9SXin Long 137*a61bd7b9SXin Long echo -n "TEST 04: nobind, connect from client 2, l3mdev_accept=0, N " 138*a61bd7b9SXin Long do_test $CLIENT_NS2 && { echo "[FAIL]"; return $RET; } 139*a61bd7b9SXin Long echo "[PASS]" 140*a61bd7b9SXin Long 141*a61bd7b9SXin Long echo -n "TEST 05: bind veth2 in server, connect from client 1, N " 142*a61bd7b9SXin Long do_test $CLIENT_NS1 veth2 && { echo "[FAIL]"; return $RET; } 143*a61bd7b9SXin Long echo "[PASS]" 144*a61bd7b9SXin Long 145*a61bd7b9SXin Long echo -n "TEST 06: bind veth1 in server, connect from client 1, Y " 146*a61bd7b9SXin Long do_test $CLIENT_NS1 veth1 || { echo "[FAIL]"; return $RET; } 147*a61bd7b9SXin Long echo "[PASS]" 148*a61bd7b9SXin Long 149*a61bd7b9SXin Long echo -n "TEST 07: bind vrf-1 in server, connect from client 1, Y " 150*a61bd7b9SXin Long do_test $CLIENT_NS1 vrf-1 || { echo "[FAIL]"; return $RET; } 151*a61bd7b9SXin Long echo "[PASS]" 152*a61bd7b9SXin Long 153*a61bd7b9SXin Long echo -n "TEST 08: bind vrf-2 in server, connect from client 1, N " 154*a61bd7b9SXin Long do_test $CLIENT_NS1 vrf-2 && { echo "[FAIL]"; return $RET; } 155*a61bd7b9SXin Long echo "[PASS]" 156*a61bd7b9SXin Long 157*a61bd7b9SXin Long echo -n "TEST 09: bind vrf-2 in server, connect from client 2, Y " 158*a61bd7b9SXin Long do_test $CLIENT_NS2 vrf-2 || { echo "[FAIL]"; return $RET; } 159*a61bd7b9SXin Long echo "[PASS]" 160*a61bd7b9SXin Long 161*a61bd7b9SXin Long echo -n "TEST 10: bind vrf-1 in server, connect from client 2, N " 162*a61bd7b9SXin Long do_test $CLIENT_NS2 vrf-1 && { echo "[FAIL]"; return $RET; } 163*a61bd7b9SXin Long echo "[PASS]" 164*a61bd7b9SXin Long 165*a61bd7b9SXin Long echo -n "TEST 11: bind vrf-1 & 2 in server, connect from client 1 & 2, Y " 166*a61bd7b9SXin Long do_testx vrf-1 vrf-2 || { echo "[FAIL]"; return $RET; } 167*a61bd7b9SXin Long echo "[PASS]" 168*a61bd7b9SXin Long 169*a61bd7b9SXin Long echo -n "TEST 12: bind vrf-2 & 1 in server, connect from client 1 & 2, N " 170*a61bd7b9SXin Long do_testx vrf-2 vrf-1 || { echo "[FAIL]"; return $RET; } 171*a61bd7b9SXin Long echo "[PASS]" 172*a61bd7b9SXin Long} 173*a61bd7b9SXin Long 174*a61bd7b9SXin Longtrap cleanup EXIT 175*a61bd7b9SXin Longsetup && echo "Testing For SCTP VRF:" && \ 176*a61bd7b9SXin LongCLIENT_IP=$CLIENT_IP4 SERVER_IP=$SERVER_IP4 AF="-4" testup && echo "***v4 Tests Done***" && 177*a61bd7b9SXin LongCLIENT_IP=$CLIENT_IP6 SERVER_IP=$SERVER_IP6 AF="-6" testup && echo "***v6 Tests Done***" 178*a61bd7b9SXin Longexit $? 179