1# $OpenBSD: Makefile,v 1.2 2024/04/19 22:20:36 bluhm Exp $ 2 3# Copyright (c) 2024 Alexander Bluhm <bluhm@openbsd.org> 4# 5# Permission to use, copy, modify, and distribute this software for any 6# purpose with or without fee is hereby granted, provided that the above 7# copyright notice and this permission notice appear in all copies. 8# 9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 17# Regression test for multipath routing. 18 19# Test that routes set with the -mpath flag distribute the traffic. 20# Each route has a different gateway and the UDP packets have different 21# source addresses. The destination address is identical for all 22# routes and packets. Analyze the use counter in netstat -r output 23# to check that multiple routes have been used. Currently this works 24# only for IPv4. sysctl net.inet.ip.multipath and net.inet6.ip6.multipath 25# are enabled before testing and reset afterwards. All routes and 26# interface addresses are created on loopback in a separate routing 27# domain. 28 29# Set up loopback interface in a different routing domain. 30# Create multipath routes on this loopback. 31# Send a bunch of packets with multiple source IP to same destination. 32# Count in netstart -r that most routes have been used. 33 34# This test uses routing domain and interface number 11. 35# Adjust it here, if you want to use something else. 36N1 = 11 37NUMS = ${N1} 38IPS != jot 100 100 39 40# Traffic distribution has not been implemented for IPv6. 41REGRESS_EXPECTED_FAILURES += run-netstat6 42 43.include <bsd.own.mk> 44 45.PHONY: busy-rdomains ifconfig unconfig pfctl 46 47REGRESS_SETUP_ONCE += busy-rdomains 48busy-rdomains: 49 # Check if rdomains are busy. 50.for n in ${NUMS} 51 @if /sbin/ifconfig | grep -v '^lo$n:' | grep ' rdomain $n '; then\ 52 echo routing domain $n is already used >&2; exit 1; fi 53.endfor 54 55REGRESS_SETUP_ONCE += multipath 56multipath: 57 ${SUDO} /sbin/sysctl net.inet.ip.multipath=1 58 ${SUDO} /sbin/sysctl net.inet6.ip6.multipath=1 59 60REGRESS_CLEANUP += singlepath 61singlepath: 62 ${SUDO} /sbin/sysctl net.inet.ip.multipath=0 63 ${SUDO} /sbin/sysctl net.inet6.ip6.multipath=0 64 65REGRESS_SETUP_ONCE += ifconfig 66ifconfig: unconfig 67 # Create and configure loopback interfaces. 68.for n in ${NUMS} 69 ${SUDO} /sbin/ifconfig lo$n rdomain $n 70 ${SUDO} /sbin/ifconfig lo$n inet 10.0.0.1/8 71 ${SUDO} /sbin/ifconfig lo$n inet 10.0.0.$n alias 72.for i in ${IPS} 73 ${SUDO} /sbin/ifconfig lo$n inet 10.0.$n.$i alias 74 ${SUDO} /sbin/route -n -T $n add -inet -blackhole -mpath -host \ 75 10.$n.0.0 10.0.$n.$i 76.endfor 77 ${SUDO} /sbin/ifconfig lo$n inet6 fc00::$n alias 78.for i in ${IPS} 79 ${SUDO} /sbin/ifconfig lo$n inet6 fc00::$n:$i alias 80 ${SUDO} /sbin/route -n -T $n add -inet6 -blackhole -mpath -host \ 81 fc00::$n:0:0 fc00::$n:$i 82.endfor 83 # Wait until IPv6 addresses are no longer tentative. 84 for i in `jot 50`; do\ 85 if ! /sbin/ifconfig lo$n | fgrep -q tentative; then\ 86 break;\ 87 fi;\ 88 sleep .1;\ 89 done 90 ! /sbin/ifconfig lo${N1} | fgrep tentative 91.endfor 92 93REGRESS_CLEANUP += unconfig 94unconfig: 95 # Destroy interfaces. 96.for n in ${NUMS} 97 -${SUDO} /sbin/ifconfig lo$n rdomain $n 98.for i in ${IPS} 99 -${SUDO} /sbin/route -n -T $n delete -inet6 -host \ 100 fc00::$n:0:0 fc00::$n:$i 101 -${SUDO} /sbin/route -n -T $n delete -inet -host \ 102 10.$n.0.0 10.0.$n.$i 103.endfor 104 -${SUDO} /sbin/ifconfig lo$n -inet -inet6 105 -${SUDO} /sbin/ifconfig lo$n destroy 106.endfor 107 rm -f stamp-ifconfig 108 109REGRESS_TARGETS += run-netcat 110run-netcat netstat.log: 111 # count UDP IPv6 packets used with multipath routes 112 rm -f netstat.log 113.for i in ${IPS} 114 /usr/bin/nc -4 -V${N1} -u -z -s10.0.${N1}.$i 10.${N1}.0.0 discard 115.endfor 116 /usr/bin/netstat -T${N1} -f inet -rn >netstat.log 117 118REGRESS_TARGETS += run-netstat 119run-netstat: netstat.log 120 # check route distribution of IPv4 packets 121 awk 'BEGIN{ mpath = uses = used = maxuse = 0; }\ 122 /^10.${N1}.0.0 /{\ 123 if ($$3 == "UGHSBP") mpath++;\ 124 if ($$5 > 0) used++;\ 125 if ($$5 > max) max = $$5;\ 126 uses += $$5;\ 127 }\ 128 END{\ 129 print "mpath "mpath", uses "uses", max "max", used "used;\ 130 if (mpath != 100) { print "not 100 mpath: " mpath; exit 1; }\ 131 if (uses != 100) { print "not 100 uses: " uses; exit 1; }\ 132 if (max > 30) { print "max more than 30: " max; exit 1; }\ 133 if (used < 50) { print "used less than 50: " used; exit 1; }\ 134 }' \ 135 netstat.log 136 137REGRESS_TARGETS += run-netcat6 138run-netcat6 netstat6.log: 139 # count UDP IPv6 packets used with multipath routes 140 rm -f netstat6.log 141.for i in ${IPS} 142 /usr/bin/nc -6 -V${N1} -u -z -sfc00::${N1}:$i fc00::${N1}:0:0 discard 143.endfor 144 /usr/bin/netstat -T${N1} -f inet6 -rn >netstat6.log 145 146REGRESS_TARGETS += run-netstat6 147run-netstat6: netstat6.log 148 # check route distribution of IPv6 packets 149 awk 'BEGIN{ mpath = used = uses = max = 0; }\ 150 /^fc00::${N1}:0:0 /{\ 151 if ($$3 == "UGHSBP") mpath++;\ 152 if ($$5 > 0) used++;\ 153 if ($$5 > max) max = $$5;\ 154 uses += $$5;\ 155 }\ 156 END{\ 157 print "mpath "mpath", uses "uses", max "max", used "used;\ 158 if (mpath != 100) { print "not 100 mpath: " mpath; exit 1; }\ 159 if (uses != 100) { print "not 100 uses: " uses; exit 1; }\ 160 if (max > 30) { print "max more than 30: " max; exit 1; }\ 161 if (used < 50) { print "used less than 50: " used; exit 1; }\ 162 }' \ 163 netstat6.log 164 165CLEANFILES += *.log stamp-* 166 167.include <bsd.regress.mk> 168