1*71ec8d3aScloder#!/bin/sh 2*71ec8d3aScloder# $OpenBSD: run.sh,v 1.1 2005/04/08 17:12:49 cloder Exp $ 3*71ec8d3aScloder# $EOM: run.sh,v 1.6 1999/08/05 15:02:33 niklas Exp $ 4*71ec8d3aScloder 5*71ec8d3aScloder# 6*71ec8d3aScloder# Copyright (c) 1998, 1999 Niklas Hallqvist. All rights reserved. 7*71ec8d3aScloder# 8*71ec8d3aScloder# Redistribution and use in source and binary forms, with or without 9*71ec8d3aScloder# modification, are permitted provided that the following conditions 10*71ec8d3aScloder# are met: 11*71ec8d3aScloder# 1. Redistributions of source code must retain the above copyright 12*71ec8d3aScloder# notice, this list of conditions and the following disclaimer. 13*71ec8d3aScloder# 2. Redistributions in binary form must reproduce the above copyright 14*71ec8d3aScloder# notice, this list of conditions and the following disclaimer in the 15*71ec8d3aScloder# documentation and/or other materials provided with the distribution. 16*71ec8d3aScloder# 17*71ec8d3aScloder# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18*71ec8d3aScloder# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19*71ec8d3aScloder# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20*71ec8d3aScloder# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21*71ec8d3aScloder# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22*71ec8d3aScloder# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23*71ec8d3aScloder# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24*71ec8d3aScloder# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25*71ec8d3aScloder# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26*71ec8d3aScloder# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*71ec8d3aScloder# 28*71ec8d3aScloder 29*71ec8d3aScloder# 30*71ec8d3aScloder# This code was written under funding by Ericsson Radio Systems. 31*71ec8d3aScloder# 32*71ec8d3aScloder 33*71ec8d3aScloder# Defaults 34*71ec8d3aScloderSRCPORT=1500 35*71ec8d3aScloderDSTPORT=1501 36*71ec8d3aScloderFIFO=test.fifo 37*71ec8d3aScloderTIMEOUT=2 38*71ec8d3aScloder 39*71ec8d3aScloderNC=${NC:-/usr/bin/nc} 40*71ec8d3aScloderISAKMPD=${ISAKMPD:-/sbin/isakmpd} 41*71ec8d3aScloder 42*71ec8d3aScloderprogname=`basename $0` 43*71ec8d3aScloderindent=`echo -n $progname |sed 's/./ /g'` 44*71ec8d3aScloderseed=980801 45*71ec8d3aScloderinitiator=yes 46*71ec8d3aScloderretval=0 47*71ec8d3aScloderverbose=no 48*71ec8d3aScloderclean=yes 49*71ec8d3aScloder 50*71ec8d3aScloderusage () 51*71ec8d3aScloder{ 52*71ec8d3aScloder echo "usage: $progname [-nrv] [-d dst-port] [-f fifo] [-s src-port]" >&2 53*71ec8d3aScloder echo " $indent [-t timeout] testsuite" >&2 54*71ec8d3aScloder exit 2 55*71ec8d3aScloder} 56*71ec8d3aScloder 57*71ec8d3aScloderset -- `getopt d:f:nrs:t:v $*` 58*71ec8d3aScloderif [ $? != 0 ]; then 59*71ec8d3aScloder usage 60*71ec8d3aScloderfi 61*71ec8d3aScloderfor i; do 62*71ec8d3aScloder case "$i" in 63*71ec8d3aScloder -d) 64*71ec8d3aScloder DSTPORT=$2; shift; shift;; 65*71ec8d3aScloder -f) 66*71ec8d3aScloder FIFO=$2; shift; shift;; 67*71ec8d3aScloder -n) 68*71ec8d3aScloder clean=no; shift;; 69*71ec8d3aScloder -r) 70*71ec8d3aScloder initiator=no; shift;; 71*71ec8d3aScloder -s) 72*71ec8d3aScloder SRCPORT=$2; shift; shift;; 73*71ec8d3aScloder -t) 74*71ec8d3aScloder TIMEOUT=$2; shift; shift;; 75*71ec8d3aScloder -v) 76*71ec8d3aScloder verbose=yes; shift;; 77*71ec8d3aScloder --) 78*71ec8d3aScloder shift; break;; 79*71ec8d3aScloder esac 80*71ec8d3aScloderdone 81*71ec8d3aScloder 82*71ec8d3aScloderif [ $# -eq 1 ]; then 83*71ec8d3aScloder suite=$1 84*71ec8d3aScloderelse 85*71ec8d3aScloder usage 86*71ec8d3aScloderfi 87*71ec8d3aScloder 88*71ec8d3aScloder[ ${verbose} = yes ] && set -x 89*71ec8d3aScloder 90*71ec8d3aScloder# Start isakmpd and wait for the fifo to get created 91*71ec8d3aScloderecho Removing ${FIFO} 92*71ec8d3aScloderrm -f ${FIFO} 93*71ec8d3aScloder${ISAKMPD} -d -p${SRCPORT} -f${FIFO} -r${seed} & 94*71ec8d3aScloderisakmpd_pid=$! 95*71ec8d3aScloderecho isakmpd pid is $isakmpd_pid 96*71ec8d3aSclodertrap 'echo Got signal; kill $isakmpd_pid; echo Removing ${FIFO}; rm -f ${FIFO}; [ $clean = yes ] && rm -f packet' 1 2 15 97*71ec8d3aScloderwhile [ ! -p ${FIFO} ]; do 98*71ec8d3aScloder sleep 1 99*71ec8d3aScloderdone 100*71ec8d3aScloder 101*71ec8d3aScloder# Start the exchange 102*71ec8d3aScloderif [ $initiator = yes ]; then 103*71ec8d3aScloder ${NC} -nul -w${TIMEOUT} 127.0.0.1 ${DSTPORT} </dev/null >packet & 104*71ec8d3aScloder# ${NC} -nu -w${TIMEOUT} -p${SRCPORT} 127.0.0.1 ${DSTPORT} </dev/null >packet 105*71ec8d3aScloder sleep 1 106*71ec8d3aScloder echo "c udp 127.0.0.1:${DSTPORT} 2 1" >${FIFO} 107*71ec8d3aScloder in_packets=`ls ${suite}-i.* 2>/dev/null` 108*71ec8d3aScloder out_packets=`ls ${suite}-r.* 2>/dev/null` 109*71ec8d3aScloderelse 110*71ec8d3aScloder in_packets=`ls ${suite}-r.* 2>/dev/null` 111*71ec8d3aScloder out_packets=`ls ${suite}-i.* 2>/dev/null` 112*71ec8d3aScloderfi 113*71ec8d3aScloderhis_turn=$initiator 114*71ec8d3aScloderwhile [ \( $his_turn = yes -a X"$in_packets" != X \) \ 115*71ec8d3aScloder -o \( $his_turn = no -a X"$out_packets" != X \) ]; do 116*71ec8d3aScloder if [ $his_turn = no ]; then 117*71ec8d3aScloder set $out_packets 118*71ec8d3aScloder packet=$1 119*71ec8d3aScloder shift 120*71ec8d3aScloder out_packets=$* 121*71ec8d3aScloder cat $packet |${NC} -nu -w${TIMEOUT} -p${SRCPORT} 127.0.0.1 ${DSTPORT} \ 122*71ec8d3aScloder >packet 123*71ec8d3aScloder my_turn=no 124*71ec8d3aScloder else 125*71ec8d3aScloder set $in_packets 126*71ec8d3aScloder packet=$1 127*71ec8d3aScloder shift 128*71ec8d3aScloder in_packets=$* 129*71ec8d3aScloder if ! cmp $packet packet 2>/dev/null; then 130*71ec8d3aScloder retval=1 131*71ec8d3aScloder break 132*71ec8d3aScloder fi 133*71ec8d3aScloder my_turn=yes 134*71ec8d3aScloder fi 135*71ec8d3aScloderdone 136*71ec8d3aScloderkill $isakmpd_pid 137*71ec8d3aScloderrm -f ${FIFO} 138*71ec8d3aScloder[ $clean = yes ] && rm -f packet 139*71ec8d3aScloderexit $retval 140