1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# Double quotes to prevent globbing and word splitting is recommended in new 5# code but we accept it, especially because there were too many before having 6# address all other issues detected by shellcheck. 7#shellcheck disable=SC2086 8 9. "$(dirname "${0}")/mptcp_lib.sh" 10 11ret=0 12 13usage() { 14 echo "Usage: $0 [ -h ]" 15} 16 17optstring=h 18while getopts "$optstring" option;do 19 case "$option" in 20 "h") 21 usage $0 22 exit ${KSFT_PASS} 23 ;; 24 "?") 25 usage $0 26 exit ${KSFT_FAIL} 27 ;; 28 esac 29done 30 31ns1="" 32err=$(mktemp) 33 34# This function is used in the cleanup trap 35#shellcheck disable=SC2317 36cleanup() 37{ 38 rm -f $err 39 mptcp_lib_ns_exit "${ns1}" 40} 41 42mptcp_lib_check_mptcp 43mptcp_lib_check_tools ip 44 45trap cleanup EXIT 46 47mptcp_lib_ns_init ns1 48 49check() 50{ 51 local cmd="$1" 52 local expected="$2" 53 local msg="$3" 54 local rc=0 55 56 mptcp_lib_print_title "$msg" 57 mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?} 58 if [ ${rc} -eq 2 ]; then 59 mptcp_lib_result_fail "${msg} # error ${rc}" 60 ret=${KSFT_FAIL} 61 elif [ ${rc} -eq 0 ]; then 62 mptcp_lib_print_ok "[ OK ]" 63 mptcp_lib_result_pass "${msg}" 64 elif [ ${rc} -eq 1 ]; then 65 mptcp_lib_result_fail "${msg} # different output" 66 ret=${KSFT_FAIL} 67 fi 68} 69 70check "ip netns exec $ns1 ./pm_nl_ctl dump" "" "defaults addr list" 71 72default_limits="$(ip netns exec $ns1 ./pm_nl_ctl limits)" 73if mptcp_lib_expect_all_features; then 74 check "ip netns exec $ns1 ./pm_nl_ctl limits" "accept 0 75subflows 2" "defaults limits" 76fi 77 78ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 79ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.2 flags subflow dev lo 80ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 flags signal,backup 81check "ip netns exec $ns1 ./pm_nl_ctl get 1" "id 1 flags 10.0.1.1" "simple add/get addr" 82 83check "ip netns exec $ns1 ./pm_nl_ctl dump" \ 84"id 1 flags 10.0.1.1 85id 2 flags subflow dev lo 10.0.1.2 86id 3 flags signal,backup 10.0.1.3" "dump addrs" 87 88ip netns exec $ns1 ./pm_nl_ctl del 2 89check "ip netns exec $ns1 ./pm_nl_ctl get 2" "" "simple del addr" 90check "ip netns exec $ns1 ./pm_nl_ctl dump" \ 91"id 1 flags 10.0.1.1 92id 3 flags signal,backup 10.0.1.3" "dump addrs after del" 93 94ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 2>/dev/null 95check "ip netns exec $ns1 ./pm_nl_ctl get 4" "" "duplicate addr" 96 97ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.4 flags signal 98check "ip netns exec $ns1 ./pm_nl_ctl get 4" "id 4 flags signal 10.0.1.4" "id addr increment" 99 100for i in $(seq 5 9); do 101 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.$i flags signal >/dev/null 2>&1 102done 103check "ip netns exec $ns1 ./pm_nl_ctl get 9" "id 9 flags signal 10.0.1.9" "hard addr limit" 104check "ip netns exec $ns1 ./pm_nl_ctl get 10" "" "above hard addr limit" 105 106ip netns exec $ns1 ./pm_nl_ctl del 9 107for i in $(seq 10 255); do 108 ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.9 id $i 109 ip netns exec $ns1 ./pm_nl_ctl del $i 110done 111check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags 10.0.1.1 112id 3 flags signal,backup 10.0.1.3 113id 4 flags signal 10.0.1.4 114id 5 flags signal 10.0.1.5 115id 6 flags signal 10.0.1.6 116id 7 flags signal 10.0.1.7 117id 8 flags signal 10.0.1.8" "id limit" 118 119ip netns exec $ns1 ./pm_nl_ctl flush 120check "ip netns exec $ns1 ./pm_nl_ctl dump" "" "flush addrs" 121 122ip netns exec $ns1 ./pm_nl_ctl limits 9 1 2>/dev/null 123check "ip netns exec $ns1 ./pm_nl_ctl limits" "$default_limits" "rcv addrs above hard limit" 124 125ip netns exec $ns1 ./pm_nl_ctl limits 1 9 2>/dev/null 126check "ip netns exec $ns1 ./pm_nl_ctl limits" "$default_limits" "subflows above hard limit" 127 128ip netns exec $ns1 ./pm_nl_ctl limits 8 8 129check "ip netns exec $ns1 ./pm_nl_ctl limits" "accept 8 130subflows 8" "set limits" 131 132ip netns exec $ns1 ./pm_nl_ctl flush 133ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 134ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.2 135ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 id 100 136ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.4 137ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.5 id 254 138ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.6 139ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.7 140ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.8 141check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags 10.0.1.1 142id 2 flags 10.0.1.2 143id 3 flags 10.0.1.7 144id 4 flags 10.0.1.8 145id 100 flags 10.0.1.3 146id 101 flags 10.0.1.4 147id 254 flags 10.0.1.5 148id 255 flags 10.0.1.6" "set ids" 149 150ip netns exec $ns1 ./pm_nl_ctl flush 151ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.1 152ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.2 id 254 153ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.3 154ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.4 155ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.5 id 253 156ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.6 157ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.7 158ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.8 159check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags 10.0.0.1 160id 2 flags 10.0.0.4 161id 3 flags 10.0.0.6 162id 4 flags 10.0.0.7 163id 5 flags 10.0.0.8 164id 253 flags 10.0.0.5 165id 254 flags 10.0.0.2 166id 255 flags 10.0.0.3" "wrap-around ids" 167 168ip netns exec $ns1 ./pm_nl_ctl flush 169ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags subflow 170ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags backup 171check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ 172subflow,backup 10.0.1.1" "set flags (backup)" 173ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags nobackup 174check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ 175subflow 10.0.1.1" " (nobackup)" 176 177# fullmesh support has been added later 178ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh 2>/dev/null 179if ip netns exec $ns1 ./pm_nl_ctl dump | grep -q "fullmesh" || 180 mptcp_lib_expect_all_features; then 181 check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ 182subflow,fullmesh 10.0.1.1" " (fullmesh)" 183 ip netns exec $ns1 ./pm_nl_ctl set id 1 flags nofullmesh 184 check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ 185subflow 10.0.1.1" " (nofullmesh)" 186 ip netns exec $ns1 ./pm_nl_ctl set id 1 flags backup,fullmesh 187 check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ 188subflow,backup,fullmesh 10.0.1.1" " (backup,fullmesh)" 189else 190 for st in fullmesh nofullmesh backup,fullmesh; do 191 st=" (${st})" 192 mptcp_lib_print_title "${st}" 193 mptcp_lib_pr_skip 194 mptcp_lib_result_skip "${st}" 195 done 196fi 197 198mptcp_lib_result_print_all_tap 199exit $ret 200