^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Uncomment to see generated bytecode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #VERBOSE=verbose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) NS1=lwt_ns1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) NS2=lwt_ns2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) VETH0=tst_lwt1a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) VETH1=tst_lwt1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) VETH2=tst_lwt2a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) VETH3=tst_lwt2b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) IPVETH0="192.168.254.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) IPVETH1="192.168.254.2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) IPVETH1b="192.168.254.3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) IPVETH2="192.168.111.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) IPVETH3="192.168.111.2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) IP_LOCAL="192.168.99.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) TRACE_ROOT=/sys/kernel/debug/tracing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) function lookup_mac()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) set +x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if [ ! -z "$2" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) MAC=$(ip netns exec $2 ip link show $1 | grep ether | awk '{print $2}')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MAC=$(ip link show $1 | grep ether | awk '{print $2}')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MAC="${MAC//:/}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) echo "0x${MAC:10:2}${MAC:8:2}${MAC:6:2}${MAC:4:2}${MAC:2:2}${MAC:0:2}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) set -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) function cleanup {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) set +ex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) rm test_lwt_bpf.o 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ip link del $VETH0 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ip link del $VETH1 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ip link del $VETH2 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ip link del $VETH3 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ip netns exec $NS1 killall netserver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ip netns delete $NS1 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ip netns delete $NS2 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) set -ex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) function setup_one_veth {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ip netns add $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ip link add $2 type veth peer name $3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ip link set dev $2 up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ip addr add $4/24 dev $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ip link set $3 netns $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ip netns exec $1 ip link set dev $3 up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ip netns exec $1 ip addr add $5/24 dev $3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if [ "$6" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ip netns exec $1 ip addr add $6/32 dev $3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) function get_trace {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) set +x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) cat ${TRACE_ROOT}/trace | grep -v '^#'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) set -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) function cleanup_routes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ip route del ${IPVETH1}/32 dev $VETH0 2> /dev/null || true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ip route del table local local ${IP_LOCAL}/32 dev lo 2> /dev/null || true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) function install_test {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) cleanup_routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) cp /dev/null ${TRACE_ROOT}/trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) OPTS="encap bpf headroom 14 $1 obj test_lwt_bpf.o section $2 $VERBOSE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if [ "$1" == "in" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ip route add table local local ${IP_LOCAL}/32 $OPTS dev lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ip route add ${IPVETH1}/32 $OPTS dev $VETH0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) function remove_prog {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if [ "$1" == "in" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ip route del table local local ${IP_LOCAL}/32 dev lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ip route del ${IPVETH1}/32 dev $VETH0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) function filter_trace {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) # Add newline to allow starting EXPECT= variables on newline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) NL=$'\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) echo "${NL}$*" | sed -e 's/^.*: : //g'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) function expect_fail {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) set +x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) echo "FAIL:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) echo "Expected: $1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) echo "Got: $2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) set -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) function match_trace {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) set +x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) RET=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) TRACE=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) EXPECT=$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) GOT="$(filter_trace "$TRACE")"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) [ "$GOT" != "$EXPECT" ] && {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) expect_fail "$EXPECT" "$GOT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) RET=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) set -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return $RET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) function test_start {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) set +x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) echo "----------------------------------------------------------------"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) echo "Starting test: $*"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) echo "----------------------------------------------------------------"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) set -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) function failure {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) get_trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) echo "FAIL: $*"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) function test_ctx_xmit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) test_start "test_ctx on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) install_test xmit test_ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ping -c 3 $IPVETH1 || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) failure "test_ctx xmit: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) cb 1234 ingress_ifindex 0 ifindex $DST_IFINDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) cb 1234 ingress_ifindex 0 ifindex $DST_IFINDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) cb 1234 ingress_ifindex 0 ifindex $DST_IFINDEX" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) remove_prog xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) function test_ctx_out {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) test_start "test_ctx on lwt out"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) install_test out test_ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ping -c 3 $IPVETH1 || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) failure "test_ctx out: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) len 84 hash 0 protocol 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) cb 1234 ingress_ifindex 0 ifindex 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) len 84 hash 0 protocol 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) cb 1234 ingress_ifindex 0 ifindex 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) len 84 hash 0 protocol 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) cb 1234 ingress_ifindex 0 ifindex 0" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) remove_prog out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) function test_ctx_in {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) test_start "test_ctx on lwt in"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) install_test in test_ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ping -c 3 $IP_LOCAL || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) failure "test_ctx out: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) # We will both request & reply packets as the packets will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) # be from $IP_LOCAL => $IP_LOCAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) cb 1234 ingress_ifindex 1 ifindex 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) cb 1234 ingress_ifindex 1 ifindex 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) cb 1234 ingress_ifindex 1 ifindex 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) cb 1234 ingress_ifindex 1 ifindex 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) cb 1234 ingress_ifindex 1 ifindex 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) len 84 hash 0 protocol 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) cb 1234 ingress_ifindex 1 ifindex 1" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) remove_prog in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) function test_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) test_start "test_data on lwt $1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) install_test $1 test_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ping -c 3 $IPVETH1 || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) failure "test_data ${1}: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) src: 1fea8c0 dst: 2fea8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) src: 1fea8c0 dst: 2fea8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) src: 1fea8c0 dst: 2fea8c0" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) remove_prog $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) function test_data_in {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) test_start "test_data on lwt in"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) install_test in test_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ping -c 3 $IP_LOCAL || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) failure "test_data in: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) # We will both request & reply packets as the packets will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) # be from $IP_LOCAL => $IP_LOCAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) src: 163a8c0 dst: 163a8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) src: 163a8c0 dst: 163a8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) src: 163a8c0 dst: 163a8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) src: 163a8c0 dst: 163a8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) src: 163a8c0 dst: 163a8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) src: 163a8c0 dst: 163a8c0" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) remove_prog in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) function test_cb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) test_start "test_cb on lwt $1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) install_test $1 test_cb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ping -c 3 $IPVETH1 || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) failure "test_cb ${1}: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) cb3: 0 cb4: 0" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) remove_prog $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) function test_cb_in {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) test_start "test_cb on lwt in"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) install_test in test_cb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ping -c 3 $IP_LOCAL || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) failure "test_cb in: packets are dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) # We will both request & reply packets as the packets will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) # be from $IP_LOCAL => $IP_LOCAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) cb3: 0 cb4: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) cb0: 0 cb1: 0 cb2: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) cb3: 0 cb4: 0" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) remove_prog in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) function test_drop_all {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) test_start "test_drop_all on lwt $1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) install_test $1 drop_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ping -c 3 $IPVETH1 && {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) failure "test_drop_all ${1}: Unexpected success of ping"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dropping with: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) dropping with: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) dropping with: 2" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) remove_prog $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) function test_drop_all_in {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) test_start "test_drop_all on lwt in"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) install_test in drop_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ping -c 3 $IP_LOCAL && {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) failure "test_drop_all in: Unexpected success of ping"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) dropping with: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) dropping with: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) dropping with: 2" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) remove_prog in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) function test_push_ll_and_redirect {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) test_start "test_push_ll_and_redirect on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) install_test xmit push_ll_and_redirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ping -c 3 $IPVETH1 || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) failure "Redirected packets appear to be dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) redirected to $DST_IFINDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) redirected to $DST_IFINDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) redirected to $DST_IFINDEX" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) remove_prog xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) function test_no_l2_and_redirect {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) test_start "test_no_l2_and_redirect on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) install_test xmit fill_garbage_and_redirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ping -c 3 $IPVETH1 && {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) failure "Unexpected success despite lack of L2 header"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) redirected to $DST_IFINDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) redirected to $DST_IFINDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) redirected to $DST_IFINDEX" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) remove_prog xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) function test_rewrite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) test_start "test_rewrite on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) install_test xmit test_rewrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ping -c 3 $IPVETH1 || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) failure "Rewritten packets appear to be dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) out: rewriting from 2fea8c0 to 3fea8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) out: rewriting from 2fea8c0 to 3fea8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) out: rewriting from 2fea8c0 to 3fea8c0" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) remove_prog out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) function test_fill_garbage {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) test_start "test_fill_garbage on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) install_test xmit fill_garbage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ping -c 3 $IPVETH1 && {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) failure "test_drop_all ${1}: Unexpected success of ping"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) match_trace "$(get_trace)" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) Set initial 96 bytes of header to FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) Set initial 96 bytes of header to FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) Set initial 96 bytes of header to FF" || exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) remove_prog xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) function test_netperf_nop {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) test_start "test_netperf_nop on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) install_test xmit nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) netperf -H $IPVETH1 -t TCP_STREAM || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) failure "packets appear to be dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) match_trace "$(get_trace)" ""|| exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) remove_prog xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) function test_netperf_redirect {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) test_start "test_netperf_redirect on lwt xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) install_test xmit push_ll_and_redirect_silent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) netperf -H $IPVETH1 -t TCP_STREAM || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) failure "Rewritten packets appear to be dropped"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) match_trace "$(get_trace)" ""|| exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) remove_prog xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) setup_one_veth $NS1 $VETH0 $VETH1 $IPVETH0 $IPVETH1 $IPVETH1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) setup_one_veth $NS2 $VETH2 $VETH3 $IPVETH2 $IPVETH3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ip netns exec $NS1 netserver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) echo 1 > ${TRACE_ROOT}/tracing_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) DST_MAC=$(lookup_mac $VETH1 $NS1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) SRC_MAC=$(lookup_mac $VETH0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) DST_IFINDEX=$(cat /sys/class/net/$VETH0/ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) CLANG_OPTS="-O2 -target bpf -I ../include/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) CLANG_OPTS+=" -DSRC_MAC=$SRC_MAC -DDST_MAC=$DST_MAC -DDST_IFINDEX=$DST_IFINDEX"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) clang $CLANG_OPTS -c test_lwt_bpf.c -o test_lwt_bpf.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) test_ctx_xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) test_ctx_out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) test_ctx_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) test_data "xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) test_data "out"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) test_data_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) test_cb "xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) test_cb "out"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) test_cb_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) test_drop_all "xmit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) test_drop_all "out"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) test_drop_all_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) test_rewrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) test_push_ll_and_redirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) test_no_l2_and_redirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) test_fill_garbage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) test_netperf_nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) test_netperf_redirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) echo 0 > ${TRACE_ROOT}/tracing_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) exit 0