Makefile revision 1.1
1# $OpenBSD: Makefile,v 1.1 2018/04/19 01:09:30 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} 96 ${SUDO} /sbin/ifconfig gif${n}4 tunnel ${SRC_TUNNEL4_${n}}\ 97 ${DST_TUNNEL4_${n}} tunneldomain ${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} 103 ${SUDO} /sbin/ifconfig gif${n}6 tunnel ${SRC_TUNNEL6_${n}}\ 104 ${DST_TUNNEL6_${n}} tunneldomain ${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 113.for n in ${NUMS} 114 -${SUDO} /sbin/ifconfig lo${n} inet 127.0.0.1 delete 115 -${SUDO} /sbin/ifconfig lo${n} inet6 ::1 delete 116 -${SUDO} /sbin/ifconfig lo${n} inet ${SRC_TUNNEL4_${n}} delete 117 -${SUDO} /sbin/ifconfig lo${n} inet6 ${SRC_TUNNEL6_${n}} delete 118 -${SUDO} /sbin/ifconfig gif${n}4 destroy 119 -${SUDO} /sbin/ifconfig gif${n}6 destroy 120.endfor 121 rm -f stamp-setup 122 123stamp-setup: Makefile 124 @echo '\n======== $@ ========' 125 ${.MAKE} -C ${.CURDIR} ifconfig 126 sleep 1 # XXX test is unreliable without sleep 127 date >$@ 128 129# Create python include file containing the addresses. 130addr.py: Makefile 131 rm -f $@ $@.tmp 132.for N in N1 N2 133 echo '${N}="${${N}}"' >>$@.tmp 134 echo 'IF_${N}="lo${${N}}"' >>$@.tmp 135 echo 'DST_TUNNEL4_${N}="${DST_TUNNEL4_${${N}}}"' >>$@.tmp 136 echo 'DST_TUNNEL6_${N}="${DST_TUNNEL6_${${N}}}"' >>$@.tmp 137.endfor 138 mv $@.tmp $@ 139 140# Load the pf rules into the kernel. 141stamp-pfctl: addr.py pf.conf stamp-setup 142 @echo '\n======== $@ ========' 143 cat addr.py ${.CURDIR}/pf.conf | /sbin/pfctl -n -f - 144 cat addr.py ${.CURDIR}/pf.conf | ${SUDO} /sbin/pfctl -a regress -f - 145 @date >$@ 146 147.for n in ${N1} ${N2} 148 149REGRESS_TARGETS += run-regress-ping-local-${n} 150run-regress-ping-local-${n}: stamp-setup stamp-pfctl 151 @echo '\n======== $@ ========' 152 # Ping localhost in routing domain ${n}. 153 /sbin/ping -n -w 1 -c 1 -V ${n} 127.0.0.1 154 155REGRESS_TARGETS += run-regress-ping-src-${n} 156run-regress-ping-src-${n}: stamp-setup stamp-pfctl 157 @echo '\n======== $@ ========' 158 # Ping source address in local routing domain. 159 /sbin/ping -n -w 1 -c 1 -V ${n} ${SRC_TUNNEL4_${n}} 160 161REGRESS_TARGETS += run-regress-ping-dst-${n} 162run-regress-ping-dst-${n}: stamp-setup stamp-pfctl 163 @echo '\n======== $@ ========' 164 # Ping destination address in other routing domain. 165 /sbin/ping -n -w 1 -c 1 -V ${n} ${DST_TUNNEL4_${n}} 166 167REGRESS_TARGETS += run-regress-ping-tunnel4-${n} 168run-regress-ping-tunnel4-${n}: stamp-setup stamp-pfctl 169 @echo '\n======== $@ ========' 170 # Ping IPv4 address through IPv4 tunnel. 171 /sbin/ping -n -w 1 -c 1 -V ${n} ${TUNNEL4_DST_ADDR4_${n}} 172 173REGRESS_TARGETS += run-regress-ping-tunnel6-${n} 174run-regress-ping-tunnel6-${n}: stamp-setup stamp-pfctl 175 @echo '\n======== $@ ========' 176 # Ping IPv4 address through IPv6 tunnel. 177 /sbin/ping -n -w 1 -c 1 -V ${n} ${TUNNEL6_DST_ADDR4_${n}} 178 179REGRESS_TARGETS += run-regress-ping6-local-${n} 180run-regress-ping6-local-${n}: stamp-setup stamp-pfctl 181 @echo '\n======== $@ ========' 182 # Ping localhost in routing domain ${n}. 183 /sbin/ping6 -n -w 1 -c 1 -V ${n} ::1 184 185REGRESS_TARGETS += run-regress-ping6-src-${n} 186run-regress-ping6-src-${n}: stamp-setup stamp-pfctl 187 @echo '\n======== $@ ========' 188 # Ping source address in local routing domain. 189 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${SRC_TUNNEL6_${n}} 190 191REGRESS_TARGETS += run-regress-ping6-dst-${n} 192run-regress-ping6-dst-${n}: stamp-setup stamp-pfctl 193 @echo '\n======== $@ ========' 194 # Ping destination address in other routing domain. 195 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${DST_TUNNEL6_${n}} 196 197REGRESS_TARGETS += run-regress-ping6-tunnel4-${n} 198run-regress-ping6-tunnel4-${n}: stamp-setup stamp-pfctl 199 @echo '\n======== $@ ========' 200 # Ping IPv6 address through IPv4 tunnel. 201 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${TUNNEL4_DST_ADDR6_${n}} 202 203REGRESS_TARGETS += run-regress-ping6-tunnel6-${n} 204run-regress-ping6-tunnel6-${n}: stamp-setup stamp-pfctl 205 @echo '\n======== $@ ========' 206 # Ping IPv6 address through IPv6 tunnel. 207 /sbin/ping6 -n -w 1 -c 1 -V ${n} ${TUNNEL6_DST_ADDR6_${n}} 208 209.endfor 210 211REGRESS_TARGETS += run-regress-cleanup 212run-regress-cleanup: 213 @echo '\n======== $@ ========' 214 ${.MAKE} -C ${.CURDIR} unconfig 215 216CLEANFILES += addr.py *.pyc *.log stamp-* 217 218.include <bsd.regress.mk> 219