^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # This test is for checking rtnetlink callpaths, and get as much coverage as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # set -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) devdummy="test-dummy0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # Kselftest framework requirement - SKIP code is 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) ksft_skip=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # set global exit status, but never reset nonzero one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) check_err()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) if [ $ret -eq 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ret=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # same but inverted -- used when command must fail for test to pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) check_fail()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if [ $1 -eq 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) ret=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) kci_add_dummy()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ip link add name "$devdummy" type dummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ip link set "$devdummy" up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) kci_del_dummy()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ip link del dev "$devdummy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) kci_test_netconf()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) dev="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) r=$ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ip netconf show dev "$dev" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) for f in 4 6; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ip -$f netconf show dev "$dev" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if [ $ret -ne 0 ] ;then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) echo "FAIL: ip netconf show $dev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) test $r -eq 0 && ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) # add a bridge with vlans on top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) kci_test_bridge()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) devbr="test-br0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) vlandev="testbr-vlan1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ip link add name "$devbr" type bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ip link set dev "$devdummy" master "$devbr"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ip link set "$devbr" up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ip link add link "$devbr" name "$vlandev" type vlan id 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ip addr add dev "$vlandev" 10.200.7.23/30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ip -6 addr add dev "$vlandev" dead:42::1234/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ip -d link > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ip r s t all > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) for name in "$devbr" "$vlandev" "$devdummy" ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) kci_test_netconf "$name"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ip -6 addr del dev "$vlandev" dead:42::1234/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ip link del dev "$vlandev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ip link del dev "$devbr"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) echo "FAIL: bridge setup"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) echo "PASS: bridge setup"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) kci_test_gre()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) gredev=neta
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) rem=10.42.42.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) loc=10.0.0.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ip link set $gredev up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ip addr add 10.23.7.10 dev $gredev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ip route add 10.23.8.0/30 dev $gredev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ip addr add dev "$devdummy" 10.23.7.11/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ip link > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ip addr > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) kci_test_netconf "$gredev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ip addr del dev "$devdummy" 10.23.7.11/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ip link del $gredev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) echo "FAIL: gre tunnel endpoint"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) echo "PASS: gre tunnel endpoint"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) # tc uses rtnetlink too, for full tc testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) # please see tools/testing/selftests/tc-testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) kci_test_tc()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dev=lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) tc qdisc add dev "$dev" root handle 1: htb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) tc class add dev "$dev" parent 1: classid 1:10 htb rate 1mbit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) tc filter add dev "$dev" parent 1:0 prio 5 handle ffe: protocol ip u32 divisor 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) tc filter add dev "$dev" parent 1:0 prio 5 handle ffd: protocol ip u32 divisor 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) tc filter add dev "$dev" parent 1:0 prio 5 handle ffc: protocol ip u32 divisor 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) tc filter add dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32 ht ffe:2: match ip src 10.0.0.3 flowid 1:10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) tc filter add dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:2 u32 ht ffe:2: match ip src 10.0.0.2 flowid 1:10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) tc filter show dev "$dev" parent 1:0 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) tc filter del dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) tc filter show dev "$dev" parent 1:0 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) tc qdisc del dev "$dev" root handle 1: htb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) echo "FAIL: tc htb hierarchy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) echo "PASS: tc htb hierarchy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kci_test_polrouting()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ip rule add fwmark 1 lookup 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ip route add local 0.0.0.0/0 dev lo table 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ip r s t all > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ip rule del fwmark 1 lookup 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ip route del local 0.0.0.0/0 dev lo table 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) echo "FAIL: policy route test"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) echo "PASS: policy routing"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) kci_test_route_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ip route get 127.0.0.1 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ip route get 127.0.0.1 dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ip route get ::1 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ip route get fe80::1 dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ip route get 127.0.0.1 from 127.0.0.1 oif lo tos 0x1 mark 0x1 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ip route get ::1 from ::1 iif lo oif lo tos 0x1 mark 0x1 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ip addr add dev "$devdummy" 10.23.7.11/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ip route get 10.23.7.11 from 10.23.7.12 iif "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ip route add 10.23.8.0/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) nexthop via 10.23.7.13 dev "$devdummy" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) nexthop via 10.23.7.14 dev "$devdummy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) sysctl -wq net.ipv4.fib_multipath_hash_policy=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) ip route get 10.23.8.11 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sysctl -wq net.ipv4.fib_multipath_hash_policy=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ip route get 10.23.8.11 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) sysctl -wq net.ipv4.fib_multipath_hash_policy="$hash_policy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ip route del 10.23.8.0/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ip addr del dev "$devdummy" 10.23.7.11/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) echo "FAIL: route get"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) echo "PASS: route get"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) kci_test_addrlft()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) for i in $(seq 10 100) ;do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) lft=$(((RANDOM%3) + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ip addr add 10.23.11.$i/32 dev "$devdummy" preferred_lft $lft valid_lft $((lft+1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) sleep 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ip addr show dev "$devdummy" | grep "10.23.11."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if [ $? -eq 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) echo "FAIL: preferred_lft addresses remaining"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) check_err 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) echo "PASS: preferred_lft addresses have expired"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) kci_test_promote_secondaries()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) for i in $(seq 2 254);do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) IP="10.23.11.$i"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ip -f inet addr add $IP/16 brd + dev "$devdummy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ifconfig "$devdummy" $IP netmask 255.255.0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ip addr flush dev "$devdummy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) [ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) echo "PASS: promote_secondaries complete"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) kci_test_addrlabel()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ip addrlabel add prefix dead::/64 dev lo label 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ip addrlabel list |grep -q "prefix dead::/64 dev lo label 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ip addrlabel del prefix dead::/64 dev lo label 1 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ip addrlabel add prefix dead::/64 label 1 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ip addrlabel del prefix dead::/64 label 1 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) # concurrent add/delete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) for i in $(seq 1 1000); do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ip addrlabel add prefix 1c3::/64 label 12345 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) done &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) for i in $(seq 1 1000); do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) echo "FAIL: ipv6 addrlabel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) echo "PASS: ipv6 addrlabel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) kci_test_ifalias()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) namewant=$(uuidgen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) syspathname="/sys/class/net/$devdummy/ifalias"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ip link set dev "$devdummy" alias "$namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) echo "FAIL: cannot set interface alias of $devdummy to $namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ip link show "$devdummy" | grep -q "alias $namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if [ -r "$syspathname" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) read namehave < "$syspathname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if [ "$namewant" != "$namehave" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) echo "FAIL: did set ifalias $namewant but got $namehave"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) namewant=$(uuidgen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) echo "$namewant" > "$syspathname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ip link show "$devdummy" | grep -q "alias $namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) # sysfs interface allows to delete alias again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) echo "" > "$syspathname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ip link show "$devdummy" | grep -q "alias $namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) for i in $(seq 1 100); do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) uuidgen > "$syspathname" &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) # re-add the alias -- kernel should free mem when dummy dev is removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ip link set dev "$devdummy" alias "$namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) echo "FAIL: set interface alias $devdummy to $namewant"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) echo "PASS: set ifalias $namewant for $devdummy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) kci_test_vrf()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) vrfname="test-vrf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) ip link show type vrf 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) echo "SKIP: vrf: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ip link add "$vrfname" type vrf table 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) echo "FAIL: can't add vrf interface, skipping test"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ip -br link show type vrf | grep -q "$vrfname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) echo "FAIL: created vrf device not found"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) ip link set dev "$vrfname" up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ip link set dev "$devdummy" master "$vrfname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ip link del dev "$vrfname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) echo "FAIL: vrf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) echo "PASS: vrf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) kci_test_encap_vxlan()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) vxlan="test-vxlan0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) vlan="test-vlan0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) testns="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) ip -netns "$testns" link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) dev "$devdummy" dstport 4789 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) echo "FAIL: can't add vxlan interface, skipping test"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ip -netns "$testns" addr add 10.2.11.49/24 dev "$vxlan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) ip -netns "$testns" link set up dev "$vxlan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ip -netns "$testns" link add link "$vxlan" name "$vlan" type vlan id 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) # changelink testcases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ip -netns "$testns" link set dev "$vxlan" type vxlan vni 43 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ip -netns "$testns" link set dev "$vxlan" type vxlan group ffe5::5 dev "$devdummy" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) ip -netns "$testns" link set dev "$vxlan" type vxlan ttl inherit 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ip -netns "$testns" link set dev "$vxlan" type vxlan ttl 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ip -netns "$testns" link set dev "$vxlan" type vxlan nolearning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) ip -netns "$testns" link set dev "$vxlan" type vxlan proxy 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ip -netns "$testns" link set dev "$vxlan" type vxlan norsc 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ip -netns "$testns" link set dev "$vxlan" type vxlan l2miss 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ip -netns "$testns" link set dev "$vxlan" type vxlan l3miss 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) ip -netns "$testns" link set dev "$vxlan" type vxlan external 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) ip -netns "$testns" link set dev "$vxlan" type vxlan udpcsum 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumtx 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumrx 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumtx 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumrx 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ip -netns "$testns" link set dev "$vxlan" type vxlan gbp 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ip -netns "$testns" link set dev "$vxlan" type vxlan gpe 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) ip -netns "$testns" link del "$vxlan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) echo "FAIL: vxlan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) echo "PASS: vxlan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) kci_test_encap_fou()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) name="test-fou"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) testns="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ip fou help 2>&1 |grep -q 'Usage: ip fou'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) echo "SKIP: fou: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if ! /sbin/modprobe -q -n fou; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) echo "SKIP: module fou is not found"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /sbin/modprobe -q fou
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) ip -netns "$testns" fou add port 7777 ipproto 47 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) echo "FAIL: can't add fou port 7777, skipping test"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ip -netns "$testns" fou add port 8888 ipproto 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ip -netns "$testns" fou del port 9999 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) check_fail $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ip -netns "$testns" fou del port 7777
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) echo "FAIL: fou"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) echo "PASS: fou"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) # test various encap methods, use netns to avoid unwanted interference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) kci_test_encap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) testns="testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) ip netns add "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) echo "SKIP encap tests: cannot add net namespace $testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) ip -netns "$testns" link set lo up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) ip -netns "$testns" link add name "$devdummy" type dummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ip -netns "$testns" link set "$devdummy" up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) kci_test_encap_vxlan "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) kci_test_encap_fou "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return $ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) kci_test_macsec()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) msname="test_macsec0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) echo "SKIP: macsec: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) echo "FAIL: can't add macsec interface, skipping test"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ip macsec show > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ip link del dev "$msname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) echo "FAIL: macsec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) echo "PASS: macsec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) #-------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) # Example commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) # spi 0x07 mode transport reqid 0x07 replay-window 32 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) # sel src 14.0.0.52/24 dst 14.0.0.70/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) # spi 0x07 mode transport reqid 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) # Subcommands not tested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) # ip x s update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) # ip x s allocspi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) # ip x s deleteall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) # ip x p update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) # ip x p deleteall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) # ip x p set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) #-------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) kci_test_ipsec()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) srcip=192.168.123.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) dstip=192.168.123.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) spi=7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) ip addr add $srcip dev $devdummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) # flush to be sure there's nothing configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) ip x s flush ; ip x p flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) # start the monitor in the background
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) tmpfile=`mktemp /var/run/ipsectestXXX`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) mpid=`(ip x m > $tmpfile & echo $!) 2>/dev/null`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) sleep 0.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) ipsecid="proto esp src $srcip dst $dstip spi 0x07"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) ip x s add $ipsecid \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) mode transport reqid 0x07 replay-window 32 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) $algo sel src $srcip/24 dst $dstip/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) test $lines -eq 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ip x s count | grep -q "SAD count 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) test $lines -eq 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ip x s delete $ipsecid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) lines=`ip x s list | wc -l`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) test $lines -eq 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) ipsecsel="dir out src $srcip/24 dst $dstip/24"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) ip x p add $ipsecsel \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) tmpl proto esp src $srcip dst $dstip \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) spi 0x07 mode transport reqid 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) test $lines -eq 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ip x p count | grep -q "SPD IN 0 OUT 1 FWD 0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) test $lines -eq 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ip x p delete $ipsecsel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) lines=`ip x p list | wc -l`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) test $lines -eq 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) # check the monitor results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) kill $mpid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) lines=`wc -l $tmpfile | cut "-d " -f1`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) test $lines -eq 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) rm -rf $tmpfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) # clean up any leftovers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ip x s flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) ip x p flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) ip addr del $srcip/32 dev $devdummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) echo "FAIL: ipsec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) echo "PASS: ipsec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) #-------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) # Example commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) # spi 0x07 mode transport reqid 0x07 replay-window 32 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) # sel src 14.0.0.52/24 dst 14.0.0.70/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) # offload dev sim1 dir out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) # spi 0x07 mode transport reqid 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) #-------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) kci_test_ipsec_offload()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) srcip=192.168.123.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) dstip=192.168.123.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) sysfsf=$sysfsd/ipsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) probed=false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) # setup netdevsim since dummydev doesn't have offload support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if [ ! -w /sys/bus/netdevsim/new_device ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) modprobe -q netdevsim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) echo "SKIP: ipsec_offload can't load netdevsim"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) probed=true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) echo "0" > /sys/bus/netdevsim/new_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) while [ ! -d $sysfsnet ] ; do :; done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) udevadm settle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) dev=`ls $sysfsnet`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) ip addr add $srcip dev $dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) ip link set $dev up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if [ ! -d $sysfsd ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) echo "FAIL: ipsec_offload can't create device $dev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if [ ! -f $sysfsf ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) echo "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) # flush to be sure there's nothing configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ip x s flush ; ip x p flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) # create offloaded SAs, both in and out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) ip x p add dir out src $srcip/24 dst $dstip/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) tmpl proto esp src $srcip dst $dstip spi 9 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) mode transport reqid 42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) ip x p add dir out src $dstip/24 dst $srcip/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) tmpl proto esp src $dstip dst $srcip spi 9 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) mode transport reqid 42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) ip x s add proto esp src $srcip dst $dstip spi 9 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) mode transport reqid 42 $algo sel src $srcip/24 dst $dstip/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) offload dev $dev dir out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) ip x s add proto esp src $dstip dst $srcip spi 9 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) mode transport reqid 42 $algo sel src $dstip/24 dst $srcip/24 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) offload dev $dev dir in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) echo "FAIL: ipsec_offload can't create SA"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) # does offload show up in ip output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) lines=`ip x s list | grep -c "crypto offload parameters: dev $dev dir"`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if [ $lines -ne 2 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) echo "FAIL: ipsec_offload SA offload missing from list output"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) check_err 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) # use ping to exercise the Tx path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) ping -I $dev -c 3 -W 1 -i 0 $dstip >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) # does driver have correct offload info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) diff $sysfsf - << EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) SA count=2 tx=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) sa[0] tx ipaddr=0x00000000 00000000 00000000 00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) sa[0] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) sa[0] key=0x34333231 38373635 32313039 36353433
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) sa[1] rx ipaddr=0x00000000 00000000 00000000 037ba8c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) sa[1] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) sa[1] key=0x34333231 38373635 32313039 36353433
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if [ $? -ne 0 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) echo "FAIL: ipsec_offload incorrect driver data"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) check_err 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) # does offload get removed from driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) ip x s flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) ip x p flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) lines=`grep -c "SA count=0" $sysfsf`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if [ $lines -ne 1 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) echo "FAIL: ipsec_offload SA not removed from driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) check_err 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) # clean up any leftovers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) $probed && rmmod netdevsim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) echo "FAIL: ipsec_offload"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) echo "PASS: ipsec_offload"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) kci_test_gretap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) testns="testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) DEV_NS=gretap00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) ip netns add "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) echo "SKIP gretap tests: cannot add net namespace $testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) ip link help gretap 2>&1 | grep -q "^Usage:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) echo "SKIP: gretap: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) # test native tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) ip -netns "$testns" link add dev "$DEV_NS" type gretap seq \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) key 102 local 172.16.1.100 remote 172.16.1.200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) ip -netns "$testns" link set dev $DEV_NS up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) # test external mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) ip -netns "$testns" link add dev "$DEV_NS" type gretap external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) echo "FAIL: gretap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) echo "PASS: gretap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) kci_test_ip6gretap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) testns="testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) DEV_NS=ip6gretap00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) ip netns add "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) echo "SKIP ip6gretap tests: cannot add net namespace $testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) ip link help ip6gretap 2>&1 | grep -q "^Usage:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) echo "SKIP: ip6gretap: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) # test native tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap seq \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) key 102 local fc00:100::1 remote fc00:100::2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) ip -netns "$testns" addr add dev "$DEV_NS" fc00:200::1/96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) ip -netns "$testns" link set dev $DEV_NS up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) # test external mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) echo "FAIL: ip6gretap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) echo "PASS: ip6gretap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) kci_test_erspan()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) testns="testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) DEV_NS=erspan00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) ip link help erspan 2>&1 | grep -q "^Usage:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) echo "SKIP: erspan: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) ip netns add "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) echo "SKIP erspan tests: cannot add net namespace $testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) # test native tunnel erspan v1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) key 102 local 172.16.1.100 remote 172.16.1.200 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) erspan_ver 1 erspan 488
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) ip -netns "$testns" link set dev $DEV_NS up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) # test native tunnel erspan v2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) key 102 local 172.16.1.100 remote 172.16.1.200 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) erspan_ver 2 erspan_dir ingress erspan_hwid 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) ip -netns "$testns" link set dev $DEV_NS up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) # test external mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) ip -netns "$testns" link add dev "$DEV_NS" type erspan external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) echo "FAIL: erspan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) echo "PASS: erspan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) kci_test_ip6erspan()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) testns="testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) DEV_NS=ip6erspan00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) ip link help ip6erspan 2>&1 | grep -q "^Usage:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) echo "SKIP: ip6erspan: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) ip netns add "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) echo "SKIP ip6erspan tests: cannot add net namespace $testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) # test native tunnel ip6erspan v1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) key 102 local fc00:100::1 remote fc00:100::2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) erspan_ver 1 erspan 488
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) ip -netns "$testns" link set dev $DEV_NS up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) # test native tunnel ip6erspan v2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) key 102 local fc00:100::1 remote fc00:100::2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) erspan_ver 2 erspan_dir ingress erspan_hwid 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) ip -netns "$testns" link set dev $DEV_NS up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) # test external mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) ip -netns "$testns" link add dev "$DEV_NS" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) type ip6erspan external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) ip -netns "$testns" link del "$DEV_NS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) echo "FAIL: ip6erspan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) echo "PASS: ip6erspan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) ip netns del "$testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) kci_test_fdb_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) IP="ip -netns testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) BRIDGE="bridge -netns testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) brdev="test-br0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) vxlandev="vxlan10"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) test_mac=de:ad:be:ef:13:37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) localip="10.0.2.2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) dstip="10.0.2.3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) bridge fdb help 2>&1 |grep -q 'bridge fdb get'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) echo "SKIP: fdb get tests: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) ip netns add testns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) echo "SKIP fdb get tests: cannot add net namespace $testns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) $IP link add "$vxlandev" type vxlan id 10 local $localip \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) dstport 4789 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) $IP link add name "$brdev" type bridge &>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) $IP link set dev "$vxlandev" master "$brdev" &>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) $BRIDGE fdb add $test_mac dev "$vxlandev" master &>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) $BRIDGE fdb add $test_mac dev "$vxlandev" dst $dstip self &>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) $BRIDGE fdb get $test_mac brport "$vxlandev" 2>/dev/null | grep -q "dev $vxlandev master $brdev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) $BRIDGE fdb get $test_mac br "$brdev" 2>/dev/null | grep -q "dev $vxlandev master $brdev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) $BRIDGE fdb get $test_mac dev "$vxlandev" self 2>/dev/null | grep -q "dev $vxlandev dst $dstip"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) ip netns del testns &>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) echo "FAIL: bridge fdb get"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) echo "PASS: bridge fdb get"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) kci_test_neigh_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) dstmac=de:ad:be:ef:13:37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) dstip=10.0.2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) dstip6=dead::2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) ip neigh help 2>&1 |grep -q 'ip neigh get'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) echo "SKIP: fdb get tests: iproute2 too old"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) # ipv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) ip neigh add $dstip lladdr $dstmac dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) ip neigh get $dstip dev "$devdummy" 2> /dev/null | grep -q "$dstmac"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) ip neigh del $dstip lladdr $dstmac dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) # ipv4 proxy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) ip neigh add proxy $dstip dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) ip neigh get proxy $dstip dev "$devdummy" 2>/dev/null | grep -q "$dstip"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) ip neigh del proxy $dstip dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) # ipv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) ip neigh add $dstip6 lladdr $dstmac dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) ip neigh get $dstip6 dev "$devdummy" 2> /dev/null | grep -q "$dstmac"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) ip neigh del $dstip6 lladdr $dstmac dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) # ipv6 proxy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) ip neigh add proxy $dstip6 dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) ip neigh get proxy $dstip6 dev "$devdummy" 2>/dev/null | grep -q "$dstip6"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) ip neigh del proxy $dstip6 dev "$devdummy" > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) echo "FAIL: neigh get"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) echo "PASS: neigh get"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) kci_test_bridge_parent_id()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) sysfsnet=/sys/bus/netdevsim/devices/netdevsim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) probed=false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) if [ ! -w /sys/bus/netdevsim/new_device ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) modprobe -q netdevsim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) echo "SKIP: bridge_parent_id can't load netdevsim"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) probed=true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) echo "10 1" > /sys/bus/netdevsim/new_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) while [ ! -d ${sysfsnet}10 ] ; do :; done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) echo "20 1" > /sys/bus/netdevsim/new_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) while [ ! -d ${sysfsnet}20 ] ; do :; done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) udevadm settle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) dev10=`ls ${sysfsnet}10/net/`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) dev20=`ls ${sysfsnet}20/net/`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) ip link add name test-bond0 type bond mode 802.3ad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) ip link set dev $dev10 master test-bond0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) ip link set dev $dev20 master test-bond0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) ip link add name test-br0 type bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) ip link set dev test-bond0 master test-br0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) # clean up any leftovers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) ip link del dev test-br0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) ip link del dev test-bond0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) echo 20 > /sys/bus/netdevsim/del_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) echo 10 > /sys/bus/netdevsim/del_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) $probed && rmmod netdevsim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if [ $ret -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) echo "FAIL: bridge_parent_id"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) echo "PASS: bridge_parent_id"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) kci_test_rtnl()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) local ret=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) kci_add_dummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) echo "FAIL: cannot add dummy interface"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) kci_test_polrouting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) kci_test_route_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) kci_test_addrlft
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) kci_test_promote_secondaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) kci_test_tc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) kci_test_gre
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) kci_test_gretap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) kci_test_ip6gretap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) kci_test_erspan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) kci_test_ip6erspan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) kci_test_bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) kci_test_addrlabel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) kci_test_ifalias
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) kci_test_vrf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) kci_test_encap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) kci_test_macsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) kci_test_ipsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) kci_test_ipsec_offload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) kci_test_fdb_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) kci_test_neigh_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) kci_test_bridge_parent_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) check_err $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) kci_del_dummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) return $ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) #check for needed privileges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if [ "$(id -u)" -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) echo "SKIP: Need root privileges"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) for x in ip tc;do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) $x -Version 2>/dev/null >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) echo "SKIP: Could not run test without the $x tool"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) kci_test_rtnl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) exit $?