1# $OpenBSD: Makefile,v 1.23 2024/12/27 10:53:46 bluhm Exp $ 2 3# The following ports must be installed for the regression tests: 4# p5-Socket6 Perl defines relating to AF_INET6 sockets 5# p5-IO-Socket-SSL perl interface to SSL 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 Socket6 } or print $@; \ 12 eval { require IO::Socket::SSL } or print $@; \ 13' 14.if ! empty (PERL_REQUIRE) 15regress: 16 @echo "${PERL_REQUIRE}" 17 @echo 'run "pkg_add p5-Socket6 p5-IO-Socket-SSL"' 18 @echo SKIPPED 19.endif 20 21REGRESS_SETUP_ONCE += setup 22setup: 23.if empty (REMOTE_SSH) 24 ${SUDO} true 25.else 26 ssh -t ${REMOTE_SSH} ${SUDO} true 27.endif 28 29# Fill out these variables if you want to test relayd with 30# the relayd process running on a remote machine. You have to specify 31# a local and remote ip address for the tcp connections. To control 32# the remote machine you need a hostname for ssh to log in. All the 33# test files must be in the same directory local and remote. 34 35LOCAL_ADDR ?= 36REMOTE_ADDR ?= 37REMOTE_SSH ?= 38 39# Automatically generate regress targets from test cases in directory. 40 41ARGS != cd ${.CURDIR} && ls args-*.pl 42CLEANFILES += *.log relayd.conf ktrace.out stamp-* 43CLEANFILES += *.pem *.req *.crt *.key *.srl 44 45# Set variables so that make runs with and without obj directory. 46# Only do that if necessary to keep visible output short. 47 48.if ${.CURDIR} == ${.OBJDIR} 49PERLINC = -I. 50PERLPATH = 51.else 52PERLINC = -I${.CURDIR} 53PERLPATH = ${.CURDIR}/ 54.endif 55 56# The arg tests take a perl hash with arguments controlling the 57# test parameters. Generally they consist of client, relayd, server. 58 59.for a in ${ARGS} 60REGRESS_TARGETS += run-$a 61run-$a: $a 62.if empty (REMOTE_SSH) 63 time SUDO="${SUDO}" KTRACE=${KTRACE} RELAYD=${RELAYD} perl ${PERLINC} ${PERLPATH}relayd.pl copy ${PERLPATH}$a 64 time SUDO="${SUDO}" KTRACE=${KTRACE} RELAYD=${RELAYD} perl ${PERLINC} ${PERLPATH}relayd.pl splice ${PERLPATH}$a 65.else 66 time SUDO="${SUDO}" KTRACE=${KTRACE} RELAYD=${RELAYD} perl ${PERLINC} ${PERLPATH}remote.pl copy ${LOCAL_ADDR} ${REMOTE_ADDR} ${REMOTE_SSH} ${PERLPATH}$a 67 time SUDO="${SUDO}" KTRACE=${KTRACE} RELAYD=${RELAYD} perl ${PERLINC} ${PERLPATH}remote.pl splice ${LOCAL_ADDR} ${REMOTE_ADDR} ${REMOTE_SSH} ${PERLPATH}$a 68.endif 69.endfor 70 71# create certificates for TLS 72 73.for ip in ${REMOTE_ADDR} 127.0.0.1 74${ip}.crt: ca.crt client-ca.crt 75 openssl req -batch -new \ 76 -subj /L=OpenBSD/O=relayd-regress/OU=relayd/CN=${ip}/ \ 77 -nodes -newkey rsa -keyout ${ip}.key -x509 \ 78 -out $@ 79.if empty (REMOTE_SSH) 80 ${SUDO} cp 127.0.0.1.crt /etc/ssl/ 81 ${SUDO} cp 127.0.0.1.key /etc/ssl/private/ 82.else 83 scp ${REMOTE_ADDR}.crt root@${REMOTE_SSH}:/etc/ssl/ 84 scp ${REMOTE_ADDR}.key root@${REMOTE_SSH}:/etc/ssl/private/ 85 scp ca.crt ca.key ${REMOTE_SSH}: 86 scp client-ca.crt client-ca.key ${REMOTE_SSH}: 87.endif 88.endfor 89 90ca.crt client-ca.crt: 91 openssl req -batch -new \ 92 -subj /L=OpenBSD/O=relayd-regress/OU=${@:R}/CN=root/ \ 93 -nodes -newkey rsa -keyout ${@:R}.key -x509 \ 94 -out $@ 95 96server.req client.req: 97 openssl req -batch -new \ 98 -subj /L=OpenBSD/O=relayd-regress/OU=${@:R}/CN=localhost/ \ 99 -nodes -newkey rsa -keyout ${@:R}.key \ 100 -out $@ 101 102server.crt: ca.crt server.req 103 openssl x509 -CAcreateserial -CAkey ca.key -CA ca.crt \ 104 -req -in server.req -out server.crt 105 106client.crt: client-ca.crt client.req 107 openssl x509 -CAcreateserial -CAkey client-ca.key -CA client-ca.crt \ 108 -req -in client.req -out client.crt 109 110${REGRESS_TARGETS:M*ssl*} ${REGRESS_TARGETS:M*https*}: server.crt client.crt 111.if empty (REMOTE_SSH) 112${REGRESS_TARGETS:M*ssl*} ${REGRESS_TARGETS:M*https*}: 127.0.0.1.crt 113.else 114${REGRESS_TARGETS:M*ssl*} ${REGRESS_TARGETS:M*https*}: ${REMOTE_ADDR}.crt 115.endif 116 117# make perl syntax check for all args files 118 119.PHONY: syntax 120 121syntax: stamp-syntax 122 123stamp-syntax: ${ARGS} 124.for a in ${ARGS} 125 @perl -c ${PERLPATH}$a 126.endfor 127 @date >$@ 128 129.include <bsd.regress.mk> 130