0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 ksft_skip=4
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 ALPHA=(
0132 1
0133 11111111
0134 0xffff
0135 0xffffffff
0136 101
0137 101101
0138 0xdeadbee0
0139 0xcafec0caf00dc0de
0140 777
0141 "something that will be 4n-aligned"
0142 )
0143
0144 BETA=(
0145 2
0146 22222222
0147 201
0148 201201
0149 202
0150 202202
0151 0xdeadbee1
0152 0xcafec0caf11dc0de
0153 666
0154 "Hello there -Obi"
0155 )
0156
0157 GAMMA=(
0158 3
0159 33333333
0160 301
0161 301301
0162 0xffff
0163 0xffffffff
0164 0xdeadbee2
0165 0xcafec0caf22dc0de
0166 0xffffff
0167 ""
0168 )
0169
0170 TESTS_OUTPUT="
0171 out_undef_ns
0172 out_no_room
0173 out_bits
0174 out_full_supp_trace
0175 "
0176
0177 TESTS_INPUT="
0178 in_undef_ns
0179 in_no_room
0180 in_oflag
0181 in_bits
0182 in_full_supp_trace
0183 "
0184
0185 TESTS_GLOBAL="
0186 fwd_full_supp_trace
0187 "
0188
0189
0190
0191
0192
0193
0194
0195
0196 check_kernel_compatibility()
0197 {
0198 ip netns add ioam-tmp-node
0199 ip link add name veth0 netns ioam-tmp-node type veth \
0200 peer name veth1 netns ioam-tmp-node
0201
0202 ip -netns ioam-tmp-node link set veth0 up
0203 ip -netns ioam-tmp-node link set veth1 up
0204
0205 ip -netns ioam-tmp-node ioam namespace add 0
0206 ns_ad=$?
0207
0208 ip -netns ioam-tmp-node ioam namespace show | grep -q "namespace 0"
0209 ns_sh=$?
0210
0211 if [[ $ns_ad != 0 || $ns_sh != 0 ]]
0212 then
0213 echo "SKIP: kernel version probably too old, missing ioam support"
0214 ip link del veth0 2>/dev/null || true
0215 ip netns del ioam-tmp-node || true
0216 exit $ksft_skip
0217 fi
0218
0219 ip -netns ioam-tmp-node route add db02::/64 encap ioam6 mode inline \
0220 trace prealloc type 0x800000 ns 0 size 4 dev veth0
0221 tr_ad=$?
0222
0223 ip -netns ioam-tmp-node -6 route | grep -q "encap ioam6"
0224 tr_sh=$?
0225
0226 if [[ $tr_ad != 0 || $tr_sh != 0 ]]
0227 then
0228 echo "SKIP: cannot attach an ioam trace to a route, did you compile" \
0229 "without CONFIG_IPV6_IOAM6_LWTUNNEL?"
0230 ip link del veth0 2>/dev/null || true
0231 ip netns del ioam-tmp-node || true
0232 exit $ksft_skip
0233 fi
0234
0235 ip link del veth0 2>/dev/null || true
0236 ip netns del ioam-tmp-node || true
0237
0238 lsmod | grep -q "ip6_tunnel"
0239 ip6tnl_loaded=$?
0240
0241 if [ $ip6tnl_loaded = 0 ]
0242 then
0243 encap_tests=0
0244 else
0245 modprobe ip6_tunnel &>/dev/null
0246 lsmod | grep -q "ip6_tunnel"
0247 encap_tests=$?
0248
0249 if [ $encap_tests != 0 ]
0250 then
0251 ip a | grep -q "ip6tnl0"
0252 encap_tests=$?
0253
0254 if [ $encap_tests != 0 ]
0255 then
0256 echo "Note: ip6_tunnel not found neither as a module nor inside the" \
0257 "kernel, tests that require it (encap mode) will be omitted"
0258 fi
0259 fi
0260 fi
0261 }
0262
0263 cleanup()
0264 {
0265 ip link del ioam-veth-alpha 2>/dev/null || true
0266 ip link del ioam-veth-gamma 2>/dev/null || true
0267
0268 ip netns del ioam-node-alpha || true
0269 ip netns del ioam-node-beta || true
0270 ip netns del ioam-node-gamma || true
0271
0272 if [ $ip6tnl_loaded != 0 ]
0273 then
0274 modprobe -r ip6_tunnel 2>/dev/null || true
0275 fi
0276 }
0277
0278 setup()
0279 {
0280 ip netns add ioam-node-alpha
0281 ip netns add ioam-node-beta
0282 ip netns add ioam-node-gamma
0283
0284 ip link add name ioam-veth-alpha netns ioam-node-alpha type veth \
0285 peer name ioam-veth-betaL netns ioam-node-beta
0286 ip link add name ioam-veth-betaR netns ioam-node-beta type veth \
0287 peer name ioam-veth-gamma netns ioam-node-gamma
0288
0289 ip -netns ioam-node-alpha link set ioam-veth-alpha name veth0
0290 ip -netns ioam-node-beta link set ioam-veth-betaL name veth0
0291 ip -netns ioam-node-beta link set ioam-veth-betaR name veth1
0292 ip -netns ioam-node-gamma link set ioam-veth-gamma name veth0
0293
0294 ip -netns ioam-node-alpha addr add db01::2/64 dev veth0
0295 ip -netns ioam-node-alpha link set veth0 up
0296 ip -netns ioam-node-alpha link set lo up
0297 ip -netns ioam-node-alpha route add db02::/64 via db01::1 dev veth0
0298 ip -netns ioam-node-alpha route del db01::/64
0299 ip -netns ioam-node-alpha route add db01::/64 dev veth0
0300
0301 ip -netns ioam-node-beta addr add db01::1/64 dev veth0
0302 ip -netns ioam-node-beta addr add db02::1/64 dev veth1
0303 ip -netns ioam-node-beta link set veth0 up
0304 ip -netns ioam-node-beta link set veth1 up
0305 ip -netns ioam-node-beta link set lo up
0306
0307 ip -netns ioam-node-gamma addr add db02::2/64 dev veth0
0308 ip -netns ioam-node-gamma link set veth0 up
0309 ip -netns ioam-node-gamma link set lo up
0310 ip -netns ioam-node-gamma route add db01::/64 via db02::1 dev veth0
0311
0312
0313 ip netns exec ioam-node-alpha sysctl -wq net.ipv6.ioam6_id=${ALPHA[0]}
0314 ip netns exec ioam-node-alpha sysctl -wq net.ipv6.ioam6_id_wide=${ALPHA[1]}
0315 ip netns exec ioam-node-alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id=${ALPHA[4]}
0316 ip netns exec ioam-node-alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${ALPHA[5]}
0317 ip -netns ioam-node-alpha ioam namespace add 123 data ${ALPHA[6]} wide ${ALPHA[7]}
0318 ip -netns ioam-node-alpha ioam schema add ${ALPHA[8]} "${ALPHA[9]}"
0319 ip -netns ioam-node-alpha ioam namespace set 123 schema ${ALPHA[8]}
0320
0321 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.all.forwarding=1
0322 ip netns exec ioam-node-beta sysctl -wq net.ipv6.ioam6_id=${BETA[0]}
0323 ip netns exec ioam-node-beta sysctl -wq net.ipv6.ioam6_id_wide=${BETA[1]}
0324 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
0325 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_id=${BETA[2]}
0326 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${BETA[3]}
0327 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth1.ioam6_id=${BETA[4]}
0328 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth1.ioam6_id_wide=${BETA[5]}
0329 ip -netns ioam-node-beta ioam namespace add 123 data ${BETA[6]} wide ${BETA[7]}
0330 ip -netns ioam-node-beta ioam schema add ${BETA[8]} "${BETA[9]}"
0331 ip -netns ioam-node-beta ioam namespace set 123 schema ${BETA[8]}
0332
0333 ip netns exec ioam-node-gamma sysctl -wq net.ipv6.ioam6_id=${GAMMA[0]}
0334 ip netns exec ioam-node-gamma sysctl -wq net.ipv6.ioam6_id_wide=${GAMMA[1]}
0335 ip netns exec ioam-node-gamma sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
0336 ip netns exec ioam-node-gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id=${GAMMA[2]}
0337 ip netns exec ioam-node-gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${GAMMA[3]}
0338 ip -netns ioam-node-gamma ioam namespace add 123 data ${GAMMA[6]} wide ${GAMMA[7]}
0339
0340 sleep 1
0341
0342 ip netns exec ioam-node-alpha ping6 -c 5 -W 1 db02::2 &>/dev/null
0343 if [ $? != 0 ]
0344 then
0345 echo "Setup FAILED"
0346 cleanup &>/dev/null
0347 exit 0
0348 fi
0349 }
0350
0351 log_test_passed()
0352 {
0353 local desc=$1
0354 printf "TEST: %-60s [ OK ]\n" "${desc}"
0355 }
0356
0357 log_test_failed()
0358 {
0359 local desc=$1
0360 printf "TEST: %-60s [FAIL]\n" "${desc}"
0361 }
0362
0363 log_results()
0364 {
0365 echo "- Tests passed: ${npassed}"
0366 echo "- Tests failed: ${nfailed}"
0367 }
0368
0369 run_test()
0370 {
0371 local name=$1
0372 local desc=$2
0373 local node_src=$3
0374 local node_dst=$4
0375 local ip6_src=$5
0376 local ip6_dst=$6
0377 local if_dst=$7
0378 local trace_type=$8
0379 local ioam_ns=$9
0380
0381 ip netns exec $node_dst ./ioam6_parser $if_dst $name $ip6_src $ip6_dst \
0382 $trace_type $ioam_ns &
0383 local spid=$!
0384 sleep 0.1
0385
0386 ip netns exec $node_src ping6 -t 64 -c 1 -W 1 $ip6_dst &>/dev/null
0387 if [ $? != 0 ]
0388 then
0389 nfailed=$((nfailed+1))
0390 log_test_failed "${desc}"
0391 kill -2 $spid &>/dev/null
0392 else
0393 wait $spid
0394 if [ $? = 0 ]
0395 then
0396 npassed=$((npassed+1))
0397 log_test_passed "${desc}"
0398 else
0399 nfailed=$((nfailed+1))
0400 log_test_failed "${desc}"
0401 fi
0402 fi
0403 }
0404
0405 run()
0406 {
0407 echo
0408 printf "%0.s-" {1..74}
0409 echo
0410 echo "OUTPUT tests"
0411 printf "%0.s-" {1..74}
0412 echo
0413
0414
0415 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=0
0416
0417 for t in $TESTS_OUTPUT
0418 do
0419 $t "inline"
0420 [ $encap_tests = 0 ] && $t "encap"
0421 done
0422
0423
0424 ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
0425 ip -netns ioam-node-alpha route change db01::/64 dev veth0
0426
0427
0428 echo
0429 printf "%0.s-" {1..74}
0430 echo
0431 echo "INPUT tests"
0432 printf "%0.s-" {1..74}
0433 echo
0434
0435
0436 ip -netns ioam-node-alpha ioam namespace del 123
0437
0438 for t in $TESTS_INPUT
0439 do
0440 $t "inline"
0441 [ $encap_tests = 0 ] && $t "encap"
0442 done
0443
0444
0445 ip -netns ioam-node-alpha ioam namespace add 123 \
0446 data ${ALPHA[6]} wide ${ALPHA[7]}
0447 ip -netns ioam-node-alpha ioam namespace set 123 schema ${ALPHA[8]}
0448 ip -netns ioam-node-alpha route change db01::/64 dev veth0
0449
0450 echo
0451 printf "%0.s-" {1..74}
0452 echo
0453 echo "GLOBAL tests"
0454 printf "%0.s-" {1..74}
0455 echo
0456
0457 for t in $TESTS_GLOBAL
0458 do
0459 $t "inline"
0460 [ $encap_tests = 0 ] && $t "encap"
0461 done
0462
0463 echo
0464 log_results
0465 }
0466
0467 bit2type=(
0468 0x800000 0x400000 0x200000 0x100000 0x080000 0x040000 0x020000 0x010000
0469 0x008000 0x004000 0x002000 0x001000 0x000800 0x000400 0x000200 0x000100
0470 0x000080 0x000040 0x000020 0x000010 0x000008 0x000004 0x000002
0471 )
0472 bit2size=( 4 4 4 4 4 4 4 4 8 8 8 4 4 4 4 4 4 4 4 4 4 4 4 )
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482 out_undef_ns()
0483 {
0484
0485
0486
0487
0488 local desc="Unknown IOAM namespace"
0489
0490 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0491 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0492
0493 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0494 trace prealloc type 0x800000 ns 0 size 4 dev veth0
0495
0496 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0497 db01::2 db01::1 veth0 0x800000 0
0498
0499 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0500 }
0501
0502 out_no_room()
0503 {
0504
0505
0506
0507
0508 local desc="Missing trace room"
0509
0510 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0511 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0512
0513 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0514 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
0515
0516 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0517 db01::2 db01::1 veth0 0xc00000 123
0518
0519 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0520 }
0521
0522 out_bits()
0523 {
0524
0525
0526
0527
0528
0529 local desc="Trace type with bit <n> only"
0530
0531 local tmp=${bit2size[22]}
0532 bit2size[22]=$(( $tmp + ${
0533
0534 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0535 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0536
0537 for i in {0..22}
0538 do
0539 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0540 trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
0541 dev veth0 &>/dev/null
0542
0543 local cmd_res=$?
0544 local descr="${desc/<n>/$i}"
0545
0546 if [[ $i -ge 12 && $i -le 21 ]]
0547 then
0548 if [ $cmd_res != 0 ]
0549 then
0550 npassed=$((npassed+1))
0551 log_test_passed "$descr"
0552 else
0553 nfailed=$((nfailed+1))
0554 log_test_failed "$descr"
0555 fi
0556 else
0557 run_test "out_bit$i" "$descr ($1 mode)" ioam-node-alpha \
0558 ioam-node-beta db01::2 db01::1 veth0 ${bit2type[$i]} 123
0559 fi
0560 done
0561
0562 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0563
0564 bit2size[22]=$tmp
0565 }
0566
0567 out_full_supp_trace()
0568 {
0569
0570
0571
0572
0573 local desc="Full supported trace"
0574
0575 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0576 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0577
0578 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0579 trace prealloc type 0xfff002 ns 123 size 100 dev veth0
0580
0581 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0582 db01::2 db01::1 veth0 0xfff002 123
0583
0584 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0585 }
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597 in_undef_ns()
0598 {
0599
0600
0601
0602
0603 local desc="Unknown IOAM namespace"
0604
0605 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0606 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0607
0608 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0609 trace prealloc type 0x800000 ns 0 size 4 dev veth0
0610
0611 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0612 db01::2 db01::1 veth0 0x800000 0
0613
0614 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0615 }
0616
0617 in_no_room()
0618 {
0619
0620
0621
0622
0623 local desc="Missing trace room"
0624
0625 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0626 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0627
0628 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0629 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
0630
0631 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0632 db01::2 db01::1 veth0 0xc00000 123
0633
0634 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0635 }
0636
0637 in_bits()
0638 {
0639
0640
0641
0642
0643
0644 local desc="Trace type with bit <n> only"
0645
0646 local tmp=${bit2size[22]}
0647 bit2size[22]=$(( $tmp + ${
0648
0649 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0650 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0651
0652 for i in {0..11} {22..22}
0653 do
0654 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0655 trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
0656 dev veth0
0657
0658 run_test "in_bit$i" "${desc/<n>/$i} ($1 mode)" ioam-node-alpha \
0659 ioam-node-beta db01::2 db01::1 veth0 ${bit2type[$i]} 123
0660 done
0661
0662 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0663
0664 bit2size[22]=$tmp
0665 }
0666
0667 in_oflag()
0668 {
0669
0670
0671
0672
0673 local desc="Overflow flag is set"
0674
0675
0676
0677
0678 ip -netns ioam-node-alpha ioam namespace add 123
0679
0680 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0681 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0682
0683 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0684 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
0685
0686 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0687 db01::2 db01::1 veth0 0xc00000 123
0688
0689 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0690
0691
0692
0693 ip -netns ioam-node-alpha ioam namespace del 123
0694 }
0695
0696 in_full_supp_trace()
0697 {
0698
0699
0700
0701
0702 local desc="Full supported trace"
0703
0704 [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
0705 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
0706
0707 ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
0708 trace prealloc type 0xfff002 ns 123 size 80 dev veth0
0709
0710 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
0711 db01::2 db01::1 veth0 0xfff002 123
0712
0713 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
0714 }
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724 fwd_full_supp_trace()
0725 {
0726
0727
0728
0729
0730 local desc="Forward - Full supported trace"
0731
0732 [ "$1" = "encap" ] && mode="$1 tundst db02::2" || mode="$1"
0733 [ "$1" = "encap" ] && ip -netns ioam-node-gamma link set ip6tnl0 up
0734
0735 ip -netns ioam-node-alpha route change db02::/64 encap ioam6 mode $mode \
0736 trace prealloc type 0xfff002 ns 123 size 244 via db01::1 dev veth0
0737
0738 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-gamma \
0739 db01::2 db02::2 veth0 0xfff002 123
0740
0741 [ "$1" = "encap" ] && ip -netns ioam-node-gamma link set ip6tnl0 down
0742 }
0743
0744
0745
0746
0747
0748
0749
0750
0751 npassed=0
0752 nfailed=0
0753
0754 if [ "$(id -u)" -ne 0 ]
0755 then
0756 echo "SKIP: Need root privileges"
0757 exit $ksft_skip
0758 fi
0759
0760 if [ ! -x "$(command -v ip)" ]
0761 then
0762 echo "SKIP: Could not run test without ip tool"
0763 exit $ksft_skip
0764 fi
0765
0766 ip ioam &>/dev/null
0767 if [ $? = 1 ]
0768 then
0769 echo "SKIP: iproute2 too old, missing ioam command"
0770 exit $ksft_skip
0771 fi
0772
0773 check_kernel_compatibility
0774
0775 cleanup &>/dev/null
0776 setup
0777 run
0778 cleanup &>/dev/null