Makefile revision 1.2
1# $OpenBSD: Makefile,v 1.2 2017/10/27 17:11:12 bluhm Exp $ 2 3# The following ports must be installed: 4# 5# python-2.7 interpreted object-oriented programming language 6# py-libdnet python interface to libdnet 7# scapy powerful interactive packet manipulation in python 8 9.include <bsd.own.mk> 10 11.if ! (make(clean) || make(cleandir) || make(obj)) 12# Check wether all required python packages are installed. If some 13# are missing print a warning and skip the tests, but do not fail. 14PYTHON_IMPORT !!= python2.7 -c 'from scapy.all import *' 2>&1 || true 15.endif 16 17.if ! empty(PYTHON_IMPORT) 18.BEGIN: 19 @true 20regress: 21 @echo '${PYTHON_IMPORT}' 22 @echo Install python and the scapy module for additional tests. 23 @echo SKIPPED 24.endif 25 26.if ! empty (PERL_REQUIRE) 27regress: 28 @echo "${PERL_REQUIRE}" 29 @echo install these perl packages for additional tests 30.endif 31 32# This test needs a manual setup of two machines 33# Set up machines: LOCAL REMOTE 34# LOCAL is the machine where this makefile is running. 35# REMOTE is running OpenBSD with echo server to test PMTU 36# FAKE is an non existing machine in a non existing network. 37# REMOTE_SSH is the hostname to log in on the REMOTE machine. 38 39# Configure Addresses on the machines. 40# Adapt interface and addresse variables to your local setup. 41# 42LOCAL_IF ?= 43REMOTE_SSH ?= 44 45LOCAL_ADDR ?= 46REMOTE_ADDR ?= 47FAKE_NET ?= 48FAKE_NET_ADDR ?= 49 50.if empty (LOCAL_IF) || empty (REMOTE_SSH) || \ 51 empty (LOCAL_ADDR) || \ 52 empty (REMOTE_ADDR) || \ 53 empty (FAKE_NET) || \ 54 empty (FAKE_NET_ADDR) 55.BEGIN: 56 @true 57regress: 58 @echo This tests needs a remote machine to operate on 59 @echo LOCAL_IF REMOTE_SSH LOCAL_ADDR REMOTE_ADDR FAKE_NET FAKE_NET_ADDR 60 @echo are empty. Fill out these variables for additional tests. 61 @echo SKIPPED 62.endif 63 64.MAIN: all 65 66.if make (regress) || make (all) 67.BEGIN: pf.conf addr.py 68 @echo 69 ${SUDO} true 70 ssh -t ${REMOTE_SSH} true 71.endif 72 73# Create python include file containing the addresses. 74addr.py: Makefile 75 rm -f $@ $@.tmp 76 echo 'LOCAL_IF = "${LOCAL_IF}"' >>$@.tmp 77.for var in LOCAL REMOTE FAKE_NET 78 echo '${var}_ADDR = "${${var}_ADDR}"' >>$@.tmp 79.endfor 80 echo 'FAKE_NET = "${FAKE_NET}"' >>$@.tmp 81 mv $@.tmp $@ 82 83SCAPYS != cd ${.CURDIR} && ls scapy-*.py 84TARGETS = ${SCAPYS} 85 86# Set variables so that make runs with and without obj directory. 87# Only do that if necessary to keep visible output short. 88.if ${.CURDIR} == ${.OBJDIR} 89PYTHON = python2.7 -u 90SCAPYPATH = 91.else 92PYTHON = PYTHONPATH=${.OBJDIR} python2.7 -u 93SCAPYPATH = ${.CURDIR}/ 94.endif 95 96.for s in ${SCAPYS} 97run-regress-$s: $s addr.py 98 @echo '\n======== $@ ========' 99 time SUDO=${SUDO} PYTHON="${PYTHON}" perl ${PERLINC} ${PERLPATH}scapy.pl splice ${FAKE_NET_ADDR} ${REMOTE_ADDR} ${REMOTE_SSH} ${SCAPYPATH}$s 100.endfor 101 102CLEANFILES += addr.py *.pyc *.log stamp-* 103 104.PHONY: check-setup check-setup-local check-setup-remote 105 106# Check wether the address, route and remote setup is correct 107check-setup: check-setup-local check-setup-remote 108 109check-setup-local: 110 @echo '\n======== $@ ========' 111 ping -n -c 1 ${LOCAL_ADDR} # LOCAL_ADDR 112 route -n get -inet ${LOCAL_ADDR} | grep -q 'flags: .*LOCAL' # LOCAL_ADDR 113 ping -n -c 1 ${REMOTE_ADDR} # REMOTE_ADDR 114 route -n get -inet ${REMOTE_ADDR} | fgrep -q 'interface: ${LOCAL_IF}' # REMOTE_ADDR LOCAL_IF 115 ! ping -n -c 1 -w 1 ${FAKE_NET_ADDR} # FAKE_NET_ADDR 116.for ip in FAKE_NET FAKE_NET_ADDR 117 route -n get -inet ${${ip}} | grep -q 'flags: .*BLACKHOLE' # ${ip} 118.endfor 119 120check-setup-remote: 121 @echo '\n======== $@ ========' 122 ssh ${REMOTE_SSH} ping -n -c 1 ${REMOTE_ADDR} # REMOTE_ADDR 123 ssh ${REMOTE_SSH} route -n get -inet ${REMOTE_ADDR} | grep -q 'flags: .*LOCAL' # REMOTE_ADDR 124 ssh ${REMOTE_SSH} ping -n -c 1 ${LOCAL_ADDR} # LOCAL_ADDR 125.for ip in FAKE_NET FAKE_NET_ADDR 126 ssh ${REMOTE_SSH} route -n get -inet ${${ip}} | fgrep -q 'gateway: ${LOCAL_ADDR}' # ${ip} LOCAL_ADDR 127.endfor 128 129.include <bsd.regress.mk> 130