1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-06-03 17:16:51 +00:00

Fixed a few testing issues

This commit is contained in:
Gerhard Rieger 2025-01-28 01:25:22 +01:00
parent f38b76f5c8
commit af7d44d751
6 changed files with 227 additions and 47 deletions

View file

@ -11,6 +11,8 @@ Testing:
test.sh produces file results.txt with columns of test numbers, names, test.sh produces file results.txt with columns of test numbers, names,
and results. and results.
Fixed a few testing issues
####################### V 1.8.0.2: ####################### V 1.8.0.2:
Security: Security:

View file

@ -1 +1 @@
"1.8.0.2" "1.8.0.2+"

View file

@ -37,6 +37,7 @@ while [ "$1" ]; do
X-q) QUIET=1; OPTS="-d0" ;; X-q) QUIET=1; OPTS="-d0" ;;
X-d*|X-l?*) OPTS="$OPTS $1" ;; X-d*|X-l?*) OPTS="$OPTS $1" ;;
X-b|X-S|X-t|X-T|X-l) OPT=$1; shift; OPTS="$OPTS $OPT $1" ;; X-b|X-S|X-t|X-T|X-l) OPT=$1; shift; OPTS="$OPTS $OPT $1" ;;
X--experimental) ;;
X-) break ;; X-) break ;;
X-*) echo "Unknown option \"$1\"" >&2 X-*) echo "Unknown option \"$1\"" >&2
usage >&2 usage >&2

View file

@ -77,6 +77,7 @@ while [ "$1" ]; do
X-q) QUIET=1; OPTS="-d0" ;; X-q) QUIET=1; OPTS="-d0" ;;
X-d*|X-l?*) OPTS="$OPTS $1" ;; X-d*|X-l?*) OPTS="$OPTS $1" ;;
X-b|X-S|X-t|X-T|X-l) OPT=$1; shift; OPTS="$OPTS $OPT $1" ;; X-b|X-S|X-t|X-T|X-l) OPT=$1; shift; OPTS="$OPTS $OPT $1" ;;
X--experimental) ;;
X-) break ;; X-) break ;;
X-*) echo "$0: Unknown option \"$1\"" >&2 X-*) echo "$0: Unknown option \"$1\"" >&2
usage >&2 usage >&2

View file

@ -43,6 +43,7 @@ while [ "$1" ]; do
X-q) QUIET=1; OPTS="-d0" ;; X-q) QUIET=1; OPTS="-d0" ;;
X-d*|X-l?*) OPTS="$OPTS $1" ;; X-d*|X-l?*) OPTS="$OPTS $1" ;;
X-b|X-S|X-t|X-T|X-l) OPT=$1; shift; OPTS="$OPTS $OPT $1" ;; X-b|X-S|X-t|X-T|X-l) OPT=$1; shift; OPTS="$OPTS $OPT $1" ;;
X--experimental) ;;
X-) break ;; X-) break ;;
X-*) echo "$0: Unknown option \"$1\"" >&2 X-*) echo "$0: Unknown option \"$1\"" >&2
usage >&2 usage >&2

267
test.sh
View file

@ -48,6 +48,7 @@ usage() {
$ECHO "\t-d \t\tShow log output of commands, even when they did not fail (not yet completed)" $ECHO "\t-d \t\tShow log output of commands, even when they did not fail (not yet completed)"
$ECHO "\t-D \t\tOutput some platform/system specific defines (variables)" $ECHO "\t-D \t\tOutput some platform/system specific defines (variables)"
$ECHO "\t--internet \tAllow tests that send packets to Internet" $ECHO "\t--internet \tAllow tests that send packets to Internet"
$ECHO "\t--experimental \tApply --experimental option to Socat"
$ECHO "\t--expect-fail N1,N2,... \tIgnore failure of these tests" $ECHO "\t--expect-fail N1,N2,... \tIgnore failure of these tests"
$ECHO "\ttest-spec \Number of test or name of test" $ECHO "\ttest-spec \Number of test or name of test"
$ECHO "Contents of environment variable OPTS are passed to Socat invocations, e.'g:" $ECHO "Contents of environment variable OPTS are passed to Socat invocations, e.'g:"
@ -78,8 +79,9 @@ while [ "$1" ]; do
X-n) shift; NUMCOND="test \$N -eq $1" ;; X-n) shift; NUMCOND="test \$N -eq $1" ;;
X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;; X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
X-N) shift; NUMCOND="test \$N -ge $1" ;; X-N) shift; NUMCOND="test \$N -ge $1" ;;
X-C) rm -f testcert*.conf testcert.dh testcli*.* testsrv*.* ;; X-C) rm -f testcert*.conf testcert.dh testcli*.* testsrv*.* testalt.* ;;
X--internet|X-internet) INTERNET=1 ;; # allow access to 3rd party Internet hosts X--internet|X-internet) INTERNET=1 ;; # allow access to 3rd party Internet hosts
X--experimental) EXPERIMENTAL=1 ;;
X--expect-fail|X-expect-fail) OPT_EXPECT_FAIL=1; shift; EXPECT_FAIL="$1" ;; X--expect-fail|X-expect-fail) OPT_EXPECT_FAIL=1; shift; EXPECT_FAIL="$1" ;;
X-*) echo "Unknown option \"$1\"" >&2 X-*) echo "Unknown option \"$1\"" >&2
usage >&2 usage >&2
@ -129,16 +131,23 @@ if [ -z "$PROCAN" ]; then if test -x ./procan; then PROCAN="./procan"; elif type
if [ -z "$FILAN" ]; then if test -x ./filan; then FILAN="./filan"; elif ! type filan >/dev/null 2>&1; then FILAN=filan; elif test -x ${SOCAT%/*}/filan; then FILAN=${SOCAT%/*}/filan; else FILAN=false; fi; fi if [ -z "$FILAN" ]; then if test -x ./filan; then FILAN="./filan"; elif ! type filan >/dev/null 2>&1; then FILAN=filan; elif test -x ${SOCAT%/*}/filan; then FILAN=${SOCAT%/*}/filan; else FILAN=false; fi; fi
[ "$DEFS" ] && echo "FILAN=\"$FILAN\"" >&2 [ "$DEFS" ] && echo "FILAN=\"$FILAN\"" >&2
if ! sleep 0.1 2>/dev/null; then
sleep () {
$SOCAT -T $0 PIPE PIPE
}
fi
if [ -z "$val_t" ]; then if [ -z "$val_t" ]; then
# Determine the time Socat needs for an empty run # Determine the time Socat needs for an empty run
$SOCAT /dev/null /dev/null # populate caches $SOCAT /dev/null /dev/null # populate caches
MILLIs=$(bash -c 'time socat /dev/null /dev/null' 2>&1 |grep ^real |sed 's/.*m\(.*\)s.*/\1/' |tr -d ,.) MILLIs=$(bash -c 'time $SOCAT /dev/null /dev/null' 2>&1 |grep ^real |sed 's/.*m\(.*\)s.*/\1/' |tr -d ,.)
while [ "${MILLIs:0:1}" = '0' ]; do MILLIs=${MILLIs##0}; done # strip leading '0' to avoid octal while [ "${MILLIs:0:1}" = '0' ]; do MILLIs=${MILLIs##0}; done # strip leading '0' to avoid octal
[ -z "$MILLIs" ] && MILLIs=1 [ -z "$MILLIs" ] && MILLIs=1
[ "$DEFS" ] && echo "MILLIs=\"$MILLIs\" (1)" >&2 [ "$DEFS" ] && echo "MILLIs=\"$MILLIs\" (1)" >&2
# On my idle development computer this value flaps from 0.001 to 0.004 # On my idle development computer this value flaps from 0.001 to 0.004
# 0.001 lets many tests fail, so we triple the result # 0.001 lets many tests fail, so we triple the result
#MILLIs=$((10*MILLIs))
MILLIs=$((3*MILLIs)) MILLIs=$((3*MILLIs))
[ "$DEFS" ] && echo "MILLIs=\"$MILLIs\" (2)" >&2 [ "$DEFS" ] && echo "MILLIs=\"$MILLIs\" (2)" >&2
MICROS=${MILLIs}000 MICROS=${MILLIs}000
@ -191,6 +200,7 @@ PATH=.:$PATH # for usleep,relsleep
MISCDELAY=1 MISCDELAY=1
OPTS="$opt_t $OPTS" OPTS="$opt_t $OPTS"
[ "$EXPERIMENTAL" ] && OPTS="--experimental $OPTS"
opts="$OPTS" opts="$OPTS"
[ "$DEFS" ] && echo "opts=\"$opts\"" >&2 [ "$DEFS" ] && echo "opts=\"$opts\"" >&2
@ -356,12 +366,12 @@ IP.2 = ::1
EOF EOF
# clean up from previous runs # clean up from previous runs - no, only with -C
rm -f testcli.{crt,key,pem} #rm -f testcli.{crt,key,pem}
rm -f testsrv.{crt,key,pem} #rm -f testsrv.{crt,key,pem}
rm -f testcli6.{crt,key,pem} #rm -f testcli6.{crt,key,pem}
rm -f testsrv6.{crt,key,pem} #rm -f testsrv6.{crt,key,pem}
rm -f testalt.{crt,key,pem} #rm -f testalt.{crt,key,pem}
CAT="cat" CAT="cat"
OD_C="od -c" OD_C="od -c"
@ -657,20 +667,12 @@ vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256col
RED="\0033[31m" RED="\0033[31m"
GREEN="\0033[32m" GREEN="\0033[32m"
YELLOW="\0033[33m" YELLOW="\0033[33m"
# if [ "$UNAME" = SunOS ]; then NORMAL="\0033[39m"
# NORMAL="\0033[30m" else # "\101"
# else
NORMAL="\0033[39m"
# fi
else
RED="\033[31m" RED="\033[31m"
GREEN="\033[32m" GREEN="\033[32m"
YELLOW="\033[33m" YELLOW="\033[33m"
# if [ "$UNAME" = SunOS ]; then NORMAL="\033[39m"
# NORMAL="\033[30m"
# else
NORMAL="\033[39m"
# fi
fi fi
OK="${GREEN}OK${NORMAL}" OK="${GREEN}OK${NORMAL}"
FAILED="${RED}FAILED${NORMAL}" FAILED="${RED}FAILED${NORMAL}"
@ -787,6 +789,63 @@ fi
/bin/rm "$TF-diff" /bin/rm "$TF-diff"
esac esac
case "$TESTS" in
*%consistency%*)
# Test if help shows option types without inconsistency
$ECHO "testing if help shows option types correctly...\c"
TF="$TD/socat-hhh"
LINE="$($SOCAT -hhh |grep "^[[:space:]]*ip-add-source-membership\>")"
if [ -z "$LINE" ]; then
$ECHO $CANT
else
TYPE="$($ECHO "$LINE" |sed 's/^.*type=\([^[:space:]][^[:space:]]*\).*/\1/')"
if [ "$TYPE" != "IP-MREQ-SOURCE" ]; then
$ECHO "\n*** help does not show option types correctly" >&2
exit 1
else
echo " ok"
fi
fi
esac
case "$TESTS" in
*%consistency%*)
# Test if help shows option phases without inconsistency
$ECHO "testing if help shows option phases correctly...\c"
TF="$TD/socat-hhh"
LINE="$($SOCAT -hhh |grep "^[[:space:]]*dash\>")"
if [ -z "$LINE" ]; then
$ECHO $CANT
else
PHASE="$($ECHO "$LINE" |sed 's/^.*phase=\([^[:space:]][^[:space:]]*\).*/\1/')"
if [ "$PHASE" != "PREEXEC" ]; then
$ECHO "\n*** help does not show option phases correctly" >&2
exit 1
else
echo " ok"
fi
fi
esac
case "$TESTS" in
*%consistency%*)
# Test if help shows option groups without inconsistency
$ECHO "testing if help shows option groups correctly...\c"
TF="$TD/socat-hhh"
LINE="$($SOCAT -hhh |grep "^[[:space:]]*udplite-recv-cscov\>")"
if [ -z "$LINE" ]; then
$ECHO $CANT
else
GROUP="$($ECHO "$LINE" |sed 's/^.*groups=\([^[:space:]][^[:space:]]*\).*/\1/')"
if [ "$GROUP" != "UDPLITE" ]; then
$ECHO "\n*** help does not show option groups correctly" >&2
exit 1
else
echo " ok"
fi
fi
esac
#============================================================================== #==============================================================================
N=1 N=1
@ -976,6 +1035,10 @@ testoptions () {
# if not: prints ev.message to stderr, returns 1 # if not: prints ev.message to stderr, returns 1
childprocess () { childprocess () {
local l local l
case "$1" in
[1-9]*) ;;
*) echo "childprocess \"$1\": not a number" >&2; exit 1 ;;
esac
case "$UNAME" in case "$UNAME" in
AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;; AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;;
FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;; FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;;
@ -999,6 +1062,10 @@ childprocess () {
childpids () { childpids () {
local recursive i local recursive i
if [ "X$1" = "X-r" ]; then recursive=1; shift; fi if [ "X$1" = "X-r" ]; then recursive=1; shift; fi
case "$1" in
[1-9]*) ;;
*) echo "childpids \"$1\": not a number" >&2; exit 1 ;;
esac
case "$UNAME" in case "$UNAME" in
AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)" |awk '{print($2);}')" ;; AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)" |awk '{print($2);}')" ;;
FreeBSD) l="$(ps -fl |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$1[ ]" |awk '{print($2);}')" ;; FreeBSD) l="$(ps -fl |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$1[ ]" |awk '{print($2);}')" ;;
@ -1204,7 +1271,7 @@ runsunix () {
routesip6 () { routesip6 () {
runsip6 >/dev/null || { echo route6; return 1; } runsip6 >/dev/null || { echo route6; return 1; }
ping -c 1 -s 0 -6 2606:4700:4700::1111 >/dev/null 2>&1 || { echo route6; return 1; } $PING6 -c 1 2606:4700:4700::1111 >/dev/null 2>&1 || { echo route6; return 1; }
return 0; return 0;
} }
@ -1236,13 +1303,6 @@ checkconds() {
[ "$i" ] && { echo "Only on (one of) $unames"; return 255; } [ "$i" ] && { echo "Only on (one of) $unames"; return 255; }
fi fi
if [ "$root" = "root" ]; then
if [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
echo "Must be root"
return 255
fi
fi
if [ "$progs" ]; then if [ "$progs" ]; then
for i in $progs; do for i in $progs; do
if ! type >/dev/null 2>&1; then if ! type >/dev/null 2>&1; then
@ -1283,11 +1343,20 @@ checkconds() {
fi fi
if [ "$inet" ]; then if [ "$inet" ]; then
if [ -z "$NTERNET" ]; then if [ -z "$INTERNET" ]; then
echo "Use test.sh option --internet" echo "Use test.sh option --internet"
return 255 return 255
fi fi
fi fi
# Only at the end, so we get a better overview of missing features
if [ "$root" = "root" ]; then
if [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
echo "Must be root"
return 255
fi
fi
return 0 return 0
} }
@ -1319,7 +1388,7 @@ waitip4proto () {
# SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;; # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
# HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;; # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
# OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;; # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
*) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;; *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
relsleep 5; return 0 ;; relsleep 5; return 0 ;;
esac esac
[ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
@ -1444,7 +1513,7 @@ waittcp4port () {
OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;; OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;; CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;; DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
*) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;; *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
esac esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
@ -1525,7 +1594,7 @@ waitudp4port () {
HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;; HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;; OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;; DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
*) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;; *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
esac esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
@ -1586,7 +1655,7 @@ waitsctp4port () {
while [ $timeout -gt 0 ]; do while [ $timeout -gt 0 ]; do
case "$UNAME" in case "$UNAME" in
Linux) if [ "$SS" ]; then Linux) if [ "$SS" ]; then
l=$($SS -4 -n 2>/dev/null |grep "^sctp.*LISTEN .*:$port\>") l=$($SS -4 -a -n 2>/dev/null |grep "^sctp.*LISTEN .*:$port\>")
else else
l=$(netstat -n -a |grep '^sctp .*[0-9*]:'$port' .* LISTEN') l=$(netstat -n -a |grep '^sctp .*[0-9*]:'$port' .* LISTEN')
fi ;; fi ;;
@ -1601,7 +1670,7 @@ waitsctp4port () {
# HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;; # HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
# OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;; # OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
# CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;; # CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
*) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;; *) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
esac esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
@ -1631,6 +1700,7 @@ waitudplite4port () {
Linux) #if [ "$SS" ]; then Linux) #if [ "$SS" ]; then
#l=$($SS -4 -l -n -u |grep "^UNCONN .*:$port\>") #l=$($SS -4 -l -n -u |grep "^UNCONN .*:$port\>")
#else #else
# On Ubuntu-20 only netstat shows udplite ports
if ! netstat -nU >/dev/null 2>&1; then if ! netstat -nU >/dev/null 2>&1; then
return 0 # speculative return 0 # speculative
fi fi
@ -1665,6 +1735,51 @@ waitudplite4port () {
return 1 return 1
} }
# wait until an DCCP4 listen port is ready
waitdccp4port () {
local port="$1"
local logic="$2" # 0..wait until free; 1..wait until listening
local timeout="$3"
local l
local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
[ "$logic" ] || logic=1
[ "$timeout" ] || timeout=5
while [ $timeout -gt 0 ]; do
case "$UNAME" in
Linux)
# On Ubuntu-20, only ss shows DCCP ports
if [ "$SS" ]; then
l=$($SS -4 -a -n 2>/dev/null |grep "^dccp.*LISTEN .*:$port\>")
else
l=$(netstat -n -a |grep '^dccp .*[0-9*]:'$port' .* LISTEN')
fi ;;
# FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
# NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
# Darwin) case "$(uname -r)" in
# [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
# *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
# esac ;;
# AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
SunOS) l=$(netstat -an -f inet -P dccp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
# HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
# OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
# CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
*) l=$(netstat -an |grep -i 'dccp .*[0-9*][:.]'$port' .* listen') ;;
esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then
set ${vx}vx
return 0
fi
sleep $val_t
timeout=$((timeout-1))
done
$ECHO "!port $port timed out! \c" >&2
set ${vx}vx
return 1
}
# check if a TCP6 port is in use # check if a TCP6 port is in use
# exits with 0 when it is not used # exits with 0 when it is not used
checktcp6port () { checktcp6port () {
@ -1696,7 +1811,7 @@ waittcp6port () {
SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;; SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
#OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;; #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;; DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
*) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;; *) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;;
esac esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
@ -1746,7 +1861,7 @@ waitudp6port () {
#HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;; #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
#OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;; #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;; DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
*) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;; *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
esac esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
@ -1781,9 +1896,9 @@ waitsctp6port () {
while [ $timeout -gt 0 ]; do while [ $timeout -gt 0 ]; do
case "$UNAME" in case "$UNAME" in
Linux) if [ "$SS" ]; then Linux) if [ "$SS" ]; then
l=$($SS -6 -n 2>/dev/null |grep "^LISTEN .*:$port\>") l=$($SS -6 -a -n 2>/dev/null |grep "^sctp .*LISTEN .*:$port\>")
else else
l=$(netstat -an |grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN') l=$(netstat -an |grep '^sctp[6 ] .* \*:'$port' .* LISTEN')
fi ;; fi ;;
# FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;; # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
# NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;; # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
@ -1791,7 +1906,7 @@ waitsctp6port () {
# AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;; # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;; SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
# #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;; # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
*) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;; *) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
esac esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
@ -1852,6 +1967,45 @@ waitudplite6port () {
return 1 return 1
} }
# wait until a dccp6 listen port is ready
# not all (Linux) variants show this in netstat
waitdccp6port () {
local port="$1"
local logic="$2" # 0..wait until free; 1..wait until listening
local timeout="$3"
local l
local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
[ "$logic" ] || logic=1
[ "$timeout" ] || timeout=5
while [ $timeout -gt 0 ]; do
case "$UNAME" in
Linux) if [ "$SS" ]; then
l=$($SS -6 -a -n 2>/dev/null |grep "^dccp .*LISTEN .*:$port\>")
else
l=$(netstat -an |grep '^dccp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN')
fi ;;
# FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
# NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
# OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
# AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
SunOS) l=$(netstat -an -f inet6 -P dccp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
# #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
*) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
esac
if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
\( \( $logic -eq 0 \) -a -z "$l" \) ]; then
set ${vx}vx
return 0
fi
sleep $val_t
timeout=$((timeout-1))
done
$ECHO "!port $port timed out! \c" >&2
set ${vx}vx
return 1
}
# we need this misleading function name for canonical reasons # we need this misleading function name for canonical reasons
waitunixport () { waitunixport () {
waitfile "$1" "$2" "$3" waitfile "$1" "$2" "$3"
@ -1895,6 +2049,15 @@ case "$UNAME" in
*) SOCK_SEQPACKET=5 ;; *) SOCK_SEQPACKET=5 ;;
esac esac
if [ "$INTERNET" ]; then
# No "-s 24" on Solaris
if ! ping -c 1 "server-4.dest-unreach.net" >/dev/null 2>&1; then
echo "$0: Option --internet but no connectivity or DNS" >&2
#exit 1
fi
fi
# generate a test certificate and key # generate a test certificate and key
gentestcert () { gentestcert () {
local name="$1" local name="$1"
@ -5004,7 +5167,7 @@ waittcp4port $PORT3 1 50 || $PRINTF "$FAILED: port $PORT3\n" >&2 </dev/null
# now we start the external daemon # now we start the external daemon
eval "$CMD5 2>\"${te}5\" &" eval "$CMD5 2>\"${te}5\" &"
pid5=$! pid5=$!
waittcp4port $PORT5 1 50 || $PRINTF "$FAILED: port $5PORT\n" >&2 </dev/null waittcp4port $PORT5 1 50 || $PRINTF "$FAILED: port $PORT5\n" >&2 </dev/null
# and this is the outside client: # and this is the outside client:
echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" & echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" &
pid6_1=$! pid6_1=$!
@ -5014,7 +5177,7 @@ echo "$da3" |$CMD6 >${tf}_3 2>"${te}6_3" &
pid6_3=$! pid6_3=$!
wait $pid6_1 $pid6_2 $pid6_3 wait $pid6_1 $pid6_2 $pid6_3
kill $pid1 $pid2 $pid3 $pid4 $pid5 $(childpids $pid5) 2>/dev/null kill $pid1 $pid2 $pid3 $pid4 $pid5 $(childpids $pid5) 2>/dev/null
# (On BSDs a child of pid5 loves to hang) # (On BSDs a child of pid5 likes to hang)
# #
(echo "$da1"; relsleep 2) |diff - "${tf}_1" >"${tdiff}1" (echo "$da1"; relsleep 2) |diff - "${tf}_1" >"${tdiff}1"
(echo "$da2"; relsleep 2) |diff - "${tf}_2" >"${tdiff}2" (echo "$da2"; relsleep 2) |diff - "${tf}_2" >"${tdiff}2"
@ -12027,7 +12190,7 @@ if [ "$ERRNOENT" ]; then
cat "$tlog" >&2 cat "$tlog" >&2
failed failed
elif [ "$user" != "$SUBSTUSER" ]; then elif [ "$user" != "$SUBSTUSER" ]; then
$PRINTF "${FAILD}(user \"$user\", expected \"$SUBSTUSER\")\n" $PRINTF "${FAILED}(user \"$user\", expected \"$SUBSTUSER\")\n"
echo "$CMD0 &" echo "$CMD0 &"
cat "$te0" >&2 cat "$te0" >&2
failed failed
@ -12812,7 +12975,20 @@ TEST="$NAME: is option ipv6-join-group used"
# Terminate immediately, do not transfer data. # Terminate immediately, do not transfer data.
# If socat exits with 0 the test succeeds. # If socat exits with 0 the test succeeds.
# Up to 1.7.3.1 it failed with "1 option(s) could not be used" # Up to 1.7.3.1 it failed with "1 option(s) could not be used"
if ! eval $NUMCOND; then :; else if ! eval $NUMCOND; then :;
elif ! cond=$(checkconds \
"" \
"" \
"" \
"IP6 UDP GOPEN" \
"UDP6-RECV GOPEN" \
"ipv6-join-group" \
"udp6" ); then
$PRINTF "test $F_n $TEST... ${YELLOW}$cond${NORMAL}\n" $N
numCANT=$((numCANT+1))
listCANT="$listCANT $N"
namesCANT="$namesCANT $NAME"
else
tf="$td/test$N.stdout" tf="$td/test$N.stdout"
te="$td/test$N.stderr" te="$td/test$N.stderr"
tdiff="$td/test$N.diff" tdiff="$td/test$N.diff"
@ -16935,9 +17111,8 @@ te="$td/test$N.stderr"
tdiff="$td/test$N.diff" tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM" da="test$N $(date) $RANDOM"
#CMD0="$TRACE $SOCAT $opts PIPE SYSTEM:\"$SOCAT\ -dddd\ -lf ${te}1\ PIPE\ PIPE\",setsid,sigint" #CMD0="$TRACE $SOCAT $opts PIPE SYSTEM:\"$SOCAT\ -dddd\ -lf ${te}1\ PIPE\ PIPE\",setsid,sigint"
# -T is required on (only?) OpenBSD-4 # Without -T process remains on OpenBSD-4, AIX, ?
CMD0="$TRACE $SOCAT $opts -T 2 SOCKETPAIR SYSTEM:\"$SOCAT\ -dddd\ -lf\ ${te}1\ PIPE\ PIPE\",setsid,sigint" CMD0="$TRACE $SOCAT $opts -T 2 SOCKETPAIR SYSTEM:\"$SOCAT\ -dddd\ -T\ 1\ -lf ${te}1\ PIPE\ PIPE\",setsid,sigint"
#CMD0="$TRACE $SOCAT $opts -T 2 SOCKETPAIR SYSTEM:\"$SOCAT\ -dddd\ -T\ 1\ -lf ${te}1\ PIPE\ PIPE\",setsid,sigint"
printf "test $F_n $TEST... " $N printf "test $F_n $TEST... " $N
eval $CMD0 >/dev/null 2>"${te}0" & eval $CMD0 >/dev/null 2>"${te}0" &
pid0=$! pid0=$!
@ -18733,7 +18908,7 @@ elif ! cond=$(checkconds \
"" \ "" \
"IP6 TCP LISTEN FILE" \ "IP6 TCP LISTEN FILE" \
"TCP-LISTEN TCP6-CONNECT FILE" \ "TCP-LISTEN TCP6-CONNECT FILE" \
"" \ "ai-addrconfig" \
"tcp6" ); then "tcp6" ); then
$PRINTF "test $F_n $TEST... ${YELLOW}$cond${NORMAL}\n" $N $PRINTF "test $F_n $TEST... ${YELLOW}$cond${NORMAL}\n" $N
cant cant