1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 3 # 4 source lib.sh 5 6 timeout=4m 7 ret=0 8 tmp=$(mktemp) 9 cleanup() { 10 cleanup_all_ns 11 rm -f "$tmp" 12 } 13 14 trap cleanup EXIT 15 16 maxpolicies=100000 17 [ "$KSFT_MACHINE_SLOW" = "yes" ] && maxpolicies=10000 18 19 do_dummies4() { 20 local dir="$1" 21 local max="$2" 22 23 local policies 24 local pfx 25 pfx=30 26 policies=0 27 28 ip netns exec "$ns" ip xfrm policy flush 29 30 for i in $(seq 1 100);do 31 local s 32 local d 33 for j in $(seq 1 255);do 34 s=$((i+0)) 35 d=$((i+100)) 36 37 for a in $(seq 1 8 255); do 38 policies=$((policies+1)) 39 [ "$policies" -gt "$max" ] && return 40 echo xfrm policy add src 10.$s.$j.0/30 dst 10.$d.$j.$a/$pfx dir $dir action block 41 done 42 for a in $(seq 1 8 255); do 43 policies=$((policies+1)) 44 [ "$policies" -gt "$max" ] && return 45 echo xfrm policy add src 10.$s.$j.$a/30 dst 10.$d.$j.0/$pfx dir $dir action block 46 done 47 done 48 done 49 } 50 51 setup_ns ns 52 53 do_bench() 54 { 55 local max="$1" 56 57 start=$(date +%s%3N) 58 do_dummies4 "out" "$max" > "$tmp" 59 if ! timeout "$timeout" ip netns exec "$ns" ip -batch "$tmp";then 60 echo "WARNING: policy insertion cancelled after $timeout" 61 ret=1 62 fi 63 stop=$(date +%s%3N) 64 65 result=$((stop-start)) 66 67 policies=$(wc -l < "$tmp") 68 printf "Inserted %-06s policies in $result ms\n" $policies 69 70 have=$(ip netns exec "$ns" ip xfrm policy show | grep "action block" | wc -l) 71 if [ "$have" -ne "$policies" ]; then 72 echo "WARNING: mismatch, have $have policies, expected $policies" 73 ret=1 74 fi 75 } 76 77 p=100 78 while [ $p -le "$maxpolicies" ]; do 79 do_bench "$p" 80 p="${p}0" 81 done 82 83 exit $ret
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.