1# $OpenBSD: Makefile,v 1.9 2023/10/19 18:36:40 anton Exp $ 2 3# Copyright (c) 2018-2020 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# Set up two gif interfaces in different routing domains. 18# Try to ping existing addresses in these domains with various tunnels. 19 20# This test uses routing domain and interface number 11 and 12. 21# Adjust it here, if you want to use something else. 22N1 = 11 23N2 = 12 24NUMS = ${N1} ${N2} 25 26TUNNEL4_SRC_ADDR4_${N1} = 10.188.44.${N1} 27TUNNEL4_DST_ADDR4_${N1} = 10.188.44.${N2} 28TUNNEL6_SRC_ADDR4_${N1} = 10.188.64.${N1} 29TUNNEL6_DST_ADDR4_${N1} = 10.188.64.${N2} 30SRC_TUNNEL4_${N1} = 10.188.4.${N1} 31DST_TUNNEL4_${N1} = 10.188.4.${N2} 32TUNNEL4_SRC_ADDR6_${N1} = fdd7:e83e:66bc:46::${N1} 33TUNNEL4_DST_ADDR6_${N1} = fdd7:e83e:66bc:46::${N2} 34TUNNEL6_SRC_ADDR6_${N1} = fdd7:e83e:66bc:66::${N1} 35TUNNEL6_DST_ADDR6_${N1} = fdd7:e83e:66bc:66::${N2} 36SRC_TUNNEL6_${N1} = fdd7:e83e:66bc:6::${N1} 37DST_TUNNEL6_${N1} = fdd7:e83e:66bc:6::${N2} 38 39TUNNEL4_SRC_ADDR4_${N2} = ${TUNNEL4_DST_ADDR4_${N1}} 40TUNNEL4_DST_ADDR4_${N2} = ${TUNNEL4_SRC_ADDR4_${N1}} 41TUNNEL6_SRC_ADDR4_${N2} = ${TUNNEL6_DST_ADDR4_${N1}} 42TUNNEL6_DST_ADDR4_${N2} = ${TUNNEL6_SRC_ADDR4_${N1}} 43SRC_TUNNEL4_${N2} = ${DST_TUNNEL4_${N1}} 44DST_TUNNEL4_${N2} = ${SRC_TUNNEL4_${N1}} 45TUNNEL4_SRC_ADDR6_${N2} = ${TUNNEL4_DST_ADDR6_${N1}} 46TUNNEL4_DST_ADDR6_${N2} = ${TUNNEL4_SRC_ADDR6_${N1}} 47TUNNEL6_SRC_ADDR6_${N2} = ${TUNNEL6_DST_ADDR6_${N1}} 48TUNNEL6_DST_ADDR6_${N2} = ${TUNNEL6_SRC_ADDR6_${N1}} 49SRC_TUNNEL6_${N2} = ${DST_TUNNEL6_${N1}} 50DST_TUNNEL6_${N2} = ${SRC_TUNNEL6_${N1}} 51 52.include <bsd.own.mk> 53 54.if ! (make(clean) || make(cleandir) || make(obj)) 55 56SYSCTL_FORWARDING != sysctl net.inet.ip.forwarding 57.if ${SYSCTL_FORWARDING:C/.*=//} != 1 58regress: 59 @echo sysctl: "${SYSCTL_FORWARDING}" 60 @echo Set sysctl to 1 to run this regress. 61 @echo SKIPPED 62.endif 63 64PF_STATUS != ${SUDO} /sbin/pfctl -si | sed -n 's/^Status: \([^ ]*\) .*/\1/p' 65.if empty(PF_STATUS:MEnabled) 66regress: 67 @echo pf status: "${PF_STATUS}" 68 @echo Enable pf to run this regress. 69 @echo SKIPPED 70.endif 71PF_SKIP != ${SUDO} /sbin/pfctl -sI -v | sed -n 's/ (skip)//p' | \ 72 grep -w -e lo${N1} -e lo${N2} || : 73.if ! empty(PF_SKIP) 74regress: 75 @echo pf skip: "${PF_SKIP}" 76 @echo Do not set skip on interface lo, lo${N1}, or lo${N2}. 77 @echo SKIPPED 78.endif 79 80PF_ANCHOR != ${SUDO} /sbin/pfctl -sr |\ 81 sed -n 's/^anchor "\([^"]*\)" all$$/\1/p' 82.if empty(PF_ANCHOR:Mregress) 83regress: 84 @echo pf anchor: "${PF_ANCHOR}" 85 @echo Need anchor '"regress"' in pf.conf to load additional rules. 86 @echo SKIPPED 87.endif 88 89.endif 90 91.PHONY: busy-rdomains ifconfig unconfig pfctl 92 93REGRESS_SETUP_ONCE += busy-rdomains 94busy-rdomains: 95 # Check if rdomains are busy. 96.for n in ${NUMS} 97 @if /sbin/ifconfig | grep -v '^lo$n:' | grep ' rdomain $n '; then\ 98 echo routing domain $n is already used >&2; exit 1; fi 99.endfor 100 101REGRESS_SETUP_ONCE += ifconfig 102ifconfig: unconfig 103 # Create and configure loopback interfaces. 104.for n in ${NUMS} 105 ${SUDO} /sbin/ifconfig lo$n rdomain $n 106 ${SUDO} /sbin/ifconfig lo$n inet 127.0.0.1/8 107 ${SUDO} /sbin/ifconfig lo$n inet6 ::1/128 108 ${SUDO} /sbin/ifconfig lo$n inet ${SRC_TUNNEL4_$n} alias 109 ${SUDO} /sbin/ifconfig lo$n inet6 ${SRC_TUNNEL6_$n} alias 110 ${SUDO} /sbin/route -n -T $n add -inet -host ${DST_TUNNEL4_$n} 127.0.0.1 111 ${SUDO} /sbin/route -n -T $n add -inet6 -host ${DST_TUNNEL6_$n} ::1 112 ${SUDO} /sbin/ifconfig gif$n4 create rdomain $n tunneldomain $n 113 ${SUDO} /sbin/ifconfig gif$n4 tunnel ${SRC_TUNNEL4_$n} ${DST_TUNNEL4_$n} 114 ${SUDO} /sbin/ifconfig gif$n4 inet ${TUNNEL4_SRC_ADDR4_$n}/32\ 115 ${TUNNEL4_DST_ADDR4_$n} 116 ${SUDO} /sbin/ifconfig gif$n4 inet6 ${TUNNEL4_SRC_ADDR6_$n}\ 117 ${TUNNEL4_DST_ADDR6_$n} 118 ${SUDO} /sbin/ifconfig gif$n6 create rdomain $n tunneldomain $n 119 ${SUDO} /sbin/ifconfig gif$n6 tunnel ${SRC_TUNNEL6_$n}\ 120 ${DST_TUNNEL6_$n} 121 ${SUDO} /sbin/ifconfig gif$n6 inet ${TUNNEL6_SRC_ADDR4_$n}/32\ 122 ${TUNNEL6_DST_ADDR4_$n} 123 ${SUDO} /sbin/ifconfig gif$n6 inet6 ${TUNNEL6_SRC_ADDR6_$n}\ 124 ${TUNNEL6_DST_ADDR6_$n} 125.endfor 126 # Wait until IPv6 addresses are no longer tentative. 127 for i in `jot 50`; do\ 128 if ! { /sbin/ifconfig lo${N1}; /sbin/ifconfig lo${N2};\ 129 /sbin/ifconfig gif${N1}4; /sbin/ifconfig gif${N1}6;\ 130 /sbin/ifconfig gif${N2}4; /sbin/ifconfig gif${N2}6; }\ 131 | fgrep -q tentative; then\ 132 break;\ 133 fi;\ 134 sleep .1;\ 135 done 136 ! { /sbin/ifconfig lo${N1}; /sbin/ifconfig lo${N2};\ 137 /sbin/ifconfig gif${N1}4; /sbin/ifconfig gif${N1}6;\ 138 /sbin/ifconfig gif${N2}4; /sbin/ifconfig gif${N2}6; }\ 139 | fgrep -q tentative 140 141REGRESS_CLEANUP += unconfig 142unconfig: 143.for n in ${NUMS} 144 -${SUDO} /sbin/ifconfig lo$n rdomain $n 145 -${SUDO} /sbin/ifconfig lo$n inet 127.0.0.1 delete 146 -${SUDO} /sbin/ifconfig lo$n inet6 ::1 delete 147 -${SUDO} /sbin/ifconfig lo$n inet ${SRC_TUNNEL4_$n} delete 148 -${SUDO} /sbin/ifconfig lo$n inet6 ${SRC_TUNNEL6_$n} delete 149 -${SUDO} /sbin/ifconfig gif$n4 destroy 150 -${SUDO} /sbin/ifconfig gif$n6 destroy 151 -${SUDO} /sbin/ifconfig lo$n destroy 152.endfor 153 rm -f stamp-ifconfig 154 155addr.py: Makefile 156 # Create python include file containing the addresses. 157 rm -f $@ $@.tmp 158.for N in N1 N2 159 echo '${N}="${${N}}"' >>$@.tmp 160 echo 'IF_${N}="lo${${N}}"' >>$@.tmp 161 echo 'DST_TUNNEL4_${N}="${DST_TUNNEL4_${${N}}}"' >>$@.tmp 162 echo 'DST_TUNNEL6_${N}="${DST_TUNNEL6_${${N}}}"' >>$@.tmp 163.endfor 164 mv $@.tmp $@ 165 166REGRESS_SETUP_ONCE += pfctl 167pfctl: addr.py pf.conf 168 # Load the pf rules into the kernel. 169 cat addr.py ${.CURDIR}/pf.conf | /sbin/pfctl -n -f - 170 cat addr.py ${.CURDIR}/pf.conf | ${SUDO} /sbin/pfctl -a regress -f - 171 # ifconfig gif inet6 DAD created tunnel states based on old pf rules 172 ${SUDO} /sbin/pfctl -Fs 173 174.for n in ${N1} ${N2} 175 176REGRESS_TARGETS += run-ping-local-$n 177run-ping-local-$n: 178 # Ping localhost in routing domain $n. 179 /sbin/ping -n -w 1 -c 1 -V $n 127.0.0.1 180 181REGRESS_TARGETS += run-ping-src-$n 182run-ping-src-$n: 183 # Ping source address in local routing domain. SRC_TUNNEL4_$n 184 /sbin/ping -n -w 1 -c 1 -V $n ${SRC_TUNNEL4_$n} 185 186REGRESS_TARGETS += run-ping-dst-$n 187run-ping-dst-$n: 188 # Ping destination address in other routing domain. DST_TUNNEL4_$n 189 /sbin/ping -n -w 1 -c 1 -V $n ${DST_TUNNEL4_$n} 190 191REGRESS_TARGETS += run-ping-tunnel4-$n 192run-ping-tunnel4-$n: 193 # Ping IPv4 address through IPv4 tunnel. TUNNEL4_DST_ADDR4_$n 194 /sbin/ping -n -w 1 -c 1 -V $n ${TUNNEL4_DST_ADDR4_$n} 195 196REGRESS_TARGETS += run-ping-tunnel6-$n 197run-ping-tunnel6-$n: 198 # Ping IPv4 address through IPv6 tunnel. TUNNEL6_DST_ADDR4_$n 199 /sbin/ping -n -w 1 -c 1 -V $n ${TUNNEL6_DST_ADDR4_$n} 200 201REGRESS_TARGETS += run-ping6-local-$n 202run-ping6-local-$n: 203 # Ping localhost in routing domain $n. 204 /sbin/ping6 -n -w 1 -c 1 -V $n ::1 205 206REGRESS_TARGETS += run-ping6-src-$n 207run-ping6-src-$n: 208 # Ping source address in local routing domain. SRC_TUNNEL6_$n 209 /sbin/ping6 -n -w 1 -c 1 -V $n ${SRC_TUNNEL6_$n} 210 211REGRESS_TARGETS += run-ping6-dst-$n 212run-ping6-dst-$n: 213 # Ping destination address in other routing domain. DST_TUNNEL6_$n 214 /sbin/ping6 -n -w 1 -c 1 -V $n ${DST_TUNNEL6_$n} 215 216REGRESS_TARGETS += run-ping6-tunnel4-$n 217run-ping6-tunnel4-$n: 218 # Ping IPv6 address through IPv4 tunnel. TUNNEL4_DST_ADDR6_$n 219 /sbin/ping6 -n -w 1 -c 1 -V $n ${TUNNEL4_DST_ADDR6_$n} 220 221REGRESS_TARGETS += run-ping6-tunnel6-$n 222run-ping6-tunnel6-$n: 223 # Ping IPv6 address through IPv6 tunnel. TUNNEL6_DST_ADDR6_$n 224 /sbin/ping6 -n -w 1 -c 1 -V $n ${TUNNEL6_DST_ADDR6_$n} 225 226.endfor 227 228CLEANFILES += addr.py *.pyc *.log 229 230.include <bsd.regress.mk> 231