Check which getprotobynumber_r() variant to use
[socat.git] / test.sh
blobc334fbf4b7347ccb4d2dedad2a7d51cb0d1b4538
1 #! /usr/bin/env bash
2 # source: test.sh
3 # Copyright Gerhard Rieger and contributors (see file CHANGES)
4 # Published under the GNU General Public License V.2, see file COPYING
6 # perform lots of tests on socat
8 # this script uses functions; you need a shell that supports them
10 # you can pass general options to socat: export OPTS="-d -d -d -d -lu"
11 # you can eg strace socat with: export TRACE="strace -v -tt -ff -D -x -s 1024 -o /tmp/$USER/socat.strace"
12 #set -vx
14 val_t=0.1
15 NUMCOND=true
16 #NUMCOND="test \$N -gt 70"
17 VERBOSE=
18 FOREIGN=
19 while [ "$1" ]; do
20 case "X$1" in
21 X-t?*) val_t="${1#-t}" ;;
22 X-t) shift; val_t="$1" ;;
23 X-v) VERBOSE=1 ;; # show commands
24 X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
25 X-n) shift; NUMCOND="test \$N -eq $1" ;;
26 X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
27 X-N) shift; NUMCOND="test \$N -ge $1" ;;
28 X-C) rm -f testcert*.conf testcert.dh testcli*.* testsrv*.* ;;
29 X-foreign) FOREIGN=1 ;; # allow access to 3rd party Internet hosts
30 *) break;
31 esac
32 shift
33 done
35 opt_t="-t $val_t"
37 UNAME=`uname`
38 UNAME_R=`uname -r`
40 #MICROS=100000
41 case "X$val_t" in
42 X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
43 X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
44 X*) S="${val_t}"; uS="000000" ;;
45 esac
46 MICROS=${S}${uS}
47 MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
48 #echo MICROS=$MICROS >&2
50 _MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
51 [ -z "$SECONDs" ] && SECONDs=0
53 withroot=0 # perform privileged tests even if not run by root
54 #PATH=$PATH:/opt/freeware/bin
55 #PATH=$PATH:/usr/local/ssl/bin
56 PATH=$PATH:/sbin # RHEL6:ip
57 case "$0" in
58 */*) PATH="${0%/*}:$PATH"
59 esac
60 #OPENSSL_RAND="-rand /dev/egd-pool"
61 #SOCAT_EGD="egd=/dev/egd-pool"
62 MISCDELAY=1
63 [ -z "$SOCAT" ] && SOCAT="./socat"
64 if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
65 echo "$SOCAT does not exist" >&2; exit 1;
67 if [ -z "$PROCAN" ]; then if test -x ./procan; then PROCAN="./procan"; elif ! type procan >/dev/null 2>&1; then PROCAN=${SOCAT%/*}/procan; fi; fi
68 if [ -z "$FILAN" ]; then if test -x ./filan; then FILAN="./filan"; elif ! type filan >/dev/null 2>&1; then FILAN=${SOCAT%/*}/filan; fi; fi
69 opts="$opt_t $OPTS"
70 export SOCAT_OPTS="$opts"
71 #debug="1"
72 debug=
73 TESTS="$*"; export TESTS
74 if ! $SOCAT -V >/dev/null 2>&1; then
75 echo "Failed to execute $SOCAT, exiting" >&2
76 exit 1
79 SOCAT_VERSION=$($SOCAT -V |head -n 2 |tail -n 1 |sed 's/.* \([0-9][1-9]*\.[0-9][0-9]*\.[0-9][^[:space:]]*\).*/\1/')
80 if [ -z "$SOCAT_VERSION" ]; then
81 echo "Warning: failed to retrieve Socat version" >&2
84 # for some tests we need a network interface
85 if type ip >/dev/null 2>&1; then
86 INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
87 else
88 case "$UNAME" in
89 Linux)
90 if [ "$IP" ]; then
91 INTERFACE="$($IP route get 8.8.8.8 |grep ' dev ' |sed -e 's/.* dev //' -e 's/ .*//')"
92 else
93 INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($8);}')"
94 fi ;;
95 FreeBSD) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
96 *) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
97 esac
99 MCINTERFACE=$INTERFACE
100 [ -z "$MCINTERFACE" ] && MCINTERFACE=lo # !!! Linux only - and not always
101 #LOCALHOST=192.168.58.1
102 LOCALHOST=localhost
103 #LOCALHOST=127.0.0.1
104 LOCALHOST6="[::1]"
105 #PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
106 #PROTO=$(($PROTO+1))
107 PROTO=$((144+RANDOM/2048))
108 PORT=12002
109 SOURCEPORT=2002
110 REUSEADDR=reuseaddr # use this with LISTEN addresses and bind options
112 # SSL certificate contents
113 TESTCERT_CONF=testcert.conf
114 TESTCERT6_CONF=testcert6.conf
115 TESTALT_CONF=testalt.conf
117 TESTCERT_COMMONNAME="$LOCALHOST"
118 TESTCERT_COMMONNAME6="$LOCALHOST6"
119 TESTCERT_COUNTRYNAME="XY"
120 TESTCERT_LOCALITYNAME="Lunar Base"
121 TESTCERT_ORGANIZATIONALUNITNAME="socat"
122 TESTCERT_ORGANIZATIONNAME="dest-unreach"
123 TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
124 TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
125 RSABITS=2048 # Ubuntu-20.04 with OpenSSL-1.1.1f does not work with 1024 nor 1536
126 DSABITS=2048
127 cat >$TESTCERT_CONF <<EOF
128 prompt=no
130 [ req ]
131 default_bits = $RSABITS
132 distinguished_name=Test
134 [ Test ]
135 countryName=$TESTCERT_COUNTRYNAME
136 commonName=$TESTCERT_COMMONNAME
137 O=$TESTCERT_ORGANIZATIONNAME
138 OU=$TESTCERT_ORGANIZATIONALUNITNAME
139 L=$TESTCERT_LOCALITYNAME
143 cat >$TESTCERT6_CONF <<EOF
144 prompt=no
146 [ req ]
147 default_bits = $RESBITS
148 distinguished_name=Test
150 [ Test ]
151 countryName=$TESTCERT_COUNTRYNAME
152 commonName=$TESTCERT_COMMONNAME6
153 O=$TESTCERT_ORGANIZATIONNAME
154 OU=$TESTCERT_ORGANIZATIONALUNITNAME
155 L=$TESTCERT_LOCALITYNAME
159 cat >$TESTALT_CONF <<EOF
160 # config for generation of self signed certificate with IP addresses in
161 # SubjectAltNames
162 prompt=no
164 [ req ]
165 default_bits = $RSABITS
166 distinguished_name = subject
167 x509_extensions = x509_ext
169 [ subject ]
170 countryName=$TESTCERT_COUNTRYNAME
171 commonName=servername
172 O=$TESTCERT_ORGANIZATIONNAME
173 OU=$TESTCERT_ORGANIZATIONALUNITNAME
174 L=$TESTCERT_LOCALITYNAME
176 [ x509_ext ]
177 subjectAltName = @alternate_names
179 [ alternate_names ]
180 DNS.1 = localhost
181 DNS.2 = localhost4
182 DNS.3 = localhost6
183 IP.1 = 127.0.0.1
184 IP.2 = ::1
188 # clean up from previous runs
189 rm -f testcli.{crt,key,pem}
190 rm -f testsrv.{crt,key,pem}
191 rm -f testcli6.{crt,key,pem}
192 rm -f testsrv6.{crt,key,pem}
193 rm -f testalt.{crt,key,pem}
195 CAT="cat"
196 OD_C="od -c"
198 toupper () {
199 case ${BASH_VERSION:0:1} in
200 [1-3]) echo "$@" |tr a-z A-Z ;;
201 [4-9]) echo "${@^^*}" ;;
202 esac
205 tolower () {
206 case ${BASH_VERSION:0:1} in
207 [1-3]) echo "$@" |tr A-Z a-z ;;
208 [4-9]) echo "${@,,*}" ;;
209 esac
212 # precision sleep; takes seconds with fractional part
213 psleep () {
214 local T="$1"
215 [ "$T" = 0 ] && T=0.000002
216 $SOCAT -T "$T" pipe pipe
218 # time in microseconds to wait in some situations
219 if ! type usleep >/dev/null 2>&1 ||
220 usleep 0 2>&1 |grep -q deprecated; then
221 usleep () {
222 local n="$1"
223 case "$n" in
224 *???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
225 *) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
226 esac
227 $SOCAT -T "$S.$uS" pipe pipe
230 #USLEEP=usleep
232 if type ping6 >/dev/null 2>&1; then
233 PING6=ping6
234 else
235 PING6="ping -6"
238 F_n="%3d" # format string for test numbers
239 export LC_ALL=C # for timestamps format...
240 export LANG=C
241 export LANGUAGE=C # knoppix
242 case "$UNAME" in
243 HP-UX|OSF1)
244 echo "$SOCAT -u stdin stdout" >cat.sh
245 chmod a+x cat.sh
246 CAT=./cat.sh
248 SunOS)
249 # /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
250 # /usr/xpg4/bin/tr instead
251 alias tr=/usr/xpg4/bin/tr
254 CAT="cat"
256 esac
258 case "$UNAME" in
259 #HP-UX)
260 # # on HP-UX, the default options (below) hang some tests (former 14, 15)
261 # PTYOPTS=
262 # PTYOPTS2=
263 # ;;
265 PTYOPTS="echo=0,opost=0"
266 #PTYOPTS2="raw,echo=0"
267 PTYOPTS2="cfmakeraw"
268 #PTYOPTS2="rawer"
270 esac
272 # for some tests we need an unprivileged user id to su to
273 if [ "$SUDO_USER" ]; then
274 SUBSTUSER="$SUDO_USER"
275 else
276 SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
279 if type ip >/dev/null 2>&1; then
280 if ip -V |grep -q "^ip utility, iproute2-"; then
281 IP=$(type -p ip)
282 else
283 unset IP
287 if type ss >/dev/null 2>&1; then
288 if ss -V |grep -q "^ss utility, iproute2-"; then
289 SS=$(type -p ss)
290 else
291 unset SS
295 if [ -z "$SS" ]; then
296 # non-root users might miss ifconfig in their path
297 case "$UNAME" in
298 AIX) IFCONFIG=/usr/sbin/ifconfig ;;
299 FreeBSD) IFCONFIG=/sbin/ifconfig ;;
300 HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
301 Linux) IFCONFIG=/sbin/ifconfig ;;
302 NetBSD)IFCONFIG=/sbin/ifconfig ;;
303 OpenBSD)IFCONFIG=/sbin/ifconfig ;;
304 OSF1) IFCONFIG=/sbin/ifconfig ;;
305 SunOS) IFCONFIG=/sbin/ifconfig ;;
306 Darwin)IFCONFIG=/sbin/ifconfig ;;
307 DragonFly) IFCONFIG=/sbin/ifconfig ;;
308 *) IFCONFIG=/sbin/ifconfig ;;
309 esac
312 # need output like "644"
313 case "$UNAME" in
314 Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
315 FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
316 *) fileperms() {
317 local p s=0 c
318 p="$(ls -l -L "$1" |awk '{print($1);}')"
319 p="${p:1:9}"
320 while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
321 printf "%03o\n" $s;
322 } ;;
323 esac
325 # need user (owner) of filesystem entry
326 case "$UNAME" in
327 Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
328 FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
329 *) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
330 esac
332 if2addr4() {
333 local IF="$1"
334 if [ "$IP" ]; then
335 $IP address show dev "$IF" |grep "inet " |sed -e "s/.*inet //" -e "s/ .*//"
336 else
337 $IFCONFIG "$BROADCASTIF" |grep 'inet ' |awk '{print($2);}' |cut -d: -f2
341 if2bc4() {
342 local IF="$1"
343 if [ "$IP" ]; then
344 $IP address show dev "$IF" |grep ' inet .* brd ' |awk '{print($4);}'
345 else
346 $IFCONFIG "$IF" |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}'
350 # for some tests we need a second local IPv4 address
351 case "$UNAME" in
352 Linux)
353 if [ "$IP" ]; then
354 BROADCASTIF=$($IP r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
355 else
356 BROADCASTIF=$(route -n |grep '^0.0.0.0 ' |awk '{print($8);}')
358 [ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
359 SECONDADDR=127.1.0.1
360 SECONDMASK=255.255.0.0
361 BCADDR=127.255.255.255
362 BCIFADDR=$(if2addr4 $BROADCASTIF) ;;
363 FreeBSD|NetBSD|OpenBSD)
364 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
365 BROADCASTIF="$MAINIF"
366 SECONDADDR=$($IFCONFIG "$BROADCASTIF" |grep 'inet ' |awk '{print($2);}')
367 BCIFADDR="$SECONDADDR"
368 BCADDR=$($IFCONFIG "$BROADCASTIF" |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
369 HP-UX)
370 MAINIF=lan0 # might use "netstat -ni" for this
371 BROADCASTIF="$MAINIF"
372 SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
373 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
374 SunOS)
375 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
376 BROADCASTIF="$MAINIF"
377 #BROADCASTIF=hme0
378 #BROADCASTIF=eri0
379 #SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
380 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
381 #BCIFADDR="$SECONDADDR"
382 #BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
384 DragonFly)
385 MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
386 BROADCASTIF="$MAINIF"
387 SECONDADDR=$($IFCONFIG "$BROADCASTIF" |grep 'inet ' |awk '{print($2);}')
388 BCIFADDR="$SECONDADDR"
389 BCADDR=$($IFCONFIG "$BROADCASTIF" |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
390 #AIX|FreeBSD|Solaris)
392 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
394 esac
395 # for generic sockets we need this address in hex form
396 if [ "$SECONDADDR" ]; then
397 SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' ' '))"
400 # for some tests we need a second local IPv6 address
401 case "$UNAME" in
402 Linux) if [ "$IP" ]; then
403 SECONDIP6ADDR=$(expr "$($IP address |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet6 \([0-9a-f:][0-9a-f:]*\)/.*')
404 else
405 SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
406 fi ;;
408 SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
410 esac
411 if [ -z "$SECONDIP6ADDR" ]; then
412 # case "$TESTS" in
413 # *%root2%*) $IFCONFIG eth0 ::2/128
414 # esac
415 SECONDIP6ADDR="$LOCALHOST6"
416 else
417 SECONDIP6ADDR="[$SECONDIP6ADDR]"
420 TRUE=$(type true)
421 #E=-e # Linux
422 if [ $(echo "x\c") = "x" ]; then E=""
423 elif [ $(echo -e "x\c") = "x" ]; then E="-e"
424 else
425 echo "cannot suppress trailing newline on echo" >&2
426 exit 1
428 ECHO="echo $E"
429 PRINTF="printf"
431 case "$TERM" in
432 vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color|screen)
433 # there are different behaviours of printf (and echo)
434 # on some systems, echo behaves different than printf...
435 if [ "$($PRINTF "\0101")" = "A" ]; then
436 RED="\0033[31m"
437 GREEN="\0033[32m"
438 YELLOW="\0033[33m"
439 # if [ "$UNAME" = SunOS ]; then
440 # NORMAL="\0033[30m"
441 # else
442 NORMAL="\0033[39m"
443 # fi
444 else
445 RED="\033[31m"
446 GREEN="\033[32m"
447 YELLOW="\033[33m"
448 # if [ "$UNAME" = SunOS ]; then
449 # NORMAL="\033[30m"
450 # else
451 NORMAL="\033[39m"
452 # fi
454 OK="${GREEN}OK${NORMAL}"
455 FAILED="${RED}FAILED${NORMAL}"
456 NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
458 *) OK="OK"
459 FAILED="FAILED"
460 NO_RESULT="NO RESULT"
462 esac
464 if [ -x /usr/xpg4/bin/id ]; then
465 # SunOS has rather useless tools in its default path
466 PATH="/usr/xpg4/bin:$PATH"
469 OPENSSL_S_CLIENT_4=
470 OPENSSL_S_CLIENT_DTLS=
471 init_openssl_s_client () {
472 if openssl s_client -help 2>&1 |grep -q ' -4 '; then
473 OPENSSL_S_CLIENT_4="-4"
474 else
475 OPENSSL_S_CLIENT_4=" "
477 if openssl s_client -help 2>&1 | grep -q ' -dtls '; then
478 OPENSSL_S_CLIENT_DTLS=-dtls
479 else
480 OPENSSL_S_CLIENT_DTLS=-dtls1
484 OPENSSL_S_SERVER_4=
485 OPENSSL_S_SERVER_DTLS=
486 OPENSSL_S_SERVER_NO_IGN_EOF=
487 init_openssl_s_server () {
488 if openssl s_server -help 2>&1 |grep -q ' -4 '; then
489 OPENSSL_S_SERVER_4="-4"
490 else
491 OPENSSL_S_SERVER_4=" "
493 if openssl s_server -help 2>&1 | grep -q ' -dtls '; then
494 OPENSSL_S_SERVER_DTLS="-dtls"
495 else
496 OPENSSL_S_SERVER_DTLS="-dtls1"
498 if openssl s_server -help 2>&1 | grep -q ' -no-ign_eof '; then
499 OPENSSL_S_SERVER_NO_IGN_EOF="-no-ign_eof"
500 else
501 OPENSSL_S_SERVER_NO_IGN_EOF=" "
506 [ -z "$TESTS" ] && TESTS="consistency functions filan"
507 # use '%' as separation char
508 TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
510 [ -z "$USER" ] && USER="$LOGNAME" # HP-UX
511 if [ -z "$TMPDIR" ]; then
512 if [ -z "$TMP" ]; then
513 TMP=/tmp
515 TMPDIR="$TMP"
517 TD="$TMPDIR/$USER/$$"; td="$TD"
518 rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
519 mkdir -p "$TD"
520 #trap "rm -r $TD" 0 3
522 echo "Using temp directory $TD"
524 case "$TESTS" in
525 *%consistency%*)
526 # test if addresses are sorted alphabetically:
527 $ECHO "testing if address array is sorted...\c"
528 TF="$TD/socat-q"
529 IFS="$($ECHO ' \n\t')"
530 $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
531 $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done |LC_ALL=C sort |diff "$TF" - >"$TF-diff"
532 if [ -s "$TF-diff" ]; then
533 $ECHO "\n*** address array is not sorted. Wrong entries:" >&2
534 cat "$TD/socat-q-diff" >&2
535 exit 1
536 else
537 echo " ok"
539 #/bin/rm "$TF"
540 #/bin/rm "$TF-diff"
541 esac
543 case "$TESTS" in
544 *%consistency%*)
545 # test if address options array ("optionnames") is sorted alphabetically:
546 $ECHO "testing if address options are sorted...\c"
547 TF="$TD/socat-qq"
548 $SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
549 LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
550 if [ -s "$TF-diff" ]; then
551 $ECHO "\n*** option array is not sorted. Wrong entries:" >&2
552 cat "$TD/socat-qq-diff" >&2
553 exit 1
554 else
555 echo " ok"
557 /bin/rm "$TF"
558 /bin/rm "$TF-diff"
559 esac
561 #==============================================================================
562 case "$TESTS" in
563 *%options%*)
565 # inquire which options are available
566 OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
567 OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
568 OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
569 OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
570 OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
571 OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
572 OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
573 OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
574 OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
575 OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
576 OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
577 OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
578 OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
579 OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
580 OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
581 OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
582 OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
583 OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
584 OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
585 OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
586 OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
587 OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
588 OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
589 OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
590 OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
591 OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
592 OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
593 OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
594 OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
595 OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
597 # find user ids to setown to; non-root only can setown to itself
598 if [ $(id -u) = 0 ]; then
599 # up to now, it is not a big problem when these do not exist
600 _UID=nobody
601 _GID=staff
602 else
603 _UID=$(id -u)
604 _GID=$(id -g)
607 # some options require values; here we try to replace these bare options with
608 # valid forms.
609 filloptionvalues() {
610 local OPTS=",$1,"
612 case "$OPTS" in
613 *,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
614 esac
615 case "$OPTS" in
616 *,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
617 esac
618 case "$OPTS" in
619 *,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
620 esac
621 case "$OPTS" in
622 *,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
623 esac
624 case "$OPTS" in
625 *,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
626 esac
627 case "$OPTS" in
628 *,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
629 esac
630 case "$OPTS" in
631 *,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
632 esac
633 case "$OPTS" in
634 *,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
635 esac
636 case "$OPTS" in
637 *,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
638 esac
639 case "$OPTS" in
640 *,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
641 esac
642 case "$OPTS" in
643 *,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
644 esac
645 case "$OPTS" in
646 *,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
647 esac
648 case "$OPTS" in
649 *,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
650 esac
651 case "$OPTS" in
652 *,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
653 esac
654 case "$OPTS" in
655 *,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
656 esac
657 case "$OPTS" in
658 *,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
659 esac
660 case "$OPTS" in
661 *,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
662 esac
663 case "$OPTS" in
664 *,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
665 esac
666 case "$OPTS" in
667 *,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
668 esac
669 # SOCKET
670 case "$OPTS" in
671 *,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
672 esac
673 case "$OPTS" in
674 *,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
675 esac
676 case "$OPTS" in
677 *,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
678 esac
679 # IP
680 case "$OPTS" in
681 *,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
682 esac
683 case "$OPTS" in
684 *,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
685 esac
686 case "$OPTS" in
687 *,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
688 esac
689 case "$OPTS" in
690 *,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
691 esac
692 # PTY
693 case "$OPTS" in
694 *,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
695 esac
696 # RETRY
697 case "$OPTS" in
698 *,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
699 esac
700 # READLINE
701 case "$OPTS" in
702 *,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
703 esac
704 case "$OPTS" in
705 *,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
706 esac
707 case "$OPTS" in
708 *,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
709 esac
710 # IPAPP
711 case "$OPTS" in
712 *,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
713 esac
714 # OPENSSL
715 case "$OPTS" in
716 *,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
717 esac
718 case "$OPTS" in
719 *,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
720 esac
721 case "$OPTS" in
722 *,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
723 esac
724 case "$OPTS" in
725 *,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
726 esac
727 case "$OPTS" in
728 *,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
729 esac
730 case "$OPTS" in
731 *,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
732 esac
733 case "$OPTS" in
734 *,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
735 esac
736 case "$OPTS" in
737 *,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
738 esac
739 case "$OPTS" in
740 *,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
741 esac
742 # PROXY
743 case "$OPTS" in
744 *,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
745 esac
746 case "$OPTS" in
747 *,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
748 esac
749 case "$OPTS" in
750 *,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
751 esac
752 # TCP-WRAPPERS
753 case "$OPTS" in
754 *,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
755 esac
756 case "$OPTS" in
757 *,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
758 esac
759 case "$OPTS" in
760 *,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
761 esac
762 echo $OPTS >&2
763 expr "$OPTS" : ',\(.*\),'
765 # OPTS_FIFO: nothing yet
767 # OPTS_CHR: nothing yet
769 # OPTS_BLK: nothing yet
771 # OPTS_REG: nothing yet
773 OPTS_SOCKET=",$OPTS_SOCKET,"
774 OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
777 #------------------------------------------------------------------------------
779 #method=open
780 #METHOD=$(echo "$method" |tr a-z A-Z)
781 #TEST="$METHOD on file accepts all its options"
782 # echo "### $TEST"
783 #TF=$TD/file$N
784 #DA="test$N $(date) $RANDOM"
785 #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
786 #for g in $(echo $OPTGROUPS |tr ',' ' '); do
787 # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
788 # OPTS="$OPTS,$OPTG";
789 #done
790 ##echo $OPTS
792 #for o in $(filloptionvalues $OPTS|tr ',' ' '); do
793 # echo testing if $METHOD accepts option $o
794 # touch $TF
795 # $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
796 # rm -f $TF
797 #done
799 #------------------------------------------------------------------------------
801 # test openssl connect
803 #set -vx
804 if true; then
805 #if false; then
806 #opts="-s -d -d -d -d"
807 pid=$!
808 for addr in openssl; do
809 ADDR=$(echo "$addr" |tr a-z A-Z)
810 TEST="$ADDR accepts all its options"
811 echo "### $TEST"
812 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
813 # echo OPTGROUPS=$OPTGROUPS
814 OPTS=
815 for g in $(echo $OPTGROUPS |tr ',' ' '); do
816 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
817 OPTS="$OPTS,$OPTG";
818 done
819 echo $OPTS
820 openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
821 pid=$!
822 sleep 1
823 #waittcp4port $PORT
824 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
825 echo "testing if $ADDR accepts option $o"
826 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
827 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
828 done
829 kill $pid
830 done
831 kill $pid 2>/dev/null
832 opts=
833 PORT=$((PORT+1))
836 #------------------------------------------------------------------------------
838 # test proxy connect
840 #set -vx
841 if true; then
842 #if false; then
843 #opts="-s -d -d -d -d"
844 pid=$!
845 for addr in proxy; do
846 ADDR=$(echo "$addr" |tr a-z A-Z)
847 TEST="$ADDR accepts all its options"
848 echo "### $TEST"
849 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
850 # echo OPTGROUPS=$OPTGROUPS
851 OPTS=
852 for g in $(echo $OPTGROUPS |tr ',' ' '); do
853 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
854 OPTS="$OPTS,$OPTG";
855 done
856 echo $OPTS
857 # prepare dummy server
858 $SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/usr/bin/env bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
859 pid=$!
860 sleep 1
861 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
862 echo "testing if $ADDR accepts option $o"
863 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
864 $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
865 done
866 kill $pid 2>/dev/null
867 done
868 kill $pid 2>/dev/null
869 opts=
870 PORT=$((PORT+2))
873 #------------------------------------------------------------------------------
875 # test tcp4
877 #set -vx
878 if true; then
879 #if false; then
880 #opts="-s -d -d -d -d"
881 $SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
882 pid=$!
883 for addr in tcp4; do
884 ADDR=$(echo "$addr" |tr a-z A-Z)
885 TEST="$ADDR accepts all its options"
886 echo "### $TEST"
887 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
888 # echo OPTGROUPS=$OPTGROUPS
889 OPTS=
890 for g in $(echo $OPTGROUPS |tr ',' ' '); do
891 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
892 OPTS="$OPTS,$OPTG";
893 done
894 echo $OPTS
895 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
896 echo "testing if $ADDR accepts option $o"
897 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
898 done
899 done
900 kill $pid 2>/dev/null
901 opts=
902 PORT=$((PORT+1))
905 #------------------------------------------------------------------------------
907 # test udp4-connect
909 #set -vx
910 if true; then
911 #if false; then
912 #opts="-s -d -d -d -d"
913 $SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
914 pid=$!
915 for addr in udp4-connect; do
916 ADDR=$(echo "$addr" |tr a-z A-Z)
917 TEST="$ADDR accepts all its options"
918 echo "### $TEST"
919 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
920 # echo OPTGROUPS=$OPTGROUPS
921 OPTS=
922 for g in $(echo $OPTGROUPS |tr ',' ' '); do
923 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
924 OPTS="$OPTS,$OPTG";
925 done
926 echo $OPTS
927 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
928 echo "testing if $ADDR accepts option $o"
929 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
930 done
931 done
932 kill $pid 2>/dev/null
933 opts=
934 PORT=$((PORT+1))
937 #------------------------------------------------------------------------------
939 # test tcp4-listen
941 #set -vx
942 if true; then
943 #if false; then
944 #opts="-s -d -d -d -d"
945 for addr in tcp4-listen; do
946 ADDR=$(echo "$addr" |tr a-z A-Z)
947 TEST="$ADDR accepts all its options"
948 echo "### $TEST"
949 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
950 OPTS=
951 for g in $(echo $OPTGROUPS |tr ',' ' '); do
952 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
953 OPTS="$OPTS,$OPTG";
954 done
955 echo $OPTS
956 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
957 echo "testing if $ADDR accepts option $o"
958 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
959 pid=$!
960 $SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
961 kill $pid 2>/dev/null
962 done
963 done
964 opts=
965 PORT=$((PORT+1))
968 #------------------------------------------------------------------------------
970 # test udp4-listen
972 #set -vx
973 if true; then
974 #if false; then
975 #opts="-s -d -d -d -d"
976 for addr in udp4-listen; do
977 ADDR=$(echo "$addr" |tr a-z A-Z)
978 TEST="$ADDR accepts all its options"
979 echo "### $TEST"
980 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
981 OPTS=
982 for g in $(echo $OPTGROUPS |tr ',' ' '); do
983 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
984 OPTS="$OPTS,$OPTG";
985 done
986 echo $OPTS
987 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
988 echo "testing if $ADDR accepts option $o"
989 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
990 pid=$!
991 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
992 kill $pid 2>/dev/null
993 done
994 done
995 opts=
996 PORT=$((PORT+1))
999 #------------------------------------------------------------------------------
1001 # test udp4-sendto
1003 #set -vx
1004 if true; then
1005 #if false; then
1006 #opts="-s -d -d -d -d"
1007 $SOCAT $opts udp4-recv:$PORT,fork,$o echo </dev/null &
1008 pid=$!
1009 for addr in udp4-sendto; do
1010 ADDR=$(echo "$addr" |tr a-z A-Z)
1011 TEST="$ADDR accepts all its options"
1012 echo "### $TEST"
1013 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1014 # echo OPTGROUPS=$OPTGROUPS
1015 OPTS=
1016 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1017 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1018 OPTS="$OPTS,$OPTG";
1019 done
1020 echo $OPTS
1021 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1022 echo "testing if $ADDR accepts option $o"
1023 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
1024 done
1025 done
1026 kill $pid 2>/dev/null
1027 opts=
1028 PORT=$((PORT+1))
1031 #------------------------------------------------------------------------------
1033 # test udp4-datagram
1035 #set -vx
1036 if true; then
1037 #if false; then
1038 #opts="-s -d -d -d -d"
1039 #$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
1040 #pid=$!
1041 for addr in udp4-datagram; do
1042 ADDR=$(echo "$addr" |tr a-z A-Z)
1043 TEST="$ADDR accepts all its options"
1044 echo "### $TEST"
1045 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1046 # echo OPTGROUPS=$OPTGROUPS
1047 OPTS=
1048 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1049 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1050 OPTS="$OPTS,$OPTG";
1051 done
1052 echo $OPTS
1053 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1054 echo "testing if $ADDR accepts option $o"
1055 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
1056 done
1057 done
1058 #kill $pid 2>/dev/null
1059 opts=
1060 PORT=$((PORT+1))
1063 #------------------------------------------------------------------------------
1065 # test udp4-recv
1067 #set -vx
1068 if true; then
1069 #if false; then
1070 #opts="-s -d -d -d -d"
1071 for addr in udp4-recv; do
1072 ADDR=$(echo "$addr" |tr a-z A-Z)
1073 TEST="$ADDR accepts all its options"
1074 echo "### $TEST"
1075 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1076 OPTS=
1077 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1078 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1079 OPTS="$OPTS,$OPTG";
1080 done
1081 echo $OPTS
1082 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1083 echo "testing if $ADDR accepts option $o"
1084 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1085 pid=$!
1086 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
1087 kill $pid 2>/dev/null
1088 done
1089 done
1090 opts=
1091 PORT=$((PORT+1))
1094 #------------------------------------------------------------------------------
1096 # test udp4-recvfrom
1098 #set -vx
1099 if true; then
1100 #if false; then
1101 #opts="-s -d -d -d -d"
1102 for addr in udp4-recvfrom; do
1103 ADDR=$(echo "$addr" |tr a-z A-Z)
1104 TEST="$ADDR accepts all its options"
1105 echo "### $TEST"
1106 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1107 OPTS=
1108 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1109 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1110 OPTS="$OPTS,$OPTG";
1111 done
1112 echo $OPTS
1113 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1114 echo "testing if $ADDR accepts option $o"
1115 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1116 pid=$!
1117 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
1118 kill $pid 2>/dev/null
1119 done
1120 done
1121 opts=
1122 PORT=$((PORT+1))
1125 #------------------------------------------------------------------------------
1127 # test ip4-sendto
1129 #set -vx
1130 if true; then
1131 #if false; then
1132 #opts="-s -d -d -d -d"
1133 $SOCAT $opts ip4-recv:$PORT,fork,$o echo </dev/null &
1134 pid=$!
1135 for addr in ip4-sendto; do
1136 ADDR=$(echo "$addr" |tr a-z A-Z)
1137 TEST="$ADDR accepts all its options"
1138 echo "### $TEST"
1139 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1140 # echo OPTGROUPS=$OPTGROUPS
1141 OPTS=
1142 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1143 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1144 OPTS="$OPTS,$OPTG";
1145 done
1146 echo $OPTS
1147 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1148 echo "testing if $ADDR accepts option $o"
1149 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
1150 done
1151 done
1152 kill $pid 2>/dev/null
1153 opts=
1154 PORT=$((PORT+1))
1157 #------------------------------------------------------------------------------
1159 # test ip4-recv
1161 #set -vx
1162 if true; then
1163 #if false; then
1164 #opts="-s -d -d -d -d"
1165 for addr in ip4-recv; do
1166 ADDR=$(echo "$addr" |tr a-z A-Z)
1167 TEST="$ADDR accepts all its options"
1168 echo "### $TEST"
1169 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1170 OPTS=
1171 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1172 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1173 OPTS="$OPTS,$OPTG";
1174 done
1175 echo $OPTS
1176 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1177 echo "testing if $ADDR accepts option $o"
1178 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1179 pid=$!
1180 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1181 kill $pid 2>/dev/null
1182 done
1183 done
1184 opts=
1185 PORT=$((PORT+1))
1188 #------------------------------------------------------------------------------
1190 # test ip4-recvfrom
1192 #set -vx
1193 if true; then
1194 #if false; then
1195 #opts="-s -d -d -d -d"
1196 for addr in ip4-recvfrom; do
1197 ADDR=$(echo "$addr" |tr a-z A-Z)
1198 TEST="$ADDR accepts all its options"
1199 echo "### $TEST"
1200 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1201 OPTS=
1202 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1203 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1204 OPTS="$OPTS,$OPTG";
1205 done
1206 echo $OPTS
1207 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1208 echo "testing if $ADDR accepts option $o"
1209 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1210 pid=$!
1211 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1212 kill $pid 2>/dev/null
1213 done
1214 done
1215 opts=
1216 PORT=$((PORT+1))
1219 #------------------------------------------------------------------------------
1221 # test READLINE
1223 if true; then
1224 #if false; then
1225 #opts="-s -d -d -d -d"
1226 for addr in readline; do
1227 ADDR=$(echo "$addr" |tr a-z A-Z)
1228 TEST="$ADDR accepts all its options"
1229 echo "### $TEST"
1230 TS=$TD/script$N
1231 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1232 OPTS=
1233 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1234 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1235 OPTS="$OPTS,$OPTG";
1236 done
1237 #echo $OPTS
1238 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1239 # for o in bs0; do
1240 echo "testing if $ADDR accepts option $o"
1241 echo "$SOCAT $opts readline,$o /dev/null" >$TS
1242 chmod u+x $TS
1243 $SOCAT /dev/null,ignoreeof exec:$TS,pty
1244 #stty sane
1245 done
1246 #reset 1>&0 2>&0
1247 done
1248 opts=
1251 #------------------------------------------------------------------------------
1253 # unnamed pipe
1254 #if false; then
1255 if true; then
1256 for addr in pipe; do
1257 ADDR=$(echo "$addr" |tr a-z A-Z)
1258 TEST="unnamed $ADDR accepts all its options"
1259 echo "### $TEST"
1260 OPTGROUPS=$($SOCAT -? |egrep " $addr[^:]" |sed 's/.*=//')
1261 OPTS=
1262 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1263 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1264 OPTS="$OPTS,$OPTG";
1265 done
1266 #echo $OPTS
1268 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1269 echo testing if unnamed $ADDR accepts option $o
1270 $SOCAT $opts $addr,$o /dev/null </dev/null
1271 done
1272 done
1275 #------------------------------------------------------------------------------
1277 # test addresses on files
1280 #if false; then
1281 if true; then
1282 for addr in create; do
1283 ADDR=$(echo "$addr" |tr a-z A-Z)
1284 TEST="$ADDR on new file accepts all its options"
1285 echo "### $TEST"
1286 TF=$TD/file$N
1287 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1288 OPTS=
1289 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1290 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1291 OPTS="$OPTS,$OPTG";
1292 done
1293 #echo $OPTS
1295 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1296 echo testing if $ADDR accepts option $o
1297 rm -f $TF
1298 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1299 rm -f $TF
1300 done
1301 done
1303 #------------------------------------------------------------------------------
1305 #if false; then
1306 if true; then
1307 for addr in exec system; do
1308 ADDR=$(echo "$addr" |tr a-z A-Z)
1310 TEST="$ADDR with socketpair accepts all its options"
1311 echo "### $TEST"
1312 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1313 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g')
1314 OPTS=
1315 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1316 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1317 OPTS="$OPTS,$OPTG";
1318 done
1319 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1320 #echo $OPTS
1321 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1322 echo testing if $ADDR with socketpair accepts option $o
1323 $SOCAT $opts $addr:$TRUE,$o /dev/null,ignoreof </dev/null
1324 done
1326 TEST="$ADDR with pipes accepts all its options"
1327 echo "### $TEST"
1328 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1329 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1330 OPTS=
1331 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1332 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1333 OPTS="$OPTS,$OPTG";
1334 done
1335 # flock tends to hang, so dont test it
1336 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g' -e 's/,flock,/,/g')
1337 #echo $OPTS
1338 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1339 echo testing if $ADDR with pipes accepts option $o
1340 $SOCAT $opts $addr:$TRUE,pipes,$o /dev/null,ignoreof </dev/null
1341 done
1343 TEST="$ADDR with pty accepts all its options"
1344 echo "### $TEST"
1345 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1346 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1347 OPTS=
1348 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1349 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1350 OPTS="$OPTS,$OPTG";
1351 done
1352 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1353 #echo $OPTS
1354 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1355 echo testing if $ADDR with pty accepts option $o
1356 $SOCAT $opts $addr:$TRUE,pty,$o /dev/null,ignoreof </dev/null
1357 done
1359 TEST="$ADDR with nofork accepts all its options"
1360 echo "### $TEST"
1361 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1362 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,PTY,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1363 OPTS=
1364 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1365 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1366 OPTS="$OPTS,$OPTG";
1367 done
1368 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1369 #echo $OPTS
1370 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1371 echo testing if $ADDR with nofork accepts option $o
1372 $SOCAT /dev/null $opts $addr:$TRUE,nofork,$o </dev/null
1373 done
1375 done
1378 #------------------------------------------------------------------------------
1380 #if false; then
1381 if true; then
1382 for addr in fd; do
1383 ADDR=$(echo "$addr" |tr a-z A-Z)
1384 TEST="$ADDR accepts all its options"
1385 echo "### $TEST"
1386 TF=$TD/file$N
1387 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1388 OPTS=
1389 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1390 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1391 OPTS="$OPTS,$OPTG";
1392 done
1393 #echo $OPTS
1394 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1395 echo "testing if $ADDR (to file) accepts option $o"
1396 rm -f $TF
1397 $SOCAT $opts -u /dev/null $addr:3,$o 3>$TF
1398 done
1399 done
1402 #------------------------------------------------------------------------------
1404 # test OPEN address
1406 #! test it on pipe, device, new file
1409 #if false; then
1410 if true; then
1411 for addr in open; do
1412 ADDR=$(echo "$addr" |tr a-z A-Z)
1413 TEST="$ADDR on file accepts all its options"
1414 echo "### $TEST"
1415 TF=$TD/file$N
1416 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1417 OPTS=
1418 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1419 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1420 OPTS="$OPTS,$OPTG";
1421 done
1422 #echo $OPTS
1423 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1424 echo testing if $ADDR on file accepts option $o
1425 touch $TF
1426 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1427 rm -f $TF
1428 done
1429 done
1432 #------------------------------------------------------------------------------
1434 # test GOPEN address on files, sockets, pipes, devices
1437 #if false; then
1438 if true; then
1439 for addr in gopen; do
1440 ADDR=$(echo "$addr" |tr a-z A-Z)
1442 TEST="$ADDR on new file accepts all its options"
1443 echo "### $TEST"
1444 TF=$TD/file$N
1445 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1446 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1447 OPTS=
1448 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1449 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1450 OPTS="$OPTS,$OPTG";
1451 done
1452 #echo $OPTS
1453 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1454 echo testing if $ADDR on new file accepts option $o
1455 rm -f $TF
1456 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1457 rm -f $TF
1458 done
1460 TEST="$ADDR on existing file accepts all its options"
1461 echo "### $TEST"
1462 TF=$TD/file$N
1463 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1464 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1465 OPTS=
1466 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1467 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1468 OPTS="$OPTS,$OPTG";
1469 done
1470 #echo $OPTS
1471 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1472 echo testing if $ADDR on existing file accepts option $o
1473 rm -f $TF; touch $TF
1474 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1475 rm -f $TF
1476 done
1478 TEST="$ADDR on existing pipe accepts all its options"
1479 echo "### $TEST"
1480 TF=$TD/pipe$N
1481 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1482 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1483 OPTS=
1484 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1485 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1486 OPTS="$OPTS,$OPTG";
1487 done
1488 #echo $OPTS
1489 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1490 echo testing if $ADDR on named pipe accepts option $o
1491 rm -f $TF; mkfifo $TF
1492 $SOCAT $opts $addr:$TF,$o,nonblock /dev/null </dev/null
1493 rm -f $TF
1494 done
1496 TEST="$ADDR on existing socket accepts all its options"
1497 echo "### $TEST"
1498 TF=$TD/sock$N
1499 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1500 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1501 OPTS=
1502 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1503 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1504 OPTS="$OPTS,$OPTG";
1505 done
1506 #echo $OPTS
1507 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1508 echo testing if $ADDR on socket accepts option $o
1509 rm -f $TF; $SOCAT - UNIX-L:$TF & pid=$!
1510 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1511 kill $pid 2>/dev/null
1512 rm -f $TF
1513 done
1515 if [ $(id -u) -eq 0 ]; then
1516 TEST="$ADDR on existing device accepts all its options"
1517 echo "### $TEST"
1518 TF=$TD/null
1519 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1520 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1521 OPTS=
1522 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1523 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1524 OPTS="$OPTS,$OPTG";
1525 done
1526 #echo $OPTS
1527 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1528 echo testing if $ADDR on existing device accepts option $o
1529 rm -f $TF; mknod $TF c 1 3
1530 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1531 done
1532 else
1533 TEST="$ADDR on existing device accepts all its options"
1534 echo "### $TEST"
1535 TF=/dev/null
1536 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1537 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1538 OPTS=
1539 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1540 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1541 OPTS="$OPTS,$OPTG";
1542 done
1543 #echo $OPTS
1544 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1545 echo testing if $ADDR on existing device accepts option $o
1546 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1547 done
1550 done
1553 #------------------------------------------------------------------------------
1555 # test named pipe
1558 #if false; then
1559 if true; then
1560 for addr in pipe; do
1561 ADDR=$(echo "$addr" |tr a-z A-Z)
1562 TEST="$ADDR on file accepts all its options"
1563 echo "### $TEST"
1564 TF=$TD/pipe$N
1565 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1566 OPTS=
1567 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1568 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1569 OPTS="$OPTS,$OPTG";
1570 done
1571 #echo $OPTS
1573 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1574 echo testing if named $ADDR accepts option $o
1575 rm -f $TF
1576 # blocks with rdonly, wronly
1577 case "$o" in rdonly|wronly) o="$o,nonblock" ;; esac
1578 $SOCAT $opts $addr:$TF,$o /dev/null </dev/null
1579 rm -f $TF
1580 done
1581 done
1583 #------------------------------------------------------------------------------
1585 # test STDIO
1587 #! test different stream types
1589 #if false; then
1590 if true; then
1591 for addr in stdio; do
1592 ADDR=$(echo "$addr" |tr a-z A-Z)
1593 TEST="$ADDR accepts all its options"
1594 echo "### $TEST"
1595 OPTGROUPS=$($SOCAT -? |fgrep " $addr" |sed 's/.*=//')
1596 OPTS=
1597 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1598 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1599 OPTS="$OPTS,$OPTG";
1600 done
1601 #echo $OPTS
1603 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1604 echo "testing if $ADDR (/dev/null, stdout) accepts option $o"
1605 $SOCAT $opts $addr,$o /dev/null,ignoreof </dev/null
1606 done
1607 done
1610 #------------------------------------------------------------------------------
1612 # test STDIN
1614 #if false; then
1615 if true; then
1616 for addr in stdin; do
1617 ADDR=$(echo "$addr" |tr a-z A-Z)
1618 TEST="$ADDR accepts all its options"
1619 echo "### $TEST"
1620 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1621 OPTS=
1622 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1623 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1624 OPTS="$OPTS,$OPTG";
1625 done
1626 #echo $OPTS
1628 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1629 echo "testing if $ADDR (/dev/null) accepts option $o"
1630 $SOCAT $opts -u $addr,$o /dev/null </dev/null
1631 done
1632 done
1635 #------------------------------------------------------------------------------
1637 # test STDOUT, STDERR
1639 if true; then
1640 #if false; then
1641 for addr in stdout stderr; do
1642 ADDR=$(echo "$addr" |tr a-z A-Z)
1643 TEST="$ADDR accepts all its options"
1644 echo "### $TEST"
1645 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1646 OPTS=
1647 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1648 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1649 OPTS="$OPTS,$OPTG";
1650 done
1651 #echo $OPTS
1652 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1653 echo "testing if $ADDR accepts option $o"
1654 $SOCAT $opts -u /dev/null $addr,$o
1655 done
1656 done
1659 #------------------------------------------------------------------------------
1660 # REQUIRES ROOT
1662 if [ "$withroot" ]; then
1663 for addr in ip4; do
1664 ADDR=$(echo "$addr" |tr a-z A-Z)
1665 TEST="$ADDR accepts all its options"
1666 echo "### $TEST"
1667 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1668 OPTS=
1669 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1670 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1671 OPTS="$OPTS,$OPTG";
1672 done
1673 #echo $OPTS
1674 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1675 echo "testing if $ADDR accepts option $o"
1676 $SOCAT $opts $addr:127.0.0.1:200 /dev/null,ignoreof </dev/null
1677 done
1678 done
1681 #------------------------------------------------------------------------------
1682 # REQUIRES ROOT
1684 if [ "$withroot" ]; then
1685 for addr in ip6; do
1686 ADDR=$(echo "$addr" |tr a-z A-Z)
1687 TEST="$ADDR accepts all its options"
1688 echo "### $TEST"
1689 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1690 OPTS=
1691 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1692 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1693 OPTS="$OPTS,$OPTG";
1694 done
1695 #echo $OPTS
1696 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1697 echo "testing if $ADDR accepts option $o"
1698 $SOCAT $opts $addr:[::1]:200 /dev/null,ignoreof </dev/null
1699 done
1700 done
1703 #==============================================================================
1705 #TEST="stdio accepts all options of GROUP_ANY"
1706 #echo "### $TEST"
1707 #CMD="$SOCAT $opts -,$OPTS_ANY /dev/null"
1708 #$CMD
1709 #if [ $? = 0 ]; then
1710 # echo "... test $N ($TEST) succeeded"
1711 ## echo "CMD=$CMD"
1712 #else
1713 # echo "*** test $N ($TEST) FAILED"
1714 # echo "CMD=$CMD"
1717 #N=$((N+1))
1718 ##------------------------------------------------------------------------------
1720 #TEST="exec accepts all options of GROUP_ANY and GROUP_SOCKET"
1721 #echo "### $TEST"
1722 #CMD="$SOCAT $opts exec:$TRUE,$OPTS_ANY,$OPTS_SOCKET /dev/null"
1723 #$CMD
1724 #if [ $? = 0 ]; then
1725 # echo "... test $N ($TEST) succeeded"
1726 ## echo "CMD=$CMD"
1727 #else
1728 # echo "*** test $N ($TEST) FAILED"
1729 # echo "CMD=$CMD"
1732 #------------------------------------------------------------------------------
1734 esac
1736 #==============================================================================
1739 numOK=0
1740 numFAIL=0
1741 numCANT=0
1742 listFAIL=
1743 listCANT=
1745 #==============================================================================
1746 # test if selected socat features work ("FUNCTIONS")
1748 testecho () {
1749 local N="$1"
1750 local title="$2"
1751 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1752 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1753 local opts="$5"
1754 local T="$6"; [ -z "$T" ] && T=0
1755 local tf="$td/test$N.stdout"
1756 local te="$td/test$N.stderr"
1757 local tdiff="$td/test$N.diff"
1758 local da="test$N $(date) $RANDOM"
1759 if ! eval $NUMCOND; then :; else
1760 #local cmd="$TRACE $SOCAT $opts $arg1 $arg2"
1761 #$ECHO "testing $title (test $N)... \c"
1762 $PRINTF "test $F_n %s... " $N "$title"
1763 #echo "$da" |$cmd >"$tf" 2>"$te"
1764 (psleep $T; echo "$da"; psleep $T) |($TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $? >"$td/test$N.rc") &
1765 export rc1=$!
1766 #sleep 5 && kill $rc1 2>/dev/null &
1767 # rc2=$!
1768 wait $rc1
1769 # kill $rc2 2>/dev/null
1770 if [ "$(cat "$td/test$N.rc")" != 0 ]; then
1771 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1772 echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
1773 cat "$te" >&2
1774 numFAIL=$((numFAIL+1))
1775 listFAIL="$listFAIL $N"
1776 elif echo "$da" |diff - "$tf" >"$tdiff" 2>&1; then
1777 $PRINTF "$OK\n"
1778 if [ "$VERBOSE" ]; then echo "$SOCAT $opts $arg1 $arg2" >&2; fi
1779 if [ -n "$debug" ]; then cat $te >&2; fi
1780 numOK=$((numOK+1))
1781 else
1782 $PRINTF "$FAILED:\n"
1783 echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
1784 cat "$te" >&2
1785 echo diff: >&2
1786 cat "$tdiff" >&2
1787 numFAIL=$((numFAIL+1))
1788 listFAIL="$listFAIL $N"
1790 fi # NUMCOND
1793 # test if call to od and throughput of data works - with graceful shutdown and
1794 # flush of od buffers
1795 testod () {
1796 local num="$1"
1797 local title="$2"
1798 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1799 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1800 local opts="$5"
1801 local T="$6"; [ -z "$T" ] && T=0
1802 local tf="$td/test$N.stdout"
1803 local te="$td/test$N.stderr"
1804 local tr="$td/test$N.ref"
1805 local tdiff="$td/test$N.diff"
1806 local dain="$(date) $RANDOM"
1807 if ! eval $NUMCOND; then :; else
1808 echo "$dain" |$OD_C >"$tr"
1809 # local daout="$(echo "$dain" |$OD_C)"
1810 $PRINTF "test $F_n %s... " $num "$title"
1811 (psleep $T; echo "$dain"; psleep $T) |$TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"
1812 if [ "$?" != 0 ]; then
1813 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1814 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1815 cat "$te"
1816 numFAIL=$((numFAIL+1))
1817 listFAIL="$listFAIL $num"
1818 # elif echo "$daout" |diff - "$tf" >"$tdiff" 2>&1; then
1819 elif diff "$tr" "$tf" >"$tdiff" 2>&1; then
1820 $PRINTF "$OK\n"
1821 if [ -n "$debug" ]; then cat $te; fi
1822 numOK=$((numOK+1))
1823 else
1824 $PRINTF "$FAILED: diff:\n"
1825 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1826 cat "$te"
1827 cat "$tdiff"
1828 numFAIL=$((numFAIL+1))
1829 listFAIL="$listFAIL $num"
1831 fi # NUMCOND
1834 # test if the socat executable has these features compiled in
1835 # print the first missing address type
1836 testfeats () {
1837 local a A;
1838 for a in $@; do
1839 A=$(echo "$a" |tr 'a-z-' 'A-Z_')
1840 if $SOCAT -V |grep "#define WITH_$A 1\$" >/dev/null; then
1841 if [[ "$A" =~ OPENSSL.* ]]; then
1842 gentestcert testsrv
1843 gentestcert testcli
1845 shift
1846 continue
1848 echo "$a"
1849 return 1
1850 done
1851 return 0
1854 # test if the socat executable has these address types compiled in
1855 # print the first missing address type
1856 testaddrs () {
1857 local a A;
1858 for a in $@; do
1859 A=$(echo "$a" |tr 'a-z' 'A-Z')
1860 if ! $SOCAT $A /dev/null 2>&1 |grep -q "E unknown device/address"; then
1861 shift
1862 continue
1864 echo "$a"
1865 return 1
1866 done
1867 return 0
1870 # test if the socat executable has these options compiled in
1871 # print the first missing option
1872 testoptions () {
1873 local a A;
1874 for a in $@; do
1875 A=$(echo "$a" |tr 'a-z' 'A-Z')
1876 if $SOCAT -??? |grep "[^a-z0-9-]$a[^a-z0-9-]" >/dev/null; then
1877 shift
1878 continue
1880 echo "$a"
1881 return 1
1882 done
1883 return 0
1886 # check if the given pid exists and has child processes
1887 # if yes: prints child process lines to stdout, returns 0
1888 # if not: prints ev.message to stderr, returns 1
1889 childprocess () {
1890 local l
1891 case "$UNAME" in
1892 AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;;
1893 FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;;
1894 HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1895 Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1896 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)")" ;;
1897 NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1898 OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)")" ;;
1899 SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1900 DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1901 CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]")" ;;
1902 *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]**[ ][ ]*$(printf %5u $1) ")" ;; esac
1903 if [ -z "$l" ]; then
1904 return 1;
1906 echo "$l"
1907 return 0
1910 # return a list of child process pids
1911 childpids () {
1912 case "$UNAME" in
1913 AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)" |awk '{print($2);}')" ;;
1914 FreeBSD) l="$(ps -fl |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$(printf %5u $1)" |awk '{print($2);}')" ;;
1915 HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1916 Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1917 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)" |awk '{print($2);}')" ;;
1918 NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1919 OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1920 SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1921 DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1922 CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]" |awk '{print($2);}')" ;;
1923 *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$(printf %5u $1) " |awk '{print($2);}')" ;; esac
1924 if [ -z "$l" ]; then
1925 return 1;
1927 echo "$l"
1928 return 0
1931 # check if the given process line refers to a defunct (zombie) process
1932 # yes: returns 0
1933 # no: returns 1
1934 isdefunct () {
1935 local l
1936 case "$UNAME" in
1937 AIX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1938 FreeBSD) l="$(echo "$1" |grep ' <defunct>$')" ;;
1939 HP-UX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1940 Linux) l="$(echo "$1" |grep ' <defunct>$')" ;;
1941 SunOS) l="$(echo "$1" |grep ' <defunct>$')" ;;
1942 DragonFly)l="$(echo "$1" |grep ' <defunct>$')" ;;
1943 *) l="$(echo "$1" |grep ' <defunct>$')" ;;
1944 esac
1945 [ -n "$l" ];
1948 # check if UNIX socket protocol is available on host
1949 runsunix () {
1950 return 0;
1951 $TRACE $SOCAT /dev/null UNIX-LISTEN:"$td/unix.socket" 2>"$td/unix.stderr" &
1952 pid=$!
1953 usleep $MICROS
1954 kill "$pid" 2>/dev/null
1955 test ! -s "$td/unix.stderr"
1958 unset HAVENOT_IP4
1959 # check if an IP4 loopback interface exists
1960 runsip4 () {
1961 [ -n "$HAVENOT_IP4" ] && return $HAVENOT_IP4
1962 local l
1963 case "$UNAME" in
1964 AIX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1965 FreeBSD) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1966 HP-UX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1967 Linux) if [ "$IP" ]; then
1968 l=$($IP address |egrep ' inet 127.0.0.1/')
1969 else
1970 l=$($IFCONFIG |egrep 'inet (addr:)?127\.0\.0\.1 ')
1971 fi ;;
1972 NetBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1973 OpenBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1974 OSF1) l=$($IFCONFIG -a |grep ' inet ') ;;
1975 SunOS) l=$($IFCONFIG -a |grep 'inet ') ;;
1976 Darwin)l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1977 DragonFly)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1978 CYGWIN*) l=$(ipconfig |grep IPv4);;
1979 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1980 esac
1981 [ -z "$l" ] && return 1
1982 # existence of interface might not suffice, check for routeability:
1983 case "$UNAME" in
1984 Darwin) ping -c 1 127.0.0.1 >/dev/null 2>&1; l="$?" ;;
1985 Linux) ping -c 1 127.0.0.1 >/dev/null 2>&1; l="$?" ;;
1986 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1987 esac
1988 HAVENOT_IP4=$l
1989 if [ "$HAVENOT_IP4" -ne 0 ]; then
1990 echo IP4
1992 return $l;
1995 unset HAVENOT_IP6
1996 # check if an IP6 loopback interface exists
1997 runsip6 () {
1998 [ -n "$HAVENOT_IP6" ] && return $HAVENOT_IP6
1999 local l
2000 case "$UNAME" in
2001 AIX) l=$($IFCONFIG lo0 |grep 'inet6 ::1/0') ;;
2002 HP-UX) l=$($IFCONFIG lo0 |grep ' inet6 ') ;;
2003 Linux) if [ "$IP" ]; then
2004 l=$($IP address |egrep 'inet6 ::1/128')
2005 else
2006 l=$($IFCONFIG |egrep 'inet6 (addr: )?::1/?')
2007 fi ;;
2008 NetBSD)l=$($IFCONFIG -a |grep 'inet6 ::1 ');;
2009 OSF1) l=$($IFCONFIG -a |grep ' inet6 ') ;;
2010 SunOS) l=$($IFCONFIG -a |grep 'inet6 ') ;;
2011 Darwin)l=$($IFCONFIG lo0 |grep 'inet6 ::1 ') ;;
2012 CYGWIN*) l=$(ipconfig |grep IPv6);;
2013 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
2014 esac
2015 [ -z "$l" ] && return 1
2016 # existence of interface might not suffice, check for routeability:
2017 case "$UNAME" in
2018 Darwin) $PING6 -c 1 ::1 >/dev/null 2>&1; l="$?" ;;
2019 Linux) $PING6 -c 1 ::1 >/dev/null 2>&1; l="$?" ;;
2020 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
2021 esac
2022 HAVENOT_IP6=$l
2023 if [ "$HAVENOT_IP6" -ne 0 ]; then
2024 echo IP6
2026 return "$HAVENOT_IP6"
2029 # check if TCP on IPv4 is available on host
2030 runstcp4 () {
2031 runsip4 >/dev/null || { echo TCP4; return 1; }
2032 $SOCAT -h |grep '\<tcp4-' >/dev/null || return 1
2033 return 0;
2036 # check if TCP on IPv6 is available on host
2037 runstcp6 () {
2038 runsip6 >/dev/null || { echo TCP6; return 1; }
2039 $SOCAT -h |grep '\<tcp6-' >/dev/null || return 1
2040 return 0;
2043 # check if UDP on IPv4 is available on host
2044 runsudp4 () {
2045 runsip4 >/dev/null || { echo UDP4; return 1; }
2046 $SOCAT -h |grep '\<udp4-' >/dev/null || return 1
2047 return 0;
2050 # check if UDP on IPv6 is available on host
2051 runsudp6 () {
2052 runsip6 >/dev/null || { echo UDP6; return 1; }
2053 $SOCAT -h |grep '\<udp6-' >/dev/null || return 1
2054 return 0;
2057 # check if SCTP on IPv4 is available on host
2058 runssctp4 () {
2059 runsip4 >/dev/null || { echo SCTP4; return 1; }
2060 $SOCAT -h |grep '\<sctp4-' >/dev/null || return 1
2061 return 0;
2064 # check if SCTP on IPv6 is available on host
2065 runssctp6 () {
2066 runsip6 >/dev/null || { echo SCTP6; return 1; }
2067 $SOCAT -h |grep '\<sctp6-' >/dev/null || return 1
2068 return 0;
2071 # wait until an IP4 protocol is ready
2072 waitip4proto () {
2073 local proto="$1"
2074 local logic="$2" # 0..wait until free; 1..wait until listening
2075 local timeout="$3"
2076 local l
2077 [ "$logic" ] || logic=1
2078 [ "$timeout" ] || timeout=5
2079 while [ $timeout -gt 0 ]; do
2080 case "$UNAME" in
2081 Linux) if [ "$SS" ]; then
2082 l=$($SS -n -w -l |grep '^\(raw\|UNCONN\) .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
2083 else
2084 l=$(netstat -n -w -l |grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
2085 fi ;;
2086 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
2087 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2088 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2089 # Darwin) case "$(uname -r)" in
2090 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
2091 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
2092 # esac ;;
2093 AIX) # does not seem to show raw sockets in netstat
2094 sleep 1; return 0 ;;
2095 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
2096 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
2097 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
2098 *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
2099 sleep 1; return 0 ;;
2100 esac
2101 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2102 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2103 sleep 1
2104 timeout=$((timeout-1))
2105 done
2107 $ECHO "!protocol $proto timed out! \c" >&2
2108 return 1
2111 # we need this misleading function name for canonical reasons
2112 waitip4port () {
2113 waitip4proto "$1" "$2" "$3"
2116 # wait until an IP6 protocol is ready
2117 waitip6proto () {
2118 local proto="$1"
2119 local logic="$2" # 0..wait until free; 1..wait until listening
2120 local timeout="$3"
2121 local l
2122 [ "$logic" ] || logic=1
2123 [ "$timeout" ] || timeout=5
2124 while [ $timeout -gt 0 ]; do
2125 case "$UNAME" in
2126 Linux)
2127 if [ "$SS" ]; then
2128 l=$($SS -n -w -l |grep '^\(raw\|UNCONN\) .* \*:'$proto' [ ]*\*:\*')
2129 else
2130 l=$(netstat -n -w -l |grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*')
2131 fi ;;
2132 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
2133 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2134 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2135 # Darwin) case "$(uname -r)" in
2136 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
2137 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
2138 # esac ;;
2139 AIX) # does not seem to show raw sockets in netstat
2140 sleep 1; return 0 ;;
2141 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
2142 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
2143 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
2144 *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;;
2145 sleep 1; return 0 ;;
2146 esac
2147 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2148 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2149 sleep 1
2150 timeout=$((timeout-1))
2151 done
2153 $ECHO "!protocol $proto timed out! \c" >&2
2154 return 1
2157 # we need this misleading function name for canonical reasons
2158 waitip6port () {
2159 waitip6proto "$1" "$2" "$3"
2162 # check if a TCP4 port is in use
2163 # exits with 0 when it is not used
2164 checktcp4port () {
2165 local port="$1"
2166 local l
2167 case "$UNAME" in
2168 Linux) if [ "$SS" ]; then
2169 l=$($SS -4 -l -n -t |grep "^LISTEN .*:$port\>")
2170 else
2171 l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
2172 fi ;;
2173 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2174 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2175 Darwin) case "$(uname -r)" in
2176 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2177 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2178 esac ;;
2179 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2180 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2181 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2182 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2183 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2184 DragonFly)l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2185 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2186 esac
2187 [ -z "$l" ] && return 0
2188 return 1
2191 # wait until a TCP4 listen port is ready
2192 waittcp4port () {
2193 local port="$1"
2194 local logic="$2" # 0..wait until free; 1..wait until listening (default)
2195 local timeout="$3"
2196 local l
2197 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2198 [ "$logic" ] || logic=1
2199 [ "$timeout" ] || timeout=5
2200 while [ $timeout -gt 0 ]; do
2201 case "$UNAME" in
2202 Linux) if [ "$SS" ]; then
2203 l=$($SS -l -n -t |grep "^LISTEN .*:$port\>")
2204 else
2205 l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
2206 fi ;;
2207 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2208 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2209 Darwin) case "$(uname -r)" in
2210 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2211 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2212 esac ;;
2213 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2214 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2215 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2216 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2217 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2218 DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2219 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2220 esac
2221 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2222 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2223 set ${vx}vx
2224 return 0
2226 sleep 1
2227 timeout=$((timeout-1))
2228 done
2230 $ECHO "!port $port timed out! \c" >&2
2231 set ${vx}vx
2232 return 1
2235 # wait until a UDP4 port is ready
2236 waitudp4port () {
2237 local port="$1"
2238 local logic="$2" # 0..wait until free; 1..wait until listening
2239 local timeout="$3"
2240 local l
2241 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2242 [ "$logic" ] || logic=1
2243 [ "$timeout" ] || timeout=5
2244 while [ $timeout -gt 0 ]; do
2245 case "$UNAME" in
2246 Linux) if [ "$SS" ]; then
2247 l=$($SS -4 -l -n -u |grep "^UNCONN .*:$port\>")
2248 else
2249 l=$(netstat -a -n -u -l |grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*')
2250 fi ;;
2251 FreeBSD) l=$(netstat -an |egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;;
2252 NetBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2253 OpenBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2254 Darwin) case "$(uname -r)" in
2255 [1-5]*) l=$(netstat -an |grep '^udp.* .*[0-9*]\.'$port' .* \*\.\*') ;;
2256 *) l=$(netstat -an |grep '^udp4.* .*[0-9*]\.'$port' .* \*\.\* .*') ;;
2257 esac ;;
2258 AIX) l=$(netstat -an |grep '^udp[4 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2259 SunOS) l=$(netstat -an -f inet -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2260 HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
2261 OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2262 DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2263 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2264 esac
2265 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2266 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2267 set ${vx}vx
2268 return 0
2270 sleep 1
2271 timeout=$((timeout-1))
2272 done
2274 $ECHO "!port $port timed out! \c" >&2
2275 set ${vx}vx
2276 return 1
2279 # wait until an SCTP4 listen port is ready
2280 waitsctp4port () {
2281 local port="$1"
2282 local logic="$2" # 0..wait until free; 1..wait until listening
2283 local timeout="$3"
2284 local l
2285 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2286 [ "$logic" ] || logic=1
2287 [ "$timeout" ] || timeout=5
2288 while [ $timeout -gt 0 ]; do
2289 case "$UNAME" in
2290 Linux) if [ "$SS" ]; then
2291 l=$($SS -4 -n -A sctp 2>/dev/null |grep "^LISTEN .*:$port\>")
2292 else
2293 l=$(netstat -n -a |grep '^sctp .* .*[0-9*]:'$port' .* LISTEN')
2294 fi ;;
2295 # FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2296 # NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2297 # Darwin) case "$(uname -r)" in
2298 # [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2299 # *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2300 # esac ;;
2301 # AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2302 SunOS) l=$(netstat -an -f inet -P sctp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2303 # HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2304 # OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2305 # CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2306 *) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
2307 esac
2308 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2309 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2310 set ${vx}vx
2311 return 0
2313 sleep 1
2314 timeout=$((timeout-1))
2315 done
2317 $ECHO "!port $port timed out! \c" >&2
2318 set ${vx}vx
2319 return 1
2322 # wait until a tcp6 listen port is ready
2323 waittcp6port () {
2324 local port="$1"
2325 local logic="$2" # 0..wait until free; 1..wait until listening
2326 local timeout="$3"
2327 local l
2328 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2329 [ "$logic" ] || logic=1
2330 [ "$timeout" ] || timeout=5
2331 while [ $timeout -gt 0 ]; do
2332 case "$UNAME" in
2333 Linux) if [ "$SS" ]; then
2334 l=$($SS -6 -n -t -l |grep "^LISTEN .*:$port\>")
2335 else
2336 l=$(netstat -an |grep -E '^tcp6? .* [0-9a-f:%]*:'$port' .* LISTEN')
2337 fi ;;
2338 FreeBSD) l=$(netstat -an |egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;;
2339 NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2340 OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2341 Darwin) l=$(netstat -an |egrep '^tcp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+ +LISTEN') ;;
2342 AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2343 SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2344 #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2345 DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2346 *) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;;
2347 esac
2348 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2349 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2350 set ${vx}vx
2351 return 0
2353 sleep 1
2354 timeout=$((timeout-1))
2355 done
2357 $ECHO "!port $port timed out! \c" >&2
2358 #echo set ${vx}vx >&2
2359 set ${vx}vx
2360 return 1
2363 # wait until a UDP6 port is ready
2364 waitudp6port () {
2365 local port="$1"
2366 local logic="$2" # 0..wait until free; 1..wait until listening
2367 local timeout="$3"
2368 local l
2369 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2370 [ "$logic" ] || logic=1
2371 [ "$timeout" ] || timeout=5
2372 while [ $timeout -gt 0 ]; do
2373 case "$UNAME" in
2374 Linux) if [ "$SS" ]; then
2375 # CAUTION!!! ss from iproute2 4.15.0-2ubuntu on 18-04 changes
2376 # the output format when writing to pipe
2377 l=$($SS -6 -u -l -n |grep "^UNCONN.*:$port\>")
2378 else
2379 l=$(netstat -an |grep -E '^udp6? .* .*[0-9*:%]:'$port' [ ]*:::\*')
2380 fi ;;
2381 FreeBSD) l=$(netstat -an |egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;;
2382 NetBSD) l=$(netstat -an |grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;;
2383 OpenBSD) l=$(netstat -an |grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2384 Darwin) l=$(netstat -an |egrep '^udp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+') ;;
2385 AIX) l=$(netstat -an |grep '^udp[6 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2386 SunOS) l=$(netstat -an -f inet6 -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2387 #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
2388 #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2389 DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2390 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2391 esac
2392 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2393 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2394 set ${vx}vx
2395 return 0
2397 sleep 1
2398 timeout=$((timeout-1))
2399 done
2401 $ECHO "!port $port timed out! \c" >&2
2402 set ${vx}vx
2403 return 1
2406 # wait until a sctp6 listen port is ready
2407 # not all (Linux) variants show this in netstat
2408 waitsctp6port () {
2409 local port="$1"
2410 local logic="$2" # 0..wait until free; 1..wait until listening
2411 local timeout="$3"
2412 local l
2413 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2414 [ "$logic" ] || logic=1
2415 [ "$timeout" ] || timeout=5
2416 while [ $timeout -gt 0 ]; do
2417 case "$UNAME" in
2418 Linux) if [ "$SS" ]; then
2419 l=$($SS -6 -n -A sctp 2>/dev/null |grep "^LISTEN .*:$port\>")
2420 else
2421 l=$(netstat -an |grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN')
2422 fi ;;
2423 # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
2424 # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2425 # OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2426 # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2427 SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2428 # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2429 *) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
2430 esac
2431 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2432 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2433 set ${vx}vx
2434 return 0
2436 sleep 1
2437 timeout=$((timeout-1))
2438 done
2440 $ECHO "!port $port timed out! \c" >&2
2441 set ${vx}vx
2442 return 1
2445 # we need this misleading function name for canonical reasons
2446 waitunixport () {
2447 waitfile "$1" "$2" "$3"
2450 # wait until a filesystem entry exists
2451 waitfile () {
2452 local crit=-e
2453 case "X$1" in X-*) crit="$1"; shift ;; esac
2454 local file="$1"
2455 local logic="$2" # 0..wait until gone; 1..wait until exists (default);
2456 # 2..wait until not empty
2457 local timeout="$3"
2458 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2459 [ "$logic" ] || logic=1
2460 [ "$logic" -eq 2 ] && crit=-s
2461 [ "$timeout" ] || timeout=5
2462 while [ $timeout -gt 0 ]; do
2463 if [ \( $logic -ne 0 -a $crit "$file" \) -o \
2464 \( $logic -eq 0 -a ! $crit "$file" \) ]; then
2465 set ${vx}vx
2466 return 0
2468 sleep 1
2469 timeout=$((timeout-1))
2470 done
2472 echo "file $file timed out" >&2
2473 set ${vx}vx
2474 return 1
2477 # generate a test certificate and key
2478 gentestcert () {
2479 local name="$1"
2480 if ! [ -f testcert.dh ]; then
2481 openssl dhparam -out testcert.dh $RSABITS
2483 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2484 openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
2485 #openssl req -new -config $TESTCERT_CONF -key $name.key -x509 -out $name.crt -days 3653 -extensions v3_ca >/dev/null 2>&1
2486 openssl req -new -config $TESTCERT_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2487 cat $name.key $name.crt testcert.dh >$name.pem
2490 # generate a test DSA key and certificate
2491 gentestdsacert () {
2492 local name="$1"
2493 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2494 openssl dsaparam -out $name-dsa.pem $DSABITS >/dev/null 2>&1
2495 openssl dhparam -dsaparam -out $name-dh.pem $DSABITS >/dev/null 2>&1
2496 openssl req -newkey dsa:$name-dsa.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
2497 cat $name-dsa.pem $name-dh.pem $name.key $name.crt >$name.pem
2500 # generate a test EC key and certificate
2501 gentesteccert () {
2502 local name="$1"
2503 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2504 openssl ecparam -name secp521r1 -out $name-ec.pem >/dev/null 2>&1
2505 chmod 0400 $name-ec.pem
2506 openssl req -newkey ec:$name-ec.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
2507 cat $name-ec.pem $name.key $name.crt >$name.pem
2510 gentestcert6 () {
2511 local name="$1"
2512 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2513 cat $TESTCERT_CONF |
2514 { echo "# automatically generated by $0"; cat; } |
2515 sed 's/\(commonName\s*=\s*\).*/\1[::1]/' >$TESTCERT6_CONF
2516 openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
2517 openssl req -new -config $TESTCERT6_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2518 cat $name.key $name.crt >$name.pem
2521 # generate a server certificate and key with SubjectAltName
2522 gentestaltcert () {
2523 local name="$1"
2524 if ! [ -f testcert.dh ]; then
2525 openssl dhparam -out testcert.dh $RSABITS
2527 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2528 openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
2529 openssl req -new -config $TESTALT_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2530 cat $name.key $name.crt testcert.dh >$name.pem
2534 NAME=UNISTDIO
2535 case "$TESTS " in
2536 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2537 TEST="$NAME: unidirectional throughput from stdin to stdout"
2538 testecho "$N" "$TEST" "stdin" "stdout" "$opts -u"
2539 esac
2540 N=$((N+1))
2543 NAME=UNPIPESTDIO
2544 case "$TESTS" in
2545 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2546 TEST="$NAME: stdio with simple echo via internal pipe"
2547 testecho "$N" "$TEST" "stdio" "pipe" "$opts"
2548 esac
2549 N=$((N+1))
2552 NAME=UNPIPESHORT
2553 case "$TESTS" in
2554 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2555 TEST="$NAME: short form of stdio ('-') with simple echo via internal pipe"
2556 testecho "$N" "$TEST" "-" "pipe" "$opts"
2557 esac
2558 N=$((N+1))
2561 NAME=DUALSTDIO
2562 case "$TESTS" in
2563 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2564 TEST="$NAME: splitted form of stdio ('stdin!!stdout') with simple echo via internal pipe"
2565 testecho "$N" "$TEST" "stdin!!stdout" "pipe" "$opts"
2566 esac
2567 N=$((N+1))
2570 NAME=DUALSHORTSTDIO
2571 case "$TESTS" in
2572 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2573 TEST="$NAME: short splitted form of stdio ('-!!-') with simple echo via internal pipe"
2574 testecho "$N" "$TEST" "-!!-" "pipe" "$opts"
2575 esac
2576 N=$((N+1))
2579 NAME=DUALFDS
2580 case "$TESTS" in
2581 *%$N%*|*%functions%*|*%fd%*|*%$NAME%*)
2582 TEST="$NAME: file descriptors with simple echo via internal pipe"
2583 testecho "$N" "$TEST" "0!!1" "pipe" "$opts"
2584 esac
2585 N=$((N+1))
2588 NAME=NAMEDPIPE
2589 case "$TESTS" in
2590 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2591 TEST="$NAME: simple echo via named pipe"
2592 # with MacOS, this test hangs if nonblock is not used. Is an OS bug.
2593 tp="$td/pipe$N"
2594 # note: the nonblock is required by MacOS 10.1(?), otherwise it hangs (OS bug?)
2595 testecho "$N" "$TEST" "" "pipe:$tp,nonblock" "$opts"
2596 esac
2597 N=$((N+1))
2600 NAME=DUALPIPE
2601 case "$TESTS" in
2602 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2603 TEST="$NAME: simple echo via named pipe, specified twice"
2604 tp="$td/pipe$N"
2605 testecho "$N" "$TEST" "" "pipe:$tp,nonblock!!pipe:$tp" "$opts"
2606 esac
2607 N=$((N+1))
2610 NAME=FILE
2611 case "$TESTS" in
2612 *%$N%*|*%functions%*|*%engine%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
2613 TEST="$NAME: simple echo via file"
2614 tf="$td/file$N"
2615 testecho "$N" "$TEST" "" "$tf,ignoreeof!!$tf" "$opts"
2616 esac
2617 N=$((N+1))
2620 NAME=EXECSOCKET
2621 case "$TESTS" in
2622 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2623 TEST="$NAME: simple echo via exec of cat with socketpair"
2624 testecho "$N" "$TEST" "" "exec:$CAT" "$opts"
2625 esac
2626 N=$((N+1))
2629 NAME=SYSTEMSOCKET
2630 case "$TESTS" in
2631 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2632 TEST="$NAME: simple echo via system() of cat with socketpair"
2633 testecho "$N" "$TEST" "" "system:$CAT" "$opts" "$val_t"
2634 esac
2635 N=$((N+1))
2638 NAME=EXECPIPES
2639 case "$TESTS" in
2640 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2641 TEST="$NAME: simple echo via exec of cat with pipes"
2642 testecho "$N" "$TEST" "" "exec:$CAT,pipes" "$opts"
2643 esac
2644 N=$((N+1))
2647 NAME=SYSTEMPIPES
2648 case "$TESTS" in
2649 *%$N%*|*%functions%*|*%pipes%*|*%$NAME%*)
2650 TEST="$NAME: simple echo via system() of cat with pipes"
2651 testecho "$N" "$TEST" "" "system:$CAT,pipes" "$opts"
2652 esac
2653 N=$((N+1))
2656 NAME=EXECPTY
2657 case "$TESTS" in
2658 *%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2659 TEST="$NAME: simple echo via exec of cat with pseudo terminal"
2660 if ! eval $NUMCOND; then :;
2661 elif ! testfeats pty >/dev/null; then
2662 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2663 numCANT=$((numCANT+1))
2664 listCANT="$listCANT $N"
2665 else
2666 testecho "$N" "$TEST" "" "exec:$CAT,pty,$PTYOPTS" "$opts"
2668 esac
2669 N=$((N+1))
2672 NAME=SYSTEMPTY
2673 case "$TESTS" in
2674 *%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2675 TEST="$NAME: simple echo via system() of cat with pseudo terminal"
2676 if ! eval $NUMCOND; then :;
2677 elif ! testfeats pty >/dev/null; then
2678 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2679 numCANT=$((numCANT+1))
2680 listCANT="$listCANT $N"
2681 else
2682 testecho "$N" "$TEST" "" "system:$CAT,pty,$PTYOPTS" "$opts"
2684 esac
2685 N=$((N+1))
2688 NAME=SYSTEMPIPESFDS
2689 case "$TESTS" in
2690 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2691 TEST="$NAME: simple echo via system() of cat with pipes, non stdio"
2692 testecho "$N" "$TEST" "" "system:$CAT>&9 <&8,pipes,fdin=8,fdout=9" "$opts"
2693 esac
2694 N=$((N+1))
2697 NAME=DUALSYSTEMFDS
2698 case "$TESTS" in
2699 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2700 TEST="$NAME: echo via dual system() of cat"
2701 testecho "$N" "$TEST" "system:$CAT>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" "$val_t"
2702 esac
2703 N=$((N+1))
2706 # test: send EOF to exec'ed sub process, let it finish its operation, and
2707 # check if the sub process returns its data before terminating.
2708 NAME=EXECSOCKETFLUSH
2709 # idea: have socat exec'ing od; send data and EOF, and check if the od'ed data
2710 # arrives.
2711 case "$TESTS" in
2712 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2713 TEST="$NAME: call to od via exec with socketpair"
2714 testod "$N" "$TEST" "" "exec:$OD_C" "$opts"
2715 esac
2716 N=$((N+1))
2719 NAME=SYSTEMSOCKETFLUSH
2720 case "$TESTS" in
2721 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2722 TEST="$NAME: call to od via system() with socketpair"
2723 testod "$N" "$TEST" "" "system:$OD_C" "$opts" $val_t
2724 esac
2725 N=$((N+1))
2728 NAME=EXECPIPESFLUSH
2729 case "$TESTS" in
2730 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2731 TEST="$NAME: call to od via exec with pipes"
2732 testod "$N" "$TEST" "" "exec:$OD_C,pipes" "$opts"
2733 esac
2734 N=$((N+1))
2737 NAME=SYSTEMPIPESFLUSH
2738 case "$TESTS" in
2739 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2740 TEST="$NAME: call to od via system() with pipes"
2741 testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
2742 esac
2743 N=$((N+1))
2746 ## LATER:
2747 #NAME=EXECPTYFLUSH
2748 #case "$TESTS" in
2749 #*%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2750 #TEST="$NAME: call to od via exec with pseudo terminal"
2751 #if ! testfeats pty >/dev/null; then
2752 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2753 # numCANT=$((numCANT+1))
2754 # listCANT="$listCANT $N"
2755 #else
2756 #testod "$N" "$TEST" "" "exec:$OD_C,pty,$PTYOPTS" "$opts"
2758 #esac
2759 #N=$((N+1))
2762 ## LATER:
2763 #NAME=SYSTEMPTYFLUSH
2764 #case "$TESTS" in
2765 #*%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2766 #TEST="$NAME: call to od via system() with pseudo terminal"
2767 #if ! testfeats pty >/dev/null; then
2768 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2769 # numCANT=$((numCANT+1))
2770 # listCANT="$listCANT $N"
2771 #else
2772 #testod "$N" "$TEST" "" "system:$OD_C,pty,$PTYOPTS" "$opts"
2774 #esac
2775 #N=$((N+1))
2778 NAME=SYSTEMPIPESFDSFLUSH
2779 case "$TESTS" in
2780 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2781 TEST="$NAME: call to od via system() with pipes, non stdio"
2782 testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
2783 esac
2784 N=$((N+1))
2787 NAME=DUALSYSTEMFDSFLUSH
2788 case "$TESTS" in
2789 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2790 TEST="$NAME: call to od via dual system()"
2791 testod "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "pipe" "$opts" "$val_t"
2792 esac
2793 N=$((N+1))
2796 case "$UNAME" in
2797 Linux) IPPROTO=254 ;;
2798 Darwin) IPPROTO=255 ;;
2799 *) IPPROTO=254 ;; # just a guess
2800 esac
2802 NAME=RAWIP4SELF
2803 case "$TESTS" in
2804 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2805 TEST="$NAME: simple echo via self receiving raw IPv4 protocol"
2806 if ! eval $NUMCOND; then :;
2807 elif ! feat=$(testfeats ip4) || ! runsip4 >/dev/null; then
2808 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2809 numCANT=$((numCANT+1))
2810 listCANT="$listCANT $N"
2811 elif ! feat=$(testfeats rawip) >/dev/null; then
2812 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2813 numCANT=$((numCANT+1))
2814 listCANT="$listCANT $N"
2815 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2816 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2817 numCANT=$((numCANT+1))
2818 listCANT="$listCANT $N"
2819 else
2820 testecho "$N" "$TEST" "" "ip4:127.0.0.1:$IPPROTO" "$opts"
2822 esac
2823 N=$((N+1))
2825 NAME=RAWIPX4SELF
2826 case "$TESTS" in
2827 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2828 TEST="$NAME: simple echo via self receiving raw IP protocol, v4 by target"
2829 if ! eval $NUMCOND; then :;
2830 elif ! feat=$(testfeats ip4) || ! runsip4 >/dev/null; then
2831 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2832 numCANT=$((numCANT+1))
2833 listCANT="$listCANT $N"
2834 elif ! feat=$(testfeats rawip) >/dev/null; then
2835 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2836 numCANT=$((numCANT+1))
2837 listCANT="$listCANT $N"
2838 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2839 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2840 numCANT=$((numCANT+1))
2841 listCANT="$listCANT $N"
2842 else
2843 testecho "$N" "$TEST" "" "ip:127.0.0.1:$IPPROTO" "$opts"
2844 fi ;; # NUMCOND, feats
2845 esac
2846 N=$((N+1))
2848 NAME=RAWIP6SELF
2849 case "$TESTS" in
2850 *%$N%*|*%functions%*|*%ip6%*|*%rawip%*|*%root%*|*%$NAME%*)
2851 TEST="$NAME: simple echo via self receiving raw IPv6 protocol"
2852 if ! eval $NUMCOND; then :;
2853 elif ! feat=$(testfeats ip6) || ! runsip6 >/dev/null; then
2854 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2855 numCANT=$((numCANT+1))
2856 listCANT="$listCANT $N"
2857 elif ! feat=$(testfeats rawip) || ! runsip6 >/dev/null; then
2858 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2859 numCANT=$((numCANT+1))
2860 listCANT="$listCANT $N"
2861 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2862 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2863 numCANT=$((numCANT+1))
2864 listCANT="$listCANT $N"
2865 else
2866 testecho "$N" "$TEST" "" "ip6:[::1]:$IPPROTO" "$opts"
2867 fi ;; # NUMCOND, feats
2868 esac
2869 N=$((N+1))
2871 NAME=RAWIPX6SELF
2872 case "$TESTS" in
2873 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%root%*|*%$NAME%*)
2874 TEST="$NAME: simple echo via self receiving raw IP protocol, v6 by target"
2875 if ! eval $NUMCOND; then :;
2876 elif ! feat=$(testfeats ip6) || ! runsip6 >/dev/null; then
2877 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2878 numCANT=$((numCANT+1))
2879 listCANT="$listCANT $N"
2880 elif ! feat=$(testfeats rawip) || ! runsip6 >/dev/null; then
2881 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2882 numCANT=$((numCANT+1))
2883 listCANT="$listCANT $N"
2884 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2885 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2886 numCANT=$((numCANT+1))
2887 listCANT="$listCANT $N"
2888 else
2889 testecho "$N" "$TEST" "" "ip:[::1]:$IPPROTO" "$opts"
2891 esac
2892 N=$((N+1))
2895 NAME=TCPSELF
2896 case "$TESTS" in
2897 *%$N%*|*%functions%*|*%$NAME%*)
2898 TEST="$NAME: echo via self connection of TCP IPv4 socket"
2899 if ! eval $NUMCOND; then :;
2900 elif [ "$UNAME" != Linux ]; then
2901 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2902 numCANT=$((numCANT+1))
2903 listCANT="$listCANT $N"
2904 else
2905 #ts="127.0.0.1:$tsl"
2906 testecho "$N" "$TEST" "" "tcp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR,reuseaddr" "$opts"
2908 esac
2909 PORT=$((PORT+1))
2910 N=$((N+1))
2913 NAME=UDPSELF
2914 if ! eval $NUMCOND; then :; else
2915 case "$TESTS" in
2916 *%$N%*|*%functions%*|*%$NAME%*)
2917 TEST="$NAME: echo via self connection of UDP IPv4 socket"
2918 if [ "$UNAME" != Linux ]; then
2919 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2920 numCANT=$((numCANT+1))
2921 listCANT="$listCANT $N"
2922 else
2923 testecho "$N" "$TEST" "" "udp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR" "$opts"
2925 esac
2926 fi # NUMCOND
2927 PORT=$((PORT+1))
2928 N=$((N+1))
2931 NAME=UDP6SELF
2932 case "$TESTS" in
2933 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%$NAME%*)
2934 TEST="$NAME: echo via self connection of UDP IPv6 socket"
2935 if ! eval $NUMCOND; then :;
2936 elif [ "$UNAME" != Linux ]; then
2937 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
2938 numCANT=$((numCANT+1))
2939 listCANT="$listCANT $N"
2940 elif ! testfeats udp ip6 >/dev/null || ! runsudp6 >/dev/null; then
2941 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
2942 numCANT=$((numCANT+1))
2943 listCANT="$listCANT $N"
2944 else
2945 tf="$td/file$N"
2946 testecho "$N" "$TEST" "" "udp6:[::1]:$PORT,sp=$PORT,bind=[::1]" "$opts"
2948 esac
2949 PORT=$((PORT+1))
2950 N=$((N+1))
2953 NAME=DUALUDPSELF
2954 if ! eval $NUMCOND; then :; else
2955 case "$TESTS" in
2956 *%$N%*|*%functions%*|*%$NAME%*)
2957 TEST="$NAME: echo via two unidirectional UDP IPv4 sockets"
2958 tf="$td/file$N"
2959 p1=$PORT
2960 p2=$((PORT+1))
2961 testecho "$N" "$TEST" "" "udp:127.0.0.1:$p2,sp=$p1!!udp:127.0.0.1:$p1,sp=$p2" "$opts"
2962 esac
2963 fi # NUMCOND
2964 PORT=$((PORT+2))
2965 N=$((N+1))
2968 #function testdual {
2969 # local
2973 NAME=UNIXSTREAM
2974 if ! eval $NUMCOND; then :; else
2975 case "$TESTS" in
2976 *%$N%*|*%functions%*|*%unix%*|*%$NAME%*)
2977 TEST="$NAME: echo via connection to UNIX domain socket"
2978 tf="$td/test$N.stdout"
2979 te="$td/test$N.stderr"
2980 ts="$td/test$N.socket"
2981 tdiff="$td/test$N.diff"
2982 da="test$N $(date) $RANDOM"
2983 CMD1="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
2984 CMD2="$TRACE $SOCAT $opts -!!- UNIX-CONNECT:$ts"
2985 printf "test $F_n $TEST... " $N
2986 $CMD1 </dev/null >$tf 2>"${te}1" &
2987 bg=$! # background process id
2988 waitfile "$ts"
2989 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2990 rc2=$?
2991 if [ "$rc2" -ne 0 ]; then
2992 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2993 echo "$CMD1 &"
2994 echo "$CMD2"
2995 echo "rc=$rc2"
2996 cat "${te}1"
2997 cat "${te}2"
2998 numFAIL=$((numFAIL+1))
2999 listFAIL="$listFAIL $N"
3000 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3001 $PRINTF "$FAILED: diff:\n"
3002 cat "$tdiff"
3003 numFAIL=$((numFAIL+1))
3004 listFAIL="$listFAIL $N"
3005 else
3006 $PRINTF "$OK\n"
3007 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3008 numOK=$((numOK+1))
3010 kill $bg 2>/dev/null
3011 esac
3012 fi # NUMCOND
3013 N=$((N+1))
3016 NAME=TCP4
3017 if ! eval $NUMCOND; then :; else
3018 case "$TESTS" in
3019 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3020 TEST="$NAME: echo via connection to TCP V4 socket"
3021 tf="$td/test$N.stdout"
3022 te="$td/test$N.stderr"
3023 tdiff="$td/test$N.diff"
3024 tsl=$PORT
3025 ts="127.0.0.1:$tsl"
3026 da="test$N $(date) $RANDOM"
3027 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
3028 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3029 printf "test $F_n $TEST... " $N
3030 $CMD1 >"$tf" 2>"${te}1" &
3031 pid1=$!
3032 waittcp4port $tsl 1
3033 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3034 if [ $? -ne 0 ]; then
3035 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3036 echo "$CMD1 &"
3037 cat "${te}1"
3038 echo "$CMD2"
3039 cat "${te}2"
3040 numFAIL=$((numFAIL+1))
3041 listFAIL="$listFAIL $N"
3042 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3043 $PRINTF "$FAILED\n"
3044 cat "$tdiff"
3045 numFAIL=$((numFAIL+1))
3046 listFAIL="$listFAIL $N"
3047 else
3048 $PRINTF "$OK\n"
3049 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3050 numOK=$((numOK+1))
3052 kill $pid1 2>/dev/null
3053 wait ;;
3054 esac
3055 PORT=$((PORT+1))
3056 fi # NUMCOND
3057 N=$((N+1))
3060 #et -xv
3061 NAME=TCP6
3062 case "$TESTS" in
3063 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3064 TEST="$NAME: echo via connection to TCP V6 socket"
3065 if ! eval $NUMCOND; then :;
3066 elif ! testfeats tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
3067 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
3068 numCANT=$((numCANT+1))
3069 listCANT="$listCANT $N"
3070 else
3071 tf="$td/test$N.stdout"
3072 te="$td/test$N.stderr"
3073 tdiff="$td/test$N.diff"
3074 tsl=$PORT
3075 ts="[::1]:$tsl"
3076 da="test$N $(date) $RANDOM"
3077 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
3078 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3079 printf "test $F_n $TEST... " $N
3080 $CMD1 >"$tf" 2>"${te}1" &
3081 pid=$! # background process id
3082 waittcp6port $tsl 1
3083 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3084 if [ $? -ne 0 ]; then
3085 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3086 echo "$CMD1 &"
3087 echo "$CMD2"
3088 cat "$te"
3089 numFAIL=$((numFAIL+1))
3090 listFAIL="$listFAIL $N"
3091 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3092 $PRINTF "$FAILED: diff:\n"
3093 cat "$tdiff"
3094 numFAIL=$((numFAIL+1))
3095 listFAIL="$listFAIL $N"
3096 else
3097 $PRINTF "$OK\n"
3098 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3099 numOK=$((numOK+1))
3101 kill $pid 2>/dev/null
3103 esac
3104 PORT=$((PORT+1))
3105 N=$((N+1))
3106 #set +vx
3109 NAME=TCPX4
3110 case "$TESTS" in
3111 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3112 TEST="$NAME: echo via connection to TCP socket, v4 by target"
3113 if ! eval $NUMCOND; then :;
3114 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3115 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3116 numCANT=$((numCANT+1))
3117 listCANT="$listCANT $N"
3118 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3119 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3120 numCANT=$((numCANT+1))
3121 listCANT="$listCANT $N"
3122 else
3123 tf="$td/test$N.stdout"
3124 te="$td/test$N.stderr"
3125 tdiff="$td/test$N.diff"
3126 tsl=$PORT
3127 ts="127.0.0.1:$tsl"
3128 da="test$N $(date) $RANDOM"
3129 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip4,$REUSEADDR PIPE"
3130 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
3131 printf "test $F_n $TEST... " $N
3132 $CMD1 >"$tf" 2>"${te}1" &
3133 pid=$! # background process id
3134 waittcp4port $tsl 1
3135 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3136 if [ $? -ne 0 ]; then
3137 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3138 echo "$CMD1 &"
3139 echo "$CMD2"
3140 cat "$te"
3141 numFAIL=$((numFAIL+1))
3142 listFAIL="$listFAIL $N"
3143 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3144 $PRINTF "$FAILED: diff:\n"
3145 cat "$tdiff"
3146 numFAIL=$((numFAIL+1))
3147 listFAIL="$listFAIL $N"
3148 else
3149 $PRINTF "$OK\n"
3150 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3151 numOK=$((numOK+1))
3153 kill $pid 2>/dev/null
3155 esac
3156 PORT=$((PORT+1))
3157 N=$((N+1))
3160 NAME=TCPX6
3161 case "$TESTS" in
3162 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3163 TEST="$NAME: echo via connection to TCP socket, v6 by target"
3164 if ! eval $NUMCOND; then :;
3165 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3166 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3167 numCANT=$((numCANT+1))
3168 listCANT="$listCANT $N"
3169 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3170 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3171 numCANT=$((numCANT+1))
3172 listCANT="$listCANT $N"
3173 else
3174 tf="$td/test$N.stdout"
3175 te="$td/test$N.stderr"
3176 tdiff="$td/test$N.diff"
3177 tsl=$PORT
3178 ts="[::1]:$tsl"
3179 da="test$N $(date) $RANDOM"
3180 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip6,$REUSEADDR PIPE"
3181 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
3182 printf "test $F_n $TEST... " $N
3183 $CMD1 >"$tf" 2>"${te}1" &
3184 pid=$! # background process id
3185 waittcp6port $tsl 1
3186 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3187 if [ $? -ne 0 ]; then
3188 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3189 echo "$CMD1 &"
3190 echo "$CMD2"
3191 cat "$te"
3192 numFAIL=$((numFAIL+1))
3193 listFAIL="$listFAIL $N"
3194 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3195 $PRINTF "$FAILED: diff:\n"
3196 cat "$tdiff"
3197 numFAIL=$((numFAIL+1))
3198 listFAIL="$listFAIL $N"
3199 else
3200 $PRINTF "$OK\n"
3201 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3202 numOK=$((numOK+1))
3204 kill $pid 2>/dev/null
3206 esac
3207 PORT=$((PORT+1))
3208 N=$((N+1))
3210 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
3211 # ipv6-v6only=0 shows this behaviour.
3212 NAME=IPV6ONLY0
3213 case "$TESTS" in
3214 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3215 TEST="$NAME: option ipv6-v6only=0 listens on IPv4"
3216 # create a listening TCP6 socket and try to connect to the port using TCP4
3217 if ! eval $NUMCOND; then :;
3218 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3219 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3220 numCANT=$((numCANT+1))
3221 listCANT="$listCANT $N"
3222 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3223 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
3224 numCANT=$((numCANT+1))
3225 listCANT="$listCANT $N"
3226 elif ! feat=$(testoptions ipv6-v6only); then
3227 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3228 numCANT=$((numCANT+1))
3229 listCANT="$listCANT $N"
3230 else
3231 tf="$td/test$N.stdout"
3232 te="$td/test$N.stderr"
3233 tdiff="$td/test$N.diff"
3234 tsl=$PORT
3235 ts="127.0.0.1:$tsl"
3236 da="test$N $(date) $RANDOM"
3237 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$tsl,ipv6-v6only=0,$REUSEADDR PIPE"
3238 CMD2="$TRACE $SOCAT $opts STDIN!!STDOUT TCP4:$ts"
3239 printf "test $F_n $TEST... " $N
3240 $CMD1 >"$tf" 2>"${te}1" &
3241 pid=$! # background process id
3242 waittcp6port $tsl 1
3243 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3244 if [ $? -ne 0 ]; then
3245 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3246 echo "$CMD1 &"
3247 echo "$CMD2"
3248 cat "${te}1" "${te}2"
3249 numFAIL=$((numFAIL+1))
3250 listFAIL="$listFAIL $N"
3251 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3252 $PRINTF "$FAILED: diff:\n"
3253 cat "$tdiff"
3254 numFAIL=$((numFAIL+1))
3255 listFAIL="$listFAIL $N"
3256 else
3257 $PRINTF "$OK\n"
3258 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3259 numOK=$((numOK+1))
3261 kill $pid 2>/dev/null
3263 esac
3264 PORT=$((PORT+1))
3265 N=$((N+1))
3267 #set -vx
3268 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
3269 # ipv6-v6only=1 turns off this behaviour.
3270 NAME=IPV6ONLY1
3271 case "$TESTS" in
3272 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3273 TEST="$NAME: option ipv6-v6only=1 does not listen on IPv4"
3274 if ! eval $NUMCOND; then :;
3275 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3276 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3277 numCANT=$((numCANT+1))
3278 listCANT="$listCANT $N"
3279 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3280 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3281 numCANT=$((numCANT+1))
3282 listCANT="$listCANT $N"
3283 elif ! feat=$(testoptions ipv6-v6only); then
3284 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3285 numCANT=$((numCANT+1))
3286 listCANT="$listCANT $N"
3287 else
3288 tf="$td/test$N.stdout"
3289 te="$td/test$N.stderr"
3290 tdiff="$td/test$N.diff"
3291 tsl=$PORT
3292 ts="127.0.0.1:$tsl"
3293 da="test$N $(date) $RANDOM"
3294 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,$REUSEADDR PIPE"
3295 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3296 printf "test $F_n $TEST... " $N
3297 $CMD1 >"$tf" 2>"${te}1" &
3298 pid=$! # background process id
3299 waittcp6port $tsl 1
3300 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3301 if [ $? -eq 0 ]; then
3302 $PRINTF "$FAILED:\n"
3303 cat "${te}1" "${te}2"
3304 numFAIL=$((numFAIL+1))
3305 listFAIL="$listFAIL $N"
3306 elif echo "$da" |diff - "$tf" >"$tdiff"; then
3307 $PRINTF "$FAILED:\n"
3308 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3309 numFAIL=$((numFAIL+1))
3310 listFAIL="$listFAIL $N"
3311 else
3312 $PRINTF "$OK\n"
3313 numOK=$((numOK+1))
3315 kill $pid; wait
3316 wait
3318 esac
3319 PORT=$((PORT+1))
3320 N=$((N+1))
3321 #set +vx
3323 NAME=ENV_LISTEN_4
3324 case "$TESTS" in
3325 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3326 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv4 preference on listen"
3327 if ! eval $NUMCOND; then :;
3328 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3329 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3330 numCANT=$((numCANT+1))
3331 listCANT="$listCANT $N"
3332 elif ! testfeats ip6 >/dev/null || ! runstcp6 >/dev/null; then
3333 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
3334 numCANT=$((numCANT+1))
3335 listCANT="$listCANT $N"
3336 elif ! feat=$(testoptions ipv6-v6only); then
3337 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3338 numCANT=$((numCANT+1))
3339 listCANT="$listCANT $N"
3340 else
3341 tf="$td/test$N.stdout"
3342 te="$td/test$N.stderr"
3343 tdiff="$td/test$N.diff"
3344 tsl=$PORT
3345 ts="127.0.0.1:$tsl"
3346 da="test$N $(date) $RANDOM"
3347 CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3348 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3349 printf "test $F_n $TEST... " $N
3350 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3351 pid=$! # background process id
3352 waittcp4port $tsl 1
3353 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3354 if [ $? -ne 0 ]; then
3355 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3356 echo "$CMD1 &"
3357 echo "$CMD2"
3358 cat "${te}1" "${te}2"
3359 numFAIL=$((numFAIL+1))
3360 listFAIL="$listFAIL $N"
3361 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3362 $PRINTF "$FAILED: diff:\n"
3363 cat "$tdiff"
3364 numFAIL=$((numFAIL+1))
3365 listFAIL="$listFAIL $N"
3366 else
3367 $PRINTF "$OK\n"
3368 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3369 numOK=$((numOK+1))
3371 kill $pid 2>/dev/null; wait
3373 esac
3374 PORT=$((PORT+1))
3375 N=$((N+1))
3377 NAME=ENV_LISTEN_6
3378 case "$TESTS" in
3379 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3380 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv6 preference on listen"
3381 if ! eval $NUMCOND; then :;
3382 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3383 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3384 numCANT=$((numCANT+1))
3385 listCANT="$listCANT $N"
3386 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3387 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3388 numCANT=$((numCANT+1))
3389 listCANT="$listCANT $N"
3390 else
3391 tf="$td/test$N.stdout"
3392 te="$td/test$N.stderr"
3393 tdiff="$td/test$N.diff"
3394 tsl=$PORT
3395 ts="[::1]:$tsl"
3396 da="test$N $(date) $RANDOM"
3397 CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3398 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3399 printf "test $F_n $TEST... " $N
3400 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3401 pid=$! # background process id
3402 waittcp6port $tsl 1
3403 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3404 if [ $? -ne 0 ]; then
3405 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3406 echo "$CMD1 &"
3407 echo "$CMD2"
3408 cat "${te}1" "${te}2"
3409 numFAIL=$((numFAIL+1))
3410 listFAIL="$listFAIL $N"
3411 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3412 $PRINTF "$FAILED: diff:\n"
3413 cat "$tdiff"
3414 numFAIL=$((numFAIL+1))
3415 listFAIL="$listFAIL $N"
3416 else
3417 $PRINTF "$OK\n"
3418 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3419 numOK=$((numOK+1))
3421 kill $pid 2>/dev/null; wait
3423 esac
3424 PORT=$((PORT+1))
3425 N=$((N+1))
3427 NAME=LISTEN_OPTION_4
3428 case "$TESTS" in
3429 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3430 TEST="$NAME: option -4 for IPv4 preference on listen"
3431 if ! eval $NUMCOND; then :;
3432 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3433 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3434 numCANT=$((numCANT+1))
3435 listCANT="$listCANT $N"
3436 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3437 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3438 numCANT=$((numCANT+1))
3439 listCANT="$listCANT $N"
3440 elif ! feat=$(testoptions ipv6-v6only); then
3441 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3442 numCANT=$((numCANT+1))
3443 listCANT="$listCANT $N"
3444 else
3445 tf="$td/test$N.stdout"
3446 te="$td/test$N.stderr"
3447 tdiff="$td/test$N.diff"
3448 tsl=$PORT
3449 ts="127.0.0.1:$tsl"
3450 da="test$N $(date) $RANDOM"
3451 CMD1="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3452 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3453 printf "test $F_n $TEST... " $N
3454 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3455 pid=$! # background process id
3456 waittcp4port $tsl 1
3457 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3458 if [ $? -ne 0 ]; then
3459 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3460 echo "$CMD1 &"
3461 echo "$CMD2"
3462 cat "${te}1" "${te}2"
3463 numFAIL=$((numFAIL+1))
3464 listFAIL="$listFAIL $N"
3465 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3466 $PRINTF "$FAILED: diff:\n"
3467 cat "$tdiff"
3468 numFAIL=$((numFAIL+1))
3469 listFAIL="$listFAIL $N"
3470 else
3471 $PRINTF "$OK\n"
3472 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3473 numOK=$((numOK+1))
3475 kill $pid 2>/dev/null; wait
3477 esac
3478 PORT=$((PORT+1))
3479 N=$((N+1))
3481 NAME=LISTEN_OPTION_6
3482 case "$TESTS" in
3483 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3484 TEST="$NAME: option -6 for IPv6 preference on listen"
3485 if ! eval $NUMCOND; then :;
3486 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3487 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3488 numCANT=$((numCANT+1))
3489 listCANT="$listCANT $N"
3490 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3491 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3492 numCANT=$((numCANT+1))
3493 listCANT="$listCANT $N"
3494 else
3495 tf="$td/test$N.stdout"
3496 te="$td/test$N.stderr"
3497 tdiff="$td/test$N.diff"
3498 tsl=$PORT
3499 ts="[::1]:$tsl"
3500 da="test$N $(date) $RANDOM"
3501 CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,$REUSEADDR PIPE"
3502 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3503 printf "test $F_n $TEST... " $N
3504 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3505 pid=$! # background process id
3506 waittcp6port $tsl 1
3507 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3508 if [ $? -ne 0 ]; then
3509 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3510 echo "$CMD1 &"
3511 echo "$CMD2"
3512 cat "${te}1" "${te}2"
3513 numFAIL=$((numFAIL+1))
3514 listFAIL="$listFAIL $N"
3515 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3516 $PRINTF "$FAILED: diff:\n"
3517 cat "$tdiff"
3518 numFAIL=$((numFAIL+1))
3519 listFAIL="$listFAIL $N"
3520 else
3521 $PRINTF "$OK\n"
3522 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3523 numOK=$((numOK+1))
3525 kill $pid 2>/dev/null; wait
3526 wait
3527 fi # feats
3528 esac
3529 PORT=$((PORT+1))
3530 N=$((N+1))
3532 NAME=LISTEN_PF_IP4
3533 case "$TESTS" in
3534 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3535 TEST="$NAME: pf=4 overrides option -6 on listen"
3536 if ! eval $NUMCOND; then :;
3537 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3538 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3539 numCANT=$((numCANT+1))
3540 listCANT="$listCANT $N"
3541 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3542 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3543 numCANT=$((numCANT+1))
3544 listCANT="$listCANT $N"
3545 elif ! feat=$(testoptions ipv6-v6only); then
3546 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3547 numCANT=$((numCANT+1))
3548 listCANT="$listCANT $N"
3549 else
3550 tf="$td/test$N.stdout"
3551 te="$td/test$N.stderr"
3552 tdiff="$td/test$N.diff"
3553 tsl=$PORT
3554 ts="127.0.0.1:$tsl"
3555 da="test$N $(date) $RANDOM"
3556 CMD1="$TRACE $SOCAT $opts -6 TCP-LISTEN:$tsl,pf=ip4,$REUSEADDR PIPE"
3557 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3558 printf "test $F_n $TEST... " $N
3559 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3560 pid=$! # background process id
3561 waittcp4port $tsl 1
3562 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3563 if [ $? -ne 0 ]; then
3564 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3565 echo "$CMD1 &"
3566 echo "$CMD2"
3567 cat "${te}1" "${te}2"
3568 numFAIL=$((numFAIL+1))
3569 listFAIL="$listFAIL $N"
3570 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3571 $PRINTF "$FAILED: diff:\n"
3572 cat "$tdiff"
3573 numFAIL=$((numFAIL+1))
3574 listFAIL="$listFAIL $N"
3575 else
3576 $PRINTF "$OK\n"
3577 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3578 numOK=$((numOK+1))
3580 kill $pid 2>/dev/null; wait
3582 esac
3583 PORT=$((PORT+1))
3584 N=$((N+1))
3586 NAME=LISTEN_PF_IP6
3587 case "$TESTS" in
3588 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3589 TEST="$NAME: pf=6 overrides option -4 on listen"
3590 if ! eval $NUMCOND; then :;
3591 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3592 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3593 numCANT=$((numCANT+1))
3594 listCANT="$listCANT $N"
3595 elif ! testfeats ip6 >/dev/null || ! runsip6 >/dev/null; then
3596 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3597 numCANT=$((numCANT+1))
3598 listCANT="$listCANT $N"
3599 else
3600 tf="$td/test$N.stdout"
3601 te="$td/test$N.stderr"
3602 tdiff="$td/test$N.diff"
3603 tsl=$PORT
3604 ts="[::1]:$tsl"
3605 da="test$N $(date) $RANDOM"
3606 CMD1="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,pf=ip6,$REUSEADDR PIPE"
3607 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3608 printf "test $F_n $TEST... " $N
3609 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3610 pid=$! # background process id
3611 waittcp6port $tsl 1
3612 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3613 if [ $? -ne 0 ]; then
3614 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3615 echo "$CMD1 &"
3616 echo "$CMD2"
3617 cat "${te}1" "${te}2"
3618 numFAIL=$((numFAIL+1))
3619 listFAIL="$listFAIL $N"
3620 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3621 $PRINTF "$FAILED: diff:\n"
3622 cat "$tdiff"
3623 numFAIL=$((numFAIL+1))
3624 listFAIL="$listFAIL $N"
3625 else
3626 $PRINTF "$OK\n"
3627 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3628 numOK=$((numOK+1))
3630 kill $pid 2>/dev/null; wait
3631 fi ;; # NUMCOND, feats
3632 esac
3633 PORT=$((PORT+1))
3634 N=$((N+1))
3637 NAME=UDP4STREAM
3638 case "$TESTS" in
3639 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3640 TEST="$NAME: echo via connection to UDP V4 socket"
3641 if ! eval $NUMCOND; then :; else
3642 tf="$td/test$N.stdout"
3643 te="$td/test$N.stderr"
3644 tdiff="$td/test$N.diff"
3645 tsl=$PORT
3646 ts="$LOCALHOST:$tsl"
3647 da="test$N $(date) $RANDOM"
3648 CMD1="$TRACE $SOCAT $opts UDP4-LISTEN:$tsl,$REUSEADDR PIPE"
3649 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
3650 printf "test $F_n $TEST... " $N
3651 $CMD1 >"$tf" 2>"${te}1" &
3652 pid1=$!
3653 waitudp4port $tsl 1
3654 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3655 rc2=$?
3656 kill $pid1 2>/dev/null; wait
3657 if [ $rc2 -ne 0 ]; then
3658 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3659 echo "$CMD1 &"
3660 echo "$CMD2"
3661 cat "${te}1" "${te}2"
3662 numFAIL=$((numFAIL+1))
3663 listFAIL="$listFAIL $N"
3664 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3665 $PRINTF "$FAILED\n"
3666 echo "$CMD1 &"
3667 cat "${te}1"
3668 echo "$CMD2"
3669 cat "${te}2"
3670 cat "$tdiff"
3671 numFAIL=$((numFAIL+1))
3672 listFAIL="$listFAIL $N"
3673 else
3674 $PRINTF "$OK\n"
3675 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3676 numOK=$((numOK+1))
3678 fi ;; # NUMCOND
3679 esac
3680 PORT=$((PORT+1))
3681 N=$((N+1))
3684 NAME=UDP6STREAM
3685 case "$TESTS" in
3686 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3687 TEST="$NAME: echo via connection to UDP V6 socket"
3688 if ! eval $NUMCOND; then :;
3689 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
3690 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
3691 numCANT=$((numCANT+1))
3692 listCANT="$listCANT $N"
3693 else
3694 tf="$td/test$N.stdout"
3695 te="$td/test$N.stderr"
3696 tdiff="$td/test$N.diff"
3697 tsl=$PORT
3698 ts="$LOCALHOST6:$tsl"
3699 da="test$N $(date) $RANDOM"
3700 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR PIPE"
3701 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
3702 printf "test $F_n $TEST... " $N
3703 $CMD1 >"$tf" 2>"${te}1" &
3704 pid1=$!
3705 waitudp6port $tsl 1
3706 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3707 rc2=$?
3708 kill $pid1 2>/dev/null; wait
3709 if [ $rc2 -ne 0 ]; then
3710 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3711 echo "$CMD1 &"
3712 echo "$CMD2"
3713 cat "${te}1" "${te}2"
3714 numFAIL=$((numFAIL+1))
3715 listFAIL="$listFAIL $N"
3716 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3717 $PRINTF "$FAILED\n"
3718 cat "$tdiff"
3719 numFAIL=$((numFAIL+1))
3720 listFAIL="$listFAIL $N"
3721 else
3722 $PRINTF "$OK\n"
3723 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3724 numOK=$((numOK+1))
3726 fi ;; # ! testfeats
3727 esac
3728 PORT=$((PORT+1))
3729 N=$((N+1))
3732 NAME=GOPENFILE
3733 case "$TESTS" in
3734 *%$N%*|*%functions%*|*%engine%*|*%gopen%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
3735 TEST="$NAME: file opening with gopen"
3736 if ! eval $NUMCOND; then :; else
3737 tf1="$td/test$N.1.stdout"
3738 tf2="$td/test$N.2.stdout"
3739 te="$td/test$N.stderr"
3740 tdiff="$td/test$N.diff"
3741 da="test$N $(date) $RANDOM"
3742 echo "$da" >$tf1
3743 CMD="$TRACE $SOCAT $opts $tf1!!/dev/null /dev/null,ignoreeof!!-"
3744 printf "test $F_n $TEST... " $N
3745 $CMD >"$tf2" 2>"$te"
3746 if [ $? -ne 0 ]; then
3747 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3748 echo "$CMD"
3749 cat "$te"
3750 numFAIL=$((numFAIL+1))
3751 listFAIL="$listFAIL $N"
3752 elif ! diff "$tf1" "$tf2" >"$tdiff"; then
3753 $PRINTF "$FAILED: diff:\n"
3754 cat "$tdiff"
3755 numFAIL=$((numFAIL+1))
3756 listFAIL="$listFAIL $N"
3757 else
3758 $PRINTF "$OK\n"
3759 if [ -n "$debug" ]; then cat $te; fi
3760 numOK=$((numOK+1))
3762 fi # NUMCOND
3763 esac
3764 N=$((N+1))
3767 NAME=GOPENPIPE
3768 case "$TESTS" in
3769 *%$N%*|*%functions%*|*%gopen%*|*%pipe%*|*%ignoreeof%*|*%$NAME%*)
3770 TEST="$NAME: pipe opening with gopen for reading"
3771 if ! eval $NUMCOND; then :; else
3772 tp="$td/pipe$N"
3773 tf="$td/test$N.stdout"
3774 te="$td/test$N.stderr"
3775 tdiff="$td/test$N.diff"
3776 da="test$N $(date) $RANDOM"
3777 CMD="$TRACE $SOCAT $opts $tp!!/dev/null /dev/null,ignoreeof!!$tf"
3778 printf "test $F_n $TEST... " $N
3779 #mknod $tp p # no mknod p on FreeBSD
3780 mkfifo $tp
3781 $CMD >$tf 2>"$te" &
3782 #($CMD >$tf 2>"$te" || rm -f "$tp") 2>/dev/null &
3783 bg=$! # background process id
3784 usleep $MICROS
3785 if [ ! -p "$tp" ]; then
3786 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3787 echo "$CMD"
3788 cat "$te"
3789 numFAIL=$((numFAIL+1))
3790 listFAIL="$listFAIL $N"
3791 else
3792 #echo "$da" >"$tp" # might hang forever
3793 echo "$da" >"$tp" & export pid=$!; (sleep 1; kill $pid 2>/dev/null) &
3794 # Solaris needs more time:
3795 sleep 1
3796 kill "$bg" 2>/dev/null; wait
3797 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3798 if [ -s "$te" ]; then
3799 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3800 echo "$CMD"
3801 cat "$te"
3802 else
3803 $PRINTF "$FAILED: diff:\n"
3804 cat "$tdiff"
3806 numFAIL=$((numFAIL+1))
3807 listFAIL="$listFAIL $N"
3808 else
3809 $PRINTF "$OK\n"
3810 if [ -n "$debug" ]; then cat $te; fi
3811 numOK=$((numOK+1))
3814 wait
3815 fi # NUMCOND
3816 esac
3817 N=$((N+1))
3820 NAME=GOPENUNIXSTREAM
3821 case "$TESTS" in
3822 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%listen%*|*%$NAME%*)
3823 TEST="$NAME: GOPEN on UNIX stream socket"
3824 if ! eval $NUMCOND; then :; else
3825 ts="$td/test$N.socket"
3826 tf="$td/test$N.stdout"
3827 te="$td/test$N.stderr"
3828 tdiff="$td/test$N.diff"
3829 da1="test$N $(date) $RANDOM"
3830 #establish a listening unix socket in background
3831 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
3832 #make a connection
3833 CMD="$TRACE $SOCAT $opts - $ts"
3834 $PRINTF "test $F_n $TEST... " $N
3835 eval "$SRV 2>${te}s &"
3836 pids=$!
3837 waitfile "$ts"
3838 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
3839 if [ $? -ne 0 ]; then
3840 kill "$pids" 2>/dev/null
3841 $PRINTF "$FAILED:\n"
3842 echo "$SRV &"
3843 cat "${te}s"
3844 echo "$CMD"
3845 cat "${te}1"
3846 numFAIL=$((numFAIL+1))
3847 listFAIL="$listFAIL $N"
3848 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
3849 kill "$pids" 2>/dev/null
3850 $PRINTF "$FAILED:\n"
3851 echo "$SRV &"
3852 cat "${te}s"
3853 echo "$CMD"
3854 cat "${te}1"
3855 cat "$tdiff"
3856 numFAIL=$((numFAIL+1))
3857 listFAIL="$listFAIL $N"
3858 else
3859 $PRINTF "$OK\n"
3860 if [ -n "$debug" ]; then cat $te; fi
3861 numOK=$((numOK+1))
3862 fi # !(rc -ne 0)
3863 wait
3864 fi # NUMCOND
3865 esac
3866 N=$((N+1))
3868 NAME=GOPENUNIXSEQPACKET
3869 case "$TESTS" in
3870 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%listen%*|*%seqpacket%*|*%$NAME%*)
3871 TEST="$NAME: GOPEN on UNIX seqpacket socket"
3872 if ! eval $NUMCOND; then :; else
3873 case "$UNAME" in
3874 SunOS) SOCK_SEQPACKET=6 ;;
3875 *) SOCK_SEQPACKET=5 ;;
3876 esac
3877 ts="$td/test$N.socket"
3878 tf="$td/test$N.stdout"
3879 te="$td/test$N.stderr"
3880 tdiff="$td/test$N.diff"
3881 da1="test$N $(date) $RANDOM"
3882 #establish a listening unix socket in background
3883 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\",so-type=$SOCK_SEQPACKET PIPE"
3884 #make a connection
3885 CMD="$TRACE $SOCAT $opts - $ts"
3886 $PRINTF "test $F_n $TEST... " $N
3887 eval "$SRV 2>${te}s &"
3888 pids=$!
3889 waitfile "$ts"
3890 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
3891 if [ $? -ne 0 ]; then
3892 kill "$pids" 2>/dev/null
3893 $PRINTF "$FAILED:\n"
3894 echo "$SRV &"
3895 cat "${te}s"
3896 echo "$CMD"
3897 cat "${te}1"
3898 numFAIL=$((numFAIL+1))
3899 listFAIL="$listFAIL $N"
3900 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
3901 kill "$pids" 2>/dev/null
3902 $PRINTF "$FAILED:\n"
3903 echo "$SRV &"
3904 cat "${te}s"
3905 echo "$CMD"
3906 cat "${te}1"
3907 cat "$tdiff"
3908 numFAIL=$((numFAIL+1))
3909 listFAIL="$listFAIL $N"
3910 else
3911 $PRINTF "$OK\n"
3912 if [ -n "$debug" ]; then cat $te; fi
3913 numOK=$((numOK+1))
3914 fi # !(rc -ne 0)
3915 wait
3916 fi # NUMCOND
3917 esac
3918 N=$((N+1))
3921 NAME=GOPENUNIXDGRAM
3922 case "$TESTS" in
3923 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%dgram%*|*%$NAME%*)
3924 TEST="$NAME: GOPEN on UNIX datagram socket"
3925 if ! eval $NUMCOND; then :; else
3926 ts="$td/test$N.socket"
3927 tf="$td/test$N.stdout"
3928 te="$td/test$N.stderr"
3929 tdiff="$td/test$N.diff"
3930 da1="test$N $(date) $RANDOM"
3931 #establish a receiving unix socket in background
3932 SRV="$TRACE $SOCAT $opts -u -lpserver UNIX-RECV:\"$ts\" file:\"$tf\",create"
3933 #make a connection
3934 CMD="$TRACE $SOCAT $opts -u - $ts"
3935 $PRINTF "test $F_n $TEST... " $N
3936 eval "$SRV 2>${te}s &"
3937 pids=$!
3938 waitfile "$ts"
3939 echo "$da1" |eval "$CMD" 2>"${te}1"
3940 waitfile -s "$tf"
3941 if [ $? -ne 0 ]; then
3942 $PRINTF "$FAILED:\n"
3943 echo "$SRV &"
3944 cat "${te}s"
3945 echo "$CMD"
3946 cat "${te}1"
3947 numFAIL=$((numFAIL+1))
3948 listFAIL="$listFAIL $N"
3949 elif ! echo "$da1" |diff - "${tf}" >"$tdiff"; then
3950 $PRINTF "$FAILED:\n"
3951 echo "$SRV &"
3952 cat "${te}s"
3953 echo "$CMD"
3954 cat "${te}1"
3955 cat "$tdiff"
3956 numFAIL=$((numFAIL+1))
3957 listFAIL="$listFAIL $N"
3958 else
3959 $PRINTF "$OK\n"
3960 if [ -n "$debug" ]; then cat $te; fi
3961 numOK=$((numOK+1))
3962 fi # !(rc -ne 0)
3963 kill "$pids" 2>/dev/null; wait
3964 fi ;; # NUMCOND
3965 esac
3966 N=$((N+1))
3969 NAME=IGNOREEOF
3970 case "$TESTS" in
3971 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3972 TEST="$NAME: ignoreeof on file"
3973 if ! eval $NUMCOND; then :; else
3974 ti="$td/test$N.file"
3975 tf="$td/test$N.stdout"
3976 te="$td/test$N.stderr"
3977 tdiff="$td/test$N.diff"
3978 da="test$N $(date) $RANDOM"
3979 CMD="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
3980 printf "test $F_n $TEST... " $N
3981 touch "$ti"
3982 $CMD >"$tf" 2>"$te" &
3983 bg=$!
3984 usleep 500000
3985 echo "$da" >>"$ti"
3986 sleep 1
3987 kill $bg 2>/dev/null; wait
3988 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3989 $PRINTF "$FAILED: diff:\n"
3990 cat "$tdiff"
3991 listFAIL="$listFAIL $N"
3992 numFAIL=$((numFAIL+1))
3993 else
3994 $PRINTF "$OK\n"
3995 if [ -n "$debug" ]; then cat $te; fi
3996 numOK=$((numOK+1))
3998 fi ;; # NUMCOND
3999 esac
4000 N=$((N+1))
4002 NAME=IGNOREEOF_REV
4003 case "$TESTS" in
4004 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
4005 TEST="$NAME: ignoreeof on file right-to-left"
4006 if ! eval $NUMCOND; then :; else
4007 ti="$td/test$N.file"
4008 tf="$td/test$N.stdout"
4009 te="$td/test$N.stderr"
4010 tdiff="$td/test$N.diff"
4011 da="test$N $(date) $RANDOM"
4012 CMD="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
4013 printf "test $F_n $TEST... " $N
4014 touch "$ti"
4015 $CMD >"$tf" 2>"$te" &
4016 bg=$!
4017 usleep 500000
4018 echo "$da" >>"$ti"
4019 sleep 1
4020 kill $bg 2>/dev/null
4021 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4022 $PRINTF "$FAILED: diff:\n"
4023 cat "$tdiff"
4024 listFAIL="$listFAIL $N"
4025 numFAIL=$((numFAIL+1))
4026 else
4027 $PRINTF "$OK\n"
4028 if [ -n "$debug" ]; then cat $te; fi
4029 numOK=$((numOK+1))
4031 wait
4032 fi ;; # NUMCOND
4033 esac
4034 N=$((N+1))
4037 NAME=EXECIGNOREEOF
4038 case "$TESTS" in
4039 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
4040 TEST="$NAME: exec against address with ignoreeof"
4041 if ! eval $NUMCOND; then :; else
4042 tf="$td/test$N.stdout"
4043 te="$td/test$N.stderr"
4044 CMD="$TRACE $SOCAT $opts -lf /dev/null EXEC:$TRUE /dev/null,ignoreeof"
4045 printf "test $F_n $TEST... " $N
4046 $CMD >"$tf" 2>"$te"
4047 if [ -s "$te" ]; then
4048 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4049 echo "$CMD"
4050 cat "$te"
4051 numFAIL=$((numFAIL+1))
4052 listFAIL="$listFAIL $N"
4053 else
4054 $PRINTF "$OK\n"
4055 if [ -n "$debug" ]; then cat $te; fi
4056 numOK=$((numOK+1))
4058 fi ;; # NUMCOND
4059 esac
4060 N=$((N+1))
4063 NAME=FAKEPTY
4064 case "$TESTS" in
4065 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
4066 TEST="$NAME: generation of pty for other processes"
4067 if ! eval $NUMCOND; then :;
4068 elif ! testfeats pty >/dev/null; then
4069 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
4070 numCANT=$((numCANT+1))
4071 listCANT="$listCANT $N"
4072 else
4073 tt="$td/pty$N"
4074 tf="$td/test$N.stdout"
4075 te="$td/test$N.stderr"
4076 tdiff="$td/test$N.diff"
4077 da="test$N $(date) $RANDOM"
4078 CMD1="$TRACE $SOCAT $opts pty,link=$tt pipe"
4079 CMD2="$TRACE $SOCAT $opts - $tt,$PTYOPTS2"
4080 printf "test $F_n $TEST... " $N
4081 $CMD1 2>"${te}1" &
4082 pid=$! # background process id
4083 waitfile "$tt"
4084 # this hangs on HP-UX, so we use a timeout
4085 (echo "$da"; sleep 1) |$CMD2 >$tf 2>"${te}2" &
4086 rc2=$!
4087 #sleep 5 && kill $rc2 2>/dev/null &
4088 wait $rc2
4089 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4090 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4091 echo "$CMD1 &"
4092 sleep 1
4093 echo "$CMD2"
4094 cat "${te}1"
4095 cat "${te}2"
4096 cat "$tdiff"
4097 numFAIL=$((numFAIL+1))
4098 listFAIL="$listFAIL $N"
4099 else
4100 $PRINTF "$OK\n"
4101 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4102 numOK=$((numOK+1))
4104 kill $pid 2>/dev/null; wait
4105 fi ;; # NUMCOND, feats
4106 esac
4107 N=$((N+1))
4110 NAME=O_TRUNC
4111 case "$TESTS" in
4112 *%$N%*|*%functions%*|*%$NAME%*)
4113 TEST="$NAME: option o-trunc"
4114 if ! eval $NUMCOND; then :; else
4115 ff="$td/test$N.file"
4116 tf="$td/test$N.stdout"
4117 te="$td/test$N.stderr"
4118 tdiff="$td/test$N.diff"
4119 da="test$N $(date) $RANDOM"
4120 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,o-trunc"
4121 printf "test $F_n $TEST... " $N
4122 rm -f $ff; $ECHO "prefix-\c" >$ff
4123 echo "$da" |$CMD >$tf 2>"$te"
4124 rc0=$?
4125 if ! [ $rc0 = 0 ] ||
4126 ! echo "$da" |diff - $ff >"$tdiff"; then
4127 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4128 echo "$CMD"
4129 cat "$te"
4130 cat "$tdiff"
4131 numFAIL=$((numFAIL+1))
4132 listFAIL="$listFAIL $N"
4133 else
4134 $PRINTF "$OK\n"
4135 if [ -n "$debug" ]; then cat $te; fi
4136 numOK=$((numOK+1))
4138 fi ;; # NUMCOND
4139 esac
4140 N=$((N+1))
4143 NAME=FTRUNCATE
4144 case "$TESTS" in
4145 *%$N%*|*%functions%*|*%$NAME%*)
4146 TEST="$NAME: option ftruncate"
4147 if ! eval $NUMCOND; then :; else
4148 ff="$td/test$N.file"
4149 tf="$td/test$N.stdout"
4150 te="$td/test$N.stderr"
4151 tdiff="$td/test$N.diff"
4152 da="test$N $(date) $RANDOM"
4153 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,ftruncate=0"
4154 printf "test $F_n $TEST... " $N
4155 rm -f $ff; $ECHO "prefix-\c" >$ff
4156 if ! echo "$da" |$CMD >$tf 2>"$te" ||
4157 ! echo "$da" |diff - $ff >"$tdiff"; then
4158 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4159 echo "$CMD"
4160 cat "$te"
4161 cat "$tdiff"
4162 numFAIL=$((numFAIL+1))
4163 listFAIL="$listFAIL $N"
4164 else
4165 $PRINTF "$OK\n"
4166 if [ -n "$debug" ]; then cat $te; fi
4167 numOK=$((numOK+1))
4169 fi ;; # NUMCOND
4170 esac
4171 N=$((N+1))
4174 NAME=RIGHTTOLEFT
4175 case "$TESTS" in
4176 *%$N%*|*%functions%*|*%$NAME%*)
4177 TEST="$NAME: unidirectional throughput from stdin to stdout, right to left"
4178 testecho "$N" "$TEST" "stdout" "stdin" "$opts -U"
4179 esac
4180 N=$((N+1))
4183 NAME=CHILDDEFAULT
4184 case "$TESTS" in
4185 *%$N%*|*%functions%*|*%$NAME%*)
4186 if ! eval $NUMCOND; then :; else
4187 TEST="$NAME: child process default properties"
4188 tf="$td/test$N.stdout"
4189 te="$td/test$N.stderr"
4190 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN -"
4191 printf "test $F_n $TEST... " $N
4192 $CMD >$tf 2>$te
4193 MYPID=`expr "\`grep "process id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
4194 MYPPID=`expr "\`grep "process parent id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
4195 MYPGID=`expr "\`grep "process group id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
4196 MYSID=`expr "\`grep "process session id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
4197 #echo "PID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
4198 if [ "$MYPID" = "$MYPPID" -o "$MYPID" = "$MYPGID" -o "$MYPID" = "$MYSID" -o \
4199 "$MYPPID" = "$MYPGID" -o "$MYPPID" = "$MYSID" -o "$MYPGID" = "$MYSID" ];
4200 then
4201 $PRINTF "$FAILED:\n"
4202 echo "$CMD"
4203 cat "$te"
4204 numFAIL=$((numFAIL+1))
4205 listFAIL="$listFAIL $N"
4206 else
4207 $PRINTF "$OK\n"
4208 numOK=$((numOK+1))
4210 fi ;; # NUMCOND
4211 esac
4212 N=$((N+1))
4215 NAME=CHILDSETSID
4216 case "$TESTS" in
4217 *%$N%*|*%functions%*|*%$NAME%*)
4218 TEST="$NAME: child process with setsid"
4219 if ! eval $NUMCOND; then :; else
4220 tf="$td/test$N.stdout"
4221 te="$td/test$N.stderr"
4222 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN,setsid -"
4223 printf "test $F_n $TEST... " $N
4224 $CMD >$tf 2>$te
4225 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4226 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4227 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4228 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4229 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
4230 # PID, PGID, and SID must be the same
4231 if [ "$MYPID" = "$MYPPID" -o \
4232 "$MYPID" != "$MYPGID" -o "$MYPID" != "$MYSID" ];
4233 then
4234 $PRINTF "$FAILED\n"
4235 echo "$CMD"
4236 cat "$te"
4237 numFAIL=$((numFAIL+1))
4238 listFAIL="$listFAIL $N"
4239 else
4240 $PRINTF "$OK\n"
4241 numOK=$((numOK+1))
4243 fi ;; # NUMCOND
4244 esac
4245 N=$((N+1))
4248 NAME=MAINSETSID
4249 case "$TESTS" in
4250 *%$N%*|*%functions%*|*%$NAME%*)
4251 TEST="$NAME: main process with setsid"
4252 if ! eval $NUMCOND; then :; else
4253 tf="$td/test$N.stdout"
4254 te="$td/test$N.stderr"
4255 CMD="$TRACE $SOCAT $opts -U -,setsid exec:$PROCAN"
4256 printf "test $F_n $TEST... " $N
4257 $CMD >$tf 2>$te
4258 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4259 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4260 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4261 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4262 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
4263 # PPID, PGID, and SID must be the same
4264 if [ "$MYPID" = "$MYPPID" -o \
4265 "$MYPPID" != "$MYPGID" -o "$MYPPID" != "$MYSID" ];
4266 then
4267 $PRINTF "$FAILED\n"
4268 echo "$CMD"
4269 cat "$te"
4270 numFAIL=$((numFAIL+1))
4271 listFAIL="$listFAIL $N"
4272 else
4273 $PRINTF "$OK\n"
4274 numOK=$((numOK+1))
4276 fi ;; # NUMCOND
4277 esac
4278 N=$((N+1))
4281 NAME=OPENSSL_TCP4
4282 case "$TESTS" in
4283 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4284 TEST="$NAME: openssl connect"
4285 if ! eval $NUMCOND; then :;
4286 elif ! testfeats openssl >/dev/null; then
4287 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4288 numCANT=$((numCANT+1))
4289 listCANT="$listCANT $N"
4290 elif ! type openssl >/dev/null 2>&1; then
4291 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
4292 numCANT=$((numCANT+1))
4293 listCANT="$listCANT $N"
4294 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4295 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4296 numCANT=$((numCANT+1))
4297 listCANT="$listCANT $N"
4298 else
4299 gentestcert testsrv
4300 tf="$td/test$N.stdout"
4301 te="$td/test$N.stderr"
4302 tdiff="$td/test$N.diff"
4303 da="test$N $(date) $RANDOM"
4304 init_openssl_s_server
4305 CMD2="$TRACE $SOCAT $opts exec:'openssl s_server $OPENSSL_S_SERVER_4 -accept "$PORT" -quiet -cert testsrv.pem' pipe"
4306 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4307 printf "test $F_n $TEST... " $N
4308 eval "$CMD2 2>\"${te}1\" &"
4309 pid=$! # background process id
4310 # this might timeout when openssl opens tcp46 port like " :::$PORT"
4311 waittcp4port $PORT
4312 #echo "$da" |$CMD >$tf 2>"${te}2"
4313 #note: with about OpenSSL 1.1 s_server lost the half close feature, thus:
4314 (echo "$da"; sleep 0.1) |$CMD >$tf 2>"${te}2"
4315 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4316 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4317 echo "$CMD2 &"
4318 echo "$CMD"
4319 cat "${te}1"
4320 cat "${te}2"
4321 cat "$tdiff"
4322 numFAIL=$((numFAIL+1))
4323 listFAIL="$listFAIL $N"
4324 else
4325 $PRINTF "$OK\n"
4326 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4327 numOK=$((numOK+1))
4329 kill $pid 2>/dev/null; wait
4330 fi ;; # NUMCOND, feats
4331 esac
4332 PORT=$((PORT+1))
4333 N=$((N+1))
4336 NAME=OPENSSLLISTEN_TCP4
4337 case "$TESTS" in
4338 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4339 TEST="$NAME: openssl listen"
4340 if ! eval $NUMCOND; then :;
4341 elif ! testfeats openssl >/dev/null; then
4342 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4343 numCANT=$((numCANT+1))
4344 listCANT="$listCANT $N"
4345 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4346 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4347 numCANT=$((numCANT+1))
4348 listCANT="$listCANT $N"
4349 else
4350 gentestcert testsrv
4351 tf="$td/test$N.stdout"
4352 te="$td/test$N.stderr"
4353 tdiff="$td/test$N.diff"
4354 da="test$N $(date) $RANDOM"
4355 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4356 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4357 printf "test $F_n $TEST... " $N
4358 eval "$CMD2 2>\"${te}1\" &"
4359 pid=$! # background process id
4360 waittcp4port $PORT
4361 echo "$da" |$CMD >$tf 2>"${te}2"
4362 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4363 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4364 echo "$CMD2 &"
4365 echo "$CMD"
4366 cat "${te}1"
4367 cat "${te}2"
4368 cat "$tdiff"
4369 numFAIL=$((numFAIL+1))
4370 listFAIL="$listFAIL $N"
4371 else
4372 $PRINTF "$OK\n"
4373 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4374 numOK=$((numOK+1))
4376 kill $pid 2>/dev/null
4377 wait
4378 fi ;; # NUMCOND, feats
4379 esac
4380 PORT=$((PORT+1))
4381 N=$((N+1))
4383 NAME=OPENSSLLISTEN_TCP6
4384 case "$TESTS" in
4385 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4386 TEST="$NAME: openssl listen"
4387 if ! eval $NUMCOND; then :;
4388 elif ! testfeats openssl >/dev/null; then
4389 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4390 numCANT=$((numCANT+1))
4391 listCANT="$listCANT $N"
4392 elif ! testfeats listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4393 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4394 numCANT=$((numCANT+1))
4395 listCANT="$listCANT $N"
4396 else
4397 gentestcert testsrv
4398 tf="$td/test$N.stdout"
4399 te="$td/test$N.stderr"
4400 tdiff="$td/test$N.diff"
4401 da="test$N $(date) $RANDOM"
4402 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4403 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD"
4404 printf "test $F_n $TEST... " $N
4405 eval "$CMD2 2>\"${te}1\" &"
4406 pid=$! # background process id
4407 waittcp6port $PORT
4408 echo "$da" |$CMD >$tf 2>"${te}2"
4409 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4410 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4411 echo "$CMD2 &"
4412 echo "$CMD"
4413 cat "${te}1"
4414 cat "${te}2"
4415 cat "$tdiff"
4416 numFAIL=$((numFAIL+1))
4417 listFAIL="$listFAIL $N"
4418 else
4419 $PRINTF "$OK\n"
4420 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4421 numOK=$((numOK+1))
4423 kill $pid 2>/dev/null
4424 wait
4425 fi ;; # NUMCOND, feats
4426 esac
4427 PORT=$((PORT+1))
4428 N=$((N+1))
4431 while read NAMEKEYW FEAT RUNS TESTTMPL PEERTMPL WAITTMPL; do
4432 if [ -z "$NAMEKEYW" ] || [[ "$NAMEKEYW" == \#* ]]; then continue; fi
4434 export ts="$td/test$N.socket"
4435 WAITTMPL="$(echo "$WAITTMPL" |sed -e 's/\040/ /g')"
4436 TESTADDR=$(eval echo $TESTTMPL)
4437 PEERADDR=$(eval echo $PEERTMPL)
4438 WAITCMD=$(eval echo $WAITTMPL)
4439 TESTKEYW=${TESTADDR%%:*}
4440 feat=$(tolower $FEAT)
4442 # does our address implementation support halfclose?
4443 NAME=${NAMEKEYW}_HALFCLOSE
4444 case "$TESTS" in
4445 *%$N%*|*%functions%*|*%$feat%*|*%socket%*|*%halfclose%*|*%$NAME%*)
4446 TEST="$NAME: $TESTKEYW half close"
4447 # have a "peer" socat "peer" that executes "$OD_C" and see if EOF on the
4448 # connecting socat brings the result of od
4449 if ! eval $NUMCOND; then :;
4450 elif [ "$FEAT" != ',' ] && ! testfeats "$FEAT" >/dev/null; then
4451 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
4452 numCANT=$((numCANT+1))
4453 listCANT="$listCANT $N"
4454 elif ! runs$RUNS >/dev/null; then
4455 $PRINTF "test $F_n $TEST... ${YELLOW}$RUNS not available${NORMAL}\n" $N
4456 numCANT=$((numCANT+1))
4457 listCANT="$listCANT $N"
4458 else
4459 tf="$td/test$N.stdout"
4460 te="$td/test$N.stderr"
4461 tdiff="$td/test$N.diff"
4462 da="test$N $(date) $RANDOM"
4463 CMD2="$TRACE $SOCAT $opts \"$PEERADDR\" EXEC:'$OD_C'"
4464 CMD="$TRACE $SOCAT -T1 $opts -t 1 - $TESTADDR"
4465 printf "test $F_n $TEST... " $N
4466 eval "$CMD2 2>\"${te}1\" &"
4467 pid=$! # background process id
4468 $WAITCMD
4469 echo "$da" |$CMD >$tf 2>"${te}2"
4470 if ! echo "$da" |$OD_C |diff - "$tf" >"$tdiff"; then
4471 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4472 echo "$CMD2 &"
4473 echo "$CMD"
4474 cat "${te}1"
4475 cat "${te}2"
4476 cat "$tdiff"
4477 numFAIL=$((numFAIL+1))
4478 listFAIL="$listFAIL $N"
4479 else
4480 $PRINTF "$OK\n"
4481 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4482 numOK=$((numOK+1))
4484 kill $pid 2>/dev/null
4485 wait
4486 fi ;; # NUMCOND, feats
4487 esac
4488 PORT=$((PORT+1))
4489 N=$((N+1))
4491 done <<<"
4492 UNIXCONNECT , unix UNIX-CONNECT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4493 UNIXCLIENT , unix UNIX-CLIENT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4494 GOPEN_UNIXSTREAM , unix GOPEN:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4495 UNIXLISTEN , unix UNIX-LISTEN:\$ts UNIX-CONNECT:\$ts,retry=3 sleep\040\1
4496 TCP4CONNECT , tcp4 TCP4-CONNECT:\$LOCALHOST:\$PORT TCP4-LISTEN:\$PORT,$REUSEADDR waittcp4port\040\$PORT
4497 TCP4LISTEN , tcp4 TCP4-LISTEN:\$PORT,$REUSEADDR TCP4-CONNECT:\$LOCALHOST:\$PORT,retry=3
4498 TCP6CONNECT , tcp6 TCP6-CONNECT:\$LOCALHOST6:\$PORT TCP6-LISTEN:\$PORT,$REUSEADDR waittcp6port\040\$PORT
4499 TCP6LISTEN , tcp6 TCP6-LISTEN:\$PORT,$REUSEADDR TCP6-CONNECT:\$LOCALHOST6:\$PORT,retry=3
4500 OPENSSL4CLIENT OPENSSL tcp4 OPENSSL:\$LOCALHOST:\$PORT,verify=0 OPENSSL-LISTEN:\$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp4port\040\$PORT
4501 OPENSSL4SERVER OPENSSL tcp4 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST:\$PORT,$REUSEADDR,verify=0,retry=3
4502 OPENSSL6CLIENT OPENSSL tcp6 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0 OPENSSL-LISTEN:\$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp6port\040\$PORT
4503 OPENSSL6SERVER OPENSSL tcp6 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,$REUSEADDR,verify=0,retry=3
4507 NAME=OPENSSL_SERVERAUTH
4508 case "$TESTS" in
4509 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4510 TEST="$NAME: OpenSSL server authentication (hostname)"
4511 if ! eval $NUMCOND; then :;
4512 elif ! testfeats openssl >/dev/null; then
4513 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4514 numCANT=$((numCANT+1))
4515 listCANT="$listCANT $N"
4516 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4517 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4518 numCANT=$((numCANT+1))
4519 listCANT="$listCANT $N"
4520 else
4521 gentestcert testsrv
4522 gentestcert testcli
4523 tf="$td/test$N.stdout"
4524 te="$td/test$N.stderr"
4525 tdiff="$td/test$N.diff"
4526 da="test$N $(date) $RANDOM"
4527 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4528 CMD1="$TRACE $SOCAT $opts - OPENSSL:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD"
4529 printf "test $F_n $TEST... " $N
4530 eval "$CMD0 2>\"${te}0\" &"
4531 pid=$! # background process id
4532 waittcp4port $PORT
4533 echo "$da" |$CMD1 >$tf 2>"${te}1"
4534 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4535 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4536 echo "$CMD0 &"
4537 cat "${te}0"
4538 echo "$CMD1"
4539 cat "${te}1"
4540 cat "$tdiff"
4541 numFAIL=$((numFAIL+1))
4542 listFAIL="$listFAIL $N"
4543 else
4544 $PRINTF "$OK\n"
4545 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4546 numOK=$((numOK+1))
4548 kill $pid 2>/dev/null
4549 wait
4550 fi ;; # NUMCOND, feats
4551 esac
4552 PORT=$((PORT+1))
4553 N=$((N+1))
4555 NAME=OPENSSL_CLIENTAUTH
4556 case "$TESTS" in
4557 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4558 TEST="$NAME: openssl client authentication"
4559 if ! eval $NUMCOND; then :;
4560 elif ! testfeats openssl >/dev/null; then
4561 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4562 numCANT=$((numCANT+1))
4563 listCANT="$listCANT $N"
4564 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4565 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4566 numCANT=$((numCANT+1))
4567 listCANT="$listCANT $N"
4568 else
4569 gentestcert testsrv
4570 gentestcert testcli
4571 tf="$td/test$N.stdout"
4572 te="$td/test$N.stderr"
4573 tdiff="$td/test$N.diff"
4574 da="test$N $(date) $RANDOM"
4575 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe"
4576 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD"
4577 printf "test $F_n $TEST... " $N
4578 eval "$CMD2 2>\"${te}1\" &"
4579 pid=$! # background process id
4580 waittcp4port $PORT
4581 echo "$da" |$CMD >$tf 2>"${te}2"
4582 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4583 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4584 echo "$CMD2 &"
4585 echo "$CMD"
4586 cat "${te}1"
4587 cat "${te}2"
4588 cat "$tdiff"
4589 numFAIL=$((numFAIL+1))
4590 listFAIL="$listFAIL $N"
4591 else
4592 $PRINTF "$OK\n"
4593 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4594 numOK=$((numOK+1))
4596 kill $pid 2>/dev/null
4597 wait
4598 fi ;; # NUMCOND, feats
4599 esac
4600 PORT=$((PORT+1))
4601 N=$((N+1))
4603 NAME=OPENSSL_FIPS_BOTHAUTH
4604 case "$TESTS" in
4605 *%$N%*|*%functions%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4606 TEST="$NAME: OpenSSL+FIPS client and server authentication"
4607 if ! eval $NUMCOND; then :;
4608 elif ! testfeats openssl >/dev/null; then
4609 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4610 numCANT=$((numCANT+1))
4611 listCANT="$listCANT $N"
4612 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4613 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4614 numCANT=$((numCANT+1))
4615 listCANT="$listCANT $N"
4616 elif ! testoptions fips >/dev/null; then
4617 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
4618 numCANT=$((numCANT+1))
4619 listCANT="$listCANT $N"
4620 else
4621 OPENSSL_FIPS=1 gentestcert testsrvfips
4622 OPENSSL_FIPS=1 gentestcert testclifips
4623 tf="$td/test$N.stdout"
4624 te="$td/test$N.stderr"
4625 tdiff="$td/test$N.diff"
4626 da="test$N $(date) $RANDOM"
4627 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe"
4628 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD"
4629 printf "test $F_n $TEST... " $N
4630 eval "$CMD2 2>\"${te}1\" &"
4631 pid=$! # background process id
4632 waittcp4port $PORT
4633 echo "$da" |$CMD >$tf 2>"${te}2"
4634 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4635 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4636 echo "$CMD2 &"
4637 echo "$CMD"
4638 cat "${te}1"
4639 cat "${te}2"
4640 cat "$tdiff"
4641 numFAIL=$((numFAIL+1))
4642 listFAIL="$listFAIL $N"
4643 else
4644 $PRINTF "$OK\n"
4645 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4646 numOK=$((numOK+1))
4648 kill $pid 2>/dev/null
4649 wait
4650 fi ;; # NUMCOND, feats
4651 esac
4652 PORT=$((PORT+1))
4653 N=$((N+1))
4656 NAME=OPENSSL_COMPRESS
4657 case "$TESTS" in
4658 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4659 TEST="$NAME: OpenSSL compression"
4660 if ! eval $NUMCOND; then :;
4661 elif ! testfeats openssl >/dev/null; then
4662 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4663 numCANT=$((numCANT+1))
4664 listCANT="$listCANT $N"
4665 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4666 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4667 numCANT=$((numCANT+1))
4668 listCANT="$listCANT $N"
4669 elif ! testoptions openssl-compress >/dev/null; then
4670 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL compression option not available${NORMAL}\n" $N
4671 numCANT=$((numCANT+1))
4672 listCANT="$listCANT $N"
4673 else
4674 gentestcert testsrv
4675 printf "test $F_n $TEST... " $N
4676 tf="$td/test$N.stdout"
4677 te="$td/test$N.stderr"
4678 tdiff="$td/test$N.diff"
4679 da="test$N $(date) $RANDOM"
4680 success=yes
4681 for srccompr in '' compress=auto compress=none; do
4682 for dstcompr in '' compress=auto compress=none; do
4683 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0,$dstcompr pipe"
4684 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD,$srccompr"
4685 eval "$CMD2 2>\"${te}1\" &"
4686 pid=$! # background process id
4687 waittcp4port $PORT
4688 echo "$da" | $CMD >$tf 2>"${te}2"
4689 kill $pid 2>/dev/null
4690 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4691 success=
4692 break
4694 done
4695 done
4696 if test -z "$success"; then
4697 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4698 echo "$CMD2 &"
4699 echo "$CMD"
4700 cat "${te}1"
4701 cat "${te}2"
4702 cat "$tdiff"
4703 numFAIL=$((numFAIL+1))
4704 listFAIL="$listFAIL $N"
4705 else
4706 $PRINTF "$OK\n"
4707 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4708 numOK=$((numOK+1))
4710 fi ;; # NUMCOND, feats
4711 esac
4712 PORT=$((PORT+1))
4713 N=$((N+1))
4716 NAME=SOCKS4CONNECT_TCP4
4717 case "$TESTS" in
4718 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4719 TEST="$NAME: socks4 connect over TCP/IPv4"
4720 if ! eval $NUMCOND; then :;
4721 elif ! testfeats socks4 >/dev/null; then
4722 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4723 numCANT=$((numCANT+1))
4724 listCANT="$listCANT $N"
4725 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4726 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4727 numCANT=$((numCANT+1))
4728 listCANT="$listCANT $N"
4729 else
4730 tf="$td/test$N.stdout"
4731 te="$td/test$N.stderr"
4732 tdiff="$td/test$N.diff"
4733 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4734 # we have a normal tcp echo listening - so the socks header must appear in answer
4735 CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
4736 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4737 printf "test $F_n $TEST... " $N
4738 eval "$CMD2 2>\"${te}1\" &"
4739 pid=$! # background process id
4740 waittcp4port $PORT 1
4741 echo "$da" |$CMD >$tf 2>"${te}2"
4742 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4743 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4744 echo "$CMD2 &"
4745 echo "$CMD"
4746 cat "${te}1"
4747 cat "${te}2"
4748 cat "$tdiff"
4749 numFAIL=$((numFAIL+1))
4750 listFAIL="$listFAIL $N"
4751 else
4752 $PRINTF "$OK\n"
4753 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4754 numOK=$((numOK+1))
4756 kill $pid 2>/dev/null
4757 wait
4758 fi ;; # NUMCOND, feats
4759 esac
4760 PORT=$((PORT+1))
4761 N=$((N+1))
4763 NAME=SOCKS4CONNECT_TCP6
4764 case "$TESTS" in
4765 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4766 TEST="$NAME: socks4 connect over TCP/IPv6"
4767 if ! eval $NUMCOND; then :;
4768 elif ! testfeats socks4 >/dev/null; then
4769 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4770 numCANT=$((numCANT+1))
4771 listCANT="$listCANT $N"
4772 elif ! testfeats listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4773 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4774 numCANT=$((numCANT+1))
4775 listCANT="$listCANT $N"
4776 else
4777 tf="$td/test$N.stdout"
4778 te="$td/test$N.stderr"
4779 tdiff="$td/test$N.diff"
4780 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4781 # we have a normal tcp echo listening - so the socks header must appear in answer
4782 CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
4783 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser="nobody"
4784 printf "test $F_n $TEST... " $N
4785 eval "$CMD2 2>\"${te}1\" &"
4786 pid=$! # background process id
4787 waittcp6port $PORT 1
4788 echo "$da" |$CMD >$tf 2>"${te}2"
4789 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4790 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4791 echo "$CMD2 &"
4792 echo "$CMD"
4793 cat "${te}1"
4794 cat "${te}2"
4795 cat "$tdiff"
4796 numFAIL=$((numFAIL+1))
4797 listFAIL="$listFAIL $N"
4798 else
4799 $PRINTF "$OK\n"
4800 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4801 numOK=$((numOK+1))
4803 kill $pid 2>/dev/null
4804 wait
4805 fi ;; # NUMCOND, feats
4806 esac
4807 PORT=$((PORT+1))
4808 N=$((N+1))
4811 NAME=SOCKS4ACONNECT_TCP4
4812 case "$TESTS" in
4813 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4814 TEST="$NAME: socks4a connect over TCP/IPv4"
4815 if ! eval $NUMCOND; then :;
4816 elif ! testfeats socks4a >/dev/null; then
4817 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4818 numCANT=$((numCANT+1))
4819 listCANT="$listCANT $N"
4820 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4821 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4822 numCANT=$((numCANT+1))
4823 listCANT="$listCANT $N"
4824 else
4825 tf="$td/test$N.stdout"
4826 te="$td/test$N.stderr"
4827 tdiff="$td/test$N.diff"
4828 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4829 # we have a normal tcp echo listening - so the socks header must appear in answer
4830 CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
4831 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4832 printf "test $F_n $TEST... " $N
4833 eval "$CMD2 2>\"${te}1\" &"
4834 pid=$! # background process id
4835 waittcp4port $PORT 1
4836 echo "$da" |$CMD >$tf 2>"${te}2"
4837 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4838 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4839 echo "$CMD2 &"
4840 echo "$CMD"
4841 cat "${te}1"
4842 cat "${te}2"
4843 cat "$tdiff"
4844 numFAIL=$((numFAIL+1))
4845 listFAIL="$listFAIL $N"
4846 else
4847 $PRINTF "$OK\n"
4848 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4849 numOK=$((numOK+1))
4851 kill $pid 2>/dev/null
4852 wait
4853 fi ;; # NUMCOND, feats
4854 esac
4855 PORT=$((PORT+1))
4856 N=$((N+1))
4858 NAME=SOCKS4ACONNECT_TCP6
4859 case "$TESTS" in
4860 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4861 TEST="$NAME: socks4a connect over TCP/IPv6"
4862 if ! eval $NUMCOND; then :;
4863 elif ! testfeats socks4a >/dev/null; then
4864 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4865 numCANT=$((numCANT+1))
4866 listCANT="$listCANT $N"
4867 elif ! testfeats listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4868 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4869 numCANT=$((numCANT+1))
4870 listCANT="$listCANT $N"
4871 else
4872 tf="$td/test$N.stdout"
4873 te="$td/test$N.stderr"
4874 tdiff="$td/test$N.diff"
4875 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4876 # we have a normal tcp echo listening - so the socks header must appear in answer
4877 CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
4878 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser="nobody"
4879 printf "test $F_n $TEST... " $N
4880 eval "$CMD2 2>\"${te}1\" &"
4881 pid=$! # background process id
4882 waittcp6port $PORT 1
4883 echo "$da" |$CMD >$tf 2>"${te}2"
4884 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4885 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4886 echo "$CMD2 &"
4887 echo "$CMD"
4888 cat "${te}1"
4889 cat "${te}2"
4890 cat "$tdiff"
4891 numFAIL=$((numFAIL+1))
4892 listFAIL="$listFAIL $N"
4893 else
4894 $PRINTF "$OK\n"
4895 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4896 numOK=$((numOK+1))
4898 kill $pid 2>/dev/null
4899 wait
4900 fi ;; # NUMCOND, feats
4901 esac
4902 PORT=$((PORT+1))
4903 N=$((N+1))
4906 NAME=PROXYCONNECT_TCP4
4907 case "$TESTS" in
4908 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4909 TEST="$NAME: proxy connect over TCP/IPv4"
4910 if ! eval $NUMCOND; then :;
4911 elif ! testfeats proxy >/dev/null; then
4912 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4913 numCANT=$((numCANT+1))
4914 listCANT="$listCANT $N"
4915 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4916 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4917 numCANT=$((numCANT+1))
4918 listCANT="$listCANT $N"
4919 else
4920 ts="$td/test$N.sh"
4921 tf="$td/test$N.stdout"
4922 te="$td/test$N.stderr"
4923 tdiff="$td/test$N.diff"
4924 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4925 #CMD2="$TRACE $SOCAT tcp4-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4926 CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
4927 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4928 printf "test $F_n $TEST... " $N
4929 eval "$CMD2 2>\"${te}2\" &"
4930 pid=$! # background process id
4931 waittcp4port $PORT 1
4932 echo "$da" |$CMD >"$tf" 2>"${te}1"
4933 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4934 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4935 echo "$CMD2 &"
4936 echo "$CMD"
4937 cat "${te}1"
4938 cat "${te}2"
4939 cat "$tdiff"
4940 numFAIL=$((numFAIL+1))
4941 listFAIL="$listFAIL $N"
4942 else
4943 $PRINTF "$OK\n"
4944 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4945 numOK=$((numOK+1))
4947 kill $pid 2>/dev/null
4948 wait
4949 fi ;; # NUMCOND, feats
4950 esac
4951 PORT=$((PORT+1))
4952 N=$((N+1))
4954 NAME=PROXYCONNECT_TCP6
4955 case "$TESTS" in
4956 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4957 TEST="$NAME: proxy connect over TCP/IPv6"
4958 if ! eval $NUMCOND; then :;
4959 elif ! testfeats proxy >/dev/null; then
4960 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4961 numCANT=$((numCANT+1))
4962 listCANT="$listCANT $N"
4963 elif ! testfeats listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4964 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4965 numCANT=$((numCANT+1))
4966 listCANT="$listCANT $N"
4967 else
4968 ts="$td/test$N.sh"
4969 tf="$td/test$N.stdout"
4970 te="$td/test$N.stderr"
4971 tdiff="$td/test$N.diff"
4972 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4973 #CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4974 CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
4975 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT"
4976 printf "test $F_n $TEST... " $N
4977 eval "$CMD2 2>\"${te}2\" &"
4978 pid=$! # background process id
4979 waittcp6port $PORT 1
4980 echo "$da" |$CMD >"$tf" 2>"${te}1"
4981 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4982 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4983 echo "$CMD2 &"
4984 echo "$CMD"
4985 cat "${te}1"
4986 cat "${te}2"
4987 cat "$tdiff"
4988 numFAIL=$((numFAIL+1))
4989 listFAIL="$listFAIL $N"
4990 else
4991 $PRINTF "$OK\n"
4992 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4993 numOK=$((numOK+1))
4995 kill $pid 2>/dev/null
4996 wait
4997 fi ;; # NUMCOND, feats
4998 esac
4999 PORT=$((PORT+1))
5000 N=$((N+1))
5003 NAME=TCP4NOFORK
5004 case "$TESTS" in
5005 *%$N%*|*%functions%*|*%$NAME%*)
5006 TEST="$NAME: echo via connection to TCP V4 socket with nofork'ed exec"
5007 if ! eval $NUMCOND; then :; else
5008 tf="$td/test$N.stdout"
5009 te="$td/test$N.stderr"
5010 tdiff="$td/test$N.diff"
5011 tsl=$PORT
5012 ts="127.0.0.1:$tsl"
5013 da="test$N $(date) $RANDOM"
5014 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR exec:$CAT,nofork"
5015 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
5016 printf "test $F_n $TEST... " $N
5017 #$CMD1 >"$tf" 2>"${te}1" &
5018 $CMD1 >/dev/null 2>"${te}1" &
5019 waittcp4port $tsl
5020 #usleep $MICROS
5021 echo "$da" |$CMD2 >"$tf" 2>>"${te}2"
5022 if [ $? -ne 0 ]; then
5023 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5024 echo "$CMD1 &"
5025 echo "$CMD2"
5026 cat "${te}1"
5027 cat "${te}2"
5028 numFAIL=$((numFAIL+1))
5029 listFAIL="$listFAIL $N"
5030 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
5031 $PRINTF "$FAILED\n"
5032 cat "$tdiff"
5033 numFAIL=$((numFAIL+1))
5034 listFAIL="$listFAIL $N"
5035 else
5036 $PRINTF "$OK\n"
5037 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
5038 numOK=$((numOK+1))
5040 fi ;; # NUMCOND
5041 esac
5042 PORT=$((PORT+1))
5043 N=$((N+1))
5046 NAME=EXECCATNOFORK
5047 case "$TESTS" in
5048 *%$N%*|*%functions%*|*%$NAME%*)
5049 TEST="$NAME: simple echo via exec of cat with nofork"
5050 testecho "$N" "$TEST" "" "exec:$CAT,nofork" "$opts"
5051 esac
5052 N=$((N+1))
5055 NAME=SYSTEMCATNOFORK
5056 case "$TESTS" in
5057 *%$N%*|*%functions%*|*%$NAME%*)
5058 TEST="$NAME: simple echo via system() of cat with nofork"
5059 testecho "$N" "$TEST" "" "system:$CAT,nofork" "$opts"
5060 esac
5061 N=$((N+1))
5064 NAME=NOFORKSETSID
5065 case "$TESTS" in
5066 *%$N%*|*%functions%*|*%$NAME%*)
5067 TEST="$NAME: simple echo via exec() of cat with nofork and setsid"
5068 testecho "$N" "$TEST" "" "system:$CAT,nofork,setsid" "$opts"
5069 esac
5070 N=$((N+1))
5072 #==============================================================================
5073 #TEST="$NAME: echo via 'connection' to UDP V4 socket"
5074 #if ! eval $NUMCOND; then :; else
5075 #tf="$td/file$N"
5076 #tsl=65534
5077 #ts="127.0.0.1:$tsl"
5078 #da="test$N $(date) $RANDOM"
5079 #$TRACE $SOCAT UDP-listen:$tsl,$REUSEADDR PIPE &
5080 #sleep 2
5081 #echo "$da" |$TRACE $SOCAT stdin!!stdout UDP:$ts >"$tf"
5082 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
5083 # $ECHO "... test $N succeeded"
5084 # numOK=$((numOK+1))
5085 #else
5086 # $ECHO "*** test $N $FAILED"
5087 # numFAIL=$((numFAIL+1))
5088 # listFAIL="$listFAIL $N"
5090 #fi ;; # NUMCOND
5091 #N=$((N+1))
5092 #==============================================================================
5093 # TEST 4 - simple echo via new file
5094 #if ! eval $NUMCOND; then :; else
5095 #N=4
5096 #tf="$td/file$N"
5097 #tp="$td/pipe$N"
5098 #da="test$N $(date) $RANDOM"
5099 #rm -f "$tf.tmp"
5100 #echo "$da" |$TRACE $SOCAT - FILE:$tf.tmp,ignoreeof >"$tf"
5101 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
5102 # $ECHO "... test $N succeeded"
5103 # numOK=$((numOK+1))
5104 #else
5105 # $ECHO "*** test $N $FAILED"
5106 # numFAIL=$((numFAIL+1))
5107 # listFAIL="$listFAIL $N"
5109 #fi ;; # NUMCOND
5111 #==============================================================================
5113 NAME=TOTALTIMEOUT
5114 case "$TESTS" in
5115 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%$NAME%*)
5116 TEST="$NAME: socat inactivity timeout"
5117 if ! eval $NUMCOND; then :; else
5118 #set -vx
5119 tf="$td/test$N.stdout"
5120 te="$td/test$N.stderr"
5121 tdiff="$td/test$N.diff"
5122 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
5123 CMD2="$TRACE $SOCAT $opts -T 1 TCP4-LISTEN:$PORT,$REUSEADDR pipe"
5124 CMD="$TRACE $SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT"
5125 printf "test $F_n $TEST... " $N
5126 eval "$CMD2 2>${te}1 &"
5127 pid=$! # background process id
5128 waittcp4port $PORT 1
5129 (echo "$da"; sleep 2; echo X) |$CMD >"$tf" 2>"${te}2"
5130 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5131 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5132 echo "$CMD2 &"
5133 echo "$CMD"
5134 cat "${te}1"
5135 cat "${te}2"
5136 cat "$tdiff"
5137 numFAIL=$((numFAIL+1))
5138 listFAIL="$listFAIL $N"
5139 else
5140 $PRINTF "$OK\n"
5141 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
5142 numOK=$((numOK+1))
5144 kill $pid 2>/dev/null
5145 wait
5146 #set +vx
5147 fi ;; # NUMCOND
5148 esac
5149 PORT=$((PORT+1))
5150 N=$((N+1))
5153 NAME=IGNOREEOF+TOTALTIMEOUT
5154 case "$TESTS" in
5155 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
5156 TEST="$NAME: ignoreeof and inactivity timeout"
5157 if ! eval $NUMCOND; then :; else
5158 #set -vx
5159 ti="$td/test$N.file"
5160 tf="$td/test$N.stdout"
5161 te="$td/test$N.stderr"
5162 tdiff="$td/test$N.diff"
5163 da="test$N $(date) $RANDOM"
5164 CMD="$TRACE $SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -"
5165 printf "test $F_n $TEST... " $N
5166 touch "$ti"
5167 $CMD >"$tf" 2>"$te" &
5168 bg=$! # background process id
5169 psleep 0.5
5170 echo "$da" >>"$ti"
5171 sleep 4
5172 echo X >>"$ti"
5173 sleep 1
5174 kill $bg 2>/dev/null
5175 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5176 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5177 echo "$CMD &"
5178 cat "$te"
5179 cat "$tdiff"
5180 numFAIL=$((numFAIL+1))
5181 listFAIL="$listFAIL $N"
5182 else
5183 $PRINTF "$OK\n"
5184 if [ -n "$debug" ]; then cat "$te"; fi
5185 numOK=$((numOK+1))
5187 wait
5188 fi ;; # NUMCOND, feats
5189 esac
5190 N=$((N+1))
5193 NAME=PROXY2SPACES
5194 case "$TESTS" in
5195 *%$N%*|*%functions%*|*%proxy%*|*%$NAME%*)
5196 TEST="$NAME: proxy connect accepts status with multiple spaces"
5197 if ! eval $NUMCOND; then :;
5198 elif ! testfeats proxy >/dev/null; then
5199 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
5200 numCANT=$((numCANT+1))
5201 listCANT="$listCANT $N"
5202 else
5203 ts="$td/test$N.sh"
5204 tf="$td/test$N.stdout"
5205 te="$td/test$N.stderr"
5206 tdiff="$td/test$N.diff"
5207 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
5208 #CMD2="$TRACE $SOCAT $opts tcp-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
5209 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/usr/bin/env bash proxyecho.sh -w 2\""
5210 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
5211 printf "test $F_n $TEST... " $N
5212 eval "$CMD2 2>\"${te}1\" &"
5213 pid=$! # background process id
5214 waittcp4port $PORT 1
5215 echo "$da" |$CMD >"$tf" 2>"${te}2"
5216 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5217 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5218 echo "$CMD2 &"
5219 echo "$CMD"
5220 cat "${te}1"
5221 cat "${te}2"
5222 cat "$tdiff"
5223 numFAIL=$((numFAIL+1))
5224 listFAIL="$listFAIL $N"
5225 else
5226 $PRINTF "$OK\n"
5227 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
5228 numOK=$((numOK+1))
5230 kill $pid 2>/dev/null
5231 wait
5232 fi ;; # NUMCOND, feats
5233 esac
5234 PORT=$((PORT+1))
5235 N=$((N+1))
5238 NAME=BUG-UNISTDIO
5239 case "$TESTS" in
5240 *%$N%*|*%functions%*|*%$NAME%*)
5241 TEST="$NAME: for bug with address options on both stdin/out in unidirectional mode"
5242 if ! eval $NUMCOND; then :; else
5243 tf="$td/test$N.stdout"
5244 te="$td/test$N.stderr"
5245 ff="$td/test$N.file"
5246 printf "test $F_n $TEST... " $N
5247 >"$ff"
5248 #$TRACE $SOCAT $opts -u /dev/null -,setlk <"$ff" 2>"$te"
5249 CMD="$TRACE $SOCAT $opts -u /dev/null -,setlk"
5250 $CMD <"$ff" 2>"$te"
5251 if [ "$?" -eq 0 ]; then
5252 $PRINTF "$OK\n"
5253 numOK=$((numOK+1))
5254 else
5255 if [ "$UNAME" = "Linux" ]; then
5256 $PRINTF "$FAILED\n"
5257 echo "$CMD"
5258 cat "$te"
5259 numFAIL=$((numFAIL+1))
5260 listFAIL="$listFAIL $N"
5261 else
5262 $PRINTF "${YELLOW}failed (don't care)${NORMAL}\n"
5263 numCANT=$((numCANT+1))
5264 listCANT="$listCANT $N"
5267 fi ;; # NUMCOND
5268 esac
5269 N=$((N+1))
5272 NAME=SINGLEEXECOUTSOCKETPAIR
5273 case "$TESTS" in
5274 *%$N%*|*%functions%*|*%$NAME%*)
5275 TEST="$NAME: inheritance of stdout to single exec with socketpair"
5276 testecho "$N" "$TEST" "-!!exec:cat" "" "$opts" 1
5277 esac
5278 N=$((N+1))
5280 NAME=SINGLEEXECOUTPIPE
5281 case "$TESTS" in
5282 *%$N%*|*%functions%*|*%$NAME%*)
5283 TEST="$NAME: inheritance of stdout to single exec with pipe"
5284 testecho "$N" "$TEST" "-!!exec:cat,pipes" "" "$opts" 1
5285 esac
5286 N=$((N+1))
5288 NAME=SINGLEEXECOUTPTY
5289 case "$TESTS" in
5290 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5291 TEST="$NAME: inheritance of stdout to single exec with pty"
5292 if ! eval $NUMCOND; then :;
5293 elif ! testfeats pty >/dev/null; then
5294 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5295 numCANT=$((numCANT+1))
5296 listCANT="$listCANT $N"
5297 else
5298 testecho "$N" "$TEST" "-!!exec:cat,pty,raw" "" "$opts" 1
5299 fi ;; # NUMCOND, feats
5300 esac
5301 N=$((N+1))
5303 NAME=SINGLEEXECINSOCKETPAIR
5304 case "$TESTS" in
5305 *%$N%*|*%functions%*|*%$NAME%*)
5306 TEST="$NAME: inheritance of stdin to single exec with socketpair"
5307 testecho "$N" "$TEST" "exec:cat!!-" "" "$opts"
5308 esac
5309 N=$((N+1))
5311 NAME=SINGLEEXECINPIPE
5312 case "$TESTS" in
5313 *%$N%*|*%functions%*|*%$NAME%*)
5314 TEST="$NAME: inheritance of stdin to single exec with pipe"
5315 testecho "$N" "$TEST" "exec:cat,pipes!!-" "" "$opts"
5316 esac
5317 N=$((N+1))
5319 NAME=SINGLEEXECINPTYDELAY
5320 case "$TESTS" in
5321 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5322 TEST="$NAME: inheritance of stdin to single exec with pty, with delay"
5323 if ! eval $NUMCOND; then :;
5324 elif ! testfeats pty >/dev/null; then
5325 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5326 numCANT=$((numCANT+1))
5327 listCANT="$listCANT $N"
5328 else
5329 testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts" $MISCDELAY
5330 fi ;; # NUMCOND, feats
5331 esac
5332 N=$((N+1))
5334 NAME=SINGLEEXECINPTY
5335 case "$TESTS" in
5336 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5337 TEST="$NAME: inheritance of stdin to single exec with pty"
5338 if ! eval $NUMCOND; then :;
5339 elif ! testfeats pty >/dev/null; then
5340 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5341 numCANT=$((numCANT+1))
5342 listCANT="$listCANT $N"
5343 else
5344 testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts"
5345 fi ;; # NUMCOND, feats
5346 esac
5347 N=$((N+1))
5350 NAME=READLINE
5351 #set -vx
5352 case "$TESTS" in
5353 *%$N%*|*%functions%*|*%pty%*|*%readline%*|*%$NAME%*)
5354 TEST="$NAME: readline with password and sigint"
5355 if ! eval $NUMCOND; then :;
5356 elif ! feat=$(testfeats readline pty); then
5357 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5358 numCANT=$((numCANT+1))
5359 listCANT="$listCANT $N"
5360 else
5361 SAVETERM="$TERM"; TERM= # 'cause konsole might print controls even in raw
5362 SAVEMICS=$MICROS
5363 #MICROS=2000000
5364 ts="$td/test$N.sh"
5365 to="$td/test$N.stdout"
5366 tpi="$td/test$N.inpipe"
5367 tpo="$td/test$N.outpipe"
5368 te="$td/test$N.stderr"
5369 tr="$td/test$N.ref"
5370 tdiff="$td/test$N.diff"
5371 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
5372 # the feature that we really want to test is in the readline.sh script:
5373 CMD="$TRACE $SOCAT $opts -t1 open:$tpi,nonblock!!open:$tpo exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig"
5374 #echo "$CMD" >"$ts"
5375 #chmod a+x "$ts"
5376 printf "test $F_n $TEST... " $N
5377 rm -f "$tpi" "$tpo"
5378 mkfifo "$tpi"
5379 touch "$tpo"
5381 # during development of this test, the following command line succeeded:
5382 # (sleep 1; $ECHO "user\n\c"; sleep 1; $ECHO "password\c"; sleep 1; $ECHO "\n\c"; sleep 1; $ECHO "test 1\n\c"; sleep 1; $ECHO "\003\c"; sleep 1; $ECHO "test 2\n\c"; sleep 1; $ECHO "exit\n\c"; sleep 1) |$TRACE $SOCAT -d -d -d -d -lf/tmp/$USER/debug1 -v -x - exec:'./readline.sh ./readline-test.sh',pty,ctty,setsid,raw,echo=0,isig
5384 PATH=${SOCAT%socat}:$PATH eval "$CMD 2>$te &"
5385 pid=$! # background process id
5386 usleep $MICROS
5389 usleep $((3*MICROS))
5390 $ECHO "user\n\c"
5391 usleep $MICROS
5392 $ECHO "password\c"
5393 usleep $MICROS
5394 $ECHO "\n\c"
5395 usleep $MICROS
5396 $ECHO "test 1\n\c"
5397 usleep $MICROS
5398 $ECHO "\003\c"
5399 usleep $MICROS
5400 $ECHO "test 2\n\c"
5401 usleep $MICROS
5402 $ECHO "exit\n\c"
5403 usleep $MICROS
5404 ) >"$tpi"
5406 cat >$tr <<EOF
5407 readline feature test program
5408 Authentication required
5409 Username: user
5410 Password:
5411 prog> test 1
5412 executing test 1
5413 prog> ./readline-test.sh got SIGINT
5414 test 2
5415 executing test 2
5416 prog> exit
5419 #0 if ! sed 's/.*\r//g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5420 #0 if ! sed 's/.*'"$($ECHO '\r\c')"'/</g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5421 wait
5422 if ! tr "$($ECHO '\r \c')" "% " <$tpo |sed 's/%$//g' |sed 's/.*%//g' |diff "$tr" - >"$tdiff" 2>&1; then
5423 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5424 echo "$CMD"
5425 cat "$te"
5426 cat "$tdiff"
5427 numFAIL=$((numFAIL+1))
5428 listFAIL="$listFAIL $N"
5429 else
5430 $PRINTF "$OK\n"
5431 if [ -n "$debug" ]; then cat $te; fi
5432 numOK=$((numOK+1))
5434 kill $pid 2>/dev/null # necc on OpenBSD
5435 wait
5436 MICROS=$SAVEMICS
5437 TERM="$SAVETERM"
5438 fi ;; # NUMCOND, feats
5439 esac
5440 PORT=$((PORT+1))
5441 N=$((N+1))
5444 NAME=GENDERCHANGER
5445 case "$TESTS" in
5446 *%$N%*|*%functions%*|*%$NAME%*)
5447 TEST="$NAME: TCP4 \"gender changer\""
5448 if ! eval $NUMCOND; then :; else
5449 tf="$td/test$N.stdout"
5450 te="$td/test$N.stderr"
5451 tdiff="$td/test$N.diff"
5452 da="test$N $(date) $RANDOM"
5453 # this is the server in the protected network that we want to reach
5454 CMD1="$TRACE $SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5455 # this is the double client in the protected network
5456 CMD2="$TRACE $SOCAT -lp2client $opts tcp4:$LOCALHOST:$((PORT+1)),retry=10,interval=1 tcp4:$LOCALHOST:$PORT"
5457 # this is the double server in the outside network
5458 CMD3="$TRACE $SOCAT -lp2server $opts tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST"
5459 # this is the outside client that wants to use the protected server
5460 CMD4="$TRACE $SOCAT -lpclient $opts -t1 - tcp4:$LOCALHOST:$((PORT+2))"
5461 printf "test $F_n $TEST... " $N
5462 eval "$CMD1 2>${te}1 &"
5463 pid1=$!
5464 eval "$CMD2 2>${te}2 &"
5465 pid2=$!
5466 eval "$CMD3 2>${te}3 &"
5467 pid3=$!
5468 waittcp4port $PORT 1 &&
5469 waittcp4port $((PORT+2)) 1
5470 sleep 1
5471 echo "$da" |$CMD4 >$tf 2>"${te}4"
5472 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5473 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5474 echo "$CMD1 &"
5475 echo "$CMD2 &"
5476 echo "$CMD3 &"
5477 echo "$CMD4"
5478 cat "${te}1" "${te}2" "${te}3" "${te}4"
5479 cat "$tdiff"
5480 numFAIL=$((numFAIL+1))
5481 listFAIL="$listFAIL $N"
5482 else
5483 $PRINTF "$OK\n"
5484 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4"; fi
5485 numOK=$((numOK+1))
5487 kill $pid1 $pid2 $pid3 $pid4 2>/dev/null
5488 wait
5489 fi ;; # NUMCOND
5490 esac
5491 PORT=$((PORT+3))
5492 N=$((N+1))
5496 #PORT=10000
5498 NAME=OUTBOUNDIN
5499 case "$TESTS" in
5500 *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5501 TEST="$NAME: gender changer via SSL through HTTP proxy, oneshot"
5502 if ! eval $NUMCOND; then :;
5503 elif ! feat=$(testfeats openssl proxy); then
5504 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5505 numCANT=$((numCANT+1))
5506 listCANT="$listCANT $N"
5507 else
5508 gentestcert testsrv
5509 gentestcert testcli
5510 tf="$td/test$N.stdout"
5511 te="$td/test$N.stderr"
5512 tdiff="$td/test$N.diff"
5513 da="test$N $(date) $RANDOM"
5514 # this is the server in the protected network that we want to reach
5515 CMD1="$TRACE $SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5516 # this is the proxy in the protected network that provides a way out
5517 CMD2="$TRACE $SOCAT $opts -lpproxy tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5518 # this is our proxy connect wrapper in the protected network
5519 CMD3="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5520 # this is our double client in the protected network using SSL
5521 #CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5522 CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5523 # this is the double server in the outside network
5524 CMD5="$TRACE $SOCAT $opts -lp2server -t1 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt"
5525 # this is the outside client that wants to use the protected server
5526 CMD6="$TRACE $SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4))"
5527 printf "test $F_n $TEST... " $N
5528 eval "$CMD1 2>${te}1 &"
5529 pid1=$!
5530 eval "$CMD2 2>${te}2 &"
5531 pid2=$!
5532 eval "$CMD3 2>${te}3 &"
5533 pid3=$!
5534 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5535 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5536 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5537 eval "$CMD5 2>${te}5 &"
5538 pid5=$!
5539 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5540 echo "$da" |$CMD6 >$tf 2>"${te}6" &
5541 pid6=$!
5542 waittcp4port $((PORT+3)) 1 || $PRINTF "$FAILED: port $((PORT+3))\n" >&2 </dev/null
5543 eval "$CMD4 2>${te}4 &"
5544 pid4=$!
5545 wait $pid6
5546 if ! (echo "$da"; sleep 2) |diff - "$tf" >"$tdiff"; then
5547 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5548 echo "$CMD1 &"
5549 cat "${te}1"
5550 echo "$CMD2 &"
5551 cat "${te}2"
5552 echo "$CMD3 &"
5553 cat "${te}3"
5554 echo "$CMD5 &"
5555 cat "${te}5"
5556 echo "$CMD6"
5557 cat "${te}6"
5558 echo "$CMD4 &"
5559 cat "${te}4"
5560 cat "$tdiff"
5561 numFAIL=$((numFAIL+1))
5562 listFAIL="$listFAIL $N"
5563 else
5564 $PRINTF "$OK\n"
5565 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" "${te}6"; fi
5566 numOK=$((numOK+1))
5568 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5569 wait
5570 fi ;; # NUMCOND, feats
5571 esac
5572 PORT=$((PORT+5))
5573 N=$((N+1))
5576 # test the TCP gender changer with almost production requirements: a double
5577 # client repeatedly tries to connect to a double server via SSL through an HTTP
5578 # proxy. the double servers SSL port becomes active for one connection only
5579 # after a (real) client has connected to its TCP port. when the double client
5580 # succeeded to establish an SSL connection, it connects with its second client
5581 # side to the specified (protected) server. all three consecutive connections
5582 # must function for full success of this test.
5583 PORT=$((RANDOM+16184))
5585 NAME=INTRANETRIPPER
5586 case "$TESTS" in
5587 *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5588 TEST="$NAME: gender changer via SSL through HTTP proxy, daemons"
5589 if ! eval $NUMCOND; then :;
5590 elif ! feat=$(testfeats openssl proxy); then
5591 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5592 numCANT=$((numCANT+1))
5593 listCANT="$listCANT $N"
5594 else
5595 gentestcert testsrv
5596 gentestcert testcli
5597 tf="$td/test$N.stdout"
5598 te="$td/test$N.stderr"
5599 tdiff="$td/test$N.diff"
5600 da1="test$N.1 $(date) $RANDOM"
5601 da2="test$N.2 $(date) $RANDOM"
5602 da3="test$N.3 $(date) $RANDOM"
5603 # this is the server in the protected network that we want to reach
5604 CMD1="$TRACE $SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo"
5605 # this is the proxy in the protected network that provides a way out
5606 # note: the proxy.sh script starts one or two more socat processes without
5607 # setting the program name
5608 CMD2="$TRACE $SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5609 # this is our proxy connect wrapper in the protected network
5610 CMD3="$TRACE $SOCAT $opts -lpwrapper -t3 tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5611 # this is our double client in the protected network using SSL
5612 CMD4="$TRACE $SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT,forever,interval=0.1"
5613 # this is the double server in the outside network
5614 CMD5="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,backlog=3,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=20,interval=0.5"
5615 # this is the outside client that wants to use the protected server
5616 CMD6="$TRACE $SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3"
5617 printf "test $F_n $TEST... " $N
5618 # start the intranet infrastructure
5619 eval "$CMD1 2>\"${te}1\" &"
5620 pid1=$!
5621 eval "$CMD2 2>\"${te}2\" &"
5622 pid2=$!
5623 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5624 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5625 # initiate our internal measures
5626 eval "$CMD3 2>\"${te}3\" &"
5627 pid3=$!
5628 eval "$CMD4 2>\"${te}4\" &"
5629 pid4=$!
5630 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5631 # now we start the external daemon
5632 eval "$CMD5 2>\"${te}5\" &"
5633 pid5=$!
5634 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5635 # and this is the outside client:
5636 echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" &
5637 pid6_1=$!
5638 echo "$da2" |$CMD6 >${tf}_2 2>"${te}6_2" &
5639 pid6_2=$!
5640 echo "$da3" |$CMD6 >${tf}_3 2>"${te}6_3" &
5641 pid6_3=$!
5642 wait $pid6_1 $pid6_2 $pid6_3
5644 (echo "$da1"; sleep 2) |diff - "${tf}_1" >"${tdiff}1"
5645 (echo "$da2"; sleep 2) |diff - "${tf}_2" >"${tdiff}2"
5646 (echo "$da3"; sleep 2) |diff - "${tf}_3" >"${tdiff}3"
5647 if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then
5648 # FAILED only when none of the three transfers succeeded
5649 if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then
5650 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5651 echo "$CMD1 &"
5652 cat "${te}1"
5653 echo "$CMD2 &"
5654 cat "${te}2"
5655 echo "$CMD3 &"
5656 cat "${te}3"
5657 echo "$CMD4 &"
5658 cat "${te}4"
5659 echo "$CMD5 &"
5660 cat "${te}5"
5661 echo "$CMD6 &"
5662 cat "${te}6_1"
5663 cat "${tdiff}1"
5664 echo "$CMD6 &"
5665 cat "${te}6_2"
5666 cat "${tdiff}2"
5667 echo "$CMD6 &"
5668 cat "${te}6_3"
5669 cat "${tdiff}3"
5670 numFAIL=$((numFAIL+1))
5671 listFAIL="$listFAIL $N"
5672 else
5673 $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n"
5674 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5675 numOK=$((numOK+1))
5677 else
5678 $PRINTF "$OK\n"
5679 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5680 numOK=$((numOK+1))
5682 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5683 wait
5684 fi ;; # NUMCOND, feats
5685 esac
5686 PORT=$((PORT+5))
5687 N=$((N+1))
5690 # let us test the security features with -s, retry, and fork
5691 # method: first test without security feature if it works
5692 # then try with security feature, must fail
5694 # test the security features of a server address
5695 testserversec () {
5696 local N="$1"
5697 local title="$2"
5698 local opts="$3"
5699 local arg1="$4" # the server address
5700 local secopt0="$5" # option without security for server, mostly empty
5701 local secopt1="$6" # the security option for server, to be tested
5702 local arg2="$7" # the client address
5703 local ipvers="$8" # IP version, for check of listen port
5704 local proto="$9" # protocol, for check of listen port
5705 local port="${10}" # start client when this port is listening
5706 local expect="${11}" # expected behaviour of client: 0..empty output; -1..error; *: any of these
5707 local T="${12}"; [ -z "$T" ] && T=0
5708 local tf="$td/test$N.stdout"
5709 local te="$td/test$N.stderr"
5710 local tdiff1="$td/test$N.diff1"
5711 local tdiff2="$td/test$N.diff2"
5712 local da="test$N.1 $(date) $RANDOM"
5713 local stat result
5715 $PRINTF "test $F_n %s... " $N "$title"
5716 # first: without security
5717 # start server
5718 $TRACE $SOCAT $opts "$arg1,$secopt0" echo 2>"${te}1" &
5719 spid=$!
5720 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5721 kill $spid 2>/dev/null
5722 $PRINTF "$NO_RESULT (ph.1 server not working):\n"
5723 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5724 cat "${te}1"
5725 numCANT=$((numCANT+1))
5726 listCANT="$listCANT $N"
5727 wait; return
5729 # now use client
5730 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}2"
5731 stat="$?"
5732 kill $spid 2>/dev/null
5733 #killall $TRACE $SOCAT 2>/dev/null
5734 if [ "$stat" != 0 ]; then
5735 $PRINTF "$NO_RESULT (ph.1 function fails): $TRACE $SOCAT:\n"
5736 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5737 cat "${te}1"
5738 echo "$TRACE $SOCAT $opts - \"$arg2\""
5739 cat "${te}2"
5740 numCANT=$((numCANT+1))
5741 listCANT="$listCANT $N"
5742 wait; return
5743 elif echo "$da" |diff - "$tf" >"$tdiff1" 2>&1; then
5744 : # function without security is ok, go on
5745 else
5746 $PRINTF "$NO_RESULT (ph.1 function fails): diff:\n"
5747 echo "$TRACE $SOCAT $opts $arg1,$secopt0 echo &"
5748 cat "${te}1"
5749 echo "$TRACE $SOCAT $opts - $arg2"
5750 cat "${te}2"
5751 cat "$tdiff1"
5752 numCANT=$((numCANT+1))
5753 listCANT="$listCANT $N"
5754 wait; return
5757 # then: with security
5758 if [ "$port" ] && ! wait${proto}${ipvers}port $port 0; then
5759 $PRINTF "$NO_RESULT (ph.1 port remains in use)\n"
5760 numCANT=$((numCANT+1))
5761 listCANT="$listCANT $N"
5762 wait; return
5764 wait
5766 #set -vx
5767 # assemble address w/ security option; on dual, take read part:
5768 case "$arg1" in
5769 *!!*) arg="${arg1%!!*},$secopt1!!${arg1#*!!}" ;;
5770 *) arg="$arg1,$secopt1" ;;
5771 esac
5772 # start server
5773 # use -s to make sure that it fails due to a sec violation, not some other failure
5774 CMD3="$TRACE $SOCAT $opts -s $arg echo"
5775 $CMD3 2>"${te}3" &
5776 spid=$!
5777 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5778 kill $spid 2>/dev/null
5779 $PRINTF "$NO_RESULT (ph.2 server not working)\n"
5780 wait
5781 echo "$CMD3"
5782 cat "${te}3"
5783 numCANT=$((numCANT+1))
5784 listCANT="$listCANT $N"
5785 return
5787 # now use client
5788 da="test$N.2 $(date) $RANDOM"
5789 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}4"
5790 stat=$?
5791 kill $spid 2>/dev/null
5792 #set +vx
5793 #killall $TRACE $SOCAT 2>/dev/null
5794 if [ "$stat" != 0 ]; then
5795 result=-1; # socat had error
5796 elif [ ! -s "$tf" ]; then
5797 result=0; # empty output
5798 elif echo "$da" |diff - "$tf" >"$tdiff2" 2>&1; then
5799 result=1; # output is copy of input
5800 else
5801 result=2; # output differs from input
5803 if [ "$expect" != '1' -a "$result" -eq 1 ]; then
5804 $PRINTF "$FAILED: SECURITY BROKEN\n"
5805 echo "$TRACE $SOCAT $opts $arg echo"
5806 cat "${te}3"
5807 echo "$TRACE $SOCAT $opts - $arg2"
5808 cat "${te}4"
5809 cat "$tdiff2"
5810 numFAIL=$((numFAIL+1))
5811 listFAIL="$listFAIL $N"
5812 elif [ "X$expect" != 'X*' -a X$result != X$expect ]; then
5813 case X$result in
5814 X-1) $PRINTF "$NO_RESULT (ph.2 client error): $TRACE $SOCAT:\n"
5815 echo "$TRACE $SOCAT $opts $arg echo"
5816 cat "${te}3"
5817 echo "$TRACE $SOCAT $opts - $arg2"
5818 cat "${te}4"
5819 numCANT=$((numCANT+1))
5820 listCANT="$listCANT $N"
5822 X0) $PRINTF "$NO_RESULT (ph.2 diff failed): diff:\n"
5823 echo "$TRACE $SOCAT $opts $arg echo"
5824 cat "${te}3"
5825 echo "$TRACE $SOCAT $opts - $arg2"
5826 cat "${te}4"
5827 cat "$tdiff2"
5828 numCANT=$((numCANT+1))
5829 listCANT="$listCANT $N"
5831 X1) $PRINTF "$FAILED: SECURITY BROKEN\n"
5832 echo "$TRACE $SOCAT $opts $arg echo"
5833 cat "${te}3"
5834 echo "$TRACE $SOCAT $opts - $arg2"
5835 cat "${te}4"
5836 cat "$tdiff2"
5837 numFAIL=$((numFAIL+1))
5838 listFAIL="$listFAIL $N"
5840 X2) $PRINTF "$FAILED: diff:\n"
5841 echo "$TRACE $SOCAT $opts $arg echo"
5842 cat "${te}3"
5843 echo "$TRACE $SOCAT $opts - $arg2"
5844 cat "${te}4"
5845 cat "$tdiff2"
5846 numFAIL=$((numFAIL+1))
5847 listFAIL="$listFAIL $N"
5849 esac
5850 else
5851 $PRINTF "$OK\n"
5852 [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts $arg echo"
5853 [ "$debug" ] && cat ${te}3
5854 [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts - $arg2"
5855 [ "$debug" ] && cat ${te}4
5856 numOK=$((numOK+1))
5858 wait
5859 #set +vx
5863 NAME=TCP4RANGEBITS
5864 case "$TESTS" in
5865 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5866 TEST="$NAME: security of TCP4-L with RANGE option"
5867 if ! eval $NUMCOND; then :;
5868 elif [ -z "$SECONDADDR" ]; then
5869 # we need access to a second addresses
5870 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5871 numCANT=$((numCANT+1))
5872 listCANT="$listCANT $N"
5873 else
5874 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5875 fi ;; # $SECONDADDR, NUMCOND
5876 esac
5877 PORT=$((PORT+1))
5878 N=$((N+1))
5880 NAME=TCP4RANGEMASK
5881 case "$TESTS" in
5882 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5883 TEST="$NAME: security of TCP4-L with RANGE option"
5884 if ! eval $NUMCOND; then :;
5885 elif [ -z "$SECONDADDR" ]; then
5886 # we need access to a second addresses
5887 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5888 numCANT=$((numCANT+1))
5889 listCANT="$listCANT $N"
5890 else
5891 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR:255.255.255.255" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5892 fi ;; # $SECONDADDR, NUMCOND
5893 esac
5894 PORT=$((PORT+1))
5895 N=$((N+1))
5897 # like TCP4RANGEMASK, but the "bad" address is within the same class A network
5898 NAME=TCP4RANGEMASKHAIRY
5899 case "$TESTS" in
5900 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5901 TEST="$NAME: security of TCP4-L with RANGE option"
5902 if ! eval $NUMCOND; then :; else
5903 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=127.0.0.0:255.255.0.0" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
5904 fi ;; # Linux, NUMCOND
5905 esac
5906 PORT=$((PORT+1))
5907 N=$((N+1))
5910 NAME=TCP4SOURCEPORT
5911 case "$TESTS" in
5912 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5913 TEST="$NAME: security of TCP4-L with SOURCEPORT option"
5914 if ! eval $NUMCOND; then :; else
5915 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5916 fi ;; # NUMCOND
5917 esac
5918 PORT=$((PORT+1))
5919 N=$((N+1))
5921 NAME=TCP4LOWPORT
5922 case "$TESTS" in
5923 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5924 TEST="$NAME: security of TCP4-L with LOWPORT option"
5925 if ! eval $NUMCOND; then :; else
5926 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5927 fi ;; # NUMCOND
5928 esac
5929 PORT=$((PORT+1))
5930 N=$((N+1))
5932 NAME=TCP4WRAPPERS_ADDR
5933 case "$TESTS" in
5934 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5935 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5936 if ! eval $NUMCOND; then :;
5937 elif ! feat=$(testfeats tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5938 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5939 numCANT=$((numCANT+1))
5940 listCANT="$listCANT $N"
5941 else
5942 ha="$td/hosts.allow"
5943 hd="$td/hosts.deny"
5944 $ECHO "socat: $SECONDADDR" >"$ha"
5945 $ECHO "ALL: ALL" >"$hd"
5946 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5947 fi ;; # NUMCOND, feats
5948 esac
5949 PORT=$((PORT+1))
5950 N=$((N+1))
5952 NAME=TCP4WRAPPERS_NAME
5953 case "$TESTS" in
5954 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5955 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5956 if ! eval $NUMCOND; then :;
5957 elif ! feat=$(testfeats tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5958 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5959 numCANT=$((numCANT+1))
5960 listCANT="$listCANT $N"
5961 else
5962 ha="$td/hosts.allow"
5963 hd="$td/hosts.deny"
5964 $ECHO "socat: $LOCALHOST" >"$ha"
5965 $ECHO "ALL: ALL" >"$hd"
5966 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
5967 fi ;; # NUMCOND, feats
5968 esac
5969 PORT=$((PORT+1))
5970 N=$((N+1))
5973 NAME=TCP6RANGE
5974 case "$TESTS" in
5975 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5976 TEST="$NAME: security of TCP6-L with RANGE option"
5977 if ! eval $NUMCOND; then :;
5978 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
5979 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5980 numCANT=$((numCANT+1))
5981 listCANT="$listCANT $N"
5982 else
5983 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "range=[::2]/128" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5984 fi ;; # NUMCOND, feats
5985 esac
5986 PORT=$((PORT+1))
5987 N=$((N+1))
5989 NAME=TCP6SOURCEPORT
5990 case "$TESTS" in
5991 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5992 TEST="$NAME: security of TCP6-L with SOURCEPORT option"
5993 if ! eval $NUMCOND; then :;
5994 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
5995 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5996 numCANT=$((numCANT+1))
5997 listCANT="$listCANT $N"
5998 else
5999 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
6000 fi ;; # NUMCOND, feats
6001 esac
6002 PORT=$((PORT+1))
6003 N=$((N+1))
6005 NAME=TCP6LOWPORT
6006 case "$TESTS" in
6007 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
6008 TEST="$NAME: security of TCP6-L with LOWPORT option"
6009 if ! eval $NUMCOND; then :;
6010 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
6011 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6012 numCANT=$((numCANT+1))
6013 listCANT="$listCANT $N"
6014 else
6015 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
6016 fi ;; # NUMCOND, feats
6017 esac
6018 PORT=$((PORT+1))
6019 N=$((N+1))
6021 NAME=TCP6TCPWRAP
6022 case "$TESTS" in
6023 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
6024 TEST="$NAME: security of TCP6-L with TCPWRAP option"
6025 if ! eval $NUMCOND; then :;
6026 elif ! feat=$(testfeats tcp ip6 libwrap && runstcp6); then
6027 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6028 numCANT=$((numCANT+1))
6029 listCANT="$listCANT $N"
6030 else
6031 ha="$td/hosts.allow"
6032 hd="$td/hosts.deny"
6033 $ECHO "socat: [::2]" >"$ha"
6034 $ECHO "ALL: ALL" >"$hd"
6035 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
6036 fi ;; # NUMCOND, feats
6037 esac
6038 PORT=$((PORT+1))
6039 N=$((N+1))
6042 NAME=UDP4RANGE
6043 case "$TESTS" in
6044 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
6045 TEST="$NAME: security of UDP4-L with RANGE option"
6046 if ! eval $NUMCOND; then :; else
6047 #testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
6048 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
6049 fi ;; # NUMCOND
6050 esac
6051 PORT=$((PORT+1))
6052 N=$((N+1))
6054 NAME=UDP4SOURCEPORT
6055 case "$TESTS" in
6056 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
6057 TEST="$NAME: security of UDP4-L with SOURCEPORT option"
6058 if ! eval $NUMCOND; then :; else
6059 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "sp=$PORT" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
6060 fi ;; # NUMCOND
6061 esac
6062 PORT=$((PORT+1))
6063 N=$((N+1))
6065 NAME=UDP4LOWPORT
6066 case "$TESTS" in
6067 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
6068 TEST="$NAME: security of UDP4-L with LOWPORT option"
6069 if ! eval $NUMCOND; then :; else
6070 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "lowport" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
6071 fi ;; # NUMCOND
6072 esac
6073 PORT=$((PORT+1))
6074 N=$((N+1))
6076 NAME=UDP4TCPWRAP
6077 case "$TESTS" in
6078 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
6079 TEST="$NAME: security of UDP4-L with TCPWRAP option"
6080 if ! eval $NUMCOND; then :;
6081 elif ! feat=$(testfeats udp ip4 libwrap) || ! runsip4 >/dev/null; then
6082 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6083 numCANT=$((numCANT+1))
6084 listCANT="$listCANT $N"
6085 else
6086 ha="$td/hosts.allow"
6087 hd="$td/hosts.deny"
6088 $ECHO "socat: $SECONDADDR" >"$ha"
6089 $ECHO "ALL: ALL" >"$hd"
6090 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
6091 fi ;; # NUMCOND, feats
6092 esac
6093 PORT=$((PORT+1))
6094 N=$((N+1))
6097 NAME=UDP6RANGE
6098 case "$TESTS" in
6099 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
6100 TEST="$NAME: security of UDP6-L with RANGE option"
6101 if ! eval $NUMCOND; then :;
6102 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
6103 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6104 numCANT=$((numCANT+1))
6105 listCANT="$listCANT $N"
6106 else
6107 #testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
6108 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
6109 fi ;; # NUMCOND, feats
6110 esac
6111 PORT=$((PORT+1))
6112 N=$((N+1))
6114 NAME=UDP6SOURCEPORT
6115 case "$TESTS" in
6116 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
6117 TEST="$NAME: security of UDP6-L with SOURCEPORT option"
6118 if ! eval $NUMCOND; then :;
6119 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
6120 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
6121 numCANT=$((numCANT+1))
6122 listCANT="$listCANT $N"
6123 else
6124 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "sp=$PORT" "udp6:[::1]:$PORT" 6 udp $PORT 0
6125 fi ;; # NUMCOND, feats
6126 esac
6127 PORT=$((PORT+1))
6128 N=$((N+1))
6130 NAME=UDP6LOWPORT
6131 case "$TESTS" in
6132 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
6133 TEST="$NAME: security of UDP6-L with LOWPORT option"
6134 if ! eval $NUMCOND; then :;
6135 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
6136 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
6137 numCANT=$((numCANT+1))
6138 listCANT="$listCANT $N"
6139 else
6140 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
6141 fi ;; # NUMCOND, feats
6142 esac
6143 PORT=$((PORT+1))
6144 N=$((N+1))
6146 NAME=UDP6TCPWRAP
6147 case "$TESTS" in
6148 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
6149 TEST="$NAME: security of UDP6-L with TCPWRAP option"
6150 if ! eval $NUMCOND; then :;
6151 elif ! feat=$(testfeats tcp ip6 libwrap && runsip6); then
6152 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6153 numCANT=$((numCANT+1))
6154 listCANT="$listCANT $N"
6155 else
6156 ha="$td/hosts.allow"
6157 hd="$td/hosts.deny"
6158 $ECHO "socat: [::2]" >"$ha"
6159 $ECHO "ALL: ALL" >"$hd"
6160 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
6161 fi ;; # NUMCOND, feats
6162 esac
6163 PORT=$((PORT+1))
6164 N=$((N+1))
6166 NAME=OPENSSLTCP4_RANGE
6167 case "$TESTS" in
6168 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%range%*|*%$NAME%*)
6169 TEST="$NAME: security of SSL-L over TCP/IPv4 with RANGE option"
6170 if ! eval $NUMCOND; then :;
6171 elif ! testfeats openssl >/dev/null; then
6172 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6173 numCANT=$((numCANT+1))
6174 listCANT="$listCANT $N"
6175 else
6176 gentestcert testsrv
6177 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "range=$SECONDADDR/32" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
6178 fi ;; # NUMCOND, feats
6179 esac
6180 PORT=$((PORT+1))
6181 N=$((N+1))
6183 NAME=OPENSSLTCP4_SOURCEPORT
6184 case "$TESTS" in
6185 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
6186 TEST="$NAME: security of SSL-L with SOURCEPORT option"
6187 if ! eval $NUMCOND; then :;
6188 elif ! testfeats openssl >/dev/null; then
6189 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6190 numCANT=$((numCANT+1))
6191 listCANT="$listCANT $N"
6192 else
6193 gentestcert testsrv
6194 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "sp=$PORT" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
6195 fi ;; # NUMCOND, feats
6196 esac
6197 PORT=$((PORT+1))
6198 N=$((N+1))
6200 NAME=OPENSSLTCP4_LOWPORT
6201 case "$TESTS" in
6202 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%lowport%*|*%$NAME%*)
6203 TEST="$NAME: security of SSL-L with LOWPORT option"
6204 if ! eval $NUMCOND; then :;
6205 elif ! testfeats openssl >/dev/null; then
6206 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6207 numCANT=$((numCANT+1))
6208 listCANT="$listCANT $N"
6209 else
6210 gentestcert testsrv
6211 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "lowport" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
6212 fi ;; # NUMCOND, feats
6213 esac
6214 PORT=$((PORT+1))
6215 N=$((N+1))
6217 NAME=OPENSSLTCP4_TCPWRAP
6218 case "$TESTS" in
6219 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
6220 TEST="$NAME: security of SSL-L with TCPWRAP option"
6221 if ! eval $NUMCOND; then :;
6222 elif ! feat=$(testfeats ip4 tcp libwrap openssl); then
6223 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6224 numCANT=$((numCANT+1))
6225 listCANT="$listCANT $N"
6226 else
6227 gentestcert testsrv
6228 ha="$td/hosts.allow"
6229 hd="$td/hosts.deny"
6230 $ECHO "socat: $SECONDADDR" >"$ha"
6231 $ECHO "ALL: ALL" >"$hd"
6232 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "tcpwrap-etc=$td" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
6233 fi ;; # NUMCOND, feats
6234 esac
6235 PORT=$((PORT+1))
6236 N=$((N+1))
6238 NAME=OPENSSLCERTSERVER
6239 case "$TESTS" in
6240 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
6241 TEST="$NAME: security of SSL-L with client certificate"
6242 if ! eval $NUMCOND; then :;
6243 elif ! testfeats openssl >/dev/null; then
6244 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6245 numCANT=$((numCANT+1))
6246 listCANT="$listCANT $N"
6247 else
6248 gentestcert testsrv
6249 gentestcert testcli
6250 testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify,cert=testsrv.crt,key=testsrv.key" "cafile=testcli.crt" "cafile=testsrv.crt" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,cert=testcli.pem,$SOCAT_EGD" 4 tcp $PORT '*'
6251 fi ;; # NUMCOND, feats
6252 esac
6253 PORT=$((PORT+1))
6254 N=$((N+1))
6256 NAME=OPENSSLCERTCLIENT
6257 case "$TESTS" in
6258 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
6259 TEST="$NAME: security of SSL with server certificate"
6260 if ! eval $NUMCOND; then :;
6261 elif ! testfeats openssl >/dev/null; then
6262 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6263 numCANT=$((numCANT+1))
6264 listCANT="$listCANT $N"
6265 else
6266 gentestcert testsrv
6267 gentestcert testcli
6268 testserversec "$N" "$TEST" "$opts -t 0.5 -lu -d" "ssl:$LOCALHOST:$PORT,pf=ip4,fork,retry=2,verify,cert=testcli.pem,$SOCAT_EGD" "cafile=testsrv.crt" "cafile=testcli.crt" "ssl-l:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cafile=testcli.crt,cert=testsrv.crt,key=testsrv.key" 4 tcp "" -1
6269 fi ;; # NUMCOND, feats
6270 esac
6271 PORT=$((PORT+1))
6272 N=$((N+1))
6275 NAME=OPENSSLTCP6_RANGE
6276 case "$TESTS" in
6277 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%range%*|*%$NAME%*)
6278 TEST="$NAME: security of SSL-L over TCP/IPv6 with RANGE option"
6279 if ! eval $NUMCOND; then :;
6280 elif ! testfeats openssl >/dev/null; then
6281 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6282 numCANT=$((numCANT+1))
6283 listCANT="$listCANT $N"
6284 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
6285 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6286 numCANT=$((numCANT+1))
6287 listCANT="$listCANT $N"
6288 else
6289 gentestcert6 testsrv6
6290 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "range=[::2]/128" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
6291 fi ;; # NUMCOND, feats
6292 esac
6293 PORT=$((PORT+1))
6294 N=$((N+1))
6296 NAME=OPENSSLTCP6_SOURCEPORT
6297 case "$TESTS" in
6298 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
6299 TEST="$NAME: security of SSL-L over TCP/IPv6 with SOURCEPORT option"
6300 if ! eval $NUMCOND; then :;
6301 elif ! testfeats openssl >/dev/null; then
6302 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6303 numCANT=$((numCANT+1))
6304 listCANT="$listCANT $N"
6305 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
6306 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6307 numCANT=$((numCANT+1))
6308 listCANT="$listCANT $N"
6309 else
6310 gentestcert6 testsrv6
6311 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "sp=$PORT" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
6312 fi ;; # NUMCOND, feats
6313 esac
6314 PORT=$((PORT+1))
6315 N=$((N+1))
6317 NAME=OPENSSLTCP6_LOWPORT
6318 case "$TESTS" in
6319 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%lowport%*|*%$NAME%*)
6320 TEST="$NAME: security of SSL-L over TCP/IPv6 with LOWPORT option"
6321 if ! eval $NUMCOND; then :;
6322 elif ! testfeats openssl >/dev/null; then
6323 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6324 numCANT=$((numCANT+1))
6325 listCANT="$listCANT $N"
6326 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
6327 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6328 numCANT=$((numCANT+1))
6329 listCANT="$listCANT $N"
6330 else
6331 gentestcert6 testsrv6
6332 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "lowport" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
6333 fi ;; # NUMCOND, feats
6334 esac
6335 PORT=$((PORT+1))
6336 N=$((N+1))
6338 NAME=OPENSSLTCP6_TCPWRAP
6339 case "$TESTS" in
6340 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
6341 TEST="$NAME: security of SSL-L over TCP/IPv6 with TCPWRAP option"
6342 if ! eval $NUMCOND; then :;
6343 elif ! feat=$(testfeats ip6 tcp libwrap openssl && runsip6); then
6344 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6345 numCANT=$((numCANT+1))
6346 listCANT="$listCANT $N"
6347 else
6348 gentestcert6 testsrv6
6349 ha="$td/hosts.allow"
6350 hd="$td/hosts.deny"
6351 $ECHO "socat: [::2]" >"$ha"
6352 $ECHO "ALL: ALL" >"$hd"
6353 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "tcpwrap-etc=$td" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
6354 fi ;; # NUMCOND, feats
6355 esac
6356 PORT=$((PORT+1))
6357 N=$((N+1))
6360 # test security with the openssl-commonname option on client side
6361 NAME=OPENSSL_CN_CLIENT_SECURITY
6362 case "$TESTS" in
6363 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6364 TEST="$NAME: security of client openssl-commonname option"
6365 # connect using non matching server name/address with commonname
6366 # options, this should succeed. Then without this option, should fail
6367 if ! eval $NUMCOND; then :;
6368 elif ! testfeats openssl >/dev/null; then
6369 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6370 numCANT=$((numCANT+1))
6371 listCANT="$listCANT $N"
6372 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6373 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6374 numCANT=$((numCANT+1))
6375 listCANT="$listCANT $N"
6376 else
6377 gentestcert testsrv
6378 gentestcert testcli
6379 testserversec "$N" "$TEST" "$opts -t 0.5 -4" "SSL:127.0.0.1:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "commonname=$LOCALHOST" "" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0" 4 tcp "" '*'
6380 fi ;; # testfeats, NUMCOND
6381 esac
6382 PORT=$((PORT+1))
6383 N=$((N+1))
6385 # test security with the openssl-commonname option on server side
6386 NAME=OPENSSL_CN_SERVER_SECURITY
6387 case "$TESTS" in
6388 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6389 TEST="$NAME: security of server openssl-commonname option"
6390 # connect using with client certificate to server, this should succeed.
6391 # Then use the server with a non matching openssl-commonname option,
6392 # this must fail
6393 if ! eval $NUMCOND; then :;
6394 elif ! testfeats openssl >/dev/null; then
6395 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6396 numCANT=$((numCANT+1))
6397 listCANT="$listCANT $N"
6398 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6399 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6400 numCANT=$((numCANT+1))
6401 listCANT="$listCANT $N"
6402 else
6403 gentestcert testsrv
6404 gentestcert testcli
6405 testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt" "" "commonname=onlyyou" "SSL:$LOCALHOST:$PORT,$REUSEADDR,verify=0,cafile=testsrv.crt,cert=testcli.crt,key=testcli.key" 4 tcp "$PORT" '*'
6406 fi ;; # testfeats, NUMCOND
6407 esac
6408 PORT=$((PORT+1))
6409 N=$((N+1))
6412 NAME=OPENSSL_FIPS_SECURITY
6413 case "$TESTS" in
6414 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6415 TEST="$NAME: OpenSSL restrictions by FIPS"
6416 if ! eval $NUMCOND; then :;
6417 elif ! testfeats openssl >/dev/null; then
6418 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6419 numCANT=$((numCANT+1))
6420 listCANT="$listCANT $N"
6421 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6422 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6423 numCANT=$((numCANT+1))
6424 listCANT="$listCANT $N"
6425 elif ! testoptions fips >/dev/null; then
6426 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
6427 numCANT=$((numCANT+1))
6428 listCANT="$listCANT $N"
6429 else
6430 gentestcert testsrv
6431 gentestcert testcli
6432 # openssl client accepts a "normal" certificate only when not in fips mode
6433 testserversec "$N" "$TEST" "$opts" "ssl:$LOCALHOST:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "" "fips" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key" 4 tcp "" -1
6434 fi ;; # testfeats, NUMCOND
6435 esac
6436 PORT=$((PORT+1))
6437 N=$((N+1))
6440 NAME=UNIEXECEOF
6441 case "$TESTS" in
6442 *%$N%*|*%functions%*|*%$NAME%*)
6443 TEST="$NAME: give exec'd write-only process a chance to flush (-u)"
6444 testod "$N" "$TEST" "" exec:"$OD_C" "$opts -u"
6445 esac
6446 N=$((N+1))
6449 NAME=REVEXECEOF
6450 case "$TESTS" in
6451 *%$N%*|*%functions%*|*%$NAME%*)
6452 TEST="$NAME: give exec'd write-only process a chance to flush (-U)"
6453 testod "$N" "$TEST" exec:"$OD_C" "-" "$opts -U"
6454 esac
6455 N=$((N+1))
6458 NAME=FILANDIR
6459 case "$TESTS" in
6460 *%$N%*|*%filan%*|*%$NAME%*)
6461 TEST="$NAME: check type printed for directories"
6462 if ! eval $NUMCOND; then :; else
6463 te="$td/test$N.stderr"
6464 printf "test $F_n $TEST... " $N
6465 type=$($FILAN -f . 2>$te |tail -n 1 |awk '{print($2);}')
6466 if [ "$type" = "dir" ]; then
6467 $PRINTF "$OK\n"
6468 numOK=$((numOK+1))
6469 else
6470 $PRINTF "$FAILED\n"
6471 cat "$te"
6472 numFAIL=$((numFAIL+1))
6473 listFAIL="$listFAIL $N"
6475 fi ;; # NUMCOND
6476 esac
6477 N=$((N+1))
6480 NAME=FILANSOCKET
6481 case "$TESTS" in
6482 *%$N%*|*%filan%*|*%$NAME%*)
6483 TEST="$NAME: capability to analyze named unix socket"
6484 if ! eval $NUMCOND; then :; else
6485 ts="$td/test$N.socket"
6486 te1="$td/test$N.stderr1" # socat
6487 te2="$td/test$N.stderr2" # filan
6488 printf "test $F_n $TEST... " $N
6489 $TRACE $SOCAT $opts UNIX-LISTEN:"$ts" /dev/null </dev/null 2>"$te1" &
6490 spid=$!
6491 waitfile "$ts" 1
6492 type=$($FILAN -f "$ts" 2>$te2 |tail -n 1 |awk '{print($2);}')
6493 if [ "$type" = "socket" ]; then
6494 $PRINTF "$OK\n"
6495 numOK=$((numOK+1))
6496 else
6497 $PRINTF "$FAILED\n"
6498 cat "$te1"
6499 cat "$te2"
6500 numFAIL=$((numFAIL+1))
6501 listFAIL="$listFAIL $N"
6503 kill $spid 2>/dev/null
6504 wait
6505 fi ;; # NUMCOND
6506 esac
6507 N=$((N+1))
6510 testptywaitslave () {
6511 local N="$1"
6512 local TEST="$2"
6513 local PTYTYPE="$3" # ptmx or openpty
6514 local opts="$4"
6516 local tp="$td/test$N.pty"
6517 local ts="$td/test$N.socket"
6518 local tf="$td/test$N.file"
6519 local tdiff="$td/test$N.diff"
6520 local te1="$td/test$N.stderr1"
6521 local te2="$td/test$N.stderr2"
6522 local te3="$td/test$N.stderr3"
6523 local te4="$td/test$N.stderr4"
6524 local da="test$N $(date) $RANDOM"
6525 printf "test $F_n $TEST... " $N
6526 # first generate a pty, then a socket
6527 ($TRACE $SOCAT $opts -lpsocat1 pty,$PTYTYPE,pty-wait-slave,link="$tp" unix-listen:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev/null &
6528 pid=$!
6529 waitfile "$tp"
6530 # if pty was non-blocking, the socket is active, and socat1 will term
6531 $TRACE $SOCAT $opts -T 10 -lpsocat2 file:/dev/null unix-connect:"$ts" 2>"$te2"
6532 # if pty is blocking, first socat is still active and we get a connection now
6533 #((echo "$da"; sleep 2) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6534 ( (waitfile "$ts"; echo "$da"; sleep 1) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6535 waitfile "$ts"
6536 # but we need an echoer on the socket
6537 $TRACE $SOCAT $opts -lpsocat4 unix:"$ts" echo 2>"$te4"
6538 # now $tf file should contain $da
6539 #kill $pid 2>/dev/null
6540 wait
6542 if echo "$da" |diff - "$tf"> "$tdiff"; then
6543 $PRINTF "$OK\n"
6544 numOK=$((numOK+1))
6545 else
6546 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
6547 cat "$te1"
6548 #cat "$te2" # not of interest
6549 cat "$te3"
6550 cat "$te4"
6551 cat "$tdiff"
6552 numCANT=$((numCANT+1))
6553 listCANT="$listCANT $N"
6557 NAME=PTMXWAITSLAVE
6558 PTYTYPE=ptmx
6559 case "$TESTS" in
6560 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6561 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6562 if ! eval $NUMCOND; then :; else
6563 if ! feat=$(testfeats pty); then
6564 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6565 numCANT=$((numCANT+1))
6566 listCANT="$listCANT $N"
6567 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6568 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6569 numCANT=$((numCANT+1))
6570 listCANT="$listCANT $N"
6571 else
6572 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6574 fi ;; # NUMCOND
6575 esac
6576 N=$((N+1))
6578 NAME=OPENPTYWAITSLAVE
6579 PTYTYPE=openpty
6580 case "$TESTS" in
6581 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6582 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6583 if ! eval $NUMCOND; then :;
6584 elif ! feat=$(testfeats pty); then
6585 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6586 numCANT=$((numCANT+1))
6587 listCANT="$listCANT $N"
6588 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6589 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6590 numCANT=$((numCANT+1))
6591 listCANT="$listCANT $N"
6592 else
6593 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6594 fi ;; # NUMCOND, feats
6595 esac
6596 N=$((N+1))
6599 # Test the connect-timeout address option
6600 NAME=CONNECTTIMEOUT
6601 case "$TESTS" in
6602 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6603 TEST="$NAME: test the connect-timeout option"
6604 if ! eval $NUMCOND; then :;
6605 elif ! feat=$(testfeats tcp); then
6606 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6607 numCANT=$((numCANT+1))
6608 listCANT="$listCANT $N"
6609 elif ! feat=$(testoptions connect-timeout); then
6610 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6611 numCANT=$((numCANT+1))
6612 listCANT="$listCANT $N"
6613 else
6614 # we need a hanging connection attempt, guess an address for this
6615 case "$UNAME" in
6616 Linux) HANGIP=1.0.0.1 ;;
6617 *) HANGIP=255.255.255.254 ;;
6618 esac
6619 te1="$td/test$N.stderr1"
6620 tk1="$td/test$N.kill1"
6621 te2="$td/test$N.stderr2"
6622 tk2="$td/test$N.kill2"
6623 $PRINTF "test $F_n $TEST... " $N
6624 # first, try to make socat hang and see if it can be killed
6625 #$TRACE $SOCAT $opts - tcp:$HANGIP:1 >"$te1" 2>&1 </dev/null &
6626 CMD="$TRACE $SOCAT $opts - tcp:$HANGIP:1"
6627 $CMD >"$te1" 2>&1 </dev/null &
6628 pid1=$!
6629 sleep 2
6630 if ! kill $pid1 2>"$tk1"; then
6631 $PRINTF "${YELLOW}does not hang${NORMAL}\n"
6632 numCANT=$((numCANT+1))
6633 listCANT="$listCANT $N"
6634 else
6635 # second, set connect-timeout and see if socat exits before kill
6636 $TRACE $SOCAT $opts - tcp:$HANGIP:1,connect-timeout=1.0 >"$te2" 2>&1 </dev/null &
6637 pid2=$!
6638 sleep 2
6639 if kill $pid2 2>"$tk2"; then
6640 $PRINTF "$FAILED\n"
6641 echo "$CMD"
6642 cat "$te1"
6643 cat "$te2"
6644 numFAIL=$((numFAIL+1))
6645 listFAIL="$listFAIL $N"
6646 else
6647 $PRINTF "$OK\n"
6648 numOK=$((numOK+1))
6651 wait
6652 fi ;; # testfeats, NUMCOND
6653 esac
6654 N=$((N+1))
6657 # version 1.7.0.0 had a bug with the connect-timeout option: while it correctly
6658 # terminated a hanging connect attempt, it prevented a successful connection
6659 # establishment from being recognized by socat, instead the timeout occurred
6660 NAME=CONNECTTIMEOUT_CONN
6661 if ! eval $NUMCOND; then :; else
6662 case "$TESTS" in
6663 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6664 TEST="$NAME: TCP4 connect-timeout option when server replies"
6665 # just try a connection that is expected to succeed with the usual data
6666 # transfer; with the bug it will fail
6667 tf="$td/test$N.stdout"
6668 te="$td/test$N.stderr"
6669 tdiff="$td/test$N.diff"
6670 tsl=$PORT
6671 ts="127.0.0.1:$tsl"
6672 da="test$N $(date) $RANDOM"
6673 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
6674 CMD2="$TRACE $SOCAT $opts STDIO TCP4:$ts,connect-timeout=1"
6675 printf "test $F_n $TEST... " $N
6676 $CMD1 >"$tf" 2>"${te}1" &
6677 pid1=$!
6678 waittcp4port $tsl 1
6679 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6680 if [ $? -ne 0 ]; then
6681 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6682 echo "$CMD1 &"
6683 cat "${te}1"
6684 echo "$CMD2"
6685 cat "${te}2"
6686 numFAIL=$((numFAIL+1))
6687 listFAIL="$listFAIL $N"
6688 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6689 $PRINTF "$FAILED\n"
6690 cat "$tdiff"
6691 numFAIL=$((numFAIL+1))
6692 listFAIL="$listFAIL $N"
6693 else
6694 $PRINTF "$OK\n"
6695 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
6696 numOK=$((numOK+1))
6698 kill $pid1 2>/dev/null
6699 wait ;;
6700 esac
6701 PORT=$((PORT+1))
6702 fi # NUMCOND
6703 N=$((N+1))
6706 NAME=OPENSSLLISTENDSA
6707 case "$TESTS" in
6708 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
6709 TEST="$NAME: openssl listen with DSA certificate"
6710 if ! eval $NUMCOND; then :;
6711 elif ! testfeats openssl >/dev/null; then
6712 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6713 numCANT=$((numCANT+1))
6714 listCANT="$listCANT $N"
6715 else
6716 SRVCERT=testsrvdsa
6717 gentestdsacert $SRVCERT
6718 tf="$td/test$N.stdout"
6719 te="$td/test$N.stderr"
6720 tdiff="$td/test$N.diff"
6721 da="test$N $(date) $RANDOM"
6722 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe"
6723 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
6724 $PRINTF "test $F_n $TEST... " $N
6725 eval "$CMD2 2>\"${te}1\" &"
6726 pid=$! # background process id
6727 waittcp4port $PORT
6728 echo "$da" |$CMD >$tf 2>"${te}2"
6729 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
6730 $PRINTF "$FAILED\n"
6731 echo "$CMD2 &"
6732 echo "$CMD"
6733 cat "${te}1"
6734 cat "${te}2"
6735 cat "$tdiff"
6736 numFAIL=$((numFAIL+1))
6737 listFAIL="$listFAIL $N"
6738 else
6739 $PRINTF "$OK\n"
6740 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
6741 numOK=$((numOK+1))
6743 kill $pid 2>/dev/null
6744 wait
6745 fi ;; # testfeats, NUMCOND
6746 esac
6747 PORT=$((PORT+1))
6748 N=$((N+1))
6751 # derive signal number from signal name
6752 # kill -l should provide the info
6753 signum () {
6754 if [ ! "$BASH_VERSION" -o -o posix ]; then
6755 # we expect:
6756 for i in $(POSIXLY_CORRECT=1 kill -l); do echo "$i"; done |grep -n -i "^$1$" |cut -d: -f1
6757 else
6758 # expect:
6759 # " 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL"
6760 signam="$1"
6761 kill -l </dev/null |
6762 while read l; do printf "%s %s\n%s %s\n%s %s\n%s %s\n" $l; done |
6763 grep -e "SIG$signam\$" |
6764 cut -d ')' -f 1
6768 # problems with QUIT, INT (are blocked in system() )
6769 for signam in TERM ILL; do
6770 NAME=EXITCODESIG$signam
6771 case "$TESTS" in
6772 *%$N%*|*%functions%*|*%pty%*|*%signal%*|*%$NAME%*)
6773 TEST="$NAME: exit status when dying on SIG$signam"
6774 if ! eval $NUMCOND; then :;
6775 elif ! feat=$(testfeats pty); then
6776 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
6777 numCANT=$((numCANT+1))
6778 listCANT="$listCANT $N"
6779 else
6780 SIG="$(signum $signam)"
6781 te="$td/test$N.stderr"
6782 tpp="$td/test$N.ppid"
6783 tp="$td/test$N.pid"
6784 $PRINTF "test $F_n $TEST... " $N
6785 (sleep 1; kill -"$SIG" "$(cat "$tpp")") &
6786 # a simple "system:echo $PPID..." does not work on NetBSD, OpenBSD
6787 #$TRACE $SOCAT $opts echo SYSTEM:'exec /usr/bin/env bash -c "echo \$PPID '">$tpp"'; echo \$$ '">$tp; read x\"",nofork 2>"$te"; stat=$?
6788 tsh="$td/test$N.sh"
6789 cat <<EOF >"$tsh"
6790 #! /usr/bin/env bash
6791 echo \$PPID >"$tpp"
6792 echo \$\$ >"$tp"
6793 read x
6795 chmod a+x "$tsh"
6796 #$TRACE $SOCAT $opts echo SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"; stat=$?
6797 CMD="$TRACE $SOCAT $opts ECHO SYSTEM:\"exec\\\ \\\"$tsh\\\"\",pty,setsid,nofork"
6798 $TRACE $SOCAT $opts ECHO SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"
6799 stat=$?
6800 sleep 1; kill -INT $(cat $tp)
6801 wait
6802 if [ "$stat" -eq $((128+$SIG)) ]; then
6803 $PRINTF "$OK\n"
6804 numOK=$((numOK+1))
6805 else
6806 $PRINTF "$FAILED\n"
6807 echo "$CMD"
6808 cat "$te"
6809 numFAIL=$((numFAIL+1))
6810 listFAIL="$listFAIL $N"
6812 wait
6813 fi ;; # NUMCOND, feats
6814 esac
6815 N=$((N+1))
6816 done
6819 NAME=READBYTES
6820 #set -vx
6821 case "$TESTS" in
6822 *%$N%*|*%functions%*|*%$NAME%*)
6823 TEST="$NAME: restrict reading from file with bytes option"
6824 if ! eval $NUMCOND; then :;
6825 elif false; then
6826 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6827 numCANT=$((numCANT+1))
6828 listCANT="$listCANT $N"
6829 else
6830 tr="$td/test$N.ref"
6831 ti="$td/test$N.in"
6832 to="$td/test$N.out"
6833 te="$td/test$N.err"
6834 tdiff="$td/test$N.diff"
6835 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
6836 # the feature that we really want to test is in the readline.sh script:
6837 CMD="$TRACE $SOCAT $opts -u open:$ti,readbytes=100 -"
6838 printf "test $F_n $TEST... " $N
6839 rm -f "$tf" "$ti" "$to"
6841 echo "AAAAAAAAAAAAAAAAAAAAAAAA
6842 AAAAAAAAAAAAAAAAAAAAAAAA
6843 AAAAAAAAAAAAAAAAAAAAAAAA
6844 AAAAAAAAAAAAAAAAAAAAAAAA" >"$tr" # 100 bytes
6845 cat "$tr" "$tr" >"$ti" # 200 bytes
6846 $CMD >"$to" 2>"$te"
6847 if ! diff "$tr" "$to" >"$tdiff" 2>&1; then
6848 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6849 echo "$CMD"
6850 cat "$te"
6851 cat "$tdiff"
6852 numFAIL=$((numFAIL+1))
6853 listFAIL="$listFAIL $N"
6854 else
6855 $PRINTF "$OK\n"
6856 if [ -n "$debug" ]; then cat $te; fi
6857 numOK=$((numOK+1))
6859 fi ;; # NUMCOND, feats
6860 esac
6861 N=$((N+1))
6864 NAME=UDPLISTENFORK
6865 case "$TESTS" in
6866 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%listen%*|*%fork%*|*%$NAME%*)
6867 TEST="$NAME: UDP socket rebinds after first connection"
6868 if ! eval $NUMCOND; then :; else
6869 tf="$td/test$N.stdout"
6870 te="$td/test$N.stderr"
6871 tdiff="$td/test$N.diff"
6872 da1="test$N $(date) $RANDOM"
6873 da2="test$N $(date) $RANDOM"
6874 #establish a listening and forking udp socket in background
6875 #processes hang forever without -T
6876 SRV="$TRACE $SOCAT -T 5 $opts -lpserver UDP4-LISTEN:$PORT,bind=$LOCALHOST,$REUSEADDR,fork PIPE"
6877 #make a first and a second connection
6878 CLI="$TRACE $SOCAT $opts -lpclient - UDP4-CONNECT:$LOCALHOST:$PORT"
6879 $PRINTF "test $F_n $TEST... " $N
6880 eval "$SRV 2>${te}s &"
6881 pids=$!
6882 waitudp4port "$PORT"
6883 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6884 if [ $? -ne 0 ]; then
6885 kill "$pids" 2>/dev/null
6886 $PRINTF "$NO_RESULT (first conn failed):\n"
6887 echo "$SRV &"
6888 echo "$CLI"
6889 cat "${te}s" "${te}1"
6890 numCANT=$((numCANT+1))
6891 listCANT="$listCANT $N"
6892 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6893 kill "$pids" 2>/dev/null
6894 $PRINTF "$NO_RESULT (first conn failed); diff:\n"
6895 cat "$tdiff"
6896 numCANT=$((numCANT+1))
6897 listCANT="$listCANT $N"
6898 else
6899 sleep 2 # UDP-LISTEN sleeps 1s
6900 echo "$da2" |eval "$CLI" >"${tf}2" 2>"${te}2"
6901 rc="$?"; kill "$pids" 2>/dev/null
6902 if [ $rc -ne 0 ]; then
6903 $PRINTF "$FAILED:\n"
6904 echo "$SRV &"
6905 cat "${te}s"
6906 echo "$CLI"
6907 cat "${te}2"
6908 numFAIL=$((numFAIL+1))
6909 listFAIL="$listFAIL $N"
6910 elif ! echo "$da2" |diff - "${tf}2" >"$tdiff"; then
6911 $PRINTF "$FAILED: diff\n"
6912 cat "$tdiff"
6913 numFAIL=$((numFAIL+1))
6914 listFAIL="$listFAIL $N"
6915 else
6916 $PRINTF "$OK\n"
6917 numOK=$((numOK+1))
6918 fi # !( $? -ne 0)
6919 fi # !(rc -ne 0)
6920 wait
6921 fi ;; # NUMCOND, feats
6922 esac
6923 PORT=$((PORT+1))
6924 N=$((N+1))
6927 # Is a listen address capable of forking two child processes and have both
6928 # active?
6929 while read PROTOV MAJADDR MINADDR; do
6930 if [ -z "$PROTOV" ] || [[ "$PROTOV" == \#* ]]; then continue; fi
6931 protov="$(echo "$PROTOV" |tr A-Z a-z)"
6932 proto="${protov%%[0-9]}"
6933 NAME=${PROTOV}LISTENFORK
6934 case "$TESTS" in
6935 *%$N%*|*%functions%*|*%$protov%*|*%$proto%*|*%listen%*|*%fork%*|*%$NAME%*)
6936 TEST="$NAME: $PROTOV listen handles 2 concurrent connections"
6937 # Have a listening address with fork option. connect with client1, send a piece
6938 # of data, wait 1s, connect with client2, send another piece of data, wait 1s,
6939 # and send another piece of data with client1. The server processes append all
6940 # data to the same file. Check all data are written to the file in correct
6941 # order.
6942 if ! eval $NUMCOND; then :;
6943 #elif ! feat=$(testfeats $PROTOV); then
6944 # $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$PROTOV" |tr a-z A-Z) not available${NORMAL}\n" $N
6945 # numCANT=$((numCANT+1))
6946 elif ! runs$protov >/dev/null; then
6947 $PRINTF "test $F_n $TEST... ${YELLOW}$PROTOV not available${NORMAL}\n" $N
6948 numCANT=$((numCANT+1))
6949 listCANT="$listCANT $N"
6950 else
6951 ts="$td/test$N.sock"
6952 tref="$td/test$N.ref"
6953 tf="$td/test$N.stdout"
6954 te="$td/test$N.stderr"
6955 tdiff="$td/test$N.diff"
6956 da1a="test$N $(date) 1a $RANDOM"
6957 da1b="test$N $(date) 1b $RANDOM"
6958 da2="test$N $(date) 2 $RANDOM"
6959 case "$MAJADDR" in
6960 "FILE")
6961 tla="$ts"
6962 tca="$ts"
6963 waitproto="file"
6964 waitfor="$ts" ;;
6965 esac
6966 case "$MINADDR" in
6967 "PORT")
6968 tla="$PORT,bind=$MAJADDR"
6969 tca="$MAJADDR:$PORT"
6970 waitproto="${protov}port"
6971 waitfor="$PORT" ;;
6972 esac
6973 #set -xv
6974 echo -e "$da1a\n$da2\n$da1b" >"$tref"
6975 # establish a listening and forking listen socket in background
6976 # UDP processes hang forever without -T
6977 CMD0="$TRACE $SOCAT -T 5 $opts -lpserver $PROTOV-LISTEN:$tla,$REUSEADDR,fork PIPE"
6978 # make a first and a second connection
6979 CMD1="$TRACE $SOCAT $opts -lpclient - $PROTOV-CONNECT:$tca"
6980 $PRINTF "test $F_n $TEST... " $N
6981 eval "$CMD0 2>${te}0 &"
6982 pid0=$!
6983 wait$waitproto "$waitfor" 1 2
6984 (echo "$da1a"; sleep 2; echo "$da1b") |eval "$CMD1" >>"${tf}" 2>"${te}1" &
6985 sleep 1
6986 # trailing sleep req for sctp because no half close
6987 (echo "$da2"; sleep 1) |eval "$CMD1" >>"${tf}" 2>"${te}2" &
6988 sleep 2
6989 kill $pid0 2>/dev/null
6990 wait
6991 if ! diff "$tref" "$tf" >"$tdiff"; then
6992 $PRINTF "$FAILED\n"
6993 cat "${te}0" "${te}1" "${te}2"
6994 cat "$tdiff"
6995 numFAIL=$((numFAIL+1))
6996 listFAIL="$listFAIL $N"
6997 else
6998 $PRINTF "$OK\n"
6999 numOK=$((numOK+1))
7000 fi # !(rc -ne 0)
7001 wait
7002 fi ;; # NUMCOND, feats
7003 esac
7004 PORT=$((PORT+1))
7005 N=$((N+1))
7006 done <<<"
7007 TCP4 $LOCALHOST PORT
7008 TCP6 $LOCALHOST6 PORT
7009 UDP4 $LOCALHOST PORT
7010 UDP6 $LOCALHOST6 PORT
7011 SCTP4 $LOCALHOST PORT
7012 SCTP6 $LOCALHOST6 PORT
7013 UNIX FILE ,
7017 NAME=UNIXTOSTREAM
7018 case "$TESTS" in
7019 *%$N%*|*%functions%*|*%unix%*|*%listen%*|*%$NAME%*)
7020 TEST="$NAME: generic UNIX client connects to stream socket"
7021 if ! eval $NUMCOND; then :; else
7022 ts="$td/test$N.socket"
7023 tf="$td/test$N.stdout"
7024 te="$td/test$N.stderr"
7025 tdiff="$td/test$N.diff"
7026 da1="test$N $(date) $RANDOM"
7027 #establish a listening unix socket in background
7028 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
7029 #make a connection
7030 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts\""
7031 $PRINTF "test $F_n $TEST... " $N
7032 eval "$SRV 2>${te}s &"
7033 pids=$!
7034 waitfile "$ts"
7035 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
7036 if [ $? -ne 0 ]; then
7037 kill "$pids" 2>/dev/null
7038 $PRINTF "$FAILED:\n"
7039 echo "$SRV &"
7040 echo "$CLI"
7041 cat "${te}s" "${te}1"
7042 numFAIL=$((numFAIL+1))
7043 listFAIL="$listFAIL $N"
7044 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
7045 kill "$pids" 2>/dev/null
7046 $PRINTF "$FAILED; diff:\n"
7047 cat "$tdiff"
7048 numFAIL=$((numFAIL+1))
7049 listFAIL="$listFAIL $N"
7050 else
7051 $PRINTF "$OK\n"
7052 numOK=$((numOK+1))
7053 fi # !(rc -ne 0)
7054 wait
7055 fi ;; # NUMCOND
7056 esac
7057 N=$((N+1))
7060 NAME=UNIXTODGRAM
7061 case "$TESTS" in
7062 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%recv%*|*%$NAME%*)
7063 TEST="$NAME: generic UNIX client connects to datagram socket"
7064 if ! eval $NUMCOND; then :; else
7065 ts1="$td/test$N.socket1"
7066 ts2="$td/test$N.socket2"
7067 tf="$td/test$N.stdout"
7068 te="$td/test$N.stderr"
7069 tdiff="$td/test$N.diff"
7070 da1="test$N $(date) $RANDOM"
7071 #establish a receiving unix datagram socket in background
7072 SRV="$TRACE $SOCAT $opts -lpserver UNIX-RECVFROM:\"$ts1\" PIPE"
7073 #make a connection
7074 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\",bind=\"$ts2\""
7075 #CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\""
7076 $PRINTF "test $F_n $TEST... " $N
7077 eval "$SRV 2>${te}s &"
7078 pids=$!
7079 waitfile "$ts1"
7080 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
7081 rc=$?
7082 wait
7083 if [ $rc -ne 0 ]; then
7084 kill "$pids" 2>/dev/null
7085 $PRINTF "$FAILED:\n"
7086 echo "$SRV &"
7087 cat "${te}s"
7088 echo "$CLI"
7089 cat "${te}1" "${te}1"
7090 numFAIL=$((numFAIL+1))
7091 listFAIL="$listFAIL $N"
7092 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
7093 kill "$pids" 2>/dev/null
7094 $PRINTF "$FAILED:\n"
7095 echo "$SRV &"
7096 cat "${te}s"
7097 echo "$CLI"
7098 cat "${te}1"
7099 cat "$tdiff"
7100 numFAIL=$((numFAIL+1))
7101 listFAIL="$listFAIL $N"
7102 else
7103 $PRINTF "$OK\n"
7104 numOK=$((numOK+1))
7105 fi # !(rc -ne 0)
7106 fi ;; # NUMCOND
7107 esac
7108 N=$((N+1))
7111 # there was an error in address EXEC with options pipes,stderr
7112 NAME=EXECPIPESSTDERR
7113 case "$TESTS" in
7114 *%$N%*|*%functions%*|*%$NAME%*)
7115 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
7116 # this test is known to fail when logging is enabled with OPTS/opts env var.
7117 SAVE_opts="$opts"
7118 opts="$(echo "$opts" |sed 's/-d//g')"
7119 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
7120 opts="$SAVE_opts"
7121 esac
7122 N=$((N+1))
7124 # EXEC and SYSTEM with stderr injected socat messages into the data stream.
7125 NAME=EXECSTDERRLOG
7126 case "$TESTS" in
7127 *%$N%*|*%functions%*|*%$NAME%*)
7128 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
7129 SAVE_opts="$opts"
7130 # make sure at least two -d are there
7131 case "$opts" in
7132 *-d*-d*) ;;
7133 *-d*) opts="$opts -d" ;;
7134 *) opts="-d -d" ;;
7135 esac
7136 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
7137 opts="$SAVE_opts"
7138 esac
7139 N=$((N+1))
7142 NAME=SIMPLEPARSE
7143 case "$TESTS" in
7144 *%$N%*|*%functions%*|*%PARSE%*|*%$NAME%*)
7145 TEST="$NAME: invoke socat from socat"
7146 testecho "$N" "$TEST" "" exec:"$SOCAT - exec\:$CAT,pipes" "$opts"
7147 esac
7148 N=$((N+1))
7151 NAME=FULLPARSE
7152 case "$TESTS" in
7153 *%$N%*|*%functions%*|*%parse%*|*%$NAME%*)
7154 TEST="$NAME: correctly parse special chars"
7155 if ! eval $NUMCOND; then :; else
7156 $PRINTF "test $F_n $TEST... " $N
7157 tf="$td/test$N.stdout"
7158 te="$td/test$N.stderr"
7159 tdiff="$td/test$N.diff"
7160 # a string where commas are hidden in nesting lexical constructs
7161 # if they are scanned incorrectly, socat will see an "unknown option"
7162 dain='(,)[,]{,}","([),])hugo'
7163 daout='(,)[,]{,},([),])hugo'
7164 $TRACE "$SOCAT" $opts -u "exec:echo $dain" - >"$tf" 2>"$te"
7165 rc=$?
7166 echo "$daout" |diff "$tf" - >"$tdiff"
7167 if [ "$rc" -ne 0 ]; then
7168 $PRINTF "$FAILED:\n"
7169 echo "$TRACE $SOCAT" -u "exec:echo $da" -
7170 cat "$te"
7171 numFAIL=$((numFAIL+1))
7172 listFAIL="$listFAIL $N"
7173 elif [ -s "$tdiff" ]; then
7174 $PRINTF "$FAILED:\n"
7175 echo diff:
7176 cat "$tdiff"
7177 if [ -n "$debug" ]; then cat $te; fi
7178 numFAIL=$((numFAIL+1))
7179 listFAIL="$listFAIL $N"
7180 else
7181 $PRINTF "$OK\n"
7182 if [ -n "$debug" ]; then cat $te; fi
7183 numOK=$((numOK+1))
7185 fi ;; # NUMCOND
7186 esac
7187 N=$((N+1))
7189 NAME=NESTEDSOCATEXEC
7190 case "$TESTS" in
7191 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
7192 TEST="$NAME: does lexical analysis work sensibly (exec)"
7193 testecho "$N" "$TEST" "" "exec:'$SOCAT - exec:$CAT,pipes'" "$opts" 1
7194 esac
7195 N=$((N+1))
7197 NAME=NESTEDSOCATSYSTEM
7198 case "$TESTS" in
7199 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
7200 TEST="$NAME: does lexical analysis work sensibly (system)"
7201 testecho "$N" "$TEST" "" "system:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
7202 esac
7203 N=$((N+1))
7206 NAME=TCP6BYTCP4
7207 case "$TESTS" in
7208 *%$N%*|*%functions%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
7209 TEST="$NAME: TCP4 mapped into TCP6 address space"
7210 if ! eval $NUMCOND; then :;
7211 elif true; then
7212 $PRINTF "test $F_n $TEST... ${YELLOW}Feature removed${NORMAL}\n" $N
7213 numCANT=$((numCANT+1))
7214 listCANT="$listCANT $N"
7215 elif ! testfeats tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
7216 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7217 numCANT=$((numCANT+1))
7218 listCANT="$listCANT $N"
7219 else
7220 tf="$td/test$N.stdout"
7221 te="$td/test$N.stderr"
7222 tdiff="$td/test$N.diff"
7223 tsl=$PORT
7224 ts="127.0.0.1:$tsl"
7225 da="test$N $(date) $RANDOM"
7226 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
7227 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
7228 printf "test $F_n $TEST... " $N
7229 $CMD1 >"$tf" 2>"${te}1" &
7230 pid=$! # background process id
7231 waittcp6port $tsl 1
7232 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7233 if [ $? -ne 0 ]; then
7234 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7235 echo "$CMD1 &"
7236 echo "$CMD2"
7237 cat "${te}1"
7238 cat "${te}2"
7239 numFAIL=$((numFAIL+1))
7240 listFAIL="$listFAIL $N"
7241 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7242 $PRINTF "$FAILED: diff:\n"
7243 cat "$tdiff"
7244 numFAIL=$((numFAIL+1))
7245 listFAIL="$listFAIL $N"
7246 else
7247 $PRINTF "$OK\n"
7248 if [ -n "$debug" ]; then cat $te; fi
7249 numOK=$((numOK+1))
7251 kill $pid 2>/dev/null; wait
7252 fi ;; # NUMCOND, feats
7253 esac
7254 PORT=$((PORT+1))
7255 N=$((N+1))
7258 # test the UDP4-SENDTO and UDP4-RECVFROM addresses together
7259 NAME=UDP4DGRAM
7260 case "$TESTS" in
7261 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%$NAME%*)
7262 TEST="$NAME: UDP/IPv4 sendto and recvfrom"
7263 # start a UDP4-RECVFROM process that echoes data, and send test data using
7264 # UDP4-SENDTO. The sent data should be returned.
7265 if ! eval $NUMCOND; then :; else
7266 tf="$td/test$N.stdout"
7267 te="$td/test$N.stderr"
7268 tdiff="$td/test$N.diff"
7269 ts1p=$PORT; PORT=$((PORT+1))
7270 ts1a="127.0.0.1"
7271 ts1="$ts1a:$ts1p"
7272 ts2p=$PORT; PORT=$((PORT+1))
7273 ts2="127.0.0.1:$ts2p"
7274 da="test$N $(date) $RANDOM"
7275 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
7276 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2"
7277 printf "test $F_n $TEST... " $N
7278 $CMD1 2>"${te}1" &
7279 pid1="$!"
7280 waitudp4port $ts1p 1
7281 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7282 rc2="$?"
7283 kill "$pid1" 2>/dev/null; wait;
7284 if [ "$rc2" -ne 0 ]; then
7285 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7286 echo "$CMD1 &"
7287 cat "${te}1"
7288 echo "$CMD2"
7289 cat "${te}2"
7290 numFAIL=$((numFAIL+1))
7291 listFAIL="$listFAIL $N"
7292 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7293 $PRINTF "$FAILED\n"
7294 cat "$tdiff"
7295 echo "$CMD1 &"
7296 cat "${te}1"
7297 echo "$CMD2"
7298 cat "${te}2"
7299 numFAIL=$((numFAIL+1))
7300 listFAIL="$listFAIL $N"
7301 else
7302 $PRINTF "$OK\n"
7303 if [ -n "$debug" ]; then cat $te; fi
7304 numOK=$((numOK+1))
7306 fi # NUMCOND
7308 esac
7309 PORT=$((PORT+1))
7310 N=$((N+1))
7313 NAME=UDP6DGRAM
7314 case "$TESTS" in
7315 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%$NAME%*)
7316 TEST="$NAME: UDP/IPv6 datagram"
7317 if ! eval $NUMCOND; then :;
7318 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
7319 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7320 numCANT=$((numCANT+1))
7321 listCANT="$listCANT $N"
7322 else
7323 tf="$td/test$N.stdout"
7324 te="$td/test$N.stderr"
7325 tdiff="$td/test$N.diff"
7326 ts1p=$PORT; PORT=$((PORT+1))
7327 tsa="[::1]"
7328 ts1="$tsa:$ts1p"
7329 ts2p=$PORT; PORT=$((PORT+1))
7330 ts2="$tsa:$ts2p"
7331 da="test$N $(date) $RANDOM"
7332 CMD1="$TRACE $SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
7333 CMD2="$TRACE $SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2"
7334 printf "test $F_n $TEST... " $N
7335 $CMD1 2>"${te}1" &
7336 waitudp6port $ts1p 1
7337 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7338 if [ $? -ne 0 ]; then
7339 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7340 echo "$CMD1 &"
7341 echo "$CMD2"
7342 cat "${te}1"
7343 cat "${te}2"
7344 numFAIL=$((numFAIL+1))
7345 listFAIL="$listFAIL $N"
7346 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7347 $PRINTF "$FAILED\n"
7348 cat "$tdiff"
7349 numFAIL=$((numFAIL+1))
7350 listFAIL="$listFAIL $N"
7351 else
7352 $PRINTF "$OK\n"
7353 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
7354 numOK=$((numOK+1))
7356 fi ;; # NUMCOND, feats
7357 esac
7358 PORT=$((PORT+1))
7359 N=$((N+1))
7362 NAME=RAWIP4RECVFROM
7363 case "$TESTS" in
7364 *%$N%*|*%functions%*|*%ip%*|*%ip4%*|*%rawip%*|*%rawip4%*|*%dgram%*|*%root%*|*%$NAME%*)
7365 TEST="$NAME: raw IPv4 datagram"
7366 if ! eval $NUMCOND; then :;
7367 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7368 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7369 numCANT=$((numCANT+1))
7370 listCANT="$listCANT $N"
7371 else
7372 tf="$td/test$N.stdout"
7373 te="$td/test$N.stderr"
7374 tdiff="$td/test$N.diff"
7375 ts1p=$PROTO; PROTO=$((PROTO+1))
7376 ts1a="127.0.0.1"
7377 ts1="$ts1a:$ts1p"
7378 ts2a="$SECONDADDR"
7379 ts2="$ts2a:$ts2p"
7380 da="test$N $(date) $RANDOM"
7381 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
7382 CMD2="$TRACE $SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a"
7383 printf "test $F_n $TEST... " $N
7384 $CMD1 2>"${te}1" &
7385 pid1=$!
7386 waitip4proto $ts1p 1
7387 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7388 rc2=$?
7389 kill $pid1 2>/dev/null; wait
7390 if [ $rc2 -ne 0 ]; then
7391 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7392 echo "$CMD1 &"
7393 echo "$CMD2"
7394 cat "${te}1"
7395 cat "${te}2"
7396 numFAIL=$((numFAIL+1))
7397 listFAIL="$listFAIL $N"
7398 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7399 $PRINTF "$FAILED\n"
7400 cat "$tdiff"
7401 numFAIL=$((numFAIL+1))
7402 listFAIL="$listFAIL $N"
7403 else
7404 $PRINTF "$OK\n"
7405 if [ -n "$debug" ]; then cat $te; fi
7406 numOK=$((numOK+1))
7408 fi ;; # root, NUMCOND
7409 esac
7410 N=$((N+1))
7413 if false; then
7414 NAME=RAWIP6RECVFROM
7415 case "$TESTS" in
7416 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%dgram%*|*%root%*|*%$NAME%*)
7417 TEST="$NAME: raw IPv6 datagram by self addressing"
7418 if ! eval $NUMCOND; then :;
7419 elif ! feat=$(testfeats ip6 rawip && runsip6); then
7420 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7421 numCANT=$((numCANT+1))
7422 listCANT="$listCANT $N"
7423 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7424 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7425 numCANT=$((numCANT+1))
7426 listCANT="$listCANT $N"
7427 else
7428 tf="$td/test$N.stdout"
7429 te="$td/test$N.stderr"
7430 tdiff="$td/test$N.diff"
7431 ts1p=$PROTO; PROTO=$((PROTO+1))
7432 tsa="[::1]"
7433 ts1="$tsa:$ts1p"
7434 ts2="$tsa"
7435 da="test$N $(date) $RANDOM"
7436 #CMD1="$TRACE $SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
7437 CMD2="$TRACE $SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2"
7438 printf "test $F_n $TEST... " $N
7439 #$CMD1 2>"${te}1" &
7440 waitip6proto $ts1p 1
7441 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7442 if [ $? -ne 0 ]; then
7443 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7444 # echo "$CMD1 &"
7445 # cat "${te}1"
7446 echo "$CMD2"
7447 cat "${te}2"
7448 numFAIL=$((numFAIL+1))
7449 listFAIL="$listFAIL $N"
7450 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7451 $PRINTF "$FAILED\n"
7452 cat "$tdiff"
7453 numFAIL=$((numFAIL+1))
7454 listFAIL="$listFAIL $N"
7455 else
7456 $PRINTF "$OK\n"
7457 if [ -n "$debug" ]; then cat "$te"; fi
7458 numOK=$((numOK+1))
7460 fi ;; # root, NUMCOND
7461 esac
7462 N=$((N+1))
7463 fi #false
7466 NAME=UNIXDGRAM
7467 case "$TESTS" in
7468 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%dgram%*|*%$NAME%*)
7469 TEST="$NAME: UNIX datagram"
7470 if ! eval $NUMCOND; then :; else
7471 tf="$td/test$N.stdout"
7472 te="$td/test$N.stderr"
7473 tdiff="$td/test$N.diff"
7474 ts1="$td/test$N.socket1"
7475 ts2="$td/test$N.socket2"
7476 da="test$N $(date) $RANDOM"
7477 CMD1="$TRACE $SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE"
7478 CMD2="$TRACE $SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2"
7479 printf "test $F_n $TEST... " $N
7480 $CMD1 2>"${te}1" &
7481 pid1="$!"
7482 waitfile $ts1 1
7483 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7484 rc2=$?
7485 kill "$pid1" 2>/dev/null; wait
7486 if [ $rc2 -ne 0 ]; then
7487 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7488 echo "$CMD1 &"
7489 cat "${te}1"
7490 echo "$CMD2"
7491 cat "${te}2"
7492 numFAIL=$((numFAIL+1))
7493 listFAIL="$listFAIL $N"
7494 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7495 $PRINTF "$FAILED\n"
7496 cat "$tdiff"
7497 numFAIL=$((numFAIL+1))
7498 listFAIL="$listFAIL $N"
7499 else
7500 $PRINTF "$OK\n"
7501 if [ -n "$debug" ]; then cat $te; fi
7502 numOK=$((numOK+1))
7504 fi # NUMCOND
7506 esac
7507 N=$((N+1))
7510 NAME=UDP4RECV
7511 case "$TESTS" in
7512 *%$N%*|*%functions%*|*%engine%*|*%ip4%*|*%dgram%*|*%udp%*|*%udp4%*|*%recv%*|*%$NAME%*)
7513 TEST="$NAME: UDP/IPv4 receive"
7514 if ! eval $NUMCOND; then :; else
7515 tf="$td/test$N.stdout"
7516 te="$td/test$N.stderr"
7517 tdiff="$td/test$N.diff"
7518 ts1p=$PORT; PORT=$((PORT+1))
7519 ts1a="127.0.0.1"
7520 ts1="$ts1a:$ts1p"
7521 da="test$N $(date) $RANDOM"
7522 CMD1="$TRACE $SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -"
7523 CMD2="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1"
7524 printf "test $F_n $TEST... " $N
7525 $CMD1 >"$tf" 2>"${te}1" &
7526 pid1="$!"
7527 waitudp4port $ts1p 1
7528 echo "$da" |$CMD2 2>>"${te}2"
7529 rc2="$?"
7530 #ls -l $tf
7531 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7532 kill "$pid1" 2>/dev/null; wait
7533 if [ "$rc2" -ne 0 ]; then
7534 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7535 echo "$CMD1 &"
7536 echo "$CMD2"
7537 cat "${te}1"
7538 cat "${te}2"
7539 numFAIL=$((numFAIL+1))
7540 listFAIL="$listFAIL $N"
7541 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7542 $PRINTF "$FAILED\n"
7543 cat "$tdiff"
7544 echo "$CMD1 &"
7545 echo "$CMD2"
7546 cat "${te}1"
7547 cat "${te}2"
7548 numFAIL=$((numFAIL+1))
7549 listFAIL="$listFAIL $N"
7550 else
7551 $PRINTF "$OK\n"
7552 if [ -n "$debug" ]; then cat $te; fi
7553 numOK=$((numOK+1))
7555 fi # NUMCOND
7557 esac
7558 N=$((N+1))
7561 NAME=UDP6RECV
7562 case "$TESTS" in
7563 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%udp%*|*%udp6%*|*%recv%*|*%$NAME%*)
7564 TEST="$NAME: UDP/IPv6 receive"
7565 if ! eval $NUMCOND; then :;
7566 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
7567 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7568 numCANT=$((numCANT+1))
7569 listCANT="$listCANT $N"
7570 else
7571 tf="$td/test$N.stdout"
7572 te="$td/test$N.stderr"
7573 tdiff="$td/test$N.diff"
7574 ts1p=$PORT; PORT=$((PORT+1))
7575 ts1a="[::1]"
7576 ts1="$ts1a:$ts1p"
7577 da="test$N $(date) $RANDOM"
7578 CMD1="$TRACE $SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -"
7579 CMD2="$TRACE $SOCAT $opts -u - UDP6-SENDTO:$ts1"
7580 printf "test $F_n $TEST... " $N
7581 $CMD1 >"$tf" 2>"${te}1" &
7582 pid1="$!"
7583 waitudp6port $ts1p 1
7584 echo "$da" |$CMD2 2>>"${te}2"
7585 rc2="$?"
7586 #ls -l $tf
7587 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7588 kill "$pid1" 2>/dev/null; wait
7589 if [ "$rc2" -ne 0 ]; then
7590 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7591 echo "$CMD1 &"
7592 echo "$CMD2"
7593 cat "${te}1"
7594 cat "${te}2"
7595 numFAIL=$((numFAIL+1))
7596 listFAIL="$listFAIL $N"
7597 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7598 $PRINTF "$FAILED\n"
7599 cat "$tdiff"
7600 numFAIL=$((numFAIL+1))
7601 listFAIL="$listFAIL $N"
7602 else
7603 $PRINTF "$OK\n"
7604 if [ -n "$debug" ]; then cat $te; fi
7605 numOK=$((numOK+1))
7607 fi ;; # NUMCOND, feats
7608 esac
7609 N=$((N+1))
7612 NAME=RAWIP4RECV
7613 case "$TESTS" in
7614 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
7615 TEST="$NAME: raw IPv4 receive"
7616 if ! eval $NUMCOND; then :;
7617 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7618 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7619 numCANT=$((numCANT+1))
7620 listCANT="$listCANT $N"
7621 else
7622 tf="$td/test$N.stdout"
7623 te="$td/test$N.stderr"
7624 tdiff="$td/test$N.diff"
7625 ts1p=$PROTO; PROTO=$((PROTO+1))
7626 ts1a="127.0.0.1"
7627 ts1="$ts1a:$ts1p"
7628 da="test$N $(date) $RANDOM"
7629 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -"
7630 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
7631 printf "test $F_n $TEST... " $N
7632 $CMD1 >"$tf" 2>"${te}1" &
7633 pid1="$!"
7634 waitip4proto $ts1p 1
7635 echo "$da" |$CMD2 2>>"${te}2"
7636 rc2="$?"
7637 #ls -l $tf
7638 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7639 kill "$pid1" 2>/dev/null; wait
7640 if [ "$rc2" -ne 0 ]; then
7641 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7642 echo "$CMD1 &"
7643 echo "$CMD2"
7644 cat "${te}1"
7645 cat "${te}2"
7646 numFAIL=$((numFAIL+1))
7647 listFAIL="$listFAIL $N"
7648 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7649 $PRINTF "$FAILED\n"
7650 cat "$tdiff"
7651 numFAIL=$((numFAIL+1))
7652 listFAIL="$listFAIL $N"
7653 else
7654 $PRINTF "$OK\n"
7655 if [ -n "$debug" ]; then cat $te; fi
7656 numOK=$((numOK+1))
7658 fi ;; # NUMCOND, root
7659 esac
7660 N=$((N+1))
7663 NAME=RAWIP6RECV
7664 case "$TESTS" in
7665 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%rawip%*|*%rawip6%*|*%recv%*|*%root%*|*%$NAME%*)
7666 TEST="$NAME: raw IPv6 receive"
7667 if ! eval $NUMCOND; then :;
7668 elif ! feat=$(testfeats ip6 rawip && runsip6); then
7669 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7670 numCANT=$((numCANT+1))
7671 listCANT="$listCANT $N"
7672 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7673 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7674 numCANT=$((numCANT+1))
7675 listCANT="$listCANT $N"
7676 else
7677 tf="$td/test$N.stdout"
7678 te="$td/test$N.stderr"
7679 tdiff="$td/test$N.diff"
7680 ts1p=$PROTO; PROTO=$((PROTO+1))
7681 ts1a="[::1]"
7682 ts1="$ts1a:$ts1p"
7683 da="test$N $(date) $RANDOM"
7684 CMD1="$TRACE $SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -"
7685 CMD2="$TRACE $SOCAT $opts -u - IP6-SENDTO:$ts1"
7686 printf "test $F_n $TEST... " $N
7687 $CMD1 >"$tf" 2>"${te}1" &
7688 pid1="$!"
7689 waitip6proto $ts1p 1
7690 echo "$da" |$CMD2 2>>"${te}2"
7691 rc2="$?"
7692 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7693 kill "$pid1" 2>/dev/null; wait
7694 if [ "$rc2" -ne 0 ]; then
7695 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7696 echo "$CMD1 &"
7697 echo "$CMD2"
7698 cat "${te}1"
7699 cat "${te}2"
7700 numFAIL=$((numFAIL+1))
7701 listFAIL="$listFAIL $N"
7702 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7703 $PRINTF "$FAILED\n"
7704 cat "$tdiff"
7705 numFAIL=$((numFAIL+1))
7706 listFAIL="$listFAIL $N"
7707 else
7708 $PRINTF "$OK\n"
7709 if [ -n "$debug" ]; then cat $te; fi
7710 numOK=$((numOK+1))
7712 fi ;; # NUMCOND, root
7713 esac
7714 N=$((N+1))
7717 NAME=UNIXRECV
7718 case "$TESTS" in
7719 *%$N%*|*%functions%*|*%unix%*|*%dgram%*|*%recv%*|*%$NAME%*)
7720 TEST="$NAME: UNIX receive"
7721 if ! eval $NUMCOND; then :; else
7722 ts="$td/test$N.socket"
7723 tf="$td/test$N.stdout"
7724 te="$td/test$N.stderr"
7725 tdiff="$td/test$N.diff"
7726 ts1="$ts"
7727 da="test$N $(date) $RANDOM"
7728 CMD1="$TRACE $SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -"
7729 CMD2="$TRACE $SOCAT $opts -u - UNIX-SENDTO:$ts1"
7730 printf "test $F_n $TEST... " $N
7731 $CMD1 >"$tf" 2>"${te}1" &
7732 pid1="$!"
7733 waitfile $ts1 1
7734 echo "$da" |$CMD2 2>>"${te}2"
7735 rc2="$?"
7736 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7737 kill "$pid1" 2>/dev/null; wait
7738 if [ "$rc2" -ne 0 ]; then
7739 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7740 echo "$CMD1 &"
7741 echo "$CMD2"
7742 cat "${te}1"
7743 cat "${te}2"
7744 numFAIL=$((numFAIL+1))
7745 listFAIL="$listFAIL $N"
7746 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7747 $PRINTF "$FAILED\n"
7748 cat "$tdiff"
7749 numFAIL=$((numFAIL+1))
7750 listFAIL="$listFAIL $N"
7751 else
7752 $PRINTF "$OK\n"
7753 if [ -n "$debug" ]; then cat $te; fi
7754 numOK=$((numOK+1))
7756 fi # NUMCOND
7758 esac
7759 N=$((N+1))
7762 NAME=UDP4RECVFROM_SOURCEPORT
7763 case "$TESTS" in
7764 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7765 TEST="$NAME: security of UDP4-RECVFROM with SOURCEPORT option"
7766 if ! eval $NUMCOND; then :;
7767 elif ! feat=$(testfeats udp ip4) || ! runsip4 >/dev/null; then
7768 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7769 numCANT=$((numCANT+1))
7770 listCANT="$listCANT $N"
7771 else
7772 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7773 fi ;; # NUMCOND, feats
7774 esac
7775 PORT=$((PORT+1))
7776 N=$((N+1))
7778 NAME=UDP4RECVFROM_LOWPORT
7779 case "$TESTS" in
7780 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7781 TEST="$NAME: security of UDP4-RECVFROM with LOWPORT option"
7782 if ! eval $NUMCOND; then :;
7783 elif ! feat=$(testfeats udp ip4) || ! runsip4 >/dev/null; then
7784 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7785 numCANT=$((numCANT+1))
7786 listCANT="$listCANT $N"
7787 else
7788 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7789 fi ;; # NUMCOND, feats
7790 esac
7791 PORT=$((PORT+1))
7792 N=$((N+1))
7794 NAME=UDP4RECVFROM_RANGE
7795 case "$TESTS" in
7796 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7797 TEST="$NAME: security of UDP4-RECVFROM with RANGE option"
7798 #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7799 if ! eval $NUMCOND; then :; else
7800 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7801 fi ;; # NUMCOND
7802 esac
7803 PORT=$((PORT+1))
7804 N=$((N+1))
7806 NAME=UDP4RECVFROM_TCPWRAP
7807 case "$TESTS" in
7808 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7809 TEST="$NAME: security of UDP4-RECVFROM with TCPWRAP option"
7810 if ! eval $NUMCOND; then :;
7811 elif ! feat=$(testfeats ip4 udp libwrap) || ! runsip4 >/dev/null; then
7812 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7813 numCANT=$((numCANT+1))
7814 listCANT="$listCANT $N"
7815 else
7816 ha="$td/hosts.allow"
7817 hd="$td/hosts.deny"
7818 $ECHO "socat: $SECONDADDR" >"$ha"
7819 $ECHO "ALL: ALL" >"$hd"
7820 #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "tcpwrap=$d" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7821 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7822 fi ;; # NUMCOND, feats
7823 esac
7824 PORT=$((PORT+1))
7825 N=$((N+1))
7828 NAME=UDP4RECV_SOURCEPORT
7829 case "$TESTS" in
7830 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7831 TEST="$NAME: security of UDP4-RECV with SOURCEPORT option"
7832 if ! eval $NUMCOND; then :;
7833 elif ! feat=$(testfeats udp ip4) || ! runsip4 >/dev/null; then
7834 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7835 numCANT=$((numCANT+1))
7836 listCANT="$listCANT $N"
7837 else
7838 PORT1=$PORT; PORT=$((PORT+1))
7839 PORT2=$PORT; PORT=$((PORT+1))
7840 PORT3=$PORT
7841 # we use the forward channel (PORT1) for testing, and have a backward channel
7842 # (PORT2) to get the data back, so we get the classical echo behaviour
7843 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "sp=$PORT3" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7844 fi ;; # NUMCOND, feats
7845 esac
7846 PORT=$((PORT+1))
7847 N=$((N+1))
7849 NAME=UDP4RECV_LOWPORT
7850 case "$TESTS" in
7851 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7852 TEST="$NAME: security of UDP4-RECV with LOWPORT option"
7853 if ! eval $NUMCOND; then :;
7854 elif ! feat=$(testfeats udp ip4) || ! runsip4 >/dev/null; then
7855 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7856 numCANT=$((numCANT+1))
7857 listCANT="$listCANT $N"
7858 else
7859 PORT1=$PORT; PORT=$((PORT+1))
7860 PORT2=$PORT
7861 # we use the forward channel (PORT1) for testing, and have a backward channel
7862 # (PORT2) to get the data back, so we get the classical echo behaviour
7863 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "lowport" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7864 fi ;; # NUMCOND, feats
7865 esac
7866 PORT=$((PORT+1))
7867 N=$((N+1))
7869 NAME=UDP4RECV_RANGE
7870 case "$TESTS" in
7871 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7872 TEST="$NAME: security of UDP4-RECV with RANGE option"
7873 if ! eval $NUMCOND; then :;
7874 elif ! feat=$(testfeats udp ip4) || ! runsip4 >/dev/null; then
7875 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7876 numCANT=$((numCANT+1))
7877 listCANT="$listCANT $N"
7878 else
7879 PORT1=$PORT; PORT=$((PORT+1))
7880 PORT2=$PORT
7881 # we use the forward channel (PORT1) for testing, and have a backward channel
7882 # (PORT2) to get the data back, so we get the classical echo behaviour
7883 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "range=$SECONDADDR/32" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7884 fi ;; # NUMCOND, feats
7885 esac
7886 PORT=$((PORT+1))
7887 N=$((N+1))
7889 NAME=UDP4RECV_TCPWRAP
7890 case "$TESTS" in
7891 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7892 TEST="$NAME: security of UDP4-RECV with TCPWRAP option"
7893 if ! eval $NUMCOND; then :;
7894 elif ! feat=$(testfeats udp ip4 libwrap) || ! runsip4 >/dev/null; then
7895 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7896 numCANT=$((numCANT+1))
7897 listCANT="$listCANT $N"
7898 else
7899 PORT1=$PORT; PORT=$((PORT+1))
7900 PORT2=$PORT
7901 ha="$td/hosts.allow"
7902 hd="$td/hosts.deny"
7903 $ECHO "socat: $SECONDADDR" >"$ha"
7904 $ECHO "ALL: ALL" >"$hd"
7905 # we use the forward channel (PORT1) for testing, and have a backward channel
7906 # (PORT2) to get the data back, so we get the classical echo behaviour
7907 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "tcpwrap-etc=$td" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7908 fi ;; # NUMCOND, feats
7909 esac
7910 PORT=$((PORT+1))
7911 N=$((N+1))
7914 NAME=UDP6RECVFROM_SOURCEPORT
7915 case "$TESTS" in
7916 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7917 TEST="$NAME: security of UDP6-RECVFROM with SOURCEPORT option"
7918 if ! eval $NUMCOND; then :;
7919 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
7920 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7921 numCANT=$((numCANT+1))
7922 listCANT="$listCANT $N"
7923 else
7924 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7925 fi ;; # NUMCOND, feats
7926 esac
7927 PORT=$((PORT+1))
7928 N=$((N+1))
7930 NAME=UDP6RECVFROM_LOWPORT
7931 case "$TESTS" in
7932 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7933 TEST="$NAME: security of UDP6-RECVFROM with LOWPORT option"
7934 if ! eval $NUMCOND; then :;
7935 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
7936 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7937 numCANT=$((numCANT+1))
7938 listCANT="$listCANT $N"
7939 else
7940 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7941 fi ;; # NUMCOND, feats
7942 esac
7943 PORT=$((PORT+1))
7944 N=$((N+1))
7946 NAME=UDP6RECVFROM_RANGE
7947 case "$TESTS" in
7948 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7949 TEST="$NAME: security of UDP6-RECVFROM with RANGE option"
7950 if ! eval $NUMCOND; then :;
7951 elif ! feat=$(testfeats tcp ip6) || ! runsip6 >/dev/null; then
7952 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7953 numCANT=$((numCANT+1))
7954 listCANT="$listCANT $N"
7955 else
7956 #testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7957 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7958 fi ;; # NUMCOND, feats
7959 esac
7960 PORT=$((PORT+1))
7961 N=$((N+1))
7963 NAME=UDP6RECVFROM_TCPWRAP
7964 case "$TESTS" in
7965 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7966 TEST="$NAME: security of UDP6-RECVFROM with TCPWRAP option"
7967 if ! eval $NUMCOND; then :;
7968 elif ! feat=$(testfeats udp ip6 libwrap && runsip6); then
7969 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7970 numCANT=$((numCANT+1))
7971 listCANT="$listCANT $N"
7972 else
7973 ha="$td/hosts.allow"
7974 hd="$td/hosts.deny"
7975 $ECHO "socat: [::2]" >"$ha"
7976 $ECHO "ALL: ALL" >"$hd"
7977 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7978 fi ;; # NUMCOND, feats
7979 esac
7980 PORT=$((PORT+1))
7981 N=$((N+1))
7984 NAME=UDP6RECV_SOURCEPORT
7985 case "$TESTS" in
7986 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7987 TEST="$NAME: security of UDP6-RECV with SOURCEPORT option"
7988 if ! eval $NUMCOND; then :;
7989 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
7990 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7991 numCANT=$((numCANT+1))
7992 listCANT="$listCANT $N"
7993 else
7994 PORT1=$PORT; PORT=$((PORT+1))
7995 PORT2=$PORT; PORT=$((PORT+1))
7996 PORT3=$PORT
7997 # we use the forward channel (PORT1) for testing, and have a backward channel
7998 # (PORT2) to get the data back, so we get the classical echo behaviour
7999 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "sp=$PORT3" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
8000 fi ;; # NUMCOND, feats
8001 esac
8002 PORT=$((PORT+1))
8003 N=$((N+1))
8005 NAME=UDP6RECV_LOWPORT
8006 case "$TESTS" in
8007 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
8008 TEST="$NAME: security of UDP6-RECV with LOWPORT option"
8009 if ! eval $NUMCOND; then :;
8010 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
8011 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8012 numCANT=$((numCANT+1))
8013 listCANT="$listCANT $N"
8014 else
8015 PORT1=$PORT; PORT=$((PORT+1))
8016 PORT2=$PORT
8017 # we use the forward channel (PORT1) for testing, and have a backward channel
8018 # (PORT2) to get the data back, so we get the classical echo behaviour
8019 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "lowport" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
8020 fi ;; # NUMCOND, feats
8021 esac
8022 PORT=$((PORT+1))
8023 N=$((N+1))
8025 NAME=UDP6RECV_RANGE
8026 case "$TESTS" in
8027 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
8028 TEST="$NAME: security of UDP6-RECV with RANGE option"
8029 if ! eval $NUMCOND; then :;
8030 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
8031 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8032 numCANT=$((numCANT+1))
8033 listCANT="$listCANT $N"
8034 else
8035 PORT1=$PORT; PORT=$((PORT+1))
8036 PORT2=$PORT
8037 # we use the forward channel (PORT1) for testing, and have a backward channel
8038 # (PORT2) to get the data back, so we get the classical echo behaviour
8039 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "range=[::2]/128" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
8040 fi ;; # NUMCOND, feats
8041 esac
8042 PORT=$((PORT+1))
8043 N=$((N+1))
8045 NAME=UDP6RECV_TCPWRAP
8046 case "$TESTS" in
8047 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
8048 TEST="$NAME: security of UDP6-RECV with TCPWRAP option"
8049 if ! eval $NUMCOND; then :;
8050 elif ! feat=$(testfeats udp ip6 libwrap && runsip6); then
8051 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8052 numCANT=$((numCANT+1))
8053 listCANT="$listCANT $N"
8054 else
8055 ha="$td/hosts.allow"
8056 hd="$td/hosts.deny"
8057 $ECHO "socat: [::2]" >"$ha"
8058 $ECHO "ALL: ALL" >"$hd"
8059 PORT1=$PORT; PORT=$((PORT+1))
8060 PORT2=$PORT
8061 # we use the forward channel (PORT1) for testing, and have a backward channel
8062 # (PORT2) to get the data back, so we get the classical echo behaviour
8063 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "tcpwrap-etc=$td" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
8064 fi ;; # NUMCOND, feats
8065 esac
8066 PORT=$((PORT+1))
8067 N=$((N+1))
8070 NAME=IP4RECVFROM_RANGE
8071 case "$TESTS" in
8072 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
8073 TEST="$NAME: security of IP4-RECVFROM with RANGE option"
8074 if ! eval $NUMCOND; then :;
8075 elif ! feat=$(testfeats ip4 rawip) || ! runsip4 >/dev/null; then
8076 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8077 numCANT=$((numCANT+1))
8078 listCANT="$listCANT $N"
8079 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8080 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8081 numCANT=$((numCANT+1))
8082 listCANT="$listCANT $N"
8083 else
8084 #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
8085 testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "range=$SECONDADDR/32" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
8086 fi ;; # NUMCOND, feats, root
8087 esac
8088 PROTO=$((PROTO+1))
8089 PORT=$((PORT+1))
8090 N=$((N+1))
8092 NAME=IP4RECVFROM_TCPWRAP
8093 case "$TESTS" in
8094 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
8095 TEST="$NAME: security of IP4-RECVFROM with TCPWRAP option"
8096 if ! eval $NUMCOND; then :;
8097 elif ! feat=$(testfeats ip4 rawip libwrap) || ! runsip4 >/dev/null; then
8098 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8099 numCANT=$((numCANT+1))
8100 listCANT="$listCANT $N"
8101 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8102 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8103 numCANT=$((numCANT+1))
8104 listCANT="$listCANT $N"
8105 else
8106 ha="$td/hosts.allow"
8107 hd="$td/hosts.deny"
8108 $ECHO "socat: $SECONDADDR" >"$ha"
8109 $ECHO "ALL: ALL" >"$hd"
8110 #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
8111 testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "tcpwrap-etc=$td" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
8112 fi # NUMCOND, feats, root
8114 esac
8115 PROTO=$((PROTO+1))
8116 PORT=$((PORT+1))
8117 N=$((N+1))
8120 NAME=IP4RECV_RANGE
8121 case "$TESTS" in
8122 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
8123 TEST="$NAME: security of IP4-RECV with RANGE option"
8124 if ! eval $NUMCOND; then :;
8125 elif ! feat=$(testfeats ip4 rawip) || ! runsip4 >/dev/null; then
8126 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
8127 numCANT=$((numCANT+1))
8128 listCANT="$listCANT $N"
8129 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8130 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8131 numCANT=$((numCANT+1))
8132 listCANT="$listCANT $N"
8133 else
8134 PROTO1=$PROTO; PROTO=$((PROTO+1))
8135 PROTO2=$PROTO
8136 # we use the forward channel (PROTO1) for testing, and have a backward channel
8137 # (PROTO2) to get the data back, so we get the classical echo behaviour
8138 testserversec "$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "range=$SECONDADDR/32" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip $PROTO1 0
8139 fi ;; # NUMCOND, feats, root
8140 esac
8141 PROTO=$((PROTO+1))
8142 N=$((N+1))
8146 NAME=IP4RECV_TCPWRAP
8147 case "$TESTS" in
8148 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
8149 TEST="$NAME: security of IP4-RECV with TCPWRAP option"
8150 if ! eval $NUMCOND; then :;
8151 elif ! feat=$(testfeats ip4 rawip libwrap) || ! runsip4 >/dev/null; then
8152 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8153 numCANT=$((numCANT+1))
8154 listCANT="$listCANT $N"
8155 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8156 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8157 numCANT=$((numCANT+1))
8158 listCANT="$listCANT $N"
8159 else
8160 PROTO1=$PROTO; PROTO=$((PROTO+1))
8161 PROTO2=$PROTO
8162 ha="$td/hosts.allow"
8163 hd="$td/hosts.deny"
8164 $ECHO "socat: $SECONDADDR" >"$ha"
8165 $ECHO "ALL: ALL" >"$hd"
8166 # we use the forward channel (PROTO1) for testing, and have a backward channel
8167 # (PROTO2) to get the data back, so we get the classical echo behaviour
8168 testserversec "$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "tcpwrap-etc=$td" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip $PROTO1 0
8169 fi ;; # NUMCOND, feats, root
8170 esac
8171 PROTO=$((PROTO+1))
8172 N=$((N+1))
8175 NAME=IP6RECVFROM_RANGE
8176 case "$TESTS" in
8177 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
8178 TEST="$NAME: security of IP6-RECVFROM with RANGE option"
8179 if ! eval $NUMCOND; then :;
8180 elif ! feat=$(testfeats ip6 rawip && runsip6); then
8181 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8182 numCANT=$((numCANT+1))
8183 listCANT="$listCANT $N"
8184 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8185 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8186 numCANT=$((numCANT+1))
8187 listCANT="$listCANT $N"
8188 else
8189 #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "range=[::2]/128" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
8190 testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "range=[::2]/128" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
8191 fi ;; # NUMCOND, feats
8192 esac
8193 PROTO=$((PROTO+1))
8194 PORT=$((PORT+1))
8195 N=$((N+1))
8197 NAME=IP6RECVFROM_TCPWRAP
8198 case "$TESTS" in
8199 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
8200 TEST="$NAME: security of IP6-RECVFROM with TCPWRAP option"
8201 if ! eval $NUMCOND; then :;
8202 elif ! feat=$(testfeats ip6 rawip libwrap && runsip6); then
8203 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8204 numCANT=$((numCANT+1))
8205 listCANT="$listCANT $N"
8206 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8207 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8208 numCANT=$((numCANT+1))
8209 listCANT="$listCANT $N"
8210 else
8211 ha="$td/hosts.allow"
8212 hd="$td/hosts.deny"
8213 $ECHO "socat: [::2]" >"$ha"
8214 $ECHO "ALL: ALL" >"$hd"
8215 #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
8216 testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "tcpwrap-etc=$td" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
8217 fi ;; # NUMCOND, feats
8218 esac
8219 PROTO=$((PROTO+1))
8220 PORT=$((PORT+1))
8221 N=$((N+1))
8224 NAME=IP6RECV_RANGE
8225 case "$TESTS" in
8226 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
8227 TEST="$NAME: security of IP6-RECV with RANGE option"
8228 if ! eval $NUMCOND; then :;
8229 elif ! feat=$(testfeats ip6 rawip) || ! runsip6 >/dev/null; then
8230 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP6 not available${NORMAL}\n" $N
8231 numCANT=$((numCANT+1))
8232 listCANT="$listCANT $N"
8233 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8234 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8235 numCANT=$((numCANT+1))
8236 listCANT="$listCANT $N"
8237 else
8238 PROTO1=$PROTO; PROTO=$((PROTO+1))
8239 PROTO2=$PROTO
8240 # we use the forward channel (PROTO1) for testing, and have a backward channel
8241 # (PROTO2) to get the data back, so we get the classical echo behaviour
8242 testserversec "$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "range=[::2]/128" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
8243 fi ;; # NUMCOND, feats
8244 esac
8245 PROTO=$((PROTO+1))
8246 N=$((N+1))
8248 NAME=IP6RECV_TCPWRAP
8249 case "$TESTS" in
8250 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
8251 TEST="$NAME: security of IP6-RECV with TCPWRAP option"
8252 if ! eval $NUMCOND; then :;
8253 elif ! feat=$(testfeats ip6 rawip libwrap && runsip6); then
8254 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8255 numCANT=$((numCANT+1))
8256 listCANT="$listCANT $N"
8257 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8258 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8259 numCANT=$((numCANT+1))
8260 listCANT="$listCANT $N"
8261 else
8262 PROTO1=$PROTO; PROTO=$((PROTO+1))
8263 PROTO2=$PROTO
8264 ha="$td/hosts.allow"
8265 hd="$td/hosts.deny"
8266 $ECHO "socat: [::2]" >"$ha"
8267 $ECHO "ALL: ALL" >"$hd"
8268 # we use the forward channel (PROTO1) for testing, and have a backward channel
8269 # (PROTO2) to get the data back, so we get the classical echo behaviour
8270 testserversec "$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "tcpwrap-etc=$td" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
8271 fi ;; # NUMCOND, feats
8272 esac
8273 PROTO=$((PROTO+1))
8274 N=$((N+1))
8277 NAME=O_NOATIME_FILE
8278 case "$TESTS" in
8279 *%$N%*|*%functions%*|*%open%*|*%noatime%*|*%$NAME%*)
8280 TEST="$NAME: option O_NOATIME on file"
8281 # idea: create a file with o-noatime option; one second later create a file
8282 # without this option (using touch); one second later read from the first file.
8283 # Then we check which file has the later ATIME stamp. For this check we use
8284 # "ls -ltu" because it is more portable than "test ... -nt ..."
8285 if ! eval $NUMCOND; then :;
8286 elif ! testoptions o-noatime >/dev/null; then
8287 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
8288 numCANT=$((numCANT+1))
8289 listCANT="$listCANT $N"
8290 else
8291 tf="$td/test$N.file"
8292 te="$td/test$N.stderr"
8293 tdiff="$td/test$N.diff"
8294 da="test$N $(date) $RANDOM"
8295 $PRINTF "test $F_n $TEST... " $N
8296 CMD="$TRACE $SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null"
8297 # generate a file
8298 touch "${tf}1"
8299 sleep 1
8300 # generate a reference file
8301 touch "${tf}2"
8302 sleep 1
8303 # read from the first file
8304 $CMD 2>"$te"
8305 if [ $? -ne 0 ]; then # command failed
8306 $PRINTF "${FAILED}:\n"
8307 echo "$CMD"
8308 cat "$te"
8309 numFAIL=$((numFAIL+1))
8310 listFAIL="$listFAIL $N"
8311 else
8312 # check which file has a later atime stamp
8313 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
8314 then
8315 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8316 echo "$CMD"
8317 cat "$te"
8318 numFAIL=$((numFAIL+1))
8319 listFAIL="$listFAIL $N"
8320 else
8321 $PRINTF "$OK\n"
8322 if [ -n "$debug" ]; then cat "$te"; fi
8323 numOK=$((numOK+1))
8324 fi # wrong time stamps
8325 fi # command ok
8326 fi ;; # NUMCOND, feats
8327 esac
8328 N=$((N+1))
8330 NAME=O_NOATIME_FD
8331 case "$TESTS" in
8332 *%$N%*|*%functions%*|*%noatime%*|*%$NAME%*)
8333 TEST="$NAME: option O_NOATIME on file descriptor"
8334 # idea: use a fd of a file with o-noatime option; one second later create a file
8335 # without this option (using touch); one second later read from the first file.
8336 # Then we check which file has the later ATIME stamp. For this check we use
8337 # "ls -ltu" because it is more portable than "test ... -nt ..."
8338 if ! eval $NUMCOND; then :;
8339 elif ! testoptions o-noatime >/dev/null; then
8340 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
8341 numCANT=$((numCANT+1))
8342 listCANT="$listCANT $N"
8343 else
8344 tf="$td/test$N.file"
8345 te="$td/test$N.stderr"
8346 tdiff="$td/test$N.diff"
8347 da="test$N $(date) $RANDOM"
8348 $PRINTF "test $F_n $TEST... " $N
8349 touch ${tf}1
8350 CMD="$TRACE $SOCAT $opts -u -,o-noatime /dev/null <${tf}1"
8351 # generate a file, len >= 1
8352 touch "${tf}1"
8353 sleep 1
8354 # generate a reference file
8355 touch "${tf}2"
8356 sleep 1
8357 # read from the first file
8358 sh -c "$CMD" 2>"$te"
8359 if [ $? -ne 0 ]; then # command failed
8360 $PRINTF "${FAILED}:\n"
8361 echo "$CMD"
8362 cat "$te"
8363 numFAIL=$((numFAIL+1))
8364 listFAIL="$listFAIL $N"
8365 else
8366 # check which file has a later atime stamp
8367 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
8368 then
8369 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8370 echo "$CMD"
8371 cat "$te"
8372 numFAIL=$((numFAIL+1))
8373 listFAIL="$listFAIL $N"
8374 else
8375 $PRINTF "$OK\n"
8376 if [ -n "$debug" ]; then cat "$te"; fi
8377 numOK=$((numOK+1))
8378 fi # wrong time stamps
8379 fi # command ok
8380 fi ;; # NUMCOND, feats
8381 esac
8382 N=$((N+1))
8384 NAME=FS_NOATIME
8385 case "$TESTS" in
8386 *%$N%*|*%functions%*|*%fs%*|*%noatime%*|*%$NAME%*)
8387 TEST="$NAME: extended file system options using fs noatime option"
8388 # idea: create a file with fs-noatime option; one second later create a file
8389 # without this option (using touch); one second later read from the first file.
8390 # Then we check which file has the later ATIME stamp. For this check we use
8391 # "ls -ltu" because it is more portable than "test ... -nt ..."
8392 if ! eval $NUMCOND; then :;
8393 elif ! testoptions fs-noatime >/dev/null; then
8394 $PRINTF "test $F_n $TEST... ${YELLOW}fs-noatime not available${NORMAL}\n" $N
8395 numCANT=$((numCANT+1))
8396 listCANT="$listCANT $N"
8397 else
8398 ts="$td/test$N.socket"
8399 tf="$td/test$N.file"
8400 te="$td/test$N.stderr"
8401 tdiff="$td/test$N.diff"
8402 ts1="$ts"
8403 da="test$N $(date) $RANDOM"
8404 $PRINTF "test $F_n $TEST... " $N
8405 CMD0="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\""
8406 CMD="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\",fs-noatime"
8407 # check if this is a capable FS; lsattr does other things on AIX, thus socat
8408 $CMD0 2>"${te}0"
8409 if [ $? -ne 0 ]; then
8410 $PRINTF "${YELLOW} cannot test${NORMAL}\n"
8411 numCANT=$((numCANT+1))
8412 listCANT="$listCANT $N"
8413 else
8414 # generate a file with noatime, len >= 1
8415 $CMD 2>"$te"
8416 if [ $? -ne 0 ]; then # command failed
8417 $PRINTF "${YELLOW}impotent file system?${NORMAL}\n"
8418 echo "$CMD"
8419 cat "$te"
8420 numCANT=$((numCANT+1))
8421 listCANT="$listCANT $N"
8422 else
8423 sleep 1
8424 # generate a reference file
8425 touch "${tf}2"
8426 sleep 1
8427 # read from the first file
8428 cat "${tf}1" >/dev/null
8429 # check which file has a later atime stamp
8430 #if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |awk '{print($8);}') != "${tf}2" ];
8431 if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |sed "s|.*\\($td.*\\)|\1|g") != "${tf}2" ];
8432 then
8433 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8434 echo "$CMD"
8435 cat "$te"
8436 numFAIL=$((numFAIL+1))
8437 listFAIL="$listFAIL $N"
8438 else
8439 $PRINTF "$OK\n"
8440 if [ -n "$debug" ]; then cat "$te"; fi
8441 numOK=$((numOK+1))
8443 fi # not impotent
8444 fi # can test
8445 fi ;; # NUMCOND, feats
8446 esac
8447 N=$((N+1))
8450 NAME=COOLWRITE
8451 case "$TESTS" in
8452 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
8453 TEST="$NAME: option cool-write"
8454 if ! eval $NUMCOND; then :;
8455 elif ! testoptions cool-write >/dev/null; then
8456 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8457 numCANT=$((numCANT+1))
8458 listCANT="$listCANT $N"
8459 else
8460 #set -vx
8461 ti="$td/test$N.pipe"
8462 tf="$td/test$N.stdout"
8463 te="$td/test$N.stderr"
8464 tdiff="$td/test$N.diff"
8465 da="test$N $(date) $RANDOM"
8466 # a reader that will terminate after 1 byte
8467 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8468 CMD="$TRACE $SOCAT $opts -u - file:\"$ti\",cool-write"
8469 printf "test $F_n $TEST... " $N
8470 $CMD1 2>"${te}1" &
8471 bg=$! # background process id
8472 sleep 1
8473 (echo .; sleep 1; echo) |$CMD 2>"$te"
8474 rc=$?
8475 kill $bg 2>/dev/null; wait
8476 if [ $rc -ne 0 ]; then
8477 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8478 echo "$CMD &"
8479 cat "$te"
8480 numFAIL=$((numFAIL+1))
8481 listFAIL="$listFAIL $N"
8482 else
8483 $PRINTF "$OK\n"
8484 if [ -n "$debug" ]; then cat "$te"; fi
8485 numOK=$((numOK+1))
8487 fi ;; # NUMCOND, feats
8488 esac
8489 N=$((N+1))
8492 # test if option coolwrite can be applied to bidirectional address stdio
8493 # this failed up to socat 1.6.0.0
8494 NAME=COOLSTDIO
8495 case "$TESTS" in
8496 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
8497 TEST="$NAME: option cool-write on bidirectional stdio"
8498 # this test starts a socat reader that terminates after receiving one+
8499 # bytes (option readbytes); and a test process that sends two bytes via
8500 # named pipe to the receiving process and, a second later, sends another
8501 # byte. The last write will fail with "broken pipe"; if option coolwrite
8502 # has been applied successfully, socat will terminate with 0 (OK),
8503 # otherwise with error.
8504 if ! eval $NUMCOND; then :;
8505 elif ! testoptions cool-write >/dev/null; then
8506 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8507 numCANT=$((numCANT+1))
8508 listCANT="$listCANT $N"
8509 else
8510 #set -vx
8511 ti="$td/test$N.pipe"
8512 tf="$td/test$N.stdout"
8513 te="$td/test$N.stderr"
8514 tdiff="$td/test$N.diff"
8515 da="test$N $(date) $RANDOM"
8516 # a reader that will terminate after 1 byte
8517 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8518 CMD="$TRACE $SOCAT $opts -,cool-write pipe >\"$ti\""
8519 printf "test $F_n $TEST... " $N
8520 $CMD1 2>"${te}1" &
8521 bg=$! # background process id
8522 sleep 1
8523 (echo .; sleep 1; echo) |eval "$CMD" 2>"$te"
8524 rc=$?
8525 kill $bg 2>/dev/null; wait
8526 if [ $rc -ne 0 ]; then
8527 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8528 echo "$CMD &"
8529 cat "$te"
8530 numFAIL=$((numFAIL+1))
8531 listFAIL="$listFAIL $N"
8532 else
8533 $PRINTF "$OK\n"
8534 if [ -n "$debug" ]; then cat "$te"; fi
8535 numOK=$((numOK+1))
8537 fi ;; # NUMCOND, feats
8538 esac
8539 N=$((N+1))
8542 NAME=TCP4ENDCLOSE
8543 case "$TESTS" in
8544 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
8545 TEST="$NAME: end-close keeps TCP V4 socket open"
8546 if ! eval $NUMCOND; then :; else
8547 tf="$td/test$N.stdout"
8548 te="$td/test$N.stderr"
8549 tdiff="$td/test$N.diff"
8550 p1=$PORT; PORT=$((PORT+1))
8551 p2=$PORT
8552 da1a="$(date) $RANDOM"
8553 da1b="$(date) $RANDOM"
8554 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$LOCALHOST:$p1"
8555 CMD="$TRACE $SOCAT $opts -U TCP4:$LOCALHOST:$p2,end-close TCP4-LISTEN:$p1,bind=$LOCALHOST,$REUSEADDR,fork"
8556 CMD3="$TRACE $SOCAT $opts -u TCP4-LISTEN:$p2,$REUSEADDR,bind=$LOCALHOST -"
8557 printf "test $F_n $TEST... " $N
8558 $CMD3 >"$tf" 2>"${te}3" &
8559 pid3=$!
8560 waittcp4port $p2 1
8561 $CMD 2>"${te}2" &
8562 pid2=$!
8563 usleep $MICROS
8564 waittcp4port $p1 1
8565 echo "$da1a" |$CMD1 2>>"${te}1a"
8566 echo "$da1b" |$CMD1 2>>"${te}1b"
8567 sleep 1
8568 kill "$pid3" "$pid2" 2>/dev/null
8569 wait
8570 if [ $? -ne 0 ]; then
8571 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8572 echo "$CMD1 &"
8573 echo "$CMD2"
8574 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8575 numFAIL=$((numFAIL+1))
8576 listFAIL="$listFAIL $N"
8577 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8578 $PRINTF "$FAILED\n"
8579 cat "$tdiff"
8580 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8581 numFAIL=$((numFAIL+1))
8582 listFAIL="$listFAIL $N"
8583 else
8584 $PRINTF "$OK\n"
8585 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2" "${te}3"; fi
8586 numOK=$((numOK+1))
8588 fi ;; # NUMCOND
8589 esac
8590 PORT=$((PORT+1))
8591 N=$((N+1))
8594 NAME=EXECENDCLOSE
8595 case "$TESTS" in
8596 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
8597 TEST="$NAME: end-close keeps EXEC child running"
8598 if ! eval $NUMCOND; then :; else
8599 tf="$td/test$N.stdout"
8600 te="$td/test$N.stderr"
8601 ts="$td/test$N.sock"
8602 tdiff="$td/test$N.diff"
8603 da1a="$(date) $RANDOM"
8604 da1b="$(date) $RANDOM"
8605 CMD1="$TRACE $SOCAT $opts - UNIX-CONNECT:$ts"
8606 CMD="$TRACE $SOCAT $opts EXEC:"$CAT",end-close UNIX-LISTEN:$ts,fork"
8607 printf "test $F_n $TEST... " $N
8608 $CMD 2>"${te}2" &
8609 pid2=$!
8610 waitfile $ts 1
8611 echo "$da1a" |$CMD1 2>>"${te}1a" >"$tf"
8612 usleep $MICROS
8613 echo "$da1b" |$CMD1 2>>"${te}1b" >>"$tf"
8614 #usleep $MICROS
8615 kill "$pid2" 2>/dev/null
8616 wait
8617 if [ $? -ne 0 ]; then
8618 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8619 echo "$CMD1 &"
8620 echo "$CMD2"
8621 cat "${te}1a" "${te}1b" "${te}2"
8622 numFAIL=$((numFAIL+1))
8623 listFAIL="$listFAIL $N"
8624 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8625 $PRINTF "$FAILED\n"
8626 cat "$tdiff"
8627 cat "${te}1a" "${te}1b" "${te}2"
8628 numFAIL=$((numFAIL+1))
8629 listFAIL="$listFAIL $N"
8630 else
8631 $PRINTF "$OK\n"
8632 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2"; fi
8633 numOK=$((numOK+1))
8635 fi ;; # NUMCOND
8636 esac
8637 N=$((N+1))
8640 # up to 1.7.0.0 option end-close led to an error with some address types due to
8641 # bad internal handling. here we check it for address PTY
8642 NAME=PTYENDCLOSE
8643 case "$TESTS" in
8644 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
8645 TEST="$NAME: PTY handles option end-close"
8646 # with the bug, socat exits with error. we invoke socat in a no-op mode and
8647 # check its return status.
8648 if ! eval $NUMCOND; then :;
8649 else
8650 tf="$td/test$N.stout"
8651 te="$td/test$N.stderr"
8652 CMD="$TRACE $SOCAT $opts /dev/null pty,end-close"
8653 printf "test $F_n $TEST... " $N
8654 $CMD 2>"${te}"
8655 rc=$?
8656 if [ "$rc" = 0 ]; then
8657 $PRINTF "$OK\n"
8658 numOK=$((numOK+1))
8659 else
8660 $PRINTF "$FAILED\n"
8661 echo "$CMD"
8662 cat "${te}"
8663 numFAIL=$((numFAIL+1))
8664 listFAIL="$listFAIL $N"
8666 fi # NUMCOND
8668 esac
8669 N=$((N+1))
8672 # Test the shut-null and null-eof options
8673 NAME=SHUTNULLEOF
8674 case "$TESTS" in
8675 *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
8676 TEST="$NAME: options shut-null and null-eof"
8677 # Run a receiving background process with option null-eof.
8678 # Start a sending process with option shut-null that sends a test record to the
8679 # receiving process and then terminates.
8680 # Send another test record.
8681 # When the receiving process only received and stored the first test record the
8682 # test succeeded
8683 if ! eval $NUMCOND; then :; else
8684 tf="$td/test$N.stout"
8685 te="$td/test$N.stderr"
8686 tdiff="$td/test$N.diff"
8687 da="test$N $(date) $RANDOM"
8688 CMD0="$TRACE $SOCAT $opts -u UDP-RECV:$PORT,null-eof CREAT:$tf"
8689 CMD1="$TRACE $SOCAT $opts -u - UDP-SENDTO:127.0.0.1:$PORT,shut-null"
8690 printf "test $F_n $TEST... " $N
8691 $CMD0 >/dev/null 2>"${te}0" &
8692 pid0=$!
8693 waitudp4port $PORT 1
8694 { echo "$da"; sleep 0.1; } |$CMD1 >"${tf}1" 2>"${te}1"
8695 rc1=$?
8696 { echo "xyz"; sleep 0.1; } |$CMD1 >"${tf}2" 2>"${te}2"
8697 rc2=$?
8698 kill $pid0 2>/dev/null; wait
8699 if [ $rc1 != 0 -o $rc2 != 0 ]; then
8700 $PRINTF "$FAILED\n"
8701 echo "$CMD0 &"
8702 echo "$CMD1"
8703 cat "${te}0"
8704 cat "${te}1"
8705 cat "${te}2"
8706 numFAIL=$((numFAIL+1))
8707 listFAIL="$listFAIL $N"
8708 elif echo "$da" |diff - "${tf}" >"$tdiff"; then
8709 $PRINTF "$OK\n"
8710 numOK=$((numOK+1))
8711 else
8712 $PRINTF "$FAILED\n"
8713 echo "$CMD0 &"
8714 echo "$CMD1"
8715 cat "${te}0"
8716 cat "${te}1"
8717 cat "${tdiff}"
8718 numFAIL=$((numFAIL+1))
8719 listFAIL="$listFAIL $N"
8721 fi # NUMCOND
8723 esac
8724 N=$((N+1))
8727 NAME=UDP6LISTENBIND
8728 # this tests for a bug in (up to) 1.5.0.0:
8729 # with udp*-listen, the bind option supported only IPv4
8730 case "$TESTS" in
8731 *%$N%*|*%functions%*|*%bugs%*|*%ip6%*|*%ipapp%*|*%udp%*|*%udp6%*|*%$NAME%*)
8732 TEST="$NAME: UDP6-LISTEN with bind"
8733 if ! eval $NUMCOND; then :;
8734 elif ! feat=$(testfeats udp ip6) || ! runsip6 >/dev/null; then
8735 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8736 numCANT=$((numCANT+1))
8737 listCANT="$listCANT $N"
8738 else
8739 tf="$td/test$N.stdout"
8740 te="$td/test$N.stderr"
8741 tdiff="$td/test$N.diff"
8742 tsl=$PORT
8743 ts="$LOCALHOST6:$tsl"
8744 da="test$N $(date) $RANDOM"
8745 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR,bind=$LOCALHOST6 PIPE"
8746 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
8747 printf "test $F_n $TEST... " $N
8748 $CMD1 >"$tf" 2>"${te}1" &
8749 pid1=$!
8750 waitudp6port $tsl 1
8751 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8752 rc2=$?
8753 kill $pid1 2>/dev/null; wait
8754 if [ $rc2 -ne 0 ]; then
8755 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8756 echo "$CMD1 &"
8757 echo "$CMD2"
8758 cat "${te}1" "${te}2"
8759 numFAIL=$((numFAIL+1))
8760 listFAIL="$listFAIL $N"
8761 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8762 $PRINTF "$FAILED\n"
8763 cat "$tdiff"
8764 numFAIL=$((numFAIL+1))
8765 listFAIL="$listFAIL $N"
8766 else
8767 $PRINTF "$OK\n"
8768 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8769 numOK=$((numOK+1))
8771 fi ;; # NUMCOND, feats
8772 esac
8773 PORT=$((PORT+1))
8774 N=$((N+1))
8777 NAME=TCPWRAPPERS_MULTIOPTS
8778 # this tests for a bug in 1.5.0.0 that let socat fail when more than one
8779 # tcp-wrappers related option was specified in one address
8780 case "$TESTS" in
8781 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
8782 TEST="$NAME: use of multiple tcpwrapper enabling options"
8783 if ! eval $NUMCOND; then :;
8784 elif ! feat=$(testfeats tcp ip4 libwrap) || ! runsip4 >/dev/null; then
8785 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8786 numCANT=$((numCANT+1))
8787 listCANT="$listCANT $N"
8788 else
8789 tf="$td/test$N.stdout"
8790 te="$td/test$N.stderr"
8791 tdiff="$td/test$N.diff"
8792 da="test$N $(date) $RANDOM"
8793 ha="$td/hosts.allow"
8794 $ECHO "test : ALL : allow" >"$ha"
8795 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,hosts-allow=$ha,tcpwrap=test pipe"
8796 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
8797 printf "test $F_n $TEST... " $N
8798 $CMD1 2>"${te}1" &
8799 pid1=$!
8800 waittcp4port $PORT
8801 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8802 rc2=$?
8803 kill $pid1 2>/dev/null; wait
8804 if [ $rc2 -ne 0 ]; then
8805 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8806 echo "$CMD1 &"
8807 echo "$CMD2"
8808 cat "${te}1"
8809 cat "${te}2"
8810 numFAIL=$((numFAIL+1))
8811 listFAIL="$listFAIL $N"
8812 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8813 $PRINTF "$FAILED\n"
8814 cat "$tdiff"
8815 numFAIL=$((numFAIL+1))
8816 listFAIL="$listFAIL $N"
8817 else
8818 $PRINTF "$OK\n"
8819 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8820 numOK=$((numOK+1))
8822 fi ;; # NUMCOND, feats
8823 esac
8824 PORT=$((PORT+1))
8825 N=$((N+1))
8828 NAME=TCPWRAPPERS_TCP6ADDR
8829 # this tests for a bug in 1.5.0.0 that brought false results with tcp-wrappers
8830 # and IPv6 when
8831 case "$TESTS" in
8832 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
8833 TEST="$NAME: specification of TCP6 address in hosts.allow"
8834 if ! eval $NUMCOND; then :;
8835 elif ! feat=$(testfeats tcp ip6 libwrap && runsip6); then
8836 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8837 numCANT=$((numCANT+1))
8838 listCANT="$listCANT $N"
8839 else
8840 tf="$td/test$N.stdout"
8841 te="$td/test$N.stderr"
8842 tdiff="$td/test$N.diff"
8843 da="test$N $(date) $RANDOM"
8844 ha="$td/hosts.allow"
8845 hd="$td/hosts.deny"
8846 $ECHO "socat : [::1] : allow" >"$ha"
8847 $ECHO "ALL : ALL : deny" >"$hd"
8848 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$PORT,$REUSEADDR,tcpwrap-etc=$td,tcpwrappers=socat pipe"
8849 CMD2="$TRACE $SOCAT $opts - TCP6:[::1]:$PORT"
8850 printf "test $F_n $TEST... " $N
8851 $CMD1 2>"${te}1" &
8852 pid1=$!
8853 waittcp6port $PORT
8854 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8855 rc2=$?
8856 kill $pid1 2>/dev/null; wait
8857 if [ $rc2 -ne 0 ]; then
8858 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8859 echo "$CMD1 &"
8860 echo "$CMD2"
8861 cat "${te}1"
8862 cat "${te}2"
8863 numFAIL=$((numFAIL+1))
8864 listFAIL="$listFAIL $N"
8865 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8866 $PRINTF "$FAILED\n"
8867 cat "$tdiff"
8868 numFAIL=$((numFAIL+1))
8869 listFAIL="$listFAIL $N"
8870 else
8871 $PRINTF "$OK\n"
8872 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8873 numOK=$((numOK+1))
8875 fi ;; # NUMCOND, feats
8876 esac
8877 PORT=$((PORT+1))
8878 N=$((N+1))
8881 NAME=UDP4BROADCAST
8882 case "$TESTS" in
8883 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%$NAME%*)
8884 TEST="$NAME: UDP/IPv4 broadcast"
8885 if ! eval $NUMCOND; then :;
8886 elif [ -z "$BCADDR" ]; then
8887 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8888 numCANT=$((numCANT+1))
8889 listCANT="$listCANT $N"
8890 else
8891 tf="$td/test$N.stdout"
8892 te="$td/test$N.stderr"
8893 tdiff="$td/test$N.diff"
8894 ts1p=$PORT; PORT=$((PORT+1))
8895 #ts1="$BCADDR/8:$ts1p"
8896 ts1="$BCADDR:$ts1p"
8897 ts2p=$PORT; PORT=$((PORT+1))
8898 ts2="$BCIFADDR:$ts2p"
8899 da="test$N $(date) $RANDOM"
8900 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE"
8901 #CMD2="$TRACE $SOCAT $opts - UDP4-BROADCAST:$ts1"
8902 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast"
8903 printf "test $F_n $TEST... " $N
8904 $CMD1 2>"${te}1" &
8905 pid1="$!"
8906 waitudp4port $ts1p 1
8907 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8908 rc2="$?"
8909 kill "$pid1" 2>/dev/null; wait;
8910 if [ "$rc2" -ne 0 ]; then
8911 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8912 echo "$CMD1 &"
8913 echo "$CMD2"
8914 cat "${te}1"
8915 cat "${te}2"
8916 numFAIL=$((numFAIL+1))
8917 listFAIL="$listFAIL $N"
8918 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8919 $PRINTF "$FAILED\n"
8920 cat "$tdiff"
8921 numFAIL=$((numFAIL+1))
8922 listFAIL="$listFAIL $N"
8923 else
8924 $PRINTF "$OK\n"
8925 if [ -n "$tut" ]; then
8926 echo "$CMD1 &"
8927 echo "$CMD2"
8929 if [ -n "$debug" ]; then cat $te; fi
8930 numOK=$((numOK+1))
8932 fi ;; # NUMCOND, feats
8933 esac
8934 N=$((N+1))
8937 NAME=IP4BROADCAST
8938 # test a local broadcast of a raw IPv4 protocol.
8939 # because we receive - in addition to the regular reply - our own broadcast,
8940 # we use a token XXXX that is changed to YYYY in the regular reply packet.
8941 case "$TESTS" in
8942 *%$N%*|*%functions%*|*%engine%*|*%rawip%*|*%rawip4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%root%*|*%$NAME%*)
8943 TEST="$NAME: raw IPv4 broadcast"
8944 if ! eval $NUMCOND; then :;
8945 elif ! feat=$(testfeats ip4 rawip) || ! runsip4 >/dev/null; then
8946 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP4 not available${NORMAL}\n" $N
8947 numCANT=$((numCANT+1))
8948 listCANT="$listCANT $N"
8949 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8950 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8951 numCANT=$((numCANT+1))
8952 listCANT="$listCANT $N"
8953 elif [ -z "$BCADDR" ]; then
8954 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8955 else
8956 tf="$td/test$N.stdout"
8957 te="$td/test$N.stderr"
8958 tdiff="$td/test$N.diff"
8959 ts1p=$PROTO
8960 #ts1="$BCADDR/8:$ts1p"
8961 ts1="$BCADDR:$ts1p"
8962 ts2p=$ts1p
8963 ts2="$BCIFADDR"
8964 da="test$N $(date) $RANDOM XXXX"
8965 sh="$td/test$N-sed.sh"
8966 echo 'sed s/XXXX/YYYY/' >"$sh"
8967 chmod a+x "$sh"
8968 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,broadcast exec:$sh"
8969 #CMD2="$TRACE $SOCAT $opts - IP4-BROADCAST:$ts1"
8970 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:$ts1,broadcast"
8971 printf "test $F_n $TEST... " $N
8972 $CMD1 2>"${te}1" &
8973 pid1="$!"
8974 waitip4port $ts1p 1
8975 echo "$da" |$CMD2 2>>"${te}2" |grep -v XXXX >>"$tf"
8976 rc2="$?"
8977 kill "$pid1" 2>/dev/null; wait;
8978 if [ "$rc2" -ne 0 ]; then
8979 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8980 echo "$CMD1 &"
8981 echo "$CMD2"
8982 cat "${te}1"
8983 cat "${te}2"
8984 numFAIL=$((numFAIL+1))
8985 listFAIL="$listFAIL $N"
8986 elif ! echo "$da" | sed 's/XXXX/YYYY/'|diff - "$tf" >"$tdiff"; then
8987 $PRINTF "$FAILED\n"
8988 cat "$tdiff"
8989 numFAIL=$((numFAIL+1))
8990 listFAIL="$listFAIL $N"
8991 else
8992 $PRINTF "$OK\n"
8993 if [ -n "$debug" ]; then cat $te; fi
8994 numOK=$((numOK+1))
8996 fi ;; # NUMCOND, feats
8997 esac
8998 PROTO=$((PROTO+1))
8999 N=$((N+1))
9002 #NAME=UDP4BROADCAST_RANGE
9003 #case "$TESTS" in
9004 #*%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%range%*|*%$NAME%*)
9005 #TEST="$NAME: security of UDP4-BROADCAST with RANGE option"
9006 #if ! eval $NUMCOND; then :;
9007 #elif [ -z "$BCADDR" ]; then
9008 # $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
9009 #else
9010 #testserversec "$N" "$TEST" "$opts" "UDP4-BROADCAST:$BCADDR/8:$PORT" "" "range=127.1.0.0:255.255.0.0" "udp4:127.1.0.0:$PORT" 4 udp $PORT 0
9011 #fi ;; # NUMCOND, feats
9012 #esac
9013 #PORT=$((PORT+1))
9014 #N=$((N+1))
9017 NAME=UDP4MULTICAST_UNIDIR
9018 case "$TESTS" in
9019 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
9020 TEST="$NAME: UDP/IPv4 multicast, send only"
9021 if ! eval $NUMCOND; then :;
9022 elif ! feat=$(testfeats ip4 udp) || ! runsip4 >/dev/null; then
9023 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9024 numCANT=$((numCANT+1))
9025 listCANT="$listCANT $N"
9026 else
9027 tf="$td/test$N.stdout"
9028 te="$td/test$N.stderr"
9029 tdiff="$td/test$N.diff"
9030 ts1p=$PORT; PORT=$((PORT+1))
9031 ts1a="$SECONDADDR"
9032 ts1="$ts1a:$ts1p"
9033 da="test$N $(date) $RANDOM"
9034 CMD1="$TRACE $SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
9035 CMD2="$TRACE $SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
9036 printf "test $F_n $TEST... " $N
9037 $CMD1 2>"${te}1" >"${tf}" &
9038 pid1="$!"
9039 waitudp4port $ts1p 1
9040 echo "$da" |$CMD2 2>>"${te}2"
9041 rc2="$?"
9042 usleep $MICROS
9043 kill "$pid1" 2>/dev/null; wait;
9044 if [ "$rc2" -ne 0 ]; then
9045 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9046 echo "$CMD1 &"
9047 echo "$CMD2"
9048 cat "${te}1"
9049 cat "${te}2"
9050 numFAIL=$((numFAIL+1))
9051 listFAIL="$listFAIL $N"
9052 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9053 $PRINTF "$FAILED\n"
9054 cat "$tdiff"
9055 numFAIL=$((numFAIL+1))
9056 listFAIL="$listFAIL $N"
9057 else
9058 $PRINTF "$OK\n"
9059 if [ -n "$debug" ]; then cat $te; fi
9060 numOK=$((numOK+1))
9062 fi ;; # NUMCOND, feats
9063 esac
9064 N=$((N+1))
9066 NAME=IP4MULTICAST_UNIDIR
9067 case "$TESTS" in
9068 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
9069 TEST="$NAME: IPv4 multicast"
9070 if ! eval $NUMCOND; then :;
9071 elif ! feat=$(testfeats ip4 rawip) || ! runsip4 >/dev/null; then
9072 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9073 numCANT=$((numCANT+1))
9074 listCANT="$listCANT $N"
9075 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9076 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9077 numCANT=$((numCANT+1))
9078 listCANT="$listCANT $N"
9079 else
9080 tf="$td/test$N.stdout"
9081 te="$td/test$N.stderr"
9082 tdiff="$td/test$N.diff"
9083 ts1p=$PROTO
9084 ts1a="$SECONDADDR"
9085 ts1="$ts1a:$ts1p"
9086 da="test$N $(date) $RANDOM"
9087 CMD1="$TRACE $SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
9088 CMD2="$TRACE $SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
9089 printf "test $F_n $TEST... " $N
9090 $CMD1 2>"${te}1" >"${tf}" &
9091 pid1="$!"
9092 waitip4proto $ts1p 1
9093 usleep $MICROS
9094 echo "$da" |$CMD2 2>>"${te}2"
9095 rc2="$?"
9096 #usleep $MICROS
9097 sleep 1
9098 kill "$pid1" 2>/dev/null; wait;
9099 if [ "$rc2" -ne 0 ]; then
9100 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9101 echo "$CMD1 &"
9102 echo "$CMD2"
9103 cat "${te}1"
9104 cat "${te}2"
9105 numFAIL=$((numFAIL+1))
9106 listFAIL="$listFAIL $N"
9107 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9108 $PRINTF "$FAILED\n"
9109 cat "$tdiff"
9110 numFAIL=$((numFAIL+1))
9111 listFAIL="$listFAIL $N"
9112 else
9113 $PRINTF "$OK\n"
9114 if [ -n "$debug" ]; then cat $te; fi
9115 numOK=$((numOK+1))
9117 fi ;; # NUMCOND, feats
9118 esac
9119 PROTO=$((PROTO+1))
9120 N=$((N+1))
9122 if true; then
9123 # This test succeeds, e.g., on CentOS-7 with kernel 3.10.0, Ubuntu-16.04 with 4.4.0
9124 # but fails, e.g., on Ubuntu-18.04 with kernel 4.15.0, CentOS-8 with 4.10.0
9125 NAME=UDP6MULTICAST_UNIDIR
9126 case "$TESTS" in
9127 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%multicast%*|*%$NAME%*)
9128 TEST="$NAME: UDP/IPv6 multicast"
9129 if ! eval $NUMCOND; then :;
9130 elif ! feat=$(testfeats ip6 udp && runsip6); then
9131 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9132 numCANT=$((numCANT+1))
9133 listCANT="$listCANT $N"
9134 else
9135 tf="$td/test$N.stdout"
9136 te="$td/test$N.stderr"
9137 tdiff="$td/test$N.diff"
9138 ts1p=$PORT; PORT=$((PORT+1))
9139 if1="$MCINTERFACE"
9140 ts1a="[::1]"
9141 da="test$N $(date) $RANDOM"
9142 CMD1="$TRACE $SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -"
9143 CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a"
9144 #CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p"
9145 printf "test $F_n $TEST... " $N
9146 $CMD1 2>"${te}1" >"${tf}" &
9147 pid1="$!"
9148 waitudp6port $ts1p 1
9149 echo "$da" |$CMD2 2>>"${te}2"
9150 rc2="$?"
9151 usleep $MICROS
9152 kill "$pid1" 2>/dev/null; wait;
9153 if [ "$rc2" -ne 0 ]; then
9154 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9155 echo -e "$CMD1 &\n$CMD2"
9156 cat "${te}1"
9157 cat "${te}2"
9158 numFAIL=$((numFAIL+1))
9159 listFAIL="$listFAIL $N"
9160 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9161 if ! [ "$UNAME" = Linux ] || ! [[ $(uname -r) =~ ^2\.* ]] || ! [[ ^3\.* ]] || ! [[ ^4\.[0-4]\.* ]]; then
9162 $PRINTF "${YELLOW}works only on Linux up to about 4.4${NORMAL}\n" $N
9163 numCANT=$((numCANT+1))
9164 listCANT="$listCANT $N"
9165 else
9166 $PRINTF "$FAILED\n"
9167 echo "$CMD1 &"
9168 echo "$CMD2"
9169 cat "$tdiff"
9170 numFAIL=$((numFAIL+1))
9171 listFAIL="$listFAIL $N"
9173 else
9174 $PRINTF "$OK\n"
9175 if [ "$VERBOSE" ]; then echo -e "$CMD1 &\n$CMD2"; fi
9176 if [ -n "$debug" ]; then cat $te; fi
9177 numOK=$((numOK+1))
9179 fi ;; # NUMCOND, feats
9180 esac
9181 N=$((N+1))
9182 fi # false
9184 NAME=UDP4MULTICAST_BIDIR
9185 case "$TESTS" in
9186 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
9187 TEST="$NAME: UDP/IPv4 multicast, with reply"
9188 if ! eval $NUMCOND; then :; else
9189 tf="$td/test$N.stdout"
9190 te="$td/test$N.stderr"
9191 tdiff="$td/test$N.diff"
9192 ts1p=$PORT; PORT=$((PORT+1))
9193 ts1a="$SECONDADDR"
9194 ts1="$ts1a:$ts1p"
9195 ts2p=$PORT; PORT=$((PORT+1))
9196 ts2="$BCIFADDR:$ts2p"
9197 da="test$N $(date) $RANDOM"
9198 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
9199 #CMD2="$TRACE $SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
9200 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
9201 printf "test $F_n $TEST... " $N
9202 $CMD1 2>"${te}1" &
9203 pid1="$!"
9204 waitudp4port $ts1p 1
9205 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9206 rc2="$?"
9207 kill "$pid1" 2>/dev/null; wait;
9208 if [ "$rc2" -ne 0 ]; then
9209 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9210 echo "$CMD1 &"
9211 echo "$CMD2"
9212 cat "${te}1"
9213 cat "${te}2"
9214 numFAIL=$((numFAIL+1))
9215 listFAIL="$listFAIL $N"
9216 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9217 $PRINTF "$FAILED\n"
9218 cat "$tdiff"
9219 numFAIL=$((numFAIL+1))
9220 listFAIL="$listFAIL $N"
9221 else
9222 $PRINTF "$OK\n"
9223 if [ -n "$VERBOSE" ]; then
9224 echo "$CMD1 &"
9225 echo "$CMD2"
9227 if [ -n "$debug" ]; then cat $te; fi
9228 numOK=$((numOK+1))
9230 fi ;; # NUMCOND
9231 esac
9232 N=$((N+1))
9234 NAME=IP4MULTICAST_BIDIR
9235 case "$TESTS" in
9236 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
9237 TEST="$NAME: IPv4 multicast, with reply"
9238 if ! eval $NUMCOND; then :;
9239 elif ! feat=$(testfeats ip4 rawip) || ! runsip4 >/dev/null; then
9240 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9241 numCANT=$((numCANT+1))
9242 listCANT="$listCANT $N"
9243 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9244 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9245 numCANT=$((numCANT+1))
9246 listCANT="$listCANT $N"
9247 else
9248 tf="$td/test$N.stdout"
9249 te="$td/test$N.stderr"
9250 tdiff="$td/test$N.diff"
9251 ts1p=$PROTO
9252 ts1a="$SECONDADDR"
9253 ts1="$ts1a:$ts1p"
9254 da="test$N $(date) $RANDOM"
9255 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
9256 #CMD2="$TRACE $SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
9257 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
9258 printf "test $F_n $TEST... " $N
9259 $CMD1 2>"${te}1" &
9260 pid1="$!"
9261 waitip4port $ts1p 1
9262 usleep 100000 # give process a chance to add multicast membership
9263 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9264 rc2="$?"
9265 kill "$pid1" 2>/dev/null; wait;
9266 if [ "$rc2" -ne 0 ]; then
9267 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9268 echo "$CMD1 &"
9269 echo "$CMD2"
9270 cat "${te}1"
9271 cat "${te}2"
9272 numFAIL=$((numFAIL+1))
9273 listFAIL="$listFAIL $N"
9274 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9275 $PRINTF "$FAILED\n"
9276 cat "$tdiff"
9277 numFAIL=$((numFAIL+1))
9278 listFAIL="$listFAIL $N"
9279 else
9280 $PRINTF "$OK\n"
9281 if [ -n "$tut" ]; then
9282 echo "$CMD1 &"
9283 echo "$CMD2"
9285 if [ -n "$debug" ]; then cat $te; fi
9286 numOK=$((numOK+1))
9288 fi ;; # NUMCOND, feats
9289 esac
9290 PROTO=$((PROTO+1))
9291 N=$((N+1))
9294 NAME=TUNREAD
9295 case "$TESTS" in
9296 *%$N%*|*%functions%*|*%tun%*|*%root%*|*%$NAME%*)
9297 TEST="$NAME: reading data sent through tun interface"
9298 #idea: create a TUN interface and send a datagram to one of the addresses of
9299 # its virtual network. On the tunnel side, read the packet and compare its last
9300 # bytes with the datagram payload
9301 if ! eval $NUMCOND; then :;
9302 elif ! feat=$(testfeats ip4 tun) || ! runsip4 >/dev/null; then
9303 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9304 numCANT=$((numCANT+1))
9305 listCANT="$listCANT $N"
9306 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9307 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9308 numCANT=$((numCANT+1))
9309 listCANT="$listCANT $N"
9310 else
9311 tf="$td/test$N.stdout"
9312 te="$td/test$N.stderr"
9313 tdiff="$td/test$N.diff"
9314 tl="$td/test$N.lock"
9315 da="test$N $(date) $RANDOM"
9316 dalen=$((${#da}+1))
9317 TUNNET=10.255.255
9318 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT"
9319 #CMD="$TRACE $SOCAT $opts -u -L $tl TUN,ifaddr=$TUNNET.1,netmask=255.255.255.0,iff-up=1 -"
9320 CMD="$TRACE $SOCAT $opts -u -L $tl TUN:$TUNNET.1/24,iff-up=1 -"
9321 printf "test $F_n $TEST... " $N
9322 $CMD 2>"${te}" |tail -c $dalen >"${tf}" &
9323 sleep 1
9324 echo "$da" |$CMD1 2>"${te}1"
9325 sleep 1
9326 kill "$(cat $tl 2>/dev/null)" 2>/dev/null
9327 wait
9328 if [ $? -ne 0 ]; then
9329 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9330 echo "$CMD &"
9331 echo "$CMD1"
9332 cat "${te}" "${te}1"
9333 numFAIL=$((numFAIL+1))
9334 listFAIL="$listFAIL $N"
9335 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9336 $PRINTF "$FAILED\n"
9337 echo "$CMD &"
9338 echo "$CMD1"
9339 cat "$tdiff"
9340 cat "${te}" "${te}1"
9341 numFAIL=$((numFAIL+1))
9342 listFAIL="$listFAIL $N"
9343 else
9344 $PRINTF "$OK\n"
9345 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
9346 numOK=$((numOK+1))
9348 fi ;; # NUMCOND, feats
9349 esac
9350 PORT=$((PORT+1))
9351 N=$((N+1))
9354 # use the INTERFACE address on a tun/tap device and transfer data fully
9355 # transparent
9356 NAME=TUNINTERFACE
9357 case "$TESTS" in
9358 *%$N%*|*%functions%*|*%tun%*|*%interface%*|*%root%*|*%$NAME%*)
9359 TEST="$NAME: pass data through tun interface using INTERFACE"
9360 #idea: create a TUN interface and send a raw packet on the interface side.
9361 # It should arrive unmodified on the tunnel side.
9362 if ! eval $NUMCOND; then :;
9363 elif ! feat=$(testfeats ip4 tun interface) || ! runsip4 >/dev/null; then
9364 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9365 numCANT=$((numCANT+1))
9366 listCANT="$listCANT $N"
9367 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9368 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9369 numCANT=$((numCANT+1))
9370 listCANT="$listCANT $N"
9371 else
9372 tf="$td/test$N.stdout"
9373 te="$td/test$N.stderr"
9374 tdiff="$td/test$N.diff"
9375 tl="$td/test$N.lock"
9376 da="$(date) $RANDOM"
9377 dalen=$((${#da}+1))
9378 TUNNET=10.255.255
9379 TUNNAME=tun9
9380 CMD1="$TRACE $SOCAT $opts -L $tl TUN:$TUNNET.1/24,iff-up=1,tun-type=tun,tun-name=$TUNNAME echo"
9381 CMD="$TRACE $SOCAT $opts - INTERFACE:$TUNNAME"
9382 printf "test $F_n $TEST... " $N
9383 $CMD1 2>"${te}1" &
9384 pid1="$!"
9385 #waitinterface "$TUNNAME"
9386 sleep 1
9387 echo "$da" |$CMD 2>"${te}1" >"$tf" 2>"${te}"
9388 kill $pid1 2>/dev/null
9389 wait
9390 if [ $? -ne 0 ]; then
9391 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9392 echo "$CMD &"
9393 echo "$CMD1"
9394 cat "${te}" "${te}1"
9395 numFAIL=$((numFAIL+1))
9396 listFAIL="$listFAIL $N"
9397 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9398 $PRINTF "$FAILED\n"
9399 echo "$CMD &"
9400 echo "$CMD1"
9401 cat "$tdiff"
9402 cat "${te}" "${te}1"
9403 numFAIL=$((numFAIL+1))
9404 listFAIL="$listFAIL $N"
9405 else
9406 $PRINTF "$OK\n"
9407 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
9408 numOK=$((numOK+1))
9410 fi ;; # NUMCOND, feats
9411 esac
9412 PORT=$((PORT+1))
9413 N=$((N+1))
9416 NAME=ABSTRACTSTREAM
9417 case "$TESTS" in
9418 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%connect%*|*%listen%*|*%$NAME%*)
9419 TEST="$NAME: abstract UNIX stream socket, listen and connect"
9420 if ! eval $NUMCOND; then :;
9421 elif ! feat=$(testfeats abstract-unixsocket); then
9422 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9423 numCANT=$((numCANT+1))
9424 listCANT="$listCANT $N"
9425 else
9426 ts="$td/test$N.socket"
9427 tf="$td/test$N.stdout"
9428 te="$td/test$N.stderr"
9429 tdiff="$td/test$N.diff"
9430 da1="test$N $(date) $RANDOM"
9431 #establish a listening abstract unix socket
9432 SRV="$TRACE $SOCAT $opts -lpserver ABSTRACT-LISTEN:\"$ts\",$REUSEADDR PIPE"
9433 #make a connection
9434 CMD="$TRACE $SOCAT $opts - ABSTRACT-CONNECT:$ts"
9435 $PRINTF "test $F_n $TEST... " $N
9436 touch "$ts" # make a file with same name, so non-abstract fails
9437 eval "$SRV 2>${te}s &"
9438 pids=$!
9439 #waitfile "$ts"
9440 sleep 1
9441 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
9442 if [ $? -ne 0 ]; then
9443 kill "$pids" 2>/dev/null
9444 $PRINTF "$FAILED:\n"
9445 echo "$SRV &"
9446 cat "${te}s"
9447 echo "$CMD"
9448 cat "${te}1"
9449 numFAIL=$((numFAIL+1))
9450 listFAIL="$listFAIL $N"
9451 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
9452 kill "$pids" 2>/dev/null
9453 $PRINTF "$FAILED:\n"
9454 echo "$SRV &"
9455 cat "${te}s"
9456 echo "$CMD"
9457 cat "${te}1"
9458 cat "$tdiff"
9459 numFAIL=$((numFAIL+1))
9460 listFAIL="$listFAIL $N"
9461 else
9462 $PRINTF "$OK\n"
9463 if [ -n "$debug" ]; then cat $te; fi
9464 numOK=$((numOK+1))
9465 fi # !(rc -ne 0)
9466 wait
9467 fi ;; # NUMCOND, feats
9468 esac
9469 N=$((N+1))
9472 NAME=ABSTRACTDGRAM
9473 case "$TESTS" in
9474 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%$NAME%*)
9475 TEST="$NAME: abstract UNIX datagram"
9476 if ! eval $NUMCOND; then :;
9477 elif ! feat=$(testfeats abstract-unixsocket); then
9478 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9479 numCANT=$((numCANT+1))
9480 listCANT="$listCANT $N"
9481 else
9482 tf="$td/test$N.stdout"
9483 te="$td/test$N.stderr"
9484 tdiff="$td/test$N.diff"
9485 ts1="$td/test$N.socket1"
9486 ts2="$td/test$N.socket2"
9487 da="test$N $(date) $RANDOM"
9488 CMD1="$TRACE $SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE"
9489 #CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9490 CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9491 printf "test $F_n $TEST... " $N
9492 touch "$ts1" # make a file with same name, so non-abstract fails
9493 $CMD1 2>"${te}1" &
9494 pid1="$!"
9495 sleep 1
9496 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9497 rc2=$?
9498 kill "$pid1" 2>/dev/null; wait
9499 if [ $rc2 -ne 0 ]; then
9500 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9501 echo "$CMD1 &"
9502 cat "${te}1"
9503 echo "$CMD2"
9504 cat "${te}2"
9505 numFAIL=$((numFAIL+1))
9506 listFAIL="$listFAIL $N"
9507 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9508 $PRINTF "$FAILED\n"
9509 cat "$tdiff"
9510 numFAIL=$((numFAIL+1))
9511 listFAIL="$listFAIL $N"
9512 else
9513 $PRINTF "$OK\n"
9514 if [ -n "$debug" ]; then cat $te; fi
9515 numOK=$((numOK+1))
9517 fi ;; # NUMCOND, feats
9518 esac
9519 N=$((N+1))
9522 NAME=ABSTRACTRECV
9523 case "$TESTS" in
9524 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%recv%*|*%$NAME%*)
9525 TEST="$NAME: abstract UNIX datagram receive"
9526 if ! eval $NUMCOND; then :;
9527 elif ! feat=$(testfeats abstract-unixsocket); then
9528 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9529 numCANT=$((numCANT+1))
9530 listCANT="$listCANT $N"
9531 else
9532 ts="$td/test$N.socket"
9533 tf="$td/test$N.stdout"
9534 te="$td/test$N.stderr"
9535 tdiff="$td/test$N.diff"
9536 ts1="$ts"
9537 da="test$N $(date) $RANDOM"
9538 CMD1="$TRACE $SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -"
9539 CMD2="$TRACE $SOCAT $opts -u - ABSTRACT-SENDTO:$ts1"
9540 printf "test $F_n $TEST... " $N
9541 touch "$ts1" # make a file with same name, so non-abstract fails
9542 $CMD1 >"$tf" 2>"${te}1" &
9543 pid1="$!"
9544 #waitfile $ts1 1
9545 sleep 1
9546 echo "$da" |$CMD2 2>>"${te}2"
9547 rc2="$?"
9548 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9549 kill "$pid1" 2>/dev/null; wait
9550 if [ "$rc2" -ne 0 ]; then
9551 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9552 echo "$CMD1 &"
9553 echo "$CMD2"
9554 cat "${te}1"
9555 cat "${te}2"
9556 numFAIL=$((numFAIL+1))
9557 listFAIL="$listFAIL $N"
9558 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9559 $PRINTF "$FAILED\n"
9560 cat "$tdiff"
9561 numFAIL=$((numFAIL+1))
9562 listFAIL="$listFAIL $N"
9563 else
9564 $PRINTF "$OK\n"
9565 if [ -n "$debug" ]; then cat $te; fi
9566 numOK=$((numOK+1))
9568 fi ;; # NUMCOND, feats
9569 esac
9570 N=$((N+1))
9573 # bind with Linux abstract UNIX domain addresses bound to filesystem socket
9574 # instead of abstract namespace
9575 NAME=ABSTRACT_BIND
9576 case "$TESTS" in
9577 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
9578 TEST="$NAME: abstract bind"
9579 # open an abstract client address with bind option, bind to the target socket.
9580 # send a datagram.
9581 # when socat outputs the datagram it got the test succeeded
9582 if ! eval $NUMCOND; then :;
9583 elif [ "$UNAME" != Linux ]; then
9584 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
9585 numCANT=$((numCANT+1))
9586 listCANT="$listCANT $N"
9587 else
9588 tf="$td/test$N.stdout"
9589 te="$td/test$N.stderr"
9590 tdiff="$td/test$N.diff"
9591 ts1="$td/test$N.sock1"
9592 da="test$N $(date) $RANDOM"
9593 CMD1="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts1"
9594 printf "test $F_n $TEST... " $N
9595 echo "$da" |$CMD1 >$tf 2>"${te}1"
9596 rc1=$?
9597 if [ $rc1 -ne 0 ]; then
9598 $PRINTF "$FAILED\n"
9599 echo "$CMD1" >&2
9600 echo "rc=$rc1" >&2
9601 cat "${te}1" >&2
9602 numFAIL=$((numFAIL+1))
9603 listFAIL="$listFAIL $N"
9604 elif echo "$da" |diff -q - $tf; then
9605 $PRINTF "$OK\n"
9606 numOK=$((numOK+1))
9607 else
9608 $PRINTF "$FAILED\n"
9609 echo "$CMD1" >&2
9610 cat "${te}1" >&2
9611 echo "$da" |diff - "$tf" >&2
9612 numFAIL=$((numFAIL+1))
9613 listFAIL="$listFAIL $N"
9615 fi # NUMCOND
9617 esac
9618 PORT=$((PORT+1))
9619 N=$((N+1))
9622 NAME=OPENSSLREAD
9623 # socat determined availability of data using select(). With openssl, the
9624 # following situation might occur:
9625 # a SSL data block with more than 8192 bytes (socats default blocksize)
9626 # arrives; socat calls SSL_read, and the SSL routine reads the complete block.
9627 # socat then reads 8192 bytes from the SSL layer, the rest remains buffered.
9628 # If the TCP connection stays idle for some time, the data in the SSL layer
9629 # keeps there and is not transferred by socat until the socket indicates more
9630 # data or EOF.
9631 case "$TESTS" in
9632 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
9633 TEST="$NAME: socat handles data buffered by openssl"
9634 #idea: have a socat process (server) that gets an SSL block that is larger than
9635 # socat transfer block size; keep the socket connection open and kill the
9636 # server process after a short time; if not the whole data block has been
9637 # transferred, the test has failed.
9638 if ! eval $NUMCOND; then :;
9639 elif ! feat=$(testfeats openssl) >/dev/null; then
9640 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9641 numCANT=$((numCANT+1))
9642 listCANT="$listCANT $N"
9643 else
9644 tf="$td/test$N.out"
9645 te="$td/test$N.err"
9646 tdiff="$td/test$N.diff"
9647 da="test$N $(date) $RANDOM"
9648 SRVCERT=testsrv
9649 gentestcert "$SRVCERT"
9650 CMD1="$TRACE $SOCAT $opts -u -T 1 -b $($ECHO "$da\c" |wc -c) OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$SRVCERT.pem,verify=0 -"
9651 CMD2="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
9652 printf "test $F_n $TEST... " $N
9654 $CMD1 2>"${te}1" >"$tf" &
9655 pid=$! # background process id
9656 waittcp4port $PORT
9657 (echo "$da"; sleep 2) |$CMD2 2>"${te}2"
9658 kill "$pid" 2>/dev/null; wait
9659 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9660 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9661 echo "$CMD1"
9662 cat "${te}1"
9663 echo "$CMD2"
9664 cat "${te}2"
9665 cat "$tdiff"
9666 numFAIL=$((numFAIL+1))
9667 listFAIL="$listFAIL $N"
9668 else
9669 $PRINTF "$OK\n"
9670 if [ -n "$debug" ]; then cat $te; fi
9671 numOK=$((numOK+1))
9673 wait
9674 fi # NUMCOND, featsesac
9676 esac
9677 N=$((N+1))
9680 # test: there is a bug with the readbytes option: when the socket delivered
9681 # exacly that many bytes as specified with readbytes and the stays idle (no
9682 # more data, no EOF), socat waits for more data instead of generating EOF on
9683 # this in put stream.
9684 NAME=READBYTES_EOF
9685 #set -vx
9686 case "$TESTS" in
9687 *%$N%*|*%functions%*|*%$NAME%*)
9688 TEST="$NAME: trigger EOF after that many bytes, even when socket idle"
9689 #idea: we deliver that many bytes to socat; the process should terminate then.
9690 # we try to transfer data in the other direction then; if transfer succeeds,
9691 # the process did not terminate and the bug is still there.
9692 if ! eval $NUMCOND; then :;
9693 elif false; then
9694 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9695 numCANT=$((numCANT+1))
9696 listCANT="$listCANT $N"
9697 else
9698 tr="$td/test$N.ref"
9699 ti="$td/test$N.in"
9700 to="$td/test$N.out"
9701 te="$td/test$N.err"
9702 tdiff="$td/test$N.diff"
9703 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
9704 CMD="$TRACE $SOCAT $opts SYSTEM:\"echo A; sleep $((2*SECONDs))\",readbytes=2!!- -!!/dev/null"
9705 printf "test $F_n $TEST... " $N
9706 (usleep $((2*MICROS)); echo) |eval "$CMD" >"$to" 2>"$te"
9707 if test -s "$to"; then
9708 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9709 echo "$CMD"
9710 numFAIL=$((numFAIL+1))
9711 listFAIL="$listFAIL $N"
9712 else
9713 $PRINTF "$OK\n"
9714 if [ -n "$debug" ]; then cat $te; fi
9715 numOK=$((numOK+1))
9717 fi ;; # NUMCOND, feats
9718 esac
9719 N=$((N+1))
9722 # test: there was a bug with exec:...,pty that did not kill the exec'd sub
9723 # process under some circumstances.
9724 NAME=EXECPTYKILL
9725 case "$TESTS" in
9726 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
9727 TEST="$NAME: exec:...,pty explicitely kills sub process"
9728 # we want to check if the exec'd sub process is killed in time
9729 # for this we have a shell script that generates a file after two seconds;
9730 # it should be killed after one second, so if the file was generated the test
9731 # has failed
9732 if ! eval $NUMCOND; then :; else
9733 tf="$td/test$N.stdout"
9734 te="$td/test$N.stderr"
9735 ts="$td/test$N.sock"
9736 tda="$td/test$N.data"
9737 tsh="$td/test$N.sh"
9738 tdiff="$td/test$N.diff"
9739 cat >"$tsh" <<EOF
9740 sleep $SECONDs; echo; sleep $SECONDs; touch "$tda"; echo
9742 chmod a+x "$tsh"
9743 CMD1="$TRACE $SOCAT $opts -t $SECONDs -U UNIX-LISTEN:$ts,fork EXEC:$tsh,pty"
9744 CMD="$TRACE $SOCAT $opts -t $SECONDs /dev/null UNIX-CONNECT:$ts"
9745 printf "test $F_n $TEST... " $N
9746 $CMD1 2>"${te}2" &
9747 pid1=$!
9748 sleep $SECONDs
9749 waitfile $ts $SECONDs
9750 $CMD 2>>"${te}1" >>"$tf"
9751 sleep $((2*SECONDs))
9752 kill "$pid1" 2>/dev/null
9753 wait
9754 if [ $? -ne 0 ]; then
9755 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9756 echo "$CMD1 &"
9757 echo "$CMD2"
9758 cat "${te}1" "${te}2"
9759 numFAIL=$((numFAIL+1))
9760 listFAIL="$listFAIL $N"
9761 elif [ -f "$tda" ]; then
9762 $PRINTF "$FAILED\n"
9763 cat "${te}1" "${te}2"
9764 numFAIL=$((numFAIL+1))
9765 listFAIL="$listFAIL $N"
9766 else
9767 $PRINTF "$OK\n"
9768 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9769 numOK=$((numOK+1))
9771 fi ;; # NUMCOND
9772 esac
9773 PORT=$((PORT+1))
9774 N=$((N+1))
9777 # test if service name resolution works; this was buggy in 1.5 and 1.6.0.0
9778 NAME=TCP4SERVICE
9779 case "$TESTS" in
9780 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
9781 TEST="$NAME: echo via connection to TCP V4 socket"
9782 # select a tcp entry from /etc/services, have a server listen on the port
9783 # number and connect using the service name; with the bug, connection will to a
9784 # wrong port
9785 if ! eval $NUMCOND; then :; else
9786 tf="$td/test$N.stdout"
9787 te="$td/test$N.stderr"
9788 tdiff="$td/test$N.diff"
9789 # find a service entry we do not need root for (>=1024; here >=1100 for ease)
9790 SERVENT="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)"
9791 SERVICE="$(echo $SERVENT |cut -d' ' -f1)"
9792 _PORT="$PORT"
9793 PORT="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')"
9794 tsl="$PORT"
9795 ts="127.0.0.1:$SERVICE"
9796 da="test$N $(date) $RANDOM"
9797 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
9798 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
9799 printf "test $F_n $TEST... " $N
9800 $CMD1 >"$tf" 2>"${te}1" &
9801 pid1=$!
9802 waittcp4port $tsl 1
9803 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9804 if [ $? -ne 0 ]; then
9805 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9806 echo "$CMD1 &"
9807 cat "${te}1"
9808 echo "$CMD2"
9809 cat "${te}2"
9810 numFAIL=$((numFAIL+1))
9811 listFAIL="$listFAIL $N"
9812 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9813 $PRINTF "$FAILED\n"
9814 cat "$tdiff"
9815 numFAIL=$((numFAIL+1))
9816 listFAIL="$listFAIL $N"
9817 else
9818 $PRINTF "$OK\n"
9819 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9820 numOK=$((numOK+1))
9822 kill $pid1 2>/dev/null
9823 wait
9824 PORT="$_PORT"
9825 fi ;; # NUMCOND
9826 esac
9827 N=$((N+1))
9830 # test: up to socat 1.6.0.0, the highest file descriptor supported in socats
9831 # transfer engine was FOPEN_MAX-1; this usually worked fine but would fail when
9832 # socat was invoked with many file descriptors already opened. socat would
9833 # just hang in the select() call. Thanks to Daniel Lucq for reporting this
9834 # problem.
9835 # FOPEN_MAX on different OS's:
9836 # OS FOPEN_ ulimit ulimit FD_
9837 # MAX -H -n -S -n SETSIZE
9838 # Linux 2.6: 16 1024 1024 1024
9839 # HP-UX 11.11: 60 2048 2048 2048
9840 # FreeBSD: 20 11095 11095 1024
9841 # Cygwin: 20 unlimit 256 64
9842 # AIX: 32767 65534 65534
9843 # SunOS 8: 20 1024
9844 NAME=EXCEED_FOPEN_MAX
9845 case "$TESTS" in
9846 *%$N%*|*%functions%*|*%maxfds%*|*%$NAME%*)
9847 TEST="$NAME: more than FOPEN_MAX FDs in use"
9848 # this test opens a number of FDs before socat is invoked. socat will have to
9849 # allocate higher FD numbers and thus hang if it cannot handle them.
9850 if ! eval $NUMCOND; then :; else
9851 REDIR=
9852 #set -vx
9853 FOPEN_MAX=$($PROCAN -c 2>/dev/null |grep '^#define[ ][ ]*FOPEN_MAX' |awk '{print($3);}')
9854 if [ -z "$FOPEN_MAX" ]; then
9855 $PRINTF "test $F_n $TEST... ${YELLOW}could not determine FOPEN_MAX${NORMAL}\n" "$N"
9856 numCANT=$((numCANT+1))
9857 listCANT="$listCANT $N"
9858 else
9859 OPEN_FILES=$FOPEN_MAX # more than the highest FOPEN_MAX
9860 i=3; while [ "$i" -lt "$OPEN_FILES" ]; do
9861 REDIR="$REDIR $i>&2"
9862 i=$((i+1))
9863 done
9864 #echo "$REDIR"
9865 #testecho "$N" "$TEST" "" "pipe" "$opts -T 3" "" 1
9866 #set -vx
9867 eval testecho "\"$N\"" "\"$TEST\"" "\"\"" "pipe" "\"$opts -T $((2*SECONDs))\"" 1 $REDIR
9868 #set +vx
9869 fi # could determine FOPEN_MAX
9870 fi ;; # NUMCOND
9871 esac
9872 N=$((N+1))
9875 # there was a bug with udp-listen and fork: terminating sub processes became
9876 # zombies because the master process did not catch SIGCHLD
9877 NAME=UDP4LISTEN_SIGCHLD
9878 case "$TESTS" in
9879 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%zombie%*|*%signal%*|*%$NAME%*)
9880 TEST="$NAME: test if UDP4-LISTEN child becomes zombie"
9881 # idea: run a udp-listen process with fork and -T. Connect once, so a sub
9882 # process is forked off. Make some transfer and wait until the -T timeout is
9883 # over. Now check for the child process: if it is zombie the test failed.
9884 # Correct is that child process terminated
9885 if ! eval $NUMCOND; then :; else
9886 tf="$td/test$N.stdout"
9887 te="$td/test$N.stderr"
9888 tdiff="$td/test$N.diff"
9889 tsl=$PORT
9890 ts="$LOCALHOST:$tsl"
9891 da="test$N $(date) $RANDOM"
9892 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,$REUSEADDR,fork PIPE"
9893 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
9894 printf "test $F_n $TEST... " $N
9895 $CMD1 >"$tf" 2>"${te}1" &
9896 pid1=$!
9897 waitudp4port $tsl 1
9898 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9899 rc2=$?
9900 sleep 1
9901 #read -p ">"
9902 l="$(childprocess $pid1)"
9903 kill $pid1 2>/dev/null; wait
9904 if [ $rc2 -ne 0 ]; then
9905 $PRINTF "$NO_RESULT (client failed)\n" # already handled in test UDP4STREAM
9906 numCANT=$((numCANT+1))
9907 listCANT="$listCANT $N"
9908 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9909 $PRINTF "$NO_RESULT (diff failed)\n" # already handled in test UDP4STREAM
9910 numCANT=$((numCANT+1))
9911 listCANT="$listCANT $N"
9912 elif $(isdefunct "$l"); then
9913 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9914 echo "$CMD1 &"
9915 echo "$CMD2"
9916 cat "${te}1" "${te}2"
9917 numFAIL=$((numFAIL+1))
9918 listFAIL="$listFAIL $N"
9919 else
9920 $PRINTF "$OK\n"
9921 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9922 numOK=$((numOK+1))
9924 fi ;; # NUMCOND
9925 esac
9926 PORT=$((PORT+1))
9927 N=$((N+1))
9928 #set +vx
9930 # there was a bug with udp-recvfrom and fork: terminating sub processes became
9931 # zombies because the master process caught SIGCHLD but did not wait()
9932 NAME=UDP4RECVFROM_SIGCHLD
9933 case "$TESTS" in
9934 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%zombie%*|*%signal%*|*%$NAME%*)
9935 TEST="$NAME: test if UDP4-RECVFROM child becomes zombie"
9936 # idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a
9937 # sub process is forked off. Make some transfer and wait until the -T timeout
9938 # is over. Now check for the child process: if it is zombie the test failed.
9939 # Correct is that child process terminated
9940 if ! eval $NUMCOND; then :; else
9941 tf="$td/test$N.stdout"
9942 te="$td/test$N.stderr"
9943 tdiff="$td/test$N.diff"
9944 tsl=$PORT
9945 ts="$LOCALHOST:$tsl"
9946 da="test$N $(date) $RANDOM"
9947 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE"
9948 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts"
9949 printf "test $F_n $TEST... " $N
9950 $CMD1 >"$tf" 2>"${te}1" &
9951 pid1=$!
9952 waitudp4port $tsl 1
9953 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9954 rc2=$?
9955 sleep 1
9956 #read -p ">"
9957 l="$(childprocess $pid1)"
9958 kill $pid1 2>/dev/null; wait
9959 if [ $rc2 -ne 0 ]; then
9960 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9961 numCANT=$((numCANT+1))
9962 listCANT="$listCANT $N"
9963 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9964 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9965 numCANT=$((numCANT+1))
9966 listCANT="$listCANT $N"
9967 elif $(isdefunct "$l"); then
9968 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9969 echo "$CMD1 &"
9970 echo "$CMD2"
9971 cat "${te}1" "${te}2"
9972 numFAIL=$((numFAIL+1))
9973 listFAIL="$listFAIL $N"
9974 else
9975 $PRINTF "$OK\n"
9976 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9977 numOK=$((numOK+1))
9979 fi ;; # NUMCOND
9980 esac
9981 PORT=$((PORT+1))
9982 N=$((N+1))
9985 # test: there was a bug with ip*-recv and bind option: it would not bind, and
9986 # with the first received packet an error:
9987 # socket_init(): unknown address family 0
9988 # occurred
9989 NAME=RAWIP4RECVBIND
9990 case "$TESTS" in
9991 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
9992 TEST="$NAME: raw IPv4 receive with bind"
9993 # idea: start a socat process with ip4-recv:...,bind=... and send it a packet
9994 # if the packet passes the test succeeded
9995 if ! eval $NUMCOND; then :;
9996 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9997 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9998 numCANT=$((numCANT+1))
9999 listCANT="$listCANT $N"
10000 else
10001 tf="$td/test$N.stdout"
10002 te="$td/test$N.stderr"
10003 tdiff="$td/test$N.diff"
10004 ts1p=$PROTO; PROTO=$((PROTO+1))
10005 ts1a="127.0.0.1"
10006 ts1="$ts1a:$ts1p"
10007 da="test$N $(date) $RANDOM"
10008 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -"
10009 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
10010 printf "test $F_n $TEST... " $N
10011 $CMD1 >"$tf" 2>"${te}1" &
10012 pid1="$!"
10013 waitip4proto $ts1p 1
10014 echo "$da" |$CMD2 2>>"${te}2"
10015 rc2="$?"
10016 #ls -l $tf
10017 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10018 kill "$pid1" 2>/dev/null; wait
10019 if [ "$rc2" -ne 0 ]; then
10020 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10021 echo "$CMD1 &"
10022 echo "$CMD2"
10023 cat "${te}1"
10024 cat "${te}2"
10025 numFAIL=$((numFAIL+1))
10026 listFAIL="$listFAIL $N"
10027 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10028 $PRINTF "$FAILED\n"
10029 cat "$tdiff"
10030 numFAIL=$((numFAIL+1))
10031 listFAIL="$listFAIL $N"
10032 else
10033 $PRINTF "$OK\n"
10034 if [ -n "$debug" ]; then cat $te; fi
10035 numOK=$((numOK+1))
10037 fi ;; # NUMCOND, root
10038 esac
10039 PROTO=$((PROTO+1))
10040 N=$((N+1))
10043 # there was a bug in *-recvfrom with fork: due to an error in the appropriate
10044 # signal handler the master process would hang after forking off the first
10045 # child process.
10046 NAME=UDP4RECVFROM_FORK
10047 case "$TESTS" in
10048 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10049 TEST="$NAME: test if UDP4-RECVFROM handles more than one packet"
10050 # idea: run a UDP4-RECVFROM process with fork and -T. Send it one packet;
10051 # send it a second packet and check if this is processed properly. If yes, the
10052 # test succeeded.
10053 if ! eval $NUMCOND; then :; else
10054 tf="$td/test$N.stdout"
10055 te="$td/test$N.stderr"
10056 tdiff="$td/test$N.diff"
10057 tsp=$PORT
10058 ts="$LOCALHOST:$tsp"
10059 da2a="test$N $(date) $RANDOM"
10060 da2b="test$N $(date) $RANDOM"
10061 CMD1="$TRACE $SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE"
10062 CMD2="$TRACE $SOCAT $opts -T 1 - UDP4-SENDTO:$ts"
10063 printf "test $F_n $TEST... " $N
10064 $CMD1 >/dev/null 2>"${te}1" &
10065 pid1=$!
10066 waitudp4port $tsp 1
10067 echo "$da2a" |$CMD2 >/dev/null 2>>"${te}2a" # this should always work
10068 rc2a=$?
10069 echo "$da2b" |$CMD2 >"$tf" 2>>"${te}2b" # this would fail when bug
10070 rc2b=$?
10071 kill $pid1 2>/dev/null; wait
10072 if [ $rc2b -ne 0 ]; then
10073 $PRINTF "$NO_RESULT\n"
10074 numCANT=$((numCANT+1))
10075 listCANT="$listCANT $N"
10076 elif ! echo "$da2b" |diff - "$tf" >"$tdiff"; then
10077 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10078 echo "$CMD1 &" >&2
10079 cat "${te}1" >&2
10080 echo "$CMD2" >&2
10081 cat "${te}2b" >&2
10082 cat "$tdiff" >&2
10083 numFAIL=$((numFAIL+1))
10084 listFAIL="$listFAIL $N"
10085 else
10086 $PRINTF "$OK\n"
10087 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3"; fi
10088 numOK=$((numOK+1))
10090 fi ;; # NUMCOND
10091 esac
10092 PORT=$((PORT+1))
10093 N=$((N+1))
10096 # there was a bug in parsing the arguments of exec: consecutive spaces resulted
10097 # in additional empty arguments
10098 NAME=EXECSPACES
10099 case "$TESTS" in
10100 *%$N%*|*%functions%*|*%exec%*|*%parse%*|*%$NAME%*)
10101 TEST="$NAME: correctly parse exec with consecutive spaces"
10102 if ! eval $NUMCOND; then :; else
10103 $PRINTF "test $F_n $TEST... " $N
10104 tf="$td/test$N.stdout"
10105 te="$td/test$N.stderr"
10106 da="test$N $(date) $RANDOM" # with a double space
10107 tdiff="$td/test$N.diff"
10108 # put the test data as first argument after two spaces. expect the data in the
10109 # first argument of the exec'd command.
10110 $TRACE $SOCAT $opts -u "exec:\"bash -c \\\"echo \\\\\\\"\$1\\\\\\\"\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te"
10111 rc=$?
10112 echo "$da" |diff - "$tf" >"$tdiff"
10113 if [ "$rc" -ne 0 ]; then
10114 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10115 cat "$te"
10116 numFAIL=$((numFAIL+1))
10117 listFAIL="$listFAIL $N"
10118 elif [ -s "$tdiff" ]; then
10119 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10120 echo diff:
10121 cat "$tdiff"
10122 if [ -n "$debug" ]; then cat $te; fi
10123 numFAIL=$((numFAIL+1))
10124 listFAIL="$listFAIL $N"
10125 else
10126 $PRINTF "$OK\n"
10127 if [ -n "$debug" ]; then cat $te; fi
10128 numOK=$((numOK+1))
10130 fi ;; # NUMCOND
10131 esac
10132 N=$((N+1))
10135 # a bug was found in the way UDP-LISTEN handles the listening socket:
10136 # when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
10137 # range option, the old listen socket would not be closed but a new one created.
10138 NAME=UDP4LISTENCONT
10139 case "$TESTS" in
10140 *%$N%*|*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*)
10141 TEST="$NAME: let range drop a packet and see if old socket is closed"
10142 # idea: run a UDP4-LISTEN process with range option. Send it one packet from an
10143 # address outside range and check if two listening sockets are open then
10144 if ! eval $NUMCOND; then :; else
10145 tf="$td/test$N.stdout"
10146 te="$td/test$N.stderr"
10147 tdiff="$td/test$N.diff"
10148 if [ "$SS" ]; then
10149 while [ "$($SS -anu |grep "127\.0\.0\.1:$PORT\>" |wc -l)" -ne 0 ]; do
10150 PORT=$((PORT+1))
10151 done
10152 else
10153 while [ "$(netstat -an |grep "^udp.*127\.0\.0\.1:$PORT\>" |wc -l)" -ne 0 ]; do
10154 PORT=$((PORT+1))
10155 done
10157 tp=$PORT
10158 da1="test$N $(date) $RANDOM"
10159 a1="$LOCALHOST"
10160 a2="$SECONDADDR"
10161 #CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
10162 CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,$REUSEADDR,range=$a2/32 PIPE"
10163 CMD1="$TRACE $SOCAT $opts - UDP-CONNECT:$a1:$tp"
10164 printf "test $F_n $TEST... " $N
10165 $CMD0 >/dev/null 2>"${te}0" &
10166 pid1=$!
10167 waitudp4port $tp 1
10168 echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail
10169 rc1=$?
10170 waitudp4port $tp 1
10171 if [ "$SS" ]; then
10172 nsocks="$($SS -anu |grep ":$PORT\>" |wc -l)"
10173 else
10174 nsocks="$(netstat -an |grep "^udp.*[:.]$PORT\>" |wc -l)"
10176 kill $pid1 2>/dev/null; wait
10177 if [ $rc1 -ne 0 ]; then
10178 $PRINTF "$NO_RESULT\n"
10179 numCANT=$((numCANT+1))
10180 listCANT="$listCANT $N"
10181 elif [ $nsocks -eq 0 ]; then
10182 $PRINTF "$NO_RESULT\n"
10183 numCANT=$((numCANT+1))
10184 listCANT="$listCANT $N"
10185 elif [ $nsocks -ne 1 ]; then
10186 $PRINTF "$FAILED ($nsocks listening sockets)\n"
10187 echo "$CMD0 &"
10188 echo "$CMD1"
10189 cat "${te}0" "${te}1"
10190 numFAIL=$((numFAIL+1))
10191 listFAIL="$listFAIL $N"
10192 else
10193 $PRINTF "$OK\n"
10194 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
10195 numOK=$((numOK+1))
10197 fi ;; # NUMCOND
10198 esac
10199 PORT=$((PORT+1))
10200 N=$((N+1))
10203 # during wait for next poll time option ignoreeof blocked the data transfer in
10204 # the reverse direction
10205 NAME=IGNOREEOFNOBLOCK
10206 case "$TESTS" in
10207 *%$N%*|*%functions%*|*%engine%*|*%socket%*|*%ignoreeof%*|*%$NAME%*)
10208 TEST="$NAME: ignoreeof does not block other direction"
10209 # have socat poll in ignoreeof mode. while it waits one second for next check,
10210 # we send data in the reverse direction and then the total timeout fires.
10211 # it the data has passed, the test succeeded.
10212 if ! eval $NUMCOND; then :; else
10213 tf="$td/test$N.stout"
10214 te="$td/test$N.stderr"
10215 tdiff="$td/test$N.diff"
10216 da="test$N $(date) $RANDOM"
10217 CMD0="$TRACE $SOCAT $opts /dev/null,ignoreeof!!- -!!/dev/null"
10218 printf "test $F_n $TEST... " $N
10219 (usleep 333333; echo "$da") |$CMD0 >"$tf" 2>"${te}0"
10220 rc0=$?
10221 if [ $rc0 != 0 ]; then
10222 $PRINTF "$FAILED\n"
10223 echo "$CMD0 &"
10224 echo "$CMD1"
10225 cat "${te}0"
10226 cat "${te}1"
10227 numFAIL=$((numFAIL+1))
10228 listFAIL="$listFAIL $N"
10229 elif echo "$da" |diff - "$tf" >/dev/null; then
10230 $PRINTF "$OK\n"
10231 numOK=$((numOK+1))
10232 else
10233 $PRINTF "$FAILED\n"
10234 echo "$CMD0 &"
10235 echo "$CMD1"
10236 cat "${te}0"
10237 numFAIL=$((numFAIL+1))
10238 listFAIL="$listFAIL $N"
10240 fi ;; # NUMCOND
10241 esac
10242 N=$((N+1))
10245 # test the escape option
10246 NAME=ESCAPE
10247 case "$TESTS" in
10248 *%$N%*|*%functions%*|*%engine%*|*%escape%*|*%$NAME%*)
10249 TEST="$NAME: escape character triggers EOF"
10250 # idea: start socat just echoing input, but apply escape option. send a string
10251 # containing the escape character and check if the output is truncated
10252 if ! eval $NUMCOND; then :; else
10253 tf="$td/test$N.stdout"
10254 te="$td/test$N.stderr"
10255 tdiff="$td/test$N.diff"
10256 da="test$N $(date) $RANDOM"
10257 CMD="$TRACE $SOCAT $opts -,escape=27 pipe"
10258 printf "test $F_n $TEST... " $N
10259 $ECHO "$da\n\x1bXYZ" |$CMD >"$tf" 2>"$te"
10260 if [ $? -ne 0 ]; then
10261 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10262 echo "$CMD"
10263 cat "$te"
10264 numFAIL=$((numFAIL+1))
10265 listFAIL="$listFAIL $N"
10266 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10267 $PRINTF "$FAILED: diff:\n"
10268 cat "$tdiff"
10269 numFAIL=$((numFAIL+1))
10270 listFAIL="$listFAIL $N"
10271 else
10272 $PRINTF "$OK\n"
10273 if [ -n "$debug" ]; then cat $te; fi
10274 numOK=$((numOK+1))
10276 fi ;; # NUMCOND
10277 esac
10278 N=$((N+1))
10280 # test the escape option combined with ignoreeof
10281 NAME=ESCAPE_IGNOREEOF
10282 case "$TESTS" in
10283 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%escape%*|*%$NAME%*)
10284 TEST="$NAME: escape character triggers EOF"
10285 # idea: start socat just echoing input, but apply escape option. send a string
10286 # containing the escape character and check if the output is truncated
10287 if ! eval $NUMCOND; then :; else
10288 ti="$td/test$N.file"
10289 tf="$td/test$N.stdout"
10290 te="$td/test$N.stderr"
10291 tdiff="$td/test$N.diff"
10292 da="test$N $(date) $RANDOM"
10293 CMD="$TRACE $SOCAT -T 5 $opts file:$ti,ignoreeof,escape=27!!- pipe"
10294 printf "test $F_n $TEST... " $N
10295 >"$ti"
10296 $CMD >"$tf" 2>"$te" &
10297 $ECHO "$da\n\x1bXYZ" >>"$ti"
10298 sleep 1
10299 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
10300 $PRINTF "$FAILED: diff:\n"
10301 cat "$tdiff"
10302 cat "$te"
10303 numFAIL=$((numFAIL+1))
10304 listFAIL="$listFAIL $N"
10305 else
10306 $PRINTF "$OK\n"
10307 if [ -n "$debug" ]; then cat $te; fi
10308 numOK=$((numOK+1))
10310 fi ;; # NUMCOND
10311 esac
10312 N=$((N+1))
10315 # test: logging of ancillary message
10316 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_TYPE SCM_NAME ROOT SCM_VALUE
10318 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
10320 pf="$(echo "$PF" |tr A-Z a-z)"
10321 proto="$(echo "$KEYW" |tr A-Z a-z)"
10322 NAME=${KEYW}SCM_$SCM_TYPE
10323 case "$TESTS" in
10324 *%$N%*|*%functions%*|*%socket%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%$ROOT%*|*%$NAME%*)
10325 TEST="$NAME: $KEYW log ancillary message $SCM_TYPE $SCM_NAME"
10326 # idea: start a socat process with *-RECV:..,... , ev. with ancillary message
10327 # enabling option and send it a packet, ev. with some option. check the info log
10328 # for the appropriate output.
10329 if ! eval $NUMCOND; then :;
10330 #elif [[ "$PF" == "#*" ]]; then :
10331 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
10332 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
10333 numCANT=$((numCANT+1))
10334 listCANT="$listCANT $N"
10335 elif [ "$PF" = "IP6" ] && ( ! feat=$(testfeats ip6) || ! runsip6 >/dev/null ); then
10336 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10337 numCANT=$((numCANT+1))
10338 listCANT="$listCANT $N"
10339 elif ! testoptions $SCM_RECV >/dev/null; then
10340 $PRINTF "test $F_n $TEST... ${YELLOW}option $SCM_RECV not available${NORMAL}\n" $N
10341 numCANT=$((numCANT+1))
10342 listCANT="$listCANT $N"
10343 else
10344 tf="$td/test$N.stdout"
10345 te="$td/test$N.stderr"
10346 case "X$IPPORT" in
10347 "XPORT")
10348 tra="$PORT" # test recv address
10349 tsa="$ADDR:$PORT" # test sendto address
10350 PORT=$((PORT+1)) ;;
10351 "XPROTO")
10352 tra="$PROTO" # test recv address
10353 tsa="$ADDR:$PROTO" # test sendto address
10354 PROTO=$((PROTO+1)) ;;
10356 tra="$(eval echo "$ADDR")" # resolve $N
10357 tsa="$tra"
10358 esac
10359 CMD0="$TRACE $SOCAT $opts -d -d -d -u $KEYW-RECV:$tra,reuseaddr,$SCM_RECV -"
10360 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
10361 printf "test $F_n $TEST... " $N
10362 # is this option supported?
10363 if $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
10364 if [ "$SCM_VALUE" = "timestamp" ]; then
10365 secs="$(date '+%S')"
10366 if [ "$secs" -ge 58 -a "$secs" -le 59 ]; then
10367 dsecs=$((60-secs))
10368 #echo "Sleeping $dsecs seconds to avoid minute change in timestamp" >/dev/tty
10369 sleep $dsecs
10372 $CMD0 >"$tf" 2>"${te}0" &
10373 pid0="$!"
10374 wait${proto}port $tra 1
10375 echo "XYZ" |$CMD1 2>"${te}1"
10376 rc1="$?"
10377 sleep 1
10378 i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10379 kill "$pid0" 2>/dev/null; wait
10380 # do not show more messages than requested
10381 case "$opts" in
10382 *-d*-d*-d*-d*) LEVELS="[EWNID]" ;;
10383 *-d*-d*-d*) LEVELS="[EWNI]" ;;
10384 *-d*-d*) LEVELS="[EWN]" ;;
10385 *-d*) LEVELS="[EW]" ;;
10386 *) LEVELS="[E]" ;;
10387 esac
10388 if [ "$SCM_VALUE" = "timestamp" ]; then
10389 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
10391 if [ "$rc1" -ne 0 ]; then
10392 $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
10393 echo "$CMD0 &"
10394 echo "$CMD1"
10395 grep " $LEVELS " "${te}0"
10396 grep " $LEVELS " "${te}1"
10397 numCANT=$((numCANT+1))
10398 listCANT="$listCANT $N"
10399 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=" ${te}0 >/dev/null; then
10400 $PRINTF "$FAILED\n"
10401 echo "variable $SCM_TYPE: $SCM_NAME not set"
10402 echo "$CMD0 &"
10403 echo "$CMD1"
10404 grep " $LEVELS " "${te}0"
10405 grep " $LEVELS " "${te}1"
10406 numFAIL=$((numFAIL+1))
10407 listFAIL="$listFAIL $N"
10408 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=$SCM_VALUE\$" ${te}0 >/dev/null; then
10409 $PRINTF "$FAILED\n"
10410 badval="$(grep "ancillary message: $SCM_TYPE: $SCM_NAME" ${te}0 |sed 's/.*=//g')"
10411 echo "variable $SCM_TYPE: $SCM_NAME has value \"$badval\" instead of pattern \"$SCM_VALUE\"" >&2
10412 echo "$CMD0 &"
10413 echo "$CMD1"
10414 grep " $LEVELS " "${te}0"
10415 grep " $LEVELS " "${te}1"
10416 numFAIL=$((numFAIL+1))
10417 listFAIL="$listFAIL $N"
10418 else
10419 $PRINTF "$OK\n"
10420 if [ -n "$debug" ]; then
10421 grep " $LEVELS " "${te}0"; echo; grep " $LEVELS " "${te}1";
10423 numOK=$((numOK+1))
10425 else # option is not supported
10426 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
10427 numCANT=$((numCANT+1))
10428 listCANT="$listCANT $N"
10429 fi # option is not supported
10430 fi # NUMCOND, root, feats
10432 esac
10433 N=$((N+1))
10435 done <<<"
10436 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS options user x01000000
10437 IP4 UDP4 127.0.0.1 PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10438 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL ttl user 53
10439 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS tos user 7
10440 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO locaddr user 127.0.0.1
10441 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO dstaddr user 127.0.0.1
10442 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO if user lo
10443 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_RECVIF if user lo0
10444 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_RECVDSTADDR dstaddr user 127.0.0.1
10445 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS options root x01000000
10446 IP4 IP4 127.0.0.1 PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
10447 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL ttl root 53
10448 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS tos root 7
10449 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO locaddr root 127.0.0.1
10450 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO dstaddr root 127.0.0.1
10451 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO if root lo
10452 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_RECVIF if root lo0
10453 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_RECVDSTADDR dstaddr root 127.0.0.1
10454 IP6 UDP6 [::1] PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10455 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_PKTINFO dstaddr user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10456 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit user 35
10457 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass user x000000aa
10458 IP6 IP6 [::1] PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
10459 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_PKTINFO dstaddr root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10460 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit root 35
10461 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass root x000000aa
10462 #UNIX UNIX $td/test\$N.server - , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10464 # this one fails, appearently due to a Linux weakness:
10465 # UNIX so-timestamp
10468 # test: setting of environment variables that describe a stream socket
10469 # connection: SOCAT_SOCKADDR, SOCAT_PEERADDR; and SOCAT_SOCKPORT,
10470 # SOCAT_PEERPORT when applicable
10471 while read KEYW FEAT TEST_SOCKADDR TEST_PEERADDR TEST_SOCKPORT TEST_PEERPORT; do
10472 if [ -z "$KEYW" ] || [[ "$KEYW" == \#* ]]; then continue; fi
10474 protov="$(echo "$KEYW" |tr A-Z a-z)"
10475 proto="${protov%%[0-9]}"
10476 NAME=${KEYW}LISTENENV
10477 case "$TESTS" in
10478 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$proto%*|*%$protov%*|*%envvar%*|*%$NAME%*)
10479 TEST="$NAME: $KEYW-LISTEN sets environment variables with socket addresses"
10480 # have a server accepting a connection and invoking some shell code. The shell
10481 # code extracts and prints the SOCAT related environment vars.
10482 # outside code then checks if the environment contains the variables correctly
10483 # describing the peer and local sockets.
10484 if ! eval $NUMCOND; then :;
10485 elif ! feat=$(testfeats $FEAT); then
10486 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
10487 numCANT=$((numCANT+1))
10488 listCANT="$listCANT $N"
10489 elif [ "$KEYW" = "TCP6" -o "$KEYW" = "UDP6" -o "$KEYW" = "SCTP6" ] && \
10490 ! runsip6 >/dev/null; then
10491 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10492 numCANT=$((numCANT+1))
10493 listCANT="$listCANT $N"
10494 elif [ "$KEYW" = "SCTP4" ] && ! runssctp4 "$((PORT))" >/dev/null; then
10495 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
10496 elif [ "$KEYW" = "SCTP6" ] && ! runssctp6 "$((PORT))" >/dev/null; then
10497 #!!! branch not reached - caught above!
10498 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
10499 else
10500 tf="$td/test$N.stdout"
10501 te="$td/test$N.stderr"
10502 TEST_SOCKADDR="$(echo "$TEST_SOCKADDR" |sed "s/\$N/$N/g")" # actual vars
10503 tsa="$TEST_SOCKADDR" # test server address
10504 tsp="$TEST_SOCKPORT" # test server port
10505 if [ "$tsp" != ',' ]; then
10506 tsa1="$tsp"; tsa2="$tsa"; tsa="$tsa:$tsp" # tsa2 used for server bind=
10507 else
10508 tsa1="$tsa"; tsa2= # tsa1 used for addr parameter
10510 TEST_PEERADDR="$(echo "$TEST_PEERADDR" |sed "s/\$N/$N/g")" # actual vars
10511 tca="$TEST_PEERADDR" # test client address
10512 tcp="$TEST_PEERPORT" # test client port
10513 if [ "$tcp" != ',' ]; then
10514 tca="$tca:$tcp"
10516 #CMD0="$TRACE $SOCAT $opts -u $KEYW-LISTEN:$tsa1 SYSTEM:\"export -p\""
10517 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-LISTEN:$tsa1,$REUSEADDR SYSTEM:\"echo SOCAT_SOCKADDR=\\\$SOCAT_SOCKADDR; echo SOCAT_PEERADDR=\\\$SOCAT_PEERADDR; echo SOCAT_SOCKPORT=\\\$SOCAT_SOCKPORT; echo SOCAT_PEERPORT=\\\$SOCAT_PEERPORT; sleep 1\""
10518 CMD1="$TRACE $SOCAT $opts -u - $KEYW-CONNECT:$tsa,bind=$tca"
10519 printf "test $F_n $TEST... " $N
10520 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
10521 pid0=$!
10522 wait${protov}port $tsa1 1
10523 echo |$CMD1 2>"${te}1"
10524 rc1=$?
10525 waitfile "$tf" 2
10526 kill $pid0 2>/dev/null; wait
10527 #set -vx
10528 if [ $rc1 != 0 ]; then
10529 $PRINTF "$NO_RESULT (client failed):\n"
10530 echo "$CMD0 &"
10531 cat "${te}0"
10532 echo "$CMD1"
10533 cat "${te}1"
10534 numCANT=$((numCANT+1))
10535 listCANT="$listCANT $N"
10536 elif [ "$(grep SOCAT_SOCKADDR "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")" = "$TEST_SOCKADDR" -a \
10537 "$(grep SOCAT_PEERADDR "${tf}" |sed -e 's/^[^=]*=//' -e "s/[\"']//g")" = "$TEST_PEERADDR" -a \
10538 \( "$TEST_SOCKPORT" = ',' -o "$(grep SOCAT_SOCKPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tsp" \) -a \
10539 \( "$TEST_PEERPORT" = ',' -o "$(grep SOCAT_PEERPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tcp" \) \
10540 ]; then
10541 $PRINTF "$OK\n"
10542 if [ "$debug" ]; then
10543 echo "$CMD0 &"
10544 cat "${te}0"
10545 echo "$CMD1"
10546 cat "${te}1"
10548 numOK=$((numOK+1))
10549 else
10550 $PRINTF "$FAILED\n"
10551 echo "$CMD0 &"
10552 cat "${te}0"
10553 echo "$CMD1"
10554 cat "${te}1"
10555 echo -e "SOCAT_SOCKADDR=$TEST_SOCKADDR\nSOCAT_PEERADDR=$TEST_PEERADDR\nSOCAT_SOCKPORT=$TEST_SOCKPORT\nSOCAT_PEERPORT=$TEST_PEERPORT" |
10556 diff - "${tf}"
10557 numFAIL=$((numFAIL+1))
10558 listFAIL="$listFAIL $N"
10560 fi # NUMCOND, feats
10562 esac
10563 N=$((N+1))
10564 #set +xv
10566 done <<<"
10567 TCP4 TCP 127.0.0.1 $SECONDADDR $PORT $((PORT+1))
10568 TCP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+2)) $((PORT+3))
10569 UDP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+6)) $((PORT+7))
10570 SCTP4 SCTP 127.0.0.1 $SECONDADDR $((PORT+8)) $((PORT+9))
10571 SCTP6 SCTP [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+10)) $((PORT+11))
10572 UNIX UNIX $td/test\$N.server $td/test\$N.client , ,
10574 # this one fails due to weakness in socats UDP4-LISTEN implementation:
10575 #UDP4 $LOCALHOST $SECONDADDR $((PORT+4)) $((PORT+5))
10578 # test: environment variables from ancillary message
10579 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_ENVNAME ROOT SCM_VALUE
10581 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
10583 pf="$(echo "$PF" |tr A-Z a-z)"
10584 proto="$(echo "$KEYW" |tr A-Z a-z)"
10585 NAME=${KEYW}ENV_$SCM_ENVNAME
10586 case "$TESTS" in
10587 *%$N%*|*%functions%*|*%socket%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%envvar%*|*%$ROOT%*|*%$NAME%*)
10588 #set -vx
10589 TEST="$NAME: $KEYW ancillary message sets env SOCAT_$SCM_ENVNAME"
10590 # idea: start a socat process with *-RECVFROM:..,... , ev. with ancillary
10591 # message enabling option and send it a packet, ev. with some option. write
10592 # the resulting environment to a file and check its contents for the
10593 # appropriate variable.
10594 if ! eval $NUMCOND; then :;
10595 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
10596 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
10597 numCANT=$((numCANT+1))
10598 listCANT="$listCANT $N"
10599 elif [ "$PF" = "IP6" ] && ( ! feat=$(testfeats ip6) || ! runsip6 ) >/dev/null; then
10600 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10601 numCANT=$((numCANT+1))
10602 listCANT="$listCANT $N"
10603 else
10604 tf="$td/test$N.stdout"
10605 te="$td/test$N.stderr"
10606 case "X$IPPORT" in
10607 "XPORT")
10608 tra="$PORT" # test recv address
10609 tsa="$ADDR:$PORT" # test sendto address
10610 PORT=$((PORT+1)) ;;
10611 "XPROTO")
10612 tra="$PROTO" # test recv address
10613 tsa="$ADDR:$PROTO" # test sendto address
10614 PROTO=$((PROTO+1)) ;;
10616 tra="$(eval echo "$ADDR")" # resolve $N
10617 tsa="$tra"
10618 esac
10619 #CMD0="$TRACE $SOCAT $opts -u $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"export -p\""
10620 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"echo \\\$SOCAT_$SCM_ENVNAME\""
10621 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
10622 printf "test $F_n $TEST... " $N
10623 # is this option supported?
10624 if $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
10625 if [ "$SCM_VALUE" = "timestamp" ]; then
10626 secs="$(date '+%S')"
10627 if [ "$secs" -ge 58 -a "$secs" -le 59 ]; then
10628 dsecs=$((60-secs))
10629 #echo "Sleeping $dsecs seconds to avoid minute change in timestamp" >/dev/tty
10630 sleep $dsecs
10633 eval "$CMD0 >\"$tf\" 2>\"${te}0\" &"
10634 pid0="$!"
10635 wait${proto}port $tra 1
10636 echo "XYZ" |$CMD1 2>"${te}1"
10637 rc1="$?"
10638 waitfile "$tf" 2
10639 #i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10640 kill "$pid0" 2>/dev/null; wait
10641 # do not show more messages than requested
10642 if [ "$SCM_VALUE" = "timestamp" ]; then
10643 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
10645 if [ "$rc1" -ne 0 ]; then
10646 $PRINTF "$NO_RESULT: $SOCAT:\n"
10647 echo "$CMD0 &"
10648 echo "$CMD1"
10649 cat "${te}0"
10650 cat "${te}1"
10651 numCANT=$((numCANT+1))
10652 listCANT="$listCANT $N"
10653 #elif ! egrep "^export SOCAT_$SCM_ENVNAME=[\"']?$SCM_VALUE[\"']?\$" ${tf} >/dev/null; then
10654 #elif ! eval echo "$TRACE $SOCAT_\$SCM_VALUE" |diff - "${tf}" >/dev/null; then
10655 elif ! expr "$(cat "$tf")" : "$(eval echo "\$SCM_VALUE")\$" >/dev/null; then
10656 $PRINTF "$FAILED\n"
10657 echo "logged value \"$(cat "$tf")\" instead of \"$(eval echo "\$SCM_VALUE")\""
10658 echo "$CMD0 &"
10659 echo "$CMD1"
10660 cat "${te}0"
10661 cat "${te}1"
10662 numFAIL=$((numFAIL+1))
10663 listFAIL="$listFAIL $N"
10664 else
10665 $PRINTF "$OK\n"
10666 if [ -n "$debug" ]; then
10667 cat "${te}0"; echo; cat "${te}1";
10669 numOK=$((numOK+1))
10671 else # option is not supported
10672 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
10673 numCANT=$((numCANT+1))
10674 listCANT="$listCANT $N"
10675 fi # option is not supported
10676 fi ;; # NUMCOND, feats
10677 esac
10678 N=$((N+1))
10680 done <<<"
10681 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS user x01000000
10682 IP4 UDP4 127.0.0.1 PORT , so-timestamp TIMESTAMP user timestamp
10683 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL user 53
10684 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS user 7
10685 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_LOCADDR user 127.0.0.1
10686 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_DSTADDR user 127.0.0.1
10687 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_IF user lo
10688 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_IF user lo0
10689 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_DSTADDR user 127.0.0.1
10690 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS root x01000000
10691 IP4 IP4 127.0.0.1 PROTO , so-timestamp TIMESTAMP root timestamp
10692 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL root 53
10693 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS root 7
10694 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_LOCADDR root 127.0.0.1
10695 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_DSTADDR root 127.0.0.1
10696 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_IF root lo
10697 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_IF root lo0
10698 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_DSTADDR root 127.0.0.1
10699 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_DSTADDR user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10700 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT user 35
10701 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS user x000000aa
10702 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_DSTADDR root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10703 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT root 35
10704 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS root x000000aa
10705 #UNIX UNIX $td/test\$N.server - , so-timestamp TIMESTAMP user timestamp
10709 # test the SOCKET-CONNECT address (against TCP4-LISTEN)
10710 NAME=SOCKET_CONNECT_TCP4
10711 case "$TESTS" in
10712 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10713 TEST="$NAME: socket connect with TCP/IPv4"
10714 # start a TCP4-LISTEN process that echoes data, and send test data using
10715 # SOCKET-CONNECT, selecting TCP/IPv4. The sent data should be returned.
10716 if ! eval $NUMCOND; then :; else
10717 tf="$td/test$N.stdout"
10718 te="$td/test$N.stderr"
10719 tdiff="$td/test$N.diff"
10720 ts0p=$PORT; PORT=$((PORT+1))
10721 ts0a="127.0.0.1"
10722 ts1p=$(printf "%04x" $ts0p);
10723 ts1a="7f000001" # "127.0.0.1"
10724 ts1="x${ts1p}${ts1a}x0000000000000000"
10725 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10726 da="test$N $(date) $RANDOM"
10727 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
10728 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:2:6:$ts1,bind=x${ts1b}00000000x0000000000000000"
10729 printf "test $F_n $TEST... " $N
10730 $CMD0 2>"${te}0" &
10731 pid0="$!"
10732 waittcp4port $ts0p 1
10733 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10734 rc1="$?"
10735 kill "$pid0" 2>/dev/null; wait;
10736 if [ "$rc1" -ne 0 ]; then
10737 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10738 echo "$CMD0 &"
10739 cat "${te}0"
10740 echo "$CMD1"
10741 cat "${te}1"
10742 numFAIL=$((numFAIL+1))
10743 listFAIL="$listFAIL $N"
10744 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10745 $PRINTF "$FAILED\n"
10746 cat "$tdiff"
10747 echo "$CMD0 &"
10748 cat "${te}0"
10749 echo "$CMD1"
10750 cat "${te}1"
10751 numFAIL=$((numFAIL+1))
10752 listFAIL="$listFAIL $N"
10753 else
10754 $PRINTF "$OK\n"
10755 if [ -n "$debug" ]; then cat $te; fi
10756 numOK=$((numOK+1))
10758 fi # NUMCOND
10760 esac
10761 PORT=$((PORT+1))
10762 N=$((N+1))
10764 PF_INET6="$($PROCAN -c |grep "^#define[[:space:]]*PF_INET6[[:space:]]" |cut -d' ' -f3)"
10766 # test the SOCKET-CONNECT address (against TCP6-LISTEN)
10767 NAME=SOCKET_CONNECT_TCP6
10768 case "$TESTS" in
10769 *%$N%*|*%functions%*|*%generic%*|*%tcp6%*|*%socket%*|*%$NAME%*)
10770 TEST="$NAME: socket connect with TCP/IPv6"
10771 if ! eval $NUMCOND; then :;
10772 elif ! testfeats tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
10773 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
10774 numCANT=$((numCANT+1))
10775 listCANT="$listCANT $N"
10776 else
10777 # start a TCP6-LISTEN process that echoes data, and send test data using
10778 # SOCKET-CONNECT, selecting TCP/IPv6. The sent data should be returned.
10779 tf="$td/test$N.stdout"
10780 te="$td/test$N.stderr"
10781 tdiff="$td/test$N.diff"
10782 ts0p=$PORT; PORT=$((PORT+1))
10783 ts0a="[::1]"
10784 ts1p=$(printf "%04x" $ts0p);
10785 ts1a="00000000000000000000000000000001" # "[::1]"
10786 ts1="x${ts1p}x00000000x${ts1a}x00000000"
10787 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10788 da="test$N $(date) $RANDOM"
10789 CMD0="$TRACE $SOCAT $opts TCP6-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
10790 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:$PF_INET6:6:$ts1,bind=x${ts1b}x00000000x00000000000000000000000000000000x00000000"
10791 printf "test $F_n $TEST... " $N
10792 $CMD0 2>"${te}0" &
10793 pid0="$!"
10794 waittcp6port $ts0p 1
10795 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10796 rc1="$?"
10797 kill "$pid0" 2>/dev/null; wait;
10798 if [ "$rc1" -ne 0 ]; then
10799 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10800 echo "$CMD0 &"
10801 cat "${te}0"
10802 echo "$CMD1"
10803 cat "${te}1"
10804 numFAIL=$((numFAIL+1))
10805 listFAIL="$listFAIL $N"
10806 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10807 $PRINTF "$FAILED\n"
10808 cat "$tdiff"
10809 echo "$CMD0 &"
10810 cat "${te}0"
10811 echo "$CMD1"
10812 cat "${te}1"
10813 numFAIL=$((numFAIL+1))
10814 listFAIL="$listFAIL $N"
10815 else
10816 $PRINTF "$OK\n"
10817 if [ -n "$debug" ]; then cat $te; fi
10818 numOK=$((numOK+1))
10820 fi ;; # NUMCOND
10821 esac
10822 PORT=$((PORT+1))
10823 N=$((N+1))
10825 # test the SOCKET-CONNECT address (against UNIX-LISTEN)
10826 NAME=SOCKET_CONNECT_UNIX
10827 case "$TESTS" in
10828 *%$N%*|*%functions%*|*%generic%*|*%unix%*|*%socket%*|*%$NAME%*)
10829 TEST="$NAME: socket connect with UNIX domain"
10830 # start a UNIX-LISTEN process that echoes data, and send test data using
10831 # SOCKET-CONNECT, selecting UNIX socket. The sent data should be returned.
10832 if ! eval $NUMCOND; then :; else
10833 tf="$td/test$N.stdout"
10834 te="$td/test$N.stderr"
10835 tdiff="$td/test$N.diff"
10836 ts0="$td/test$N.server"
10837 ts1="$td/test$N.client"
10838 da="test$N $(date) $RANDOM"
10839 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts0,$REUSEADDR PIPE"
10840 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:1:0:\\\"$ts0\\\0\\\",bind=\\\"$ts1\\\0\\\""
10841 printf "test $F_n $TEST... " $N
10842 $CMD0 2>"${te}0" &
10843 pid0="$!"
10844 waitfile $ts0 1
10845 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10846 rc1="$?"
10847 kill "$pid0" 2>/dev/null; wait;
10848 if [ "$rc1" -ne 0 ]; then
10849 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10850 echo "$CMD0 &"
10851 cat "${te}0"
10852 echo "$CMD1"
10853 cat "${te}1"
10854 numFAIL=$((numFAIL+1))
10855 listFAIL="$listFAIL $N"
10856 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10857 $PRINTF "$FAILED\n"
10858 cat "$tdiff"
10859 echo "$CMD0 &"
10860 cat "${te}0"
10861 echo "$CMD1"
10862 cat "${te}1"
10863 numFAIL=$((numFAIL+1))
10864 listFAIL="$listFAIL $N"
10865 else
10866 $PRINTF "$OK\n"
10867 if [ -n "$debug" ]; then cat $te; fi
10868 numOK=$((numOK+1))
10870 fi ;; # NUMCOND
10871 esac
10872 N=$((N+1))
10874 # test the SOCKET-LISTEN address (with TCP4-CONNECT)
10875 NAME=SOCKET_LISTEN
10876 case "$TESTS" in
10877 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10878 TEST="$NAME: socket recvfrom with TCP/IPv4"
10879 # start a SOCKET-LISTEN process that uses TCP/IPv4 and echoes data, and
10880 # send test data using TCP4-CONNECT. The sent data should be returned.
10881 if ! eval $NUMCOND; then :; else
10882 tf="$td/test$N.stdout"
10883 te="$td/test$N.stderr"
10884 tdiff="$td/test$N.diff"
10885 ts1p=$PORT; PORT=$((PORT+1))
10886 ts1a="127.0.0.1"
10887 ts0p=$(printf "%04x" $ts1p);
10888 ts0a="7f000001" # "127.0.0.1"
10889 ts0="x${ts0p}${ts0a}x0000000000000000"
10890 ts1b=$PORT; PORT=$((PORT+1))
10891 ts1="$ts1a:$ts1p"
10892 da="test$N $(date) $RANDOM"
10893 CMD0="$TRACE $SOCAT $opts SOCKET-LISTEN:2:6:$ts0,$REUSEADDR PIPE"
10894 CMD1="$TRACE $SOCAT $opts - TCP4-CONNECT:$ts1,bind=:$ts1b"
10895 printf "test $F_n $TEST... " $N
10896 $CMD0 2>"${te}0" &
10897 pid0="$!"
10898 #sleep 1
10899 waittcp4port $ts1p 1
10900 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10901 rc1="$?"
10902 kill "$pid0" 2>/dev/null; wait;
10903 if [ "$rc1" -ne 0 ]; then
10904 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10905 echo "$CMD0 &"
10906 cat "${te}0"
10907 echo "$CMD1"
10908 cat "${te}1"
10909 numFAIL=$((numFAIL+1))
10910 listFAIL="$listFAIL $N"
10911 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10912 $PRINTF "$FAILED\n"
10913 cat "$tdiff"
10914 echo "$CMD0 &"
10915 cat "${te}0"
10916 echo "$CMD1"
10917 cat "${te}1"
10918 numFAIL=$((numFAIL+1))
10919 listFAIL="$listFAIL $N"
10920 else
10921 $PRINTF "$OK\n"
10922 if [ -n "$debug" ]; then cat $te; fi
10923 numOK=$((numOK+1))
10925 fi ;; # NUMCOND
10926 esac
10927 PORT=$((PORT+1))
10928 N=$((N+1))
10930 SOCK_DGRAM="$($PROCAN -c |grep "^#define[[:space:]]*SOCK_DGRAM[[:space:]]" |cut -d' ' -f3)"
10932 # test the SOCKET-SENDTO address (against UDP4-RECVFROM)
10933 NAME=SOCKET_SENDTO
10934 case "$TESTS" in
10935 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10936 TEST="$NAME: socket sendto with UDP/IPv4"
10937 # start a UDP4-RECVFROM process that echoes data, and send test data using
10938 # SOCKET-SENDTO, selecting UDP/IPv4. The sent data should be returned.
10939 if ! eval $NUMCOND; then :; else
10940 tf="$td/test$N.stdout"
10941 te="$td/test$N.stderr"
10942 tdiff="$td/test$N.diff"
10943 ts0p=$PORT; PORT=$((PORT+1))
10944 ts0a="127.0.0.1"
10945 ts1p=$(printf "%04x" $ts0p);
10946 ts1a="7f000001" # "127.0.0.1"
10947 ts1="x${ts1p}${ts1a}x0000000000000000"
10948 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10949 da="test$N $(date) $RANDOM"
10950 CMD0="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts0p,reuseaddr,bind=$ts0a PIPE"
10951 CMD1="$TRACE $SOCAT $opts - SOCKET-SENDTO:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10952 printf "test $F_n $TEST... " $N
10953 $CMD0 2>"${te}0" &
10954 pid0="$!"
10955 waitudp4port $ts0p 1
10956 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10957 rc1="$?"
10958 kill "$pid0" 2>/dev/null; wait;
10959 if [ "$rc1" -ne 0 ]; then
10960 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10961 echo "$CMD0 &"
10962 cat "${te}0"
10963 echo "$CMD1"
10964 cat "${te}1"
10965 numFAIL=$((numFAIL+1))
10966 listFAIL="$listFAIL $N"
10967 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10968 $PRINTF "$FAILED\n"
10969 cat "$tdiff"
10970 echo "$CMD0 &"
10971 cat "${te}0"
10972 echo "$CMD1"
10973 cat "${te}1"
10974 numFAIL=$((numFAIL+1))
10975 listFAIL="$listFAIL $N"
10976 else
10977 $PRINTF "$OK\n"
10978 if [ -n "$debug" ]; then cat $te; fi
10979 numOK=$((numOK+1))
10981 fi ;; # NUMCOND
10982 esac
10983 PORT=$((PORT+1))
10984 N=$((N+1))
10986 # test the SOCKET-RECVFROM address (with UDP4-SENDTO)
10987 NAME=SOCKET_RECVFROM
10988 case "$TESTS" in
10989 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10990 TEST="$NAME: socket recvfrom with UDP/IPv4"
10991 # start a SOCKET-RECVFROM process that uses UDP/IPv4 and echoes data, and
10992 # send test data using UDP4-SENDTO. The sent data should be returned.
10993 if ! eval $NUMCOND; then :; else
10994 tf="$td/test$N.stdout"
10995 te="$td/test$N.stderr"
10996 tdiff="$td/test$N.diff"
10997 ts1p=$PORT; PORT=$((PORT+1))
10998 ts1a="127.0.0.1"
10999 ts0p=$(printf "%04x" $ts1p);
11000 ts0a="7f000001" # "127.0.0.1"
11001 ts0="x${ts0p}${ts0a}x0000000000000000"
11002 ts1b=$PORT; PORT=$((PORT+1))
11003 ts1="$ts1a:$ts1p"
11004 da="test$N $(date) $RANDOM"
11005 CMD0="$TRACE $SOCAT $opts SOCKET-RECVFROM:2:$SOCK_DGRAM:17:$ts0,reuseaddr PIPE"
11006 CMD1="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=:$ts1b"
11007 printf "test $F_n $TEST... " $N
11008 $CMD0 2>"${te}0" &
11009 pid0="$!"
11010 sleep 1 # waitudp4port $ts1p 1
11011 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
11012 rc1="$?"
11013 kill "$pid0" 2>/dev/null; wait;
11014 if [ "$rc1" -ne 0 ]; then
11015 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11016 echo "$CMD0 &"
11017 cat "${te}0"
11018 echo "$CMD1"
11019 cat "${te}1"
11020 numFAIL=$((numFAIL+1))
11021 listFAIL="$listFAIL $N"
11022 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11023 $PRINTF "$FAILED\n"
11024 cat "$tdiff"
11025 echo "$CMD0 &"
11026 cat "${te}0"
11027 echo "$CMD1"
11028 cat "${te}1"
11029 numFAIL=$((numFAIL+1))
11030 listFAIL="$listFAIL $N"
11031 else
11032 $PRINTF "$OK\n"
11033 if [ -n "$debug" ]; then cat $te; fi
11034 numOK=$((numOK+1))
11036 fi ;; # NUMCOND
11037 esac
11038 PORT=$((PORT+1))
11039 N=$((N+1))
11042 # test the SOCKET-RECV address (with UDP4-SENDTO)
11043 NAME=SOCKET_RECV
11044 case "$TESTS" in
11045 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
11046 TEST="$NAME: socket recv with UDP/IPv4"
11047 # start a SOCKET-RECV process that uses UPD/IPv4 and writes received data to file, and
11048 # send test data using UDP4-SENDTO.
11049 if ! eval $NUMCOND; then :; else
11050 tf="$td/test$N.stdout"
11051 te="$td/test$N.stderr"
11052 tdiff="$td/test$N.diff"
11053 ts1p=$PORT; PORT=$((PORT+1))
11054 ts1a="127.0.0.1"
11055 ts0p=$(printf "%04x" $ts1p);
11056 ts0a="7f000001" # "127.0.0.1"
11057 ts0="x${ts0p}${ts0a}x0000000000000000"
11058 ts1b=$PORT; PORT=$((PORT+1))
11059 ts1="$ts1a:$ts1p"
11060 da="test$N $(date) $RANDOM"
11061 CMD0="$TRACE $SOCAT $opts -u SOCKET-RECV:2:$SOCK_DGRAM:17:$ts0,reuseaddr -"
11062 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1,bind=:$ts1b"
11063 printf "test $F_n $TEST... " $N
11064 $CMD0 2>"${te}0" >"$tf" &
11065 pid0="$!"
11066 sleep 1 # waitudp4port $ts1p 1
11067 echo "$da" |$CMD1 2>>"${te}1"
11068 rc1="$?"
11069 sleep 1
11070 kill "$pid0" 2>/dev/null; wait;
11071 if [ "$rc1" -ne 0 ]; then
11072 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11073 echo "$CMD0 &"
11074 cat "${te}0"
11075 echo "$CMD1"
11076 cat "${te}1"
11077 numFAIL=$((numFAIL+1))
11078 listFAIL="$listFAIL $N"
11079 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11080 $PRINTF "$FAILED\n"
11081 cat "$tdiff"
11082 echo "$CMD0 &"
11083 cat "${te}0"
11084 echo "$CMD1"
11085 cat "${te}1"
11086 numFAIL=$((numFAIL+1))
11087 listFAIL="$listFAIL $N"
11088 else
11089 $PRINTF "$OK\n"
11090 if [ -n "$debug" ]; then cat $te; fi
11091 numOK=$((numOK+1))
11093 fi ;; # NUMCOND
11094 esac
11095 PORT=$((PORT+1))
11096 N=$((N+1))
11098 # test SOCKET-DATAGRAM (with UDP4-DATAGRAM)
11099 NAME=SOCKET_DATAGRAM
11100 case "$TESTS" in
11101 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
11102 TEST="$NAME: socket datagram via UDP/IPv4"
11103 # start a UDP4-DATAGRAM process that echoes data, and send test data using
11104 # SOCKET-DATAGRAM, selecting UDP/IPv4. The sent data should be returned.
11105 if ! eval $NUMCOND; then :; else
11106 tf="$td/test$N.stdout"
11107 te="$td/test$N.stderr"
11108 tdiff="$td/test$N.diff"
11109 ts0p=$PORT; PORT=$((PORT+1))
11110 ts1p=$PORT; PORT=$((PORT+1))
11111 ts0a="127.0.0.1"
11112 ts1b=$(printf "%04x" $ts0p);
11113 ts1a="7f000001" # "127.0.0.1"
11114 ts0b=$(printf "%04x" $ts0p)
11115 ts1b=$(printf "%04x" $ts1p)
11116 ts1="x${ts0b}${ts1a}x0000000000000000"
11117 da="test$N $(date) $RANDOM"
11118 CMD0="$TRACE $SOCAT $opts UDP4-DATAGRAM:$ts0a:$ts1p,bind=:$ts0p,reuseaddr PIPE"
11119 CMD1="$TRACE $SOCAT $opts - SOCKET-DATAGRAM:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
11120 printf "test $F_n $TEST... " $N
11121 $CMD0 2>"${te}0" &
11122 pid0="$!"
11123 waitudp4port $ts0p 1
11124 echo "$da" |$CMD1 2>>"${te}1" >"$tf"
11125 rc1="$?"
11126 kill "$pid0" 2>/dev/null; wait;
11127 if [ "$rc1" -ne 0 ]; then
11128 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11129 echo "$CMD0 &"
11130 cat "${te}0"
11131 echo "$CMD1"
11132 cat "${te}1"
11133 numFAIL=$((numFAIL+1))
11134 listFAIL="$listFAIL $N"
11135 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11136 $PRINTF "$FAILED\n"
11137 cat "$tdiff"
11138 echo "$CMD0 &"
11139 cat "${te}0"
11140 echo "$CMD1"
11141 cat "${te}1"
11142 numFAIL=$((numFAIL+1))
11143 listFAIL="$listFAIL $N"
11144 else
11145 $PRINTF "$OK\n"
11146 if [ -n "$debug" ]; then cat $te; fi
11147 numOK=$((numOK+1))
11149 fi ;; # NUMCOND
11150 esac
11151 PORT=$((PORT+1))
11152 N=$((N+1))
11154 NAME=SOCKETRANGEMASK
11155 case "$TESTS" in
11156 *%$N%*|*%functions%*|*%security%*|*%generic%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%socket%*|*%range%*|*%$NAME%*)
11157 TEST="$NAME: security of generic socket-listen with RANGE option"
11158 if ! eval $NUMCOND; then :;
11159 elif [ -z "$SECONDADDR" ]; then
11160 # we need access to more loopback addresses
11161 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
11162 numCANT=$((numCANT+1))
11163 listCANT="$listCANT $N"
11164 else
11165 ts1p=$(printf "%04x" $PORT);
11166 testserversec "$N" "$TEST" "$opts" "SOCKET-LISTEN:2:6:x${ts1p}x00000000x0000000000000000,$REUSEADDR,fork,retry=1" "" "range=x0000x7f000000:x0000xffffffff" "SOCKET-CONNECT:2:6:x${ts1p}x${SECONDADDRHEX}x0000000000000000" 4 tcp $PORT 0
11167 fi ;; # NUMCOND, $SECONDADDR
11168 esac
11169 PORT=$((PORT+1))
11170 N=$((N+1))
11173 TIOCEXCL="$($PROCAN -c |grep "^#define[[:space:]]*TIOCEXCL[[:space:]]" |cut -d' ' -f3)"
11175 # test the generic ioctl-void option
11176 NAME=IOCTL_VOID
11177 case "$TESTS" in
11178 *%$N%*|*%functions%*|*%pty%*|*%generic%*|*%$NAME%*)
11179 TEST="$NAME: test the ioctl-void option"
11180 # there are not many ioctls that apply to non global resources and do not
11181 # require root. TIOCEXCL seems to fit:
11182 # process 0 provides a pty;
11183 # process 1 opens it with the TIOCEXCL ioctl;
11184 # process 2 opens it too and fails with "device or resource busy" only when the
11185 # previous ioctl was successful
11186 if ! eval $NUMCOND; then :;
11187 elif [ -z "$TIOCEXCL" ]; then
11188 # we use the numeric value of TIOCEXL which is system dependent
11189 $PRINTF "test $F_n $TEST... ${YELLOW}no value of TIOCEXCL${NORMAL}\n" $N
11190 numCANT=$((numCANT+1))
11191 listCANT="$listCANT $N"
11192 else
11193 tp="$td/test$N.pty"
11194 tf="$td/test$N.stdout"
11195 te="$td/test$N.stderr"
11196 tdiff="$td/test$N.diff"
11197 da="test$N $(date) $RANDOM"
11198 CMD0="$TRACE $SOCAT $opts PTY,LINK=$tp pipe"
11199 CMD1="$TRACE $SOCAT $opts - file:$tp,ioctl-void=$TIOCEXCL,raw,echo=0"
11200 CMD2="$TRACE $SOCAT $opts - file:$tp,raw,echo=0"
11201 printf "test $F_n $TEST... " $N
11202 $CMD0 >/dev/null 2>"${te}0" &
11203 pid0=$!
11204 waitfile $tp 1
11205 (echo "$da"; sleep 2) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
11206 pid1=$!
11207 usleep 1000000
11208 $CMD2 >/dev/null 2>"${te}2" </dev/null
11209 rc2=$?
11210 kill $pid0 $pid1 2>/dev/null; wait
11211 if ! echo "$da" |diff - "$tf" >/dev/null; then
11212 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
11213 echo "$CMD0 &"
11214 echo "$CMD1"
11215 echo "$da" |diff - "$tf"
11216 numCANT=$((numCANT+1))
11217 listCANT="$listCANT $N"
11218 elif [ $rc2 -eq 0 ]; then
11219 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11220 echo "$CMD0 &"
11221 echo "$CMD1"
11222 echo "$CMD2"
11223 cat "${te}0" "${te}1" "${te}2"
11224 numFAIL=$((numFAIL+1))
11225 listFAIL="$listFAIL $N"
11226 else
11227 $PRINTF "$OK\n"
11228 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
11229 numOK=$((numOK+1))
11231 fi # NUMCOND, TIOCEXCL
11233 esac
11234 N=$((N+1))
11237 SOL_SOCKET="$($PROCAN -c |grep "^#define[[:space:]]*SOL_SOCKET[[:space:]]" |cut -d' ' -f3)"
11238 SO_REUSEADDR="$($PROCAN -c |grep "^#define[[:space:]]*SO_REUSEADDR[[:space:]]" |cut -d' ' -f3)"
11239 TCP_MAXSEG="$($PROCAN -c |grep "^#define[[:space:]]*TCP_MAXSEG[[:space:]]" |cut -d' ' -f3)"
11241 # Test the generic setsockopt option
11242 NAME=SETSOCKOPT
11243 case "$TESTS" in
11244 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%generic%*|*%$NAME%*)
11245 TEST="$NAME: test the setsockopt option"
11246 # Set the TCP_MAXSEG (MSS) option with a reasonable value, this should succeed.
11247 # The try again with TCP_MAXSEG=1, this fails at least on Linux.
11248 # Thus:
11249 # process 0 provides a tcp listening,forking socket
11250 # process 1 connects to this port using reasonably MSS, data transfer should
11251 # succeed.
11252 # Then,
11253 # process 2 connects to this port using a very small MSS, this should fail
11254 if ! eval $NUMCOND; then :;
11255 elif [ -z "$TCP_MAXSEG" ]; then
11256 # we use the numeric value of TCP_MAXSEG which might be system dependent
11257 $PRINTF "test $F_n $TEST... ${YELLOW}value of TCPMAXSEG not known${NORMAL}\n" $N
11258 numCANT=$((numCANT+1))
11259 listCANT="$listCANT $N"
11260 else
11261 tf="$td/test$N.stdout"
11262 te="$td/test$N.stderr"
11263 tdiff="$td/test$N.diff"
11264 da="test$N $(date) $RANDOM"
11265 CMD0="$TRACE $SOCAT $opts TCP4-L:$PORT,so-reuseaddr,fork PIPE"
11266 CMD1="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,setsockopt=6:$TCP_MAXSEG:512"
11267 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,setsockopt=6:$TCP_MAXSEG:1"
11268 printf "test $F_n $TEST... " $N
11269 $CMD0 >/dev/null 2>"${te}0" &
11270 pid0=$!
11271 waittcp4port $PORT 1
11272 (echo "$da"; sleep 1) |$CMD1 >"${tf}1" 2>"${te}1" # this should always work
11273 rc1=$?
11274 usleep 1000000
11275 (echo "$da"; sleep 1) |$CMD2 >"${tf}2" 2>"${te}2" # this should fail
11276 rc2=$?
11277 kill $pid0 $pid1 $pid2 2>/dev/null; wait
11278 if ! echo "$da" |diff - "${tf}1" >"$tdiff"; then
11279 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
11280 echo "$CMD0 &"
11281 cat ${te}0
11282 echo "$CMD1"
11283 cat ${te}1
11284 cat "$tdiff"
11285 numCANT=$((numCANT+1))
11286 listCANT="$listCANT $N"
11287 elif [ $rc1 -ne 0 ]; then
11288 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11289 echo "$CMD0 &"
11290 cat ${te}0
11291 echo "$CMD1"
11292 cat ${te}1
11293 numFAIL=$((numFAIL+1))
11294 listFAIL="$listFAIL $N"
11295 elif [ $rc2 -eq 0 ]; then
11296 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11297 echo "$CMD0 &"
11298 cat ${te}0
11299 echo "$CMD2"
11300 cat ${te}2
11301 numFAIL=$((numFAIL+1))
11302 listFAIL="$listFAIL $N"
11303 else
11304 $PRINTF "$OK\n"
11305 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
11306 numOK=$((numOK+1))
11308 fi # NUMCOND, SO_REUSEADDR
11310 esac
11311 PORT=$((PORT+1))
11312 N=$((N+1))
11314 # Test the generic setsockopt-listen option
11315 # This test, with setsockopt-int, no longer worked due to fix for options on
11316 # listening sockets
11317 # Now it got a chance again using new option setsockopt-listen
11318 #NAME=SETSOCKOPT_INT
11319 NAME=SETSOCKOPT_LISTEN
11320 case "$TESTS" in
11321 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%generic%*|*%$NAME%*)
11322 TEST="$NAME: test the setsockopt-listen option"
11323 # there are not many socket options that apply to non global resources, do not
11324 # require root, do not require a network connection, and can easily be
11325 # tested. SO_REUSEADDR seems to fit:
11326 # process 0 provides a tcp listening socket with reuseaddr;
11327 # process 1 connects to this port; thus the port is connected but no longer
11328 # listening
11329 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
11330 # (generically specified) SO_REUSEADDR socket options did not work
11331 # process 3 connects to this port; only if it is successful the test is ok
11332 if ! eval $NUMCOND; then :;
11333 elif [ -z "$SO_REUSEADDR" ]; then
11334 # we use the numeric value of SO_REUSEADDR which might be system dependent
11335 $PRINTF "test $F_n $TEST... ${YELLOW}value of SO_REUSEADDR not known${NORMAL}\n" $N
11336 numCANT=$((numCANT+1))
11337 listCANT="$listCANT $N"
11338 else
11339 tf="$td/test$N.stdout"
11340 te="$td/test$N.stderr"
11341 tdiff="$td/test$N.diff"
11342 da="test$N $(date) $RANDOM"
11343 CMD0="$TRACE $SOCAT $opts TCP4-L:$PORT,setsockopt-listen=$SOL_SOCKET:$SO_REUSEADDR:1 PIPE"
11344 CMD1="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
11345 CMD2="$CMD0"
11346 CMD3="$CMD1"
11347 printf "test $F_n $TEST... " $N
11348 $CMD0 >/dev/null 2>"${te}0" &
11349 pid0=$!
11350 waittcp4port $PORT 1
11351 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1" # this should always work
11352 rc1=$?
11353 kill $pid0 2>/dev/null; wait
11354 $CMD2 >/dev/null 2>"${te}2" &
11355 pid2=$!
11356 waittcp4port $PORT 1
11357 echo "$da" |$CMD3 >"${tf}3" 2>"${te}3"
11358 rc3=$?
11359 kill $pid2 2>/dev/null; wait
11360 if ! echo "$da" |diff - "${tf}1" >"${tdiff}1"; then
11361 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
11362 echo "$CMD0 &"
11363 cat ${te}0
11364 echo "$CMD1"
11365 cat ${te}1
11366 cat "${tdiff}1"
11367 numCANT=$((numCANT+1))
11368 listCANT="$listCANT $N"
11369 elif [ $rc3 -ne 0 ]; then
11370 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11371 echo "$CMD0 &"
11372 cat ${te}0
11373 echo "$CMD1"
11374 cat ${te}1
11375 echo "$CMD2 &"
11376 cat ${te}2
11377 echo "$CMD3"
11378 cat ${te}3
11379 numFAIL=$((numFAIL+1))
11380 listFAIL="$listFAIL $N"
11381 elif ! echo "$da" |diff - "${tf}3" >"${tdiff}3"; then
11382 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11383 echo "$CMD0 &"
11384 cat ${te}0
11385 echo "$CMD1"
11386 cat ${te}1
11387 echo "$CMD2 &"
11388 cat ${te}2
11389 echo "$CMD3"
11390 cat ${te}3
11391 cat "${tdiff}3"
11392 numCANT=$((numCANT+1))
11393 listCANT="$listCANT $N"
11394 else
11395 $PRINTF "$OK\n"
11396 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
11397 numOK=$((numOK+1))
11399 fi # NUMCOND, SO_REUSEADDR
11401 esac
11402 PORT=$((PORT+1))
11403 N=$((N+1))
11406 NAME=SCTP4STREAM
11407 case "$TESTS" in
11408 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
11409 TEST="$NAME: echo via connection to SCTP V4 socket"
11410 PORT="$((PORT+1))"
11411 if ! eval $NUMCOND; then :;
11412 elif ! testfeats sctp ip4 >/dev/null || ! runsip4 >/dev/null || ! runssctp4 "$((PORT-1))" >/dev/null; then
11413 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
11414 listCANT="$listCANT $N"
11415 numCANT=$((numCANT+1))
11416 listCANT="$listCANT $N"
11417 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
11418 # RHEL5 based systems became unusable when an sctp socket was created but
11419 # module sctp not loaded
11420 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
11421 numCANT=$((numCANT+1))
11422 listCANT="$listCANT $N"
11423 else
11424 tf="$td/test$N.stdout"
11425 te="$td/test$N.stderr"
11426 tdiff="$td/test$N.diff"
11427 tsl=$PORT
11428 ts="127.0.0.1:$tsl"
11429 da=$(date)
11430 CMD1="$TRACE $SOCAT $opts SCTP4-LISTEN:$tsl,$REUSEADDR PIPE"
11431 CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP4:$ts"
11432 printf "test $F_n $TEST... " $N
11433 $CMD1 >"$tf" 2>"${te}1" &
11434 pid1=$!
11435 waitsctp4port $tsl 1
11436 # SCTP does not seem to support half close, so we give it 1s to finish
11437 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
11438 if [ $? -ne 0 ]; then
11439 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11440 echo "$CMD1 &"
11441 cat "${te}1"
11442 echo "$CMD2"
11443 cat "${te}2"
11444 numFAIL=$((numFAIL+1))
11445 listFAIL="$listFAIL $N"
11446 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11447 $PRINTF "$FAILED\n"
11448 cat "$tdiff"
11449 numFAIL=$((numFAIL+1))
11450 listFAIL="$listFAIL $N"
11451 else
11452 $PRINTF "$OK\n"
11453 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11454 numOK=$((numOK+1))
11456 kill $pid1 2>/dev/null
11457 wait
11458 fi # NUMCOND, feats
11460 esac
11461 PORT=$((PORT+1))
11462 N=$((N+1))
11464 NAME=SCTP6STREAM
11465 case "$TESTS" in
11466 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
11467 TEST="$NAME: echo via connection to SCTP V6 socket"
11468 PORT="$((PORT+1))"
11469 if ! eval $NUMCOND; then :;
11470 elif ! testfeats sctp ip6 >/dev/null || ! runsip6 >/dev/null || ! runssctp6 "$((PORT-1))" >/dev/null; then
11471 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP6 not available${NORMAL}\n" $N
11472 numCANT=$((numCANT+1))
11473 listCANT="$listCANT $N"
11474 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
11475 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
11476 numCANT=$((numCANT+1))
11477 listCANT="$listCANT $N"
11478 else
11479 tf="$td/test$N.stdout"
11480 te="$td/test$N.stderr"
11481 tdiff="$td/test$N.diff"
11482 tsl=$PORT
11483 ts="[::1]:$tsl"
11484 da=$(date)
11485 CMD1="$TRACE $SOCAT $opts SCTP6-listen:$tsl,$REUSEADDR PIPE"
11486 CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP6:$ts"
11487 printf "test $F_n $TEST... " $N
11488 $CMD1 >"$tf" 2>"${te}1" &
11489 pid=$! # background process id
11490 waitsctp6port $tsl 1
11491 # SCTP does not seem to support half close, so we let it 1s to finish
11492 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
11493 if [ $? -ne 0 ]; then
11494 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11495 echo "$CMD1 &"
11496 cat "${te}1"
11497 echo "$CMD2"
11498 cat "${te}2"
11499 numFAIL=$((numFAIL+1))
11500 listFAIL="$listFAIL $N"
11501 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11502 $PRINTF "$FAILED: diff:\n"
11503 cat "$tdiff"
11504 numFAIL=$((numFAIL+1))
11505 listFAIL="$listFAIL $N"
11506 else
11507 $PRINTF "$OK\n"
11508 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11509 numOK=$((numOK+1))
11511 kill $pid 2>/dev/null
11512 fi # NUMCOND, feats
11514 esac
11515 PORT=$((PORT+1))
11516 N=$((N+1))
11519 if type openssl >/dev/null 2>&1; then
11520 OPENSSL_METHOD=$(openssl s_client -help 2>&1 |egrep -o -e '-tls1(_[012])?' |sort |tail -n 1)
11521 [ -z "$OPENSSL_METHOD" ] && OPENSSL_METHOD="-tls1" # just so
11524 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
11525 # performed a renegotiation. Test if this is fixed.
11526 # Note: the renegotiation feature in OpenSSL exists only up to TLSv1.2
11527 NAME=OPENSSLRENEG1
11528 case "$TESTS" in
11529 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
11530 TEST="$NAME: OpenSSL connections survive renogotiation"
11531 # connect with s_client to socat ssl-l; force a renog, then transfer data. When
11532 # data is passed the test succeeded
11533 if ! eval $NUMCOND; then :;
11534 elif ! testfeats openssl >/dev/null; then
11535 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11536 numCANT=$((numCANT+1))
11537 listCANT="$listCANT $N"
11538 elif ! type openssl >/dev/null 2>&1; then
11539 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
11540 numCANT=$((numCANT+1))
11541 listCANT="$listCANT $N"
11542 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11543 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11544 numCANT=$((numCANT+1))
11545 listCANT="$listCANT $N"
11546 else
11547 gentestcert testsrv
11548 tf="$td/test$N.stdout"
11549 te="$td/test$N.stderr"
11550 tdiff="$td/test$N.diff"
11551 da="test$N $(date) $RANDOM"
11552 init_openssl_s_client
11553 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
11554 #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
11555 CMD1="openssl s_client $OPENSSL_S_CLIENT_4 $OPENSSL_METHOD -port $PORT"
11556 printf "test $F_n $TEST... " $N
11557 $CMD0 >/dev/null 2>"${te}0" &
11558 pid0=$!
11559 waittcp4port $PORT 1
11560 (echo "R"; sleep 1; echo "$da"; sleep 1) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
11561 rc1=$?
11562 kill $pid0 2>/dev/null; wait
11563 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
11564 $PRINTF "$OK\n"
11565 numOK=$((numOK+1))
11566 else
11567 $PRINTF "$FAILED\n"
11568 echo "$CMD0 &"
11569 echo "$CMD1"
11570 cat "${te}0"
11571 # cat "${te}1"
11572 cat "$tdiff"
11573 numFAIL=$((numFAIL+1))
11574 listFAIL="$listFAIL $N"
11576 fi # NUMCOND
11578 esac
11579 PORT=$((PORT+1))
11580 N=$((N+1))
11583 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
11584 # performed a renegotiation. The first temporary fix to this problem might
11585 # leave socat in a blocking ssl-read state. Test if this has been fixed.
11586 # Note: the renegotiation feature in OpenSSL exists only up to TLSv1.2
11587 NAME=OPENSSLRENEG2
11588 case "$TESTS" in
11589 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
11590 TEST="$NAME: OpenSSL connections do not block after renogotiation"
11591 # connect with s_client to socat ssl-l; force a renog, then transfer data from
11592 # socat to the peer. When data is passed this means that the former ssl read no
11593 # longer blocks and the test succeeds
11594 if ! eval $NUMCOND; then :;
11595 elif ! testfeats openssl >/dev/null; then
11596 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11597 numCANT=$((numCANT+1))
11598 listCANT="$listCANT $N"
11599 elif ! type openssl >/dev/null 2>&1; then
11600 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
11601 numCANT=$((numCANT+1))
11602 listCANT="$listCANT $N"
11603 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11604 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11605 numCANT=$((numCANT+1))
11606 listCANT="$listCANT $N"
11607 else
11608 gentestcert testsrv
11609 tf="$td/test$N.stdout"
11610 te="$td/test$N.stderr"
11611 tdiff="$td/test$N.diff"
11612 da="test$N $(date) $RANDOM"
11613 init_openssl_s_client
11614 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
11615 #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
11616 CMD1="openssl s_client $OPENSSL_S_CLIENT_4 $OPENSSL_METHOD -port $PORT"
11617 printf "test $F_n $TEST... " $N
11618 eval "$CMD0 >/dev/null 2>\"${te}0\" &"
11619 pid0=$!
11620 waittcp4port $PORT 1
11621 (echo "R"; sleep 2) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
11622 rc1=$?
11623 kill $pid0 2>/dev/null; wait
11624 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
11625 $PRINTF "$OK\n"
11626 numOK=$((numOK+1))
11627 else
11628 $PRINTF "$FAILED\n"
11629 echo "$CMD0 &"
11630 echo "$CMD1"
11631 cat "${te}0"
11632 # cat "${te}1"
11633 cat "$tdiff"
11634 numFAIL=$((numFAIL+1))
11635 listFAIL="$listFAIL $N"
11637 fi # NUMCOND
11639 esac
11640 PORT=$((PORT+1))
11641 N=$((N+1))
11644 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
11645 # command line arguments (whole addresses, host names, file names) were longer
11646 # than 512 bytes.
11647 NAME=HOSTNAMEOVFL
11648 case "$TESTS" in
11649 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11650 TEST="$NAME: stack overflow on overly long host name"
11651 # provide a long host name to TCP-CONNECT and check socats exit code
11652 if ! eval $NUMCOND; then :; else
11653 tf="$td/test$N.stdout"
11654 te="$td/test$N.stderr"
11655 tdiff="$td/test$N.diff"
11656 da="test$N $(date) $RANDOM"
11657 # prepare long data - perl might not be installed
11658 rm -f "$td/test$N.dat"
11659 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11660 CMD0="$TRACE $SOCAT $opts TCP-CONNECT:$(cat "$td/test$N.dat"):$PORT STDIO"
11661 printf "test $F_n $TEST... " $N
11662 $CMD0 </dev/null 1>&0 2>"${te}0"
11663 rc0=$?
11664 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11665 $PRINTF "$OK\n"
11666 numOK=$((numOK+1))
11667 else
11668 $PRINTF "$FAILED\n"
11669 echo "$CMD0"
11670 cat "${te}0"
11671 numFAIL=$((numFAIL+1))
11672 listFAIL="$listFAIL $N"
11674 fi # NUMCOND
11676 esac
11677 PORT=$((PORT+1))
11678 N=$((N+1))
11680 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
11681 # command line arguments (whole addresses, host names, file names) were longer
11682 # than 512 bytes.
11683 NAME=FILENAMEOVFL
11684 case "$TESTS" in
11685 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%openssl%*|*%$NAME%*)
11686 TEST="$NAME: stack overflow on overly long file name"
11687 # provide a 600 bytes long key file option to OPENSSL-CONNECT and check socats exit code
11688 if ! eval $NUMCOND; then :; else
11689 tf="$td/test$N.stdout"
11690 te="$td/test$N.stderr"
11691 tdiff="$td/test$N.diff"
11692 da="test$N $(date) $RANDOM"
11693 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11694 CMD0="$TRACE $SOCAT $opts OPENSSL:localhost:$PORT,key=$(cat "$td/test$N.dat") STDIO"
11695 printf "test $F_n $TEST... " $N
11696 $CMD0 </dev/null 1>&0 2>"${te}0"
11697 rc0=$?
11698 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11699 $PRINTF "$OK\n"
11700 numOK=$((numOK+1))
11701 else
11702 $PRINTF "$FAILED\n"
11703 echo "$CMD0"
11704 cat "${te}0"
11705 numFAIL=$((numFAIL+1))
11706 listFAIL="$listFAIL $N"
11708 fi # NUMCOND
11710 esac
11711 PORT=$((PORT+1))
11712 N=$((N+1))
11714 # socat up to 1.7.3.0 had a stack overflow vulnerability that occurred when
11715 # command line arguments (whole addresses, host names, file names) were longer
11716 # than 512 bytes and specially crafted.
11717 NAME=NESTEDOVFL
11718 case "$TESTS" in
11719 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%exec%*|*%$NAME%*)
11720 TEST="$NAME: stack overflow on overly long nested arg"
11721 # provide a long host name to TCP-CONNECT and check socats exit code
11722 if ! eval $NUMCOND; then :; else
11723 tf="$td/test$N.stdout"
11724 te="$td/test$N.stderr"
11725 tdiff="$td/test$N.diff"
11726 da="test$N $(date) $RANDOM"
11727 # prepare long data - perl might not be installed
11728 rm -f "$td/test$N.dat"
11729 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11730 CMD0="$TRACE $SOCAT $opts EXEC:[$(cat "$td/test$N.dat")] STDIO"
11731 printf "test $F_n $TEST... " $N
11732 $CMD0 </dev/null 1>&0 2>"${te}0"
11733 rc0=$?
11734 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11735 $PRINTF "$OK\n"
11736 numOK=$((numOK+1))
11737 else
11738 $PRINTF "$FAILED\n"
11739 echo "$CMD0"
11740 cat "${te}0"
11741 numFAIL=$((numFAIL+1))
11742 listFAIL="$listFAIL $N"
11744 fi # NUMCOND
11746 esac
11747 PORT=$((PORT+1))
11748 N=$((N+1))
11751 # test for a bug in gopen that lead to crash or warning when opening a unix
11752 # domain socket with GOPEN
11753 NAME=GOPEN_UNIX_CRASH
11754 case "$TESTS" in
11755 *%$N%*|*%functions%*|*%bugs%*|*%gopen%*|*%unix%*|*%socket%*|*%$NAME%*)
11756 TEST="$NAME: check crash when connecting to a unix domain socket using address GOPEN"
11757 # a unix domain server is started in background. the check process connects to
11758 # its socket. when this process crashes or issues a warning the bug is present.
11759 # please note that a clean behaviour does not proof anything; behaviour of bug
11760 # depends on the value of an uninitialized var
11761 #set -vx
11762 if ! eval $NUMCOND; then :; else
11763 tf="$td/test$N.stdout"
11764 te="$td/test$N.stderr"
11765 ts="$td/test$N.sock"
11766 tdiff="$td/test$N.diff"
11767 da="test$N $(date) $RANDOM"
11768 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
11769 CMD1="$TRACE $SOCAT $opts -d - GOPEN:$ts"
11770 printf "test $F_n $TEST... " $N
11771 $CMD0 >/dev/null 2>"${te}0" </dev/null &
11772 pid0=$!
11773 waitunixport "$ts" 1
11774 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11775 rc1=$?
11776 kill $pid0 2>/dev/null; wait
11777 if [ $rc1 -ne 0 ]; then
11778 $PRINTF "$FAILED\n"
11779 echo "$CMD0 &"
11780 echo "$CMD1"
11781 cat "${te}0"
11782 cat "${te}1"
11783 numFAIL=$((numFAIL+1))
11784 listFAIL="$listFAIL $N"
11785 elif grep -q ' W ' "${te}1"; then
11786 $PRINTF "$FAILED\n"
11787 echo "$CMD0 &"
11788 echo "$CMD1"
11789 cat "${te}0"
11790 cat "${te}1"
11791 numFAIL=$((numFAIL+1))
11792 listFAIL="$listFAIL $N"
11793 elif ! echo "$da" |diff - ${tf}1 >"$tdiff"; then
11794 $PRINTF "$FAILED\n"
11795 echo "$CMD0 &"
11796 echo "$CMD1"
11797 cat "${te}0"
11798 cat "${te}1"
11799 cat "$tdiff"
11800 numFAIL=$((numFAIL+1))
11801 listFAIL="$listFAIL $N"
11802 else
11803 $PRINTF "$OK\n"
11804 numOK=$((numOK+1))
11806 fi # NUMCOND
11808 esac
11809 N=$((N+1))
11812 # test if socat keeps an existing file where it wanted to create a UNIX socket
11813 NAME=UNIXLISTEN_KEEPFILE
11814 case "$TESTS" in
11815 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
11816 TEST="$NAME: socat keeps an existing file where it wanted to create a UNIX socket"
11817 # we create a file and start socat with UNIX-LISTEN on this file. expected
11818 # behaviour: socat exits immediately with error, but keeps the file
11819 # up to 1.7.1.3, it removed the file
11820 if ! eval $NUMCOND; then :; else
11821 tf="$td/test$N.file"
11822 te="$td/test$N.stderr"
11823 CMD0="$TRACE $SOCAT $opts -u UNIX-LISTEN:$tf /dev/null"
11824 printf "test $F_n $TEST... " $N
11825 rm -f "$tf"; touch "$tf"
11826 $CMD0 >/dev/null 2>"${te}0"
11827 rc0=$?
11828 if [ $rc0 -ne 0 -a -f "$tf" ]; then
11829 $PRINTF "$OK\n"
11830 numOK=$((numOK+1))
11831 else
11832 $PRINTF "$FAILED\n"
11833 echo "$CMD0"
11834 cat "${te}0"
11835 numFAIL=$((numFAIL+1))
11836 listFAIL="$listFAIL $N"
11838 fi # NUMCOND
11840 esac
11841 N=$((N+1))
11844 # PTY address allowed to sepcify address parameters but ignored them
11845 NAME=PTY_VOIDARG
11846 case "$TESTS" in
11847 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
11848 TEST="$NAME: check if address params of PTY produce error"
11849 # invoke socat with address PTY and some param; expect an error
11850 if ! eval $NUMCOND; then :; else
11851 tf="$td/test$N.stdout"
11852 te="$td/test$N.stderr"
11853 tdiff="$td/test$N.diff"
11854 da="test$N $(date) $RANDOM"
11855 CMD0="$TRACE $SOCAT $opts /dev/null PTY:/tmp/xyz"
11856 printf "test $F_n $TEST... " $N
11857 $CMD0 >/dev/null 2>"${te}0"
11858 rc0=$?
11859 if [ $rc0 -ne 0 ]; then
11860 $PRINTF "$OK\n"
11861 numOK=$((numOK+1))
11862 else
11863 $PRINTF "$FAILED\n"
11864 echo "$CMD0"
11865 cat "${te}0"
11866 numFAIL=$((numFAIL+1))
11867 listFAIL="$listFAIL $N"
11869 fi # NUMCOND
11871 esac
11872 N=$((N+1))
11875 # incomplete writes were reported but led to data loss
11876 NAME=INCOMPLETE_WRITE
11877 case "$TESTS" in
11878 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
11879 TEST="$NAME: check if incomplete writes are handled properly"
11880 # write to a nonblocking fd a block that is too large for atomic write
11881 # and check if all data arrives
11882 if ! eval $NUMCOND; then :; else
11883 tf="$td/test$N.stdout"
11884 te="$td/test$N.stderr"
11885 tp="$td/test$N.pipe"
11886 tw="$td/test$N.wc-c"
11887 # this is the size we write() in one call; data is never stored on disk, so
11888 # make it large enough to exceed any atomic write size; but higher number might
11889 # take much time
11890 bytes=100000 # for Linux 2.6.? this must be >65536
11891 CMD0="$TRACE $SOCAT $opts -u PIPE:$tp STDOUT"
11892 CMD1="$TRACE $SOCAT $opts -u -b $bytes OPEN:/dev/zero,readbytes=$bytes FILE:$tp,o-nonblock"
11893 printf "test $F_n $TEST... " $N
11894 $CMD0 2>"${te}0" |wc -c >"$tw" &
11895 pid=$!
11896 waitfile "$tp"
11897 $CMD1 2>"${te}1" >"${tf}1"
11898 rc1=$?
11899 wait
11900 if [ $rc1 -ne 0 ]; then
11901 $PRINTF "$NO_RESULT\n"
11902 numCANT=$((numCANT+1))
11903 listCANT="$listCANT $N"
11904 elif [ ! -e "$tw" ]; then
11905 $PRINTF "$NO_RESULT\n"
11906 numCANT=$((numCANT+1))
11907 listCANT="$listCANT $N"
11908 elif [ "$bytes" -eq $(cat "$tw") ]; then
11909 $PRINTF "$OK\n"
11910 numOK=$((numOK+1))
11911 else
11912 $PRINTF "$FAILED\n"
11913 echo "transferred only $(cat $tw) of $bytes bytes" >&2
11914 numFAIL=$((numFAIL+1))
11915 listFAIL="$listFAIL $N"
11917 fi # NUMCOND
11919 esac
11920 N=$((N+1))
11923 NAME=OPENSSL_ANULL
11924 case "$TESTS" in
11925 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
11926 TEST="$NAME: OpenSSL server with cipher aNULL "
11927 if ! eval $NUMCOND; then :;
11928 elif ! testfeats openssl >/dev/null; then
11929 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11930 numCANT=$((numCANT+1))
11931 listCANT="$listCANT $N"
11932 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11933 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11934 numCANT=$((numCANT+1))
11935 listCANT="$listCANT $N"
11936 else
11937 tf="$td/test$N.stdout"
11938 te="$td/test$N.stderr"
11939 tdiff="$td/test$N.diff"
11940 da="test$N $(date) $RANDOM"
11941 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,ciphers=aNULL,verify=0 pipe"
11942 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,ciphers=aNULL,verify=0,$SOCAT_EGD"
11943 printf "test $F_n $TEST... " $N
11944 eval "$CMD2 2>\"${te}1\" &"
11945 pid=$! # background process id
11946 waittcp4port $PORT
11947 echo "$da" |$CMD >$tf 2>"${te}2"
11948 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
11949 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
11950 #echo "$CMD2 &"
11951 #echo "$CMD"
11952 #cat "${te}1"
11953 #cat "${te}2"
11954 #cat "$tdiff"
11955 numOK=$((numOK+1))
11956 else
11957 $PRINTF "$OK\n"
11958 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11959 numOK=$((numOK+1))
11961 kill $pid 2>/dev/null
11962 wait
11963 fi ;; # NUMCOND, feats
11964 esac
11965 PORT=$((PORT+1))
11966 N=$((N+1))
11969 while read KEYW FEAT ADDR IPPORT; do
11970 if [ -z "$KEYW" ]|| [[ "$KEYW" == \#* ]]; then continue; fi
11971 RUNS=$(tolower $KEYW)
11972 PROTO=$KEYW
11973 proto="$(echo "$PROTO" |tr A-Z a-z)"
11974 feat="$(tolower "$FEAT")"
11975 # test the max-children option on really connection oriented sockets
11976 NAME=${KEYW}MAXCHILDREN
11977 case "$TESTS" in
11978 *%$N%*|*%functions%*|*%maxchildren%*|*%$feat%*|*%$proto%*|*%socket%*|*%$NAME%*)
11979 TEST="$NAME: max-children option"
11980 # start a listen process with max-children=1; connect with a client, let it
11981 # sleep some time before sending data; connect with second client that sends
11982 # data immediately. If max-children is working correctly the first data should
11983 # arrive first because the second process has to wait.
11984 if ! eval $NUMCOND; then :;
11985 elif ! testfeats "$FEAT" >/dev/null; then
11986 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
11987 numCANT=$((numCANT+1))
11988 listCANT="$listCANT $N"
11989 elif ! runs$RUNS >/dev/null; then
11990 $PRINTF "test $F_n $TEST... ${YELLOW}$(toupper $RUNS) not available${NORMAL}\n" $N
11991 numCANT=$((numCANT+1))
11992 listCANT="$listCANT $N"
11993 else
11994 case "X$IPPORT" in
11995 "XPORT")
11996 tsl=$PORT # test socket listen address
11997 tsc="$ADDR:$PORT" # test socket connect address
11998 PORT=$((PORT+1)) ;;
12000 tsl="$(eval echo "$ADDR")" # resolve $N
12001 tsc=$tsl
12002 esac
12003 #ts="$td/test$N.sock"
12004 tf="$td/test$N.stdout"
12005 te="$td/test$N.stderr"
12006 tdiff="$td/test$N.diff"
12007 da="test$N $(date) $RANDOM"
12008 CMD0="$TRACE $SOCAT $opts -U FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
12009 CMD1="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,shut-null"
12010 printf "test $F_n $TEST... " $N
12011 $CMD0 >/dev/null 2>"${te}0" &
12012 pid0=$!
12013 wait${proto}port $tsl 1
12014 (echo "$da 1"; sleep 2) |$CMD1 >"${tf}1" 2>"${te}1" &
12015 pid1=$!
12016 sleep 1
12017 echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2" &
12018 pid2=$!
12019 sleep 2
12020 kill $pid1 $pid2 $pid0 2>/dev/null; wait
12021 if echo -e "$da 1\n$da 2" |diff - $tf >$tdiff; then
12022 $PRINTF "$OK\n"
12023 numOK=$((numOK+1))
12024 else
12025 $PRINTF "$FAILED\n"
12026 echo "$CMD0 &"
12027 echo "(echo \"$da 1\"; sleep 2) |$CMD1"
12028 echo "echo \"$da 2\" |$CMD1"
12029 cat "${te}0"
12030 cat "${te}1"
12031 cat "${te}2"
12032 cat "$tdiff"
12033 numFAIL=$((numFAIL+1))
12034 listFAIL="$listFAIL $N"
12036 fi # NUMCOND
12038 esac
12039 N=$((N+1))
12040 done <<<"
12041 TCP4 TCP 127.0.0.1 PORT
12042 TCP6 TCP [::1] PORT
12043 SCTP4 SCTP 127.0.0.1 PORT
12044 SCTP6 SCTP [::1] PORT
12045 UNIX unix $td/test\$N.server -
12047 # debugging this hanging test was difficult - following lessons learned:
12048 # kill <parent> had no effect when child process existed
12049 # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
12050 # using the TRACE feature lets above kill command kill strace, not socat
12051 # care for timing, understand what you want :-)
12054 while read KEYW FEAT ADDR IPPORT SHUT; do
12055 if [ -z "$KEYW" ]|| [[ "$KEYW" == \#* ]]; then continue; fi
12056 RUNS=$(tolower $KEYW)
12057 PROTO=$KEYW
12058 proto="$(echo "$PROTO" |tr A-Z a-z)"
12059 # test the max-children option on pseudo connected sockets
12060 NAME=${KEYW}MAXCHILDREN
12061 case "$TESTS" in
12062 *%$N%*|*%functions%*|*%maxchildren%*|*%socket%*|*%$NAME%*)
12063 TEST="$NAME: max-children option"
12064 # start a listen process with max-children=1; connect with a client, let it
12065 # send data and then sleep; connect with second client that wants to send
12066 # data immediately, but keep first client active until server terminates.
12067 #If max-children is working correctly only the first data should
12068 # arrive.
12069 if ! eval $NUMCOND; then :;
12070 elif ! testfeats "$FEAT" >/dev/null; then
12071 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
12072 numCANT=$((numCANT+1))
12073 listCANT="$listCANT $N"
12074 elif ! runs$RUNS >/dev/null; then
12075 $PRINTF "test $F_n $TEST... ${YELLOW}$(toupper $RUNS) not available${NORMAL}\n" $N
12076 numCANT=$((numCANT+1))
12077 listCANT="$listCANT $N"
12078 else
12079 case "X$IPPORT" in
12080 "XPORT")
12081 tsl=$PORT # test socket listen address
12082 tsc="$ADDR:$PORT" # test socket connect address
12083 PORT=$((PORT+1)) ;;
12085 tsl="$(eval echo "$ADDR")" # resolve $N
12086 tsc=$tsl
12087 esac
12088 #ts="$td/test$N.sock"
12089 tf="$td/test$N.stdout"
12090 te="$td/test$N.stderr"
12091 tdiff="$td/test$N.diff"
12092 da="test$N $(date) $RANDOM"
12093 # on some Linux distributions it hangs, thus -T option here
12094 CMD0="$TRACE $SOCAT $opts -U -T 4 FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
12095 CMD1="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,$SHUT"
12096 printf "test $F_n $TEST... " $N
12097 $CMD0 >/dev/null 2>"${te}0" &
12098 pid0=$!
12099 wait${proto}port $tsl 1
12100 (echo "$da 1"; sleep 3) |$CMD1 >"${tf}1" 2>"${te}1" &
12101 pid1=$!
12102 sleep 1
12103 echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2" &
12104 pid2=$!
12105 sleep 1
12106 cpids="$(childpids $pid0)"
12107 kill $pid1 $pid2 $pid0 $cpids 2>/dev/null; wait
12108 if echo -e "$da 1" |diff - $tf >$tdiff; then
12109 $PRINTF "$OK\n"
12110 numOK=$((numOK+1))
12111 else
12112 $PRINTF "$FAILED\n"
12113 echo "$CMD0 &"
12114 echo "(echo \"$da 1\"; sleep 2) |$CMD1"
12115 echo "echo \"$da 2\" |$CMD1"
12116 cat "${te}0"
12117 cat "${te}1"
12118 cat "${te}2"
12119 cat "$tdiff"
12120 numFAIL=$((numFAIL+1))
12121 listFAIL="$listFAIL $N"
12123 fi # NUMCOND
12125 esac
12126 N=$((N+1))
12127 done <<<"
12128 UDP4 UDP 127.0.0.1 PORT shut-null
12129 UDP6 UDP [::1] PORT shut-null
12131 # debugging this hanging test was difficult - following lessons learned:
12132 # kill <parent> had no effect when child process existed
12133 # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
12134 # using the TRACE feature lets above kill command kill strace, not socat
12135 # care for timing, understand what you want :-)
12138 # socat up to 1.7.2.0 had a bug in xioscan_readline() that could be exploited
12139 # to overflow a heap based buffer (socat security advisory 3)
12140 # problem reported by Johan Thillemann
12141 NAME=READLINE_OVFL
12142 case "$TESTS" in
12143 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%readline%*|*%$NAME%*)
12144 TEST="$NAME: test for buffer overflow in readline prompt handling"
12145 # address 1 is the readline where write data was handled erroneous
12146 # address 2 provides data to trigger the buffer overflow
12147 # when no SIGSEGV or so occurs the test succeeded (bug fixed)
12148 if ! eval $NUMCOND; then :;
12149 elif ! feat=$(testfeats readline pty); then
12150 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
12151 numCANT=$((numCANT+1))
12152 listCANT="$listCANT $N"
12153 else
12154 tf="$td/test$N.stdout"
12155 te="$td/test$N.stderr"
12156 ti="$td/test$N.data"
12157 CMD0="$SOCAT $opts READLINE $ti"
12158 printf "test $F_n $TEST... " $N
12159 # prepare long data - perl might not be installed
12160 #perl -e 'print "\r","Z"x513' >"$ti"
12161 echo $E -n "\rA" >"$ti"
12162 i=0; while [ $i -lt 32 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$ti"; let i=i+1; done
12163 $TRACE $SOCAT - SYSTEM:"$CMD0; echo rc=\$? >&2",pty >/dev/null 2>"${te}0"
12164 rc=$?
12165 rc0="$(grep ^rc= "${te}0" |sed 's/.*=//')"
12166 if [ $rc -ne 0 ]; then
12167 $PRINTF "${YELLOW}framework failed${NORMAL}\n"
12168 elif [ $rc0 -eq 0 ]; then
12169 $PRINTF "$OK\n"
12170 numOK=$((numOK+1))
12171 else
12172 $PRINTF "$FAILED\n"
12173 echo "$CMD0"
12174 grep -v ^rc= "${te}0"
12175 numFAIL=$((numFAIL+1))
12176 listFAIL="$listFAIL $N"
12178 fi # NUMCOND
12180 esac
12181 PORT=$((PORT+1))
12182 N=$((N+1))
12185 # socat up to 1.7.2.1 did only shutdown() but not close() an accept() socket
12186 # that was rejected due to range, tcpwrap, lowport, or sourceport option.
12187 # This file descriptor leak could be used for a denial of service attack.
12188 NAME=FDLEAK
12189 case "$TESTS" in
12190 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
12191 TEST="$NAME: file descriptor leak with range option"
12192 # have a TCP-LISTEN with range option; connect with wrong source address until
12193 # "open files" limit would exceed. When server continues operation the bug is
12194 # not present.
12195 if ! eval $NUMCOND; then :; else
12196 tf="$td/test$N.stdout"
12197 te="$td/test$N.stderr"
12198 tdiff="$td/test$N.diff"
12199 da="test$N $(date) $RANDOM"
12200 RLIMIT_NOFILE="$(ulimit -n)"
12201 if ! [[ "$RLIMIT_NOFILE" =~ ^[0-9][0-9]*$ ]]; then
12202 $PRINTF "${YELLOW}cannot determine ulimit -n"
12203 else
12204 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR,range=$LOCALHOST:255.255.255.255 PIPE"
12205 CMD1="$TRACE $SOCAT $opts -t 0 /dev/null TCP:$SECONDADDR:$PORT,bind=$SECONDADDR"
12206 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,bind=$LOCALHOST"
12207 printf "test $F_n $TEST... " $N
12208 $CMD0 >/dev/null 2>"${te}0" &
12209 pid0=$!
12210 waittcp4port $PORT 1
12211 while [ $RLIMIT_NOFILE -gt 0 ]; do
12212 $CMD1 >/dev/null 2>>"${te}1"
12213 let RLIMIT_NOFILE=RLIMIT_NOFILE-1
12214 done
12215 echo "$da" |$CMD2 >"${tf}2" 2>"${te}2"
12216 rc2=$?
12217 kill $pid0 2>/dev/null; wait
12218 echo -e "$da" |diff "${tf}2" - >$tdiff
12219 if [ $rc2 -ne 0 ]; then
12220 $PRINTF "$FAILED\n"
12221 echo "$CMD2 &"
12222 cat "${te}2"
12223 numFAIL=$((numFAIL+1))
12224 listFAIL="$listFAIL $N"
12225 elif [ -f "$tdiff" -a ! -s "$tdiff" ]; then
12226 $PRINTF "$OK\n"
12227 numOK=$((numOK+1))
12228 else
12229 $PRINTF "$FAILED\n"
12230 echo "$CMD0 &"
12231 echo "$CMD1"
12232 echo "$CMD2"
12233 cat "${te}0"
12234 cat "${te}1"
12235 cat "${te}2"
12236 numFAIL=$((numFAIL+1))
12237 listFAIL="$listFAIL $N"
12239 fi # ulimit -n
12240 fi # NUMCOND
12242 esac
12243 PORT=$((PORT+1))
12244 N=$((N+1))
12247 if false; then # this overflow is not reliably reproducable
12248 # socat up to 2.0.0-b6 did not check the length of the PROXY-CONNECT command line paramters when copying them into the HTTP request buffer. This could lead to a buffer overflow.
12249 NAME=PROXY_ADDR_OVFL
12250 case "$TESTS" in
12251 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
12252 TEST="$NAME: proxy address parameters overflow"
12253 # invoke socat PROXY-CONNECT with long proxy server and target server names. If it terminates with exit code >= 128 it is vulnerable
12254 # However, even if vulnerable it often does not crash. Therefore we try to use a boundary check program like ElectricFence; only with its help we can tell that clean run proofs absence of vulnerability
12255 if ! eval $NUMCOND; then :; else
12256 tf="$td/test$N.stdout"
12257 te="$td/test$N.stderr"
12258 tdiff="$td/test$N.diff"
12259 da="test$N $(date) $RANDOM"
12260 EF=; for p in ef; do
12261 if type ef >/dev/null 2>&1; then
12262 EF="ef "; break
12264 done
12265 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR FILE:/dev/null"
12266 #CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$(perl -e "print 'A' x 256"):$(perl -e "print 'A' x 256"):80"
12267 CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:localhost:$(perl -e "print 'A' x 384"):80,proxyport=$PORT"
12268 printf "test $F_n $TEST... " $N
12269 $CMD0 >/dev/null 2>"${te}0" &
12270 pid0=$!
12271 waittcp4port $PORT 1
12272 $CMD1 >/dev/null 2>"${te}1"
12273 rc1=$?
12274 if [ $rc1 -lt 128 ]; then
12275 if [ "$EF" ]; then
12276 $PRINTF "$OK\n"
12277 numOK=$((numOK+1))
12278 else
12279 $PRINTF "$UNKNOWN $RED(install ElectricFEnce!)$NORMAL\n"
12280 numCANT=$((num+1))
12281 listCANT="$listCANT $N"
12283 else
12284 $PRINTF "$FAILED\n"
12285 echo "$CMD1"
12286 cat "${te}"
12287 numFAIL=$((numFAIL+1))
12288 listFAIL="$listFAIL $N"
12290 fi # NUMCOND
12292 esac
12293 PORT=$((PORT+1))
12294 N=$((N+1))
12295 fi # false
12298 # LISTEN addresses in socat up to 1.7.2.1 applied many file descriptor, socket,
12299 # and TCP options only to the listening socket instead of the connection socket.
12300 NAME=LISTEN_KEEPALIVE
12301 case "$TESTS" in
12302 *%$N%*|*%functions%*|*%bugs%*|*%listen%*|*%keepalive%*|*%socket%*|*%$NAME%*)
12303 TEST="$NAME: keepalive option is applied to connection socket"
12304 # instance 0 has TCP-LISTEN with option so-keepalive and invokes filan after
12305 # accept(). filan writes its output to the socket. instance 1 connects to
12306 # instance 0. The value of the sockets so-keepalive option is checked, it must
12307 # be 1
12308 if ! eval $NUMCOND; then :; else
12309 tf="$td/test$N.stdout"
12310 te="$td/test$N.stderr"
12311 #tdiff="$td/test$N.diff"
12312 #da="test$N $(date) $RANDOM"
12313 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,so-keepalive EXEC:\"$FILAN -i 1\",nofork"
12314 CMD1="$TRACE $SOCAT $opts - TCP4:$LOCALHOST:$PORT"
12315 printf "test $F_n $TEST... " $N
12316 eval $CMD0 >/dev/null 2>"${te}0" &
12317 pid0=$!
12318 waittcp4port $PORT 1
12319 $CMD1 >"${tf}1" 2>"${te}1"
12320 KEEPALIVE="$(cat "${tf}1" |tail -n +2 |sed -e "s/.*KEEPALIVE=//" -e "s/[[:space:]].*//")"
12321 rc1=$?
12322 kill $pid0 2>/dev/null; wait
12323 if [ -z "$KEEPALIVE" ]; then
12324 $PRINTF "$NO_RESULT\n"
12325 echo "$CMD0 &"
12326 echo "$CMD1"
12327 cat "${te}0"
12328 cat "${te}1"
12329 numCANT=$((numCANT+1))
12330 listCANT="$listCANT $N"
12331 elif [ "$KEEPALIVE" = "1" ]; then
12332 $PRINTF "$OK\n";
12333 numOK=$((numOK+1))
12334 else
12335 $PRINTF "$FAILED\n"
12336 echo "$CMD0 &"
12337 echo "$CMD1"
12338 cat "${te}0"
12339 cat "${te}1"
12340 numFAIL=$((numFAIL+1))
12341 listFAIL="$listFAIL $N"
12343 fi # NUMCOND
12345 esac
12346 PORT=$((PORT+1))
12347 N=$((N+1))
12350 # OPENSSL-CONNECT with bind option failed on some systems (eg.FreeBSD, but not
12351 # Linux) with "Invalid argument".
12352 NAME=OPENSSL_CONNECT_BIND
12353 case "$TESTS" in
12354 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12355 TEST="$NAME: test OPENSSL-CONNECT with bind option"
12356 # have a simple SSL server that just echoes data.
12357 # connect with socat using OPENSSL-CONNECT with bind, send data and check if the
12358 # reply is identical.
12359 if ! eval $NUMCOND; then :;
12360 elif ! testfeats openssl >/dev/null; then
12361 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
12362 numCANT=$((numCANT+1))
12363 listCANT="$listCANT $N"
12364 else
12365 gentestcert testsrv
12366 tf0="$td/test$N.0.stdout"
12367 te0="$td/test$N.0.stderr"
12368 tf1="$td/test$N.1.stdout"
12369 te1="$td/test$N.1.stderr"
12370 tdiff="$td/test$N.diff"
12371 da="test$N $(date) $RANDOM"
12372 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 PIPE"
12373 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,bind=$LOCALHOST,verify=0"
12374 printf "test $F_n $TEST... " $N
12375 $CMD0 >/dev/null 2>"$te0" &
12376 pid0=$!
12377 waittcp4port $PORT 1
12378 echo "$da" |$CMD1 >"$tf1" 2>"$te1"
12379 rc1=$?
12380 kill $pid0 2>/dev/null; wait
12381 if [ "$rc1" -ne 0 ]; then
12382 $PRINTF "$FAILED\n"
12383 echo "$CMD0 &"
12384 echo "$CMD1"
12385 cat "$te0"
12386 cat "$te1"
12387 numFAIL=$((numFAIL+1))
12388 listFAIL="$listFAIL $N"
12389 elif ! echo "$da" |diff - $tf1 >"$tdiff"; then
12390 $PRINTF "$FAILED\n"
12391 echo "$CMD0 &"
12392 echo "$CMD1"
12393 cat "${te}0"
12394 cat "${te}1"
12395 cat "$tdiff"
12396 numFAIL=$((numFAIL+1))
12397 listFAIL="$listFAIL $N"
12398 else
12399 $PRINTF "$OK\n"
12400 numOK=$((numOK+1))
12402 fi # NUMCOND
12404 esac
12405 PORT=$((PORT+1))
12406 N=$((N+1))
12409 # socat up to version 1.7.2.3
12410 # had a bug that converted a bit mask of 0 internally to 0xffffffff
12411 NAME=TCP4RANGE_0BITS
12412 case "$TESTS" in
12413 *%$N%*|*%functions%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
12414 TEST="$NAME: correct evaluation of range mask 0"
12415 if ! eval $NUMCOND; then :;
12416 elif [ -z "$SECONDADDR" ]; then
12417 # we need access to a second address
12418 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
12419 numCANT=$((numCANT+1))
12420 listCANT="$listCANT $N"
12421 else
12422 tf="$td/test$N.stdout"
12423 te="$td/test$N.stderr"
12424 tdiff="$td/test$N.diff"
12425 da="test$N $(date) $RANDOM"
12426 #testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
12427 CMD0="$TRACE $SOCAT $opts -u TCP4-LISTEN:$PORT,$REUSEADDR,range=127.0.0.1/0 CREATE:$tf"
12428 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$SECONDADDR:$PORT,bind=$SECONDADDR"
12429 printf "test $F_n $TEST... " $N
12430 $CMD0 2>"${te}0" &
12431 pid0=$!
12432 waittcp4port $PORT 1
12433 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12434 rc1=$?
12435 sleep 1
12436 kill $pid0 2>/dev/null; wait
12437 if [ $rc1 != 0 ]; then
12438 $PRINTF "${YELLOW}invocation failed${NORMAL}\n"
12439 numCANT=$((numCANT+1))
12440 listCANT="$listCANT $N"
12441 elif ! [ -f "$tf" ]; then
12442 $PRINTF "$FAILED\n"
12443 echo "$CMD0 &"
12444 echo "$CMD1"
12445 cat "${te}0"
12446 cat "${te}1"
12447 numFAIL=$((numFAIL+1))
12448 listFAIL="$listFAIL $N"
12449 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
12450 $PRINTF "${YELLOW}diff failed${NORMAL}\n"
12451 numCANT=$((numCANT+1))
12452 listCANT="$listCANT $N"
12453 else
12454 $PRINTF "$OK\n"
12455 numOK=$((numOK+1))
12458 fi ;; # $SECONDADDR, NUMCOND
12459 esac
12460 PORT=$((PORT+1))
12461 N=$((N+1))
12464 # test: OPENSSL sets of environment variables with important values of peer certificate
12465 while read ssldist MODE MODULE FIELD TESTADDRESS PEERADDRESS VALUE; do
12466 if [ -z "$ssldist" ] || [[ "$ssldist" == \#* ]]; then continue; fi
12468 SSLDIST=$(toupper $ssldist)
12469 NAME="ENV_${SSLDIST}_${MODE}_${MODULE}_${FIELD}"
12470 case "$TESTS" in
12471 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$ssldist%*|*%envvar%*|*%$NAME%*)
12472 TEST="$NAME: $SSLDIST sets env SOCAT_${SSLDIST}_${MODULE}_${FIELD}"
12473 # have a server accepting a connection and invoking some shell code. The shell
12474 # code extracts and prints the SOCAT related environment vars.
12475 # outside code then checks if the environment contains the variables correctly
12476 # describing the desired field.
12477 FEAT=$(echo "$ssldist" |tr a-z A-Z)
12478 if ! eval $NUMCOND; then :;
12479 elif ! testfeats $FEAT >/dev/null; then
12480 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
12481 numCANT=$((numCANT+1))
12482 listCANT="$listCANT $N"
12483 else
12484 tf="$td/test$N.stdout"
12485 te="$td/test$N.stderr"
12486 gentestcert testsrv
12487 gentestcert testcli
12488 test_proto=tcp4
12489 case "$MODE" in
12490 SERVER)
12491 CMD0="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
12492 CMD1="$SOCAT $opts -u /dev/null $PEERADDRESS"
12493 printf "test $F_n $TEST... " $N
12494 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
12495 pid0=$!
12496 wait${test_proto}port $PORT 1
12497 $CMD1 2>"${te}1"
12498 rc1=$?
12499 waitfile "$tf" 2
12500 kill $pid0 2>/dev/null; wait
12502 CLIENT)
12503 CMD0="$SOCAT $opts -u /dev/null $PEERADDRESS"
12504 CMD1="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
12505 printf "test $F_n $TEST... " $N
12506 $CMD0 2>"${te}0" &
12507 pid0=$!
12508 wait${test_proto}port $PORT 1
12509 eval "$CMD1 2>\"${te}1\" >\"$tf\""
12510 rc1=$?
12511 waitfile "$tf" 2
12512 kill $pid0 2>/dev/null; wait
12514 esac
12515 if [ $rc1 != 0 ]; then
12516 $PRINTF "$NO_RESULT (client failed):\n"
12517 echo "$CMD0 &"
12518 cat "${te}0"
12519 echo "$CMD1"
12520 cat "${te}1"
12521 numCANT=$((numCANT+1))
12522 listCANT="$listCANT $N"
12523 elif effval="$(grep SOCAT_${SSLDIST}_${MODULE}_${FIELD} "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")";
12524 [ "$effval" = "$VALUE" ]; then
12525 $PRINTF "$OK\n"
12526 if [ "$debug" ]; then
12527 echo "$CMD0 &"
12528 cat "${te}0"
12529 echo "$CMD1"
12530 cat "${te}1"
12532 numOK=$((numOK+1))
12533 else
12534 $PRINTF "$FAILED\n"
12535 echo "expected \"$VALUE\", got \"$effval\"" >&2
12536 echo "$CMD0 &"
12537 cat "${te}0"
12538 echo "$CMD1"
12539 cat "${te}1"
12540 numFAIL=$((numFAIL+1))
12541 listFAIL="$listFAIL $N"
12543 fi # NUMCOND, feats
12545 esac
12546 N=$((N+1))
12548 done <<<"
12549 openssl SERVER X509 ISSUER OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ISSUER
12550 openssl SERVER X509 SUBJECT OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_SUBJECT
12551 openssl SERVER X509 COMMONNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_COMMONNAME
12552 openssl SERVER X509 COUNTRYNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_COUNTRYNAME
12553 openssl SERVER X509 LOCALITYNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_LOCALITYNAME
12554 openssl SERVER X509 ORGANIZATIONALUNITNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ORGANIZATIONALUNITNAME
12555 openssl SERVER X509 ORGANIZATIONNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ORGANIZATIONNAME
12556 openssl CLIENT X509 SUBJECT OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_SUBJECT
12557 openssl CLIENT X509 ISSUER OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_ISSUER
12561 ###############################################################################
12562 # tests: option umask with "passive" NAMED group addresses
12563 while read addr fileopt addropts proto diropt ADDR2; do
12564 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12565 # some passive (listening...) filesystem based addresses did not implement the
12566 # umask option
12567 ADDR=$(toupper $addr)
12568 ADDR_=${ADDR/-/_}
12569 PROTO=$(toupper $proto)
12570 if [ "$diropt" = "." ]; then diropt=; fi
12571 if [ "$fileopt" = "." ]; then fileopt=; fi
12572 if [ "$addropts" = "." ]; then addropts=; fi
12573 NAME=${ADDR_}_UMASK
12574 case "$TESTS" in
12575 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%$NAME%*)
12576 TEST="$NAME: $ADDR applies option umask"
12577 # start a socat process with passive/listening file system entry. Check the
12578 # permissions of the FS entry, then terminate the process.
12579 # Test succeeds when FS entry exists and has expected permissions.
12580 if ! eval $NUMCOND; then :; else
12581 if [ $ADDR = PTY ]; then set -xv; fi
12582 tlog="$td/test$N.log"
12583 te0="$td/test$N.0.stderr"
12584 tsock="$td/test$N.sock"
12585 if [ -z "$fileopt" ]; then
12586 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
12587 else
12588 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
12590 printf "test $F_n $TEST... " $N
12591 $CMD0 >/dev/null 2>"$te0" &
12592 pid0=$!
12593 wait${proto} $tsock 1 2>"$tlog"
12594 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12595 perms=$(fileperms "$tsock")
12596 kill $pid0 2>>"$tlog"
12597 wait
12598 if [ "$ERRNOENT" ]; then
12599 $PRINTF "${RED}no entry${NORMAL}\n"
12600 echo "$CMD0 &"
12601 cat "$te0"
12602 cat "$tlog"
12603 let numFAIL=numFAIL+1
12604 listFAIL="$listFAIL $N"
12605 elif [ "$perms" != "600" ]; then
12606 $PRINTF "${RED}perms \"$perms\", expected \"600\" ${NORMAL}\n"
12607 echo "$CMD0 &"
12608 cat "$te0"
12609 let numFAIL=numFAIL+1
12610 listFAIL="$listFAIL $N"
12611 else
12612 $PRINTF "$OK\n"
12613 let numOK=numOK+1
12615 set +xv
12616 fi # NUMCOND
12618 esac
12619 PORT=$((PORT+1))
12620 N=$((N+1))
12622 done <<<"
12623 # address fileopt addropts waitfor direction ADDR2
12624 create . . file -U FILE:/dev/null
12625 open . creat file . FILE:/dev/null
12626 gopen . creat file . FILE:/dev/null
12627 unix-listen . . unixport . FILE:/dev/null
12628 unix-recvfrom . . unixport . FILE:/dev/null
12629 unix-recv . . unixport -u FILE:/dev/null
12630 pipe . . file -u FILE:/dev/null
12631 # pty does not seem to honor umask:
12632 #pty link . file . PIPE
12636 # tests: option perm with "passive" NAMED group addresses
12637 while read addr fileopt addropts proto diropt; do
12638 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12639 # test if passive (listening...) filesystem based addresses implement option perm
12640 ADDR=$(toupper $addr)
12641 ADDR_=${ADDR/-/_}
12642 PROTO=$(toupper $proto)
12643 if [ "$diropt" = "." ]; then diropt=; fi
12644 if [ "$fileopt" = "." ]; then fileopt=; fi
12645 if [ "$addropts" = "." ]; then addropts=; fi
12646 NAME=${ADDR_}_PERM
12647 case "$TESTS" in
12648 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%ignoreeof%*|*%$NAME%*)
12649 TEST="$NAME: $ADDR applies option perm"
12650 # start a socat process with passive/listening file system entry. Check the
12651 # permissions of the FS entry, then terminate the process.
12652 # Test succeeds when FS entry exists and has expected permissions.
12653 if ! eval $NUMCOND; then :; else
12654 tlog="$td/test$N.log"
12655 te0="$td/test$N.0.stderr"
12656 tsock="$td/test$N.sock"
12657 # set -vx
12658 if [ -z "$fileopt" ]; then
12659 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
12660 else
12661 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
12663 printf "test $F_n $TEST... " $N
12664 $CMD0 >/dev/null 2>"$te0" &
12665 pid0=$!
12666 wait${proto} $tsock 1 2>"$tlog"
12667 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12668 perms=$(fileperms "$tsock")
12669 kill $pid0 2>>"$tlog"
12670 wait
12671 if [ "$ERRNOENT" ]; then
12672 $PRINTF "${RED}no entry${NORMAL}\n"
12673 echo "$CMD0 &"
12674 cat "$te0"
12675 cat "$tlog"
12676 let numFAIL=numFAIL+1
12677 listFAIL="$listFAIL $N"
12678 elif [ "$perms" != "511" ]; then
12679 $PRINTF "${RED}perms \"$perms\", expected \"511\" ${NORMAL}\n"
12680 echo "$CMD0 &"
12681 cat "$te0"
12682 let numFAIL=numFAIL+1
12683 listFAIL="$listFAIL $N"
12684 else
12685 $PRINTF "$OK\n"
12686 let numOK=numOK+1
12688 set +vx
12689 fi # NUMCOND
12691 esac
12692 PORT=$((PORT+1))
12693 N=$((N+1))
12695 done <<<"
12696 # address fileopt addropts waitfor direction
12697 create . . file -U
12698 open . creat file .
12699 gopen . creat file .
12700 unix-listen . . unixport .
12701 unix-recvfrom . . unixport .
12702 unix-recv . . unixport -u
12703 pipe . . file -u
12704 pty link . file .
12708 # tests: option user with "passive" NAMED group addresses
12709 while read addr fileopt addropts proto diropt; do
12710 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12711 # test if passive (listening...) filesystem based addresses implement option user
12712 ADDR=$(toupper $addr)
12713 ADDR_=${ADDR/-/_}
12714 PROTO=$(toupper $proto)
12715 if [ "$diropt" = "." ]; then diropt=; fi
12716 if [ "$fileopt" = "." ]; then fileopt=; fi
12717 if [ "$addropts" = "." ]; then addropts=; fi
12718 NAME=${ADDR_}_USER
12719 case "$TESTS" in
12720 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%root%*|*%ignoreeof%*|*%$NAME%*)
12721 TEST="$NAME: $ADDR applies option user"
12722 # start a socat process with passive/listening file system entry with user option.
12723 # Check the owner of the FS entry, then terminate the process.
12724 # Test succeeds when FS entry exists and has expected owner.
12725 if ! eval $NUMCOND; then :;
12726 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
12727 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
12728 numCANT=$((numCANT+1))
12729 listCANT="$listCANT $N"
12730 else
12731 tlog="$td/test$N.log"
12732 te0="$td/test$N.0.stderr"
12733 tsock="$td/test$N.sock"
12734 # set -vx
12735 if [ -z "$fileopt" ]; then
12736 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
12737 else
12738 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
12740 printf "test $F_n $TEST... " $N
12741 $CMD0 >/dev/null 2>"$te0" &
12742 pid0=$!
12743 wait${proto} $tsock 1 2>"$tlog"
12744 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12745 user=$(fileuser "$tsock")
12746 kill $pid0 2>>"$tlog"
12747 wait
12748 if [ "$ERRNOENT" ]; then
12749 $PRINTF "${RED}no entry${NORMAL}\n"
12750 echo "$CMD0 &"
12751 cat "$te0"
12752 cat "$tlog"
12753 let numFAIL=numFAIL+1
12754 listFAIL="$listFAIL $N"
12755 elif [ "$user" != "$SUBSTUSER" ]; then
12756 $PRINTF "${RED}user \"$user\", expected \"$SUBSTUSER\" ${NORMAL}\n"
12757 echo "$CMD0 &"
12758 cat "$te0"
12759 let numFAIL=numFAIL+1
12760 listFAIL="$listFAIL $N"
12761 else
12762 $PRINTF "$OK\n"
12763 let numOK=numOK+1
12765 set +vx
12766 fi # NUMCOND
12768 esac
12769 PORT=$((PORT+1))
12770 N=$((N+1))
12772 done <<<"
12773 # address fileopt addropts waitfor direction
12774 create . . file -U
12775 open . creat file .
12776 gopen . creat file .
12777 unix-listen . . unixport .
12778 unix-recvfrom . . unixport .
12779 unix-recv . . unixport -u
12780 pipe . . file -u
12781 pty link . file .
12785 # tests: is "passive" filesystem entry removed at the end? (without fork)
12786 while read addr fileopt addropts proto diropt crit ADDR2; do
12787 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12788 # some passive (listening...) filesystem based addresses did not remove the file
12789 # system entry at the end
12790 ADDR=$(toupper $addr)
12791 ADDR_=${ADDR/-/_}
12792 PROTO=$(toupper $proto)
12793 if [ "$diropt" = "." ]; then diropt=; fi
12794 if [ "$fileopt" = "." ]; then fileopt=; fi
12795 if [ "$addropts" = "." ]; then addropts=; fi
12796 # $ADDR removes the file system entry when the process is terminated
12797 NAME=${ADDR_}_REMOVE
12798 case "$TESTS" in
12799 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12800 TEST="$NAME: $ADDR removes socket entry when terminated during accept"
12801 # start a socat process with listening unix domain socket etc. Terminate the
12802 # process and check if the file system socket entry still exists.
12803 # Test succeeds when entry does not exist.
12804 if ! eval $NUMCOND; then :; else
12805 tlog="$td/test$N.log"
12806 te0="$td/test$N.0.stderr"
12807 tsock="$td/test$N.sock"
12808 if [ -z "$fileopt" ]; then
12809 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts $ADDR2"
12810 else
12811 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts $ADDR2"
12813 printf "test $F_n $TEST... " $N
12814 $CMD0 >/dev/null 2>"$te0" &
12815 pid0=$!
12816 wait${proto} "$crit" $tsock 1 2>"$tlog"
12817 kill $pid0 2>>"$tlog"
12818 rc1=$?
12819 wait >>"$tlog"
12820 if [ $rc1 != 0 ]; then
12821 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
12822 echo "$CMD0 &"
12823 cat "$te0"
12824 cat "$tlog"
12825 numCANT=$((numCANT+1))
12826 listCANT="$listCANT $N"
12827 elif ! [ $crit $tsock ]; then
12828 $PRINTF "$OK\n"
12829 let numOK=numOK+1
12830 else
12831 $PRINTF "$FAILED\n"
12832 echo "$CMD0 &"
12833 cat "$te0"
12834 cat "$tlog"
12835 let numFAIL=numFAIL+1
12836 listFAIL="$listFAIL $N"
12838 fi # NUMCOND
12840 esac
12841 PORT=$((PORT+1))
12842 N=$((N+1))
12844 done <<<"
12845 # address fileopt addropts waitfor direction crit ADDR2
12846 unix-listen . . unixport . -e FILE:/dev/null
12847 unix-recvfrom . . unixport . -e FILE:/dev/null
12848 unix-recv . . unixport -u -e FILE:/dev/null
12849 pipe . . file -u -e FILE:/dev/null
12850 pty link . file . -L PIPE
12854 # tests: is "passive" filesystem entry removed at the end? (with fork)
12855 while read addr fileopt addropts proto diropt crit ADDR2; do
12856 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12857 # some passive (listening...) filesystem based addresses with fork did not remove
12858 # the file system entry at the end
12859 ADDR=$(toupper $addr)
12860 ADDR_=${ADDR/-/_}
12861 PROTO=$(toupper $proto)
12862 if [ "$diropt" = "." ]; then diropt=; fi
12863 if [ "$fileopt" = "." ]; then fileopt=; fi
12864 if [ "$addropts" = "." ]; then addropts=; fi
12865 # $ADDR with fork removes the file system entry when the process is terminated
12866 NAME=${ADDR_}_REMOVE_FORK
12867 case "$TESTS" in
12868 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12869 TEST="$NAME: $ADDR with fork removes socket entry when terminated during accept"
12870 # start a socat process with listening unix domain socket etc and option fork.
12871 # Terminate the process and check if the file system socket entry still exists.
12872 # Test succeeds when entry does not exist.
12873 if ! eval $NUMCOND; then :; else
12874 tlog="$td/test$N.log"
12875 te0="$td/test$N.0.stderr"
12876 tsock="$td/test$N.sock"
12877 if [ -z "$fileopt" ]; then
12878 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,fork,$addropts $ADDR2"
12879 else
12880 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,fork,$fileopt=$tsock,$addropts $ADDR2"
12882 printf "test $F_n $TEST... " $N
12883 $CMD0 >/dev/null 2>"$te0" &
12884 pid0=$!
12885 wait${proto} "$crit" $tsock 1 2>"$tlog"
12886 kill $pid0 2>>"$tlog"
12887 rc1=$?
12888 wait
12889 if [ $rc1 != 0 ]; then
12890 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
12891 echo "$CMD0 &"
12892 cat "$te0"
12893 cat "$tlog"
12894 numCANT=$((numCANT+1))
12895 listCANT="$listCANT $N"
12896 elif ! [ $crit $tsock ]; then
12897 $PRINTF "$OK\n"
12898 let numOK=numOK+1
12899 else
12900 $PRINTF "$FAILED\n"
12901 echo "$CMD0 &"
12902 cat "$te0"
12903 cat "$tlog"
12904 let numFAIL=numFAIL+1
12905 listFAIL="$listFAIL $N"
12907 fi # NUMCOND
12909 esac
12910 PORT=$((PORT+1))
12911 N=$((N+1))
12913 done <<<"
12914 # address fileopt addropts waitfor direction crit ADDR2
12915 unix-listen . . unixport . -e FILE:/dev/null
12916 unix-recvfrom . . unixport . -e FILE:/dev/null
12920 # bug fix: SYSTEM address child process shut down parents sockets including
12921 # SSL connection under some circumstances.
12922 NAME=SYSTEM_SHUTDOWN
12923 case "$TESTS" in
12924 *%$N%*|*%functions%*|*%bugs%*|*%system%*|*%openssl%*|*%socket%*|*%$NAME%*)
12925 TEST="$NAME: SYSTEM address does not shutdown its parents addresses"
12926 # start an OpenSSL echo server using SYSTEM:cat
12927 # start an OpenSSL client that sends data
12928 # when the client recieves its data and terminates without error the test succeeded
12929 # in case of the bug the client issues an error like:
12930 # SSL_connect(): error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
12931 if ! eval $NUMCOND; then :;
12932 elif ! testfeats openssl >/dev/null; then
12933 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
12934 numCANT=$((numCANT+1))
12935 listCANT="$listCANT $N"
12936 else
12937 gentestcert testsrv
12938 tf="$td/test$N.stdout"
12939 te="$td/test$N.stderr"
12940 tdiff="$td/test$N.diff"
12941 da="test$N $(date) $RANDOM"
12942 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 SYSTEM:cat"
12943 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
12944 printf "test $F_n $TEST... " $N
12945 $CMD0 >/dev/null 2>"${te}0" &
12946 pid0=$!
12947 waittcp4port $PORT 1
12948 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12949 rc1=$?
12950 kill $pid0 2>/dev/null; wait
12951 if [ $rc1 -ne 0 ]; then
12952 $PRINTF "$FAILED\n"
12953 echo "rc1=$rc1"
12954 echo "$CMD0 &"
12955 echo "$CMD1"
12956 cat "${te}0"
12957 cat "${te}1"
12958 numFAIL=$((numFAIL+1))
12959 listFAIL="$listFAIL $N"
12960 elif ! echo "$da" |diff - "${tf}1" >"$tdiff" 2>&1; then
12961 $PRINTF "$FAILED\n"
12962 echo "diff:"
12963 cat "$tdiff"
12964 echo "$CMD0 &"
12965 echo "$CMD1"
12966 cat "${te}0"
12967 cat "${te}1"
12968 numFAIL=$((numFAIL+1))
12969 listFAIL="$listFAIL $N"
12970 else
12971 $PRINTF "$OK\n"
12972 numOK=$((numOK+1))
12974 fi # NUMCOND
12976 esac
12977 PORT=$((PORT+1))
12978 N=$((N+1))
12981 # test if TCP4-LISTEN with empty port arg terminates with error
12982 NAME=TCP4_NOPORT
12983 case "$TESTS" in
12984 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*)
12985 TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out"
12986 # run socat with TCP4-LISTEN with empty port arg. Check if it terminates
12987 # immediately with return code 1
12988 if ! eval $NUMCOND; then :; else
12989 tf="$td/test$N.stdout"
12990 te="$td/test$N.stderr"
12991 t0rc="$td/test$N.rc"
12992 tdiff="$td/test$N.diff"
12993 da="test$N $(date) $RANDOM"
12994 CMD0="$SOCAT $opts TCP4-LISTEN: /dev/null"
12995 printf "test $F_n $TEST... " $N
12996 { $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null
12997 pid0=$!
12998 sleep 1
12999 kill $pid0 2>/dev/null; wait
13000 if [ ! -f "$t0rc" ]; then
13001 $PRINTF "$FAILED\n"
13002 echo "no return code of CMD0 stored" >&2
13003 echo "$CMD0 &"
13004 cat "${te}0"
13005 numFAIL=$((numFAIL+1))
13006 listFAIL="$listFAIL $N"
13007 elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then
13008 $PRINTF "$FAILED\n"
13009 echo "CMD0 exited with $(cat $t0rc), expected 1"
13010 echo "$CMD0 &"
13011 cat "${te}0"
13012 numFAIL=$((numFAIL+1))
13013 listFAIL="$listFAIL $N"
13014 else
13015 $PRINTF "$OK\n"
13016 numOK=$((numOK+1))
13018 fi # NUMCOND
13020 esac
13021 PORT=$((PORT+1))
13022 N=$((N+1))
13025 # tests of various SSL methods; from TLS1.3 this method is not avail in OpenSSL:
13026 OPENSSL_METHODS_OBSOLETE="SSL3 SSL23"
13027 OPENSSL_METHODS_EXPECTED="TLS1 TLS1.1 TLS1.2 DTLS1 DTLS1.2"
13029 # the OPENSSL_METHOD_DTLS1 test hangs sometimes, probably depending on the openssl version.
13030 OPENSSL_VERSION="$(openssl version)"
13031 OPENSSL_VERSION="${OPENSSL_VERSION#* }"
13032 OPENSSL_VERSION="${OPENSSL_VERSION%%-*}"
13033 OPENSSL_VERSION_GOOD=1.0.2 # this is just a guess.
13034 # known bad: 1.0.1e
13035 # known good: 1.0.2j
13038 # test if the obsolete SSL methods can be used with OpenSSL
13039 for method in $OPENSSL_METHODS_OBSOLETE; do
13041 NAME=OPENSSL_METHOD_$method
13042 case "$TESTS" in
13043 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
13044 TEST="$NAME: test OpenSSL method $method"
13045 # Start a socat process with obsoelete OpenSSL method, it should fail
13046 if ! eval $NUMCOND; then :;
13047 elif ! testfeats openssl >/dev/null; then
13048 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
13049 numCANT=$((numCANT+1))
13050 listCANT="$listCANT $N"
13051 elif ! socat -hhh |grep -q "^[[:space:]]*openssl-method[[:space:]]"; then
13052 $PRINTF "test $F_n $TEST... ${YELLOW}Option openssl-method not available${NORMAL}\n" $N
13053 numCANT=$((numCANT+1))
13054 listCANT="$listCANT $N"
13055 else
13056 gentestcert testsrv
13057 tf="$td/test$N.stdout"
13058 te="$td/test$N.stderr"
13059 tdiff="$td/test$N.diff"
13060 da="test$N $(date) $RANDOM"
13061 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,openssl-method=$method,cert=testsrv.pem,verify=0 PIPE"
13062 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,opensslmethod=$method,verify=0"
13063 printf "test $F_n $TEST... " $N
13064 if [ "$method" = DTLS1 -a "$(echo -e "$OPENSSL_VERSION\n1.0.2" |sort |tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
13065 $PRINTF "${YELLOW}might hang, skipping${NORMAL}\n"
13066 numCANT=$((numCANT+1))
13067 listCANT="$listCANT $N"
13068 else
13069 $CMD0 >/dev/null 2>"${te}0" &
13070 pid0=$!
13071 waittcp4port $PORT 1 1 2>/dev/null; w0=$? # result of waiting for process 0
13072 if [ $w0 -eq 0 ]; then
13073 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13074 rc1=$?
13075 kill $pid0 2>/dev/null; wait
13077 if [ $w0 -eq 0 ] && echo "$da" |diff - "${tf}1"; then
13078 $PRINTF "${YELLOW}WARN${NORMAL} (obsolete method succeeds)\n"
13079 numOK=$((numOK+1))
13080 else
13081 $PRINTF "$OK (obsolete method fails)\n"
13082 numOK=$((numOK+1))
13084 if [ "$VERBOSE" ]; then
13085 echo " $CMD0"
13086 echo " echo \"$da\" |$CMD1"
13088 fi # !DTLS1 hang
13089 fi # NUMCOND
13091 esac
13092 PORT=$((PORT+1))
13093 N=$((N+1))
13095 done
13097 # test if the various SSL methods can be used with OpenSSL
13098 for method in $OPENSSL_METHODS_EXPECTED; do
13100 NAME=OPENSSL_METHOD_$method
13101 METHFAM=$(tolower "${method%%[0-9]*}")
13102 case "$TESTS" in
13103 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$METHFAM%*|*%$NAME%*)
13104 TEST="$NAME: test OpenSSL method $method"
13105 # Start a socat process listening with OpenSSL and echoing data,
13106 # using the selected method
13107 # Start a second socat process connecting to the listener using
13108 # the same method, send some data and catch the reply.
13109 # If the reply is identical to the sent data the test succeeded.
13110 if ! eval $NUMCOND; then :;
13111 elif ! testfeats openssl >/dev/null; then
13112 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
13113 numCANT=$((numCANT+1))
13114 listCANT="$listCANT $N"
13115 elif ! socat -hhh |grep -q "^[[:space:]]*openssl-method[[:space:]]"; then
13116 $PRINTF "test $F_n $TEST... ${YELLOW}Option openssl-method not available${NORMAL}\n" $N
13117 numCANT=$((numCANT+1))
13118 listCANT="$listCANT $N"
13119 else
13120 gentestcert testsrv
13121 tf="$td/test$N.stdout"
13122 te="$td/test$N.stderr"
13123 tdiff="$td/test$N.diff"
13124 da="test$N $(date) $RANDOM"
13125 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,openssl-method=$method,cert=testsrv.pem,verify=0 PIPE"
13126 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,openssl-method=$method,verify=0"
13127 printf "test $F_n $TEST... " $N
13128 if [ "$method" = DTLS1 -a "$(echo -e "$OPENSSL_VERSION\n1.0.2" |sort |tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
13129 $PRINTF "${YELLOW}might hang, skipping${NORMAL}\n"
13130 numCANT=$((numCANT+1))
13131 listCANT="$listCANT $N"
13132 else
13133 $CMD0 >/dev/null 2>"${te}0" &
13134 pid0=$!
13135 if [[ "$method" =~ DTLS* ]]; then
13136 waitudp4port $PORT 1
13137 else
13138 waittcp4port $PORT 1
13140 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13141 rc1=$?
13142 kill $pid0 2>/dev/null; wait
13143 if echo "$da" |diff - "${tf}1"; then
13144 $PRINTF "$OK\n"
13145 numOK=$((numOK+1))
13146 if [ "$VERBOSE" ]; then
13147 echo " $CMD0"
13148 echo " echo \"$da\" |$CMD1"
13150 else
13151 $PRINTF "$FAILED\n"
13152 echo "$CMD0 &"
13153 echo "$CMD1"
13154 cat "${te}0"
13155 cat "${te}1"
13156 numFAIL=$((numFAIL+1))
13157 listFAIL="$listFAIL $N"
13158 #esac
13160 fi # !DTLS1 hang
13161 fi # NUMCOND
13163 esac
13164 PORT=$((PORT+1))
13165 N=$((N+1))
13167 done
13169 # test security of option openssl-set-min-proto-version
13170 OPENSSL_LATEST_PROTO_VERSION=$(openssl s_server --help 2>&1 |grep -e -ssl[1-9] -e -tls[1-9] |awk '{print($1);}' |cut -c 2- |tr '[a-z_]' '[A-Z.]' |sort |tail -n 1)
13171 OPENSSL_BEFORELAST_PROTO_VERSION=$(openssl s_server --help 2>&1 |grep -e -ssl[1-9] -e -tls[1-9] |awk '{print($1);}' |cut -c 2- |tr '[a-z_]' '[A-Z.]' |sort |tail -n 2 |head -n 1)
13173 NAME=OPENSSL_MIN_VERSION
13174 case "$TESTS" in
13175 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
13176 TEST="$NAME: security of OpenSSL server with openssl-min-proto-version"
13177 if ! eval $NUMCOND; then :;
13178 elif ! testaddrs openssl >/dev/null; then
13179 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
13180 numCANT=$((numCANT+1))
13181 listCANT="$listCANT $N"
13182 elif ! feat=$(testoptions openssl-min-proto-version); then
13183 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
13184 numCANT=$((numCANT+1))
13185 listCANT="$listCANT $N"
13186 elif ! [ "$OPENSSL_LATEST_PROTO_VERSION" -a "$OPENSSL_BEFORELAST_PROTO_VERSION" -a \
13187 "$OPENSSL_LATEST_PROTO_VERSION" != "$OPENSSL_BEFORELAST_PROTO_VERSION" ]; then
13188 $PRINTF "test $F_n $TEST... ${YELLOW}cannot determine two available SSL/TLS versions${NORMAL}\n" $N
13189 numCANT=$((numCANT+1))
13190 listCANT="$listCANT $N"
13191 else
13192 gentestcert testsrv
13193 testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "openssl-min-proto-version=$OPENSSL_LATEST_PROTO_VERSION" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD,openssl-max-proto-version=$OPENSSL_BEFORELAST_PROTO_VERSION" 4 tcp $PORT -1
13194 fi ;; # NUMCOND, $fets
13195 esac
13196 PORT=$((PORT+1))
13197 N=$((N+1))
13200 # Address options fdin and fdout were silently ignored when not applicable
13201 # due to -u or -U option. Now these combinations are caught as errors.
13202 NAME=FDOUT_ERROR
13203 case "$TESTS" in
13204 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
13205 TEST="$NAME: fdout bails out in write-only context"
13206 # use EXEC in write-only context with option fdout. Expected behaviour: error
13207 if ! eval $NUMCOND; then :; else
13208 tf="$td/test$N.stdout"
13209 te="$td/test$N.stderr"
13210 tdiff="$td/test$N.diff"
13211 da="test$N $(date) $RANDOM"
13212 CMD="$SOCAT $opts -u /dev/null EXEC:cat,fdout=1"
13213 printf "test $F_n $TEST... " $N
13214 $CMD >/dev/null 2>"${te}"
13215 rc=$?
13216 if [ $rc -eq 1 ]; then
13217 $PRINTF "$OK\n"
13218 numOK=$((numOK+1))
13219 else
13220 $PRINTF "$FAILED\n"
13221 echo "$CMD"
13222 cat "${te}"
13223 echo "command did not terminate with error!"
13224 numFAIL=$((numFAIL+1))
13225 listFAIL="$listFAIL $N"
13227 fi # NUMCOND
13229 esac
13230 PORT=$((PORT+1))
13231 N=$((N+1))
13234 # test if failure exit code of SYSTEM invocation causes socat to also exit
13235 # with !=0
13236 NAME=SYSTEM_RC
13237 case "$TESTS" in
13238 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
13239 TEST="$NAME: promote failure of SYSTEM"
13240 # run socat with SYSTEM:false and check if socat exits with !=0
13241 if ! eval $NUMCOND; then :; else
13242 tf="$td/test$N.stdout"
13243 te="$td/test$N.stderr"
13244 tdiff="$td/test$N.diff"
13245 da="test$N $(date) $RANDOM"
13246 # shut-none makes sure that the child is not killed by parent
13247 CMD0="$TRACE $SOCAT $opts - SYSTEM:false,shut-none"
13248 printf "test $F_n $TEST... " $N
13249 sleep 1 |$CMD0 >/dev/null 2>"${te}0"
13250 rc0=$?
13251 if [ $rc0 -eq 0 ]; then
13252 $PRINTF "$FAILED\n"
13253 echo "$CMD0"
13254 cat "${te}0"
13255 numFAIL=$((numFAIL+1))
13256 listFAIL="$listFAIL $N"
13257 else
13258 $PRINTF "$OK\n"
13259 numOK=$((numOK+1))
13261 fi # NUMCOND
13263 esac
13264 PORT=$((PORT+1))
13265 N=$((N+1))
13268 # test if failure exit code of EXEC invocation causes socat to also exit
13269 # with !=0
13270 NAME=EXEC_RC
13271 case "$TESTS" in
13272 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
13273 TEST="$NAME: promote failure of EXEC"
13274 # run socat with EXEC:false and check if socat exits with !=0
13275 if ! eval $NUMCOND; then :; else
13276 tf="$td/test$N.stdout"
13277 te="$td/test$N.stderr"
13278 tdiff="$td/test$N.diff"
13279 da="test$N $(date) $RANDOM"
13280 # shut-none makes sure that the child is not killed by parent
13281 CMD0="$TRACE $SOCAT $opts - EXEC:false,shut-none"
13282 printf "test $F_n $TEST... " $N
13283 sleep 1 |$CMD0 >/dev/null 2>"${te}0"
13284 rc0=$?
13285 if [ $rc0 -eq 0 ]; then
13286 $PRINTF "$FAILED\n"
13287 echo "$CMD0"
13288 cat "${te}0"
13289 numFAIL=$((numFAIL+1))
13290 listFAIL="$listFAIL $N"
13291 else
13292 $PRINTF "$OK\n"
13293 numOK=$((numOK+1))
13295 fi # NUMCOND
13297 esac
13298 PORT=$((PORT+1))
13299 N=$((N+1))
13302 # test the so-reuseaddr option
13303 NAME=SO_REUSEADDR
13304 case "$TESTS" in
13305 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
13306 TEST="$NAME: test the so-reuseaddr option"
13307 # process 0 provides a tcp listening socket with so-reuseaddr;
13308 # process 1 connects to this port; thus the port is connected but no longer
13309 # listening
13310 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
13311 # SO_REUSEADDR socket options did not work
13312 # process 3 connects to this port; only if it is successful the test is ok
13313 if ! eval $NUMCOND; then :;
13314 elif ! feat=$(testoptions so-reuseaddr); then
13315 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
13316 numCANT=$((numCANT+1))
13317 listCANT="$listCANT $N"
13318 else
13319 tp="$PORT"
13320 tf="$td/test$N.stdout"
13321 te="$td/test$N.stderr"
13322 tdiff="$td/test$N.diff"
13323 da="test$N $(date) $RANDOM"
13324 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,$REUSEADDR PIPE"
13325 CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
13326 CMD2="$CMD0"
13327 CMD3="$CMD1"
13328 printf "test $F_n $TEST... " $N
13329 $CMD0 >/dev/null 2>"${te}0" &
13330 pid0=$!
13331 waittcp4port $tp 1
13332 (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
13333 pid1=$!
13334 usleep 1000000
13335 $CMD2 >/dev/null 2>"${te}2" &
13336 pid2=$!
13337 waittcp4port $tp 1
13338 (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
13339 rc3=$?
13340 kill $pid0 $pid1 $pid2 2>/dev/null; wait
13341 if ! echo "$da" |diff - "$tf"; then
13342 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
13343 echo "$CMD0 &"
13344 echo "$CMD1"
13345 numCANT=$((numCANT+1))
13346 listCANT="$listCANT $N"
13347 elif [ $rc3 -ne 0 ]; then
13348 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
13349 echo "$CMD0 &"
13350 echo "$CMD1"
13351 echo "$CMD2 &"
13352 echo "$CMD3"
13353 cat "${te}2" "${te}3"
13354 numFAIL=$((numFAIL+1))
13355 listFAIL="$listFAIL $N"
13356 elif ! echo "$da" |diff - "${tf}3"; then
13357 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
13358 echo "$CMD0 &"
13359 echo "$CMD1"
13360 echo "$CMD2 &"
13361 echo "$CMD3"
13362 echo "$da" |diff - "${tf}3"
13363 numCANT=$((numCANT+1))
13364 listCANT="$listCANT $N"
13365 else
13366 $PRINTF "$OK\n"
13367 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
13368 numOK=$((numOK+1))
13370 fi # NUMCOND, SO_REUSEADDR
13372 esac
13373 PORT=$((PORT+1))
13374 N=$((N+1))
13377 # test the so-reuseport option
13378 NAME=SO_REUSEPORT
13379 case "$TESTS" in
13380 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
13381 TEST="$NAME: test the so-reuseport option"
13382 # process 0 provides a tcp listening socket with so-reuseport;
13383 # process 1 provides an equivalent tcp listening socket with so-reuseport;
13384 # process 2 connects to this port and transfers data
13385 # process 3 connects to this port and transfers data
13386 # test succeeds when both data transfers work
13387 if ! eval $NUMCOND; then :;
13388 elif ! feat=$(testoptions so-reuseport); then
13389 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
13390 numCANT=$((numCANT+1))
13391 listCANT="$listCANT $N"
13392 else
13393 tp="$PORT"
13394 tf="$td/test$N.stdout"
13395 te="$td/test$N.stderr"
13396 tdiff="$td/test$N.diff"
13397 da2="test$N $(date) $RANDOM"
13398 da3="test$N $(date) $RANDOM"
13399 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,$REUSEADDR,so-reuseport PIPE"
13400 CMD1="$CMD0"
13401 CMD2="$TRACE $SOCAT $opts - TCP:localhost:$tp"
13402 CMD3="$CMD2"
13403 printf "test $F_n $TEST... " $N
13404 $CMD0 >/dev/null 2>"${te}0" &
13405 pid0=$!
13406 $CMD1 >/dev/null 2>"${te}1" &
13407 pid1=$!
13408 waittcp4port $tp 1
13409 (echo "$da2") |$CMD2 >"${tf}2" 2>"${te}2" # this should always work
13410 rc2=$?
13411 (echo "$da3") |$CMD3 >"${tf}3" 2>"${te}3"
13412 rc3=$?
13413 kill $pid0 $pid1 $pid2 2>/dev/null; wait
13414 if ! echo "$da2" |diff - "${tf}2"; then
13415 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
13416 echo "$CMD0 &"
13417 cat "${te}0"
13418 echo "$CMD1 &"
13419 cat "${te}1"
13420 echo "$CMD2"
13421 cat "${te}2"
13422 numCANT=$((numCANT+1))
13423 listCANT="$listCANT $N"
13424 elif [ $rc3 -ne 0 ]; then
13425 $PRINTF "$FAILED:\n"
13426 echo "$CMD0 &"
13427 cat "${te}0"
13428 echo "$CMD1 &"
13429 cat "${te}1"
13430 echo "$CMD2"
13431 cat "${te}2"
13432 echo "$CMD3"
13433 cat "${te}3"
13434 numFAIL=$((numFAIL+1))
13435 listFAIL="$listFAIL $N"
13436 elif ! echo "$da2" |diff - "${tf}2"; then
13437 $PRINTF "$FAILED:\n"
13438 echo "$CMD0 &"
13439 cat "${te}0"
13440 echo "$CMD1 &"
13441 cat "${te}1"
13442 echo "$CMD2"
13443 cat "${te}2"
13444 echo "$CMD3"
13445 cat "${te}3"
13446 echo "$da2" |diff - "${tf}2"
13447 numFAIL=$((numFAIL+1))
13448 listFAIL="$listFAIL $N"
13449 elif ! echo "$da3" |diff - "${tf}3"; then
13450 $PRINTF "$FAILED:\n"
13451 echo "$CMD0 &"
13452 cat "${te}0"
13453 echo "$CMD1 &"
13454 cat "${te}1"
13455 echo "$CMD2"
13456 cat "${te}2"
13457 echo "$CMD3"
13458 cat "${te}3"
13459 echo "$da3" |diff - "${tf}3"
13460 numFAIL=$((numFAIL+1))
13461 listFAIL="$listFAIL $N"
13462 else
13463 $PRINTF "$OK\n"
13464 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
13465 numOK=$((numOK+1))
13467 fi # NUMCOND, SO_REUSEPORT
13469 esac
13470 PORT=$((PORT+1))
13471 N=$((N+1))
13474 # Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped.
13475 NAME=EXEC_NOFORK_UNIDIR
13476 case "$TESTS" in
13477 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
13478 TEST="$NAME: Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped"
13479 # invoke a simple echo command with EXEC, nofork, and -u
13480 # expected behaviour: output appears on stdout
13481 if ! eval $NUMCOND; then :; else
13482 tf="$td/test$N.stdout"
13483 te="$td/test$N.stderr"
13484 tdiff="$td/test$N.diff"
13485 da="test$N $(date) $RANDOM"
13486 CMD0="$TRACE $SOCAT $opts -u /dev/null EXEC:\"echo \\\\\\\"\\\"$da\\\"\\\\\\\"\",nofork"
13487 printf "test $F_n $TEST... " $N
13488 eval "$CMD0" >"${tf}0" 2>"${te}0"
13489 rc1=$?
13490 if echo "$da" |diff - "${tf}0" >"$tdiff"; then
13491 $PRINTF "$OK\n"
13492 numOK=$((numOK+1))
13493 else
13494 $PRINTF "$FAILED\n"
13495 echo "$CMD0"
13496 cat "${te}0"
13497 cat "$tdiff"
13498 numFAIL=$((numFAIL+1))
13499 listFAIL="$listFAIL $N"
13501 fi # NUMCOND
13503 esac
13504 #PORT=$((PORT+1))
13505 N=$((N+1))
13508 # OpenSSL ECDHE ciphers were introduced in socat 1.7.3.0 but in the same release
13509 # they were broken by a porting effort. This test checks if OpenSSL ECDHE works
13510 # 2019-02: this does no longer work (Ubuntu-18.04)
13511 NAME=OPENSSL_ECDHE
13512 case "$TESTS" in
13513 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
13514 TEST="$NAME: test OpenSSL ECDHE"
13515 # generate a ECDHE key, start an OpenSSL server, connect with a client and try to
13516 # pass data
13517 if ! eval $NUMCOND; then :;
13518 elif ! testfeats openssl >/dev/null; then
13519 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
13520 numCANT=$((numCANT+1))
13521 listCANT="$listCANT $N"
13522 elif ! openssl ciphers |grep -q '\<ECDHE\>'; then
13523 $PRINTF "test $F_n $TEST... ${YELLOW}openssl: cipher ECDHE not available${NORMAL}\n" $N
13524 numCANT=$((numCANT+1))
13525 listCANT="$listCANT $N"
13526 else
13527 tf="$td/test$N.stdout"
13528 te="$td/test$N.stderr"
13529 tdiff="$td/test$N.diff"
13530 da="test$N $(date) $RANDOM"
13531 #TESTSRV=./testsrvec; gentesteccert $TESTSRV
13532 TESTSRV=./testsrv; gentestcert $TESTSRV
13533 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$TESTSRV.crt,key=$TESTSRV.pem,verify=0 PIPE"
13534 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,cipher=ECDHE-ECDSA-AES256-GCM-SHA384,cafile=$TESTSRV.crt,verify=0"
13535 printf "test $F_n $TEST... " $N
13536 $CMD0 >/dev/null 2>"${te}0" &
13537 pid0=$!
13538 waittcp4port $PORT 1
13539 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13540 rc1=$?
13541 kill $pid0 2>/dev/null; wait
13542 if [ $rc1 -ne 0 ]; then
13543 $PRINTF "$FAILED\n"
13544 echo "failure symptom: client error" >&2
13545 echo "server and stderr:" >&2
13546 echo "$CMD0 &"
13547 cat "${te}0"
13548 echo "client and stderr:" >&2
13549 echo "$CMD1"
13550 cat "${te}1"
13551 numFAIL=$((numFAIL+1))
13552 listFAIL="$listFAIL $N"
13553 elif echo "$da" |diff - "${tf}1" >"$tdiff"; then
13554 $PRINTF "$OK\n"
13555 numOK=$((numOK+1))
13556 else
13557 $PRINTF "$FAILED\n"
13558 echo "server and stderr:" >&2
13559 echo "$CMD1"
13560 cat "${te}1"
13561 echo "client and stderr:" >&2
13562 echo "$CMD0 &"
13563 cat "${te}0"
13564 numFAIL=$((numFAIL+1))
13565 listFAIL="$listFAIL $N"
13567 fi # NUMCOND
13569 esac
13570 PORT=$((PORT+1))
13571 N=$((N+1))
13574 # option ipv6-join-group "could not be used"
13575 # fixed in 1.7.3.2
13576 NAME=USE_IPV6_JOIN_GROUP
13577 case "$TESTS" in
13578 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%ip6%*|*%udp%*|*%udp6%*|*%dgram%*|*%$NAME%*)
13579 TEST="$NAME: is option ipv6-join-group used"
13580 # Invoke socat with option ipv6-join-group on UDP6 address.
13581 # Terminate immediately, do not transfer data.
13582 # If socat exits with 0 the test succeeds.
13583 # Up to 1.7.3.1 it failed with "1 option(s) could not be used"
13584 if ! eval $NUMCOND; then :; else
13585 tf="$td/test$N.stdout"
13586 te="$td/test$N.stderr"
13587 tdiff="$td/test$N.diff"
13588 da="test$N $(date) $RANDOM"
13589 CMD0="$TRACE $SOCAT $opts UDP6-RECV:$PORT,ipv6-join-group=[ff02::2]:$MCINTERFACE /dev/null"
13590 printf "test $F_n $TEST... " $N
13591 $CMD0 >/dev/null 2>"${te}0"
13592 rc0=$?
13593 if [ $rc0 -eq 0 ]; then
13594 $PRINTF "$OK\n"
13595 numOK=$((numOK+1))
13596 else
13597 $PRINTF "$FAILED\n"
13598 echo "$CMD0"
13599 cat "${te}0"
13600 numFAIL=$((numFAIL+1))
13601 listFAIL="$listFAIL $N"
13603 fi # NUMCOND
13605 esac
13606 PORT=$((PORT+1))
13607 N=$((N+1))
13610 # The fix to "Make code async-signal-safe" used internally FD 3 and FD 4.
13611 # Using option fdin=3 did not pass data to executed program.
13612 NAME=DIAG_FDIN
13613 case "$TESTS" in
13614 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
13615 TEST="$NAME: test use of fdin=3"
13616 # Use FD 3 explicitely with fdin and test if Socat passes data to executed
13617 # program
13618 if ! eval $NUMCOND; then :; else
13619 tf="$td/test$N.stdout"
13620 te="$td/test$N.stderr"
13621 tdiff="$td/test$N.diff"
13622 da="test$N $(date) $RANDOM"
13623 CMD0="$TRACE $SOCAT $opts - SYSTEM:\"cat >&3 <&4\",fdin=4,fdout=3"
13624 printf "test $F_n $TEST... " $N
13625 echo "$da" |$TRACE $SOCAT $opts - SYSTEM:"cat <&3 >&4",fdin=3,fdout=4 >${tf}0 2>"${te}0"
13626 rc0=$?
13627 if [ $rc0 -ne 0 ]; then
13628 $PRINTF "$FAILED\n"
13629 echo "$CMD0"
13630 cat "${te}0"
13631 numFAIL=$((numFAIL+1))
13632 listFAIL="$listFAIL $N"
13633 elif echo "$da" |diff - ${tf}0 >$tdiff; then
13634 $PRINTF "$OK\n"
13635 numOK=$((numOK+1))
13636 else
13637 $PRINTF "$FAILED\n"
13638 echo "$CMD0"
13639 cat "${te}0"
13640 cat "$tdiff"
13641 numFAIL=$((numFAIL+1))
13642 listFAIL="$listFAIL $N"
13644 fi # NUMCOND
13646 esac
13647 PORT=$((PORT+1))
13648 N=$((N+1))
13651 NAME=SOCAT_OPT_HINT
13652 case "$TESTS" in
13653 *%$N%*|*%functions%*|*%$NAME%*)
13654 TEST="$NAME: check if merging single character options is rejected"
13655 if ! eval $NUMCOND; then :; else
13656 te="$td/test$N.stderr"
13657 CMD0="$TRACE $SOCAT $opts -vx FILE:/dev/null ECHO"
13658 printf "test $F_n $TEST... " $N
13659 $CMD0 >/dev/null 2>"${te}0"
13660 rc0=$?
13661 if [ "$rc0" = "1" ]; then
13662 $PRINTF "$OK\n"
13663 numOK=$((numOK+1))
13664 else
13665 $PRINTF "$FAILED\n"
13666 echo "$CMD0" >&2
13667 numFAIL=$((numFAIL+1))
13668 listFAIL="$listFAIL $N"
13670 fi ;; # NUMCOND
13671 esac
13672 N=$((N+1))
13675 # test for a bug in Socat version 1.7.3.3 where
13676 # termios options of the first address were applied to the second address.
13677 NAME=TERMIOS_PH_ALL
13678 case "$TESTS" in
13679 *%$N%*|*%functions%*|*%bugs%*|*%termios%*|*%$NAME%*)
13680 TEST="$NAME: are termios options applied to the correct address"
13681 # add a termios option to the first address, a tty, and have a second address
13682 # with pipe. If no error occurs the termios option was not applied to the pipe,
13683 # thus the test succeeded.
13684 if ! eval $NUMCOND; then :; else
13685 tf="$td/test$N.stdout"
13686 te="$td/test$N.stderr"
13687 tdiff="$td/test$N.diff"
13688 da="test$N $(date) $RANDOM"
13689 CMD0="$TRACE $SOCAT $opts -T 1 STDIO,echo=0 EXEC:cat"
13690 echo "$CMD0" >$td/test$N.sh
13691 chmod a+x $td/test$N.sh
13692 printf "test $F_n $TEST... " $N
13693 $SOCAT /dev/null EXEC:$td/test$N.sh,pty 2>"${te}0"
13694 rc0=$?
13695 if [ $rc0 -eq 0 ]; then
13696 $PRINTF "$OK\n"
13697 numOK=$((numOK+1))
13698 else
13699 $PRINTF "$FAILED\n"
13700 echo "$CMD0"
13701 cat "${te}0"
13702 numFAIL=$((numFAIL+1))
13703 listFAIL="$listFAIL $N"
13705 fi # NUMCOND
13707 esac
13708 PORT=$((PORT+1))
13709 N=$((N+1))
13712 # Due to a fallback logic before calling getaddrinfo(), intended to allow use
13713 # of service (port) names with SCTP, raw socket addresses where resolved with
13714 # socket type stream, which fails for protocol 6 (TCP)
13715 # Fixed after 1.7.3.3
13716 NAME=IP_SENDTO_6
13717 case "$TESTS" in
13718 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%rawip%*|*%rawip4%*|*%$NAME%*)
13719 TEST="$NAME: IP-SENDTO::6 passes getaddrinfo()"
13720 # invoke socat with address IP-SENDTO:*:6; when this does not fail with
13721 # "ai_socktype not supported", the test succeeded
13722 if ! eval $NUMCOND; then :; else
13723 tf="$td/test$N.stdout"
13724 te="$td/test$N.stderr"
13725 tdiff="$td/test$N.diff"
13726 CMD0="$TRACE $SOCAT $opts -u /dev/null IP-SENDTO:127.0.0.1:6"
13727 printf "test $F_n $TEST... " $N
13728 $CMD0 >/dev/null 2>"${te}0"
13729 if ! grep -q "ai_socktype not supported" ${te}0; then
13730 $PRINTF "$OK\n"
13731 numOK=$((numOK+1))
13732 else
13733 $PRINTF "$FAILED\n"
13734 echo "$CMD0"
13735 cat "${te}0"
13736 numFAIL=$((numFAIL+1))
13737 listFAIL="$listFAIL $N"
13739 fi # NUMCOND
13741 esac
13742 N=$((N+1))
13745 # test if the multiple EOF messages are fixed
13746 NAME=MULTIPLE_EOF
13747 case "$TESTS" in
13748 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
13749 TEST="$NAME: multiple EOF messages"
13750 # start two processes, connected via UNIX socket. The listener gets EOF from local address immediately; the second process then sends data. If the listener reports "socket 1 (fd .*) is at EOF" only once, the test succeeded
13751 if ! eval $NUMCOND; then :; else
13752 ts="$td/test$N.sock"
13753 tf="$td/test$N.stdout"
13754 te="$td/test$N.stderr"
13755 tdiff="$td/test$N.diff"
13756 da="test$N $(date) $RANDOM"
13757 CMD0="$TRACE $SOCAT $opts -d -d UNIX-LISTEN:$ts /dev/null"
13758 CMD1="$TRACE $SOCAT $opts -d -d - UNIX-CONNECT:$ts"
13759 printf "test $F_n $TEST... " $N
13760 $CMD0 >/dev/null 2>"${te}0" &
13761 pid0=$!
13762 waitunixport $ts 1
13763 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13764 rc1=$?
13765 kill $pid0 2>/dev/null; wait
13766 if [ $(grep "socket 2 (fd .*) is at EOF" ${te}0 |wc -l) -eq 1 ]; then
13767 $PRINTF "$OK\n"
13768 numOK=$((numOK+1))
13769 else
13770 $PRINTF "$FAILED\n"
13771 echo "$CMD0 &"
13772 echo "$CMD1"
13773 cat "${te}0"
13774 cat "${te}1"
13775 numFAIL=$((numFAIL+1))
13776 listFAIL="$listFAIL $N"
13778 fi # NUMCOND
13780 esac
13781 N=$((N+1))
13784 # Test for integer overflow with data transfer block size parameter
13785 NAME=BLKSIZE_INT_OVERFL
13786 case "$TESTS" in
13787 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%$NAME%*)
13788 TEST="$NAME: integer overflow with buffer size parameter"
13789 # Use a buffer size that would lead to integer overflow
13790 # Test succeeds when Socat terminates with correct error message
13791 if ! eval $NUMCOND; then :; else
13792 tf="$td/test$N.stdout"
13793 te="$td/test$N.stderr"
13794 tdiff="$td/test$N.diff"
13795 dat="$td/test$N.dat"
13796 # calculate the minimal length with integer overflow
13797 BYTES=$($PROCAN |grep size_t |awk '{print($3);}')
13798 case $BYTES in
13799 2) CHKSIZE=32768 ;;
13800 4) CHKSIZE=2147483648 ;;
13801 8) CHKSIZE=9223372036854775808 ;;
13802 16) CHKSIZE=170141183460469231731687303715884105728 ;;
13803 esac
13804 CMD0="$TRACE $SOCAT $opts -T 1 -b $CHKSIZE /dev/null PIPE"
13805 printf "test $F_n $TEST... " $N
13806 $CMD0 >/dev/null 2>"${te}0"
13807 rc0=$?
13808 if [ $rc0 -eq 0 ]; then
13809 $PRINTF "$FAILED (rc=$rc0)\n"
13810 echo "$CMD0"
13811 cat "${te}0"
13812 numFAIL=$((numFAIL+1))
13813 listFAIL="$listFAIL $N"
13814 elif [ $rc0 -eq 1 ]; then
13815 if grep -q "buffer size option (-b) to big" "${te}0"; then
13816 $PRINTF "$OK\n"
13817 numOK=$((numOK+1))
13818 else
13819 $PRINTF "$FAILED (rc=$rc0)\n"
13820 echo "$CMD0"
13821 cat "${te}0"
13822 numFAIL=$((numFAIL+1))
13823 listFAIL="$listFAIL $N"
13826 fi # NUMCOND
13828 esac
13829 PORT=$((PORT+1))
13830 N=$((N+1))
13832 # Test if unbalanced quoting in Socat addresses is detected
13833 NAME=UNBALANCED_QUOTE
13834 case "$TESTS" in
13835 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
13836 TEST="$NAME: Test fix of unbalanced quoting"
13837 # Invoke Socat with an address containing unbalanced quoting. If Socat prints
13838 # a "syntax error" message, the test succeeds
13839 if ! eval $NUMCOND; then :; else
13840 tf="$td/test$N.stdout"
13841 te="$td/test$N.stderr"
13842 tdiff="$td/test$N.diff"
13843 da="test$N $(date) $RANDOM"
13844 CMD0="$TRACE $SOCAT $opts -u FILE:$td/ab\"cd FILE:/dev/null"
13845 printf "test $F_n $TEST... " $N
13846 $CMD0 >/dev/null 2>"${te}0"
13847 if grep -q "syntax error" "${te}0"; then
13848 $PRINTF "$OK\n"
13849 numOK=$((numOK+1))
13850 else
13851 $PRINTF "$FAILED\n"
13852 echo "$CMD0"
13853 cat "${te}0"
13854 numFAIL=$((numFAIL+1))
13855 listFAIL="$listFAIL $N"
13857 fi # NUMCOND
13859 esac
13860 N=$((N+1))
13863 # Currently (2020) SCTP has not found its way into main distributions
13864 # /etc/services file. A fallback mechanism has been implemented in Socat
13865 # that allows use of TCP service names when service resolution for SCTP failed.
13866 # Furthermore, older getaddrinfo() implementations to not handle SCTP as SOCK_STREAM
13867 # at all, fall back to unspecified socktype then.
13868 NAME=SCTP_SERVICENAME
13869 case "$TESTS" in
13870 *%$N%*|*%functions%*|*%socket%*|*%sctp%*|*%$NAME%*)
13871 TEST="$NAME: Service name resolution works with SCTP"
13872 # invoke socat with address SCTP4-CONNECT:$LOCALHOST:http; when this fails with
13873 # "Connection refused", or does not fail at all, the test succeeded
13874 if ! eval $NUMCOND; then :;
13875 elif ! runssctp4 "$((PORT))" >/dev/null; then
13876 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
13877 numCANT=$((numCANT+1))
13878 listCANT="$listCANT $N"
13879 else
13880 tf="$td/test$N.stdout"
13881 te="$td/test$N.stderr"
13882 tdiff="$td/test$N.diff"
13883 CMD0="$TRACE $SOCAT $opts -u /dev/null SCTP4-CONNECT:$LOCALHOST:http"
13884 printf "test $F_n $TEST... " $N
13885 $CMD0 >/dev/null 2>"${te}0"
13886 if [ $? -eq 0 ]; then
13887 $PRINTF "$OK\n"
13888 numOK=$((numOK+1))
13889 elif grep -q "Connection refused" ${te}0; then
13890 $PRINTF "$OK\n"
13891 numOK=$((numOK+1))
13892 else
13893 $PRINTF "$FAILED\n"
13894 echo "$CMD0"
13895 cat "${te}0"
13896 numFAIL=$((numFAIL+1))
13897 listFAIL="$listFAIL $N"
13899 fi # NUMCOND
13901 esac
13902 N=$((N+1))
13905 # Test the o-direct option on reading
13906 NAME=O_DIRECT
13907 case "$TESTS" in
13908 *%$N%*|*%functions%*|*%engine%*|*%file%*|*%$NAME%*)
13909 TEST="$NAME: echo via file with o-direct"
13910 # Write data to a file and read it with options o-direct (and ignoreeof)
13911 # When the data read is the same as the data written the test succeeded.
13912 if ! eval $NUMCOND; then :;
13913 elif ! testoptions o-direct >/dev/null; then
13914 $PRINTF "test $F_n $TEST... ${YELLOW}o-direct not available${NORMAL}\n" $N
13915 numCANT=$((numCANT+1))
13916 listCANT="$listCANT $N"
13917 else
13918 tf="$td/test$N.file"
13919 to="$td/test$N.stdout"
13920 te="$td/test$N.stderr"
13921 tdiff="$td/test$N.diff"
13922 da="test$N $(date) $RANDOM"
13923 $PRINTF "test $F_n $TEST... " $N
13924 CMD="$TRACE $SOCAT $opts - $tf,o-direct,ignoreeof!!$tf"
13925 echo "$da" |$CMD >"$to" 2>"$te"
13926 rc=$?
13927 if [ $rc -ne 0 ] && grep -q "Invalid argument" "$te" && [ $UNAME = Linux ]; then
13928 case $(stat -f $tf |grep -o "Type: [^[:space:]]*" |cut -c 7-) in
13929 ext2/ext3|xfs|reiserfs)
13930 $PRINTF "${FAILED}\n"
13931 echo "$CMD" >&2
13932 cat "$te" >&2
13933 numFAIL=$((numFAIL+1))
13934 listFAIL="$listFAIL $N" ;;
13935 *) $PRINTF "${YELLOW}inable file system${NORMAL}\n"
13936 numCANT=$((numCANT+1))
13937 listCANT="$listCANT $N" ;;
13938 esac
13939 elif [ $rc -ne 0 ]; then
13940 $PRINTF "${FAILED}:\n"
13941 echo "$CMD" >&2
13942 cat "$te" >&2
13943 numFAIL=$((numFAIL+1))
13944 listFAIL="$listFAIL $N"
13945 elif ! echo "$da" |diff - "$to" >$tdiff; then
13946 $PRINTF "${FAILED}\n"
13947 echo "$CMD" >&2
13948 cat "$te" >&2
13949 cat "$tdiff" >&2
13950 numFAIL=$((numFAIL+1))
13951 listFAIL="$listFAIL $N"
13952 else
13953 $PRINTF "$OK\n"
13954 numOK=$((numOK+1))
13955 fi # command ok
13956 fi ;; # NUMCOND, feats
13957 esac
13958 N=$((N+1))
13961 # test if option unlink-close removes the bind socket file
13962 NAME=UNIX_SENDTO_UNLINK
13963 case "$TESTS" in
13964 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%$NAME%*)
13965 TEST="$NAME: Option unlink-close with UNIX sendto socket"
13966 # Have a recv socket with option unlink-close=0
13967 # and a sendto socket with option unlink-close=1
13968 # Expected beavior: the recv socket is kept, the
13969 # sendto/bind socket is removed
13970 if ! eval $NUMCOND; then :; else
13971 tf="$td/test$N.stdout"
13972 te="$td/test$N.stderr"
13973 uns="$td/test$N.server"
13974 unc="$td/test$N.client"
13975 tdiff="$td/test$N.diff"
13976 da="test$N $(date) $RANDOM"
13977 CMD0="$TRACE $SOCAT $opts -u UNIX-RECV:$uns,unlink-close=0 GOPEN:$tf"
13978 CMD1="$TRACE $SOCAT $opts - UNIX-SENDTO:$uns,bind=$unc,unlink-close=1"
13979 printf "test $F_n $TEST... " $N
13980 $CMD0 >/dev/null 2>"${te}0" &
13981 pid0=$!
13982 waitunixport $uns 1
13983 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13984 rc1=$?
13985 kill $pid0 2>/dev/null; wait
13986 if test -S $uns && ! test -S $unc; then
13987 $PRINTF "$OK\n"
13988 numOK=$((numOK+1))
13989 else
13990 $PRINTF "$FAILED\n"
13991 echo "$CMD0 &"
13992 echo "$CMD1"
13993 ls -ld $uns $unc
13994 cat "${te}0"
13995 cat "${te}1"
13996 numFAIL=$((numFAIL+1))
13997 listFAIL="$listFAIL $N"
13999 fi # NUMCOND
14001 esac
14002 N=$((N+1))
14004 # test if option unlink-close removes the bind socket file
14005 NAME=UNIX_CONNECT_UNLINK
14006 case "$TESTS" in
14007 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%$NAME%*)
14008 TEST="$NAME: Option unlink-close with UNIX connect socket"
14009 # Have a listen socket with option unlink-close=0
14010 # and a connect socket with option unlink-close=1
14011 # Expected beavior: the listen socket entry is kept, the
14012 # connect/bind socket is removed
14013 if ! eval $NUMCOND; then :; else
14014 tf="$td/test$N.stdout"
14015 te="$td/test$N.stderr"
14016 uns="$td/test$N.server"
14017 unc="$td/test$N.client"
14018 tdiff="$td/test$N.diff"
14019 da="test$N $(date) $RANDOM"
14020 CMD0="$TRACE $SOCAT $opts -u UNIX-LISTEN:$uns,unlink-close=0 GOPEN:$tf"
14021 CMD1="$TRACE $SOCAT $opts - UNIX-CONNECT:$uns,bind=$unc,unlink-close=1"
14022 printf "test $F_n $TEST... " $N
14023 $CMD0 >/dev/null 2>"${te}0" &
14024 pid0=$!
14025 waitunixport $uns 1
14026 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
14027 rc1=$?
14028 kill $pid0 2>/dev/null; wait
14029 if test -S $uns && ! test -S $unc; then
14030 $PRINTF "$OK\n"
14031 numOK=$((numOK+1))
14032 else
14033 $PRINTF "$FAILED\n"
14034 echo "$CMD0 &"
14035 echo "$CMD1"
14036 ls -ld $uns $unc
14037 cat "${te}0"
14038 cat "${te}1"
14039 numFAIL=$((numFAIL+1))
14040 listFAIL="$listFAIL $N"
14042 fi # NUMCOND
14044 esac
14045 N=$((N+1))
14048 # test the DTLS client feature
14049 NAME=OPENSSL_DTLS_CLIENT
14050 case "$TESTS" in
14051 *%$N%*|*%functions%*|*%openssl%*|*%dtls%*|*%udp%*|*%udp4%*|*%ip4%*|*%$NAME%*)
14052 TEST="$NAME: OpenSSL DTLS client"
14053 # Run openssl s_server in DTLS mode, wrapped into a simple Socat echoing command.
14054 # Start a Socat DTLS client, send data to server and check if reply is received.
14055 if ! eval $NUMCOND; then :;
14056 elif ! a=$(testfeats ip4 udp openssl); then
14057 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14058 numCANT=$((numCANT+1))
14059 listCANT="$listCANT $N"
14060 elif ! a=$(testaddrs openssl-dtls-client); then
14061 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14062 numCANT=$((numCANT+1))
14063 listCANT="$listCANT $N"
14064 elif ! runsip4 >/dev/null; then
14065 $PRINTF "test $F_n $TEST... ${YELLOW}IPv4 not available${NORMAL}\n" $N
14066 numCANT=$((numCANT+1))
14067 listCANT="$listCANT $N"
14068 elif ! type openssl >/dev/null 2>&1; then
14069 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not found${NORMAL}\n" $N
14070 numCANT=$((numCANT+1))
14071 listCANT="$listCANT $N"
14072 else
14073 gentestcert testsrv
14074 tf="$td/test$N.stdout"
14075 te="$td/test$N.stderr"
14076 tdiff="$td/test$N.diff"
14077 #set -vx
14078 da="test$N $(date) $RANDOM"
14079 init_openssl_s_server
14080 CMD1="$TRACE openssl s_server $OPENSSL_S_SERVER_4 $OPENSSL_S_SERVER_DTLS -accept $PORT -quiet $OPENSSL_S_SERVER_NO_IGN_EOF -cert testsrv.pem"
14081 CMD="$TRACE $SOCAT $opts -T 1 - OPENSSL-DTLS-CLIENT:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
14082 printf "test $F_n $TEST... " $N
14083 ( sleep 2; echo "$da"; sleep 1 ) |$CMD1 2>"${te}1" &
14084 pid1=$! # background process id
14085 waitudp4port $PORT
14086 $CMD >$tf 2>"$te"
14087 kill $pid1 2>/dev/null; wait 2>/dev/null
14088 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
14089 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
14090 echo "$CMD1 &"
14091 cat "${te}1"
14092 echo "$CMD"
14093 cat "$te"
14094 cat "$tdiff"
14095 numFAIL=$((numFAIL+1))
14096 listFAIL="$listFAIL $N"
14097 else
14098 $PRINTF "$OK\n"
14099 if [ -n "$debug" ]; then cat "${te}1" "$te"; fi
14100 numOK=$((numOK+1))
14102 fi ;; # NUMCOND, feats
14103 esac
14104 PORT=$((PORT+1))
14105 N=$((N+1))
14106 set +vx
14108 # test the DTLS server feature
14109 NAME=OPENSSL_DTLS_SERVER
14110 case "$TESTS" in
14111 *%$N%*|*%functions%*|*%openssl%*|*%dtls%*|*%udp%*|*%udp4%*|*%ip4%*|*%socket%*|*%$NAME%*)
14112 TEST="$NAME: OpenSSL DTLS server"
14113 # Run a socat OpenSSL DTLS server with echo function
14114 # Start an OpenSSL s_client, send data and check if repley is received.
14115 if ! eval $NUMCOND; then :;
14116 elif ! a=$(testfeats ip4 udp openssl) >/dev/null; then
14117 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14118 numCANT=$((numCANT+1))
14119 listCANT="$listCANT $N"
14120 elif ! a=$(testaddrs openssl-dtls-server); then
14121 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14122 numCANT=$((numCANT+1))
14123 listCANT="$listCANT $N"
14124 elif ! runsip4 >/dev/null; then
14125 $PRINTF "test $F_n $TEST... ${YELLOW}IPv4 not available${NORMAL}\n" $N
14126 numCANT=$((numCANT+1))
14127 listCANT="$listCANT $N"
14128 elif ! type openssl >/dev/null 2>&1; then
14129 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not found${NORMAL}\n" $N
14130 numCANT=$((numCANT+1))
14131 listCANT="$listCANT $N"
14132 elif [[ $(openssl version |awk '{print($2);}') =~ 0.9.8[a-c] ]]; then
14133 $PRINTF "test $F_n $TEST... ${YELLOW}openssl s_client might hang${NORMAL}\n" $N
14134 numCANT=$((numCANT+1))
14135 listCANT="$listCANT $N"
14136 else
14137 gentestcert testsrv
14138 tf="$td/test$N.stdout"
14139 te="$td/test$N.stderr"
14140 tdiff="$td/test$N.diff"
14141 da="test$N $(date) $RANDOM"
14142 init_openssl_s_client
14143 CMD1="$TRACE $SOCAT $opts OPENSSL-DTLS-SERVER:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
14144 CMD="openssl s_client $OPENSSL_S_CLIENT_4 -host $LOCALHOST -port $PORT $OPENSSL_S_CLIENT_DTLS"
14145 printf "test $F_n $TEST... " $N
14146 $CMD1 >/dev/null 2>"${te}1" &
14147 pid1=$!
14148 waitudp4port $PORT 1
14149 ( echo "$da"; sleep 0.1 ) |$CMD 2>"$te" |grep "$da" >"$tf"
14150 rc=$?
14151 kill $pid1 2>/dev/null; wait
14152 if echo "$da" |diff - $tf >"$tdiff"; then
14153 $PRINTF "$OK\n"
14154 numOK=$((numOK+1))
14155 else
14156 $PRINTF "$FAILED\n"
14157 echo "$CMD1 &"
14158 cat "${te}1"
14159 echo "$CMD"
14160 cat "$te"
14161 cat "$tdiff"
14162 numFAIL=$((numFAIL+1))
14163 listFAIL="$listFAIL $N"
14165 fi # NUMCOND
14167 esac
14168 PORT=$((PORT+1))
14169 N=$((N+1))
14172 NAME=OPENSSL_SERVERALTAUTH
14173 case "$TESTS" in
14174 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
14175 TEST="$NAME: OpenSSL server authentication with SubjectAltName (hostname)"
14176 if ! eval $NUMCOND; then :;
14177 elif ! testfeats openssl >/dev/null; then
14178 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
14179 numCANT=$((numCANT+1))
14180 listCANT="$listCANT $N"
14181 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
14182 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
14183 numCANT=$((numCANT+1))
14184 listCANT="$listCANT $N"
14185 else
14186 gentestaltcert testalt
14187 tf="$td/test$N.stdout"
14188 te="$td/test$N.stderr"
14189 tdiff="$td/test$N.diff"
14190 da="test$N $(date) $RANDOM"
14191 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,cert=testalt.crt,key=testalt.key,verify=0 pipe"
14192 CMD1="$TRACE $SOCAT $opts - OPENSSL:$LOCALHOST:$PORT,verify=1,cafile=testalt.crt,$SOCAT_EGD"
14193 printf "test $F_n $TEST... " $N
14194 eval "$CMD0 2>\"${te}0\" &"
14195 pid=$! # background process id
14196 waittcp4port $PORT
14197 echo "$da" |$CMD1 >$tf 2>"${te}1"
14198 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
14199 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
14200 echo "$CMD0 &" >&2
14201 cat "${te}0" >&2
14202 echo "$CMD1" >&2
14203 cat "${te}1" >&2
14204 cat "$tdiff" >&2
14205 numFAIL=$((numFAIL+1))
14206 listFAIL="$listFAIL $N"
14207 else
14208 $PRINTF "$OK\n"
14209 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
14210 numOK=$((numOK+1))
14212 kill $pid 2>/dev/null
14213 wait
14214 fi ;; # NUMCOND, feats
14215 esac
14216 PORT=$((PORT+1))
14217 N=$((N+1))
14219 NAME=OPENSSL_SERVERALTIP4AUTH
14220 case "$TESTS" in
14221 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
14222 TEST="$NAME: OpenSSL server authentication with SubjectAltName (IPv4 address)"
14223 if ! eval $NUMCOND; then :;
14224 elif ! testfeats openssl >/dev/null; then
14225 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
14226 numCANT=$((numCANT+1))
14227 listCANT="$listCANT $N"
14228 elif ! testfeats listen tcp ip4 openssl >/dev/null || ! runsip4 >/dev/null; then
14229 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
14230 numCANT=$((numCANT+1))
14231 listCANT="$listCANT $N"
14232 else
14233 gentestaltcert testalt
14234 tf="$td/test$N.stdout"
14235 te="$td/test$N.stderr"
14236 tdiff="$td/test$N.diff"
14237 da="test$N $(date) $RANDOM"
14238 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,cert=testalt.crt,key=testalt.key,verify=0 pipe"
14239 CMD1="$TRACE $SOCAT $opts - OPENSSL:127.0.0.1:$PORT,verify=1,cafile=testalt.crt,$SOCAT_EGD"
14240 printf "test $F_n $TEST... " $N
14241 eval "$CMD0 2>\"${te}0\" &"
14242 pid=$! # background process id
14243 waittcp4port $PORT
14244 echo "$da" |$CMD1 >$tf 2>"${te}1"
14245 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
14246 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
14247 echo "$CMD0 &" >&2
14248 cat "${te}0" >&2
14249 echo "$CMD1" >&2
14250 cat "${te}1" >&2
14251 cat "$tdiff" >&2
14252 numFAIL=$((numFAIL+1))
14253 listFAIL="$listFAIL $N"
14254 else
14255 $PRINTF "$OK\n"
14256 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
14257 numOK=$((numOK+1))
14259 kill $pid 2>/dev/null
14260 wait
14261 fi ;; # NUMCOND, feats
14262 esac
14263 PORT=$((PORT+1))
14264 N=$((N+1))
14266 NAME=OPENSSL_SERVERALTIP6AUTH
14267 case "$TESTS" in
14268 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
14269 TEST="$NAME: OpenSSL server authentication with SubjectAltName (IPv6 address)"
14270 if ! eval $NUMCOND; then :;
14271 elif ! testfeats openssl >/dev/null; then
14272 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
14273 numCANT=$((numCANT+1))
14274 listCANT="$listCANT $N"
14275 elif ! testfeats listen tcp ip6 openssl >/dev/null || ! runsip6 >/dev/null; then
14276 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
14277 numCANT=$((numCANT+1))
14278 listCANT="$listCANT $N"
14279 else
14280 gentestaltcert testalt
14281 tf="$td/test$N.stdout"
14282 te="$td/test$N.stderr"
14283 tdiff="$td/test$N.diff"
14284 da="test$N $(date) $RANDOM"
14285 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testalt.crt,key=testalt.key,verify=0 pipe"
14286 CMD1="$TRACE $SOCAT $opts - OPENSSL:[::1]:$PORT,verify=1,cafile=testalt.crt,$SOCAT_EGD"
14287 printf "test $F_n $TEST... " $N
14288 eval "$CMD0 2>\"${te}0\" &"
14289 pid=$! # background process id
14290 waittcp6port $PORT
14291 echo "$da" |$CMD1 >$tf 2>"${te}1"
14292 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
14293 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
14294 echo "$CMD0 &" >&2
14295 cat "${te}0" >&2
14296 echo "$CMD1" >&2
14297 cat "${te}1" >&2
14298 cat "$tdiff" >&2
14299 numFAIL=$((numFAIL+1))
14300 listFAIL="$listFAIL $N"
14301 else
14302 $PRINTF "$OK\n"
14303 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
14304 numOK=$((numOK+1))
14306 kill $pid 2>/dev/null
14307 wait
14308 fi ;; # NUMCOND, feats
14309 esac
14310 PORT=$((PORT+1))
14311 N=$((N+1))
14314 # Test the -r and -R options
14315 NAME=OPTION_RAW_DUMP
14316 case "$TESTS" in
14317 *%$N%*|*%functions%*|*%option%*|*%$NAME%*)
14318 TEST="$NAME: raw dump of transferred data"
14319 # Start Socat transferring data from left named pipe to right and from right
14320 # pipe to left, use options -r and -R, and check if dump files contain correct
14321 # data
14322 if ! eval $NUMCOND; then :;
14323 elif [ $($SOCAT -h |grep -e ' -[rR] ' |wc -l) -lt 2 ]; then
14324 $PRINTF "test $F_n $TEST... ${YELLOW}Options -r, -R not available${NORMAL}\n" $N
14325 numCANT=$((numCANT+1))
14326 listCANT="$listCANT $N"
14327 else
14328 tf="$td/test$N.stdout"
14329 te="$td/test$N.stderr"
14330 tp1="$td/test$N.pipe1"
14331 tp2="$td/test$N.pipe2"
14332 tr1="$td/test$N.raw1"
14333 tr2="$td/test$N.raw2"
14334 tdiff1="$td/test$N.diff1"
14335 tdiff2="$td/test$N.diff2"
14336 da1="test$N $(date) $RANDOM"
14337 da2="test$N $(date) $RANDOM"
14338 CMD0="$TRACE $SOCAT $opts -r $tr1 -R $tr2 PIPE:$tp1!!/dev/null PIPE:$tp2!!/dev/null"
14339 printf "test $F_n $TEST... " $N
14340 $CMD0 >/dev/null 2>"${te}0" &
14341 pid0=$!
14342 waitfile $tp1 1
14343 echo "$da1" >$tp1
14344 waitfile $tp2 1
14345 echo "$da2" >$tp2
14346 sleep 1
14347 kill $pid0 2>/dev/null; wait
14348 if ! echo "$da1" |diff - $tr1 >$tdiff1 || ! echo "$da2" |diff - $tr2 >$tdiff2; then
14349 $PRINTF "$FAILED\n"
14350 echo "$CMD0 &" >&2
14351 cat "${te}0" >&2
14352 echo "Left-to-right:" >&2
14353 cat $tdiff1 >&2
14354 echo "Right-to-left:" >&2
14355 cat $tdiff2 >&2
14356 numFAIL=$((numFAIL+1))
14357 listFAIL="$listFAIL $N"
14358 else
14359 $PRINTF "$OK\n"
14360 numOK=$((numOK+1))
14362 fi # NUMCOND
14364 esac
14365 N=$((N+1))
14368 # Test the OpenSSL SNI feature
14369 NAME=OPENSSL_SNI
14370 case "$TESTS" in
14371 *%$N%*|*%functions%*|*%socket%*|*%openssl%*|*%$NAME%*)
14372 TEST="$NAME: Test the OpenSSL SNI feature"
14373 # Connect to a server that is known to use SNI. Use an SNI name, not the
14374 # certifications default name. When the TLS connection is established
14375 # the test succeeded.
14376 SNISERVER=badssl.com
14377 if ! eval $NUMCOND; then :;
14378 elif ! testaddrs openssl >/dev/null; then
14379 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
14380 numCANT=$((numCANT+1))
14381 listCANT="$listCANT $N"
14382 elif ! feat=$(testoptions openssl-snihost); then
14383 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
14384 numCANT=$((numCANT+1))
14385 listCANT="$listCANT $N"
14386 elif [ -z "$FOREIGN" ]; then
14387 $PRINTF "test $F_n $TEST... ${YELLOW}use test.sh option -foreign${NORMAL}\n" $N
14388 numCANT=$((numCANT+1))
14389 listCANT="$listCANT $N"
14390 else
14391 tf="$td/test$N.stdout"
14392 te="$td/test$N.stderr"
14393 tdiff="$td/test$N.diff"
14394 da="test$N $(date) $RANDOM"
14395 CMD0="$TRACE $SOCAT $opts FILE:/dev/null OPENSSL-CONNECT:$SNISERVER:443"
14396 printf "test $F_n $TEST... " $N
14397 $CMD0 >/dev/null 2>"${te}0"
14398 rc0=$?
14399 if [ $rc0 -eq 0 ]; then
14400 $PRINTF "$OK\n"
14401 numOK=$((numOK+1))
14402 else
14403 $PRINTF "$FAILED\n"
14404 echo "$CMD0" >&2
14405 cat "${te}0" >&2
14406 numFAIL=$((numFAIL+1))
14407 listFAIL="$listFAIL $N"
14409 fi # NUMCOND
14411 esac
14412 N=$((N+1))
14415 # Test the openssl-no-sni option
14416 NAME=OPENSSL_NO_SNI
14417 case "$TESTS" in
14418 *%$N%*|*%functions%*|*%socket%*|*%openssl%*|*%$NAME%*)
14419 TEST="$NAME: Test the openssl-no-sni option"
14420 # Connect to a server that is known to use SNI. Use an SNI name, not the
14421 # certifications default name, and use option openssl-no-sni.
14422 # When the TLS connection failed the test succeeded.
14423 # Please note that this test is only relevant when test OPENSSL_SNI succeeded.
14424 SNISERVER=badssl.com
14425 if ! eval $NUMCOND; then :;
14426 elif ! testaddrs openssl >/dev/null; then
14427 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
14428 numCANT=$((numCANT+1))
14429 listCANT="$listCANT $N"
14430 elif ! feat=$(testoptions openssl-no-sni); then
14431 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
14432 numCANT=$((numCANT+1))
14433 listCANT="$listCANT $N"
14434 elif [ -z "$FOREIGN" ]; then
14435 $PRINTF "test $F_n $TEST... ${YELLOW}use test.sh option -foreign${NORMAL}\n" $N
14436 numCANT=$((numCANT+1))
14437 listCANT="$listCANT $N"
14438 else
14439 tf="$td/test$N.stdout"
14440 te="$td/test$N.stderr"
14441 tdiff="$td/test$N.diff"
14442 da="test$N $(date) $RANDOM"
14443 CMD0="$TRACE $SOCAT $opts FILE:/dev/null OPENSSL-CONNECT:$SNISERVER:443,openssl-no-sni"
14444 printf "test $F_n $TEST... " $N
14445 $CMD0 >/dev/null 2>"${te}0"
14446 rc0=$?
14447 if [ $rc0 -ne 0 ]; then
14448 $PRINTF "$OK\n"
14449 numOK=$((numOK+1))
14450 else
14451 $PRINTF "$FAILED\n"
14452 echo "$CMD0" >&2
14453 cat "${te}0" >&2
14454 numFAIL=$((numFAIL+1))
14455 listFAIL="$listFAIL $N"
14457 fi # NUMCOND
14459 esac
14460 N=$((N+1))
14463 # Test the accept-timeout (listen-timeout) address option
14464 NAME=ACCEPTTIMEOUT
14465 case "$TESTS" in
14466 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%listen%*|*%timeout%*|*%$NAME%*)
14467 TEST="$NAME: test the accept-timeout option"
14468 if ! eval $NUMCOND; then :;
14469 elif ! feat=$(testaddrs tcp); then
14470 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
14471 numCANT=$((numCANT+1))
14472 listCANT="$listCANT $N"
14473 elif ! feat=$(testoptions accept-timeout); then
14474 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
14475 numCANT=$((numCANT+1))
14476 listCANT="$listCANT $N"
14477 else
14478 # Just start a process with accept-timeout 1s and check if it still runs 2s later
14479 # but before this, we test if the process waits at all
14480 te1="$td/test$N.stderr1"
14481 tk1="$td/test$N.kill1"
14482 te2="$td/test$N.stderr2"
14483 tk2="$td/test$N.kill2"
14484 $PRINTF "test $F_n $TEST... " $N
14485 # First, try to make socat hang and see if it can be killed
14486 CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,reuseaddr PIPE"
14487 $CMD1 >"$te1" 2>&1 </dev/null &
14488 pid1=$!
14489 sleep 1
14490 if ! kill $pid1 2>"$tk1"; then
14491 $PRINTF "${YELLOW}does not hang${NORMAL}\n"
14492 echo $CMD1 >&2
14493 cat "$te1" >&2
14494 cat "$tk1" >&2
14495 numCANT=$((numCANT+1))
14496 listCANT="$listCANT $N"
14497 else
14498 # Second, set accept-timeout and see if socat exits before kill
14499 CMD2="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,reuseaddr,accept-timeout=1 PIPE" >"$te1" &
14500 $CMD2 >"$te1" 2>&1 </dev/null &
14501 pid2=$!
14502 sleep 1
14503 if kill $pid2 2>"$tk2"; then
14504 $PRINTF "$FAILED\n"
14505 echo "$CMD2" >&2
14506 cat "$te2" >&2
14507 cat "$tk2" >&2
14508 numFAIL=$((numFAIL+1))
14509 listFAIL="$listFAIL $N"
14510 else
14511 $PRINTF "$OK\n"
14512 numOK=$((numOK+1))
14515 wait
14516 fi ;; # testaddrs, NUMCOND
14517 esac
14518 N=$((N+1))
14521 # Test the modified UDP-DATAGRAM address: Now it ignores peerport by default
14522 NAME=UDP_DATAGRAM_PEERPORT
14523 case "$TESTS" in
14524 *%$N%*|*%functions%*|*%udp%*|*%socket%*|*%$NAME%*)
14525 TEST="$NAME: test UDP-DATAGRAM ignoring peerport"
14526 # A UDP-DATAGRAM address bound to PORT has defined peer on PORT+1
14527 # From another Socat instance we send a packet to PORT but with source port
14528 # PORT+2. The first instance should accept the packet
14529 if ! eval $NUMCOND; then :
14530 elif [ $(echo $E "$SOCAT_VERSION\n1.7.3.4" |sort -n |tail -n 1) = 1.7.3.4 ]; then
14531 $PRINTF "test $F_n $TEST... ${YELLOW}Only with Socat 1.7.4.0 or higher${NORMAL}\n" $N
14532 numCANT=$((numCANT+1))
14533 listCANT="$listCANT $N"
14534 else
14535 tf="$td/test$N.stdout"
14536 te="$td/test$N.stderr"
14537 tdiff="$td/test$N.diff"
14538 da="test$N $(date) $RANDOM"
14539 CMD0="$TRACE $SOCAT $opts -u UDP-DATAGRAM:$LOCALHOST:$((PORT+1)),bind=:$((PORT)) -"
14540 CMD1="$TRACE $SOCAT $opts -u - UDP-DATAGRAM:$LOCALHOST:$((PORT)),bind=:$((PORT+2))"
14541 printf "test $F_n $TEST... " $N
14542 $CMD0 >${tf}0 2>"${te}0" &
14543 pid0=$!
14544 waitudp4port $PORT 1
14545 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
14546 rc1=$?
14547 sleep 0.1
14548 kill $pid0 2>/dev/null; wait
14549 if [ -f ${tf}0 ] && echo "$da" |diff - ${tf}0 >$tdiff; then
14550 $PRINTF "$OK\n"
14551 numOK=$((numOK+1))
14552 else
14553 $PRINTF "$FAILED\n"
14554 echo "$CMD0 &" >&2
14555 cat "${te}0" >&2
14556 echo "$CMD1" >&2
14557 cat "${te}1" >&2
14558 cat "${tdiff}" >&2
14559 numFAIL=$((numFAIL+1))
14560 listFAIL="$listFAIL $N"
14562 fi # NUMCOND
14564 esac
14565 PORT=$((PORT+1))
14566 N=$((N+1))
14569 # Test the proxy-authorization-file option
14570 NAME=PROXYAUTHFILE
14571 case "$TESTS" in
14572 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
14573 TEST="$NAME: proxy-authorization-file option"
14574 if ! eval $NUMCOND; then :;
14575 elif ! testfeats proxy >/dev/null; then
14576 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
14577 numCANT=$((numCANT+1))
14578 listCANT="$listCANT $N"
14579 elif ! testfeats listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
14580 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
14581 numCANT=$((numCANT+1))
14582 listCANT="$listCANT $N"
14583 elif ! testoptions proxy-authorization-file >/dev/null; then
14584 $PRINTF "test $F_n $TEST... ${YELLOW}Option proxy-authorization-file not available${NORMAL}\n" $N
14585 numCANT=$((numCANT+1))
14586 listCANT="$listCANT $N"
14587 else
14588 ta="$td/test$N.auth"
14589 tf="$td/test$N.stdout"
14590 te="$td/test$N.stderr"
14591 tdiff="$td/test$N.diff"
14592 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
14593 CMD0="{ echo -e \"HTTP/1.0 200 OK\\n\"; sleep 2; } |$TRACE $SOCAT $opts - TCP4-L:$PORT,$REUSEADDR,crlf"
14594 CMD1="$TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT,proxy-authorization-file=$ta"
14595 printf "test $F_n $TEST... " $N
14596 echo "user:s3cr3t" >$ta
14597 eval "$CMD0 >${tf}0 2>${te}0 &"
14598 pid0=$! # background process id
14599 waittcp4port $PORT 1
14600 $CMD1 >"${tf}1" 2>"${te}1"
14601 rc1=$?
14602 kill $pid0 2>/dev/null
14603 wait $pid0
14604 if [ $rc1 -ne 0 ]; then
14605 $PRINTF "$FAILED\n"
14606 echo "$CMD0 &" >&2
14607 cat "${te}0" >&2
14608 echo "$CMD1" >&2
14609 cat "${te}1" >&2
14610 cat "${tf}0" >&2
14611 numFAIL=$((numFAIL+1))
14612 listFAIL="$listFAIL $N"
14613 elif ! grep -q '^Proxy-authorization: Basic dXNlcjpzM2NyM3QK$' ${tf}0; then
14614 $PRINTF "$FAILED:\n"
14615 echo "$CMD0 &" >&2
14616 cat "${te}0" >&2
14617 echo "$CMD1" >&2
14618 cat "${te}1" >&2
14619 cat "${tf}0" >&2
14620 echo "Authorization string not in client request" >&2
14621 numFAIL=$((numFAIL+1))
14622 listFAIL="$listFAIL $N"
14623 else
14624 $PRINTF "$OK\n"
14625 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
14626 numOK=$((numOK+1))
14628 kill $pid 2>/dev/null
14629 wait
14630 fi ;; # NUMCOND, feats
14631 esac
14632 PORT=$((PORT+1))
14633 N=$((N+1))
14636 # Test communication via vsock loopback socket
14637 NAME=VSOCK_ECHO
14638 case "$TESTS" in
14639 *%$N%*|*%functions%*|*%vsock%*|*%socket%*|*%$NAME%*)
14640 TEST="$NAME: test communication via vsock loopback socket"
14641 # Start a listening echo server
14642 # Connect with a client, send data and compare reply with original data
14643 if ! eval $NUMCOND; then :; else
14644 tf="$td/test$N.stdout"
14645 te="$td/test$N.stderr"
14646 tdiff="$td/test$N.diff"
14647 da="test$N $(date) $RANDOM"
14648 CMD0="$TRACE $SOCAT $opts VSOCK-LISTEN:$PORT PIPE"
14649 CMD1="$TRACE $SOCAT $opts - VSOCK-CONNECT:1:$PORT"
14650 printf "test $F_n $TEST... " $N
14651 $CMD0 >/dev/null 2>"${te}0" &
14652 pid0=$!
14653 sleep 1
14654 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
14655 rc1=$?
14656 kill $pid0 2>/dev/null; wait
14657 if [ $rc1 -ne 0 ] && [ "$UNAME" != Linux ]; then
14658 $PRINTF "${YELLOW}works only on Linux?${NORMAL}\n" $N
14659 numCANT=$((numCANT+1))
14660 listCANT="$listCANT $N"
14661 elif [ $rc1 -ne 0 ] && [ "$UNAME" = Linux ] && ! [[ $UNAME_R =~ ^[6-9]\.* ]] && ! [[ $UNAME_R =~ ^5\.[6-]\.* ]] && ! [[ $UNAME_R =~ ^5\.[1-9][0-9].* ]]; then
14662 $PRINTF "${YELLOW}works only on Linux from 5.6${NORMAL}\n" $N
14663 numCANT=$((numCANT+1))
14664 listCANT="$listCANT $N"
14665 elif [ $rc1 -ne 0 ]; then
14666 $PRINTF "$FAILED\n"
14667 echo "$CMD0 &" >&2
14668 cat "${te}0" >&2
14669 echo "$CMD1" >&2
14670 cat "${te}1" >&2
14671 numFAIL=$((numFAIL+1))
14672 listFAIL="$listFAIL $N"
14673 elif echo "$da" |diff - ${tf}1 >${tfdiff}$N; then
14674 $PRINTF "$OK\n"
14675 numOK=$((numOK+1))
14676 else
14677 $PRINTF "$FAILED\n"
14678 echo "$CMD0 &" >&2
14679 cat "${te}0" >&2
14680 echo "$CMD1" >&2
14681 cat "${te}1" >&2
14682 numFAIL=$((numFAIL+1))
14683 listFAIL="$listFAIL $N"
14685 fi # NUMCOND
14687 esac
14688 PORT=$((PORT+1))
14689 N=$((N+1))
14692 # File transfer with OpenSSL stream connection was incomplete
14693 # Test file transfer from client to server
14694 NAME=OPENSSL_STREAM_TO_SERVER
14695 case "$TESTS" in
14696 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%tcp%*|*%socket%*|*%$NAME%*)
14697 TEST="$NAME: OpenSSL stream from client to server"
14698 # Start a unidirectional OpenSSL server and stream receiver
14699 # Start a unidirectional OpenSSL client that connects to the server and sends
14700 # data
14701 # Test succeeded when the data received and stored by server is the same as
14702 # sent by the client
14703 if ! eval $NUMCOND; then :;
14704 elif ! a=$(testfeats ip4 tcp openssl); then
14705 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14706 numCANT=$((numCANT+1))
14707 listCANT="$listCANT $N"
14708 elif ! a=$(testaddrs openssl-listen openssl-connect); then
14709 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14710 numCANT=$((numCANT+1))
14711 listCANT="$listCANT $N"
14712 elif ! runsip4 >/dev/null; then
14713 $PRINTF "test $F_n $TEST... ${YELLOW}IPv4 not available${NORMAL}\n" $N
14714 numCANT=$((numCANT+1))
14715 listCANT="$listCANT $N"
14716 else
14717 gentestcert testsrv
14718 ti="$td/test$N.datain"
14719 to="$td/test$N.dataout"
14720 te="$td/test$N.stderr"
14721 tdiff="$td/test$N.diff"
14722 da="test$N $(date) $RANDOM"
14723 CMD0="$TRACE $SOCAT $opts -u OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 CREAT:$to"
14724 CMD1="$TRACE $SOCAT $opts -u OPEN:$ti OPENSSL-CONNECT:$LOCALHOST:$PORT,cafile=testsrv.crt"
14725 printf "test $F_n $TEST... " $N
14726 i=0; while [ $i -lt 100000 ]; do printf "%9u %9u %9u %9u %9u %9u %9u %9u %9u %9u\n" $i $i $i $i $i $i $i $i $i $i; let i+=100; done >$ti
14727 $CMD0 >/dev/null 2>"${te}0" &
14728 pid0=$!
14729 waittcp4port $PORT 1
14730 $CMD1 >"${tf}1" 2>"${te}1"
14731 rc1=$?
14732 usleep $MICROS
14733 kill $pid0 2>/dev/null; wait
14734 if [ $rc1 -ne 0 ]; then
14735 $PRINTF "$FAILED\n"
14736 echo "$CMD0 &" >&2
14737 cat "${te}0" >&2
14738 echo "$CMD1" >&2
14739 cat "${te}1" >&2
14740 numFAIL=$((numFAIL+1))
14741 listFAIL="$listFAIL $N"
14742 elif diff $ti $to >$tdiff; then
14743 $PRINTF "$OK\n"
14744 numOK=$((numOK+1))
14745 else
14746 $PRINTF "$FAILED\n"
14747 echo "$CMD0 &" >&2
14748 cat "${te}0" >&2
14749 echo "$CMD1" >&2
14750 cat "${te}1" >&2
14751 echo "diff:" >&2
14752 head -n 2 $tdiff >&2
14753 echo ... >&2
14754 numFAIL=$((numFAIL+1))
14755 listFAIL="$listFAIL $N"
14757 fi # NUMCOND
14759 esac
14760 PORT=$((PORT+1))
14761 N=$((N+1))
14763 # File transfer with OpenSSL stream connection was incomplete
14764 # Test file transfer from server to client
14765 NAME=OPENSSL_STREAM_TO_CLIENT
14766 case "$TESTS" in
14767 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%tcp%*|*%socket%*|*%$NAME%*)
14768 TEST="$NAME: OpenSSL stream from server to client"
14769 # Start a unidirectional OpenSSL server and stream sender
14770 # Start a unidirectional OpenSSL client that connects to the server and receives
14771 # data
14772 # Test succeeded when the data received and stored by client is the same as
14773 # sent by the server
14774 if ! eval $NUMCOND; then :;
14775 elif ! a=$(testfeats ip4 tcp openssl); then
14776 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14777 numCANT=$((numCANT+1))
14778 listCANT="$listCANT $N"
14779 elif ! a=$(testaddrs openssl-listen openssl-connect); then
14780 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14781 numCANT=$((numCANT+1))
14782 listCANT="$listCANT $N"
14783 elif ! runsip4 >/dev/null; then
14784 $PRINTF "test $F_n $TEST... ${YELLOW}IPv4 not available${NORMAL}\n" $N
14785 numCANT=$((numCANT+1))
14786 listCANT="$listCANT $N"
14787 else
14788 gentestcert testsrv
14789 ti="$td/test$N.datain"
14790 to="$td/test$N.dataout"
14791 te="$td/test$N.stderr"
14792 tdiff="$td/test$N.diff"
14793 da="test$N $(date) $RANDOM"
14794 CMD0="$TRACE $SOCAT $opts -U OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 OPEN:$ti"
14795 CMD1="$TRACE $SOCAT $opts -u OPENSSL-CONNECT:$LOCALHOST:$PORT,cafile=testsrv.crt CREAT:$to"
14796 printf "test $F_n $TEST... " $N
14797 i=0; while [ $i -lt 100000 ]; do printf "%9u %9u %9u %9u %9u %9u %9u %9u %9u %9u\n" $i $i $i $i $i $i $i $i $i $i; let i+=100; done >$ti
14798 $CMD0 >/dev/null 2>"${te}0" &
14799 pid0=$!
14800 waittcp4port $PORT 1
14801 $CMD1 >"${tf}1" 2>"${te}1"
14802 rc1=$?
14803 usleep $MICROS
14804 kill $pid0 2>/dev/null; wait
14805 if [ $rc1 -ne 0 ]; then
14806 $PRINTF "$FAILED\n"
14807 echo "$CMD0 &" >&2
14808 cat "${te}0" >&2
14809 echo "$CMD1" >&2
14810 cat "${te}1" >&2
14811 numFAIL=$((numFAIL+1))
14812 listFAIL="$listFAIL $N"
14813 elif diff $ti $to >$tdiff; then
14814 $PRINTF "$OK\n"
14815 numOK=$((numOK+1))
14816 else
14817 $PRINTF "$FAILED\n"
14818 echo "$CMD0 &" >&2
14819 cat "${te}0" >&2
14820 echo "$CMD1" >&2
14821 cat "${te}1" >&2
14822 echo "diff:" >&2
14823 head -n 2 $tdiff >&2
14824 echo ... >&2
14825 numFAIL=$((numFAIL+1))
14826 listFAIL="$listFAIL $N"
14828 fi # NUMCOND
14830 esac
14831 PORT=$((PORT+1))
14832 N=$((N+1))
14834 # Test file transfer from client to server using DTLS
14835 NAME=OPENSSL_DTLS_TO_SERVER
14836 case "$TESTS" in
14837 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%dtls%*|*%udp%*|*%socket%*|*%$NAME%*)
14838 TEST="$NAME: OpenSSL DTLS transfer from client to server"
14839 # Start a unidirectional OpenSSL DTLS server/receiver
14840 # Start a unidirectional OpenSSL DTLS client that connects to the server and
14841 # sends data
14842 # Test succeeded when the data received and stored by server is the same as
14843 # sent by the client
14844 if ! eval $NUMCOND; then :;
14845 elif ! a=$(testfeats ip4 udp openssl); then
14846 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14847 numCANT=$((numCANT+1))
14848 listCANT="$listCANT $N"
14849 elif ! a=$(testaddrs openssl-dtls-listen openssl-dtls-connect); then
14850 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14851 numCANT=$((numCANT+1))
14852 listCANT="$listCANT $N"
14853 elif ! runsip4 >/dev/null; then
14854 $PRINTF "test $F_n $TEST... ${YELLOW}IPv4 not available${NORMAL}\n" $N
14855 numCANT=$((numCANT+1))
14856 listCANT="$listCANT $N"
14857 elif [[ $(openssl version |awk '{print($2);}') =~ 0.9.8[a-c] ]]; then
14858 $PRINTF "test $F_n $TEST... ${YELLOW}openssl s_client might hang${NORMAL}\n" $N
14859 numCANT=$((numCANT+1))
14860 listCANT="$listCANT $N"
14861 else
14862 gentestcert testsrv
14863 ti="$td/test$N.datain"
14864 to="$td/test$N.dataout"
14865 te="$td/test$N.stderr"
14866 tdiff="$td/test$N.diff"
14867 da="test$N $(date) $RANDOM"
14868 CMD0="$TRACE $SOCAT $opts -u OPENSSL-DTLS-LISTEN:$PORT,cert=testsrv.pem,verify=0 CREAT:$to"
14869 CMD1="$TRACE $SOCAT $opts -u OPEN:$ti OPENSSL-DTLS-CONNECT:$LOCALHOST:$PORT,cafile=testsrv.crt"
14870 printf "test $F_n $TEST... " $N
14871 i=0; while [ $i -lt 100000 ]; do printf "%9u %9u %9u %9u %9u %9u %9u %9u %9u %9u\n" $i $i $i $i $i $i $i $i $i $i; let i+=100; done >$ti
14872 $CMD0 >/dev/null 2>"${te}0" &
14873 pid0=$!
14874 waitudp4port $PORT 1
14875 $CMD1 >"${tf}1" 2>"${te}1"
14876 rc1=$?
14877 usleep $MICROS
14878 kill $pid0 2>/dev/null; wait
14879 if [ $rc1 -ne 0 ]; then
14880 $PRINTF "$FAILED\n"
14881 echo "$CMD0 &" >&2
14882 cat "${te}0" >&2
14883 echo "$CMD1" >&2
14884 cat "${te}1" >&2
14885 numFAIL=$((numFAIL+1))
14886 listFAIL="$listFAIL $N"
14887 elif diff $ti $to >$tdiff; then
14888 $PRINTF "$OK\n"
14889 numOK=$((numOK+1))
14890 else
14891 $PRINTF "$FAILED\n"
14892 echo "$CMD0 &" >&2
14893 cat "${te}0" >&2
14894 echo "$CMD1" >&2
14895 cat "${te}1" >&2
14896 echo "diff:" >&2
14897 head -n 2 $tdiff >&2
14898 echo ... >&2
14899 numFAIL=$((numFAIL+1))
14900 listFAIL="$listFAIL $N"
14902 fi # NUMCOND
14904 esac
14905 PORT=$((PORT+1))
14906 N=$((N+1))
14908 # Test file transfer from server to client using DTLS
14909 NAME=OPENSSL_DTLS_TO_CLIENT
14910 case "$TESTS" in
14911 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%dtls%*|*%udp%*|*%socket%*|*%$NAME%*)
14912 TEST="$NAME: OpenSSL DTLS transfer from server to client"
14913 # Start a unidirectional OpenSSL DTLS server/sender
14914 # Start a unidirectional OpenSSL DTLS client that connects to the server and
14915 # receives data
14916 # Test succeeded when the data received and stored by client is the same as
14917 # sent by the server
14918 if ! eval $NUMCOND; then :;
14919 elif ! a=$(testfeats ip4 udp openssl); then
14920 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14921 numCANT=$((numCANT+1))
14922 listCANT="$listCANT $N"
14923 elif ! a=$(testaddrs openssl-dtls-listen openssl-dtls-connect); then
14924 $PRINTF "test $F_n $TEST... ${YELLOW}$a not available${NORMAL}\n" $N
14925 numCANT=$((numCANT+1))
14926 listCANT="$listCANT $N"
14927 elif ! runsip4 >/dev/null; then
14928 $PRINTF "test $F_n $TEST... ${YELLOW}IPv4 not available${NORMAL}\n" $N
14929 numCANT=$((numCANT+1))
14930 listCANT="$listCANT $N"
14931 elif [[ $(openssl version |awk '{print($2);}') =~ 0.9.8[a-c] ]]; then
14932 $PRINTF "test $F_n $TEST... ${YELLOW}openssl s_client might hang${NORMAL}\n" $N
14933 numCANT=$((numCANT+1))
14934 listCANT="$listCANT $N"
14935 else
14936 gentestcert testsrv
14937 ti="$td/test$N.datain"
14938 to="$td/test$N.dataout"
14939 te="$td/test$N.stderr"
14940 tdiff="$td/test$N.diff"
14941 da="test$N $(date) $RANDOM"
14942 CMD0="$TRACE $SOCAT $opts -U OPENSSL-DTLS-LISTEN:$PORT,cert=testsrv.pem,verify=0 OPEN:$ti"
14943 CMD1="$TRACE $SOCAT $opts -u OPENSSL-DTLS-CONNECT:$LOCALHOST:$PORT,cafile=testsrv.crt CREAT:$to"
14944 printf "test $F_n $TEST... " $N
14945 i=0; while [ $i -lt 100000 ]; do printf "%9u %9u %9u %9u %9u %9u %9u %9u %9u %9u\n" $i $i $i $i $i $i $i $i $i $i; let i+=100; done >$ti
14946 $CMD0 >/dev/null 2>"${te}0" &
14947 pid0=$!
14948 waitudp4port $PORT 1
14949 $CMD1 >"${tf}1" 2>"${te}1"
14950 rc1=$?
14951 usleep $MICROS
14952 kill $pid0 2>/dev/null; wait
14953 if [ $rc1 -ne 0 ]; then
14954 $PRINTF "$FAILED\n"
14955 echo "$CMD0 &" >&2
14956 cat "${te}0" >&2
14957 echo "$CMD1" >&2
14958 cat "${te}1" >&2
14959 numFAIL=$((numFAIL+1))
14960 listFAIL="$listFAIL $N"
14961 elif diff $ti $to >$tdiff; then
14962 $PRINTF "$OK\n"
14963 numOK=$((numOK+1))
14964 else
14965 $PRINTF "$FAILED\n"
14966 echo "$CMD0 &" >&2
14967 cat "${te}0" >&2
14968 echo "$CMD1" >&2
14969 cat "${te}1" >&2
14970 echo "diff:" >&2
14971 head -n 2 $tdiff >&2
14972 echo ... >&2
14973 numFAIL=$((numFAIL+1))
14974 listFAIL="$listFAIL $N"
14976 fi # NUMCOND
14978 esac
14979 PORT=$((PORT+1))
14980 N=$((N+1))
14983 # Test if the problem with overlapping internal parameters of sockets and
14984 # openssl are fixed
14985 NAME=OPENSSL_PARA_OVERLAP
14986 case "$TESTS" in
14987 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%ip4%*|*%tcp%*|*%tcp4%*|*%openssl%*|*%$NAME%*)
14988 TEST="$NAME: test diverse of socket,openssl params"
14989 # That bug had not many effects; the simplest to use is possible SIGSEGV on
14990 # close when option accept-timeout with fractional seconds was applied
14991 if ! eval $NUMCOND; then :;
14992 elif ! testfeats openssl >/dev/null; then
14993 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
14994 numCANT=$((numCANT+1))
14995 listCANT="$listCANT $N"
14996 elif ! type openssl >/dev/null 2>&1; then
14997 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
14998 numCANT=$((numCANT+1))
14999 listCANT="$listCANT $N"
15000 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
15001 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
15002 numCANT=$((numCANT+1))
15003 listCANT="$listCANT $N"
15004 else
15005 gentestcert testsrv
15006 tf="$td/test$N.stdout"
15007 te="$td/test$N.stderr"
15008 tdiff="$td/test$N.diff"
15009 trc0="$td/test$N.rc0"
15010 da="test$N $(date) $RANDOM"
15011 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,accept-timeout=4.5,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
15012 CMD1="$TRACE $SOCAT $opts /dev/null OPENSSL-CONNECT:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
15013 printf "test $F_n $TEST... " $N
15014 $CMD0 >/dev/null 2>"${te}0" || echo $? >$trc0 &
15015 pid0=$!
15016 waittcp4port $PORT 1
15017 $CMD1 >"${tf}1" 2>"${te}1"
15018 rc1=$?
15019 sleep 0.5
15020 kill $pid0 2>/dev/null; wait
15021 if [ $rc1 -ne 0 ]; then
15022 $PRINTF "$CANT\n"
15023 numCANT=$((numCANT+1))
15024 elif [ ! -e $trc0 ]; then
15025 $PRINTF "$OK\n"
15026 numOK=$((numOK+1))
15027 else
15028 $PRINTF "$FAILED\n"
15029 echo "$CMD0 &" >&2
15030 cat "${te}0" >&2
15031 echo "$CMD1" >&2
15032 cat "${te}1" >&2
15033 numFAIL=$((numFAIL+1))
15034 listFAIL="$listFAIL $N"
15036 fi # NUMCOND
15038 esac
15039 PORT=$((PORT+1))
15040 N=$((N+1))
15043 # Bug fix, OpenSSL server could be crashed by client cert with IPv6 address in SubjectAltname
15044 NAME=OPENSSL_CLIENT_IP6_CN
15045 case "$TESTS" in
15046 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%ip6%*|*%socket%*|*%$NAME%*)
15047 TEST="$NAME: Test if OpenSSL server may be crashed by client cert with IPv6 address"
15048 # Socat 1.7.4.1 had a bug that caused OpenSSL server to crash with SIGSEGV when
15049 # it checked a client certificate containing IPv6 address in SubjectAltName and
15050 # no openssl-commonname option was given
15051 if ! eval $NUMCOND; then :;
15052 elif ! testfeats openssl >/dev/null; then
15053 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
15054 numCANT=$((numCANT+1))
15055 listCANT="$listCANT $N"
15056 elif ! testfeats tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
15057 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
15058 numCANT=$((numCANT+1))
15059 listCANT="$listCANT $N"
15060 else
15061 gentestcert testsrv
15062 gentestaltcert testalt
15063 tf="$td/test$N.stdout"
15064 te="$td/test$N.stderr"
15065 tdiff="$td/test$N.diff"
15066 da="test$N $(date) $RANDOM"
15067 CMD0="$TRACE $SOCAT $opts -u OPENSSL-LISTEN:$PORT,reuseaddr,cert=./testsrv.pem,cafile=./testalt.crt -"
15068 CMD1="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:localhost:$PORT,cafile=testsrv.crt,cert=testalt.pem,verify=0"
15069 printf "test $F_n $TEST... " $N
15070 $CMD0 >/dev/null >"${tf}0" 2>"${te}0" &
15071 pid0=$!
15072 waittcp4port $PORT 1
15073 echo "$da" |$CMD1 2>"${te}1"
15074 rc1=$?
15075 kill $pid0 2>/dev/null; wait
15076 if [ $rc1 -eq 0 ] && echo "$da" |diff - "${tf}0" >$tdiff; then
15077 $PRINTF "$OK\n"
15078 numOK=$((numOK+1))
15079 else
15080 $PRINTF "$FAILED\n"
15081 echo "$CMD0 &" >&2
15082 cat "${te}0" >&2
15083 echo "$CMD1" >&2
15084 cat "${te}1" >&2
15085 numFAIL=$((numFAIL+1))
15086 listFAIL="$listFAIL $N"
15088 fi # NUMCOND
15090 esac
15091 PORT=$((PORT+1))
15092 N=$((N+1))
15095 # Test if unknown service specs are handled properly
15096 NAME=BAD_SERVICE
15097 case "$TESTS" in
15098 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%socket%*|*%$NAME%*)
15099 TEST="$NAME: test if unknown service specs are handled properly"
15100 # Try to resolve an unspecified TCP service "
15101 if ! eval $NUMCOND; then :; else
15102 tf="$td/test$N.stdout"
15103 te="$td/test$N.stderr"
15104 tdiff="$td/test$N.diff"
15105 da="test$N $(date) $RANDOM"
15106 CMD="$TRACE $SOCAT $opts - TCP:$LOCALHOST:zyxw"
15107 printf "test $F_n $TEST... " $N
15108 $CMD >/dev/null 2>"${te}" &
15109 pid=$!
15110 sleep 1
15111 kill -9 $pid 2>/dev/null;
15112 rc=$? # did process still exist?
15113 if [ $rc -ne 0 ]; then
15114 $PRINTF "$OK\n"
15115 if [ "$VERBOSE" ]; then
15116 echo "$CMD &" >&2
15118 numOK=$((numOK+1))
15119 else
15120 $PRINTF "$FAILED\n"
15121 echo "$CMD &" >&2
15122 cat "${te}" >&2
15123 numFAIL=$((numFAIL+1))
15124 listFAIL="$listFAIL $N"
15126 fi # NUMCOND
15128 esac
15129 PORT=$((PORT+1))
15130 N=$((N+1))
15133 # Test if the user option with abstract UNIX domain socket is not applied to
15134 # file "" (empty name)
15135 NAME=ABSTRACT_USER
15136 case "$TESTS" in
15137 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
15138 TEST="$NAME: Is the fs related user option on ABSTRACT socket applied to FD"
15139 # Apply the user option to an abstract socket; check if this produces an error.
15140 # No error should occur
15141 if ! eval $NUMCOND; then :;
15142 elif [ "$UNAME" != Linux ]; then
15143 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
15144 numCANT=$((numCANT+1))
15145 listCANT="$listCANT $N"
15146 else
15147 tf="$td/test$N.stdout"
15148 te="$td/test$N.stderr"
15149 tdiff="$td/test$N.diff"
15150 da="test$N $(date) $RANDOM"
15151 CMD="$TRACE $SOCAT ABSTRACT-LISTEN:temp,accept-timeout=0.1,user=$USER FILE:/dev/null"
15152 printf "test $F_n $TEST... " $N
15153 $CMD >/dev/null 2>"${te}"
15154 echo "$da" |$CMD >"${tf}1" 2>"${te}1"
15155 rc=$?
15156 if [ $rc -eq 0 ]; then
15157 $PRINTF "$OK\n"
15158 if [ "$VERBOSE" ]; then
15159 echo "$CMD" >&2
15161 numOK=$((numOK+1))
15162 else
15163 $PRINTF "$FAILED\n"
15164 echo "$CMD" >&2
15165 cat "${te}" >&2
15166 numFAIL=$((numFAIL+1))
15167 listFAIL="$listFAIL $N"
15169 fi # NUMCOND
15171 esac
15172 PORT=$((PORT+1))
15173 N=$((N+1))
15176 # Test if option -R does not "sniff" left-to-right traffic
15177 NAME=SNIFF_RIGHT_TO_LEFT
15178 case "$TESTS" in
15179 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
15180 TEST="$NAME: test if option -R does not "sniff" left-to-right traffic"
15181 # Use option -R, check if left-to-right traffic is not in output file
15182 if ! eval $NUMCOND; then :; else
15183 tf="$td/test$N.stdout"
15184 te="$td/test$N.stderr"
15185 ts="$td/test$N.sniffed"
15186 tdiff="$td/test$N.diff"
15187 da="test$N $(date) $RANDOM"
15188 CMD="$TRACE $SOCAT $opts -R $ts - /dev/null"
15189 printf "test $F_n $TEST... " $N
15190 echo "$da" |$CMD >"${tf}" 2>"${te}"
15191 rc=$?
15192 if [ ! -f "$ts" ]; then
15193 $PRINTF "$CANT\n"
15194 if [ "$VERBOSE" ]; then
15195 echo "$CMD" >&2
15196 cat "${te}" >&2
15198 numCANT=$((numCANT+1))
15199 listCANT="$listCANT $N"
15200 elif [ ! -s "$ts" ]; then
15201 $PRINTF "$OK\n"
15202 if [ "$VERBOSE" ]; then
15203 echo "$CMD" >&2
15205 numOK=$((numOK+1))
15206 else
15207 $PRINTF "$FAILED\n"
15208 echo "$CMD &" >&2
15209 cat "${te}" >&2
15210 numFAIL=$((numFAIL+1))
15211 listFAIL="$listFAIL $N"
15213 fi # NUMCOND
15215 esac
15216 PORT=$((PORT+1))
15217 N=$((N+1))
15220 # end of common tests
15222 ##################################################################################
15223 #=================================================================================
15224 # here come tests that might affect your systems integrity. Put normal tests
15225 # before this paragraph.
15226 # tests must be explicitely selected by roottough or name (not number)
15228 NAME=PTYGROUPLATE
15229 case "$TESTS" in
15230 *%roottough%*|*%$NAME%*)
15231 TEST="$NAME: pty with group-late works on pty"
15232 # up to socat 1.7.1.1 address pty changed the ownership of /dev/ptmx instead of
15233 # the pty with options user-late, group-late, or perm-late.
15234 # here we check for correct behaviour.
15235 # ATTENTION: in case of failure of this test the
15236 # group of /dev/ptmx might be changed!
15237 if ! eval $NUMCOND; then :; else
15238 # save current /dev/ptmx properties
15240 for f in /dev/ptmx /dev/ptc; do
15241 if [ -e $f ]; then
15242 F=$(echo "$f" |tr / ..)
15243 ls -l $f >"$td/test$N.$F.ls-l"
15244 break
15246 done
15247 printf "test $F_n $TEST... " $N
15248 if [ -z "$F" ]; then
15249 echo -e "${YELLOW}no /dev/ptmx or /dev/ptc${NORMAL}"
15250 else
15251 GROUP=daemon
15252 tf="$td/test$N.stdout"
15253 te="$td/test$N.stderr"
15254 tl="$td/test$N.pty"
15255 tdiff="$td/test$N.diff"
15256 da="test$N $(date) $RANDOM"
15257 CMD0="$TRACE $SOCAT $opts pty,link=$tl,group-late=$GROUP,escape=0x1a PIPE"
15258 CMD1="$TRACE $SOCAT $opts - $tl,raw,echo=0"
15259 $CMD0 >/dev/null 2>"${te}0" &
15260 pid0=$!
15261 (echo "$da"; usleep $MICROS; echo -e "\x1a") |$CMD1 >"${tf}1" 2>"${te}1" >"$tf"
15262 rc1=$?
15263 kill $pid0 2>/dev/null; wait
15264 if [ $rc1 -ne 0 ]; then
15265 $PRINTF "$FAILED\n"
15266 echo "$CMD0 &"
15267 echo "$CMD1"
15268 cat "${te}0"
15269 cat "${te}1"
15270 numFAIL=$((numFAIL+1))
15271 listFAIL="$listFAIL $N"
15272 elif echo "$da" |diff - "$tf" >$tdiff; then
15273 $PRINTF "$OK\n"
15274 numOK=$((numOK+1))
15275 else
15276 $PRINTF "$FAILED\n"
15277 cat "$tdiff"
15278 numFAIL=$((numFAIL+1))
15279 listFAIL="$listFAIL $N"
15281 if ! ls -l $f |diff "$td/test$N.$F.ls-l" -; then
15282 $PRINTF "${RED}this test changed properties of $f!${NORMAL}\n"
15284 fi # no /dev/ptmx
15285 fi # NUMCOND
15287 esac
15288 N=$((N+1))
15291 echo "Used temp directory $TD - you might want to remove it after analysis"
15292 echo "Summary: $((N-1)) tests, $((numOK+numFAIL+numCANT)) selected; $numOK ok, $numFAIL failed, $numCANT could not be performed"
15294 if [ "$numCANT" -gt 0 ]; then
15295 echo "CANT: $listCANT"
15297 if [ "$numFAIL" -gt 0 ]; then
15298 echo "FAILED: $listFAIL"
15299 exit 1
15301 exit 0
15303 #==============================================================================
15305 rm -f testsrv.* testcli.* testsrvdsa* testsrvfips* testclifips*
15307 # end
15309 # too dangerous - run as root and having a shell problem, it might purge your
15310 # file systems
15311 #rm -r "$td"
15313 # sometimes subprocesses hang; we want to see this
15314 wait
15316 exit
15318 #==============================================================================
15319 # test template
15321 # give a description of what is tested (a bugfix, a new feature...)
15322 NAME=SHORT_UNIQUE_TESTNAME
15323 case "$TESTS" in
15324 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
15325 TEST="$NAME: give a one line description of test"
15326 # describe how the test is performed, and what's the success criteria
15327 if ! eval $NUMCOND; then :; else
15328 tf="$td/test$N.stdout"
15329 te="$td/test$N.stderr"
15330 tdiff="$td/test$N.diff"
15331 da="test$N $(date) $RANDOM"
15332 CMD0="$TRACE $SOCAT $opts server-address PIPE"
15333 CMD1="$TRACE $SOCAT $opts - client-address"
15334 printf "test $F_n $TEST... " $N
15335 $CMD0 >/dev/null 2>"${te}0" &
15336 pid0=$!
15337 wait<something>port $PORT 1
15338 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
15339 rc1=$?
15340 kill $pid0 2>/dev/null; wait
15341 if [ !!! ]; then
15342 $PRINTF "$OK\n"
15343 if [ "$VERBOSE" ]; then
15344 echo "$CMD0 &" >&2
15345 echo "$CMD1" >&2
15347 numOK=$((numOK+1))
15348 else
15349 $PRINTF "$FAILED\n"
15350 echo "$CMD0 &" >&2
15351 cat "${te}0" >&2
15352 echo "$CMD1" >&2
15353 cat "${te}1" >&2
15354 numFAIL=$((numFAIL+1))
15355 listFAIL="$listFAIL $N"
15357 fi # NUMCOND
15359 esac
15360 PORT=$((PORT+1))
15361 N=$((N+1))