Makefile revision 1.7
1#	$OpenBSD: Makefile,v 1.7 2020/12/17 00:51:12 bluhm Exp $
2
3# Copyright (c) 2017-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# The following ports must be installed:
18#
19# scapy               powerful interactive packet manipulation in python
20
21.include <bsd.own.mk>
22
23.if ! (make(clean) || make(cleandir) || make(obj))
24
25.if ! exists(/usr/local/bin/scapy)
26regress:
27	@echo Install scapy package to run this regress.
28	@echo SKIPPED
29.endif
30
31# PERL_REQUIRE set in ../Makefile.inc
32.if ! empty (PERL_REQUIRE)
33regress:
34	@echo perl require: "${PERL_REQUIRE}"
35	@echo install these perl packages for additional tests
36.endif
37
38PF_STATUS !=	${SUDO} pfctl -si | sed -n 's/^Status: \([^ ]*\) .*/\1/p'
39PF_ANCHOR !=	${SUDO} pfctl -sr | sed -n 's/^anchor "\([^"]*\)" all$$/\1/p'
40.if ! empty(PF_STATUS:MEnabled) && empty(PF_ANCHOR:Mregress)
41regress:
42	@echo pf status: "${PF_STATUS}"
43	@echo pf anchor: "${PF_ANCHOR}"
44	@echo This regress cannot run with pf filtering packets on localhost.
45	@echo Either disable pf or add a line 'anchor "regress"' to pf.conf.
46	@echo There the test will add a stateless rule that passes all packets.
47	@echo SKIPPED
48.endif
49
50.endif
51
52# This test needs a manual setup of two machines
53# Set up machines: LOCAL REMOTE
54# LOCAL is the machine where this makefile is running.
55# REMOTE is running OpenBSD with echo server to test PMTU
56# FAKE is an non existing machine in a non existing network.
57# REMOTE_SSH is the hostname to log in on the REMOTE machine.
58
59# Configure Addresses on the machines.
60# Adapt interface and addresse variables to your local setup.
61#
62LOCAL_IF ?=
63REMOTE_SSH ?=
64
65LOCAL_ADDR ?=
66REMOTE_ADDR ?=
67FAKE_NET ?=
68FAKE_NET_ADDR ?=
69
70.if empty (LOCAL_IF) || empty (REMOTE_SSH) || \
71    empty (LOCAL_ADDR) || \
72    empty (REMOTE_ADDR) || \
73    empty (FAKE_NET) || \
74    empty (FAKE_NET_ADDR)
75.BEGIN:
76	@true
77regress:
78	@echo This tests needs a remote machine to operate on
79	@echo LOCAL_IF REMOTE_SSH LOCAL_ADDR REMOTE_ADDR FAKE_NET FAKE_NET_ADDR
80	@echo are empty.  Fill out these variables for additional tests.
81	@echo SKIPPED
82.endif
83
84.MAIN: all
85
86.if make (regress) || make (all)
87.BEGIN:
88	@echo
89	${SUDO} true
90	ssh -t ${REMOTE_SSH} true
91.endif
92
93# Create python include file containing the addresses.
94addr.py: Makefile
95	rm -f $@ $@.tmp
96	echo 'LOCAL_IF = "${LOCAL_IF}"' >>$@.tmp
97.for var in LOCAL REMOTE FAKE_NET
98	echo '${var}_ADDR = "${${var}_ADDR}"' >>$@.tmp
99.endfor
100	echo 'FAKE_NET = "${FAKE_NET}"' >>$@.tmp
101	mv $@.tmp $@
102
103# load the pf rules into the kernel of the REMOTE and LOCAL machine
104REGRESS_SETUP +=	stamp-pfctl
105stamp-pfctl:
106.if ! empty(PF_ANCHOR:Mregress)
107	echo 'pass on ${LOCAL_IF} no state' | ${SUDO} pfctl -a regress -f -
108.endif
109	@date >$@
110
111SCAPYS !=		cd ${.CURDIR} && ls scapy-*.py
112TARGETS =
113
114# Set variables so that make runs with and without obj directory.
115# Only do that if necessary to keep visible output short.
116.if ${.CURDIR} == ${.OBJDIR}
117PYTHON =	python2.7 -u
118SCAPYPATH =
119.else
120PYTHON =	PYTHONPATH=${.OBJDIR} python2.7 -u
121SCAPYPATH =	${.CURDIR}/
122.endif
123
124.for s in ${SCAPYS}
125REGRESS_TARGETS +=	run-$s
126run-$s: $s addr.py
127	time SUDO=${SUDO} PYTHON="${PYTHON}" perl ${PERLINC} ${PERLPATH}scapy.pl splice ${FAKE_NET_ADDR} ${REMOTE_ADDR} ${REMOTE_SSH} ${SCAPYPATH}$s
128.endfor
129
130.if ! empty(PF_ANCHOR:Mregress)
131REGRESS_CLEANUP +=	cleanup
132cleanup:
133	${SUDO} pfctl -a regress -Fr
134	rm -f stamp-pfctl
135.endif
136
137CLEANFILES +=		addr.py *.pyc *.log stamp-*
138
139.PHONY: check-setup check-setup-local check-setup-remote
140
141# Check wether the address, route and remote setup is correct
142check-setup: check-setup-local check-setup-remote
143
144check-setup-local:
145	@echo '\n======== $@ ========'
146	ping -n -c 1 ${LOCAL_ADDR}  # LOCAL_ADDR
147	route -n get -inet ${LOCAL_ADDR} | grep -q 'flags: .*LOCAL'  # LOCAL_ADDR
148	ping -n -c 1 ${REMOTE_ADDR}  # REMOTE_ADDR
149	route -n get -inet ${REMOTE_ADDR} | fgrep -q 'interface: ${LOCAL_IF}'  # REMOTE_ADDR LOCAL_IF
150	! ping -n -c 1 -w 1 ${FAKE_NET_ADDR}  # FAKE_NET_ADDR
151.for ip in FAKE_NET FAKE_NET_ADDR
152	route -n get -inet ${${ip}} | grep -q 'flags: .*BLACKHOLE'  # ${ip}
153.endfor
154
155check-setup-remote:
156	@echo '\n======== $@ ========'
157	ssh ${REMOTE_SSH} ping -n -c 1 ${REMOTE_ADDR}  # REMOTE_ADDR
158	ssh ${REMOTE_SSH} route -n get -inet ${REMOTE_ADDR} | grep -q 'flags: .*LOCAL'  # REMOTE_ADDR
159	ssh ${REMOTE_SSH} ping -n -c 1 ${LOCAL_ADDR}  # LOCAL_ADDR
160.for ip in FAKE_NET FAKE_NET_ADDR
161	ssh ${REMOTE_SSH} route -n get -inet ${${ip}} | fgrep -q 'gateway: ${LOCAL_ADDR}'  # ${ip} LOCAL_ADDR
162.endfor
163
164.include <bsd.regress.mk>
165