summaryrefslogtreecommitdiff
path: root/regress/sys/netinet/frag/Makefile
blob: ae55e9951ff68057839ec41057271332a9f2874b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#	$OpenBSD: Makefile,v 1.6 2020/01/15 20:47:13 bluhm Exp $

# The following ports must be installed:
#
# python-2.7          interpreted object-oriented programming language
# scapy               powerful interactive packet manipulation in python

.if ! exists(/usr/local/bin/python2.7) || ! exists(/usr/local/bin/scapy)
.BEGIN:
	@true
regress:
	@echo Install python and the scapy module for additional tests.
	@echo SKIPPED
.endif

# This test needs a manual setup of two machines
# Set up machines: LOCAL REMOTE
# LOCAL is the machine where this makefile is running.
# REMOTE is running OpenBSD with or without pf to test fragment reassemly
# Enable echo udp in inetd.conf on REMOTE to test UDP fragments.
# REMOTE_SSH is used to login and enable or disable pf automatically.

# Configure addresses on the machines.
# Adapt interface and addresse variables to your local setup.

LOCAL_IF ?=	em1
LOCAL_MAC ?=	00:1b:21:0e:6e:8e
REMOTE_MAC ?=	00:04:23:b0:68:8e

LOCAL_ADDR ?=	10.188.81.21
REMOTE_ADDR ?=	10.188.81.22

REMOTE_SSH ?=

.if empty (LOCAL_IF) || empty (LOCAL_MAC) || empty (REMOTE_MAC) || \
    empty (LOCAL_ADDR) || empty (REMOTE_ADDR) || empty (REMOTE_SSH)
.BEGIN:
	@true
regress:
	@echo This tests needs a remote machine to operate on.
	@echo LOCAL_IF LOCAL_MAC REMOTE_MAC LOCAL_ADDR REMOTE_ADDR REMOTE_SSH
	@echo Fill out these variables for additional tests.
	@echo SKIPPED
.endif

.MAIN: all

.if make (regress) || make (all)
.BEGIN:
	@echo
	${SUDO} true
	ssh -t ${REMOTE_SSH} ${SUDO} true
	rm -f stamp-stack stamp-pf
.endif

# Create python include file containing the addresses.
addr.py: Makefile
	rm -f $@ $@.tmp
	echo 'LOCAL_IF = "${LOCAL_IF}"' >>$@.tmp
	echo 'LOCAL_MAC = "${LOCAL_MAC}"' >>$@.tmp
	echo 'REMOTE_MAC = "${REMOTE_MAC}"' >>$@.tmp
.for var in LOCAL_ADDR REMOTE_ADDR
	echo '${var} = "${${var}}"' >>$@.tmp
.endfor
	mv $@.tmp $@

# Set variables so that make runs with and without obj directory.
# Only do that if necessary to keep visible output short.
.if ${.CURDIR} == ${.OBJDIR}
PYTHON =	python2.7 -u ./
.else
PYTHON =	PYTHONPATH=${.OBJDIR} python2.7 -u ${.CURDIR}/
.endif

stamp-stack:
	@echo '\n======== $@ ========'
	rm -f stamp-stack stamp-pf
	-ssh ${REMOTE_SSH} ${SUDO} pfctl -d
	ssh ${REMOTE_SSH} ${SUDO} pfctl -a regress -Fr
	date >$@

stamp-pf: addr.py pf.conf
	@echo '\n======== $@ ========'
	rm -f stamp-stack stamp-pf
	cat addr.py ${.CURDIR}/pf.conf | /sbin/pfctl -n -f -
	cat addr.py ${.CURDIR}/pf.conf | \
	    ssh ${REMOTE_SSH} ${SUDO} pfctl -a regress -f -
	-ssh ${REMOTE_SSH} ${SUDO} pfctl -e
	date >$@

REGRESS_TARGETS =
FRAG_SCRIPTS !!=	cd ${.CURDIR} && ls -1 frag*.py

run-stack-frag_mf0long.py:
	@echo '\n======== $@ ========'
	# the stack allows fragments with data behind a fragment without MF
	@echo DISABLED

run-stack-frag_mf0short.py:
	@echo '\n======== $@ ========'
	# the stack allows fragments without MF ending before other fragments
	@echo DISABLED

run-stack-frag_mf1end.py:
	@echo '\n======== $@ ========'
	# the stack allows fragments with MF together with fragments without MF
	@echo DISABLED

run-stack-frag_queuelimit.py:
	@echo '\n======== $@ ========'
	# the stack does not limit the amount of fragments during reassembly
	@echo DISABLED

.for sp in stack pf

# Ping all addresses.  This ensures that the ip addresses are configured
# and all routing table are set up to allow bidirectional packet flow.
${sp}: run-${sp}-ping
REGRESS_TARGETS +=	run-${sp}-ping
run-${sp}-ping: stamp-${sp}
	@echo '\n======== $@ ========'
.for ip in LOCAL_ADDR REMOTE_ADDR
	@echo Check ping ${ip}:
	ping -n -c 1 ${${ip}}
.endfor

# Ping all addresses again but with 5000 bytes payload.  These large
# packets get fragmented by LOCAL and must be handled by REMOTE.
${sp}: run-${sp}-fragping
REGRESS_TARGETS +=	run-${sp}-fragping
run-${sp}-fragping: stamp-${sp}
	@echo '\n======== $@ ========'
.for ip in LOCAL_ADDR REMOTE_ADDR
	@echo Check ping ${ip}:
	ping -n -c 1 -s 5000 ${${ip}}
.endfor

.for s in ${FRAG_SCRIPTS}
${sp}: run-${sp}-${s}
REGRESS_TARGETS +=	run-${sp}-${s}
run-${sp}-${s}: addr.py stamp-${sp}
	@echo '\n======== $@ ========'
	${SUDO} ${PYTHON}${s}
.endfor

.endfor

# After running the tests, turn on pf on remote machine.
# This is the expected default configuration.
REGRESS_CLEANUP +=	cleanup-pf
cleanup-pf:
	@echo '\n======== $@ ========'
	rm -f stamp-stack stamp-pf
	ssh ${REMOTE_SSH} ${SUDO} pfctl -a regress -Fa
	-ssh ${REMOTE_SSH} ${SUDO} pfctl -e || true

CLEANFILES +=		addr.py *.pyc *.log stamp-*

.PHONY: check-setup check-setup-local check-setup-remote

# Check wether the address, route and remote setup is correct
check-setup: check-setup-local check-setup-remote

check-setup-local:
	@echo '\n======== $@ ========'
	ping -n -c 1 ${LOCAL_ADDR}  # LOCAL_ADDR
	route -n get -inet ${LOCAL_ADDR} |\
	    grep -q 'flags: .*LOCAL'  # LOCAL_ADDR
	ping -n -c 1 ${REMOTE_ADDR}  # REMOTE_ADDR
	route -n get -inet ${REMOTE_ADDR} |\
	    grep -q 'interface: ${LOCAL_IF}$$'  # REMOTE_ADDR LOCAL_IF
	arp -n ${REMOTE_ADDR} |\
	    grep -q ' ${REMOTE_MAC} '  # REMOTE_ADDR REMOTE_MAC

check-setup-remote:
	@echo '\n======== $@ ========'
	ssh ${REMOTE_SSH} ping -n -c 1 ${REMOTE_ADDR}  # REMOTE_ADDR
	ssh ${REMOTE_SSH} route -n get -inet ${REMOTE_ADDR} |\
	    grep -q 'flags: .*LOCAL'  # REMOTE_ADDR
	ssh ${REMOTE_SSH} ping -n -c 1 ${LOCAL_ADDR}  # LOCAL_ADDR
	ssh ${REMOTE_SSH} arp -n ${LOCAL_ADDR} |\
	    grep -q ' ${LOCAL_MAC} '  # LOCAL_ADDR LOCAL_MAC

.include <bsd.regress.mk>