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