xref: /openbsd/regress/sys/net/pf_divert/Makefile (revision d8cb2e0f)
1*d8cb2e0fSbluhm#	$OpenBSD: Makefile,v 1.14 2016/11/15 16:00:50 bluhm Exp $
2336dfed2Sbluhm
3336dfed2Sbluhm# The following ports must be installed for the regression tests:
4336dfed2Sbluhm# p5-IO-Socket-INET6	object interface for AF_INET and AF_INET6 domain sockets
5336dfed2Sbluhm# p5-Socket6		Perl defines relating to AF_INET6 sockets
61e607023Sbluhm#
71e607023Sbluhm# Check wether all required perl packages are installed.  If some
81e607023Sbluhm# are missing print a warning and skip the tests, but do not fail.
9336dfed2Sbluhm
101e607023SbluhmPERL_REQUIRE !=	perl -Mstrict -Mwarnings -e ' \
111e607023Sbluhm    eval { require IO::Socket::INET6 } or print $@; \
121e607023Sbluhm    eval { require Socket6 } or print $@; \
131e607023Sbluhm'
141e607023Sbluhm.if ! empty(PERL_REQUIRE)
151e607023Sbluhmregress:
161e607023Sbluhm	@echo "${PERL_REQUIRE}"
171e607023Sbluhm	@echo install these perl packages for additional tests
1854eefd0cSbluhm	@echo SKIPPED
19336dfed2Sbluhm.endif
20336dfed2Sbluhm
21336dfed2Sbluhm# Fill out these variables as you have to test divert with the pf
22336dfed2Sbluhm# kernel running on a remote machine.  You have to specify a local
23336dfed2Sbluhm# and remote ip address for the test connections.  The fake ip address
24336dfed2Sbluhm# will be routed via the remote address to test divert with non-existing
25336dfed2Sbluhm# addresses.  To control the remote machine you need a hostname for
26336dfed2Sbluhm# ssh to log in.  All the test files must be in the same directory
27336dfed2Sbluhm# local and remote.
28336dfed2Sbluhm# You must have an anchor "regress" for the divert rules in the pf.conf
29336dfed2Sbluhm# of the remote machine.  The kernel of the remote machine gets testet.
3002079822Sbluhm#
3102079822Sbluhm# Run make check-setup to see if you got the setup correct.
32336dfed2Sbluhm
3311f7eadfSbluhmLOCAL_ADDR ?=
3411f7eadfSbluhmREMOTE_ADDR ?=
3511f7eadfSbluhmFAKE_ADDR ?=
3611f7eadfSbluhmLOCAL_ADDR6 ?=
3711f7eadfSbluhmREMOTE_ADDR6 ?=
3811f7eadfSbluhmFAKE_ADDR6 ?=
3911f7eadfSbluhmREMOTE_SSH ?=
40336dfed2Sbluhm
411e607023Sbluhm.if empty (LOCAL_ADDR) || empty (REMOTE_ADDR) || empty (FAKE_ADDR) || \
421e607023Sbluhm    empty (LOCAL_ADDR6) || empty (REMOTE_ADDR6) || empty (FAKE_ADDR6) || \
431e607023Sbluhm    empty (REMOTE_SSH)
441e607023Sbluhmregress:
45aa8f1300Sbluhm	@echo This tests needs a remote machine to operate on.
461e607023Sbluhm	@echo LOCAL_ADDR REMOTE_ADDR FAKE_ADDR LOCAL_ADDR6
47aa8f1300Sbluhm	@echo REMOTE_ADDR6 FAKE_ADDR6 REMOTE_SSH are empty.
48aa8f1300Sbluhm	@echo Fill out these variables for additional tests.
4954eefd0cSbluhm	@echo SKIPPED
501e607023Sbluhm.endif
511e607023Sbluhm
521e607023Sbluhm# Automatically generate regress targets from test cases in directory.
531e607023Sbluhm
541e607023SbluhmARGS !=			cd ${.CURDIR} && ls args-*.pl
55d0e91fd6SbluhmTARGETS ?=		inet-args-tcp-to inet6-args-tcp-to \
56d0e91fd6Sbluhm			inet-args-tcp-reply inet6-args-tcp-reply \
57d0e91fd6Sbluhm			inet-args-udp-to inet6-args-udp-to \
58d0e91fd6Sbluhm			inet-args-udp-reply inet6-args-udp-reply \
59c30a42c2Sbluhm			inet-args-udp-reply-to inet6-args-udp-reply-to \
60d0e91fd6Sbluhm			inet-args-rip-to inet6-args-rip-to \
61d0e91fd6Sbluhm			inet-args-rip-reply inet6-args-rip-reply \
62c30a42c2Sbluhm			inet-args-rip-reply-to inet6-args-rip-reply-to \
63d0e91fd6Sbluhm			inet-args-icmp-to inet6-args-icmp-to \
64c30a42c2Sbluhm			inet-args-icmp-reply-to inet6-args-icmp-reply-to \
65c30a42c2Sbluhm			inet-args-icmp-reply-reuse inet6-args-icmp-reply-reuse \
66d0e91fd6Sbluhm			inet-reuse-tcp inet6-reuse-tcp \
67d0e91fd6Sbluhm			inet-reuse-udp inet6-reuse-udp \
68d0e91fd6Sbluhm			inet-reuse-rip inet6-reuse-rip
691e607023SbluhmREGRESS_TARGETS =	${TARGETS:S/^/run-regress-/}
70d0e91fd6SbluhmCLEANFILES +=		*.log *.port ktrace.out stamp-*
711e607023Sbluhm
72336dfed2Sbluhm.MAIN: all
73336dfed2Sbluhm
741e607023Sbluhm.if ! empty (REMOTE_SSH)
75336dfed2Sbluhm.if make (regress) || make (all)
76336dfed2Sbluhm.BEGIN:
77336dfed2Sbluhm	@echo
78336dfed2Sbluhm	${SUDO} true
791e607023Sbluhm	ssh -t ${REMOTE_SSH} ${SUDO} true
801e607023Sbluhm.if ! empty (FAKE_ADDR) && ! empty (REMOTE_ADDR)
81336dfed2Sbluhm	-${SUDO} route -n delete -inet -host ${FAKE_ADDR} 2>/dev/null
82336dfed2Sbluhm	${SUDO} route -n add -inet -host ${FAKE_ADDR} ${REMOTE_ADDR}
831e607023Sbluhm.endif
841e607023Sbluhm.if ! empty (FAKE_ADDR6) && ! empty (REMOTE_ADDR6)
85336dfed2Sbluhm	-${SUDO} route -n delete -inet6 -host ${FAKE_ADDR6} 2>/dev/null
86336dfed2Sbluhm	${SUDO} route -n add -inet6 -host ${FAKE_ADDR6} ${REMOTE_ADDR6}
87336dfed2Sbluhm.endif
881e607023Sbluhm.endif
891e607023Sbluhm.endif
90336dfed2Sbluhm
91336dfed2Sbluhm# Set variables so that make runs with and without obj directory.
92336dfed2Sbluhm# Only do that if necessary to keep visible output short.
93336dfed2Sbluhm
94336dfed2Sbluhm.if ${.CURDIR} == ${.OBJDIR}
95336dfed2SbluhmPERLINC =	-I.
96336dfed2SbluhmPERLPATH =
97336dfed2Sbluhm.else
98336dfed2SbluhmPERLINC =	-I${.CURDIR}
99336dfed2SbluhmPERLPATH =	${.CURDIR}/
100336dfed2Sbluhm.endif
101336dfed2Sbluhm
102336dfed2Sbluhm# The arg tests take a perl hash with arguments controlling the test
103336dfed2Sbluhm# parameters.  The remote.pl test has local client or server and the
104336dfed2Sbluhm# diverted process is running on the remote machine reachable with
105336dfed2Sbluhm# ssh.
106336dfed2Sbluhm
107d0e91fd6Sbluhm.for inet addr in inet ADDR inet6 ADDR6
108d0e91fd6Sbluhm
109336dfed2Sbluhm.for a in ${ARGS}
110d0e91fd6Sbluhmrun-regress-${inet}-${a:R}: ${a}
1119b269b52Sbluhm	@echo '\n======== $@ ========'
112*d8cb2e0fSbluhm	time ${SUDO} SUDO=${SUDO} perl ${PERLINC} ${PERLPATH}remote.pl -f ${inet} ${LOCAL_${addr}} ${FAKE_${addr}} ${REMOTE_SSH} ${PERLPATH}${a}
113d0e91fd6Sbluhm.endfor
114d0e91fd6Sbluhm
115d0e91fd6Sbluhm.for proto in tcp udp rip
116d0e91fd6Sbluhmrun-regress-${inet}-reuse-${proto}:
1179b269b52Sbluhm	@echo '\n======== $@ ========'
118cee6974dSbluhm	time ${SUDO} SUDO=${SUDO} perl ${PERLINC} ${PERLPATH}remote.pl ${inet} ${LOCAL_${addr}} ${FAKE_${addr}} ${REMOTE_SSH} ${PERLPATH}args-${proto}-reply.pl
119d0e91fd6Sbluhm	sed -n '/^connect peer:/s/.* //p' client.log >client.port
120d0e91fd6Sbluhm	sed -n '/^connect sock:/s/.* //p' client.log >server.port
121d0e91fd6Sbluhm.if "tcp" == ${proto}
122d0e91fd6Sbluhm	${SUDO} tcpdrop ${LOCAL_${addr}} `cat client.port` ${FAKE_${addr}} `cat server.port`
123336dfed2Sbluhm.endif
124d0e91fd6Sbluhm	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
1253c0bd7e8Sbluhm.if "tcp" == ${proto}
1263c0bd7e8Sbluhm	ssh ${REMOTE_SSH} ${SUDO} tcpdrop ${FAKE_${addr}} `cat server.port` ${LOCAL_${addr}} `cat client.port`
127cee6974dSbluhm.if "inet" == ${inet}
128cee6974dSbluhm	if ssh ${REMOTE_SSH} ${SUDO} pfctl -ss | \
129cee6974dSbluhm	    grep 'all ${proto} ${FAKE_${addr}}:'`cat server.port`' .. ${LOCAL_${addr}}:'`cat client.port`' '; \
130cee6974dSbluhm		then false; \
131cee6974dSbluhm	fi
132cee6974dSbluhm.else
133cee6974dSbluhm	if ssh ${REMOTE_SSH} ${SUDO} pfctl -ss | \
134cee6974dSbluhm	    grep 'all ${proto} ${FAKE_${addr}}\['`cat server.port`\]' .. ${LOCAL_${addr}}\['`cat client.port`'\] '; \
135cee6974dSbluhm		then false; \
136cee6974dSbluhm	fi
137cee6974dSbluhm.endif
138cee6974dSbluhm.endif
139d0e91fd6Sbluhm.endfor
140d0e91fd6Sbluhm
141336dfed2Sbluhm.endfor
142336dfed2Sbluhm
14379a2adffSbluhm.PHONY: syntax check-setup
144336dfed2Sbluhm
1453c0bd7e8Sbluhm# make perl syntax check for all args files
146336dfed2Sbluhmsyntax: stamp-syntax
147336dfed2Sbluhm
148336dfed2Sbluhmstamp-syntax: ${ARGS}
149336dfed2Sbluhm.for a in ${ARGS}
150336dfed2Sbluhm	@perl -c ${PERLPATH}$a
151336dfed2Sbluhm.endfor
152336dfed2Sbluhm	@date >$@
153336dfed2Sbluhm
15479a2adffSbluhm# Check wether the address, route and remote setup is correct
15579a2adffSbluhmcheck-setup:
15602079822Sbluhm	@echo '\n======== $@ ========'
15779a2adffSbluhm	ping -n -c 1 ${LOCAL_ADDR}
15879a2adffSbluhm	ping -n -c 1 ${REMOTE_ADDR}
15979a2adffSbluhm	ping6 -n -c 1 ${LOCAL_ADDR6}
16079a2adffSbluhm	ping6 -n -c 1 ${REMOTE_ADDR6}
1613c0bd7e8Sbluhm	route -n get -inet ${FAKE_ADDR} | grep 'if address: ${LOCAL_ADDR}$$'
1623c0bd7e8Sbluhm	route -n get -inet ${FAKE_ADDR} | grep 'gateway: ${REMOTE_ADDR}$$'
1633c0bd7e8Sbluhm	route -n get -inet6 ${FAKE_ADDR6} | grep 'if address: ${LOCAL_ADDR6}$$'
1643c0bd7e8Sbluhm	route -n get -inet6 ${FAKE_ADDR6} | grep 'gateway: ${REMOTE_ADDR6}$$'
16579a2adffSbluhm	ssh ${REMOTE_SSH} ${SUDO} pfctl -sr | grep '^anchor "regress" all$$'
16679a2adffSbluhm	ssh ${REMOTE_SSH} ${SUDO} pfctl -si | grep '^Status: Enabled '
167aa8f1300Sbluhm	ssh ${REMOTE_SSH} perl -MIO::Socket::INET6 -MSocket6 -e 1
16879a2adffSbluhm
169336dfed2Sbluhm.include <bsd.regress.mk>
170