xref: /openbsd/regress/sys/net/pf_divert/Makefile (revision c30a42c2)
1#	$OpenBSD: Makefile,v 1.12 2015/07/28 12:31:29 bluhm Exp $
2
3# The following ports must be installed for the regression tests:
4# p5-IO-Socket-INET6	object interface for AF_INET and AF_INET6 domain sockets
5# p5-Socket6		Perl defines relating to AF_INET6 sockets
6#
7# Check wether all required perl packages are installed.  If some
8# are missing print a warning and skip the tests, but do not fail.
9
10PERL_REQUIRE !=	perl -Mstrict -Mwarnings -e ' \
11    eval { require IO::Socket::INET6 } or print $@; \
12    eval { require Socket6 } or print $@; \
13'
14.if ! empty(PERL_REQUIRE)
15regress:
16	@echo "${PERL_REQUIRE}"
17	@echo install these perl packages for additional tests
18.endif
19
20# Fill out these variables as you have to test divert with the pf
21# kernel running on a remote machine.  You have to specify a local
22# and remote ip address for the test connections.  The fake ip address
23# will be routed via the remote address to test divert with non-existing
24# addresses.  To control the remote machine you need a hostname for
25# ssh to log in.  All the test files must be in the same directory
26# local and remote.
27# You must have an anchor "regress" for the divert rules in the pf.conf
28# of the remote machine.  The kernel of the remote machine gets testet.
29#
30# Run make check-setup to see if you got the setup correct.
31
32LOCAL_ADDR ?=
33REMOTE_ADDR ?=
34FAKE_ADDR ?=
35LOCAL_ADDR6 ?=
36REMOTE_ADDR6 ?=
37FAKE_ADDR6 ?=
38REMOTE_SSH ?=
39
40.if empty (LOCAL_ADDR) || empty (REMOTE_ADDR) || empty (FAKE_ADDR) || \
41    empty (LOCAL_ADDR6) || empty (REMOTE_ADDR6) || empty (FAKE_ADDR6) || \
42    empty (REMOTE_SSH)
43regress:
44	@echo This tests needs a remote machine to operate on.
45	@echo LOCAL_ADDR REMOTE_ADDR FAKE_ADDR LOCAL_ADDR6
46	@echo REMOTE_ADDR6 FAKE_ADDR6 REMOTE_SSH are empty.
47	@echo Fill out these variables for additional tests.
48.endif
49
50# Automatically generate regress targets from test cases in directory.
51
52ARGS !=			cd ${.CURDIR} && ls args-*.pl
53TARGETS ?=		inet-args-tcp-to inet6-args-tcp-to \
54			inet-args-tcp-reply inet6-args-tcp-reply \
55			inet-args-udp-to inet6-args-udp-to \
56			inet-args-udp-reply inet6-args-udp-reply \
57			inet-args-udp-reply-to inet6-args-udp-reply-to \
58			inet-args-rip-to inet6-args-rip-to \
59			inet-args-rip-reply inet6-args-rip-reply \
60			inet-args-rip-reply-to inet6-args-rip-reply-to \
61			inet-args-icmp-to inet6-args-icmp-to \
62			inet-args-icmp-reply-to inet6-args-icmp-reply-to \
63			inet-args-icmp-reply-reuse inet6-args-icmp-reply-reuse \
64			inet-reuse-tcp inet6-reuse-tcp \
65			inet-reuse-udp inet6-reuse-udp \
66			inet-reuse-rip inet6-reuse-rip
67REGRESS_TARGETS =	${TARGETS:S/^/run-regress-/}
68CLEANFILES +=		*.log *.port ktrace.out stamp-*
69
70.MAIN: all
71
72.if ! empty (REMOTE_SSH)
73.if make (regress) || make (all)
74.BEGIN:
75	@echo
76	${SUDO} true
77	ssh -t ${REMOTE_SSH} ${SUDO} true
78.if ! empty (FAKE_ADDR) && ! empty (REMOTE_ADDR)
79	-${SUDO} route -n delete -inet -host ${FAKE_ADDR} 2>/dev/null
80	${SUDO} route -n add -inet -host ${FAKE_ADDR} ${REMOTE_ADDR}
81.endif
82.if ! empty (FAKE_ADDR6) && ! empty (REMOTE_ADDR6)
83	-${SUDO} route -n delete -inet6 -host ${FAKE_ADDR6} 2>/dev/null
84	${SUDO} route -n add -inet6 -host ${FAKE_ADDR6} ${REMOTE_ADDR6}
85.endif
86.endif
87.endif
88
89# Set variables so that make runs with and without obj directory.
90# Only do that if necessary to keep visible output short.
91
92.if ${.CURDIR} == ${.OBJDIR}
93PERLINC =	-I.
94PERLPATH =
95.else
96PERLINC =	-I${.CURDIR}
97PERLPATH =	${.CURDIR}/
98.endif
99
100# The arg tests take a perl hash with arguments controlling the test
101# parameters.  The remote.pl test has local client or server and the
102# diverted process is running on the remote machine reachable with
103# ssh.
104
105.for inet addr in inet ADDR inet6 ADDR6
106
107.for a in ${ARGS}
108run-regress-${inet}-${a:R}: ${a}
109	@echo '\n======== $@ ========'
110	time ${SUDO} SUDO=${SUDO} perl ${PERLINC} ${PERLPATH}remote.pl ${inet} ${LOCAL_${addr}} ${FAKE_${addr}} ${REMOTE_SSH} ${PERLPATH}${a}
111.endfor
112
113.for proto in tcp udp rip
114run-regress-${inet}-reuse-${proto}:
115	@echo '\n======== $@ ========'
116	time ${SUDO} SUDO=${SUDO} perl ${PERLINC} ${PERLPATH}remote.pl ${inet} ${LOCAL_${addr}} ${FAKE_${addr}} ${REMOTE_SSH} ${PERLPATH}args-${proto}-reply.pl
117	sed -n '/^connect peer:/s/.* //p' client.log >client.port
118	sed -n '/^connect sock:/s/.* //p' client.log >server.port
119.if "tcp" == ${proto}
120	${SUDO} tcpdrop ${LOCAL_${addr}} `cat client.port` ${FAKE_${addr}} `cat server.port`
121.endif
122	time ${SUDO} SUDO=${SUDO} perl ${PERLINC} ${PERLPATH}remote.pl ${inet} ${LOCAL_${addr}} ${FAKE_${addr}} ${REMOTE_SSH} `cat client.port` `cat server.port` ${PERLPATH}args-${proto}-to.pl
123.if "tcp" == ${proto}
124	ssh ${REMOTE_SSH} ${SUDO} tcpdrop ${FAKE_${addr}} `cat server.port` ${LOCAL_${addr}} `cat client.port`
125.if "inet" == ${inet}
126	if ssh ${REMOTE_SSH} ${SUDO} pfctl -ss | \
127	    grep 'all ${proto} ${FAKE_${addr}}:'`cat server.port`' .. ${LOCAL_${addr}}:'`cat client.port`' '; \
128		then false; \
129	fi
130.else
131	if ssh ${REMOTE_SSH} ${SUDO} pfctl -ss | \
132	    grep 'all ${proto} ${FAKE_${addr}}\['`cat server.port`\]' .. ${LOCAL_${addr}}\['`cat client.port`'\] '; \
133		then false; \
134	fi
135.endif
136.endif
137.endfor
138
139.endfor
140
141.PHONY: syntax check-setup
142
143# make perl syntax check for all args files
144syntax: stamp-syntax
145
146stamp-syntax: ${ARGS}
147.for a in ${ARGS}
148	@perl -c ${PERLPATH}$a
149.endfor
150	@date >$@
151
152# Check wether the address, route and remote setup is correct
153check-setup:
154	@echo '\n======== $@ ========'
155	ping -n -c 1 ${LOCAL_ADDR}
156	ping -n -c 1 ${REMOTE_ADDR}
157	ping6 -n -c 1 ${LOCAL_ADDR6}
158	ping6 -n -c 1 ${REMOTE_ADDR6}
159	route -n get -inet ${FAKE_ADDR} | grep 'if address: ${LOCAL_ADDR}$$'
160	route -n get -inet ${FAKE_ADDR} | grep 'gateway: ${REMOTE_ADDR}$$'
161	route -n get -inet6 ${FAKE_ADDR6} | grep 'if address: ${LOCAL_ADDR6}$$'
162	route -n get -inet6 ${FAKE_ADDR6} | grep 'gateway: ${REMOTE_ADDR6}$$'
163	ssh ${REMOTE_SSH} ${SUDO} pfctl -sr | grep '^anchor "regress" all$$'
164	ssh ${REMOTE_SSH} ${SUDO} pfctl -si | grep '^Status: Enabled '
165	ssh ${REMOTE_SSH} perl -MIO::Socket::INET6 -MSocket6 -e 1
166
167.include <bsd.regress.mk>
168