| @@ -8,9 +8,14 @@ ksft_skip=4 · 7 unmodified lines |
| 8 | 8 | ret=0 |
| 9 | 9 | test_inet_nat=true |
| 10 | 10 | |
| 11 | +sfx=$(mktemp -u "XXXXXXXX") |
| 12 | +ns0="ns0-$sfx" |
| 13 | +ns1="ns1-$sfx" |
| 14 | +ns2="ns2-$sfx" |
| 15 | + |
| 11 | 16 | cleanup() |
| 12 | 17 | { |
| 13 | | − for i in 0 1 2; do ip netns del ns$i;done |
| 18 | + for i in 0 1 2; do ip netns del ns$i-"$sfx";done |
| 14 | 19 | } |
| 15 | 20 | |
| 16 | 21 | nft --version > /dev/null 2>&1 |
| @@ -25,40 +30,49 @@ if [ $? -ne 0 ];then · 8 unmodified lines |
| 25 | 30 | exit $ksft_skip |
| 26 | 31 | fi |
| 27 | 32 | |
| 28 | | −ip netns add ns0 |
| 33 | +ip netns add "$ns0" |
| 29 | 34 | if [ $? -ne 0 ];then |
| 30 | | − echo "SKIP: Could not create net namespace" |
| 35 | + echo "SKIP: Could not create net namespace $ns0" |
| 31 | 36 | exit $ksft_skip |
| 32 | 37 | fi |
| 33 | 38 | |
| 34 | 39 | trap cleanup EXIT |
| 35 | 40 | |
| 36 | | −ip netns add ns1 |
| 37 | | −ip netns add ns2 |
| 41 | +ip netns add "$ns1" |
| 42 | +if [ $? -ne 0 ];then |
| 43 | + echo "SKIP: Could not create net namespace $ns1" |
| 44 | + exit $ksft_skip |
| 45 | +fi |
| 46 | + |
| 47 | +ip netns add "$ns2" |
| 48 | +if [ $? -ne 0 ];then |
| 49 | + echo "SKIP: Could not create net namespace $ns2" |
| 50 | + exit $ksft_skip |
| 51 | +fi |
| 38 | 52 | |
| 39 | | −ip link add veth0 netns ns0 type veth peer name eth0 netns ns1 > /dev/null 2>&1 |
| 53 | +ip link add veth0 netns "$ns0" type veth peer name eth0 netns "$ns1" > /dev/null 2>&1 |
| 40 | 54 | if [ $? -ne 0 ];then |
| 41 | 55 | echo "SKIP: No virtual ethernet pair device support in kernel" |
| 42 | 56 | exit $ksft_skip |
| 43 | 57 | fi |
| 44 | | −ip link add veth1 netns ns0 type veth peer name eth0 netns ns2 |
| 58 | +ip link add veth1 netns "$ns0" type veth peer name eth0 netns "$ns2" |
| 45 | 59 | |
| 46 | | −ip -net ns0 link set lo up |
| 47 | | −ip -net ns0 link set veth0 up |
| 48 | | −ip -net ns0 addr add 10.0.1.1/24 dev veth0 |
| 49 | | −ip -net ns0 addr add dead:1::1/64 dev veth0 |
| 60 | +ip -net "$ns0" link set lo up |
| 61 | +ip -net "$ns0" link set veth0 up |
| 62 | +ip -net "$ns0" addr add 10.0.1.1/24 dev veth0 |
| 63 | +ip -net "$ns0" addr add dead:1::1/64 dev veth0 |
| 50 | 64 | |
| 51 | | −ip -net ns0 link set veth1 up |
| 52 | | −ip -net ns0 addr add 10.0.2.1/24 dev veth1 |
| 53 | | −ip -net ns0 addr add dead:2::1/64 dev veth1 |
| 65 | +ip -net "$ns0" link set veth1 up |
| 66 | +ip -net "$ns0" addr add 10.0.2.1/24 dev veth1 |
| 67 | +ip -net "$ns0" addr add dead:2::1/64 dev veth1 |
| 54 | 68 | |
| 55 | 69 | for i in 1 2; do |
| 56 | | − ip -net ns$i link set lo up |
| 57 | | − ip -net ns$i link set eth0 up |
| 58 | | − ip -net ns$i addr add 10.0.$i.99/24 dev eth0 |
| 59 | | − ip -net ns$i route add default via 10.0.$i.1 |
| 60 | | − ip -net ns$i addr add dead:$i::99/64 dev eth0 |
| 61 | | − ip -net ns$i route add default via dead:$i::1 |
| 70 | + ip -net ns$i-$sfx link set lo up |
| 71 | + ip -net ns$i-$sfx link set eth0 up |
| 72 | + ip -net ns$i-$sfx addr add 10.0.$i.99/24 dev eth0 |
| 73 | + ip -net ns$i-$sfx route add default via 10.0.$i.1 |
| 74 | + ip -net ns$i-$sfx addr add dead:$i::99/64 dev eth0 |
| 75 | + ip -net ns$i-$sfx route add default via dead:$i::1 |
| 62 | 76 | done |
| 63 | 77 | |
| 64 | 78 | bad_counter() |
| @@ -66,8 +80,9 @@ bad_counter() · 1 unmodified line |
| 66 | 80 | local ns=$1 |
| 67 | 81 | local counter=$2 |
| 68 | 82 | local expect=$3 |
| 83 | + local tag=$4 |
| 69 | 84 | |
| 70 | | − echo "ERROR: $counter counter in $ns has unexpected value (expected $expect)" 1>&2 |
| 85 | + echo "ERROR: $counter counter in $ns has unexpected value (expected $expect) at $tag" 1>&2 |
| 71 | 86 | ip netns exec $ns nft list counter inet filter $counter 1>&2 |
| 72 | 87 | } |
| 73 | 88 | |
| @@ -78,24 +93,24 @@ check_counters() · 4 unmodified lines |
| 78 | 93 | |
| 79 | 94 | cnt=$(ip netns exec $ns nft list counter inet filter ns0in | grep -q "packets 1 bytes 84") |
| 80 | 95 | if [ $? -ne 0 ]; then |
| 81 | | − bad_counter $ns ns0in "packets 1 bytes 84" |
| 96 | + bad_counter $ns ns0in "packets 1 bytes 84" "check_counters 1" |
| 82 | 97 | lret=1 |
| 83 | 98 | fi |
| 84 | 99 | cnt=$(ip netns exec $ns nft list counter inet filter ns0out | grep -q "packets 1 bytes 84") |
| 85 | 100 | if [ $? -ne 0 ]; then |
| 86 | | − bad_counter $ns ns0out "packets 1 bytes 84" |
| 101 | + bad_counter $ns ns0out "packets 1 bytes 84" "check_counters 2" |
| 87 | 102 | lret=1 |
| 88 | 103 | fi |
| 89 | 104 | |
| 90 | 105 | expect="packets 1 bytes 104" |
| 91 | 106 | cnt=$(ip netns exec $ns nft list counter inet filter ns0in6 | grep -q "$expect") |
| 92 | 107 | if [ $? -ne 0 ]; then |
| 93 | | − bad_counter $ns ns0in6 "$expect" |
| 108 | + bad_counter $ns ns0in6 "$expect" "check_counters 3" |
| 94 | 109 | lret=1 |
| 95 | 110 | fi |
| 96 | 111 | cnt=$(ip netns exec $ns nft list counter inet filter ns0out6 | grep -q "$expect") |
| 97 | 112 | if [ $? -ne 0 ]; then |
| 98 | | − bad_counter $ns ns0out6 "$expect" |
| 113 | + bad_counter $ns ns0out6 "$expect" "check_counters 4" |
| 99 | 114 | lret=1 |
| 100 | 115 | fi |
| 101 | 116 | |
| @@ -107,41 +122,41 @@ check_ns0_counters() · 5 unmodified lines |
| 107 | 122 | local ns=$1 |
| 108 | 123 | local lret=0 |
| 109 | 124 | |
| 110 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns0in | grep -q "packets 0 bytes 0") |
| 125 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0in | grep -q "packets 0 bytes 0") |
| 111 | 126 | if [ $? -ne 0 ]; then |
| 112 | | − bad_counter ns0 ns0in "packets 0 bytes 0" |
| 127 | + bad_counter "$ns0" ns0in "packets 0 bytes 0" "check_ns0_counters 1" |
| 113 | 128 | lret=1 |
| 114 | 129 | fi |
| 115 | 130 | |
| 116 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns0in6 | grep -q "packets 0 bytes 0") |
| 131 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0in6 | grep -q "packets 0 bytes 0") |
| 117 | 132 | if [ $? -ne 0 ]; then |
| 118 | | − bad_counter ns0 ns0in6 "packets 0 bytes 0" |
| 133 | + bad_counter "$ns0" ns0in6 "packets 0 bytes 0" |
| 119 | 134 | lret=1 |
| 120 | 135 | fi |
| 121 | 136 | |
| 122 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns0out | grep -q "packets 0 bytes 0") |
| 137 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0out | grep -q "packets 0 bytes 0") |
| 123 | 138 | if [ $? -ne 0 ]; then |
| 124 | | − bad_counter ns0 ns0out "packets 0 bytes 0" |
| 139 | + bad_counter "$ns0" ns0out "packets 0 bytes 0" "check_ns0_counters 2" |
| 125 | 140 | lret=1 |
| 126 | 141 | fi |
| 127 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns0out6 | grep -q "packets 0 bytes 0") |
| 142 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0out6 | grep -q "packets 0 bytes 0") |
| 128 | 143 | if [ $? -ne 0 ]; then |
| 129 | | − bad_counter ns0 ns0out6 "packets 0 bytes 0" |
| 144 | + bad_counter "$ns0" ns0out6 "packets 0 bytes 0" "check_ns0_counters3 " |
| 130 | 145 | lret=1 |
| 131 | 146 | fi |
| 132 | 147 | |
| 133 | 148 | for dir in "in" "out" ; do |
| 134 | 149 | expect="packets 1 bytes 84" |
| 135 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir} | grep -q "$expect") |
| 150 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ${ns}${dir} | grep -q "$expect") |
| 136 | 151 | if [ $? -ne 0 ]; then |
| 137 | | − bad_counter ns0 $ns$dir "$expect" |
| 152 | + bad_counter "$ns0" $ns$dir "$expect" "check_ns0_counters 4" |
| 138 | 153 | lret=1 |
| 139 | 154 | fi |
| 140 | 155 | |
| 141 | 156 | expect="packets 1 bytes 104" |
| 142 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir}6 | grep -q "$expect") |
| 157 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ${ns}${dir}6 | grep -q "$expect") |
| 143 | 158 | if [ $? -ne 0 ]; then |
| 144 | | − bad_counter ns0 $ns$dir6 "$expect" |
| 159 | + bad_counter "$ns0" $ns$dir6 "$expect" "check_ns0_counters 5" |
| 145 | 160 | lret=1 |
| 146 | 161 | fi |
| 147 | 162 | done |
| @@ -152,7 +167,7 @@ check_ns0_counters() · 4 unmodified lines |
| 152 | 167 | reset_counters() |
| 153 | 168 | { |
| 154 | 169 | for i in 0 1 2;do |
| 155 | | − ip netns exec ns$i nft reset counters inet > /dev/null |
| 170 | + ip netns exec ns$i-$sfx nft reset counters inet > /dev/null |
| 156 | 171 | done |
| 157 | 172 | } |
| 158 | 173 | |
| @@ -166,7 +181,7 @@ test_local_dnat6() · 7 unmodified lines |
| 166 | 181 | IPF="ip6" |
| 167 | 182 | fi |
| 168 | 183 | |
| 169 | | −ip netns exec ns0 nft -f - <<EOF |
| 184 | +ip netns exec "$ns0" nft -f /dev/stdin <<EOF |
| 170 | 185 | table $family nat { |
| 171 | 186 | chain output { |
| 172 | 187 | type nat hook output priority 0; policy accept; |
| @@ -180,7 +195,7 @@ EOF · 7 unmodified lines |
| 180 | 195 | fi |
| 181 | 196 | |
| 182 | 197 | # ping netns1, expect rewrite to netns2 |
| 183 | | − ip netns exec ns0 ping -q -c 1 dead:1::99 > /dev/null |
| 198 | + ip netns exec "$ns0" ping -q -c 1 dead:1::99 > /dev/null |
| 184 | 199 | if [ $? -ne 0 ]; then |
| 185 | 200 | lret=1 |
| 186 | 201 | echo "ERROR: ping6 failed" |
| @@ -189,18 +204,18 @@ EOF · 2 unmodified lines |
| 189 | 204 | |
| 190 | 205 | expect="packets 0 bytes 0" |
| 191 | 206 | for dir in "in6" "out6" ; do |
| 192 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 207 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 193 | 208 | if [ $? -ne 0 ]; then |
| 194 | | − bad_counter ns0 ns1$dir "$expect" |
| 209 | + bad_counter "$ns0" ns1$dir "$expect" "test_local_dnat6 1" |
| 195 | 210 | lret=1 |
| 196 | 211 | fi |
| 197 | 212 | done |
| 198 | 213 | |
| 199 | 214 | expect="packets 1 bytes 104" |
| 200 | 215 | for dir in "in6" "out6" ; do |
| 201 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 216 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 202 | 217 | if [ $? -ne 0 ]; then |
| 203 | | − bad_counter ns0 ns2$dir "$expect" |
| 218 | + bad_counter "$ns0" ns2$dir "$expect" "test_local_dnat6 2" |
| 204 | 219 | lret=1 |
| 205 | 220 | fi |
| 206 | 221 | done |
| @@ -208,9 +223,9 @@ EOF · 1 unmodified line |
| 208 | 223 | # expect 0 count in ns1 |
| 209 | 224 | expect="packets 0 bytes 0" |
| 210 | 225 | for dir in "in6" "out6" ; do |
| 211 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 226 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 212 | 227 | if [ $? -ne 0 ]; then |
| 213 | | − bad_counter ns1 ns0$dir "$expect" |
| 228 | + bad_counter "$ns1" ns0$dir "$expect" "test_local_dnat6 3" |
| 214 | 229 | lret=1 |
| 215 | 230 | fi |
| 216 | 231 | done |
| @@ -218,15 +233,15 @@ EOF · 1 unmodified line |
| 218 | 233 | # expect 1 packet in ns2 |
| 219 | 234 | expect="packets 1 bytes 104" |
| 220 | 235 | for dir in "in6" "out6" ; do |
| 221 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 236 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 222 | 237 | if [ $? -ne 0 ]; then |
| 223 | | − bad_counter ns2 ns0$dir "$expect" |
| 238 | + bad_counter "$ns2" ns0$dir "$expect" "test_local_dnat6 4" |
| 224 | 239 | lret=1 |
| 225 | 240 | fi |
| 226 | 241 | done |
| 227 | 242 | |
| 228 | | − test $lret -eq 0 && echo "PASS: ipv6 ping to ns1 was $family NATted to ns2" |
| 229 | | − ip netns exec ns0 nft flush chain ip6 nat output |
| 243 | + test $lret -eq 0 && echo "PASS: ipv6 ping to $ns1 was $family NATted to $ns2" |
| 244 | + ip netns exec "$ns0" nft flush chain ip6 nat output |
| 230 | 245 | |
| 231 | 246 | return $lret |
| 232 | 247 | } |
| @@ -241,7 +256,7 @@ test_local_dnat() · 8 unmodified lines |
| 241 | 256 | IPF="ip" |
| 242 | 257 | fi |
| 243 | 258 | |
| 244 | | −ip netns exec ns0 nft -f - <<EOF 2>/dev/null |
| 259 | +ip netns exec "$ns0" nft -f /dev/stdin <<EOF 2>/dev/null |
| 245 | 260 | table $family nat { |
| 246 | 261 | chain output { |
| 247 | 262 | type nat hook output priority 0; policy accept; |
| @@ -260,7 +275,7 @@ EOF · 12 unmodified lines |
| 260 | 275 | fi |
| 261 | 276 | |
| 262 | 277 | # ping netns1, expect rewrite to netns2 |
| 263 | | − ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null |
| 278 | + ip netns exec "$ns0" ping -q -c 1 10.0.1.99 > /dev/null |
| 264 | 279 | if [ $? -ne 0 ]; then |
| 265 | 280 | lret=1 |
| 266 | 281 | echo "ERROR: ping failed" |
| @@ -269,18 +284,18 @@ EOF · 2 unmodified lines |
| 269 | 284 | |
| 270 | 285 | expect="packets 0 bytes 0" |
| 271 | 286 | for dir in "in" "out" ; do |
| 272 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 287 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 273 | 288 | if [ $? -ne 0 ]; then |
| 274 | | − bad_counter ns0 ns1$dir "$expect" |
| 289 | + bad_counter "$ns0" ns1$dir "$expect" "test_local_dnat 1" |
| 275 | 290 | lret=1 |
| 276 | 291 | fi |
| 277 | 292 | done |
| 278 | 293 | |
| 279 | 294 | expect="packets 1 bytes 84" |
| 280 | 295 | for dir in "in" "out" ; do |
| 281 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 296 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 282 | 297 | if [ $? -ne 0 ]; then |
| 283 | | − bad_counter ns0 ns2$dir "$expect" |
| 298 | + bad_counter "$ns0" ns2$dir "$expect" "test_local_dnat 2" |
| 284 | 299 | lret=1 |
| 285 | 300 | fi |
| 286 | 301 | done |
| @@ -288,9 +303,9 @@ EOF · 1 unmodified line |
| 288 | 303 | # expect 0 count in ns1 |
| 289 | 304 | expect="packets 0 bytes 0" |
| 290 | 305 | for dir in "in" "out" ; do |
| 291 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 306 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 292 | 307 | if [ $? -ne 0 ]; then |
| 293 | | − bad_counter ns1 ns0$dir "$expect" |
| 308 | + bad_counter "$ns1" ns0$dir "$expect" "test_local_dnat 3" |
| 294 | 309 | lret=1 |
| 295 | 310 | fi |
| 296 | 311 | done |
| @@ -298,19 +313,19 @@ EOF · 1 unmodified line |
| 298 | 313 | # expect 1 packet in ns2 |
| 299 | 314 | expect="packets 1 bytes 84" |
| 300 | 315 | for dir in "in" "out" ; do |
| 301 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 316 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 302 | 317 | if [ $? -ne 0 ]; then |
| 303 | | − bad_counter ns2 ns0$dir "$expect" |
| 318 | + bad_counter "$ns2" ns0$dir "$expect" "test_local_dnat 4" |
| 304 | 319 | lret=1 |
| 305 | 320 | fi |
| 306 | 321 | done |
| 307 | 322 | |
| 308 | | − test $lret -eq 0 && echo "PASS: ping to ns1 was $family NATted to ns2" |
| 323 | + test $lret -eq 0 && echo "PASS: ping to $ns1 was $family NATted to $ns2" |
| 309 | 324 | |
| 310 | | − ip netns exec ns0 nft flush chain $family nat output |
| 325 | + ip netns exec "$ns0" nft flush chain $family nat output |
| 311 | 326 | |
| 312 | 327 | reset_counters |
| 313 | | − ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null |
| 328 | + ip netns exec "$ns0" ping -q -c 1 10.0.1.99 > /dev/null |
| 314 | 329 | if [ $? -ne 0 ]; then |
| 315 | 330 | lret=1 |
| 316 | 331 | echo "ERROR: ping failed" |
| @@ -319,17 +334,17 @@ EOF · 2 unmodified lines |
| 319 | 334 | |
| 320 | 335 | expect="packets 1 bytes 84" |
| 321 | 336 | for dir in "in" "out" ; do |
| 322 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 337 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 323 | 338 | if [ $? -ne 0 ]; then |
| 324 | | − bad_counter ns1 ns1$dir "$expect" |
| 339 | + bad_counter "$ns1" ns1$dir "$expect" "test_local_dnat 5" |
| 325 | 340 | lret=1 |
| 326 | 341 | fi |
| 327 | 342 | done |
| 328 | 343 | expect="packets 0 bytes 0" |
| 329 | 344 | for dir in "in" "out" ; do |
| 330 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 345 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 331 | 346 | if [ $? -ne 0 ]; then |
| 332 | | − bad_counter ns0 ns2$dir "$expect" |
| 347 | + bad_counter "$ns0" ns2$dir "$expect" "test_local_dnat 6" |
| 333 | 348 | lret=1 |
| 334 | 349 | fi |
| 335 | 350 | done |
| @@ -337,9 +352,9 @@ EOF · 1 unmodified line |
| 337 | 352 | # expect 1 count in ns1 |
| 338 | 353 | expect="packets 1 bytes 84" |
| 339 | 354 | for dir in "in" "out" ; do |
| 340 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 355 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 341 | 356 | if [ $? -ne 0 ]; then |
| 342 | | − bad_counter ns0 ns0$dir "$expect" |
| 357 | + bad_counter "$ns0" ns0$dir "$expect" "test_local_dnat 7" |
| 343 | 358 | lret=1 |
| 344 | 359 | fi |
| 345 | 360 | done |
| @@ -347,14 +362,14 @@ EOF · 1 unmodified line |
| 347 | 362 | # expect 0 packet in ns2 |
| 348 | 363 | expect="packets 0 bytes 0" |
| 349 | 364 | for dir in "in" "out" ; do |
| 350 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 365 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 351 | 366 | if [ $? -ne 0 ]; then |
| 352 | | − bad_counter ns2 ns2$dir "$expect" |
| 367 | + bad_counter "$ns2" ns0$dir "$expect" "test_local_dnat 8" |
| 353 | 368 | lret=1 |
| 354 | 369 | fi |
| 355 | 370 | done |
| 356 | 371 | |
| 357 | | − test $lret -eq 0 && echo "PASS: ping to ns1 OK after $family nat output chain flush" |
| 372 | + test $lret -eq 0 && echo "PASS: ping to $ns1 OK after $family nat output chain flush" |
| 358 | 373 | |
| 359 | 374 | return $lret |
| 360 | 375 | } |
| @@ -366,26 +381,26 @@ test_masquerade6() · 5 unmodified lines |
| 366 | 381 | local natflags=$2 |
| 367 | 382 | local lret=0 |
| 368 | 383 | |
| 369 | | − ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null |
| 384 | + ip netns exec "$ns0" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null |
| 370 | 385 | |
| 371 | | − ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 386 | + ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 372 | 387 | if [ $? -ne 0 ] ; then |
| 373 | | − echo "ERROR: cannot ping ns1 from ns2 via ipv6" |
| 388 | + echo "ERROR: cannot ping $ns1 from $ns2 via ipv6" |
| 374 | 389 | return 1 |
| 375 | 390 | lret=1 |
| 376 | 391 | fi |
| 377 | 392 | |
| 378 | 393 | expect="packets 1 bytes 104" |
| 379 | 394 | for dir in "in6" "out6" ; do |
| 380 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 395 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 381 | 396 | if [ $? -ne 0 ]; then |
| 382 | | − bad_counter ns1 ns2$dir "$expect" |
| 397 | + bad_counter "$ns1" ns2$dir "$expect" "test_masquerade6 1" |
| 383 | 398 | lret=1 |
| 384 | 399 | fi |
| 385 | 400 | |
| 386 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 401 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 387 | 402 | if [ $? -ne 0 ]; then |
| 388 | | − bad_counter ns2 ns1$dir "$expect" |
| 403 | + bad_counter "$ns2" ns1$dir "$expect" "test_masquerade6 2" |
| 389 | 404 | lret=1 |
| 390 | 405 | fi |
| 391 | 406 | done |
| @@ -393,7 +408,7 @@ test_masquerade6() · 1 unmodified line |
| 393 | 408 | reset_counters |
| 394 | 409 | |
| 395 | 410 | # add masquerading rule |
| 396 | | −ip netns exec ns0 nft -f - <<EOF |
| 411 | +ip netns exec "$ns0" nft -f /dev/stdin <<EOF |
| 397 | 412 | table $family nat { |
| 398 | 413 | chain postrouting { |
| 399 | 414 | type nat hook postrouting priority 0; policy accept; |
| @@ -406,24 +421,24 @@ EOF · 6 unmodified lines |
| 406 | 421 | return $ksft_skip |
| 407 | 422 | fi |
| 408 | 423 | |
| 409 | | − ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 424 | + ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 410 | 425 | if [ $? -ne 0 ] ; then |
| 411 | | − echo "ERROR: cannot ping ns1 from ns2 with active $family masquerade $natflags" |
| 426 | + echo "ERROR: cannot ping $ns1 from $ns2 with active $family masquerade $natflags" |
| 412 | 427 | lret=1 |
| 413 | 428 | fi |
| 414 | 429 | |
| 415 | 430 | # ns1 should have seen packets from ns0, due to masquerade |
| 416 | 431 | expect="packets 1 bytes 104" |
| 417 | 432 | for dir in "in6" "out6" ; do |
| 418 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 433 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 419 | 434 | if [ $? -ne 0 ]; then |
| 420 | | − bad_counter ns1 ns0$dir "$expect" |
| 435 | + bad_counter "$ns1" ns0$dir "$expect" "test_masquerade6 3" |
| 421 | 436 | lret=1 |
| 422 | 437 | fi |
| 423 | 438 | |
| 424 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 439 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 425 | 440 | if [ $? -ne 0 ]; then |
| 426 | | − bad_counter ns2 ns1$dir "$expect" |
| 441 | + bad_counter "$ns2" ns1$dir "$expect" "test_masquerade6 4" |
| 427 | 442 | lret=1 |
| 428 | 443 | fi |
| 429 | 444 | done |
| @@ -431,32 +446,32 @@ EOF · 1 unmodified line |
| 431 | 446 | # ns1 should not have seen packets from ns2, due to masquerade |
| 432 | 447 | expect="packets 0 bytes 0" |
| 433 | 448 | for dir in "in6" "out6" ; do |
| 434 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 449 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 435 | 450 | if [ $? -ne 0 ]; then |
| 436 | | − bad_counter ns1 ns0$dir "$expect" |
| 451 | + bad_counter "$ns1" ns0$dir "$expect" "test_masquerade6 5" |
| 437 | 452 | lret=1 |
| 438 | 453 | fi |
| 439 | 454 | |
| 440 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 455 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 441 | 456 | if [ $? -ne 0 ]; then |
| 442 | | − bad_counter ns2 ns1$dir "$expect" |
| 457 | + bad_counter "$ns0" ns1$dir "$expect" "test_masquerade6 6" |
| 443 | 458 | lret=1 |
| 444 | 459 | fi |
| 445 | 460 | done |
| 446 | 461 | |
| 447 | | − ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 462 | + ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 448 | 463 | if [ $? -ne 0 ] ; then |
| 449 | | − echo "ERROR: cannot ping ns1 from ns2 with active ipv6 masquerade $natflags (attempt 2)" |
| 464 | + echo "ERROR: cannot ping $ns1 from $ns2 with active ipv6 masquerade $natflags (attempt 2)" |
| 450 | 465 | lret=1 |
| 451 | 466 | fi |
| 452 | 467 | |
| 453 | | − ip netns exec ns0 nft flush chain $family nat postrouting |
| 468 | + ip netns exec "$ns0" nft flush chain $family nat postrouting |
| 454 | 469 | if [ $? -ne 0 ]; then |
| 455 | 470 | echo "ERROR: Could not flush $family nat postrouting" 1>&2 |
| 456 | 471 | lret=1 |
| 457 | 472 | fi |
| 458 | 473 | |
| 459 | | − test $lret -eq 0 && echo "PASS: $family IPv6 masquerade $natflags for ns2" |
| 474 | + test $lret -eq 0 && echo "PASS: $family IPv6 masquerade $natflags for $ns2" |
| 460 | 475 | |
| 461 | 476 | return $lret |
| 462 | 477 | } |
| @@ -467,26 +482,26 @@ test_masquerade() · 4 unmodified lines |
| 467 | 482 | local natflags=$2 |
| 468 | 483 | local lret=0 |
| 469 | 484 | |
| 470 | | − ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null |
| 471 | | − ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null |
| 485 | + ip netns exec "$ns0" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null |
| 486 | + ip netns exec "$ns0" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null |
| 472 | 487 | |
| 473 | | − ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 488 | + ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 474 | 489 | if [ $? -ne 0 ] ; then |
| 475 | | − echo "ERROR: cannot ping ns1 from ns2 $natflags" |
| 490 | + echo "ERROR: cannot ping $ns1 from "$ns2" $natflags" |
| 476 | 491 | lret=1 |
| 477 | 492 | fi |
| 478 | 493 | |
| 479 | 494 | expect="packets 1 bytes 84" |
| 480 | 495 | for dir in "in" "out" ; do |
| 481 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 496 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 482 | 497 | if [ $? -ne 0 ]; then |
| 483 | | − bad_counter ns1 ns2$dir "$expect" |
| 498 | + bad_counter "$ns1" ns2$dir "$expect" "test_masquerade 1" |
| 484 | 499 | lret=1 |
| 485 | 500 | fi |
| 486 | 501 | |
| 487 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 502 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 488 | 503 | if [ $? -ne 0 ]; then |
| 489 | | − bad_counter ns2 ns1$dir "$expect" |
| 504 | + bad_counter "$ns2" ns1$dir "$expect" "test_masquerade 2" |
| 490 | 505 | lret=1 |
| 491 | 506 | fi |
| 492 | 507 | done |
| @@ -494,7 +509,7 @@ test_masquerade() · 1 unmodified line |
| 494 | 509 | reset_counters |
| 495 | 510 | |
| 496 | 511 | # add masquerading rule |
| 497 | | −ip netns exec ns0 nft -f - <<EOF |
| 512 | +ip netns exec "$ns0" nft -f /dev/stdin <<EOF |
| 498 | 513 | table $family nat { |
| 499 | 514 | chain postrouting { |
| 500 | 515 | type nat hook postrouting priority 0; policy accept; |
| @@ -507,24 +522,24 @@ EOF · 6 unmodified lines |
| 507 | 522 | return $ksft_skip |
| 508 | 523 | fi |
| 509 | 524 | |
| 510 | | − ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 525 | + ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 511 | 526 | if [ $? -ne 0 ] ; then |
| 512 | | − echo "ERROR: cannot ping ns1 from ns2 with active $family masquerade $natflags" |
| 527 | + echo "ERROR: cannot ping $ns1 from $ns2 with active $family masquerade $natflags" |
| 513 | 528 | lret=1 |
| 514 | 529 | fi |
| 515 | 530 | |
| 516 | 531 | # ns1 should have seen packets from ns0, due to masquerade |
| 517 | 532 | expect="packets 1 bytes 84" |
| 518 | 533 | for dir in "in" "out" ; do |
| 519 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 534 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect") |
| 520 | 535 | if [ $? -ne 0 ]; then |
| 521 | | − bad_counter ns1 ns0$dir "$expect" |
| 536 | + bad_counter "$ns1" ns0$dir "$expect" "test_masquerade 3" |
| 522 | 537 | lret=1 |
| 523 | 538 | fi |
| 524 | 539 | |
| 525 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 540 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 526 | 541 | if [ $? -ne 0 ]; then |
| 527 | | − bad_counter ns2 ns1$dir "$expect" |
| 542 | + bad_counter "$ns2" ns1$dir "$expect" "test_masquerade 4" |
| 528 | 543 | lret=1 |
| 529 | 544 | fi |
| 530 | 545 | done |
| @@ -532,32 +547,32 @@ EOF · 1 unmodified line |
| 532 | 547 | # ns1 should not have seen packets from ns2, due to masquerade |
| 533 | 548 | expect="packets 0 bytes 0" |
| 534 | 549 | for dir in "in" "out" ; do |
| 535 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 550 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 536 | 551 | if [ $? -ne 0 ]; then |
| 537 | | − bad_counter ns1 ns0$dir "$expect" |
| 552 | + bad_counter "$ns1" ns0$dir "$expect" "test_masquerade 5" |
| 538 | 553 | lret=1 |
| 539 | 554 | fi |
| 540 | 555 | |
| 541 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 556 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 542 | 557 | if [ $? -ne 0 ]; then |
| 543 | | − bad_counter ns2 ns1$dir "$expect" |
| 558 | + bad_counter "$ns0" ns1$dir "$expect" "test_masquerade 6" |
| 544 | 559 | lret=1 |
| 545 | 560 | fi |
| 546 | 561 | done |
| 547 | 562 | |
| 548 | | − ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 563 | + ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 549 | 564 | if [ $? -ne 0 ] ; then |
| 550 | | − echo "ERROR: cannot ping ns1 from ns2 with active ip masquerade $natflags (attempt 2)" |
| 565 | + echo "ERROR: cannot ping $ns1 from $ns2 with active ip masquerade $natflags (attempt 2)" |
| 551 | 566 | lret=1 |
| 552 | 567 | fi |
| 553 | 568 | |
| 554 | | − ip netns exec ns0 nft flush chain $family nat postrouting |
| 569 | + ip netns exec "$ns0" nft flush chain $family nat postrouting |
| 555 | 570 | if [ $? -ne 0 ]; then |
| 556 | 571 | echo "ERROR: Could not flush $family nat postrouting" 1>&2 |
| 557 | 572 | lret=1 |
| 558 | 573 | fi |
| 559 | 574 | |
| 560 | | − test $lret -eq 0 && echo "PASS: $family IP masquerade $natflags for ns2" |
| 575 | + test $lret -eq 0 && echo "PASS: $family IP masquerade $natflags for $ns2" |
| 561 | 576 | |
| 562 | 577 | return $lret |
| 563 | 578 | } |
| @@ -567,25 +582,25 @@ test_redirect6() · 3 unmodified lines |
| 567 | 582 | local family=$1 |
| 568 | 583 | local lret=0 |
| 569 | 584 | |
| 570 | | − ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null |
| 585 | + ip netns exec "$ns0" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null |
| 571 | 586 | |
| 572 | | − ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 587 | + ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 573 | 588 | if [ $? -ne 0 ] ; then |
| 574 | | − echo "ERROR: cannnot ping ns1 from ns2 via ipv6" |
| 589 | + echo "ERROR: cannnot ping $ns1 from $ns2 via ipv6" |
| 575 | 590 | lret=1 |
| 576 | 591 | fi |
| 577 | 592 | |
| 578 | 593 | expect="packets 1 bytes 104" |
| 579 | 594 | for dir in "in6" "out6" ; do |
| 580 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 595 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 581 | 596 | if [ $? -ne 0 ]; then |
| 582 | | − bad_counter ns1 ns2$dir "$expect" |
| 597 | + bad_counter "$ns1" ns2$dir "$expect" "test_redirect6 1" |
| 583 | 598 | lret=1 |
| 584 | 599 | fi |
| 585 | 600 | |
| 586 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 601 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 587 | 602 | if [ $? -ne 0 ]; then |
| 588 | | − bad_counter ns2 ns1$dir "$expect" |
| 603 | + bad_counter "$ns2" ns1$dir "$expect" "test_redirect6 2" |
| 589 | 604 | lret=1 |
| 590 | 605 | fi |
| 591 | 606 | done |
| @@ -593,7 +608,7 @@ test_redirect6() · 1 unmodified line |
| 593 | 608 | reset_counters |
| 594 | 609 | |
| 595 | 610 | # add redirect rule |
| 596 | | −ip netns exec ns0 nft -f - <<EOF |
| 611 | +ip netns exec "$ns0" nft -f /dev/stdin <<EOF |
| 597 | 612 | table $family nat { |
| 598 | 613 | chain prerouting { |
| 599 | 614 | type nat hook prerouting priority 0; policy accept; |
| @@ -606,18 +621,18 @@ EOF · 6 unmodified lines |
| 606 | 621 | return $ksft_skip |
| 607 | 622 | fi |
| 608 | 623 | |
| 609 | | − ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 624 | + ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 |
| 610 | 625 | if [ $? -ne 0 ] ; then |
| 611 | | − echo "ERROR: cannot ping ns1 from ns2 via ipv6 with active $family redirect" |
| 626 | + echo "ERROR: cannot ping $ns1 from $ns2 via ipv6 with active $family redirect" |
| 612 | 627 | lret=1 |
| 613 | 628 | fi |
| 614 | 629 | |
| 615 | 630 | # ns1 should have seen no packets from ns2, due to redirection |
| 616 | 631 | expect="packets 0 bytes 0" |
| 617 | 632 | for dir in "in6" "out6" ; do |
| 618 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 633 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 619 | 634 | if [ $? -ne 0 ]; then |
| 620 | | − bad_counter ns1 ns0$dir "$expect" |
| 635 | + bad_counter "$ns1" ns0$dir "$expect" "test_redirect6 3" |
| 621 | 636 | lret=1 |
| 622 | 637 | fi |
| 623 | 638 | done |
| @@ -625,20 +640,20 @@ EOF · 1 unmodified line |
| 625 | 640 | # ns0 should have seen packets from ns2, due to masquerade |
| 626 | 641 | expect="packets 1 bytes 104" |
| 627 | 642 | for dir in "in6" "out6" ; do |
| 628 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 643 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 629 | 644 | if [ $? -ne 0 ]; then |
| 630 | | − bad_counter ns1 ns0$dir "$expect" |
| 645 | + bad_counter "$ns1" ns0$dir "$expect" "test_redirect6 4" |
| 631 | 646 | lret=1 |
| 632 | 647 | fi |
| 633 | 648 | done |
| 634 | 649 | |
| 635 | | − ip netns exec ns0 nft delete table $family nat |
| 650 | + ip netns exec "$ns0" nft delete table $family nat |
| 636 | 651 | if [ $? -ne 0 ]; then |
| 637 | 652 | echo "ERROR: Could not delete $family nat table" 1>&2 |
| 638 | 653 | lret=1 |
| 639 | 654 | fi |
| 640 | 655 | |
| 641 | | − test $lret -eq 0 && echo "PASS: $family IPv6 redirection for ns2" |
| 656 | + test $lret -eq 0 && echo "PASS: $family IPv6 redirection for $ns2" |
| 642 | 657 | |
| 643 | 658 | return $lret |
| 644 | 659 | } |
| @@ -648,26 +663,26 @@ test_redirect() · 3 unmodified lines |
| 648 | 663 | local family=$1 |
| 649 | 664 | local lret=0 |
| 650 | 665 | |
| 651 | | − ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null |
| 652 | | − ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null |
| 666 | + ip netns exec "$ns0" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null |
| 667 | + ip netns exec "$ns0" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null |
| 653 | 668 | |
| 654 | | − ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 669 | + ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 655 | 670 | if [ $? -ne 0 ] ; then |
| 656 | | − echo "ERROR: cannot ping ns1 from ns2" |
| 671 | + echo "ERROR: cannot ping $ns1 from $ns2" |
| 657 | 672 | lret=1 |
| 658 | 673 | fi |
| 659 | 674 | |
| 660 | 675 | expect="packets 1 bytes 84" |
| 661 | 676 | for dir in "in" "out" ; do |
| 662 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 677 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 663 | 678 | if [ $? -ne 0 ]; then |
| 664 | | − bad_counter ns1 ns2$dir "$expect" |
| 679 | + bad_counter "$ns1" $ns2$dir "$expect" "test_redirect 1" |
| 665 | 680 | lret=1 |
| 666 | 681 | fi |
| 667 | 682 | |
| 668 | | − cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 683 | + cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect") |
| 669 | 684 | if [ $? -ne 0 ]; then |
| 670 | | − bad_counter ns2 ns1$dir "$expect" |
| 685 | + bad_counter "$ns2" ns1$dir "$expect" "test_redirect 2" |
| 671 | 686 | lret=1 |
| 672 | 687 | fi |
| 673 | 688 | done |
| @@ -675,7 +690,7 @@ test_redirect() · 1 unmodified line |
| 675 | 690 | reset_counters |
| 676 | 691 | |
| 677 | 692 | # add redirect rule |
| 678 | | −ip netns exec ns0 nft -f - <<EOF |
| 693 | +ip netns exec "$ns0" nft -f /dev/stdin <<EOF |
| 679 | 694 | table $family nat { |
| 680 | 695 | chain prerouting { |
| 681 | 696 | type nat hook prerouting priority 0; policy accept; |
| @@ -688,9 +703,9 @@ EOF · 6 unmodified lines |
| 688 | 703 | return $ksft_skip |
| 689 | 704 | fi |
| 690 | 705 | |
| 691 | | − ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 706 | + ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 |
| 692 | 707 | if [ $? -ne 0 ] ; then |
| 693 | | − echo "ERROR: cannot ping ns1 from ns2 with active $family ip redirect" |
| 708 | + echo "ERROR: cannot ping $ns1 from $ns2 with active $family ip redirect" |
| 694 | 709 | lret=1 |
| 695 | 710 | fi |
| 696 | 711 | |
| @@ -698,9 +713,9 @@ EOF · 1 unmodified line |
| 698 | 713 | expect="packets 0 bytes 0" |
| 699 | 714 | for dir in "in" "out" ; do |
| 700 | 715 | |
| 701 | | − cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 716 | + cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 702 | 717 | if [ $? -ne 0 ]; then |
| 703 | | − bad_counter ns1 ns0$dir "$expect" |
| 718 | + bad_counter "$ns1" ns0$dir "$expect" "test_redirect 3" |
| 704 | 719 | lret=1 |
| 705 | 720 | fi |
| 706 | 721 | done |
| @@ -708,28 +723,28 @@ EOF · 1 unmodified line |
| 708 | 723 | # ns0 should have seen packets from ns2, due to masquerade |
| 709 | 724 | expect="packets 1 bytes 84" |
| 710 | 725 | for dir in "in" "out" ; do |
| 711 | | − cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 726 | + cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect") |
| 712 | 727 | if [ $? -ne 0 ]; then |
| 713 | | − bad_counter ns1 ns0$dir "$expect" |
| 728 | + bad_counter "$ns0" ns0$dir "$expect" "test_redirect 4" |
| 714 | 729 | lret=1 |
| 715 | 730 | fi |
| 716 | 731 | done |
| 717 | 732 | |
| 718 | | − ip netns exec ns0 nft delete table $family nat |
| 733 | + ip netns exec "$ns0" nft delete table $family nat |
| 719 | 734 | if [ $? -ne 0 ]; then |
| 720 | 735 | echo "ERROR: Could not delete $family nat table" 1>&2 |
| 721 | 736 | lret=1 |
| 722 | 737 | fi |
| 723 | 738 | |
| 724 | | − test $lret -eq 0 && echo "PASS: $family IP redirection for ns2" |
| 739 | + test $lret -eq 0 && echo "PASS: $family IP redirection for $ns2" |
| 725 | 740 | |
| 726 | 741 | return $lret |
| 727 | 742 | } |
| 728 | 743 | |
| 729 | 744 | |
| 730 | | −# ip netns exec ns0 ping -c 1 -q 10.0.$i.99 |
| 745 | +# ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99 |
| 731 | 746 | for i in 0 1 2; do |
| 732 | | −ip netns exec ns$i nft -f - <<EOF |
| 747 | +ip netns exec ns$i-$sfx nft -f /dev/stdin <<EOF |
| 733 | 748 | table inet filter { |
| 734 | 749 | counter ns0in {} |
| 735 | 750 | counter ns1in {} |
| @@ -796,18 +811,18 @@ done · 60 unmodified lines |
| 796 | 811 | sleep 3 |
| 797 | 812 | # test basic connectivity |
| 798 | 813 | for i in 1 2; do |
| 799 | | − ip netns exec ns0 ping -c 1 -q 10.0.$i.99 > /dev/null |
| 814 | + ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99 > /dev/null |
| 800 | 815 | if [ $? -ne 0 ];then |
| 801 | 816 | echo "ERROR: Could not reach other namespace(s)" 1>&2 |
| 802 | 817 | ret=1 |
| 803 | 818 | fi |
| 804 | 819 | |
| 805 | | − ip netns exec ns0 ping -c 1 -q dead:$i::99 > /dev/null |
| 820 | + ip netns exec "$ns0" ping -c 1 -q dead:$i::99 > /dev/null |
| 806 | 821 | if [ $? -ne 0 ];then |
| 807 | 822 | echo "ERROR: Could not reach other namespace(s) via ipv6" 1>&2 |
| 808 | 823 | ret=1 |
| 809 | 824 | fi |
| 810 | | − check_counters ns$i |
| 825 | + check_counters ns$i-$sfx |
| 811 | 826 | if [ $? -ne 0 ]; then |
| 812 | 827 | ret=1 |
| 813 | 828 | fi |
| @@ -820,7 +835,7 @@ for i in 1 2; do · 6 unmodified lines |
| 820 | 835 | done |
| 821 | 836 | |
| 822 | 837 | if [ $ret -eq 0 ];then |
| 823 | | − echo "PASS: netns routing/connectivity: ns0 can reach ns1 and ns2" |
| 838 | + echo "PASS: netns routing/connectivity: $ns0 can reach $ns1 and $ns2" |
| 824 | 839 | fi |
| 825 | 840 | |
| 826 | 841 | reset_counters |
| @@ -846,4 +861,9 @@ reset_counters · 19 unmodified lines |
| 846 | 861 | $test_inet_nat && test_redirect inet |
| 847 | 862 | $test_inet_nat && test_redirect6 inet |
| 848 | 863 | |
| 864 | +if [ $ret -ne 0 ];then |
| 865 | + echo -n "FAIL: " |
| 866 | + nft --version |
| 867 | +fi |
| 868 | + |
| 849 | 869 | exit $ret |