1# $OpenBSD: Makefile,v 1.2 2021/04/21 10:18:35 bluhm Exp $ 2 3# Copyright (c) 2021 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# Setup two pair(4) and one lo(4) interface in different routing 18# domains and with different interface MTU. 19 20# pair1 with MTU 8000 <-> pair2 <-> loopback3 21 22# Both pairs are patched. Between pair2 and loopback3 pf switches 23# the routing table. Do extensive ping tests to check that packets 24# get through. Use tcpbench for TCP path MTU discovery. The jumbo 25# frames with MTU 8000 together with switching the routing domain 26# trigger unusual code paths in the kernel. 27 28# This test uses routing domain 11, 12, 13. 29# Adjust it here, if you want to use something else. 30N1 = 11 31N2 = 12 32N3 = 13 33NUMS = ${N1} ${N2} ${N3} 34PAIRS = ${N1} ${N2} 35IP_${N1} = 169.254.1.${N1} 36IP6_${N1} = fc00:0:0:1::${N1} 37IP_${N2} = 169.254.1.${N2} 38IP6_${N2} = fc00:0:0:1::${N2} 39IP_${N3} = 169.254.0.${N3} 40IP6_${N3} = fc00::${N3} 41 42.include <bsd.own.mk> 43 44.if ! (make(clean) || make(cleandir) || make(obj)) 45 46SYSCTL_FORWARDING != sysctl net.inet.ip.forwarding 47SYSCTL_FORWARDING6 != sysctl net.inet6.ip6.forwarding 48.if ${SYSCTL_FORWARDING:C/.*=//} != 1 || ${SYSCTL_FORWARDING6:C/.*=//} != 1 49regress: 50 @echo sysctl: "${SYSCTL_FORWARDING}" "${SYSCTL_FORWARDING6}" 51 @echo Set sysctl to 1 to run this regress. 52 @echo SKIPPED 53.endif 54 55PF_STATUS != ${SUDO} pfctl -si | sed -n 's/^Status: \([^ ]*\) .*/\1/p' 56.if empty(PF_STATUS:MEnabled) 57regress: 58 @echo pf status: "${PF_STATUS}" 59 @echo Enable pf to run this regress. 60 @echo SKIPPED 61.endif 62 63PF_SKIP != ${SUDO} pfctl -sI -v | sed -n 's/ (skip)//p' 64.if ! empty(PF_SKIP:Mlo*:Nlo0) 65regress: 66 @echo pf skip: "${PF_SKIP}" 67 @echo Do not set skip on interface lo or lo$N. 68 @echo SKIPPED 69.endif 70 71PF_ANCHOR != ${SUDO} pfctl -sr | sed -n 's/^anchor "\([^"]*\)" all$$/\1/p' 72.if empty(PF_ANCHOR:Mregress) 73regress: 74 @echo pf anchor: "${PF_ANCHOR}" 75 @echo Need anchor '"regress"' in pf.conf to load additional rules. 76 @echo SKIPPED 77.endif 78 79.endif 80 81.PHONY: ifconfig unconfig pfctl 82 83REGRESS_SETUP_ONCE += ifconfig 84ifconfig: unconfig 85 # Create and configure pflog and loopback interfaces. 86.for n in ${NUMS} 87 ${SUDO} ifconfig lo$n rdomain $n 88 ${SUDO} ifconfig lo$n inet 127.0.0.1/8 89 ${SUDO} ifconfig lo$n inet6 ::1/128 90 ${SUDO} route -n -T $n add -inet 169.254.0.0/16 127.0.0.1 91 ${SUDO} route -n -T $n add -inet6 fc00::/48 ::1 92.endfor 93.for n in ${PAIRS} 94 ${SUDO} ifconfig pair$n rdomain $n 95 ${SUDO} ifconfig pair$n inet ${IP_$n}/24 96 ${SUDO} ifconfig pair$n inet6 ${IP6_$n}/64 97.endfor 98 ${SUDO} ifconfig pair${N1} patch pair${N2} 99 ${SUDO} ifconfig lo${N3} inet ${IP_${N3}}/24 alias 100 ${SUDO} ifconfig lo${N3} inet6 ${IP6_${N3}}/64 101 ${SUDO} ifconfig pair${N1} mtu 8000 102 ${SUDO} route -n -T ${N1} add -inet ${IP_${N3}} ${IP_${N2}} 103 ${SUDO} route -n -T ${N1} add -inet6 ${IP6_${N3}} ${IP6_${N2}} 104 # Wait until IPv6 addresses are no longer tentative. 105 for i in `jot 50`; do\ 106 if ! { ifconfig pair${N1}; ifconfig pair${N2}; ifconfig lo${N3}; }\ 107 | fgrep -q tentative; then\ 108 break;\ 109 fi;\ 110 sleep .1;\ 111 done 112 ! { ifconfig pair${N1}; ifconfig pair${N2}; ifconfig lo${N3};}\ 113 | fgrep tentative 114 115REGRESS_CLEANUP += unconfig 116unconfig: 117 # Destroy interfaces. 118 -${SUDO} route -n -T ${N1} delete -inet ${IP_${N3}} 119 -${SUDO} route -n -T ${N1} delete -inet6 ${IP6_${N3}} 120 -${SUDO} ifconfig lo${N3} inet ${IP_${N3}} delete 121 -${SUDO} ifconfig lo${N3} inet6 ${IP6_${N3}} delete 122.for n in ${PAIRS} 123 -${SUDO} ifconfig pair$n destroy 124.endfor 125.for n in ${NUMS} 126 -${SUDO} route -n -T $n delete -inet 169.254.0.0/16 127 -${SUDO} route -n -T $n delete -inet6 fc00::/48 128 -${SUDO} ifconfig lo$n inet 127.0.0.1 delete 129 -${SUDO} ifconfig lo$n inet6 ::1 delete 130.endfor 131 rm -f stamp-ifconfig 132 133addr.py: Makefile 134 # Create python include file containing the addresses. 135 rm -f $@ $@.tmp 136.for var in N1 N2 N3 137 echo '${var}="${${var}}"' >>$@.tmp 138 echo 'LO_${var}="lo${${var}}"' >>$@.tmp 139 echo 'PAIR_${var}="pair${${var}}"' >>$@.tmp 140 echo 'IP_${var}="${IP_${${var}}}"' >>$@.tmp 141 echo 'IP6_${var}="${IP6_${${var}}}"' >>$@.tmp 142.endfor 143 mv $@.tmp $@ 144 145REGRESS_SETUP_ONCE += pfctl 146pfctl: addr.py pf.conf 147 # Load the pf rules into the kernel. 148 cat addr.py ${.CURDIR}/pf.conf | /sbin/pfctl -n -f - 149 cat addr.py ${.CURDIR}/pf.conf | ${SUDO} pfctl -a regress -f - 150 151.for f in 1 2 3 152.for t in 1 2 3 153REGRESS_TARGETS += run-ping-$f-$t 154run-ping-$f-$t: 155 ping -c 1 -w 1 -n -V ${N$f} -I ${IP_${N$f}} ${IP_${N$t}} 156 157REGRESS_TARGETS += run-ping6-$f-$t 158run-ping6-$f-$t: 159 ping6 -c 1 -w 1 -n -V ${N$f} -I ${IP6_${N$f}} ${IP6_${N$t}} 160 161REGRESS_TARGETS += run-tcpbench-$f-$t 162run-tcpbench-$f-$t: 163 rm -f nc.log 164 nc -4 -v -l -V ${N$t} ${IP_${N$t}} 12345 >/dev/null 2>nc.log & 165 # Wait until nc is listening. 166 for i in `jot 30`; do\ 167 if fgrep -q Listening nc.log; then break; fi; sleep .1; done 168 fgrep Listening nc.log 169 # Test that path MTU dicovery is working. 170 tcpbench -4 -t 5 -V ${N$f} -b ${IP_${N$f}} ${IP_${N$t}} 171.if $f == "3" && $t == "1" 172 # path MTU discovery must create a dynamic route 173 route -T ${N$f} -n get -host -inet ${IP_${N$t}} | grep DYNAMIC 174.endif 175 176REGRESS_TARGETS += run-tcpbench6-$f-$t 177run-tcpbench6-$f-$t: 178 rm -f nc.log 179 nc -6 -v -l -V ${N$t} ${IP6_${N$t}} 12345 >/dev/null 2>nc.log & 180 # Wait until nc is listening. 181 for i in `jot 30`; do\ 182 if fgrep -q Listening nc.log; then break; fi; sleep .1; done 183 fgrep Listening nc.log 184 # Test that path MTU dicovery is working. 185 tcpbench -6 -t 5 -V ${N$f} -b ${IP6_${N$f}} ${IP6_${N$t}} 186.if $f == "3" && $t == "1" 187 # path MTU discovery in other rtable does not work in ip6_output() 188 route -T ${N$f} -n get -host -inet6 ${IP6_${N$t}} 189 @echo DISABLED 190.endif 191 192.endfor 193.endfor 194 195CLEANFILES += addr.py *.pyc *.log stamp-* 196 197.include <bsd.regress.mk> 198