xref: /openbsd/regress/sys/net/gif/Makefile (revision 097a140d)
1#	$OpenBSD: Makefile,v 1.5 2020/12/17 00:39:42 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 pfctl
90
91REGRESS_SETUP_ONCE +=	busy-rdomains
92busy-rdomains:
93	# Check if rdomains are busy.
94.for n in ${NUMS}
95	@if /sbin/ifconfig | grep -v '^lo$n:' | grep ' rdomain $n '; then\
96	    echo routing domain $n is already used >&2; exit 1; fi
97.endfor
98
99REGRESS_SETUP_ONCE +=	ifconfig
100ifconfig: unconfig
101	# Create and configure loopback interfaces.
102.for n in ${NUMS}
103	${SUDO} ifconfig lo$n rdomain $n
104	${SUDO} ifconfig lo$n inet 127.0.0.1/8
105	${SUDO} ifconfig lo$n inet6 ::1/128
106	${SUDO} ifconfig lo$n inet ${SRC_TUNNEL4_$n} alias
107	${SUDO} ifconfig lo$n inet6 ${SRC_TUNNEL6_$n} alias
108	${SUDO} route -n -T $n add -inet -host ${DST_TUNNEL4_$n} 127.0.0.1
109	${SUDO} route -n -T $n add -inet6 -host ${DST_TUNNEL6_$n} ::1
110	${SUDO} ifconfig gif$n4 create rdomain $n tunneldomain $n
111	${SUDO} ifconfig gif$n4 tunnel ${SRC_TUNNEL4_$n} ${DST_TUNNEL4_$n}
112	${SUDO} ifconfig gif$n4 inet ${TUNNEL4_SRC_ADDR4_$n}/32\
113	    ${TUNNEL4_DST_ADDR4_$n}
114	${SUDO} ifconfig gif$n4 inet6 ${TUNNEL4_SRC_ADDR6_$n}\
115	    ${TUNNEL4_DST_ADDR6_$n}
116	${SUDO} ifconfig gif$n6 create rdomain $n tunneldomain $n
117	${SUDO} ifconfig gif$n6 tunnel ${SRC_TUNNEL6_$n}\
118	    ${DST_TUNNEL6_$n}
119	${SUDO} ifconfig gif$n6 inet ${TUNNEL6_SRC_ADDR4_$n}/32\
120	    ${TUNNEL6_DST_ADDR4_$n}
121	${SUDO} ifconfig gif$n6 inet6 ${TUNNEL6_SRC_ADDR6_$n}\
122	    ${TUNNEL6_DST_ADDR6_$n}
123.endfor
124	# Wait until DAD for inet6 tunnel addresses has finished.
125	sleep 1
126
127REGRESS_CLEANUP +=	unconfig
128unconfig:
129	# Destroy interfaces, keep lo as routing domain cannot be destroyed.
130.for n in ${NUMS}
131	-${SUDO} ifconfig lo$n rdomain $n
132	-${SUDO} ifconfig lo$n inet 127.0.0.1 delete
133	-${SUDO} ifconfig lo$n inet6 ::1 delete
134	-${SUDO} ifconfig lo$n inet ${SRC_TUNNEL4_$n} delete
135	-${SUDO} ifconfig lo$n inet6 ${SRC_TUNNEL6_$n} delete
136	-${SUDO} ifconfig gif$n4 destroy
137	-${SUDO} ifconfig gif$n6 destroy
138.endfor
139	rm -f stamp-ifconfig
140
141addr.py: Makefile
142	# Create python include file containing the addresses.
143	rm -f $@ $@.tmp
144.for N in N1 N2
145	echo '${N}="${${N}}"' >>$@.tmp
146	echo 'IF_${N}="lo${${N}}"' >>$@.tmp
147	echo 'DST_TUNNEL4_${N}="${DST_TUNNEL4_${${N}}}"' >>$@.tmp
148	echo 'DST_TUNNEL6_${N}="${DST_TUNNEL6_${${N}}}"' >>$@.tmp
149.endfor
150	mv $@.tmp $@
151
152REGRESS_SETUP_ONCE +=	pfctl
153pfctl: addr.py pf.conf
154	# Load the pf rules into the kernel.
155	cat addr.py ${.CURDIR}/pf.conf | /sbin/pfctl -n -f -
156	cat addr.py ${.CURDIR}/pf.conf | ${SUDO} pfctl -a regress -f -
157	# ifconfig gif inet6 DAD created tunnel states based on old pf rules
158	${SUDO} /sbin/pfctl -Fs
159
160.for n in ${N1} ${N2}
161
162REGRESS_TARGETS +=	run-ping-local-$n
163run-ping-local-$n:
164	# Ping localhost in routing domain $n.
165	/sbin/ping -n -w 1 -c 1 -V $n 127.0.0.1
166
167REGRESS_TARGETS +=	run-ping-src-$n
168run-ping-src-$n:
169	# Ping source address in local routing domain.  SRC_TUNNEL4_$n
170	/sbin/ping -n -w 1 -c 1 -V $n ${SRC_TUNNEL4_$n}
171
172REGRESS_TARGETS +=	run-ping-dst-$n
173run-ping-dst-$n:
174	# Ping destination address in other routing domain.  DST_TUNNEL4_$n
175	/sbin/ping -n -w 1 -c 1 -V $n ${DST_TUNNEL4_$n}
176
177REGRESS_TARGETS +=	run-ping-tunnel4-$n
178run-ping-tunnel4-$n:
179	# Ping IPv4 address through IPv4 tunnel.  TUNNEL4_DST_ADDR4_$n
180	/sbin/ping -n -w 1 -c 1 -V $n ${TUNNEL4_DST_ADDR4_$n}
181
182REGRESS_TARGETS +=	run-ping-tunnel6-$n
183run-ping-tunnel6-$n:
184	# Ping IPv4 address through IPv6 tunnel.  TUNNEL6_DST_ADDR4_$n
185	/sbin/ping -n -w 1 -c 1 -V $n ${TUNNEL6_DST_ADDR4_$n}
186
187REGRESS_TARGETS +=	run-ping6-local-$n
188run-ping6-local-$n:
189	# Ping localhost in routing domain $n.
190	/sbin/ping6 -n -w 1 -c 1 -V $n ::1
191
192REGRESS_TARGETS +=	run-ping6-src-$n
193run-ping6-src-$n:
194	# Ping source address in local routing domain.  SRC_TUNNEL6_$n
195	/sbin/ping6 -n -w 1 -c 1 -V $n ${SRC_TUNNEL6_$n}
196
197REGRESS_TARGETS +=	run-ping6-dst-$n
198run-ping6-dst-$n:
199	# Ping destination address in other routing domain.  DST_TUNNEL6_$n
200	/sbin/ping6 -n -w 1 -c 1 -V $n ${DST_TUNNEL6_$n}
201
202REGRESS_TARGETS +=	run-ping6-tunnel4-$n
203run-ping6-tunnel4-$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-ping6-tunnel6-$n
208run-ping6-tunnel6-$n:
209	# Ping IPv6 address through IPv6 tunnel.  TUNNEL6_DST_ADDR6_$n
210	/sbin/ping6 -n -w 1 -c 1 -V $n ${TUNNEL6_DST_ADDR6_$n}
211
212.endfor
213
214CLEANFILES +=	addr.py *.pyc *.log
215
216.include <bsd.regress.mk>
217