1# $OpenBSD: Makefile,v 1.4 2020/01/08 21:28:00 bluhm 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 doamin 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} 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} pfctl -sI -v | sed -n 's/ (skip)//p' 72.if ! empty(PF_SKIP:Mlo*:Nlo0) 73regress: 74 @echo pf skip: "${PF_SKIP}" 75 @echo Do not set skip on interface lo, lo${N1}, or lo${N2}. 76 @echo SKIPPED 77.endif 78 79PF_ANCHOR != ${SUDO} pfctl -sr | sed -n 's/^anchor "\([^"]*\)" all$$/\1/p' 80.if empty(PF_ANCHOR:Mregress) 81regress: 82 @echo pf anchor: "${PF_ANCHOR}" 83 @echo Need anchor '"regress"' in pf.conf to load additional rules. 84 @echo SKIPPED 85.endif 86 87.endif 88 89.PHONY: busy-rdomains ifconfig unconfig 90 91busy-rdomains: 92 # check if rdomains are busy 93.for n in ${NUMS} 94 @if /sbin/ifconfig | grep -v '^lo${n}:' | grep ' rdomain ${n} '; then\ 95 echo routing domain ${n} is already used >&2; exit 1; fi 96.endfor 97 98ifconfig: unconfig 99 # create and configure loopback interfaces 100.for n in ${NUMS} 101 ${SUDO} ifconfig lo${n} rdomain ${n} 102 ${SUDO} ifconfig lo${n} inet 127.0.0.1/8 103 ${SUDO} ifconfig lo${n} inet6 ::1/128 104 ${SUDO} ifconfig lo${n} inet ${SRC_TUNNEL4_${n}} alias 105 ${SUDO} ifconfig lo${n} inet6 ${SRC_TUNNEL6_${n}} alias 106 ${SUDO} route -n -T ${n} add -inet -host ${DST_TUNNEL4_${n}} 127.0.0.1 107 ${SUDO} route -n -T ${n} add -inet6 -host ${DST_TUNNEL6_${n}} ::1 108 ${SUDO} ifconfig gif${n}4 create rdomain ${n} tunneldomain ${n} 109 ${SUDO} ifconfig gif${n}4 tunnel ${SRC_TUNNEL4_${n}} ${DST_TUNNEL4_${n}} 110 ${SUDO} ifconfig gif${n}4 inet ${TUNNEL4_SRC_ADDR4_${n}}/32\ 111 ${TUNNEL4_DST_ADDR4_${n}} 112 ${SUDO} ifconfig gif${n}4 inet6 ${TUNNEL4_SRC_ADDR6_${n}}\ 113 ${TUNNEL4_DST_ADDR6_${n}} 114 ${SUDO} ifconfig gif${n}6 create rdomain ${n} tunneldomain ${n} 115 ${SUDO} ifconfig gif${n}6 tunnel ${SRC_TUNNEL6_${n}}\ 116 ${DST_TUNNEL6_${n}} 117 ${SUDO} ifconfig gif${n}6 inet ${TUNNEL6_SRC_ADDR4_${n}}/32\ 118 ${TUNNEL6_DST_ADDR4_${n}} 119 ${SUDO} ifconfig gif${n}6 inet6 ${TUNNEL6_SRC_ADDR6_${n}}\ 120 ${TUNNEL6_DST_ADDR6_${n}} 121.endfor 122 123unconfig: 124 # destroy interfaces, keep lo as routing domain cannot be destroyed 125.for n in ${NUMS} 126 -${SUDO} ifconfig lo${n} rdomain ${n} 127 -${SUDO} ifconfig lo${n} inet 127.0.0.1 delete 128 -${SUDO} ifconfig lo${n} inet6 ::1 delete 129 -${SUDO} ifconfig lo${n} inet ${SRC_TUNNEL4_${n}} delete 130 -${SUDO} ifconfig lo${n} inet6 ${SRC_TUNNEL6_${n}} delete 131 -${SUDO} ifconfig gif${n}4 destroy 132 -${SUDO} ifconfig gif${n}6 destroy 133.endfor 134 rm -f stamp-setup 135 136stamp-setup: Makefile 137 @echo '\n======== $@ ========' 138 ${.MAKE} -C ${.CURDIR} busy-rdomains ifconfig 139 # wait until DAD for inet6 tunnel addresses has finished 140 sleep 1 141 date >$@ 142 143# Create python include file containing the addresses. 144addr.py: Makefile 145 rm -f $@ $@.tmp 146.for N in N1 N2 147 echo '${N}="${${N}}"' >>$@.tmp 148 echo 'IF_${N}="lo${${N}}"' >>$@.tmp 149 echo 'DST_TUNNEL4_${N}="${DST_TUNNEL4_${${N}}}"' >>$@.tmp 150 echo 'DST_TUNNEL6_${N}="${DST_TUNNEL6_${${N}}}"' >>$@.tmp 151.endfor 152 mv $@.tmp $@ 153 154# Load the pf rules into the kernel. 155stamp-pfctl: addr.py pf.conf stamp-setup 156 @echo '\n======== $@ ========' 157 cat addr.py ${.CURDIR}/pf.conf | /sbin/pfctl -n -f - 158 cat addr.py ${.CURDIR}/pf.conf | ${SUDO} pfctl -a regress -f - 159 # ifconfig gif inet6 DAD created tunnel states based on old pf rules 160 ${SUDO} /sbin/pfctl -Fs 161 @date >$@ 162 163.for n in ${N1} ${N2} 164 165REGRESS_TARGETS += run-regress-ping-local-${n} 166run-regress-ping-local-${n}: stamp-setup stamp-pfctl 167 @echo '\n======== $@ ========' 168 # Ping localhost in routing domain ${n}. 169 /sbin/ping -n -w 1 -c 1 -V ${n} 127.0.0.1 170 171REGRESS_TARGETS += run-regress-ping-src-${n} 172run-regress-ping-src-${n}: stamp-setup stamp-pfctl 173 @echo '\n======== $@ ========' 174 # Ping source address in local routing domain. SRC_TUNNEL4_${n} 175 /sbin/ping -n -w 1 -c 1 -V ${n} ${SRC_TUNNEL4_${n}} 176 177REGRESS_TARGETS += run-regress-ping-dst-${n} 178run-regress-ping-dst-${n}: stamp-setup stamp-pfctl 179 @echo '\n======== $@ ========' 180 # Ping destination address in other routing domain. DST_TUNNEL4_${n} 181 /sbin/ping -n -w 1 -c 1 -V ${n} ${DST_TUNNEL4_${n}} 182 183REGRESS_TARGETS += run-regress-ping-tunnel4-${n} 184run-regress-ping-tunnel4-${n}: stamp-setup stamp-pfctl 185 @echo '\n======== $@ ========' 186 # Ping IPv4 address through IPv4 tunnel. TUNNEL4_DST_ADDR4_${n} 187 /sbin/ping -n -w 1 -c 1 -V ${n} ${TUNNEL4_DST_ADDR4_${n}} 188 189REGRESS_TARGETS += run-regress-ping-tunnel6-${n} 190run-regress-ping-tunnel6-${n}: stamp-setup stamp-pfctl 191 @echo '\n======== $@ ========' 192 # Ping IPv4 address through IPv6 tunnel. TUNNEL6_DST_ADDR4_${n} 193 /sbin/ping -n -w 1 -c 1 -V ${n} ${TUNNEL6_DST_ADDR4_${n}} 194 195REGRESS_TARGETS += run-regress-ping6-local-${n} 196run-regress-ping6-local-${n}: stamp-setup stamp-pfctl 197 @echo '\n======== $@ ========' 198 # Ping localhost in routing domain ${n}. 199 /sbin/ping6 -n -w 1 -c 1 -V ${n} ::1 200 201REGRESS_TARGETS += run-regress-ping6-src-${n} 202run-regress-ping6-src-${n}: stamp-setup stamp-pfctl 203 @echo '\n======== $@ ========' 204 # Ping source address in local routing domain. SRC_TUNNEL6_${n} 205 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${SRC_TUNNEL6_${n}} 206 207REGRESS_TARGETS += run-regress-ping6-dst-${n} 208run-regress-ping6-dst-${n}: stamp-setup stamp-pfctl 209 @echo '\n======== $@ ========' 210 # Ping destination address in other routing domain. DST_TUNNEL6_${n} 211 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${DST_TUNNEL6_${n}} 212 213REGRESS_TARGETS += run-regress-ping6-tunnel4-${n} 214run-regress-ping6-tunnel4-${n}: stamp-setup stamp-pfctl 215 @echo '\n======== $@ ========' 216 # Ping IPv6 address through IPv4 tunnel. TUNNEL4_DST_ADDR6_${n} 217 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${TUNNEL4_DST_ADDR6_${n}} 218 219REGRESS_TARGETS += run-regress-ping6-tunnel6-${n} 220run-regress-ping6-tunnel6-${n}: stamp-setup stamp-pfctl 221 @echo '\n======== $@ ========' 222 # Ping IPv6 address through IPv6 tunnel. TUNNEL6_DST_ADDR6_${n} 223 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${TUNNEL6_DST_ADDR6_${n}} 224 225.endfor 226 227REGRESS_TARGETS += run-regress-cleanup 228run-regress-cleanup: 229 @echo '\n======== $@ ========' 230 ${.MAKE} -C ${.CURDIR} unconfig 231 232CLEANFILES += addr.py *.pyc *.log stamp-* 233 234.include <bsd.regress.mk> 235