nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #! /bin/bash
2 # source: test.sh
3 # Copyright Gerhard Rieger
4 # Published under the GNU General Public License V.2, see file COPYING
5  
6 # perform lots of tests on socat
7  
8 # this script uses functions; you need a shell that supports them
9  
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
13  
14 val_t=0.1
15 NUMCOND=true
16 #NUMCOND="test \$N -gt 70"
17 while [ "$1" ]; do
18 case "X$1" in
19 X-t?*) val_t="${1#-t}" ;;
20 X-t) shift; val_t="$1" ;;
21 X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
22 X-n) shift; NUMCOND="test \$N -eq $1" ;;
23 X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
24 X-N) shift; NUMCOND="test \$N -ge $1" ;;
25 *) break;
26 esac
27 shift
28 done
29  
30 opt_t="-t $val_t"
31  
32  
33 #MICROS=100000
34 case "X$val_t" in
35 X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
36 X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
37 X*) S="${val_t}"; uS="000000" ;;
38 esac
39 MICROS=${S}${uS}
40 MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
41 #
42 _MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
43 [ -z "$SECONDs" ] && SECONDs=0
44  
45 withroot=0 # perform privileged tests even if not run by root
46 #PATH=$PATH:/opt/freeware/bin
47 #PATH=$PATH:/usr/local/ssl/bin
48 case "$0" in
49 */*) PATH="${0%/*}:$PATH"
50 esac
51 #OPENSSL_RAND="-rand /dev/egd-pool"
52 #SOCAT_EGD="egd=/dev/egd-pool"
53 MISCDELAY=1
54 [ -z "$SOCAT" ] && SOCAT="./socat"
55 if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
56 echo "$SOCAT does not exist" >&2; exit 1;
57 fi
58 [ -z "$PROCAN" ] && PROCAN="./procan"
59 [ -z "$FILAN" ] && FILAN="./filan"
60 opts="$opt_t $OPTS"
61 export SOCAT_OPTS="$opts"
62 #debug="1"
63 debug=
64 TESTS="$@"; export TESTS
65 # for some tests we need a network interface
66 if type ip >/dev/null 2>&1; then
67 INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
68 else
69 INTERFACE=eth0
70 fi
71 MCINTERFACE=lo # !!! Linux only
72 #LOCALHOST=192.168.58.1
73 LOCALHOST=localhost
74 #LOCALHOST=127.0.0.1
75 LOCALHOST6=[::1]
76 #PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
77 #PROTO=$(($PROTO+1))
78 PROTO=$((144+RANDOM/2048))
79 PORT=12002
80 SOURCEPORT=2002
81  
82 # SSL certificate contents
83 TESTCERT_CONF=testcert.conf
84 TESTCERT6_CONF=testcert6.conf
85 #
86 TESTCERT_COMMONNAME="$LOCALHOST"
87 TESTCERT_COMMONNAME6="$LOCALHOST6"
88 TESTCERT_COUNTRYNAME="XY"
89 TESTCERT_LOCALITYNAME="Lunar Base"
90 TESTCERT_ORGANIZATIONALUNITNAME="socat"
91 TESTCERT_ORGANIZATIONNAME="dest-unreach"
92 TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
93 TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
94 cat >$TESTCERT_CONF <<EOF
95 prompt=no
96  
97 [ req ]
98 default_bits = 768
99 distinguished_name=Test
100  
101 [ Test ]
102 countryName=$TESTCERT_COUNTRYNAME
103 commonName=$TESTCERT_COMMONNAME
104 O=$TESTCERT_ORGANIZATIONNAME
105 OU=$TESTCERT_ORGANIZATIONALUNITNAME
106 L=$TESTCERT_LOCALITYNAME
107 EOF
108  
109 cat >$TESTCERT6_CONF <<EOF
110 prompt=no
111  
112 [ req ]
113 default_bits = 768
114 distinguished_name=Test
115  
116 [ Test ]
117 countryName=$TESTCERT_COUNTRYNAME
118 commonName=$TESTCERT_COMMONNAME6
119 O=$TESTCERT_ORGANIZATIONNAME
120 OU=$TESTCERT_ORGANIZATIONALUNITNAME
121 L=$TESTCERT_LOCALITYNAME
122 EOF
123  
124 # clean up from previous runs
125 rm -f testcli.{crt,key,pem}
126 rm -f testsrv.{crt,key,pem}
127 rm -f testcli6.{crt,key,pem}
128 rm -f testsrv6.{crt,key,pem}
129  
130  
131 CAT=cat
132 OD_C="od -c"
133  
134 # precision sleep; takes seconds with fractional part
135 psleep () {
136 local T="$1"
137 #[ "$T" = 0 ] && T=0.000002
138 [ "$T" = 0 ] && return
139 $SOCAT -T "$T" pipe pipe
140 }
141 # time in microseconds to wait in some situations
142 if ! type usleep >/dev/null 2>&1; then
143 usleep () {
144 local n="$1"
145 case "$n" in
146 *???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
147 *) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
148 esac
149 [ "$S.$uS" = "0.000000" ] && return
150 $SOCAT -T $S.$uS pipe pipe
151 }
152 fi
153  
154 # a "real value" sleep
155 rsleep () {
156 local n="$1"
157 local s="${n%.*}"
158 local u="${n#*.}"
159 sleep "$s"
160 usleep "$((u*10**(6-${#u})))"
161 }
162  
163 #USLEEP=usleep
164 F_n="%3d" # format string for test numbers
165 LC_ALL=C # for timestamps format...
166 LANG=C
167 LANGUAGE=C # knoppix
168 UNAME=`uname`
169 case "$UNAME" in
170 HP-UX|OSF1)
171 echo "$SOCAT -u stdin stdout" >cat.sh
172 chmod a+x cat.sh
173 CAT=./cat.sh
174 ;;
175 SunOS)
176 # /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
177 # /usr/xpg4/bin/tr instead
178 alias tr=/usr/xpg4/bin/tr
179 ;;
180 *)
181 CAT=cat
182 ;;
183 esac
184  
185 case "$UNAME" in
186 #HP-UX)
187 # # on HP-UX, the default options (below) hang some tests (former 14, 15)
188 # PTYOPTS=
189 # PTYOPTS2=
190 # ;;
191 *)
192 #PTYOPTS="echo=0,opost=0"
193 PTYOPTS2="raw,echo=0"
194 #PTYOPTS2="rawer"
195 ;;
196 esac
197  
198 # for some tests we need an unprivileged user id to su to
199 if [ "$SUDO_USER" ]; then
200 SUBSTUSER="$SUDO_USER"
201 else
202 SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
203 fi
204  
205 # non-root users might miss ifconfig in their path
206 case "$UNAME" in
207 AIX) IFCONFIG=/usr/sbin/ifconfig ;;
208 FreeBSD) IFCONFIG=/sbin/ifconfig ;;
209 HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
210 Linux) IFCONFIG=/sbin/ifconfig ;;
211 NetBSD)IFCONFIG=/sbin/ifconfig ;;
212 OpenBSD)IFCONFIG=/sbin/ifconfig ;;
213 OSF1) IFCONFIG=/sbin/ifconfig ;;
214 SunOS) IFCONFIG=/sbin/ifconfig ;;
215 Darwin)IFCONFIG=/sbin/ifconfig ;;
216 DragonFly) IFCONFIG=/sbin/ifconfig ;;
217 *) IFCONFIG=/sbin/ifconfig ;;
218 esac
219  
220 # need output like "644"
221 case "$UNAME" in
222 Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
223 FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
224 *) fileperms() {
225 local p s=0 c
226 p="$(ls -l -L "$1" |awk '{print($1);}')"
227 p="${p:1:9}"
228 while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
229 printf "%03o\n" $s;
230 } ;;
231 esac
232  
233 # need user (owner) of filesystem entry
234 case "$UNAME" in
235 Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
236 FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
237 *) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
238 esac
239  
240  
241 # for some tests we need a second local IPv4 address
242 case "$UNAME" in
243 Linux)
244 BROADCASTIF=$(ip r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
245 [ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
246 SECONDADDR=127.1.0.1
247 SECONDMASK=255.255.0.0
248 BCADDR=127.255.255.255
249 BCIFADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}' |cut -d: -f2) ;;
250 FreeBSD|NetBSD|OpenBSD)
251 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
252 BROADCASTIF="$MAINIF"
253 SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
254 BCIFADDR="$SECONDADDR"
255 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
256 HP-UX)
257 MAINIF=lan0 # might use "netstat -ni" for this
258 BROADCASTIF="$MAINIF"
259 SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
260 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
261 SunOS)
262 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
263 BROADCASTIF="$MAINIF"
264 #BROADCASTIF=hme0
265 #BROADCASTIF=eri0
266 #SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
267 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
268 #BCIFADDR="$SECONDADDR"
269 #BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
270 ;;
271 DragonFly)
272 MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
273 BROADCASTIF="$MAINIF"
274 SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
275 BCIFADDR="$SECONDADDR"
276 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
277 #AIX|FreeBSD|Solaris)
278 *)
279 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
280 ;;
281 esac
282 # for generic sockets we need this address in hex form
283 if [ "$SECONDADDR" ]; then
284 SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' '
285 '))"
286 fi
287  
288 # for some tests we need a second local IPv6 address
289 case "$UNAME" in
290 *)
291 SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
292 ;;
293 esac
294 if [ -z "$SECONDIP6ADDR" ]; then
295 # case "$TESTS" in
296 # *%root2%*) $IFCONFIG eth0 ::2/128
297 # esac
298 SECONDIP6ADDR="$LOCALHOST6"
299 else
300 SECONDIP6ADDR="[$SECONDIP6ADDR]"
301 fi
302  
303 TRUE=$(which true)
304 #E=-e # Linux
305 if [ $(echo "x\c") = "x" ]; then E=""
306 elif [ $(echo -e "x\c") = "x" ]; then E="-e"
307 else
308 echo "cannot suppress trailing newline on echo" >&2
309 exit 1
310 fi
311 ECHO="echo $E"
312 PRINTF="printf"
313  
314 case "$TERM" in
315 vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color)
316 # there are different behaviours of printf (and echo)
317 # on some systems, echo behaves different than printf...
318 if [ $($PRINTF "\0101") = "A" ]; then
319 RED="\0033[31m"
320 GREEN="\0033[32m"
321 YELLOW="\0033[33m"
322 # if [ "$UNAME" = SunOS ]; then
323 # NORMAL="\0033[30m"
324 # else
325 NORMAL="\0033[39m"
326 # fi
327 else
328 RED="\033[31m"
329 GREEN="\033[32m"
330 YELLOW="\033[33m"
331 # if [ "$UNAME" = SunOS ]; then
332 # NORMAL="\033[30m"
333 # else
334 NORMAL="\033[39m"
335 # fi
336 fi
337 OK="${GREEN}OK${NORMAL}"
338 FAILED="${RED}FAILED${NORMAL}"
339 NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
340 ;;
341 *) OK="OK"
342 FAILED="FAILED"
343 NO_RESULT="NO RESULT"
344 ;;
345 esac
346  
347  
348 if [ -x /usr/xpg4/bin/id ]; then
349 # SunOS has rather useless tools in its default path
350 PATH="/usr/xpg4/bin:$PATH"
351 fi
352  
353 [ -z "$TESTS" ] && TESTS="consistency functions filan"
354 # use '%' as separation char
355 TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
356  
357 [ -z "$USER" ] && USER="$LOGNAME" # HP-UX
358 if [ -z "$TMPDIR" ]; then
359 if [ -z "$TMP" ]; then
360 TMP=/tmp
361 fi
362 TMPDIR="$TMP"
363 fi
364 TD="$TMPDIR/$USER/$$"; td="$TD"
365 rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
366 mkdir -p "$TD"
367 #trap "rm -r $TD" 0 3
368  
369 echo "using temp directory $TD"
370  
371 case "$TESTS" in
372 *%consistency%*)
373 # test if addresses are sorted alphabetically:
374 $ECHO "testing if address array is sorted...\c"
375 TF="$TD/socat-q"
376 IFS="$($ECHO ' \n\t')"
377 $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
378 $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"
379 if [ -s "$TF-diff" ]; then
380 $ECHO "\n*** address array is not sorted. Wrong entries:" >&2
381 cat "$TD/socat-q-diff" >&2
382 exit 1
383 else
384 echo " ok"
385 fi
386 #/bin/rm "$TF"
387 #/bin/rm "$TF-diff"
388 esac
389  
390 case "$TESTS" in
391 *%consistency%*)
392 # test if address options array ("optionnames") is sorted alphabetically:
393 $ECHO "testing if address options are sorted...\c"
394 TF="$TD/socat-qq"
395 $SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
396 LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
397 if [ -s "$TF-diff" ]; then
398 $ECHO "\n*** option array is not sorted. Wrong entries:" >&2
399 cat "$TD/socat-qq-diff" >&2
400 exit 1
401 else
402 echo " ok"
403 fi
404 /bin/rm "$TF"
405 /bin/rm "$TF-diff"
406 esac
407  
408 #==============================================================================
409 case "$TESTS" in
410 *%options%*)
411  
412 # inquire which options are available
413 OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
414 OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
415 OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
416 OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
417 OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
418 OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
419 OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
420 OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
421 OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
422 OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
423 OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
424 OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
425 OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
426 OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
427 OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
428 OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
429 OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
430 OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
431 OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
432 OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
433 OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
434 OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
435 OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
436 OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
437 OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
438 OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
439 OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
440 OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
441 OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
442 OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
443  
444 # find user ids to setown to; non-root only can setown to itself
445 if [ $(id -u) = 0 ]; then
446 # up to now, it is not a big problem when these do not exist
447 _UID=nobody
448 _GID=staff
449 else
450 _UID=$(id -u)
451 _GID=$(id -g)
452 fi
453  
454 # some options require values; here we try to replace these bare options with
455 # valid forms.
456 filloptionvalues() {
457 local OPTS=",$1,"
458 #
459 case "$OPTS" in
460 *,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
461 esac
462 case "$OPTS" in
463 *,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
464 esac
465 case "$OPTS" in
466 *,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
467 esac
468 case "$OPTS" in
469 *,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
470 esac
471 case "$OPTS" in
472 *,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
473 esac
474 case "$OPTS" in
475 *,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
476 esac
477 case "$OPTS" in
478 *,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
479 esac
480 case "$OPTS" in
481 *,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
482 esac
483 case "$OPTS" in
484 *,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
485 esac
486 case "$OPTS" in
487 *,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
488 esac
489 case "$OPTS" in
490 *,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
491 esac
492 case "$OPTS" in
493 *,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
494 esac
495 case "$OPTS" in
496 *,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
497 esac
498 case "$OPTS" in
499 *,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
500 esac
501 case "$OPTS" in
502 *,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
503 esac
504 case "$OPTS" in
505 *,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
506 esac
507 case "$OPTS" in
508 *,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
509 esac
510 case "$OPTS" in
511 *,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
512 esac
513 case "$OPTS" in
514 *,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
515 esac
516 # SOCKET
517 case "$OPTS" in
518 *,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
519 esac
520 case "$OPTS" in
521 *,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
522 esac
523 case "$OPTS" in
524 *,rcvtimeo,*) OPTS=$(echo "$OPTS" |sed "s/,rcvtimeo,/,rcvtimeo=1,/g");;
525 esac
526 case "$OPTS" in
527 *,sndtimeo,*) OPTS=$(echo "$OPTS" |sed "s/,sndtimeo,/,sndtimeo=1,/g");;
528 esac
529 case "$OPTS" in
530 *,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
531 esac
532 # IP
533 case "$OPTS" in
534 *,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
535 esac
536 case "$OPTS" in
537 *,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
538 esac
539 case "$OPTS" in
540 *,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
541 esac
542 case "$OPTS" in
543 *,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
544 esac
545 # PTY
546 case "$OPTS" in
547 *,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
548 esac
549 # RETRY
550 case "$OPTS" in
551 *,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
552 esac
553 # READLINE
554 case "$OPTS" in
555 *,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
556 esac
557 case "$OPTS" in
558 *,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
559 esac
560 case "$OPTS" in
561 *,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
562 esac
563 # IPAPP
564 case "$OPTS" in
565 *,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
566 esac
567 # OPENSSL
568 case "$OPTS" in
569 *,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
570 esac
571 case "$OPTS" in
572 *,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
573 esac
574 case "$OPTS" in
575 *,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
576 esac
577 case "$OPTS" in
578 *,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
579 esac
580 case "$OPTS" in
581 *,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
582 esac
583 case "$OPTS" in
584 *,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
585 esac
586 case "$OPTS" in
587 *,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
588 esac
589 case "$OPTS" in
590 *,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
591 esac
592 case "$OPTS" in
593 *,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
594 esac
595 # PROXY
596 case "$OPTS" in
597 *,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
598 esac
599 case "$OPTS" in
600 *,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
601 esac
602 case "$OPTS" in
603 *,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
604 esac
605 # TCP-WRAPPERS
606 case "$OPTS" in
607 *,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
608 esac
609 case "$OPTS" in
610 *,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
611 esac
612 case "$OPTS" in
613 *,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
614 esac
615 echo $OPTS >&2
616 expr "$OPTS" : ',\(.*\),'
617 }
618 # OPTS_FIFO: nothing yet
619  
620 # OPTS_CHR: nothing yet
621  
622 # OPTS_BLK: nothing yet
623  
624 # OPTS_REG: nothing yet
625  
626 OPTS_SOCKET=",$OPTS_SOCKET,"
627 OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
628  
629 N=1
630 #------------------------------------------------------------------------------
631  
632 #method=open
633 #METHOD=$(echo "$method" |tr a-z A-Z)
634 #TEST="$METHOD on file accepts all its options"
635 # echo "### $TEST"
636 #TF=$TD/file$N
637 #DA="test$N $(date) $RANDOM"
638 #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
639 #for g in $(echo $OPTGROUPS |tr ',' ' '); do
640 # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
641 # OPTS="$OPTS,$OPTG";
642 #done
643 ##echo $OPTS
644 #
645 #for o in $(filloptionvalues $OPTS|tr ',' ' '); do
646 # echo testing if $METHOD accepts option $o
647 # touch $TF
648 # $SOCAT $opts $method:$TF,$o%- /dev/null,ignoreof </dev/null
649 # rm -f $TF
650 #done
651  
652 #------------------------------------------------------------------------------
653  
654 # test openssl connect
655  
656 #set -vx
657 if true; then
658 #if false; then
659 #opts="-s -d -d -d -d"
660 pid=$!
661 for addr in openssl; do
662 ADDR=$(echo "$addr" |tr a-z A-Z)
663 TEST="$ADDR accepts all its options"
664 echo "### $TEST"
665 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
666 # echo OPTGROUPS=$OPTGROUPS
667 OPTS=
668 for g in $(echo $OPTGROUPS |tr ',' ' '); do
669 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
670 OPTS="$OPTS,$OPTG";
671 done
672 echo $OPTS
673 openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
674 pid=$!
675 sleep 1
676 #waittcp4port $PORT
677 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
678 echo "testing if $ADDR accepts option $o"
679 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
680 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
681 done
682 kill $pid
683 done
684 kill $pid 2>/dev/null
685 opts=
686 PORT=$((PORT+1))
687 fi
688  
689 #------------------------------------------------------------------------------
690  
691 # test proxy connect
692  
693 #set -vx
694 if true; then
695 #if false; then
696 #opts="-s -d -d -d -d"
697 pid=$!
698 for addr in proxy; do
699 ADDR=$(echo "$addr" |tr a-z A-Z)
700 TEST="$ADDR accepts all its options"
701 echo "### $TEST"
702 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
703 # echo OPTGROUPS=$OPTGROUPS
704 OPTS=
705 for g in $(echo $OPTGROUPS |tr ',' ' '); do
706 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
707 OPTS="$OPTS,$OPTG";
708 done
709 echo $OPTS
710 # prepare dummy server
711 $SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/bin/bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
712 pid=$!
713 sleep 1
714 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
715 echo "testing if $ADDR accepts option $o"
716 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
717 $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
718 done
719 kill $pid 2>/dev/null
720 done
721 kill $pid 2>/dev/null
722 opts=
723 PORT=$((PORT+2))
724 fi
725  
726 #------------------------------------------------------------------------------
727  
728 # test tcp4
729  
730 #set -vx
731 if true; then
732 #if false; then
733 #opts="-s -d -d -d -d"
734 $SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
735 pid=$!
736 for addr in tcp4; do
737 ADDR=$(echo "$addr" |tr a-z A-Z)
738 TEST="$ADDR accepts all its options"
739 echo "### $TEST"
740 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
741 # echo OPTGROUPS=$OPTGROUPS
742 OPTS=
743 for g in $(echo $OPTGROUPS |tr ',' ' '); do
744 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
745 OPTS="$OPTS,$OPTG";
746 done
747 echo $OPTS
748 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
749 echo "testing if $ADDR accepts option $o"
750 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
751 done
752 done
753 kill $pid 2>/dev/null
754 opts=
755 PORT=$((PORT+1))
756 fi
757  
758 #------------------------------------------------------------------------------
759  
760 # test udp4-connect
761  
762 #set -vx
763 if true; then
764 #if false; then
765 #opts="-s -d -d -d -d"
766 $SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
767 pid=$!
768 for addr in udp4-connect; do
769 ADDR=$(echo "$addr" |tr a-z A-Z)
770 TEST="$ADDR accepts all its options"
771 echo "### $TEST"
772 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
773 # echo OPTGROUPS=$OPTGROUPS
774 OPTS=
775 for g in $(echo $OPTGROUPS |tr ',' ' '); do
776 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
777 OPTS="$OPTS,$OPTG";
778 done
779 echo $OPTS
780 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
781 echo "testing if $ADDR accepts option $o"
782 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
783 done
784 done
785 kill $pid 2>/dev/null
786 opts=
787 PORT=$((PORT+1))
788 fi
789  
790 #------------------------------------------------------------------------------
791  
792 # test tcp4-listen
793  
794 #set -vx
795 if true; then
796 #if false; then
797 #opts="-s -d -d -d -d"
798 for addr in tcp4-listen; do
799 ADDR=$(echo "$addr" |tr a-z A-Z)
800 TEST="$ADDR accepts all its options"
801 echo "### $TEST"
802 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
803 OPTS=
804 for g in $(echo $OPTGROUPS |tr ',' ' '); do
805 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
806 OPTS="$OPTS,$OPTG";
807 done
808 echo $OPTS
809 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
810 echo "testing if $ADDR accepts option $o"
811 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
812 pid=$!
813 $SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
814 kill $pid 2>/dev/null
815 done
816 done
817 opts=
818 PORT=$((PORT+1))
819 fi
820  
821 #------------------------------------------------------------------------------
822  
823 # test udp4-listen
824  
825 #set -vx
826 if true; then
827 #if false; then
828 #opts="-s -d -d -d -d"
829 for addr in udp4-listen; do
830 ADDR=$(echo "$addr" |tr a-z A-Z)
831 TEST="$ADDR accepts all its options"
832 echo "### $TEST"
833 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
834 OPTS=
835 for g in $(echo $OPTGROUPS |tr ',' ' '); do
836 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
837 OPTS="$OPTS,$OPTG";
838 done
839 echo $OPTS
840 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
841 echo "testing if $ADDR accepts option $o"
842 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
843 pid=$!
844 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
845 kill $pid 2>/dev/null
846 done
847 done
848 opts=
849 PORT=$((PORT+1))
850 fi
851  
852 #------------------------------------------------------------------------------
853  
854 # test udp4-sendto
855  
856 #set -vx
857 if true; then
858 #if false; then
859 #opts="-s -d -d -d -d"
860 $SOCAT $opts udp4-recv:$PORT,fork,$o echo </dev/null &
861 pid=$!
862 for addr in udp4-sendto; do
863 ADDR=$(echo "$addr" |tr a-z A-Z)
864 TEST="$ADDR accepts all its options"
865 echo "### $TEST"
866 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
867 # echo OPTGROUPS=$OPTGROUPS
868 OPTS=
869 for g in $(echo $OPTGROUPS |tr ',' ' '); do
870 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
871 OPTS="$OPTS,$OPTG";
872 done
873 echo $OPTS
874 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
875 echo "testing if $ADDR accepts option $o"
876 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
877 done
878 done
879 kill $pid 2>/dev/null
880 opts=
881 PORT=$((PORT+1))
882 fi
883  
884 #------------------------------------------------------------------------------
885  
886 # test udp4-datagram
887  
888 #set -vx
889 if true; then
890 #if false; then
891 #opts="-s -d -d -d -d"
892 #$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
893 #pid=$!
894 for addr in udp4-datagram; do
895 ADDR=$(echo "$addr" |tr a-z A-Z)
896 TEST="$ADDR accepts all its options"
897 echo "### $TEST"
898 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
899 # echo OPTGROUPS=$OPTGROUPS
900 OPTS=
901 for g in $(echo $OPTGROUPS |tr ',' ' '); do
902 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
903 OPTS="$OPTS,$OPTG";
904 done
905 echo $OPTS
906 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
907 echo "testing if $ADDR accepts option $o"
908 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
909 done
910 done
911 #kill $pid 2>/dev/null
912 opts=
913 PORT=$((PORT+1))
914 fi
915  
916 #------------------------------------------------------------------------------
917  
918 # test udp4-recv
919  
920 #set -vx
921 if true; then
922 #if false; then
923 #opts="-s -d -d -d -d"
924 for addr in udp4-recv; do
925 ADDR=$(echo "$addr" |tr a-z A-Z)
926 TEST="$ADDR accepts all its options"
927 echo "### $TEST"
928 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
929 OPTS=
930 for g in $(echo $OPTGROUPS |tr ',' ' '); do
931 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
932 OPTS="$OPTS,$OPTG";
933 done
934 echo $OPTS
935 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
936 echo "testing if $ADDR accepts option $o"
937 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
938 pid=$!
939 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
940 kill $pid 2>/dev/null
941 done
942 done
943 opts=
944 PORT=$((PORT+1))
945 fi
946  
947 #------------------------------------------------------------------------------
948  
949 # test udp4-recvfrom
950  
951 #set -vx
952 if true; then
953 #if false; then
954 #opts="-s -d -d -d -d"
955 for addr in udp4-recvfrom; do
956 ADDR=$(echo "$addr" |tr a-z A-Z)
957 TEST="$ADDR accepts all its options"
958 echo "### $TEST"
959 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
960 OPTS=
961 for g in $(echo $OPTGROUPS |tr ',' ' '); do
962 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
963 OPTS="$OPTS,$OPTG";
964 done
965 echo $OPTS
966 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
967 echo "testing if $ADDR accepts option $o"
968 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
969 pid=$!
970 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
971 kill $pid 2>/dev/null
972 done
973 done
974 opts=
975 PORT=$((PORT+1))
976 fi
977  
978 #------------------------------------------------------------------------------
979  
980 # test ip4-sendto
981  
982 #set -vx
983 if true; then
984 #if false; then
985 #opts="-s -d -d -d -d"
986 $SOCAT $opts ip4-recv:$PORT,fork,$o echo </dev/null &
987 pid=$!
988 for addr in ip4-sendto; do
989 ADDR=$(echo "$addr" |tr a-z A-Z)
990 TEST="$ADDR accepts all its options"
991 echo "### $TEST"
992 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
993 # echo OPTGROUPS=$OPTGROUPS
994 OPTS=
995 for g in $(echo $OPTGROUPS |tr ',' ' '); do
996 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
997 OPTS="$OPTS,$OPTG";
998 done
999 echo $OPTS
1000 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1001 echo "testing if $ADDR accepts option $o"
1002 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
1003 done
1004 done
1005 kill $pid 2>/dev/null
1006 opts=
1007 PORT=$((PORT+1))
1008 fi
1009  
1010 #------------------------------------------------------------------------------
1011  
1012 # test ip4-recv
1013  
1014 #set -vx
1015 if true; then
1016 #if false; then
1017 #opts="-s -d -d -d -d"
1018 for addr in ip4-recv; do
1019 ADDR=$(echo "$addr" |tr a-z A-Z)
1020 TEST="$ADDR accepts all its options"
1021 echo "### $TEST"
1022 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1023 OPTS=
1024 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1025 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1026 OPTS="$OPTS,$OPTG";
1027 done
1028 echo $OPTS
1029 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1030 echo "testing if $ADDR accepts option $o"
1031 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1032 pid=$!
1033 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1034 kill $pid 2>/dev/null
1035 done
1036 done
1037 opts=
1038 PORT=$((PORT+1))
1039 fi
1040  
1041 #------------------------------------------------------------------------------
1042  
1043 # test ip4-recvfrom
1044  
1045 #set -vx
1046 if true; then
1047 #if false; then
1048 #opts="-s -d -d -d -d"
1049 for addr in ip4-recvfrom; do
1050 ADDR=$(echo "$addr" |tr a-z A-Z)
1051 TEST="$ADDR accepts all its options"
1052 echo "### $TEST"
1053 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1054 OPTS=
1055 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1056 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1057 OPTS="$OPTS,$OPTG";
1058 done
1059 echo $OPTS
1060 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1061 echo "testing if $ADDR accepts option $o"
1062 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1063 pid=$!
1064 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1065 kill $pid 2>/dev/null
1066 done
1067 done
1068 opts=
1069 PORT=$((PORT+1))
1070 fi
1071  
1072 #------------------------------------------------------------------------------
1073  
1074 # test READLINE
1075  
1076 if true; then
1077 #if false; then
1078 #opts="-s -d -d -d -d"
1079 for addr in readline; do
1080 ADDR=$(echo "$addr" |tr a-z A-Z)
1081 TEST="$ADDR accepts all its options"
1082 echo "### $TEST"
1083 TS=$TD/script$N
1084 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1085 OPTS=
1086 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1087 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1088 OPTS="$OPTS,$OPTG";
1089 done
1090 #echo $OPTS
1091 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1092 # for o in bs0; do
1093 echo "testing if $ADDR accepts option $o"
1094 echo "$SOCAT $opts readline,$o /dev/null" >$TS
1095 chmod u+x $TS
1096 $SOCAT /dev/null,ignoreeof exec:$TS,pty
1097 #stty sane
1098 done
1099 #reset 1>&0 2>&0
1100 done
1101 opts=
1102 fi
1103  
1104 #------------------------------------------------------------------------------
1105  
1106 # unnamed pipe
1107 #if false; then
1108 if true; then
1109 for addr in pipe; do
1110 ADDR=$(echo "$addr" |tr a-z A-Z)
1111 TEST="unnamed $ADDR accepts all its options"
1112 echo "### $TEST"
1113 OPTGROUPS=$($SOCAT -? |egrep " $addr[^:]" |sed 's/.*=//')
1114 OPTS=
1115 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1116 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1117 OPTS="$OPTS,$OPTG";
1118 done
1119 #echo $OPTS
1120  
1121 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1122 echo testing if unnamed $ADDR accepts option $o
1123 $SOCAT $opts $addr,$o /dev/null </dev/null
1124 done
1125 done
1126 fi
1127  
1128 #------------------------------------------------------------------------------
1129  
1130 # test addresses on files
1131  
1132 N=1
1133 #if false; then
1134 if true; then
1135 for addr in create; do
1136 ADDR=$(echo "$addr" |tr a-z A-Z)
1137 TEST="$ADDR on new file accepts all its options"
1138 echo "### $TEST"
1139 TF=$TD/file$N
1140 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
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  
1148 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1149 echo testing if $ADDR accepts option $o
1150 rm -f $TF
1151 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1152 rm -f $TF
1153 done
1154 done
1155 fi
1156 #------------------------------------------------------------------------------
1157  
1158 #if false; then
1159 if true; then
1160 for addr in exec system; do
1161 ADDR=$(echo "$addr" |tr a-z A-Z)
1162  
1163 TEST="$ADDR with socketpair accepts all its options"
1164 echo "### $TEST"
1165 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1166 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g')
1167 OPTS=
1168 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1169 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1170 OPTS="$OPTS,$OPTG";
1171 done
1172 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1173 #echo $OPTS
1174 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1175 echo testing if $ADDR with socketpair accepts option $o
1176 $SOCAT $opts $addr:$TRUE,$o /dev/null,ignoreof </dev/null
1177 done
1178  
1179 TEST="$ADDR with pipes accepts all its options"
1180 echo "### $TEST"
1181 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1182 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1183 OPTS=
1184 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1185 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1186 OPTS="$OPTS,$OPTG";
1187 done
1188 # flock tends to hang, so dont test it
1189 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')
1190 #echo $OPTS
1191 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1192 echo testing if $ADDR with pipes accepts option $o
1193 $SOCAT $opts $addr:$TRUE,pipes,$o /dev/null,ignoreof </dev/null
1194 done
1195  
1196 TEST="$ADDR with pty accepts all its options"
1197 echo "### $TEST"
1198 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1199 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1200 OPTS=
1201 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1202 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1203 OPTS="$OPTS,$OPTG";
1204 done
1205 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1206 #echo $OPTS
1207 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1208 echo testing if $ADDR with pty accepts option $o
1209 $SOCAT $opts $addr:$TRUE,pty,$o /dev/null,ignoreof </dev/null
1210 done
1211  
1212 TEST="$ADDR with nofork accepts all its options"
1213 echo "### $TEST"
1214 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1215 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,PTY,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1216 OPTS=
1217 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1218 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1219 OPTS="$OPTS,$OPTG";
1220 done
1221 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1222 #echo $OPTS
1223 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1224 echo testing if $ADDR with nofork accepts option $o
1225 $SOCAT /dev/null $opts $addr:$TRUE,nofork,$o </dev/null
1226 done
1227  
1228 done
1229 fi
1230  
1231 #------------------------------------------------------------------------------
1232  
1233 #if false; then
1234 if true; then
1235 for addr in fd; do
1236 ADDR=$(echo "$addr" |tr a-z A-Z)
1237 TEST="$ADDR accepts all its options"
1238 echo "### $TEST"
1239 TF=$TD/file$N
1240 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1241 OPTS=
1242 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1243 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1244 OPTS="$OPTS,$OPTG";
1245 done
1246 #echo $OPTS
1247 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1248 echo "testing if $ADDR (to file) accepts option $o"
1249 rm -f $TF
1250 $SOCAT $opts -u /dev/null $addr:3,$o 3>$TF
1251 done
1252 done
1253 fi
1254  
1255 #------------------------------------------------------------------------------
1256  
1257 # test OPEN address
1258  
1259 #! test it on pipe, device, new file
1260  
1261 N=1
1262 #if false; then
1263 if true; then
1264 for addr in open; do
1265 ADDR=$(echo "$addr" |tr a-z A-Z)
1266 TEST="$ADDR on file accepts all its options"
1267 echo "### $TEST"
1268 TF=$TD/file$N
1269 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1270 OPTS=
1271 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1272 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1273 OPTS="$OPTS,$OPTG";
1274 done
1275 #echo $OPTS
1276 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1277 echo testing if $ADDR on file accepts option $o
1278 touch $TF
1279 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1280 rm -f $TF
1281 done
1282 done
1283 fi
1284  
1285 #------------------------------------------------------------------------------
1286  
1287 # test GOPEN address on files, sockets, pipes, devices
1288  
1289 N=1
1290 #if false; then
1291 if true; then
1292 for addr in gopen; do
1293 ADDR=$(echo "$addr" |tr a-z A-Z)
1294  
1295 TEST="$ADDR on new file accepts all its options"
1296 echo "### $TEST"
1297 TF=$TD/file$N
1298 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1299 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1300 OPTS=
1301 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1302 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1303 OPTS="$OPTS,$OPTG";
1304 done
1305 #echo $OPTS
1306 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1307 echo testing if $ADDR on new file accepts option $o
1308 rm -f $TF
1309 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1310 rm -f $TF
1311 done
1312  
1313 TEST="$ADDR on existing file accepts all its options"
1314 echo "### $TEST"
1315 TF=$TD/file$N
1316 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1317 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1318 OPTS=
1319 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1320 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1321 OPTS="$OPTS,$OPTG";
1322 done
1323 #echo $OPTS
1324 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1325 echo testing if $ADDR on existing file accepts option $o
1326 rm -f $TF; touch $TF
1327 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1328 rm -f $TF
1329 done
1330  
1331 TEST="$ADDR on existing pipe accepts all its options"
1332 echo "### $TEST"
1333 TF=$TD/pipe$N
1334 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1335 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1336 OPTS=
1337 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1338 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1339 OPTS="$OPTS,$OPTG";
1340 done
1341 #echo $OPTS
1342 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1343 echo testing if $ADDR on named pipe accepts option $o
1344 rm -f $TF; mkfifo $TF
1345 $SOCAT $opts $addr:$TF,$o,nonblock /dev/null </dev/null
1346 rm -f $TF
1347 done
1348  
1349 TEST="$ADDR on existing socket accepts all its options"
1350 echo "### $TEST"
1351 TF=$TD/sock$N
1352 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1353 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1354 OPTS=
1355 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1356 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1357 OPTS="$OPTS,$OPTG";
1358 done
1359 #echo $OPTS
1360 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1361 echo testing if $ADDR on socket accepts option $o
1362 rm -f $TF; $SOCAT - UNIX-L:$TF & pid=$!
1363 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1364 kill $pid 2>/dev/null
1365 rm -f $TF
1366 done
1367  
1368 if [ $(id -u) -eq 0 ]; then
1369 TEST="$ADDR on existing device accepts all its options"
1370 echo "### $TEST"
1371 TF=$TD/null
1372 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1373 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1374 OPTS=
1375 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1376 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1377 OPTS="$OPTS,$OPTG";
1378 done
1379 #echo $OPTS
1380 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1381 echo testing if $ADDR on existing device accepts option $o
1382 rm -f $TF; mknod $TF c 1 3
1383 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1384 done
1385 else
1386 TEST="$ADDR on existing device accepts all its options"
1387 echo "### $TEST"
1388 TF=/dev/null
1389 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1390 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1391 OPTS=
1392 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1393 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1394 OPTS="$OPTS,$OPTG";
1395 done
1396 #echo $OPTS
1397 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1398 echo testing if $ADDR on existing device accepts option $o
1399 $SOCAT $opts $addr:$TF,$o%- /dev/null,ignoreof </dev/null
1400 done
1401 fi
1402  
1403 done
1404 fi
1405  
1406 #------------------------------------------------------------------------------
1407  
1408 # test named pipe
1409  
1410 N=1
1411 #if false; then
1412 if true; then
1413 for addr in pipe; do
1414 ADDR=$(echo "$addr" |tr a-z A-Z)
1415 TEST="$ADDR on file accepts all its options"
1416 echo "### $TEST"
1417 TF=$TD/pipe$N
1418 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1419 OPTS=
1420 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1421 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1422 OPTS="$OPTS,$OPTG";
1423 done
1424 #echo $OPTS
1425  
1426 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1427 echo testing if named $ADDR accepts option $o
1428 rm -f $TF
1429 # blocks with rdonly, wronly
1430 case "$o" in rdonly|wronly) o="$o,nonblock" ;; esac
1431 $SOCAT $opts $addr:$TF,$o /dev/null </dev/null
1432 rm -f $TF
1433 done
1434 done
1435 fi
1436 #------------------------------------------------------------------------------
1437  
1438 # test STDIO
1439  
1440 #! test different stream types
1441  
1442 #if false; then
1443 if true; then
1444 for addr in stdio; do
1445 ADDR=$(echo "$addr" |tr a-z A-Z)
1446 TEST="$ADDR accepts all its options"
1447 echo "### $TEST"
1448 OPTGROUPS=$($SOCAT -? |fgrep " $addr" |sed 's/.*=//')
1449 OPTS=
1450 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1451 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1452 OPTS="$OPTS,$OPTG";
1453 done
1454 #echo $OPTS
1455  
1456 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1457 echo "testing if $ADDR (/dev/null, stdout) accepts option $o"
1458 $SOCAT $opts $addr,$o /dev/null,ignoreof </dev/null
1459 done
1460 done
1461 fi
1462  
1463 #------------------------------------------------------------------------------
1464  
1465 # test STDIN
1466  
1467 #if false; then
1468 if true; then
1469 for addr in stdin; do
1470 ADDR=$(echo "$addr" |tr a-z A-Z)
1471 TEST="$ADDR accepts all its options"
1472 echo "### $TEST"
1473 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1474 OPTS=
1475 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1476 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1477 OPTS="$OPTS,$OPTG";
1478 done
1479 #echo $OPTS
1480  
1481 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1482 echo "testing if $ADDR (/dev/null) accepts option $o"
1483 $SOCAT $opts -u $addr,$o /dev/null </dev/null
1484 done
1485 done
1486 fi
1487  
1488 #------------------------------------------------------------------------------
1489  
1490 # test STDOUT, STDERR
1491  
1492 if true; then
1493 #if false; then
1494 for addr in stdout stderr; do
1495 ADDR=$(echo "$addr" |tr a-z A-Z)
1496 TEST="$ADDR accepts all its options"
1497 echo "### $TEST"
1498 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1499 OPTS=
1500 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1501 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1502 OPTS="$OPTS,$OPTG";
1503 done
1504 #echo $OPTS
1505 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1506 echo "testing if $ADDR accepts option $o"
1507 $SOCAT $opts -u /dev/null $addr,$o
1508 done
1509 done
1510 fi
1511  
1512 #------------------------------------------------------------------------------
1513 # REQUIRES ROOT
1514  
1515 if [ "$withroot" ]; then
1516 for addr in ip4; do
1517 ADDR=$(echo "$addr" |tr a-z A-Z)
1518 TEST="$ADDR accepts all its options"
1519 echo "### $TEST"
1520 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
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 accepts option $o"
1529 $SOCAT $opts $addr:127.0.0.1:200 /dev/null,ignoreof </dev/null
1530 done
1531 done
1532 fi
1533  
1534 #------------------------------------------------------------------------------
1535 # REQUIRES ROOT
1536  
1537 if [ "$withroot" ]; then
1538 for addr in ip6; do
1539 ADDR=$(echo "$addr" |tr a-z A-Z)
1540 TEST="$ADDR accepts all its options"
1541 echo "### $TEST"
1542 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1543 OPTS=
1544 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1545 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1546 OPTS="$OPTS,$OPTG";
1547 done
1548 #echo $OPTS
1549 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1550 echo "testing if $ADDR accepts option $o"
1551 $SOCAT $opts $addr:[::1]:200 /dev/null,ignoreof </dev/null
1552 done
1553 done
1554 fi
1555  
1556 #==============================================================================
1557  
1558 #TEST="stdio accepts all options of GROUP_ANY"
1559 #echo "### $TEST"
1560 #CMD="$SOCAT $opts -,$OPTS_ANY /dev/null"
1561 #$CMD
1562 #if [ $? = 0 ]; then
1563 # echo "... test $N ($TEST) succeeded"
1564 ## echo "CMD=$CMD"
1565 #else
1566 # echo "*** test $N ($TEST) FAILED"
1567 # echo "CMD=$CMD"
1568 #fi
1569 #
1570 #N=$((N+1))
1571 ##------------------------------------------------------------------------------
1572 #
1573 #TEST="exec accepts all options of GROUP_ANY and GROUP_SOCKET"
1574 #echo "### $TEST"
1575 #CMD="$SOCAT $opts exec:$TRUE,$OPTS_ANY,$OPTS_SOCKET /dev/null"
1576 #$CMD
1577 #if [ $? = 0 ]; then
1578 # echo "... test $N ($TEST) succeeded"
1579 ## echo "CMD=$CMD"
1580 #else
1581 # echo "*** test $N ($TEST) FAILED"
1582 # echo "CMD=$CMD"
1583 #fi
1584  
1585 #------------------------------------------------------------------------------
1586  
1587 esac
1588  
1589 #==============================================================================
1590  
1591 N=1
1592 numOK=0
1593 numFAIL=0
1594 numCANT=0
1595 listFAIL=
1596  
1597 #==============================================================================
1598 # test if selected socat features work ("FUNCTIONS")
1599  
1600 testecho () {
1601 #set -vx
1602 local N="$1"
1603 local title="$2"
1604 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1605 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1606 local opts="$5"
1607 local T="$6"; [ -z "$T" ] && T=0; export T
1608 local tf="$td/test$N.stdout"
1609 local te="$td/test$N.stderr"
1610 local tdiff="$td/test$N.diff"
1611 local da="test$N $(date) $RANDOM"
1612 if ! eval $NUMCOND; then :; else
1613 #local cmd="$TRACE $SOCAT $opts $arg1 $arg2"
1614 #$ECHO "testing $title (test $N)... \c"
1615 $PRINTF "test $F_n %s... " $N "$title"
1616 #echo "$da" |$cmd >"$tf" 2>"$te"
1617 (psleep $T; echo "$da"; psleep $T) |($TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $? >"$td/test$N.rc") &
1618 export rc1=$!
1619 #sleep 5 && kill $rc1 2>/dev/null &
1620 # rc2=$!
1621 wait $rc1
1622 # kill $rc2 2>/dev/null
1623 if [ "$(cat "$td/test$N.rc")" != 0 ]; then
1624 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1625 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1626 cat "$te"
1627 numFAIL=$((numFAIL+1))
1628 listFAIL="$listFAIL $N"
1629 elif echo "$da" |diff - "$tf" >"$tdiff" 2>&1; then
1630 $PRINTF "$OK\n"
1631 if [ -n "$debug" ]; then cat $te; fi
1632 numOK=$((numOK+1))
1633 else
1634 $PRINTF "$FAILED:\n"
1635 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1636 cat "$te"
1637 echo diff:
1638 cat "$tdiff"
1639 numFAIL=$((numFAIL+1))
1640 listFAIL="$listFAIL $N"
1641 fi
1642 fi # NUMCOND
1643 set +vx
1644 }
1645  
1646  
1647 # special function for use with the test address of socat V2 chains
1648 testchain () {
1649 local N="$1"
1650 local title="$2"
1651 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1652 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1653 local opts="$5"
1654 local suffix="$6" # what is to be appended by tests
1655 local T="$7"; [ -z "$T" ] && T=0; export T
1656 local tf="$td/test$N.stdout"
1657 local te="$td/test$N.stderr"
1658 local tdiff="$td/test$N.diff"
1659 local da="$(date)"
1660 if ! eval $NUMCOND; then :; else
1661 $PRINTF "test $F_n %s... " $N "$title"
1662 (echo "$da"; rsleep $T) |$SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te" &
1663 export pid1=$!
1664 wait $pid1
1665 if [ "$?" != 0 ]; then
1666 $PRINTF "$FAILED: $SOCAT:\n"
1667 echo "$SOCAT $opts $arg1 $arg2"
1668 cat "$te"
1669 numFAIL=$((numFAIL+1))
1670 listFAIL="$listFAIL $N"
1671 elif echo -e "$da\n$suffix\c" |diff - "$tf" >"$tdiff" 2>&1; then
1672 $PRINTF "$OK\n"
1673 if [ -n "$debug" ]; then cat $te; fi
1674 numOK=$((numOK+1))
1675 else
1676 $PRINTF "$FAILED:\n"
1677 echo "$SOCAT $opts $arg1 $arg2"
1678 cat "$te"
1679 echo diff:
1680 cat "$tdiff"
1681 numFAIL=$((numFAIL+1))
1682 listFAIL="$listFAIL $N"
1683 fi
1684 fi # NUMCOND
1685 }
1686  
1687  
1688 # test if call to od and throughput of data works - with graceful shutdown and
1689 # flush of od buffers
1690 testod () {
1691 local num="$1"
1692 local title="$2"
1693 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1694 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1695 local opts="$5"
1696 local T="$6"; [ -z "$T" ] && T=0; export T
1697 local tf="$td/test$N.stdout"
1698 local te="$td/test$N.stderr"
1699 local tr="$td/test$N.ref"
1700 local tdiff="$td/test$N.diff"
1701 local dain="$(date) $RANDOM"
1702 if ! eval $NUMCOND; then :; else
1703 echo "$dain" |$OD_C >"$tr"
1704 # local daout="$(echo "$dain" |$OD_C)"
1705 $PRINTF "test $F_n %s... " $num "$title"
1706 (psleep $T; echo "$dain"; psleep $T) |$TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"
1707 if [ "$?" != 0 ]; then
1708 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1709 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1710 cat "$te"
1711 numFAIL=$((numFAIL+1))
1712 listFAIL="$listFAIL $N"
1713 # elif echo "$daout" |diff - "$tf" >"$tdiff" 2>&1; then
1714 elif diff "$tr" "$tf" >"$tdiff" 2>&1; then
1715 $PRINTF "$OK\n"
1716 if [ -n "$debug" ]; then cat $te; fi
1717 numOK=$((numOK+1))
1718 else
1719 $PRINTF "$FAILED: diff:\n"
1720 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1721 cat "$te"
1722 cat "$tdiff"
1723 numFAIL=$((numFAIL+1))
1724 listFAIL="$listFAIL $N"
1725 fi
1726 fi # NUMCOND
1727 }
1728  
1729 # test if the socat executable has these address types compiled in
1730 # print the first missing address type
1731 testaddrs () {
1732 local a A;
1733 for a in $@; do
1734 A=$(echo "$a" |tr 'a-z-' 'A-Z_')
1735 if $TRACE $SOCAT -V |grep "#define WITH_$A 1\$" >/dev/null; then
1736 shift
1737 continue
1738 fi
1739 echo "$a"
1740 return 1
1741 done
1742 return 0
1743 }
1744  
1745 # test if the socat executable has these options compiled in
1746 # print the first missing option
1747 testoptions () {
1748 local a A;
1749 for a in $@; do
1750 A=$(echo "$a" |tr 'a-z' 'A-Z')
1751 if $SOCAT -??? |grep "[^a-z0-9-]$a[^a-z0-9-]" >/dev/null; then
1752 shift
1753 continue
1754 fi
1755 echo "$a"
1756 return 1
1757 done
1758 return 0
1759 }
1760  
1761 # check if the given pid exists and has child processes
1762 # if yes: prints child process lines to stdout, returns 0
1763 # if not: prints ev.message to stderr, returns 1
1764 childprocess () {
1765 local l
1766 case "$UNAME" in
1767 AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;;
1768 FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;;
1769 HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1770 Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1771 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)")" ;;
1772 NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1773 OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)")" ;;
1774 SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1775 DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1776 CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]")" ;;
1777 *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]**[ ][ ]*$(printf %5u $1) ")" ;; esac
1778 if [ -z "$l" ]; then
1779 return 1;
1780 fi
1781 echo "$l"
1782 return 0
1783 }
1784  
1785 # check if the given process line refers to a defunct (zombie) process
1786 # yes: returns 0
1787 # no: returns 1
1788 isdefunct () {
1789 local l
1790 case "$UNAME" in
1791 AIX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1792 FreeBSD) l="$(echo "$1" |grep ' <defunct>$')" ;;
1793 HP-UX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1794 Linux) l="$(echo "$1" |grep ' <defunct>$')" ;;
1795 SunOS) l="$(echo "$1" |grep ' <defunct>$')" ;;
1796 DragonFly)l="$(echo "$1" |grep ' <defunct>$')" ;;
1797 *) l="$(echo "$1" |grep ' <defunct>$')" ;;
1798 esac
1799 [ -n "$l" ];
1800 }
1801  
1802 # check if UNIX socket protocol is available on host
1803 runsunix () {
1804 return 0;
1805 $TRACE $SOCAT /dev/null UNIX-LISTEN:"$td/unix.socket" 2>"$td/unix.stderr" &
1806 pid=$!
1807 usleep $MICROS
1808 kill "$pid" 2>/dev/null
1809 test ! -s "$td/unix.stderr"
1810 }
1811  
1812 unset HAVENOT_IP4
1813 # check if an IP4 loopback interface exists
1814 runsip4 () {
1815 [ -n "$HAVENOT_IP4" ] && return $HAVENOT_IP4
1816 local l
1817 case "$UNAME" in
1818 AIX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1819 FreeBSD) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1820 HP-UX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1821 Linux) l=$($IFCONFIG |egrep 'inet (addr:)?127\.0\.0\.1 ') ;;
1822 NetBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1823 OpenBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1824 OSF1) l=$($IFCONFIG -a |grep ' inet ') ;;
1825 SunOS) l=$($IFCONFIG -a |grep 'inet ') ;;
1826 Darwin)l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1827 DragonFly)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1828 CYGWIN*) l=$(ipconfig |grep IPv4);;
1829 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1830 esac
1831 [ -z "$l" ] && return 1
1832 # existence of interface might not suffice, check for routeability:
1833 case "$UNAME" in
1834 Darwin) ping -c 1 127.0.0.1; l="$?" ;;
1835 Linux) ping -c 1 127.0.0.1; l="$?" ;;
1836 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1837 esac
1838 HAVENOT_IP4=$l
1839 return $l;
1840 }
1841  
1842 unset HAVENOT_IP6
1843 # check if an IP6 loopback interface exists
1844 runsip6 () {
1845 [ -n "$HAVENOT_IP6" ] && return $HAVENOT_IP6
1846 local l
1847 case "$UNAME" in
1848 AIX) l=$($IFCONFIG lo0 |grep 'inet6 ::1/0') ;;
1849 HP-UX) l=$($IFCONFIG lo0 |grep ' inet6 ') ;;
1850 Linux) l=$($IFCONFIG |egrep 'inet6 (addr: )?::1/?') ;;
1851 NetBSD)l=$($IFCONFIG -a |grep 'inet6 ::1 ');;
1852 OSF1) l=$($IFCONFIG -a |grep ' inet6 ') ;;
1853 SunOS) l=$($IFCONFIG -a |grep 'inet6 ') ;;
1854 Darwin)l=$($IFCONFIG lo0 |grep 'inet6 ::1 ') ;;
1855 CYGWIN*) l=$(ipconfig |grep IPv6);;
1856 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1857 esac
1858 [ -z "$l" ] && return 1
1859 # existence of interface might not suffice, check for routeability:
1860 case "$UNAME" in
1861 Darwin) ping6 -c 1 ::1; l="$?" ;;
1862 Linux) ping6 -c 1 ::1; l="$?" ;;
1863 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1864 esac
1865 HAVENOT_IP6=$l
1866 return $l;
1867 }
1868  
1869 # check if TCP on IPv4 is available on host
1870 runstcp4 () {
1871 return 0;
1872 # PORT="$1"
1873 $TRACE $SOCAT /dev/null TCP4-LISTEN:$PORT 2>"$td/tcp4.stderr" &
1874 pid=$!
1875 usleep $MICROS
1876 kill "$pid" 2>/dev/null
1877 wait
1878 usleep $MICROS
1879 test ! -s "$td/tcp4.stderr"
1880 }
1881  
1882 # check if TCP on IPv6 is available on host
1883 runstcp6 () {
1884 return 0;
1885 # PORT="$1"
1886 $TRACE $SOCAT /dev/null TCP6-LISTEN:$PORT 2>"$td/tcp6.stderr" &
1887 pid=$!
1888 usleep $MICROS
1889 kill "$pid" 2>/dev/null
1890 wait
1891 usleep $MICROS
1892 test ! -s "$td/tcp6.stderr"
1893 }
1894  
1895 # check if UDP on IPv4 is available on host
1896 runsudp4 () {
1897 return 0;
1898 # PORT="$1"
1899 $TRACE $SOCAT /dev/null UDP4-LISTEN:$PORT 2>"$td/udp4.stderr" &
1900 pid=$!
1901 usleep $MICROS
1902 kill "$pid" 2>/dev/null
1903 wait
1904 usleep $MICROS
1905 test ! -s "$td/udp4.stderr"
1906 }
1907  
1908 # check if UDP on IPv6 is available on host
1909 runsudp6 () {
1910 return 0;
1911 # PORT="$1"
1912 $TRACE $SOCAT /dev/null UDP6-LISTEN:$PORT 2>"$td/udp6.stderr" &
1913 pid=$!
1914 usleep $MICROS
1915 kill "$pid" 2>/dev/null
1916 wait
1917 usleep $MICROS
1918 test ! -s "$td/udp6.stderr"
1919 }
1920  
1921 # check if SCTP on IPv4 is available on host
1922 runssctp4 () {
1923 #PORT="$1"
1924 $TRACE $SOCAT /dev/null SCTP4-LISTEN:$PORT 2>"$td/sctp4.stderr" &
1925 pid=$!
1926 usleep $MICROS
1927 kill "$pid" 2>/dev/null
1928 wait
1929 usleep $MICROS
1930 test ! -s "$td/sctp4.stderr"
1931 }
1932  
1933 # check if SCTP on IPv6 is available on host
1934 runssctp6 () {
1935 #PORT="$1"
1936 $TRACE $SOCAT /dev/null SCTP6-LISTEN:$PORT 2>"$td/sctp6.stderr" &
1937 pid=$!
1938 usleep $MICROS
1939 kill "$pid" 2>/dev/null
1940 wait
1941 usleep $MICROS
1942 test ! -s "$td/sctp6.stderr"
1943 }
1944  
1945 # wait until an IP4 protocol is ready
1946 waitip4proto () {
1947 local proto="$1"
1948 local logic="$2" # 0..wait until free; 1..wait until listening
1949 local timeout="$3"
1950 local l
1951 [ "$logic" ] || logic=1
1952 [ "$timeout" ] || timeout=5
1953 while [ $timeout -gt 0 ]; do
1954 case "$UNAME" in
1955 Linux) l=$(netstat -n -w -l |grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*') ;;
1956 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
1957 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1958 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1959 # Darwin) case "$(uname -r)" in
1960 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
1961 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
1962 # esac ;;
1963 AIX) # does not seem to show raw sockets in netstat
1964 sleep 1; return 0 ;;
1965 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
1966 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
1967 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
1968 *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
1969 sleep 1; return 0 ;;
1970 esac
1971 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
1972 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
1973 sleep 1
1974 timeout=$((timeout-1))
1975 done
1976  
1977 $ECHO "!protocol $proto timed out! \c" >&2
1978 return 1
1979 }
1980  
1981 # we need this misleading function name for canonical reasons
1982 waitip4port () {
1983 waitip4proto "$1" "$2" "$3"
1984 }
1985  
1986 # wait until an IP6 protocol is ready
1987 waitip6proto () {
1988 local proto="$1"
1989 local logic="$2" # 0..wait until free; 1..wait until listening
1990 local timeout="$3"
1991 local l
1992 [ "$logic" ] || logic=1
1993 [ "$timeout" ] || timeout=5
1994 while [ $timeout -gt 0 ]; do
1995 case "$UNAME" in
1996 Linux) l=$(netstat -n -w -l |grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*') ;;
1997 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
1998 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1999 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2000 # Darwin) case "$(uname -r)" in
2001 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
2002 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
2003 # esac ;;
2004 AIX) # does not seem to show raw sockets in netstat
2005 sleep 1; return 0 ;;
2006 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
2007 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
2008 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
2009 *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;;
2010 sleep 1; return 0 ;;
2011 esac
2012 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2013 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2014 sleep 1
2015 timeout=$((timeout-1))
2016 done
2017  
2018 $ECHO "!protocol $proto timed out! \c" >&2
2019 return 1
2020 }
2021  
2022 # we need this misleading function name for canonical reasons
2023 waitip6port () {
2024 waitip6proto "$1" "$2" "$3"
2025 }
2026  
2027 # check if a TCP4 port is in use
2028 # exits with 0 when it is not used
2029 checktcp4port () {
2030 local port="$1"
2031 local l
2032 case "$UNAME" in
2033 Linux) l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN') ;;
2034 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2035 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2036 Darwin) case "$(uname -r)" in
2037 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2038 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2039 esac ;;
2040 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2041 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2042 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2043 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2044 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2045 DragonFly)l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2046 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2047 esac
2048 [ -z "$l" ] && return 0
2049 return 1
2050 }
2051  
2052 # wait until a TCP4 listen port is ready
2053 waittcp4port () {
2054 local port="$1"
2055 local logic="$2" # 0..wait until free; 1..wait until listening
2056 local timeout="$3"
2057 local l
2058 [ "$logic" ] || logic=1
2059 [ "$timeout" ] || timeout=5
2060 while [ $timeout -gt 0 ]; do
2061 case "$UNAME" in
2062 Linux) l=$(netstat -a -n -t -l |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN') ;;
2063 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2064 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2065 Darwin) case "$(uname -r)" in
2066 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2067 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2068 esac ;;
2069 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2070 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2071 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2072 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2073 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2074 DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2075 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2076 esac
2077 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2078 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2079 sleep 1
2080 timeout=$((timeout-1))
2081 done
2082  
2083 $ECHO "!port $port timed out! \c" >&2
2084 return 1
2085 }
2086  
2087 # wait until a UDP4 port is ready
2088 waitudp4port () {
2089 local port="$1"
2090 local logic="$2" # 0..wait until free; 1..wait until listening
2091 local timeout="$3"
2092 local l
2093 [ "$logic" ] || logic=1
2094 [ "$timeout" ] || timeout=5
2095 while [ $timeout -gt 0 ]; do
2096 case "$UNAME" in
2097 Linux) l=$(netstat -a -n -u -l |grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*') ;;
2098 FreeBSD) l=$(netstat -an |egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;;
2099 NetBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2100 OpenBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2101 Darwin) case "$(uname -r)" in
2102 [1-5]*) l=$(netstat -an |grep '^udp.* .*[0-9*]\.'$port' .* \*\.\*') ;;
2103 *) l=$(netstat -an |grep '^udp4.* .*[0-9*]\.'$port' .* \*\.\* .*') ;;
2104 esac ;;
2105 AIX) l=$(netstat -an |grep '^udp[4 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2106 SunOS) l=$(netstat -an -f inet -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2107 HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
2108 OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2109 DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2110 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2111 esac
2112 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2113 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2114 sleep 1
2115 timeout=$((timeout-1))
2116 done
2117  
2118 $ECHO "!port $port timed out! \c" >&2
2119 return 1
2120 }
2121  
2122 # wait until an SCTP4 listen port is ready
2123 waitsctp4port () {
2124 local port="$1"
2125 local logic="$2" # 0..wait until free; 1..wait until listening
2126 local timeout="$3"
2127 local l
2128 [ "$logic" ] || logic=1
2129 [ "$timeout" ] || timeout=5
2130 while [ $timeout -gt 0 ]; do
2131 case "$UNAME" in
2132 Linux) l=$(netstat -n -a |grep '^sctp .* .*[0-9*]:'$port' .* LISTEN') ;;
2133 # FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2134 # NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2135 # Darwin) case "$(uname -r)" in
2136 # [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2137 # *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2138 # esac ;;
2139 # AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2140 SunOS) l=$(netstat -an -f inet -P sctp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2141 # HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2142 # OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2143 # CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2144 *) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
2145 esac
2146 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2147 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2148 sleep 1
2149 timeout=$((timeout-1))
2150 done
2151  
2152 $ECHO "!port $port timed out! \c" >&2
2153 return 1
2154 }
2155  
2156 # wait until a tcp6 listen port is ready
2157 waittcp6port () {
2158 local port="$1"
2159 local logic="$2" # 0..wait until free; 1..wait until listening
2160 local timeout="$3"
2161 local l
2162 [ "$logic" ] || logic=1
2163 [ "$timeout" ] || timeout=5
2164 while [ $timeout -gt 0 ]; do
2165 case "$UNAME" in
2166 Linux) l=$(netstat -an |grep -E '^tcp6? .* [0-9a-f:]*:'$port' .* LISTEN') ;;
2167 FreeBSD) l=$(netstat -an |egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;;
2168 NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2169 OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2170 Darwin) l=$(netstat -an |egrep '^tcp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+ +LISTEN') ;;
2171 AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2172 SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2173 #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2174 DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2175 *) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;;
2176 esac
2177 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2178 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2179 sleep 1
2180 timeout=$((timeout-1))
2181 done
2182  
2183 $ECHO "!port $port timed out! \c" >&2
2184 return 1
2185 }
2186  
2187 # wait until a UDP6 port is ready
2188 waitudp6port () {
2189 local port="$1"
2190 local logic="$2" # 0..wait until free; 1..wait until listening
2191 local timeout="$3"
2192 local l
2193 [ "$logic" ] || logic=1
2194 [ "$timeout" ] || timeout=5
2195 while [ $timeout -gt 0 ]; do
2196 case "$UNAME" in
2197 Linux) l=$(netstat -an |grep -E '^udp6? .* .*[0-9*:]:'$port' [ ]*:::\*') ;;
2198 FreeBSD) l=$(netstat -an |egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;;
2199 NetBSD) l=$(netstat -an |grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;;
2200 OpenBSD) l=$(netstat -an |grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2201 Darwin) l=$(netstat -an |egrep '^udp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+') ;;
2202 AIX) l=$(netstat -an |grep '^udp[6 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2203 SunOS) l=$(netstat -an -f inet6 -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2204 #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
2205 #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2206 DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2207 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2208 esac
2209 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2210 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2211 sleep 1
2212 timeout=$((timeout-1))
2213 done
2214  
2215 $ECHO "!port $port timed out! \c" >&2
2216 return 1
2217 }
2218  
2219 # wait until a sctp6 listen port is ready
2220 # not all (Linux) variants show this in netstat
2221 waitsctp6port () {
2222 local port="$1"
2223 local logic="$2" # 0..wait until free; 1..wait until listening
2224 local timeout="$3"
2225 local l
2226 [ "$logic" ] || logic=1
2227 [ "$timeout" ] || timeout=5
2228 while [ $timeout -gt 0 ]; do
2229 case "$UNAME" in
2230 Linux) l=$(netstat -an |grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN') ;;
2231 # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
2232 # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2233 # OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2234 # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2235 SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2236 # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2237 *) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
2238 esac
2239 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2240 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2241 sleep 1
2242 timeout=$((timeout-1))
2243 done
2244  
2245 $ECHO "!port $port timed out! \c" >&2
2246 return 1
2247 }
2248  
2249 # we need this misleading function name for canonical reasons
2250 waitunixport () {
2251 waitfile "$1" "$2" "$3"
2252 }
2253  
2254 # wait until a filesystem entry exists
2255 waitfile () {
2256 local crit=-e
2257 case "X$1" in X-*) crit="$1"; shift ;; esac
2258 local file="$1"
2259 local logic="$2" # 0..wait until gone; 1..wait until exists (default);
2260 # 2..wait until not empty
2261 local timeout="$3"
2262 [ "$logic" ] || logic=1
2263 [ "$logic" -eq 2 ] && crit=-s
2264 [ "$timeout" ] || timeout=5
2265 while [ $timeout -gt 0 ]; do
2266 if [ \( \( $logic -ne 0 \) -a $crit "$file" \) -o \
2267 \( \( $logic -eq 0 \) -a ! $crit "$file" \) ]; then
2268 return 0
2269 fi
2270 sleep 1
2271 timeout=$((timeout-1))
2272 done
2273  
2274 echo "file $file timed out" >&2
2275 return 1
2276 }
2277  
2278 # generate a test certificate and key
2279 gentestcert () {
2280 local name="$1"
2281 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2282 openssl genrsa $OPENSSL_RAND -out $name.key 768 >/dev/null 2>&1
2283 openssl req -new -config $TESTCERT_CONF -key $name.key -x509 -days 3653 -out $name.crt >/dev/null 2>&1
2284 cat $name.key $name.crt >$name.pem
2285 }
2286  
2287 # generate a test DSA key and certificate
2288 gentestdsacert () {
2289 #set -vx
2290 local name="$1"
2291 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2292 openssl dsaparam -out $name-dsa.pem 512 >/dev/null 2>&1
2293 openssl dhparam -dsaparam -out $name-dh.pem 512 >/dev/null 2>&1
2294 openssl req -newkey dsa:$name-dsa.pem -keyout $name.key -nodes -x509 -days 3653 -config $TESTCERT_CONF -out $name.crt >/dev/null 2>&1
2295 cat $name-dsa.pem $name-dh.pem $name.key $name.crt >$name.pem
2296 }
2297  
2298 gentestcert6 () {
2299 local name="$1"
2300 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2301 cat $TESTCERT_CONF |
2302 { echo "# automatically generated by $0"; cat; } |
2303 sed 's/\(commonName\s*=\s*\).*/\1[::1]/' >$TESTCERT6_CONF
2304 openssl genrsa $OPENSSL_RAND -out $name.key 768 >/dev/null 2>&1
2305 openssl req -new -config $TESTCERT6_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2306 cat $name.key $name.crt >$name.pem
2307 }
2308  
2309  
2310 NAME=UNISTDIO
2311 case "$TESTS " in
2312 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2313 TEST="$NAME: unidirectional throughput from stdin to stdout"
2314 testecho "$N" "$TEST" "stdin" "stdout" "$opts -u"
2315 esac
2316 N=$((N+1))
2317  
2318  
2319 NAME=UNPIPESTDIO
2320 case "$TESTS" in
2321 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2322 TEST="$NAME: stdio with simple echo via internal pipe"
2323 testecho "$N" "$TEST" "stdio" "pipe" "$opts"
2324 esac
2325 N=$((N+1))
2326  
2327  
2328 NAME=UNPIPESHORT
2329 case "$TESTS" in
2330 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2331 TEST="$NAME: short form of stdio ('-') with simple echo via internal pipe"
2332 testecho "$N" "$TEST" "-" "pipe" "$opts"
2333 esac
2334 N=$((N+1))
2335  
2336  
2337 NAME=DUALSTDIO
2338 case "$TESTS" in
2339 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2340 TEST="$NAME: splitted form of stdio ('stdout%stdin') with simple echo via internal pipe"
2341 testecho "$N" "$TEST" "stdout%stdin" "pipe" "$opts"
2342 esac
2343 N=$((N+1))
2344  
2345  
2346 NAME=DUALSHORTSTDIO
2347 case "$TESTS" in
2348 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2349 TEST="$NAME: short splitted form of stdio ('-%-') with simple echo via internal pipe"
2350 testecho "$N" "$TEST" "-%-" "pipe" "$opts"
2351 esac
2352 N=$((N+1))
2353  
2354  
2355 NAME=DUALFDS
2356 case "$TESTS" in
2357 *%$N%*|*%functions%*|*%fd%*|*%$NAME%*)
2358 TEST="$NAME: file descriptors with simple echo via internal pipe"
2359 testecho "$N" "$TEST" "1%0" "pipe" "$opts"
2360 esac
2361 N=$((N+1))
2362  
2363  
2364 NAME=NAMEDPIPE
2365 case "$TESTS" in
2366 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2367 TEST="$NAME: simple echo via named pipe"
2368 # with MacOS, this test hangs if nonblock is not used. Is an OS bug.
2369 tp="$td/pipe$N"
2370 # note: the nonblock is required by MacOS 10.1(?), otherwise it hangs (OS bug?)
2371 testecho "$N" "$TEST" "" "pipe:$tp,nonblock" "$opts"
2372 esac
2373 N=$((N+1))
2374  
2375  
2376 # does not work with <write>%<read>
2377 #NAME=DUALPIPE
2378 #case "$TESTS" in
2379 #*%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2380 #TEST="$NAME: simple echo via named pipe, specified twice"
2381 #tp="$td/pipe$N"
2382 #testecho "$N" "$TEST" "" "pipe:$tp%pipe:$tp,nonblock" "$opts"
2383 #esac
2384 #N=$((N+1))
2385  
2386  
2387 NAME=FILE
2388 case "$TESTS" in
2389 *%$N%*|*%functions%*|*%engine%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
2390 TEST="$NAME: simple echo via file"
2391 tf="$td/file$N"
2392 testecho "$N" "$TEST" "" "$tf%$tf,ignoreeof" "$opts"
2393 esac
2394 N=$((N+1))
2395  
2396  
2397 #EXECSOCKET SYSTEMSOCKET EXECPIPES SYSTEMPIPES EXECPTY SYSTEMPTY
2398 while read commtype feature addropts; do
2399 COMMTYPE="$(echo $commtype |tr a-z A-Z)"
2400 if [ -z "$COMMTYPE" ] || [[ "$COMMTYPE" == \#* ]]; then continue; fi
2401 for EXEC in EXEC SYSTEM
2402 do exec="$(echo $EXEC |tr A-Z a-z)"
2403  
2404 NAME=${EXEC}$COMMTYPE
2405 case "$TESTS" in
2406 *%$N%*|*%functions%*|*%$commtype%*|*%$exec%*|*%$NAME%*)
2407 TEST="$NAME: simple echo via $exec() of cat using $commtype"
2408 if ! eval $NUMCOND; then :;
2409 elif [ "$feature" != . ] && ! testaddrs $feature >/dev/null; then
2410 $PRINTF "test $F_n $TEST... ${YELLOW}$commtype not available${NORMAL}\n" $N
2411 numCANT=$((numCANT+1))
2412 else
2413 testecho "$N" "$TEST" "" "$exec:$CAT,commtype=$commtype,$addropts" "$opts" "$val_t"
2414 fi
2415 esac
2416 N=$((N+1))
2417  
2418 done
2419 done <<<"
2420 pipes .
2421 pty pty raw,echo=0
2422 socketpair .
2423 ptys pty raw,echo=0
2424 tcp tcp
2425 socketpairs .
2426 "
2427  
2428  
2429  
2430  
2431 NAME=SYSTEMPIPESFDS
2432 case "$TESTS" in
2433 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2434 TEST="$NAME: simple echo via system() of cat with pipes, non stdio"
2435 testecho "$N" "$TEST" "" "system:$CAT>&9 <&8,pipes,fdin=8,fdout=9" "$opts"
2436 esac
2437 N=$((N+1))
2438  
2439  
2440 NAME=DUALSYSTEMFDS
2441 case "$TESTS" in
2442 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2443 TEST="$NAME: echo via dual system() of cat"
2444 #testecho "$N" "$TEST" "system:$CAT<&7,fdin=7%system:'strace -tt -o /tmp/cat.out cat'>&6,fdout=6" "" "$opts" "$T"
2445 testecho "$N" "$TEST" "system:$CAT<&7,fdin=7%system:'cat'>&6,fdout=6" "" "$opts" "0.1" "$val_t"
2446 esac
2447 N=$((N+1))
2448  
2449  
2450 # test: send EOF to exec'ed sub process, let it finish its operation, and
2451 # check if the sub process returns its data before terminating.
2452 NAME=EXECSOCKETFLUSH
2453 # idea: have socat exec'ing od; send data and EOF, and check if the od'ed data
2454 # arrives.
2455 case "$TESTS" in
2456 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2457 TEST="$NAME: call to od via exec with socketpair"
2458 testod "$N" "$TEST" "" "exec:$OD_C" "$opts" "0.1"
2459 esac
2460 N=$((N+1))
2461  
2462  
2463 NAME=SYSTEMSOCKETFLUSH
2464 case "$TESTS" in
2465 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2466 TEST="$NAME: call to od via system() with socketpair"
2467 testod "$N" "$TEST" "" "system:$OD_C" "$opts" $val_t
2468 esac
2469 N=$((N+1))
2470  
2471  
2472 NAME=EXECPIPESFLUSH
2473 case "$TESTS" in
2474 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2475 TEST="$NAME: call to od via exec with pipes"
2476 testod "$N" "$TEST" "" "exec:$OD_C,pipes" "$opts"
2477 esac
2478 N=$((N+1))
2479  
2480  
2481 NAME=SYSTEMPIPESFLUSH
2482 case "$TESTS" in
2483 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2484 TEST="$NAME: call to od via system() with pipes"
2485 testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
2486 esac
2487 N=$((N+1))
2488  
2489  
2490 ## LATER:
2491 #NAME=EXECPTYFLUSH
2492 #case "$TESTS" in
2493 #*%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2494 #TEST="$NAME: call to od via exec with pseudo terminal"
2495 #if ! testaddrs pty >/dev/null; then
2496 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2497 # numCANT=$((numCANT+1))
2498 #else
2499 #testod "$N" "$TEST" "" "exec:$OD_C,pty,$PTYOPTS" "$opts"
2500 #fi
2501 #esac
2502 #N=$((N+1))
2503  
2504  
2505 ## LATER:
2506 #NAME=SYSTEMPTYFLUSH
2507 #case "$TESTS" in
2508 #*%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2509 #TEST="$NAME: call to od via system() with pseudo terminal"
2510 #if ! testaddrs pty >/dev/null; then
2511 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2512 # numCANT=$((numCANT+1))
2513 #else
2514 #testod "$N" "$TEST" "" "system:$OD_C,pty,$PTYOPTS" "$opts"
2515 #fi
2516 #esac
2517 #N=$((N+1))
2518  
2519  
2520 NAME=SYSTEMPIPESFDSFLUSH
2521 case "$TESTS" in
2522 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2523 TEST="$NAME: call to od via system() with pipes, non stdio"
2524 testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
2525 esac
2526 N=$((N+1))
2527  
2528  
2529 NAME=DUALSYSTEMFDSFLUSH
2530 case "$TESTS" in
2531 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2532 TEST="$NAME: call to od via dual system()"
2533 testod "$N" "$TEST" "system:$CAT<&7,fdin=7%system:$OD_C>&6,fdout=6" "pipe" "$opts" "$val_t"
2534 esac
2535 N=$((N+1))
2536  
2537  
2538 case "$UNAME" in
2539 Linux) IPPROTO=254 ;;
2540 Darwin) IPPROTO=255 ;;
2541 *) IPPROTO=254 ;; # just a guess
2542 esac
2543  
2544 NAME=RAWIP4SELF
2545 case "$TESTS" in
2546 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2547 TEST="$NAME: simple echo via self receiving raw IPv4 protocol"
2548 if ! eval $NUMCOND; then :;
2549 elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
2550 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2551 numCANT=$((numCANT+1))
2552 elif ! feat=$(testaddrs rawip) >/dev/null; then
2553 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2554 numCANT=$((numCANT+1))
2555 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2556 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2557 numCANT=$((numCANT+1))
2558 else
2559 testecho "$N" "$TEST" "" "ip4:127.0.0.1:$IPPROTO" "$opts"
2560 fi
2561 esac
2562 N=$((N+1))
2563  
2564 NAME=RAWIPX4SELF
2565 case "$TESTS" in
2566 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2567 TEST="$NAME: simple echo via self receiving raw IP protocol, v4 by target"
2568 if ! eval $NUMCOND; then :;
2569 elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
2570 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2571 numCANT=$((numCANT+1))
2572 elif ! feat=$(testaddrs rawip) >/dev/null; then
2573 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2574 numCANT=$((numCANT+1))
2575 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2576 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2577 numCANT=$((numCANT+1))
2578 else
2579 testecho "$N" "$TEST" "" "ip:127.0.0.1:$IPPROTO" "$opts"
2580 fi ;; # NUMCOND, feats
2581 esac
2582 N=$((N+1))
2583  
2584 NAME=RAWIP6SELF
2585 case "$TESTS" in
2586 *%$N%*|*%functions%*|*%ip6%*|*%rawip%*|*%root%*|*%$NAME%*)
2587 TEST="$NAME: simple echo via self receiving raw IPv6 protocol"
2588 if ! eval $NUMCOND; then :;
2589 elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
2590 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2591 numCANT=$((numCANT+1))
2592 elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
2593 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2594 numCANT=$((numCANT+1))
2595 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2596 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2597 numCANT=$((numCANT+1))
2598 else
2599 testecho "$N" "$TEST" "" "ip6:[::1]:$IPPROTO" "$opts"
2600 fi ;; # NUMCOND, feats
2601 esac
2602 N=$((N+1))
2603  
2604 NAME=RAWIPX6SELF
2605 case "$TESTS" in
2606 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%root%*|*%$NAME%*)
2607 TEST="$NAME: simple echo via self receiving raw IP protocol, v6 by target"
2608 if ! eval $NUMCOND; then :;
2609 elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
2610 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2611 numCANT=$((numCANT+1))
2612 elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
2613 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2614 numCANT=$((numCANT+1))
2615 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2616 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2617 numCANT=$((numCANT+1))
2618 else
2619 testecho "$N" "$TEST" "" "ip:[::1]:$IPPROTO" "$opts"
2620 fi
2621 esac
2622 N=$((N+1))
2623  
2624  
2625 NAME=TCPSELF
2626 case "$TESTS" in
2627 *%$N%*|*%functions%*|*%$NAME%*)
2628 TEST="$NAME: echo via self connection of TCP IPv4 socket"
2629 if ! eval $NUMCOND; then :;
2630 elif [ "$UNAME" != Linux ]; then
2631 #printf "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
2632 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2633 numCANT=$((numCANT+1))
2634 else
2635 #ts="127.0.0.1:$tsl"
2636 testecho "$N" "$TEST" "" "tcp:127.100.0.1:$PORT,sp=$PORT,bind=127.100.0.1,reuseaddr" "$opts"
2637 fi
2638 esac
2639 PORT=$((PORT+1))
2640 N=$((N+1))
2641  
2642  
2643 NAME=UDPSELF
2644 if ! eval $NUMCOND; then :; else
2645 case "$TESTS" in
2646 *%$N%*|*%functions%*|*%$NAME%*)
2647 TEST="$NAME: echo via self connection of UDP IPv4 socket"
2648 if [ "$UNAME" != Linux ]; then
2649 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2650 numCANT=$((numCANT+1))
2651 else
2652 testecho "$N" "$TEST" "" "udp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR" "$opts"
2653 fi
2654 esac
2655 fi # NUMCOND
2656 PORT=$((PORT+1))
2657 N=$((N+1))
2658  
2659  
2660 NAME=UDP6SELF
2661 case "$TESTS" in
2662 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%$NAME%*)
2663 TEST="$NAME: echo via self connection of UDP IPv6 socket"
2664 if ! eval $NUMCOND; then :;
2665 elif [ "$UNAME" != Linux ]; then
2666 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
2667 numCANT=$((numCANT+1))
2668 elif ! testaddrs udp ip6 >/dev/null || ! runsip6 >/dev/null; then
2669 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
2670 numCANT=$((numCANT+1))
2671 else
2672 tf="$td/file$N"
2673 testecho "$N" "$TEST" "" "udp6:[::1]:$PORT,sp=$PORT,bind=[::1]" "$opts"
2674 fi
2675 esac
2676 PORT=$((PORT+1))
2677 N=$((N+1))
2678  
2679  
2680 NAME=DUALUDPSELF
2681 if ! eval $NUMCOND; then :; else
2682 case "$TESTS" in
2683 *%$N%*|*%functions%*|*%$NAME%*)
2684 TEST="$NAME: echo via two unidirectional UDP IPv4 sockets"
2685 tf="$td/file$N"
2686 p1=$PORT
2687 p2=$((PORT+1))
2688 testecho "$N" "$TEST" "" "udp:127.0.0.1:$p1,sp=$p2%udp:127.0.0.1:$p2,sp=$p1" "$opts"
2689 esac
2690 fi # NUMCOND
2691 PORT=$((PORT+2))
2692 N=$((N+1))
2693  
2694  
2695 #function testdual {
2696 # local
2697 #}
2698  
2699  
2700 NAME=UNIXSTREAM
2701 if ! eval $NUMCOND; then :; else
2702 case "$TESTS" in
2703 *%$N%*|*%functions%*|*%unix%*|*%$NAME%*)
2704 TEST="$NAME: echo via connection to UNIX domain socket"
2705 tf="$td/test$N.stdout"
2706 te="$td/test$N.stderr"
2707 ts="$td/test$N.socket"
2708 tdiff="$td/test$N.diff"
2709 da="test$N $(date) $RANDOM"
2710 CMD1="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
2711 CMD2="$TRACE $SOCAT $opts -%- UNIX-CONNECT:$ts"
2712 printf "test $F_n $TEST... " $N
2713 $CMD1 </dev/null >$tf 2>"${te}1" &
2714 bg=$! # background process id
2715 waitfile "$ts"
2716 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2717 if [ $? -ne 0 ]; then
2718 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2719 echo "$CMD1 &"
2720 echo "$CMD2"
2721 cat "$te"
2722 numFAIL=$((numFAIL+1))
2723 listFAIL="$listFAIL $N"
2724 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2725 $PRINTF "$FAILED: diff:\n"
2726 cat "$tdiff"
2727 numFAIL=$((numFAIL+1))
2728 listFAIL="$listFAIL $N"
2729 else
2730 $PRINTF "$OK\n"
2731 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2732 numOK=$((numOK+1))
2733 fi
2734 kill $bg 2>/dev/null
2735 esac
2736 fi # NUMCOND
2737 N=$((N+1))
2738  
2739  
2740 NAME=TCP4
2741 if ! eval $NUMCOND; then :; else
2742 case "$TESTS" in
2743 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2744 TEST="$NAME: echo via connection to TCP V4 socket"
2745 tf="$td/test$N.stdout"
2746 te="$td/test$N.stderr"
2747 tdiff="$td/test$N.diff"
2748 tsl=$PORT
2749 ts="127.0.0.1:$tsl"
2750 da="test$N $(date) $RANDOM"
2751 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE"
2752 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
2753 printf "test $F_n $TEST... " $N
2754 $CMD1 >"$tf" 2>"${te}1" &
2755 pid1=$!
2756 waittcp4port $tsl 1
2757 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2758 if [ $? -ne 0 ]; then
2759 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2760 echo "$CMD1 &"
2761 cat "${te}1"
2762 echo "$CMD2"
2763 cat "${te}2"
2764 numFAIL=$((numFAIL+1))
2765 listFAIL="$listFAIL $N"
2766 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2767 $PRINTF "$FAILED\n"
2768 cat "$tdiff"
2769 numFAIL=$((numFAIL+1))
2770 listFAIL="$listFAIL $N"
2771 else
2772 $PRINTF "$OK\n"
2773 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2774 numOK=$((numOK+1))
2775 fi
2776 kill $pid1 2>/dev/null
2777 wait ;;
2778 esac
2779 PORT=$((PORT+1))
2780 fi # NUMCOND
2781 N=$((N+1))
2782  
2783  
2784 NAME=TCP6
2785 case "$TESTS" in
2786 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2787 TEST="$NAME: echo via connection to TCP V6 socket"
2788 if ! eval $NUMCOND; then :;
2789 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
2790 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
2791 numCANT=$((numCANT+1))
2792 else
2793 tf="$td/test$N.stdout"
2794 te="$td/test$N.stderr"
2795 tdiff="$td/test$N.diff"
2796 tsl=$PORT
2797 ts="[::1]:$tsl"
2798 da="test$N $(date) $RANDOM"
2799 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,reuseaddr PIPE"
2800 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP6:$ts"
2801 printf "test $F_n $TEST... " $N
2802 $CMD1 >"$tf" 2>"${te}1" &
2803 pid=$! # background process id
2804 waittcp6port $tsl 1
2805 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2806 if [ $? -ne 0 ]; then
2807 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2808 echo "$CMD1 &"
2809 echo "$CMD2"
2810 cat "$te"
2811 numFAIL=$((numFAIL+1))
2812 listFAIL="$listFAIL $N"
2813 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2814 $PRINTF "$FAILED: diff:\n"
2815 cat "$tdiff"
2816 listFAIL="$listFAIL $N"
2817 numFAIL=$((numFAIL+1))
2818 else
2819 $PRINTF "$OK\n"
2820 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2821 numOK=$((numOK+1))
2822 fi
2823 kill $pid 2>/dev/null
2824 fi
2825 esac
2826 PORT=$((PORT+1))
2827 N=$((N+1))
2828  
2829  
2830 NAME=TCPX4
2831 case "$TESTS" in
2832 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2833 TEST="$NAME: echo via connection to TCP socket, v4 by target"
2834 if ! eval $NUMCOND; then :;
2835 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2836 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2837 numCANT=$((numCANT+1))
2838 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2839 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2840 numCANT=$((numCANT+1))
2841 else
2842 tf="$td/test$N.stdout"
2843 te="$td/test$N.stderr"
2844 tdiff="$td/test$N.diff"
2845 tsl=$PORT
2846 ts="127.0.0.1:$tsl"
2847 da="test$N $(date) $RANDOM"
2848 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip4,reuseaddr PIPE"
2849 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP:$ts"
2850 printf "test $F_n $TEST... " $N
2851 $CMD1 >"$tf" 2>"${te}1" &
2852 pid=$! # background process id
2853 waittcp4port $tsl 1
2854 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2855 if [ $? -ne 0 ]; then
2856 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2857 echo "$CMD1 &"
2858 echo "$CMD2"
2859 cat "$te"
2860 numFAIL=$((numFAIL+1))
2861 listFAIL="$listFAIL $N"
2862 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2863 $PRINTF "$FAILED: diff:\n"
2864 cat "$tdiff"
2865 numFAIL=$((numFAIL+1))
2866 listFAIL="$listFAIL $N"
2867 else
2868 $PRINTF "$OK\n"
2869 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2870 numOK=$((numOK+1))
2871 fi
2872 kill $pid 2>/dev/null
2873 fi
2874 esac
2875 PORT=$((PORT+1))
2876 N=$((N+1))
2877  
2878  
2879 NAME=TCPX6
2880 case "$TESTS" in
2881 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2882 TEST="$NAME: echo via connection to TCP socket, v6 by target"
2883 if ! eval $NUMCOND; then :;
2884 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2885 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2886 numCANT=$((numCANT+1))
2887 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2888 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2889 numCANT=$((numCANT+1))
2890 else
2891 tf="$td/test$N.stdout"
2892 te="$td/test$N.stderr"
2893 tdiff="$td/test$N.diff"
2894 tsl=$PORT
2895 ts="[::1]:$tsl"
2896 da="test$N $(date) $RANDOM"
2897 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip6,reuseaddr PIPE"
2898 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP:$ts"
2899 printf "test $F_n $TEST... " $N
2900 $CMD1 >"$tf" 2>"${te}1" &
2901 pid=$! # background process id
2902 waittcp6port $tsl 1
2903 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2904 if [ $? -ne 0 ]; then
2905 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2906 echo "$CMD1 &"
2907 echo "$CMD2"
2908 cat "$te"
2909 numFAIL=$((numFAIL+1))
2910 listFAIL="$listFAIL $N"
2911 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2912 $PRINTF "$FAILED: diff:\n"
2913 cat "$tdiff"
2914 numFAIL=$((numFAIL+1))
2915 listFAIL="$listFAIL $N"
2916 else
2917 $PRINTF "$OK\n"
2918 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2919 numOK=$((numOK+1))
2920 fi
2921 kill $pid 2>/dev/null
2922 fi
2923 esac
2924 PORT=$((PORT+1))
2925 N=$((N+1))
2926  
2927 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
2928 # ipv6-v6only=0 shows this behaviour.
2929 NAME=IPV6ONLY0
2930 case "$TESTS" in
2931 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2932 TEST="$NAME: option ipv6-v6only=0 listens on IPv4"
2933 # create a listening TCP6 socket and try to connect to the port using TCP4
2934 if ! eval $NUMCOND; then :;
2935 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2936 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2937 numCANT=$((numCANT+1))
2938 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2939 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2940 numCANT=$((numCANT+1))
2941 elif ! feat=$(testoptions ipv6-v6only); then
2942 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
2943 numCANT=$((numCANT+1))
2944 else
2945 tf="$td/test$N.stdout"
2946 te="$td/test$N.stderr"
2947 tdiff="$td/test$N.diff"
2948 tsl=$PORT
2949 ts="127.0.0.1:$tsl"
2950 da="test$N $(date) $RANDOM"
2951 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$tsl,ipv6-v6only=0,reuseaddr PIPE"
2952 CMD2="$TRACE $SOCAT $opts STDOUT%STDIN TCP4:$ts"
2953 printf "test $F_n $TEST... " $N
2954 $CMD1 >"$tf" 2>"${te}1" &
2955 pid=$! # background process id
2956 waittcp6port $tsl 1
2957 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2958 if [ $? -ne 0 ]; then
2959 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2960 echo "$CMD1 &"
2961 echo "$CMD2"
2962 cat "${te}1" "${te}2"
2963 numFAIL=$((numFAIL+1))
2964 listFAIL="$listFAIL $N"
2965 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2966 $PRINTF "$FAILED: diff:\n"
2967 cat "$tdiff"
2968 numFAIL=$((numFAIL+1))
2969 listFAIL="$listFAIL $N"
2970 else
2971 $PRINTF "$OK\n"
2972 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2973 numOK=$((numOK+1))
2974 fi
2975 kill $pid 2>/dev/null
2976 fi
2977 esac
2978 PORT=$((PORT+1))
2979 N=$((N+1))
2980  
2981 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
2982 # ipv6-v6only=1 turns off this behaviour.
2983 NAME=IPV6ONLY1
2984 case "$TESTS" in
2985 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2986 TEST="$NAME: option ipv6-v6only=1 does not listen on IPv4"
2987 if ! eval $NUMCOND; then :;
2988 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2989 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2990 numCANT=$((numCANT+1))
2991 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2992 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2993 numCANT=$((numCANT+1))
2994 elif ! feat=$(testoptions ipv6-v6only); then
2995 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
2996 numCANT=$((numCANT+1))
2997 else
2998 tf="$td/test$N.stdout"
2999 te="$td/test$N.stderr"
3000 tdiff="$td/test$N.diff"
3001 tsl=$PORT
3002 ts="127.0.0.1:$tsl"
3003 da="test$N $(date) $RANDOM"
3004 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,reuseaddr PIPE"
3005 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
3006 printf "test $F_n $TEST... " $N
3007 $CMD1 >"$tf" 2>"${te}1" &
3008 pid=$! # background process id
3009 waittcp6port $tsl 1
3010 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3011 if [ $? -eq 0 ]; then
3012 $PRINTF "$FAILED:\n"
3013 cat "${te}1" "${te}2"
3014 numFAIL=$((numFAIL+1))
3015 listFAIL="$listFAIL $N"
3016 elif echo "$da" |diff - "$tf" >"$tdiff"; then
3017 $PRINTF "$FAILED:\n"
3018 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3019 numFAIL=$((numFAIL+1))
3020 listFAIL="$listFAIL $N"
3021 else
3022 $PRINTF "$OK\n"
3023 numOK=$((numOK+1))
3024 fi
3025 kill $pid; wait
3026 fi
3027 esac
3028 PORT=$((PORT+1))
3029 N=$((N+1))
3030  
3031 NAME=ENV_LISTEN_4
3032 case "$TESTS" in
3033 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3034 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv4 preference on listen"
3035 if ! eval $NUMCOND; then :;
3036 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3037 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3038 numCANT=$((numCANT+1))
3039 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3040 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3041 numCANT=$((numCANT+1))
3042 elif ! feat=$(testoptions ipv6-v6only); then
3043 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3044 numCANT=$((numCANT+1))
3045 else
3046 tf="$td/test$N.stdout"
3047 te="$td/test$N.stderr"
3048 tdiff="$td/test$N.diff"
3049 tsl=$PORT
3050 ts="127.0.0.1:$tsl"
3051 da="test$N $(date) $RANDOM"
3052 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,reuseaddr PIPE"
3053 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
3054 printf "test $F_n $TEST... " $N
3055 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3056 pid=$! # background process id
3057 waittcp4port $tsl 1
3058 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3059 if [ $? -ne 0 ]; then
3060 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3061 echo "$CMD1 &"
3062 echo "$CMD2"
3063 cat "${te}1" "${te}2"
3064 numFAIL=$((numFAIL+1))
3065 listFAIL="$listFAIL $N"
3066 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3067 $PRINTF "$FAILED: diff:\n"
3068 cat "$tdiff"
3069 numFAIL=$((numFAIL+1))
3070 listFAIL="$listFAIL $N"
3071 else
3072 $PRINTF "$OK\n"
3073 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3074 numOK=$((numOK+1))
3075 fi
3076 kill $pid 2>/dev/null; wait
3077 fi
3078 esac
3079 PORT=$((PORT+1))
3080 N=$((N+1))
3081  
3082 NAME=ENV_LISTEN_6
3083 case "$TESTS" in
3084 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3085 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv6 preference on listen"
3086 if ! eval $NUMCOND; then :;
3087 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3088 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3089 numCANT=$((numCANT+1))
3090 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3091 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3092 numCANT=$((numCANT+1))
3093 else
3094 tf="$td/test$N.stdout"
3095 te="$td/test$N.stderr"
3096 tdiff="$td/test$N.diff"
3097 tsl=$PORT
3098 ts="[::1]:$tsl"
3099 da="test$N $(date) $RANDOM"
3100 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,reuseaddr PIPE"
3101 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP6:$ts"
3102 printf "test $F_n $TEST... " $N
3103 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3104 pid=$! # background process id
3105 waittcp6port $tsl 1
3106 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3107 if [ $? -ne 0 ]; then
3108 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3109 echo "$CMD1 &"
3110 echo "$CMD2"
3111 cat "${te}1" "${te}2"
3112 numFAIL=$((numFAIL+1))
3113 listFAIL="$listFAIL $N"
3114 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3115 $PRINTF "$FAILED: diff:\n"
3116 cat "$tdiff"
3117 numFAIL=$((numFAIL+1))
3118 listFAIL="$listFAIL $N"
3119 else
3120 $PRINTF "$OK\n"
3121 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3122 numOK=$((numOK+1))
3123 fi
3124 kill $pid 2>/dev/null; wait
3125 fi
3126 esac
3127 PORT=$((PORT+1))
3128 N=$((N+1))
3129  
3130 NAME=LISTEN_OPTION_4
3131 case "$TESTS" in
3132 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3133 TEST="$NAME: option -4 for IPv4 preference on listen"
3134 if ! eval $NUMCOND; then :;
3135 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3136 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3137 numCANT=$((numCANT+1))
3138 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3139 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3140 numCANT=$((numCANT+1))
3141 elif ! feat=$(testoptions ipv6-v6only); then
3142 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3143 numCANT=$((numCANT+1))
3144 else
3145 tf="$td/test$N.stdout"
3146 te="$td/test$N.stderr"
3147 tdiff="$td/test$N.diff"
3148 tsl=$PORT
3149 ts="127.0.0.1:$tsl"
3150 da="test$N $(date) $RANDOM"
3151 CMD1="$TRACE $SOCAT $opts -4 TCP-listen:$tsl,reuseaddr PIPE"
3152 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
3153 printf "test $F_n $TEST... " $N
3154 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3155 pid=$! # background process id
3156 waittcp4port $tsl 1
3157 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3158 if [ $? -ne 0 ]; then
3159 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3160 echo "$CMD1 &"
3161 echo "$CMD2"
3162 cat "${te}1" "${te}2"
3163 numFAIL=$((numFAIL+1))
3164 listFAIL="$listFAIL $N"
3165 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3166 $PRINTF "$FAILED: diff:\n"
3167 cat "$tdiff"
3168 numFAIL=$((numFAIL+1))
3169 listFAIL="$listFAIL $N"
3170 else
3171 $PRINTF "$OK\n"
3172 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3173 numOK=$((numOK+1))
3174 fi
3175 kill $pid 2>/dev/null; wait
3176 fi
3177 esac
3178 PORT=$((PORT+1))
3179 N=$((N+1))
3180  
3181 NAME=LISTEN_OPTION_6
3182 case "$TESTS" in
3183 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3184 TEST="$NAME: option -6 for IPv6 preference on listen"
3185 if ! eval $NUMCOND; then :;
3186 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3187 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3188 numCANT=$((numCANT+1))
3189 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3190 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3191 numCANT=$((numCANT+1))
3192 else
3193 tf="$td/test$N.stdout"
3194 te="$td/test$N.stderr"
3195 tdiff="$td/test$N.diff"
3196 tsl=$PORT
3197 ts="[::1]:$tsl"
3198 da="test$N $(date) $RANDOM"
3199 CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,reuseaddr PIPE"
3200 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP6:$ts"
3201 printf "test $F_n $TEST... " $N
3202 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3203 pid=$! # background process id
3204 waittcp6port $tsl 1
3205 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3206 if [ $? -ne 0 ]; then
3207 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3208 echo "$CMD1 &"
3209 echo "$CMD2"
3210 cat "${te}1" "${te}2"
3211 numFAIL=$((numFAIL+1))
3212 listFAIL="$listFAIL $N"
3213 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3214 $PRINTF "$FAILED: diff:\n"
3215 cat "$tdiff"
3216 numFAIL=$((numFAIL+1))
3217 listFAIL="$listFAIL $N"
3218 else
3219 $PRINTF "$OK\n"
3220 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3221 numOK=$((numOK+1))
3222 fi
3223 kill $pid 2>/dev/null; wait
3224 wait
3225 fi # feats
3226 esac
3227 PORT=$((PORT+1))
3228 N=$((N+1))
3229  
3230 NAME=LISTEN_PF_IP4
3231 case "$TESTS" in
3232 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3233 TEST="$NAME: pf=4 overrides option -6 on listen"
3234 if ! eval $NUMCOND; then :;
3235 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3236 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3237 numCANT=$((numCANT+1))
3238 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3239 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3240 numCANT=$((numCANT+1))
3241 elif ! feat=$(testoptions ipv6-v6only); then
3242 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3243 numCANT=$((numCANT+1))
3244 else
3245 tf="$td/test$N.stdout"
3246 te="$td/test$N.stderr"
3247 tdiff="$td/test$N.diff"
3248 tsl=$PORT
3249 ts="127.0.0.1:$tsl"
3250 da="test$N $(date) $RANDOM"
3251 CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,pf=ip4,reuseaddr PIPE"
3252 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
3253 printf "test $F_n $TEST... " $N
3254 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3255 pid=$! # background process id
3256 waittcp4port $tsl 1
3257 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3258 if [ $? -ne 0 ]; then
3259 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3260 echo "$CMD1 &"
3261 echo "$CMD2"
3262 cat "${te}1" "${te}2"
3263 numFAIL=$((numFAIL+1))
3264 listFAIL="$listFAIL $N"
3265 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3266 $PRINTF "$FAILED: diff:\n"
3267 cat "$tdiff"
3268 numFAIL=$((numFAIL+1))
3269 listFAIL="$listFAIL $N"
3270 else
3271 $PRINTF "$OK\n"
3272 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3273 numOK=$((numOK+1))
3274 fi
3275 kill $pid 2>/dev/null; wait
3276 fi
3277 esac
3278 PORT=$((PORT+1))
3279 N=$((N+1))
3280  
3281 NAME=LISTEN_PF_IP6
3282 case "$TESTS" in
3283 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3284 TEST="$NAME: pf=6 overrides option -4 on listen"
3285 if ! eval $NUMCOND; then :;
3286 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3287 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3288 numCANT=$((numCANT+1))
3289 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3290 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3291 numCANT=$((numCANT+1))
3292 else
3293 tf="$td/test$N.stdout"
3294 te="$td/test$N.stderr"
3295 tdiff="$td/test$N.diff"
3296 tsl=$PORT
3297 ts="[::1]:$tsl"
3298 da="test$N $(date) $RANDOM"
3299 CMD1="$TRACE $SOCAT $opts -4 TCP-listen:$tsl,pf=ip6,reuseaddr PIPE"
3300 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP6:$ts"
3301 printf "test $F_n $TEST... " $N
3302 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3303 pid=$! # background process id
3304 waittcp6port $tsl 1
3305 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3306 if [ $? -ne 0 ]; then
3307 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3308 echo "$CMD1 &"
3309 echo "$CMD2"
3310 cat "${te}1" "${te}2"
3311 numFAIL=$((numFAIL+1))
3312 listFAIL="$listFAIL $N"
3313 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3314 $PRINTF "$FAILED: diff:\n"
3315 cat "$tdiff"
3316 numFAIL=$((numFAIL+1))
3317 listFAIL="$listFAIL $N"
3318 else
3319 $PRINTF "$OK\n"
3320 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3321 numOK=$((numOK+1))
3322 fi
3323 kill $pid 2>/dev/null; wait
3324 fi ;; # NUMCOND, feats
3325 esac
3326 PORT=$((PORT+1))
3327 N=$((N+1))
3328  
3329  
3330 NAME=UDP4STREAM
3331 case "$TESTS" in
3332 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3333 TEST="$NAME: echo via connection to UDP V4 socket"
3334 if ! eval $NUMCOND; then :; else
3335 tf="$td/test$N.stdout"
3336 te="$td/test$N.stderr"
3337 tdiff="$td/test$N.diff"
3338 tsl=$PORT
3339 ts="$LOCALHOST:$tsl"
3340 da="test$N $(date) $RANDOM"
3341 CMD1="$TRACE $SOCAT $opts UDP4-LISTEN:$tsl,reuseaddr PIPE"
3342 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
3343 printf "test $F_n $TEST... " $N
3344 $CMD1 >"$tf" 2>"${te}1" &
3345 pid1=$!
3346 waitudp4port $tsl 1
3347 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3348 rc2=$?
3349 kill $pid1 2>/dev/null; wait
3350 if [ $rc2 -ne 0 ]; then
3351 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3352 echo "$CMD1 &"
3353 echo "$CMD2"
3354 cat "${te}1" "${te}2"
3355 numFAIL=$((numFAIL+1))
3356 listFAIL="$listFAIL $N"
3357 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3358 $PRINTF "$FAILED\n"
3359 echo "$CMD1 &"
3360 cat "${te}1"
3361 echo "$CMD2"
3362 cat "${te}2"
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))
3370 fi
3371 fi ;; # NUMCOND
3372 esac
3373 PORT=$((PORT+1))
3374 N=$((N+1))
3375  
3376  
3377 NAME=UDP6STREAM
3378 case "$TESTS" in
3379 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3380 TEST="$NAME: echo via connection to UDP V6 socket"
3381 if ! eval $NUMCOND; then :;
3382 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
3383 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
3384 numCANT=$((numCANT+1))
3385 else
3386 tf="$td/test$N.stdout"
3387 te="$td/test$N.stderr"
3388 tdiff="$td/test$N.diff"
3389 tsl=$PORT
3390 ts="$LOCALHOST6:$tsl"
3391 da="test$N $(date) $RANDOM"
3392 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,reuseaddr PIPE"
3393 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
3394 printf "test $F_n $TEST... " $N
3395 $CMD1 >"$tf" 2>"${te}1" &
3396 pid1=$!
3397 waitudp6port $tsl 1
3398 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3399 rc2=$?
3400 kill $pid1 2>/dev/null; wait
3401 if [ $rc2 -ne 0 ]; then
3402 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3403 echo "$CMD1 &"
3404 echo "$CMD2"
3405 cat "${te}1" "${te}2"
3406 numFAIL=$((numFAIL+1))
3407 listFAIL="$listFAIL $N"
3408 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3409 $PRINTF "$FAILED\n"
3410 cat "$tdiff"
3411 numFAIL=$((numFAIL+1))
3412 listFAIL="$listFAIL $N"
3413 else
3414 $PRINTF "$OK\n"
3415 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3416 numOK=$((numOK+1))
3417 fi
3418 fi ;; # ! testaddrs
3419 esac
3420 PORT=$((PORT+1))
3421 N=$((N+1))
3422  
3423  
3424 NAME=GOPENFILE
3425 case "$TESTS" in
3426 *%$N%*|*%functions%*|*%engine%*|*%gopen%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
3427 TEST="$NAME: file opening with gopen"
3428 if ! eval $NUMCOND; then :; else
3429 tf1="$td/test$N.1.stdout"
3430 tf2="$td/test$N.2.stdout"
3431 te="$td/test$N.stderr"
3432 tdiff="$td/test$N.diff"
3433 da="test$N $(date) $RANDOM"
3434 echo "$da" >$tf1
3435 CMD="$TRACE $SOCAT $opts /dev/null%$tf1 -%/dev/null,ignoreeof"
3436 printf "test $F_n $TEST... " $N
3437 $CMD >"$tf2" 2>"$te"
3438 if [ $? -ne 0 ]; then
3439 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3440 echo "$CMD"
3441 cat "$te"
3442 numFAIL=$((numFAIL+1))
3443 listFAIL="$listFAIL $N"
3444 elif ! diff "$tf1" "$tf2" >"$tdiff"; then
3445 $PRINTF "$FAILED: diff:\n"
3446 cat "$tdiff"
3447 numFAIL=$((numFAIL+1))
3448 listFAIL="$listFAIL $N"
3449 else
3450 $PRINTF "$OK\n"
3451 if [ -n "$debug" ]; then cat $te; fi
3452 numOK=$((numOK+1))
3453 fi
3454 fi # NUMCOND
3455 esac
3456 N=$((N+1))
3457  
3458  
3459 NAME=GOPENPIPE
3460 case "$TESTS" in
3461 *%$N%*|*%functions%*|*%engine%*|*%gopen%*|*%pipe%*|*%ignoreeof%*|*%$NAME%*)
3462 TEST="$NAME: pipe opening with gopen for reading"
3463 if ! eval $NUMCOND; then :; else
3464 tp="$td/pipe$N"
3465 tf="$td/test$N.stdout"
3466 te="$td/test$N.stderr"
3467 tdiff="$td/test$N.diff"
3468 da="test$N $(date) $RANDOM"
3469 CMD="$TRACE $SOCAT $opts /dev/null%$tp $tf%/dev/null,ignoreeof"
3470 printf "test $F_n $TEST... " $N
3471 #mknod $tp p # no mknod p on FreeBSD
3472 mkfifo $tp
3473 $CMD >$tf 2>"$te" &
3474 #($CMD >$tf 2>"$te" || rm -f "$tp") 2>/dev/null &
3475 bg=$! # background process id
3476 usleep $MICROS
3477 if [ ! -p "$tp" ]; then
3478 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3479 echo "$CMD"
3480 cat "$te"
3481 numFAIL=$((numFAIL+1))
3482 listFAIL="$listFAIL $N"
3483 else
3484 #echo "$da" >"$tp" # might hang forever
3485 echo "$da" >"$tp" & export pid=$!; (sleep 1; kill $pid 2>/dev/null) &
3486 # Solaris needs more time:
3487 sleep 1
3488 kill "$bg" 2>/dev/null
3489 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3490 if [ -s "$te" ]; then
3491 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3492 echo "$CMD"
3493 cat "$te"
3494 else
3495 $PRINTF "$FAILED: diff:\n"
3496 cat "$tdiff"
3497 fi
3498 numFAIL=$((numFAIL+1))
3499 listFAIL="$listFAIL $N"
3500 else
3501 $PRINTF "$OK\n"
3502 if [ -n "$debug" ]; then cat $te; fi
3503 numOK=$((numOK+1))
3504 fi
3505 fi
3506 wait
3507 fi # NUMCOND
3508 esac
3509 N=$((N+1))
3510  
3511  
3512 NAME=GOPENUNIXSTREAM
3513 case "$TESTS" in
3514 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%listen%*|*%$NAME%*)
3515 TEST="$NAME: GOPEN on UNIX stream socket"
3516 if ! eval $NUMCOND; then :; else
3517 ts="$td/test$N.socket"
3518 tf="$td/test$N.stdout"
3519 te="$td/test$N.stderr"
3520 tdiff="$td/test$N.diff"
3521 da1="test$N $(date) $RANDOM"
3522 #establish a listening unix socket in background
3523 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
3524 #make a connection
3525 CMD="$TRACE $SOCAT $opts - $ts"
3526 $PRINTF "test $F_n $TEST... " $N
3527 eval "$SRV 2>${te}s &"
3528 pids=$!
3529 waitfile "$ts"
3530 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
3531 if [ $? -ne 0 ]; then
3532 kill "$pids" 2>/dev/null
3533 $PRINTF "$FAILED:\n"
3534 echo "$SRV &"
3535 cat "${te}s"
3536 echo "$CMD"
3537 cat "${te}1"
3538 numFAIL=$((numFAIL+1))
3539 listFAIL="$listFAIL $N"
3540 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
3541 kill "$pids" 2>/dev/null
3542 $PRINTF "$FAILED:\n"
3543 echo "$SRV &"
3544 cat "${te}s"
3545 echo "$CMD"
3546 cat "${te}1"
3547 cat "$tdiff"
3548 numFAIL=$((numFAIL+1))
3549 listFAIL="$listFAIL $N"
3550 else
3551 $PRINTF "$OK\n"
3552 if [ -n "$debug" ]; then cat $te; fi
3553 numOK=$((numOK+1))
3554 fi # !(rc -ne 0)
3555 wait
3556 fi # NUMCOND
3557 esac
3558 N=$((N+1))
3559  
3560  
3561 NAME=GOPENUNIXDGRAM
3562 case "$TESTS" in
3563 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%dgram%*|*%$NAME%*)
3564 TEST="$NAME: GOPEN on UNIX datagram socket"
3565 if ! eval $NUMCOND; then :; else
3566 ts="$td/test$N.socket"
3567 tf="$td/test$N.stdout"
3568 te="$td/test$N.stderr"
3569 tdiff="$td/test$N.diff"
3570 da1="test$N $(date) $RANDOM"
3571 #establish a receiving unix socket in background
3572 SRV="$TRACE $SOCAT $opts -u -lpserver UNIX-RECV:\"$ts\" file:\"$tf\",create"
3573 #make a connection
3574 CMD="$TRACE $SOCAT $opts -u - $ts"
3575 $PRINTF "test $F_n $TEST... " $N
3576 eval "$SRV 2>${te}s &"
3577 pids=$!
3578 waitfile "$ts"
3579 echo "$da1" |eval "$CMD" 2>"${te}1"
3580 waitfile -s "$tf"
3581 if [ $? -ne 0 ]; then
3582 $PRINTF "$FAILED:\n"
3583 echo "$SRV &"
3584 cat "${te}s"
3585 echo "$CMD"
3586 cat "${te}1"
3587 numFAIL=$((numFAIL+1))
3588 listFAIL="$listFAIL $N"
3589 elif ! echo "$da1" |diff - "${tf}" >"$tdiff"; then
3590 $PRINTF "$FAILED:\n"
3591 echo "$SRV &"
3592 cat "${te}s"
3593 echo "$CMD"
3594 cat "${te}1"
3595 cat "$tdiff"
3596 numFAIL=$((numFAIL+1))
3597 listFAIL="$listFAIL $N"
3598 else
3599 $PRINTF "$OK\n"
3600 if [ -n "$debug" ]; then cat $te; fi
3601 numOK=$((numOK+1))
3602 fi # !(rc -ne 0)
3603 kill "$pids" 2>/dev/null
3604 wait
3605 fi ;; # NUMCOND
3606 esac
3607 N=$((N+1))
3608  
3609  
3610 NAME=IGNOREEOF
3611 case "$TESTS" in
3612 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3613 TEST="$NAME: ignoreeof on file"
3614 if ! eval $NUMCOND; then :; else
3615 ti="$td/test$N.file"
3616 tf="$td/test$N.stdout"
3617 te="$td/test$N.stderr"
3618 tdiff="$td/test$N.diff"
3619 da="test$N $(date) $RANDOM"
3620 CMD="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
3621 printf "test $F_n $TEST... " $N
3622 touch "$ti"
3623 $CMD >"$tf" 2>"$te" &
3624 bg=$!
3625 usleep 500000
3626 echo "$da" >>"$ti"
3627 sleep 1
3628 kill $bg 2>/dev/null; wait
3629 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3630 $PRINTF "$FAILED: diff:\n"
3631 cat "$tdiff"
3632 numFAIL=$((numFAIL+1))
3633 listFAIL="$listFAIL $N"
3634 else
3635 $PRINTF "$OK\n"
3636 if [ -n "$debug" ]; then cat $te; fi
3637 numOK=$((numOK+1))
3638 fi
3639 wait
3640 fi ;; # NUMCOND
3641 esac
3642 N=$((N+1))
3643  
3644  
3645 NAME=IGNOREEOF_REV
3646 case "$TESTS" in
3647 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3648 TEST="$NAME: ignoreeof on file right-to-left"
3649 if ! eval $NUMCOND; then :; else
3650 ti="$td/test$N.file"
3651 tf="$td/test$N.stdout"
3652 te="$td/test$N.stderr"
3653 tdiff="$td/test$N.diff"
3654 da="test$N $(date) $RANDOM"
3655 CMD="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
3656 printf "test $F_n $TEST... " $N
3657 touch "$ti"
3658 $CMD >"$tf" 2>"$te" &
3659 bg=$!
3660 usleep 500000
3661 echo "$da" >>"$ti"
3662 sleep 1
3663 kill $bg 2>/dev/null
3664 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3665 $PRINTF "$FAILED: diff:\n"
3666 cat "$tdiff"
3667 listFAIL="$listFAIL $N"
3668 numFAIL=$((numFAIL+1))
3669 else
3670 $PRINTF "$OK\n"
3671 if [ -n "$debug" ]; then cat $te; fi
3672 numOK=$((numOK+1))
3673 fi
3674 wait
3675 fi ;; # NUMCOND
3676 esac
3677 N=$((N+1))
3678  
3679  
3680 NAME=EXECIGNOREEOF
3681 case "$TESTS" in
3682 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3683 TEST="$NAME: exec against address with ignoreeof"
3684 if ! eval $NUMCOND; then :; else
3685 tf="$td/test$N.stdout"
3686 te="$td/test$N.stderr"
3687 CMD="$TRACE $SOCAT $opts -lf "$te" EXEC:$TRUE /dev/null,ignoreeof"
3688 printf "test $F_n $TEST... " $N
3689 $CMD >"$tf"
3690 if [ -s "$te" ]; then
3691 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3692 echo "$CMD"
3693 cat "$te"
3694 numFAIL=$((numFAIL+1))
3695 listFAIL="$listFAIL $N"
3696 else
3697 $PRINTF "$OK\n"
3698 if [ -n "$debug" ]; then cat $te; fi
3699 numOK=$((numOK+1))
3700 fi
3701 fi ;; # NUMCOND
3702 esac
3703 N=$((N+1))
3704  
3705  
3706 NAME=FAKEPTY
3707 case "$TESTS" in
3708 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
3709 TEST="$NAME: generation of pty for other processes"
3710 if ! eval $NUMCOND; then :;
3711 elif ! testaddrs pty >/dev/null; then
3712 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
3713 numCANT=$((numCANT+1))
3714 else
3715 tt="$td/pty$N"
3716 tf="$td/test$N.stdout"
3717 te="$td/test$N.stderr"
3718 tdiff="$td/test$N.diff"
3719 da="test$N $(date) $RANDOM"
3720 CMD1="$TRACE $SOCAT $opts pty,link=$tt pipe"
3721 CMD2="$TRACE $SOCAT $opts - $tt,$PTYOPTS2"
3722 printf "test $F_n $TEST... " $N
3723 $CMD1 2>"${te}1" &
3724 pid=$! # background process id
3725 waitfile "$tt"
3726 # this hangs on HP-UX, so we use a timeout
3727 (echo "$da"; sleep 1) |$CMD2 >$tf 2>"${te}2" &
3728 rc2=$!
3729 #sleep 5 && kill $rc2 2>/dev/null &
3730 wait $rc2
3731 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3732 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3733 echo "$CMD1 &"
3734 sleep 1
3735 echo "$CMD2"
3736 cat "${te}1"
3737 cat "${te}2"
3738 cat "$tdiff"
3739 numFAIL=$((numFAIL+1))
3740 listFAIL="$listFAIL $N"
3741 else
3742 $PRINTF "$OK\n"
3743 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3744 numOK=$((numOK+1))
3745 fi
3746 kill $pid 2>/dev/null; wait
3747 fi ;; # NUMCOND, feats
3748 esac
3749 N=$((N+1))
3750  
3751  
3752 NAME=O_TRUNC
3753 case "$TESTS" in
3754 *%$N%*|*%functions%*|*%$NAME%*)
3755 TEST="$NAME: option o-trunc"
3756 if ! eval $NUMCOND; then :; else
3757 ff="$td/test$N.file"
3758 tf="$td/test$N.stdout"
3759 te="$td/test$N.stderr"
3760 tdiff="$td/test$N.diff"
3761 da="test$N $(date) $RANDOM"
3762 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,o-trunc"
3763 printf "test $F_n $TEST... " $N
3764 rm -f $ff; $ECHO "prefix-\c" >$ff
3765 echo "$da" |$CMD >$tf 2>"$te"
3766 rc0=$?
3767 if ! [ $rc0 = 0 ] ||
3768 ! echo "$da" |diff - $ff >"$tdiff"; then
3769 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3770 echo "$CMD"
3771 cat "$te"
3772 cat "$tdiff"
3773 numFAIL=$((numFAIL+1))
3774 listFAIL="$listFAIL $N"
3775 else
3776 $PRINTF "$OK\n"
3777 if [ -n "$debug" ]; then cat $te; fi
3778 numOK=$((numOK+1))
3779 fi
3780 fi ;; # NUMCOND
3781 esac
3782 N=$((N+1))
3783  
3784  
3785 NAME=FTRUNCATE
3786 case "$TESTS" in
3787 *%$N%*|*%functions%*|*%$NAME%*)
3788 TEST="$NAME: option ftruncate"
3789 if ! eval $NUMCOND; then :; else
3790 ff="$td/test$N.file"
3791 tf="$td/test$N.stdout"
3792 te="$td/test$N.stderr"
3793 tdiff="$td/test$N.diff"
3794 da="test$N $(date) $RANDOM"
3795 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,ftruncate=0"
3796 printf "test $F_n $TEST... " $N
3797 rm -f $ff; $ECHO "prefix-\c" >$ff
3798 if ! echo "$da" |$CMD >$tf 2>"$te" ||
3799 ! echo "$da" |diff - $ff >"$tdiff"; then
3800 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3801 echo "$CMD"
3802 cat "$te"
3803 cat "$tdiff"
3804 numFAIL=$((numFAIL+1))
3805 listFAIL="$listFAIL $N"
3806 else
3807 $PRINTF "$OK\n"
3808 if [ -n "$debug" ]; then cat $te; fi
3809 numOK=$((numOK+1))
3810 fi
3811 fi ;; # NUMCOND
3812 esac
3813 N=$((N+1))
3814  
3815  
3816 NAME=RIGHTTOLEFT
3817 case "$TESTS" in
3818 *%$N%*|*%functions%*|*%$NAME%*)
3819 TEST="$NAME: unidirectional throughput from stdin to stdout, right to left"
3820 testecho "$N" "$TEST" "stdout" "stdin" "$opts -U"
3821 esac
3822 N=$((N+1))
3823  
3824  
3825 NAME=CHILDDEFAULT
3826 case "$TESTS" in
3827 *%$N%*|*%functions%*|*%$NAME%*)
3828 if ! eval $NUMCOND; then :; else
3829 TEST="$NAME: child process default properties"
3830 tf="$td/test$N.stdout"
3831 te="$td/test$N.stderr"
3832 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN -"
3833 printf "test $F_n $TEST... " $N
3834 $CMD >$tf 2>$te
3835 MYPID=`expr "\`grep "process id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3836 MYPPID=`expr "\`grep "process parent id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3837 MYPGID=`expr "\`grep "process group id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3838 MYSID=`expr "\`grep "process session id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3839 #echo "PID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3840 if [ "$MYPID" = "$MYPPID" -o "$MYPID" = "$MYPGID" -o "$MYPID" = "$MYSID" -o \
3841 "$MYPPID" = "$MYPGID" -o "$MYPPID" = "$MYSID" -o "$MYPGID" = "$MYSID" ];
3842 then
3843 $PRINTF "$FAILED:\n"
3844 echo "$CMD"
3845 cat "$te"
3846 numFAIL=$((numFAIL+1))
3847 listFAIL="$listFAIL $N"
3848 else
3849 $PRINTF "$OK\n"
3850 numOK=$((numOK+1))
3851 fi
3852 fi ;; # NUMCOND
3853 esac
3854 N=$((N+1))
3855  
3856  
3857 NAME=CHILDSETSID
3858 case "$TESTS" in
3859 *%$N%*|*%functions%*|*%$NAME%*)
3860 TEST="$NAME: child process with setsid"
3861 if ! eval $NUMCOND; then :; else
3862 tf="$td/test$N.stdout"
3863 te="$td/test$N.stderr"
3864 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN,setsid -"
3865 printf "test $F_n $TEST... " $N
3866 $CMD >$tf 2>$te
3867 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3868 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3869 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3870 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3871 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3872 # PID, PGID, and SID must be the same
3873 if [ "$MYPID" = "$MYPPID" -o \
3874 "$MYPID" != "$MYPGID" -o "$MYPID" != "$MYSID" ];
3875 then
3876 $PRINTF "$FAILED\n"
3877 echo "$CMD"
3878 cat "$te"
3879 numFAIL=$((numFAIL+1))
3880 listFAIL="$listFAIL $N"
3881 else
3882 $PRINTF "$OK\n"
3883 numOK=$((numOK+1))
3884 fi
3885 fi ;; # NUMCOND
3886 esac
3887 N=$((N+1))
3888  
3889  
3890 NAME=MAINSETSID
3891 case "$TESTS" in
3892 *%$N%*|*%functions%*|*%$NAME%*)
3893 TEST="$NAME: main process with setsid"
3894 if ! eval $NUMCOND; then :; else
3895 tf="$td/test$N.stdout"
3896 te="$td/test$N.stderr"
3897 CMD="$TRACE $SOCAT $opts -U -,setsid exec:$PROCAN"
3898 printf "test $F_n $TEST... " $N
3899 $CMD >$tf 2>$te
3900 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3901 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3902 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3903 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3904 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3905 # PPID, PGID, and SID must be the same
3906 if [ "$MYPID" = "$MYPPID" -o \
3907 "$MYPPID" != "$MYPGID" -o "$MYPPID" != "$MYSID" ];
3908 then
3909 $PRINTF "$FAILED\n"
3910 echo "$CMD"
3911 cat "$te"
3912 numFAIL=$((numFAIL+1))
3913 listFAIL="$listFAIL $N"
3914 else
3915 $PRINTF "$OK\n"
3916 numOK=$((numOK+1))
3917 fi
3918 fi ;; # NUMCOND
3919 esac
3920 N=$((N+1))
3921  
3922  
3923 NAME=CHAIN
3924 case "$TESTS" in
3925 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3926 TEST="$NAME: stdio to test+pipe"
3927 testchain "$N" "$TEST" "stdio" "test|pipe" "$opts" "><"
3928 esac
3929 N=$((N+1))
3930  
3931 NAME=REVCHAIN
3932 case "$TESTS" in
3933 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3934 TEST="$NAME: stdio to rev.test+pipe"
3935 testchain "$N" "$TEST" "stdio" "^test|pipe" "$opts" "<>"
3936 esac
3937 N=$((N+1))
3938  
3939 NAME=TWOCHAINS
3940 case "$TESTS" in
3941 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3942 TEST="$NAME: test+stdio vs. test+pipe"
3943 testchain "$N" "$TEST" "test|stdio" "test|pipe" "$opts" "<><>"
3944 esac
3945 N=$((N+1))
3946  
3947 NAME=TWOREVCHAINS
3948 case "$TESTS" in
3949 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3950 TEST="$NAME: rev.test+stdio vs. rev.test+pipe"
3951 testchain "$N" "$TEST" "^test|stdio" "^test|pipe" "$opts" "><><"
3952 esac
3953 N=$((N+1))
3954  
3955 NAME=LONGCHAIN
3956 case "$TESTS" in
3957 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3958 TEST="$NAME: stdio vs. four-tests+pipe"
3959 testchain "$N" "$TEST" "stdio" "test|^test|test|^test|pipe" "$opts" "><><><><"
3960 esac
3961 N=$((N+1))
3962  
3963 NAME=LONGLEFTCHAIN
3964 case "$TESTS" in
3965 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3966 TEST="$NAME: four-tests+pipe vs. stdio"
3967 testchain "$N" "$TEST" "test|^test|test|^test|test|^test|test|^test|stdio" "pipe" "$opts" "><><><><><><><><"
3968 esac
3969 N=$((N+1))
3970  
3971 NAME=TWOLONGCHAINS
3972 case "$TESTS" in
3973 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3974 TEST="$NAME: four-tests+stdio vs. four-tests+pipe"
3975 testchain "$N" "$TEST" "^test|test|^test|test|stdio" "test|^test|test|^test|pipe" "$opts" "<><>><><><><<><>"
3976 esac
3977 N=$((N+1))
3978  
3979 NAME=CHAINSPACES
3980 case "$TESTS" in
3981 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3982 TEST="$NAME: lot of test with spaces"
3983 testchain "$N" "$TEST" " ^ test | test | ^ test | test | stdio " " test | ^ test | test | ^ test | pipe " "$opts" "<><>><><><><<><>"
3984 esac
3985 N=$((N+1))
3986  
3987 NAME=CHAINUNIDIR
3988 case "$TESTS" in
3989 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3990 TEST="$NAME: two unidirectional chains"
3991 # on Linux (Debian lenny/sid) we need MISCDELAY due to a weakness/bug
3992 testchain "$N" "$TEST" "test|stdin" "test|stdout" "-u $opts" "<>" "$val_t"
3993 esac
3994 N=$((N+1))
3995  
3996 NAME=CHAINREVDIR
3997 case "$TESTS" in
3998 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
3999 TEST="$NAME: two unidirectional chains, right to left"
4000 testchain "$N" "$TEST" "^test|stdout" "^test|stdin" "-U $opts" "><" "$val_t"
4001 esac
4002 N=$((N+1))
4003  
4004 NAME=CHAINDUAL
4005 case "$TESTS" in
4006 *%$N%*|*%functions%*|*%chain%*|*%dual%*|*%$NAME%*)
4007 TEST="$NAME: bidirectional dual chain (uni/rev)"
4008 testchain "$N" "$TEST" "stdio" "testuni%testrev|pipe" "$opts" "><"
4009 esac
4010 N=$((N+1))
4011  
4012 NAME=CHAINDUAL2
4013 case "$TESTS" in
4014 *%$N%*|*%functions%*|*%chain%*|*%dual%*|*%$NAME%*)
4015 TEST="$NAME: bidirectional dual chain (bi/rev)"
4016 testchain "$N" "$TEST" "stdio" "test%testrev|pipe" "$opts" "><"
4017 esac
4018 N=$((N+1))
4019  
4020 NAME=CHAINDUAL3
4021 case "$TESTS" in
4022 *%$N%*|*%functions%*|*%chain%*|*%dual%*|*%$NAME%*)
4023 TEST="$NAME: bidirectional dual chain (uni/bi)"
4024 testchain "$N" "$TEST" "stdio" "testuni%^test|pipe" "$opts" "><"
4025 esac
4026 N=$((N+1))
4027  
4028 NAME=CHAINDUAL4
4029 case "$TESTS" in
4030 *%$N%*|*%functions%*|*%chain%*|*%dual%*|*%$NAME%*)
4031 TEST="$NAME: bidirectional dual chain (bi/bi)"
4032 testchain "$N" "$TEST" "stdio" "test%^test|pipe" "$opts" "><"
4033 esac
4034 N=$((N+1))
4035  
4036 NAME=CHAINDUAL5
4037 case "$TESTS" in
4038 *%$N%*|*%functions%*|*%chain%*|*%dual%*|*%$NAME%*)
4039 TEST="$NAME: bidirectional mixed normal and dual chains"
4040 testchain "$N" "$TEST" "test|test%^test|^test|stdio" "^test|testuni%testrev|test|pipe" "$opts" "><<<>><<>>><"
4041 esac
4042 N=$((N+1))
4043  
4044  
4045 NAME=OPENSSL_TCP4
4046 case "$TESTS" in
4047 *%$N%*|*%functions%*|*%chain%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4048 TEST="$NAME: openssl connect"
4049 if ! eval $NUMCOND; then :;
4050 elif ! testaddrs openssl >/dev/null; then
4051 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4052 numCANT=$((numCANT+1))
4053 elif ! type openssl >/dev/null 2>&1; then
4054 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
4055 numCANT=$((numCANT+1))
4056 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4057 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4058 numCANT=$((numCANT+1))
4059 else
4060 gentestcert testsrv
4061 tf="$td/test$N.stdout"
4062 te="$td/test$N.stderr"
4063 tdiff="$td/test$N.diff"
4064 da="test$N $(date) $RANDOM"
4065 CMD2="$TRACE $SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe"
4066 #! CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT"
4067 #CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4068 CMD="$TRACE $SOCAT $opts - openssl,verify=0,$SOCAT_EGD|tcp4:$LOCALHOST:$PORT"
4069 printf "test $F_n $TEST... " $N
4070 eval "$CMD2 2>\"${te}1\" &"
4071 pid=$! # background process id
4072 # this might timeout when openssl opens tcp46 port like " :::$PORT"
4073 waittcp4port $PORT
4074 # the openssl s_server program appears to not support half closed connections,
4075 # so we must delay EOF
4076 (echo "$da"; sleep 1) |$CMD >$tf 2>"${te}2"
4077 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4078 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4079 echo "$CMD2 &"
4080 echo "$CMD"
4081 cat "${te}1"
4082 cat "${te}2"
4083 cat "$tdiff"
4084 numFAIL=$((numFAIL+1))
4085 listFAIL="$listFAIL $N"
4086 else
4087 $PRINTF "$OK\n"
4088 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4089 numOK=$((numOK+1))
4090 fi
4091 kill $pid 2>/dev/null; wait
4092 fi ;; # NUMCOND, feats
4093 esac
4094 PORT=$((PORT+1))
4095 N=$((N+1))
4096  
4097  
4098 NAME=OPENSSLLISTEN_TCP4
4099 case "$TESTS" in
4100 *%$N%*|*%functions%*|*%chain%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4101 TEST="$NAME: openssl listen"
4102 if ! eval $NUMCOND; then :;
4103 elif ! testaddrs openssl >/dev/null; then
4104 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4105 numCANT=$((numCANT+1))
4106 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4107 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4108 numCANT=$((numCANT+1))
4109 else
4110 gentestcert testsrv
4111 tf="$td/test$N.stdout"
4112 te="$td/test$N.stderr"
4113 tdiff="$td/test$N.diff"
4114 da="test$N $(date) $RANDOM"
4115 #CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4116 CMD2="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr ^OPENSSL-LISTEN,$SOCAT_EGD',cert=testsrv.crt,key=testsrv.key,verify=0|pipe'"
4117 #CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,,verify=0,$SOCAT_EGD"
4118 CMD="$TRACE $SOCAT $opts - openssl,verify=0,$SOCAT_EGD|tcp4:$LOCALHOST:$PORT"
4119 printf "test $F_n $TEST... " $N
4120 eval "$CMD2 2>\"${te}1\" &"
4121 pid=$! # background process id
4122 waittcp4port $PORT
4123 echo "$da" |$CMD >$tf 2>"${te}2"
4124 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4125 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4126 echo "$CMD2 &"
4127 echo "$CMD"
4128 cat "${te}1"
4129 cat "${te}2"
4130 cat "$tdiff"
4131 numFAIL=$((numFAIL+1))
4132 listFAIL="$listFAIL $N"
4133 else
4134 $PRINTF "$OK\n"
4135 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4136 numOK=$((numOK+1))
4137 fi
4138 kill $pid 2>/dev/null
4139 wait
4140 fi ;; # NUMCOND, feats
4141 esac
4142 PORT=$((PORT+1))
4143 N=$((N+1))
4144  
4145 NAME=OPENSSLLISTEN_TCP6
4146 case "$TESTS" in
4147 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4148 TEST="$NAME: openssl listen"
4149 if ! eval $NUMCOND; then :;
4150 elif ! testaddrs openssl >/dev/null; then
4151 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4152 numCANT=$((numCANT+1))
4153 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4154 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4155 numCANT=$((numCANT+1))
4156 else
4157 gentestcert testsrv
4158 tf="$td/test$N.stdout"
4159 te="$td/test$N.stderr"
4160 tdiff="$td/test$N.diff"
4161 da="test$N $(date) $RANDOM"
4162 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4163 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD"
4164 printf "test $F_n $TEST... " $N
4165 eval "$CMD2 2>\"${te}1\" &"
4166 pid=$! # background process id
4167 waittcp6port $PORT
4168 echo "$da" |$CMD >$tf 2>"${te}2"
4169 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4170 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4171 echo "$CMD2 &"
4172 echo "$CMD"
4173 cat "${te}1"
4174 cat "${te}2"
4175 cat "$tdiff"
4176 numFAIL=$((numFAIL+1))
4177 listFAIL="$listFAIL $N"
4178 else
4179 $PRINTF "$OK\n"
4180 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4181 numOK=$((numOK+1))
4182 fi
4183 kill $pid 2>/dev/null
4184 wait
4185 fi ;; # NUMCOND, feats
4186 esac
4187 PORT=$((PORT+1))
4188 N=$((N+1))
4189  
4190  
4191 while read NAMEKEYW FEAT RUNS TESTTMPL PEERTMPL WAITTMPL; do
4192 if [ -z "$NAMEKEYW" ] || [[ "$NAMEKEYW" == \#* ]]; then continue; fi
4193  
4194 export ts="$td/test$N.socket"
4195 WAITTMPL="$(echo "$WAITTMPL" |sed -e 's/\040/ /g')"
4196 TESTADDR=$(eval echo $TESTTMPL)
4197 PEERADDR=$(eval echo $PEERTMPL)
4198 WAITCMD=$(eval echo $WAITTMPL)
4199 TESTKEYW=${TESTADDR%%:*}
4200  
4201 # does our address implementation support halfclose?
4202 NAME=${NAMEKEYW}_HALFCLOSE
4203 case "$TESTS" in
4204 *%$N%*|*%functions%*|*%$FEAT%*|*%socket%*|*%halfclose%*|*%$NAME%*)
4205 TEST="$NAME: $TESTKEYW half close"
4206 # have a "peer" socat "peer" that executes "$OD_C" and see if EOF on the
4207 # connecting socat brings the result of od
4208 if ! eval $NUMCOND; then :;
4209 elif [ "$FEAT" != ',' ] && ! testaddrs "$FEAT" >/dev/null; then
4210 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
4211 numCANT=$((numCANT+1))
4212 elif ! runs$RUNS; then
4213 $PRINTF "test $F_n $TEST... ${YELLOW}$RUNS not available${NORMAL}\n" $N
4214 numCANT=$((numCANT+1))
4215 else
4216 tf="$td/test$N.stdout"
4217 te="$td/test$N.stderr"
4218 tdiff="$td/test$N.diff"
4219 da="test$N $(date) $RANDOM"
4220 CMD2="$TRACE $SOCAT $opts \"$PEERADDR\" EXEC:'$OD_C'"
4221 CMD="$TRACE $SOCAT -T1 $opts - $TESTADDR"
4222 printf "test $F_n $TEST... " $N
4223 eval "$CMD2 2>\"${te}1\" &"
4224 pid=$! # background process id
4225 $WAITCMD
4226 echo "$da" |$CMD >$tf 2>"${te}2"
4227 if ! echo "$da" |$OD_C |diff - "$tf" >"$tdiff"; then
4228 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4229 echo "$CMD2 &"
4230 echo "$CMD"
4231 cat "${te}1"
4232 cat "${te}2"
4233 cat "$tdiff"
4234 numFAIL=$((numFAIL+1))
4235 listFAIL="$listFAIL $N"
4236 else
4237 $PRINTF "$OK\n"
4238 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4239 numOK=$((numOK+1))
4240 fi
4241 kill $pid 2>/dev/null
4242 wait
4243 fi ;; # NUMCOND, feats
4244 esac
4245 PORT=$((PORT+1))
4246 N=$((N+1))
4247  
4248 done <<<"
4249 UNIXCONNECT , unix UNIX-CONNECT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4250 UNIXCLIENT , unix UNIX-CLIENT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4251 GOPEN_UNIXSTREAM , unix GOPEN:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4252 UNIXLISTEN , unix UNIX-LISTEN:\$ts UNIX-CONNECT:\$ts,retry=3 sleep\040\1
4253 TCP4CONNECT , tcp4 TCP4-CONNECT:\$LOCALHOST:\$PORT TCP4-LISTEN:\$PORT waittcp4port\040\$PORT
4254 TCP4LISTEN , tcp4 TCP4-LISTEN:\$PORT TCP4-CONNECT:\$LOCALHOST:\$PORT,retry=3
4255 TCP6CONNECT , tcp6 TCP6-CONNECT:\$LOCALHOST6:\$PORT TCP6-LISTEN:\$PORT waittcp6port\040\$PORT
4256 TCP6LISTEN , tcp6 TCP6-LISTEN:\$PORT TCP6-CONNECT:\$LOCALHOST6:\$PORT,retry=3
4257 OPENSSL4CLIENT OPENSSL tcp4 OPENSSL:\$LOCALHOST:\$PORT,verify=0 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp4port\040\$PORT
4258 OPENSSL4SERVER OPENSSL tcp4 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST:\$PORT,verify=0,retry=3
4259 OPENSSL6CLIENT OPENSSL tcp6 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp6port\040\$PORT
4260 OPENSSL6SERVER OPENSSL tcp6 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0,retry=3
4261 "
4262  
4263  
4264 NAME=OPENSSL_SERVERAUTH
4265 case "$TESTS" in
4266 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4267 TEST="$NAME: openssl server authentication"
4268 if ! eval $NUMCOND; then :;
4269 elif ! testaddrs openssl >/dev/null; then
4270 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4271 numCANT=$((numCANT+1))
4272 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4273 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4274 numCANT=$((numCANT+1))
4275 else
4276 gentestcert testsrv
4277 gentestcert testcli
4278 tf="$td/test$N.stdout"
4279 te="$td/test$N.stderr"
4280 tdiff="$td/test$N.diff"
4281 da="test$N $(date) $RANDOM"
4282 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4283 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD"
4284 printf "test $F_n $TEST... " $N
4285 eval "$CMD2 2>\"${te}1\" &"
4286 pid=$! # background process id
4287 waittcp4port $PORT
4288 echo "$da" |$CMD >$tf 2>"${te}2"
4289 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4290 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4291 echo "$CMD2 &"
4292 echo "$CMD"
4293 cat "${te}1"
4294 cat "${te}2"
4295 cat "$tdiff"
4296 numFAIL=$((numFAIL+1))
4297 listFAIL="$listFAIL $N"
4298 else
4299 $PRINTF "$OK\n"
4300 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4301 numOK=$((numOK+1))
4302 fi
4303 kill $pid 2>/dev/null
4304 wait
4305 fi ;; # NUMCOND, feats
4306 esac
4307 PORT=$((PORT+1))
4308 N=$((N+1))
4309  
4310 NAME=OPENSSL_CLIENTAUTH
4311 case "$TESTS" in
4312 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4313 TEST="$NAME: openssl client authentication"
4314 if ! eval $NUMCOND; then :;
4315 elif ! testaddrs openssl >/dev/null; then
4316 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4317 numCANT=$((numCANT+1))
4318 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4319 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4320 numCANT=$((numCANT+1))
4321 else
4322 gentestcert testsrv
4323 gentestcert testcli
4324 tf="$td/test$N.stdout"
4325 te="$td/test$N.stderr"
4326 tdiff="$td/test$N.diff"
4327 da="test$N $(date) $RANDOM"
4328 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe"
4329 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD"
4330 printf "test $F_n $TEST... " $N
4331 eval "$CMD2 2>\"${te}1\" &"
4332 pid=$! # background process id
4333 waittcp4port $PORT
4334 echo "$da" |$CMD >$tf 2>"${te}2"
4335 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4336 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4337 echo "$CMD2 &"
4338 echo "$CMD"
4339 cat "${te}1"
4340 cat "${te}2"
4341 cat "$tdiff"
4342 numFAIL=$((numFAIL+1))
4343 listFAIL="$listFAIL $N"
4344 else
4345 $PRINTF "$OK\n"
4346 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4347 numOK=$((numOK+1))
4348 fi
4349 kill $pid 2>/dev/null
4350 wait
4351 fi ;; # NUMCOND, feats
4352 esac
4353 PORT=$((PORT+1))
4354 N=$((N+1))
4355  
4356 NAME=OPENSSL_FIPS_BOTHAUTH
4357 case "$TESTS" in
4358 *%$N%*|*%functions%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4359 TEST="$NAME: OpenSSL+FIPS client and server authentication"
4360 if ! eval $NUMCOND; then :;
4361 elif ! testaddrs openssl >/dev/null; then
4362 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4363 numCANT=$((numCANT+1))
4364 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4365 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4366 numCANT=$((numCANT+1))
4367 elif ! testoptions fips >/dev/null; then
4368 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
4369 numCANT=$((numCANT+1))
4370 else
4371 OPENSSL_FIPS=1 gentestcert testsrvfips
4372 OPENSSL_FIPS=1 gentestcert testclifips
4373 tf="$td/test$N.stdout"
4374 te="$td/test$N.stderr"
4375 tdiff="$td/test$N.diff"
4376 da="test$N $(date) $RANDOM"
4377 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe"
4378 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD"
4379 printf "test $F_n $TEST... " $N
4380 eval "$CMD2 2>\"${te}1\" &"
4381 pid=$! # background process id
4382 waittcp4port $PORT
4383 echo "$da" |$CMD >$tf 2>"${te}2"
4384 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4385 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4386 echo "$CMD2 &"
4387 echo "$CMD"
4388 cat "${te}1"
4389 cat "${te}2"
4390 cat "$tdiff"
4391 numFAIL=$((numFAIL+1))
4392 listFAIL="$listFAIL $N"
4393 else
4394 $PRINTF "$OK\n"
4395 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4396 numOK=$((numOK+1))
4397 fi
4398 kill $pid 2>/dev/null
4399 wait
4400 fi ;; # NUMCOND, feats
4401 esac
4402 PORT=$((PORT+1))
4403 N=$((N+1))
4404  
4405  
4406 NAME=OPENSSL_COMPRESS
4407 case "$TESTS" in
4408 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4409 TEST="$NAME: OpenSSL compression"
4410 if ! eval $NUMCOND; then :;
4411 elif ! testaddrs openssl >/dev/null; then
4412 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4413 numCANT=$((numCANT+1))
4414 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4415 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4416 numCANT=$((numCANT+1))
4417 elif ! testoptions openssl-compress >/dev/null; then
4418 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL compression option not available${NORMAL}\n" $N
4419 numCANT=$((numCANT+1))
4420 else
4421 gentestcert testsrv
4422 printf "test $F_n $TEST... " $N
4423 tf="$td/test$N.stdout"
4424 te="$td/test$N.stderr"
4425 tdiff="$td/test$N.diff"
4426 da="test$N $(date) $RANDOM"
4427 success=yes
4428 for srccompr in '' compress=auto compress=none; do
4429 for dstcompr in '' compress=auto compress=none; do
4430 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0,$dstcompr pipe"
4431 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD,$srccompr"
4432 eval "$CMD2 2>\"${te}1\" &"
4433 pid=$! # background process id
4434 waittcp4port $PORT
4435 echo "$da" | $CMD >$tf 2>"${te}2"
4436 kill $pid 2>/dev/null
4437 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4438 success=
4439 break
4440 fi
4441 done
4442 done
4443 if test -z "$success"; then
4444 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4445 echo "$CMD2 &"
4446 echo "$CMD"
4447 cat "${te}1"
4448 cat "${te}2"
4449 cat "$tdiff"
4450 numFAIL=$((numFAIL+1))
4451 listFAIL="$listFAIL $N"
4452 else
4453 $PRINTF "$OK\n"
4454 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4455 numOK=$((numOK+1))
4456 fi
4457 fi ;; # NUMCOND, feats
4458 esac
4459 PORT=$((PORT+1))
4460 N=$((N+1))
4461  
4462  
4463 NAME=SOCKS4CONNECT_TCP4
4464 case "$TESTS" in
4465 *%$N%*|*%functions%*|*%chain%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4466 TEST="$NAME: socks4 connect over TCP/IPv4"
4467 if ! eval $NUMCOND; then :;
4468 elif ! testaddrs socks4 >/dev/null; then
4469 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4470 numCANT=$((numCANT+1))
4471 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4472 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4473 numCANT=$((numCANT+1))
4474 else
4475 tf="$td/test$N.stdout"
4476 te="$td/test$N.stderr"
4477 tdiff="$td/test$N.diff"
4478 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4479 # we have a normal tcp echo listening - so the socks header must appear in answer
4480 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr exec:\"./socks4echo.sh\""
4481 #CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4482 CMD="$TRACE $SOCAT $opts - socks4:32.98.76.54:32109,socksuser=nobody|tcp4:$LOCALHOST:$PORT"
4483 printf "test $F_n $TEST... " $N
4484 eval "$CMD2 2>\"${te}1\" &"
4485 pid=$! # background process id
4486 waittcp4port $PORT 1
4487 echo "$da" |$CMD >$tf 2>"${te}2"
4488 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4489 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4490 echo "$CMD2 &"
4491 echo "$CMD"
4492 cat "${te}1"
4493 cat "${te}2"
4494 cat "$tdiff"
4495 numFAIL=$((numFAIL+1))
4496 listFAIL="$listFAIL $N"
4497 else
4498 $PRINTF "$OK\n"
4499 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4500 numOK=$((numOK+1))
4501 fi
4502 kill $pid 2>/dev/null
4503 wait
4504 fi ;; # NUMCOND, feats
4505 esac
4506 PORT=$((PORT+1))
4507 N=$((N+1))
4508  
4509 NAME=SOCKS4CONNECT_TCP6
4510 case "$TESTS" in
4511 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4512 TEST="$NAME: socks4 connect over TCP/IPv6"
4513 if ! eval $NUMCOND; then :;
4514 elif ! testaddrs socks4 >/dev/null; then
4515 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4516 numCANT=$((numCANT+1))
4517 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4518 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4519 numCANT=$((numCANT+1))
4520 else
4521 tf="$td/test$N.stdout"
4522 te="$td/test$N.stderr"
4523 tdiff="$td/test$N.diff"
4524 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4525 # we have a normal tcp echo listening - so the socks header must appear in answer
4526 CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,reuseaddr exec:\"./socks4echo.sh\""
4527 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser="nobody"
4528 printf "test $F_n $TEST... " $N
4529 eval "$CMD2 2>\"${te}1\" &"
4530 pid=$! # background process id
4531 waittcp6port $PORT 1
4532 echo "$da" |$CMD >$tf 2>"${te}2"
4533 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4534 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4535 echo "$CMD2 &"
4536 echo "$CMD"
4537 cat "${te}1"
4538 cat "${te}2"
4539 cat "$tdiff"
4540 numFAIL=$((numFAIL+1))
4541 listFAIL="$listFAIL $N"
4542 else
4543 $PRINTF "$OK\n"
4544 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4545 numOK=$((numOK+1))
4546 fi
4547 kill $pid 2>/dev/null
4548 wait
4549 fi ;; # NUMCOND, feats
4550 esac
4551 PORT=$((PORT+1))
4552 N=$((N+1))
4553  
4554  
4555 NAME=SOCKS4ACONNECT_TCP4
4556 case "$TESTS" in
4557 *%$N%*|*%functions%*|*%chain%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4558 TEST="$NAME: socks4a connect over TCP/IPv4"
4559 if ! eval $NUMCOND; then :;
4560 elif ! testaddrs socks4a >/dev/null; then
4561 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4562 numCANT=$((numCANT+1))
4563 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4564 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4565 numCANT=$((numCANT+1))
4566 else
4567 tf="$td/test$N.stdout"
4568 te="$td/test$N.stderr"
4569 tdiff="$td/test$N.diff"
4570 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4571 # we have a normal tcp echo listening - so the socks header must appear in answer
4572 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr exec:\"./socks4a-echo.sh\""
4573 #CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4574 CMD="$TRACE $SOCAT $opts - socks4a:localhost:32109,socksuser=nobody|tcp4:$LOCALHOST:$PORT"
4575 printf "test $F_n $TEST... " $N
4576 eval "$CMD2 2>\"${te}1\" &"
4577 pid=$! # background process id
4578 waittcp4port $PORT 1
4579 echo "$da" |$CMD >$tf 2>"${te}2"
4580 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4581 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4582 echo "$CMD2 &"
4583 echo "$CMD"
4584 cat "${te}1"
4585 cat "${te}2"
4586 cat "$tdiff"
4587 numFAIL=$((numFAIL+1))
4588 listFAIL="$listFAIL $N"
4589 else
4590 $PRINTF "$OK\n"
4591 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4592 numOK=$((numOK+1))
4593 fi
4594 kill $pid 2>/dev/null
4595 wait
4596 fi ;; # NUMCOND, feats
4597 esac
4598 PORT=$((PORT+1))
4599 N=$((N+1))
4600  
4601 NAME=SOCKS4ACONNECT_TCP6
4602 case "$TESTS" in
4603 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4604 TEST="$NAME: socks4a connect over TCP/IPv6"
4605 if ! eval $NUMCOND; then :;
4606 elif ! testaddrs socks4a >/dev/null; then
4607 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4608 numCANT=$((numCANT+1))
4609 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4610 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4611 numCANT=$((numCANT+1))
4612 else
4613 tf="$td/test$N.stdout"
4614 te="$td/test$N.stderr"
4615 tdiff="$td/test$N.diff"
4616 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4617 # we have a normal tcp echo listening - so the socks header must appear in answer
4618 CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,reuseaddr exec:\"./socks4a-echo.sh\""
4619 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser="nobody"
4620 printf "test $F_n $TEST... " $N
4621 eval "$CMD2 2>\"${te}1\" &"
4622 pid=$! # background process id
4623 waittcp6port $PORT 1
4624 echo "$da" |$CMD >$tf 2>"${te}2"
4625 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4626 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4627 echo "$CMD2 &"
4628 echo "$CMD"
4629 cat "${te}1"
4630 cat "${te}2"
4631 cat "$tdiff"
4632 numFAIL=$((numFAIL+1))
4633 listFAIL="$listFAIL $N"
4634 else
4635 $PRINTF "$OK\n"
4636 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4637 numOK=$((numOK+1))
4638 fi
4639 kill $pid 2>/dev/null
4640 wait
4641 fi ;; # NUMCOND, feats
4642 esac
4643 PORT=$((PORT+1))
4644 N=$((N+1))
4645  
4646  
4647 NAME=PROXYCONNECT_TCP4
4648 case "$TESTS" in
4649 *%$N%*|*%functions%*|*%chain%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4650 TEST="$NAME: proxy connect over TCP/IPv4"
4651 if ! eval $NUMCOND; then :;
4652 elif ! testaddrs proxy >/dev/null; then
4653 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4654 numCANT=$((numCANT+1))
4655 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4656 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4657 numCANT=$((numCANT+1))
4658 else
4659 ts="$td/test$N.sh"
4660 tf="$td/test$N.stdout"
4661 te="$td/test$N.stderr"
4662 tdiff="$td/test$N.diff"
4663 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4664 #CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,crlf system:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4665 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh\""
4666 #CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4667 CMD="$TRACE $SOCAT $opts - proxy:127.0.0.1:1000|tcp4:$LOCALHOST:$PORT"
4668 printf "test $F_n $TEST... " $N
4669 eval "$CMD2 2>\"${te}2\" &"
4670 pid=$! # background process id
4671 waittcp4port $PORT 1
4672 echo "$da" |$CMD >"$tf" 2>"${te}1"
4673 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4674 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4675 echo "$CMD2 &"
4676 echo "$CMD"
4677 cat "${te}1"
4678 cat "${te}2"
4679 cat "$tdiff"
4680 numFAIL=$((numFAIL+1))
4681 listFAIL="$listFAIL $N"
4682 else
4683 $PRINTF "$OK\n"
4684 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4685 numOK=$((numOK+1))
4686 fi
4687 kill $pid 2>/dev/null
4688 wait
4689 fi ;; # NUMCOND, feats
4690 esac
4691 PORT=$((PORT+1))
4692 N=$((N+1))
4693  
4694 NAME=PROXYCONNECT_TCP6
4695 case "$TESTS" in
4696 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4697 TEST="$NAME: proxy connect over TCP/IPv6"
4698 if ! eval $NUMCOND; then :;
4699 elif ! testaddrs proxy >/dev/null; then
4700 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4701 numCANT=$((numCANT+1))
4702 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4703 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4704 numCANT=$((numCANT+1))
4705 else
4706 ts="$td/test$N.sh"
4707 tf="$td/test$N.stdout"
4708 te="$td/test$N.stderr"
4709 tdiff="$td/test$N.diff"
4710 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4711 #CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,crlf system:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4712 CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh\""
4713 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT"
4714 printf "test $F_n $TEST... " $N
4715 eval "$CMD2 2>\"${te}2\" &"
4716 pid=$! # background process id
4717 waittcp6port $PORT 1
4718 echo "$da" |$CMD >"$tf" 2>"${te}1"
4719 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4720 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4721 echo "$CMD2 &"
4722 echo "$CMD"
4723 cat "${te}1"
4724 cat "${te}2"
4725 cat "$tdiff"
4726 numFAIL=$((numFAIL+1))
4727 listFAIL="$listFAIL $N"
4728 else
4729 $PRINTF "$OK\n"
4730 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4731 numOK=$((numOK+1))
4732 fi
4733 kill $pid 2>/dev/null
4734 wait
4735 fi ;; # NUMCOND, feats
4736 esac
4737 PORT=$((PORT+1))
4738 N=$((N+1))
4739  
4740  
4741 NAME=TCP4NOFORK
4742 case "$TESTS" in
4743 *%$N%*|*%functions%*|*%$NAME%*)
4744 TEST="$NAME: echo via connection to TCP V4 socket with nofork'ed exec"
4745 if ! eval $NUMCOND; then :; else
4746 tf="$td/test$N.stdout"
4747 te="$td/test$N.stderr"
4748 tdiff="$td/test$N.diff"
4749 tsl=$PORT
4750 ts="127.0.0.1:$tsl"
4751 da="test$N $(date) $RANDOM"
4752 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr exec:$CAT,nofork"
4753 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
4754 printf "test $F_n $TEST... " $N
4755 #$CMD1 >"$tf" 2>"${te}1" &
4756 $CMD1 >/dev/null 2>"${te}1" &
4757 waittcp4port $tsl
4758 #usleep $MICROS
4759 echo "$da" |$CMD2 >"$tf" 2>>"${te}2"
4760 if [ $? -ne 0 ]; then
4761 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4762 echo "$CMD1 &"
4763 echo "$CMD2"
4764 cat "${te}1"
4765 cat "${te}2"
4766 numFAIL=$((numFAIL+1))
4767 listFAIL="$listFAIL $N"
4768 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
4769 $PRINTF "$FAILED\n"
4770 cat "$tdiff"
4771 numFAIL=$((numFAIL+1))
4772 listFAIL="$listFAIL $N"
4773 else
4774 $PRINTF "$OK\n"
4775 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4776 numOK=$((numOK+1))
4777 fi
4778 fi ;; # NUMCOND
4779 esac
4780 PORT=$((PORT+1))
4781 N=$((N+1))
4782  
4783  
4784 NAME=EXECCATNOFORK
4785 case "$TESTS" in
4786 *%$N%*|*%functions%*|*%$NAME%*)
4787 TEST="$NAME: simple echo via exec of cat with nofork"
4788 testecho "$N" "$TEST" "" "exec:$CAT,nofork" "$opts"
4789 esac
4790 N=$((N+1))
4791  
4792  
4793 NAME=SYSTEMCATNOFORK
4794 case "$TESTS" in
4795 *%$N%*|*%functions%*|*%$NAME%*)
4796 TEST="$NAME: simple echo via system() of cat with nofork"
4797 testecho "$N" "$TEST" "" "system:$CAT,nofork" "$opts"
4798 esac
4799 N=$((N+1))
4800  
4801  
4802 NAME=NOFORKSETSID
4803 case "$TESTS" in
4804 *%$N%*|*%functions%*|*%$NAME%*)
4805 TEST="$NAME: simple echo via exec() of cat with nofork and setsid"
4806 testecho "$N" "$TEST" "" "system:$CAT,nofork,setsid" "$opts"
4807 esac
4808 N=$((N+1))
4809  
4810 #==============================================================================
4811 #TEST="$NAME: echo via 'connection' to UDP V4 socket"
4812 #if ! eval $NUMCOND; then :; else
4813 #tf="$td/file$N"
4814 #tsl=65534
4815 #ts="127.0.0.1:$tsl"
4816 #da="test$N $(date) $RANDOM"
4817 #$TRACE $SOCAT UDP-listen:$tsl PIPE &
4818 #sleep 2
4819 #echo "$da" |$TRACE $SOCAT stdout%stdin UDP:$ts >"$tf"
4820 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4821 # $ECHO "... test $N succeeded"
4822 # numOK=$((numOK+1))
4823 #else
4824 # $ECHO "*** test $N $FAILED"
4825 # numFAIL=$((numFAIL+1))
4826 # listFAIL="$listFAIL $N"
4827 #fi
4828 #fi ;; # NUMCOND
4829 #N=$((N+1))
4830 #==============================================================================
4831 # TEST 4 - simple echo via new file
4832 #if ! eval $NUMCOND; then :; else
4833 #N=4
4834 #tf="$td/file$N"
4835 #tp="$td/pipe$N"
4836 #da="test$N $(date) $RANDOM"
4837 #rm -f "$tf.tmp"
4838 #echo "$da" |$TRACE $SOCAT - FILE:$tf.tmp,ignoreeof >"$tf"
4839 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4840 # $ECHO "... test $N succeeded"
4841 # numOK=$((numOK+1))
4842 #else
4843 # $ECHO "*** test $N $FAILED"
4844 # numFAIL=$((numFAIL+1))
4845 # listFAIL="$listFAIL $N"
4846 #fi
4847 #fi ;; # NUMCOND
4848  
4849 #==============================================================================
4850  
4851 NAME=TOTALTIMEOUT
4852 case "$TESTS" in
4853 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%$NAME%*)
4854 TEST="$NAME: socat inactivity timeout"
4855 if ! eval $NUMCOND; then :; else
4856 #set -vx
4857 tf="$td/test$N.stdout"
4858 te="$td/test$N.stderr"
4859 tdiff="$td/test$N.diff"
4860 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4861 CMD2="$TRACE $SOCAT $opts -T 1 tcp4-listen:$PORT,reuseaddr pipe"
4862 CMD="$TRACE $SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT"
4863 printf "test $F_n $TEST... " $N
4864 eval "$CMD2 2>${te}1 &"
4865 pid=$! # background process id
4866 waittcp4port $PORT 1
4867 (echo "$da"; sleep 2; echo X) |$CMD >"$tf" 2>"${te}2"
4868 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4869 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4870 echo "$CMD2 &"
4871 echo "$CMD"
4872 cat "${te}1"
4873 cat "${te}2"
4874 cat "$tdiff"
4875 numFAIL=$((numFAIL+1))
4876 listFAIL="$listFAIL $N"
4877 else
4878 $PRINTF "$OK\n"
4879 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4880 numOK=$((numOK+1))
4881 fi
4882 kill $pid 2>/dev/null
4883 wait
4884 #set +vx
4885 fi ;; # NUMCOND
4886 esac
4887 PORT=$((PORT+1))
4888 N=$((N+1))
4889  
4890  
4891 NAME=IGNOREEOF+TOTALTIMEOUT
4892 case "$TESTS" in
4893 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
4894 TEST="$NAME: ignoreeof and inactivity timeout"
4895 if ! eval $NUMCOND; then :; else
4896 #set -vx
4897 ti="$td/test$N.file"
4898 tf="$td/test$N.stdout"
4899 te="$td/test$N.stderr"
4900 tdiff="$td/test$N.diff"
4901 da="test$N $(date) $RANDOM"
4902 CMD="$TRACE $SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -"
4903 printf "test $F_n $TEST... " $N
4904 touch "$ti"
4905 $CMD >"$tf" 2>"$te" &
4906 bg=$! # background process id
4907 psleep 0.5
4908 echo "$da" >>"$ti"
4909 sleep 4
4910 echo X >>"$ti"
4911 sleep 1
4912 kill $bg 2>/dev/null
4913 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4914 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4915 echo "$CMD &"
4916 cat "$te"
4917 cat "$tdiff"
4918 numFAIL=$((numFAIL+1))
4919 listFAIL="$listFAIL $N"
4920 else
4921 $PRINTF "$OK\n"
4922 if [ -n "$debug" ]; then cat "$te"; fi
4923 numOK=$((numOK+1))
4924 fi
4925 wait
4926 fi ;; # NUMCOND, feats
4927 esac
4928 N=$((N+1))
4929  
4930  
4931 NAME=PROXY2SPACES
4932 case "$TESTS" in
4933 *%$N%*|*%functions%*|*%chain%*|*%proxy%*|*%$NAME%*)
4934 TEST="$NAME: proxy connect accepts status with multiple spaces"
4935 if ! eval $NUMCOND; then :;
4936 elif ! testaddrs proxy >/dev/null; then
4937 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4938 numCANT=$((numCANT+1))
4939 else
4940 ts="$td/test$N.sh"
4941 tf="$td/test$N.stdout"
4942 te="$td/test$N.stderr"
4943 tdiff="$td/test$N.diff"
4944 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4945 #CMD2="$TRACE $SOCAT $opts tcp-l:$PORT,crlf system:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4946 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh -w 2\""
4947 #CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4948 CMD="$TRACE $SOCAT $opts - proxy:127.0.0.1:1000|tcp4:$LOCALHOST:$PORT"
4949 printf "test $F_n $TEST... " $N
4950 eval "$CMD2 2>\"${te}1\" &"
4951 pid=$! # background process id
4952 waittcp4port $PORT 1
4953 echo "$da" |$CMD >"$tf" 2>"${te}2"
4954 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4955 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4956 echo "$CMD2 &"
4957 echo "$CMD"
4958 cat "${te}1"
4959 cat "${te}2"
4960 cat "$tdiff"
4961 numFAIL=$((numFAIL+1))
4962 listFAIL="$listFAIL $N"
4963 else
4964 $PRINTF "$OK\n"
4965 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4966 numOK=$((numOK+1))
4967 fi
4968 kill $pid 2>/dev/null
4969 wait
4970 fi ;; # NUMCOND, feats
4971 esac
4972 PORT=$((PORT+1))
4973 N=$((N+1))
4974  
4975  
4976 NAME=BUG-UNISTDIO
4977 case "$TESTS" in
4978 *%$N%*|*%functions%*|*%$NAME%*)
4979 TEST="$NAME: for bug with address options on both stdin/out in unidirectional mode"
4980 if ! eval $NUMCOND; then :; else
4981 tf="$td/test$N.stdout"
4982 te="$td/test$N.stderr"
4983 ff="$td/file$N"
4984 printf "test $F_n $TEST... " $N
4985 >"$ff"
4986 #$TRACE $SOCAT $opts -u /dev/null -,setlk <"$ff" 2>"$te"
4987 CMD="$TRACE $SOCAT $opts -u /dev/null -,setlk"
4988 $CMD <"$ff" 2>"$te"
4989 if [ "$?" -eq 0 ]; then
4990 $PRINTF "$OK\n"
4991 numOK=$((numOK+1))
4992 else
4993 if [ "$UNAME" = "Linux" ]; then
4994 $PRINTF "$FAILED\n"
4995 echo "$CMD"
4996 cat "$te"
4997 numFAIL=$((numFAIL+1))
4998 listFAIL="$listFAIL $N"
4999 else
5000 $PRINTF "${YELLOW}failed (don't care)${NORMAL}\n"
5001 numCANT=$((numCANT+1))
5002 fi
5003 fi
5004 fi ;; # NUMCOND
5005 esac
5006 N=$((N+1))
5007  
5008  
5009 NAME=SINGLEEXECOUTSOCKETPAIR
5010 case "$TESTS" in
5011 *%$N%*|*%functions%*|*%$NAME%*)
5012 TEST="$NAME: inheritance of stdout to single exec with socketpair"
5013 testecho "$N" "$TEST" "exec:cat%-" "" "$opts" 1
5014 esac
5015 N=$((N+1))
5016  
5017 NAME=SINGLEEXECOUTPIPE
5018 case "$TESTS" in
5019 *%$N%*|*%functions%*|*%$NAME%*)
5020 TEST="$NAME: inheritance of stdout to single exec with pipe"
5021 testecho "$N" "$TEST" "exec:cat,pipes%-" "" "$opts" 1
5022 esac
5023 N=$((N+1))
5024  
5025 NAME=SINGLEEXECOUTPTY
5026 case "$TESTS" in
5027 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5028 TEST="$NAME: inheritance of stdout to single exec with pty"
5029 if ! eval $NUMCOND; then :;
5030 elif ! testaddrs pty >/dev/null; then
5031 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5032 numCANT=$((numCANT+1))
5033 else
5034 testecho "$N" "$TEST" "exec:cat,pty,raw%-" "" "$opts" 1
5035 fi ;; # NUMCOND, feats
5036 esac
5037 N=$((N+1))
5038  
5039 NAME=SINGLEEXECINSOCKETPAIR
5040 case "$TESTS" in
5041 *%$N%*|*%functions%*|*%$NAME%*)
5042 TEST="$NAME: inheritance of stdin to single exec with socketpair"
5043 testecho "$N" "$TEST" "-%exec:cat" "" "$opts"
5044 esac
5045 N=$((N+1))
5046  
5047 NAME=SINGLEEXECINPIPE
5048 case "$TESTS" in
5049 *%$N%*|*%functions%*|*%$NAME%*)
5050 TEST="$NAME: inheritance of stdin to single exec with pipe"
5051 testecho "$N" "$TEST" "-%exec:cat,pipes" "" "$opts"
5052 esac
5053 N=$((N+1))
5054  
5055 NAME=SINGLEEXECINPTYDELAY
5056 case "$TESTS" in
5057 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5058 TEST="$NAME: inheritance of stdin to single exec with pty, with delay"
5059 if ! eval $NUMCOND; then :;
5060 elif ! testaddrs pty >/dev/null; then
5061 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5062 numCANT=$((numCANT+1))
5063 else
5064 testecho "$N" "$TEST" "-%exec:cat,pty,raw" "" "$opts" $MISCDELAY
5065 fi ;; # NUMCOND, feats
5066 esac
5067 N=$((N+1))
5068  
5069 NAME=SINGLEEXECINPTY
5070 case "$TESTS" in
5071 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5072 TEST="$NAME: inheritance of stdin to single exec with pty"
5073 if ! eval $NUMCOND; then :;
5074 elif ! testaddrs pty >/dev/null; then
5075 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5076 numCANT=$((numCANT+1))
5077 else
5078 testecho "$N" "$TEST" "-%exec:cat,pty,raw" "" "$opts"
5079 fi ;; # NUMCOND, feats
5080 esac
5081 N=$((N+1))
5082  
5083  
5084 NAME=READLINE
5085 #set -vx
5086 case "$TESTS" in
5087 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5088 TEST="$NAME: readline with password and sigint"
5089 if ! eval $NUMCOND; then :;
5090 elif ! feat=$(testaddrs readline pty); then
5091 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5092 numCANT=$((numCANT+1))
5093 else
5094 SAVETERM="$TERM"; TERM= # 'cause konsole might print controls even in raw
5095 SAVEMICS=$MICROS
5096 #MICROS=2000000
5097 ts="$td/test$N.sh"
5098 to="$td/test$N.stdout"
5099 tpi="$td/test$N.inpipe"
5100 tpo="$td/test$N.outpipe"
5101 te="$td/test$N.stderr"
5102 tr="$td/test$N.ref"
5103 tdiff="$td/test$N.diff"
5104 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
5105 # the feature that we really want to test is in the readline.sh script:
5106 CMD="$TRACE $SOCAT $opts -t1 open:$tpo%open:$tpi,nonblock exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig"
5107 #echo "$CMD" >"$ts"
5108 #chmod a+x "$ts"
5109 printf "test $F_n $TEST... " $N
5110 rm -f "$tpi" "$tpo"
5111 mkfifo "$tpi"
5112 touch "$tpo"
5113 #
5114 # during development of this test, the following command line succeeded:
5115 # (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/gerhard/debug1 -v -x - exec:'./readline.sh ./readline-test.sh',pty,ctty,setsid,raw,echo=0,isig
5116 #
5117 PATH=${SOCAT%socat}:$PATH eval "$CMD 2>$te &"
5118 pid=$! # background process id
5119 usleep $MICROS
5120  
5121 (
5122 usleep $((3*MICROS))
5123 $ECHO "user\n\c"
5124 usleep $MICROS
5125 $ECHO "password\c"
5126 usleep $MICROS
5127 $ECHO "\n\c"
5128 usleep $MICROS
5129 $ECHO "test 1\n\c"
5130 usleep $MICROS
5131 $ECHO "\003\c"
5132 usleep $MICROS
5133 $ECHO "test 2\n\c"
5134 usleep $MICROS
5135 $ECHO "exit\n\c"
5136 usleep $MICROS
5137 ) >"$tpi"
5138  
5139 cat >$tr <<EOF
5140 readline feature test program
5141 Authentication required
5142 Username: user
5143 Password:
5144 prog> test 1
5145 executing test 1
5146 prog> ./readline-test.sh got SIGINT
5147 test 2
5148 executing test 2
5149 prog> exit
5150 EOF
5151  
5152 #0 if ! sed 's/.*\r//g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5153 #0 if ! sed 's/.*'"$($ECHO '\r\c')"'/</g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5154 wait
5155 if ! tr "$($ECHO '\r \c')" "% " <$tpo |sed 's/%$//g' |sed 's/.*%//g' |diff "$tr" - >"$tdiff" 2>&1; then
5156 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5157 echo "$CMD"
5158 cat "$te"
5159 cat "$tdiff"
5160 numFAIL=$((numFAIL+1))
5161 listFAIL="$listFAIL $N"
5162 else
5163 $PRINTF "$OK\n"
5164 if [ -n "$debug" ]; then cat $te; fi
5165 numOK=$((numOK+1))
5166 fi
5167 kill $pid 2>/dev/null # necc on OpenBSD
5168 wait
5169 MICROS=$SAVEMICS
5170 TERM="$SAVETERM"
5171 fi ;; # NUMCOND, feats
5172 esac
5173 PORT=$((PORT+1))
5174 N=$((N+1))
5175  
5176  
5177 NAME=GENDERCHANGER
5178 case "$TESTS" in
5179 *%$N%*|*%functions%*|*%$NAME%*)
5180 TEST="$NAME: TCP4 \"gender changer\""
5181 if ! eval $NUMCOND; then :; else
5182 tf="$td/test$N.stdout"
5183 te="$td/test$N.stderr"
5184 tdiff="$td/test$N.diff"
5185 da="test$N $(date) $RANDOM"
5186 # this is the server in the protected network that we want to reach
5187 CMD1="$TRACE $SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5188 # this is the double client in the protected network
5189 CMD2="$TRACE $SOCAT -lp2client $opts tcp4:$LOCALHOST:$((PORT+1)),retry=10,interval=1 tcp4:$LOCALHOST:$PORT"
5190 # this is the double server in the outside network
5191 CMD3="$TRACE $SOCAT -lp2server $opts tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST"
5192 # this is the outside client that wants to use the protected server
5193 CMD4="$TRACE $SOCAT -lpclient $opts -t1 - tcp4:$LOCALHOST:$((PORT+2))"
5194 printf "test $F_n $TEST... " $N
5195 eval "$CMD1 2>${te}1 &"
5196 pid1=$!
5197 eval "$CMD2 2>${te}2 &"
5198 pid2=$!
5199 eval "$CMD3 2>${te}3 &"
5200 pid3=$!
5201 waittcp4port $PORT 1 &&
5202 waittcp4port $((PORT+2)) 1
5203 sleep 1
5204 echo "$da" |$CMD4 >$tf 2>"${te}4"
5205 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5206 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5207 echo "$CMD1 &"
5208 echo "$CMD2 &"
5209 echo "$CMD3 &"
5210 echo "$CMD4"
5211 cat "${te}1" "${te}2" "${te}3" "${te}4"
5212 echo "$tdiff"
5213 numFAIL=$((numFAIL+1))
5214 listFAIL="$listFAIL $N"
5215 else
5216 $PRINTF "$OK\n"
5217 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4"; fi
5218 numOK=$((numOK+1))
5219 fi
5220 kill $pid1 $pid2 $pid3 $pid4 2>/dev/null
5221 wait
5222 fi ;; # NUMCOND
5223 esac
5224 PORT=$((PORT+3))
5225 N=$((N+1))
5226  
5227  
5228 #!
5229 #PORT=10000
5230 #!
5231 NAME=OUTBOUNDIN
5232 case "$TESTS" in
5233 *%$N%*|*%functions%|*%chain%**|*%openssl%*|*%proxy%*|*%$NAME%*)
5234 TEST="$NAME: gender changer via SSL through HTTP proxy, oneshot"
5235 if ! eval $NUMCOND; then :;
5236 elif ! feat=$(testaddrs openssl proxy); then
5237 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5238 numCANT=$((numCANT+1))
5239 else
5240 gentestcert testsrv
5241 gentestcert testcli
5242 tf="$td/test$N.stdout"
5243 te="$td/test$N.stderr"
5244 tdiff="$td/test$N.diff"
5245 da="test$N $(date) $RANDOM"
5246 # this is the server in the protected network that we want to reach
5247 CMD1="$TRACE $SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5248 # this is the proxy in the protected network that provides a way out
5249 CMD2="$TRACE $SOCAT $opts -lpproxy tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5250 # this is our proxy connect wrapper in the protected network
5251 #CMD3="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5252 CMD3="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$((PORT+3)),resolve\\|tcp4:$LOCALHOST:$((PORT+1))"
5253 # this is our double client in the protected network using SSL
5254 #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"
5255 #CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5256 CMD4="$TRACE $SOCAT $opts -lp2client ssl,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD\|tcp4:$LOCALHOST:$((PORT+2)) tcp4:$LOCALHOST:$PORT"
5257 # this is the double server in the outside network
5258 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"
5259 # this is the outside client that wants to use the protected server
5260 CMD6="$TRACE $SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4))"
5261 printf "test $F_n $TEST... " $N
5262 eval "$CMD1 2>${te}1 &"
5263 pid1=$!
5264 eval "$CMD2 2>${te}2 &"
5265 pid2=$!
5266 eval "$CMD3 2>${te}3 &"
5267 pid3=$!
5268 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5269 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5270 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5271 eval "$CMD5 2>${te}5 &"
5272 pid5=$!
5273 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5274 echo "$da" |$CMD6 >$tf 2>"${te}6" &
5275 pid6=$!
5276 waittcp4port $((PORT+3)) 1 || $PRINTF "$FAILED: port $((PORT+3))\n" >&2 </dev/null
5277 eval "$CMD4 2>${te}4 &"
5278 pid4=$!
5279 wait $pid6
5280 if ! (echo "$da"; sleep 2) |diff - "$tf" >"$tdiff"; then
5281 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5282 echo "$CMD1 &"
5283 cat "${te}1"
5284 echo "$CMD2 &"
5285 cat "${te}2"
5286 echo "$CMD3 &"
5287 cat "${te}3"
5288 echo "$CMD5 &"
5289 cat "${te}5"
5290 echo "$CMD6"
5291 cat "${te}6"
5292 echo "$CMD4 &"
5293 cat "${te}4"
5294 cat "$tdiff"
5295 numFAIL=$((numFAIL+1))
5296 listFAIL="$listFAIL $N"
5297 else
5298 $PRINTF "$OK\n"
5299 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" "${te}6"; fi
5300 numOK=$((numOK+1))
5301 fi
5302 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5303 wait
5304 fi ;; # NUMCOND, feats
5305 esac
5306 PORT=$((PORT+5))
5307 N=$((N+1))
5308  
5309  
5310 # test the TCP gender changer with almost production requirements: a double
5311 # client repeatedly tries to connect to a double server via SSL through an HTTP
5312 # proxy. the double servers SSL port becomes active for one connection only
5313 # after a (real) client has connected to its TCP port. when the double client
5314 # succeeded to establish an SSL connection, it connects with its second client
5315 # side to the specified (protected) server. all three consecutive connections
5316 # must function for full success of this test.
5317 PORT=$((RANDOM+16184))
5318 #!
5319 NAME=INTRANETRIPPER
5320 case "$TESTS" in
5321 *%$N%*|*%functions%*|*%chain%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5322 TEST="$NAME: gender changer via SSL through HTTP proxy, daemons"
5323 if ! eval $NUMCOND; then :;
5324 elif ! feat=$(testaddrs openssl proxy); then
5325 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5326 numCANT=$((numCANT+1))
5327 else
5328 gentestcert testsrv
5329 gentestcert testcli
5330 tf="$td/test$N.stdout"
5331 te="$td/test$N.stderr"
5332 tdiff="$td/test$N.diff"
5333 da1="test$N.1 $(date) $RANDOM"
5334 da2="test$N.2 $(date) $RANDOM"
5335 da3="test$N.3 $(date) $RANDOM"
5336 # this is the server in the protected network that we want to reach
5337 CMD1="$TRACE $SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo"
5338 # this is the proxy in the protected network that provides a way out
5339 # note: the proxy.sh script starts one or two more socat processes without
5340 # setting the program name
5341 CMD2="$TRACE $SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5342 # this is our proxy connect wrapper in the protected network
5343 #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"
5344 CMD3="$TRACE $SOCAT $opts -lu -lpwrapper -t3 tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$((PORT+3)),resolve\\|tcp4:$LOCALHOST:$((PORT+1))"
5345 # this is our double client in the protected network using SSL
5346 #CMD4="$TRACE $SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,intervall=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5347 #CMD4="$TRACE $SOCAT $opts -lu -lp2client -t3 ssl,cert=testcli.pem,cafile=testsrv.crt,fork,$SOCAT_EGD,retry=10,intervall=1\\|tcp4:$LOCALHOST:$((PORT+2)) tcp4:$LOCALHOST:$PORT"
5348 CMD4="$TRACE $SOCAT $opts -lp2client -t3 tcp4:$LOCALHOST:$((PORT+2)),fork ^ssl,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD,retry=10,intervall=1\\|tcp4:$LOCALHOST:$PORT"
5349 # this is the double server in the outside network
5350 #CMD5="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=10"
5351 #CMD5="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,fork tcp4-l:$((PORT+3)),reuseaddr,bind=$LOCALHOST,retry=10\\|ssl-l,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt"
5352 CMD5="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,backlog=3,fork ssl-l,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt\\|tcp4-l:$((PORT+3)),reuseaddr,bind=$LOCALHOST,retry=20,interval=0.5"
5353 # this is the outside client that wants to use the protected server
5354 CMD6="$TRACE $SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3"
5355 printf "test $F_n $TEST... " $N
5356 # start the intranet infrastructure
5357 eval "$CMD1 2>\"${te}1\" &"
5358 pid1=$!
5359 eval "$CMD2 2>\"${te}2\" &"
5360 pid2=$!
5361 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5362 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5363 # initiate our internal measures
5364 eval "$CMD3 2>\"${te}3\" &"
5365 pid3=$!
5366 eval "$CMD4 2>\"${te}4\" &"
5367 pid4=$!
5368 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5369 # now we start the external daemon
5370 eval "$CMD5 2>\"${te}5\" &"
5371 pid5=$!
5372 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5373 # and this is the outside client:
5374 echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" &
5375 pid6_1=$!
5376 echo "$da2" |$CMD6 >${tf}_2 2>"${te}6_2" &
5377 pid6_2=$!
5378 echo "$da3" |$CMD6 >${tf}_3 2>"${te}6_3" &
5379 pid6_3=$!
5380 wait $pid6_1 $pid6_2 $pid6_3
5381 #
5382 (echo "$da1"; sleep 2) |diff - "${tf}_1" >"${tdiff}1"
5383 (echo "$da2"; sleep 2) |diff - "${tf}_2" >"${tdiff}2"
5384 (echo "$da3"; sleep 2) |diff - "${tf}_3" >"${tdiff}3"
5385 if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then
5386 # FAILED only when none of the three transfers succeeded
5387 if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then
5388 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5389 echo "$CMD1 &"
5390 cat "${te}1"
5391 echo "$CMD2 &"
5392 cat "${te}2"
5393 echo "$CMD3 &"
5394 cat "${te}3"
5395 echo "$CMD4 &"
5396 cat "${te}4"
5397 echo "$CMD5 &"
5398 cat "${te}5"
5399 echo "$CMD6 &"
5400 cat "${te}6_1"
5401 cat "${tdiff}1"
5402 echo "$CMD6 &"
5403 cat "${te}6_2"
5404 cat "${tdiff}2"
5405 echo "$CMD6 &"
5406 cat "${te}6_3"
5407 cat "${tdiff}3"
5408 numFAIL=$((numFAIL+1))
5409 listFAIL="$listFAIL $N"
5410 else
5411 $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n"
5412 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5413 numOK=$((numOK+1))
5414 fi
5415 else
5416 $PRINTF "$OK\n"
5417 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5418 numOK=$((numOK+1))
5419 fi
5420 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5421 wait
5422 fi ;; # NUMCOND, feats
5423 esac
5424 PORT=$((PORT+5))
5425 N=$((N+1))
5426  
5427  
5428 # let us test the security features with -s, retry, and fork
5429 # method: first test without security feature if it works
5430 # then try with security feature, must fail
5431  
5432 # test the security features of a server address
5433 testserversec () {
5434 local N="$1"
5435 local title="$2"
5436 local opts="$3"
5437 local arg1="$4" # the server address
5438 local secopt0="$5" # option without security for server, mostly empty
5439 local secopt1="$6" # the security option for server, to be tested
5440 local arg2="$7" # the client address
5441 local ipvers="$8" # IP version, for check of listen port
5442 local proto="$9" # protocol, for check of listen port
5443 local port="${10}" # start client when this port is listening
5444 local expect="${11}" # expected behaviour of client: 0..empty output; -1..error
5445 local T="${12}"; [ -z "$T" ] && T=0
5446 local tf="$td/test$N.stdout"
5447 local te="$td/test$N.stderr"
5448 local tdiff1="$td/test$N.diff1"
5449 local tdiff2="$td/test$N.diff2"
5450 local da="test$N.1 $(date) $RANDOM"
5451 local stat result
5452  
5453 $PRINTF "test $F_n %s... " $N "$title"
5454 # first: without security
5455 # start server
5456 $TRACE $SOCAT $opts "$arg1,$secopt0" echo 2>"${te}1" &
5457 spid=$!
5458 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5459 kill $spid 2>/dev/null
5460 $PRINTF "$NO_RESULT (ph.1 server not working):\n"
5461 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5462 cat "${te}1"
5463 numCANT=$((numCANT+1))
5464 wait; return
5465 fi
5466 # now use client
5467 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}2"
5468 stat="$?"
5469 kill $spid 2>/dev/null
5470 #killall $SOCAT 2>/dev/null
5471 if [ "$stat" != 0 ]; then
5472 $PRINTF "$NO_RESULT (ph.1 function fails): $TRACE $SOCAT:\n"
5473 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5474 cat "${te}1"
5475 echo "$TRACE $SOCAT $opts - \"$arg2\""
5476 cat "${te}2"
5477 numCANT=$((numCANT+1))
5478 wait; return
5479 elif echo "$da" |diff - "$tf" >"$tdiff1" 2>&1; then
5480 : # function without security is ok, go on
5481 else
5482 $PRINTF "$NO_RESULT (ph.1 function fails): diff:\n"
5483 echo "$TRACE $SOCAT $opts $arg1,$secopt0 echo &"
5484 cat "${te}1"
5485 echo "$TRACE $SOCAT $opts - $arg2"
5486 cat "${te}2"
5487 cat "$tdiff1"
5488 numCANT=$((numCANT+1))
5489 wait; return
5490 fi
5491  
5492 # then: with security
5493 if [ "$port" ] && ! wait${proto}${ipvers}port $port 0; then
5494 $PRINTF "$NO_RESULT (ph.1 port remains in use)\n"
5495 numCANT=$((numCANT+1))
5496 wait; return
5497 fi
5498 wait
5499  
5500 #set -vx
5501 # assemble address w/ security option; on dual, take read part:
5502 case "$arg1" in
5503 #*!!*) arg="${arg1%!!*},$secopt1!!${arg1#*!!}" ;;
5504 #*%*) arg="${arg1%\%*}%${arg1#*%},$secopt1" ;;
5505 *%*) arg="$arg1,$secopt1" ;;
5506 *) arg="$arg1,$secopt1" ;;
5507 esac
5508 # start server
5509 CMD3="$TRACE $SOCAT $opts $arg echo"
5510 $CMD3 2>"${te}3" &
5511 spid=$!
5512 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5513 kill $spid 2>/dev/null
5514 $PRINTF "$NO_RESULT (ph.2 server not working)\n"
5515 wait
5516 echo "$CMD3"
5517 cat "${te}3"
5518 numCANT=$((numCANT+1))
5519 return
5520 fi
5521 # now use client
5522 da="test$N.2 $(date) $RANDOM"
5523 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}4"
5524 stat=$?
5525 kill $spid 2>/dev/null
5526 #set +vx
5527 #killall $TRACE $SOCAT 2>/dev/null
5528 if [ "$stat" != 0 ]; then
5529 result=-1; # socat had error
5530 elif [ ! -s "$tf" ]; then
5531 result=0; # empty output
5532 elif echo "$da" |diff - "$tf" >"$tdiff2" 2>&1; then
5533 result=1; # output is copy of input
5534 else
5535 result=2; # output differs from input
5536 fi
5537 if [ X$result != X$expect ]; then
5538 case X$result in
5539 X-1) $PRINTF "$NO_RESULT (ph.2 client error): $TRACE $SOCAT:\n"
5540 echo "$TRACE $SOCAT $opts $arg echo"
5541 cat "${te}3"
5542 echo "$TRACE $SOCAT $opts - $arg2"
5543 cat "${te}4"
5544 numCANT=$((numCANT+1)) ;;
5545 X0) $PRINTF "$NO_RESULT (ph.2 diff failed): diff:\n"
5546 echo "$TRACE $SOCAT $opts $arg echo"
5547 cat "${te}3"
5548 echo "$TRACE $SOCAT $opts - $arg2"
5549 cat "${te}4"
5550 cat "$tdiff2"
5551 numCANT=$((numCANT+1)) ;;
5552 X1) $PRINTF "$FAILED: SECURITY BROKEN\n"
5553 echo "$TRACE $SOCAT $opts $arg echo"
5554 cat "${te}3"
5555 echo "$TRACE $SOCAT $opts - $arg2"
5556 cat "${te}4"
5557 cat "$tdiff2"
5558 numFAIL=$((numFAIL+1))
5559 listFAIL="$listFAIL $N" ;;
5560 X2) $PRINTF "$FAILED: diff:\n"
5561 echo "$TRACE $SOCAT $opts $arg echo"
5562 cat "${te}3"
5563 echo "$TRACE $SOCAT $opts - $arg2"
5564 cat "${te}4"
5565 cat "$tdiff2"
5566 numFAIL=$((numFAIL+1))
5567 listFAIL="$listFAIL $N" ;;
5568 esac
5569 else
5570 $PRINTF "$OK\n"
5571 if [ -n "$debug" ]; then cat $te; fi
5572 numOK=$((numOK+1))
5573 fi
5574 wait
5575 #set +vx
5576 }
5577  
5578  
5579 NAME=TCP4RANGEBITS
5580 case "$TESTS" in
5581 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5582 TEST="$NAME: security of TCP4-L with RANGE option"
5583 if ! eval $NUMCOND; then :;
5584 elif [ -z "$SECONDADDR" ]; then
5585 # we need access to a second addresses
5586 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5587 numCANT=$((numCANT+1))
5588 else
5589 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5590 fi ;; # $SECONDADDR, NUMCOND
5591 esac
5592 PORT=$((PORT+1))
5593 N=$((N+1))
5594  
5595 NAME=TCP4RANGEMASK
5596 case "$TESTS" in
5597 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5598 TEST="$NAME: security of TCP4-L with RANGE option"
5599 if ! eval $NUMCOND; then :;
5600 elif [ -z "$SECONDADDR" ]; then
5601 # we need access to a second addresses
5602 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5603 numCANT=$((numCANT+1))
5604 else
5605 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR:255.255.255.255" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5606 fi ;; # $SECONDADDR, NUMCOND
5607 esac
5608 PORT=$((PORT+1))
5609 N=$((N+1))
5610  
5611 # like TCP4RANGEMASK, but the "bad" address is within the same class A network
5612 NAME=TCP4RANGEMASKHAIRY
5613 case "$TESTS" in
5614 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5615 TEST="$NAME: security of TCP4-L with RANGE option"
5616 if ! eval $NUMCOND; then :; else
5617 testserversec "$N" "$TEST" "$opts -s" "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
5618 fi ;; # Linux, NUMCOND
5619 esac
5620 PORT=$((PORT+1))
5621 N=$((N+1))
5622  
5623  
5624 NAME=TCP4SOURCEPORT
5625 case "$TESTS" in
5626 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5627 TEST="$NAME: security of TCP4-L with SOURCEPORT option"
5628 if ! eval $NUMCOND; then :; else
5629 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5630 fi ;; # NUMCOND
5631 esac
5632 PORT=$((PORT+1))
5633 N=$((N+1))
5634  
5635 NAME=TCP4LOWPORT
5636 case "$TESTS" in
5637 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5638 TEST="$NAME: security of TCP4-L with LOWPORT option"
5639 if ! eval $NUMCOND; then :; else
5640 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5641 fi ;; # NUMCOND
5642 esac
5643 PORT=$((PORT+1))
5644 N=$((N+1))
5645  
5646 NAME=TCP4WRAPPERS_ADDR
5647 case "$TESTS" in
5648 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5649 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5650 if ! eval $NUMCOND; then :;
5651 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5652 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5653 numCANT=$((numCANT+1))
5654 else
5655 ha="$td/hosts.allow"
5656 hd="$td/hosts.deny"
5657 $ECHO "socat: $SECONDADDR" >"$ha"
5658 $ECHO "ALL: ALL" >"$hd"
5659 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5660 fi ;; # NUMCOND, feats
5661 esac
5662 PORT=$((PORT+1))
5663 N=$((N+1))
5664  
5665 NAME=TCP4WRAPPERS_NAME
5666 case "$TESTS" in
5667 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5668 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5669 if ! eval $NUMCOND; then :;
5670 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5671 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5672 numCANT=$((numCANT+1))
5673 else
5674 ha="$td/hosts.allow"
5675 hd="$td/hosts.deny"
5676 $ECHO "socat: $LOCALHOST" >"$ha"
5677 $ECHO "ALL: ALL" >"$hd"
5678 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
5679 fi ;; # NUMCOND, feats
5680 esac
5681 PORT=$((PORT+1))
5682 N=$((N+1))
5683  
5684  
5685 NAME=TCP6RANGE
5686 case "$TESTS" in
5687 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5688 TEST="$NAME: security of TCP6-L with RANGE option"
5689 if ! eval $NUMCOND; then :;
5690 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5691 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5692 numCANT=$((numCANT+1))
5693 else
5694 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "range=[::2/128]" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5695 fi ;; # NUMCOND, feats
5696 esac
5697 PORT=$((PORT+1))
5698 N=$((N+1))
5699  
5700 NAME=TCP6SOURCEPORT
5701 case "$TESTS" in
5702 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5703 TEST="$NAME: security of TCP6-L with SOURCEPORT option"
5704 if ! eval $NUMCOND; then :;
5705 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5706 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5707 numCANT=$((numCANT+1))
5708 else
5709 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5710 fi ;; # NUMCOND, feats
5711 esac
5712 PORT=$((PORT+1))
5713 N=$((N+1))
5714  
5715 NAME=TCP6LOWPORT
5716 case "$TESTS" in
5717 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
5718 TEST="$NAME: security of TCP6-L with LOWPORT option"
5719 if ! eval $NUMCOND; then :;
5720 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5721 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5722 numCANT=$((numCANT+1))
5723 else
5724 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5725 fi ;; # NUMCOND, feats
5726 esac
5727 PORT=$((PORT+1))
5728 N=$((N+1))
5729  
5730 NAME=TCP6TCPWRAP
5731 case "$TESTS" in
5732 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
5733 TEST="$NAME: security of TCP6-L with TCPWRAP option"
5734 if ! eval $NUMCOND; then :;
5735 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
5736 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5737 numCANT=$((numCANT+1))
5738 else
5739 ha="$td/hosts.allow"
5740 hd="$td/hosts.deny"
5741 $ECHO "socat: [::2]" >"$ha"
5742 $ECHO "ALL: ALL" >"$hd"
5743 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5744 fi ;; # NUMCOND, feats
5745 esac
5746 PORT=$((PORT+1))
5747 N=$((N+1))
5748  
5749  
5750 NAME=UDP4RANGE
5751 case "$TESTS" in
5752 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5753 TEST="$NAME: security of UDP4-L with RANGE option"
5754 if ! eval $NUMCOND; then :; else
5755 #testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5756 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5757 fi ;; # NUMCOND
5758 esac
5759 PORT=$((PORT+1))
5760 N=$((N+1))
5761  
5762 NAME=UDP4SOURCEPORT
5763 case "$TESTS" in
5764 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5765 TEST="$NAME: security of UDP4-L with SOURCEPORT option"
5766 if ! eval $NUMCOND; then :; else
5767 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr" "" "sp=$PORT" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5768 fi ;; # NUMCOND
5769 esac
5770 PORT=$((PORT+1))
5771 N=$((N+1))
5772  
5773 NAME=UDP4LOWPORT
5774 case "$TESTS" in
5775 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5776 TEST="$NAME: security of UDP4-L with LOWPORT option"
5777 if ! eval $NUMCOND; then :; else
5778 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr" "" "lowport" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5779 fi ;; # NUMCOND
5780 esac
5781 PORT=$((PORT+1))
5782 N=$((N+1))
5783  
5784 NAME=UDP4TCPWRAP
5785 case "$TESTS" in
5786 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5787 TEST="$NAME: security of UDP4-L with TCPWRAP option"
5788 if ! eval $NUMCOND; then :;
5789 elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
5790 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5791 numCANT=$((numCANT+1))
5792 else
5793 ha="$td/hosts.allow"
5794 hd="$td/hosts.deny"
5795 $ECHO "socat: $SECONDADDR" >"$ha"
5796 $ECHO "ALL: ALL" >"$hd"
5797 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr,retry=1" "" "tcpwrap-etc=$td" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5798 fi ;; # NUMCOND, feats
5799 esac
5800 PORT=$((PORT+1))
5801 N=$((N+1))
5802  
5803  
5804 NAME=UDP6RANGE
5805 case "$TESTS" in
5806 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5807 TEST="$NAME: security of UDP6-L with RANGE option"
5808 if ! eval $NUMCOND; then :;
5809 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5810 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5811 numCANT=$((numCANT+1))
5812 else
5813 #testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr,fork" "" "range=[::2/128]" "udp6:[::1]:$PORT" 6 udp $PORT 0
5814 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "range=[::2/128]" "udp6:[::1]:$PORT" 6 udp $PORT 0
5815 fi ;; # NUMCOND, feats
5816 esac
5817 PORT=$((PORT+1))
5818 N=$((N+1))
5819  
5820 NAME=UDP6SOURCEPORT
5821 case "$TESTS" in
5822 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5823 TEST="$NAME: security of UDP6-L with SOURCEPORT option"
5824 if ! eval $NUMCOND; then :;
5825 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
5826 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5827 numCANT=$((numCANT+1))
5828 else
5829 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "sp=$PORT" "udp6:[::1]:$PORT" 6 udp $PORT 0
5830 fi ;; # NUMCOND, feats
5831 esac
5832 PORT=$((PORT+1))
5833 N=$((N+1))
5834  
5835 NAME=UDP6LOWPORT
5836 case "$TESTS" in
5837 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
5838 TEST="$NAME: security of UDP6-L with LOWPORT option"
5839 if ! eval $NUMCOND; then :;
5840 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
5841 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5842 numCANT=$((numCANT+1))
5843 else
5844 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
5845 fi ;; # NUMCOND, feats
5846 esac
5847 PORT=$((PORT+1))
5848 N=$((N+1))
5849  
5850 NAME=UDP6TCPWRAP
5851 case "$TESTS" in
5852 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
5853 TEST="$NAME: security of UDP6-L with TCPWRAP option"
5854 if ! eval $NUMCOND; then :;
5855 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
5856 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5857 numCANT=$((numCANT+1))
5858 else
5859 ha="$td/hosts.allow"
5860 hd="$td/hosts.deny"
5861 $ECHO "socat: [::2]" >"$ha"
5862 $ECHO "ALL: ALL" >"$hd"
5863 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
5864 fi ;; # NUMCOND, feats
5865 esac
5866 PORT=$((PORT+1))
5867 N=$((N+1))
5868  
5869  
5870 NAME=OPENSSLTCP4_RANGE
5871 case "$TESTS" in
5872 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%range%*|*%$NAME%*)
5873 TEST="$NAME: security of SSL-L over TCP/IPv4 with RANGE option"
5874 if ! eval $NUMCOND; then :;
5875 elif ! testaddrs openssl >/dev/null; then
5876 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5877 numCANT=$((numCANT+1))
5878 else
5879 gentestcert testsrv
5880 testserversec "$N" "$TEST" "$opts -s" "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
5881 fi ;; # NUMCOND, feats
5882 esac
5883 PORT=$((PORT+1))
5884 N=$((N+1))
5885  
5886 NAME=OPENSSLTCP4_SOURCEPORT
5887 case "$TESTS" in
5888 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
5889 TEST="$NAME: security of SSL-L with SOURCEPORT option"
5890 if ! eval $NUMCOND; then :;
5891 elif ! testaddrs openssl >/dev/null; then
5892 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5893 numCANT=$((numCANT+1))
5894 else
5895 gentestcert testsrv
5896 testserversec "$N" "$TEST" "$opts -s" "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
5897 fi ;; # NUMCOND, feats
5898 esac
5899 PORT=$((PORT+1))
5900 N=$((N+1))
5901  
5902 NAME=OPENSSLTCP4_LOWPORT
5903 case "$TESTS" in
5904 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%lowport%*|*%$NAME%*)
5905 TEST="$NAME: security of SSL-L with LOWPORT option"
5906 if ! eval $NUMCOND; then :;
5907 elif ! testaddrs openssl >/dev/null; then
5908 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5909 numCANT=$((numCANT+1))
5910 else
5911 gentestcert testsrv
5912 testserversec "$N" "$TEST" "$opts -s" "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
5913 fi ;; # NUMCOND, feats
5914 esac
5915 PORT=$((PORT+1))
5916 N=$((N+1))
5917  
5918 NAME=OPENSSLTCP4_TCPWRAP
5919 case "$TESTS" in
5920 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
5921 TEST="$NAME: security of SSL-L with TCPWRAP option"
5922 if ! eval $NUMCOND; then :;
5923 elif ! feat=$(testaddrs ip4 tcp libwrap openssl); then
5924 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5925 numCANT=$((numCANT+1))
5926 else
5927 gentestcert testsrv
5928 ha="$td/hosts.allow"
5929 hd="$td/hosts.deny"
5930 $ECHO "socat: $SECONDADDR" >"$ha"
5931 $ECHO "ALL: ALL" >"$hd"
5932 testserversec "$N" "$TEST" "$opts -s" "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
5933 fi ;; # NUMCOND, feats
5934 esac
5935 PORT=$((PORT+1))
5936 N=$((N+1))
5937  
5938 NAME=OPENSSLCERTSERVER
5939 case "$TESTS" in
5940 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
5941 TEST="$NAME: security of SSL-L with client certificate"
5942 if ! eval $NUMCOND; then :;
5943 elif ! testaddrs openssl >/dev/null; then
5944 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5945 numCANT=$((numCANT+1))
5946 else
5947 gentestcert testsrv
5948 gentestcert testcli
5949 testserversec "$N" "$TEST" "$opts -s" "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 -1
5950 fi ;; # NUMCOND, feats
5951 esac
5952 PORT=$((PORT+1))
5953 N=$((N+1))
5954  
5955 NAME=OPENSSLCERTCLIENT
5956 case "$TESTS" in
5957 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
5958 TEST="$NAME: security of SSL with server certificate"
5959 if ! eval $NUMCOND; then :;
5960 elif ! testaddrs openssl >/dev/null; then
5961 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5962 numCANT=$((numCANT+1))
5963 else
5964 gentestcert testsrv
5965 gentestcert testcli
5966 testserversec "$N" "$TEST" "$opts -s -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
5967 fi ;; # NUMCOND, feats
5968 esac
5969 PORT=$((PORT+1))
5970 N=$((N+1))
5971  
5972  
5973 NAME=OPENSSLTCP6_RANGE
5974 case "$TESTS" in
5975 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%range%*|*%$NAME%*)
5976 TEST="$NAME: security of SSL-L over TCP/IPv6 with RANGE option"
5977 if ! eval $NUMCOND; then :;
5978 elif ! testaddrs openssl >/dev/null; then
5979 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5980 numCANT=$((numCANT+1))
5981 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5982 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5983 numCANT=$((numCANT+1))
5984 else
5985 gentestcert6 testsrv6
5986 testserversec "$N" "$TEST" "$opts -s" "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
5987 fi ;; # NUMCOND, feats
5988 esac
5989 PORT=$((PORT+1))
5990 N=$((N+1))
5991  
5992 NAME=OPENSSLTCP6_SOURCEPORT
5993 case "$TESTS" in
5994 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
5995 TEST="$NAME: security of SSL-L over TCP/IPv6 with SOURCEPORT option"
5996 if ! eval $NUMCOND; then :;
5997 elif ! testaddrs openssl >/dev/null; then
5998 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5999 numCANT=$((numCANT+1))
6000 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
6001 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6002 numCANT=$((numCANT+1))
6003 else
6004 gentestcert6 testsrv6
6005 testserversec "$N" "$TEST" "$opts -s" "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
6006 fi ;; # NUMCOND, feats
6007 esac
6008 PORT=$((PORT+1))
6009 N=$((N+1))
6010  
6011 NAME=OPENSSLTCP6_LOWPORT
6012 case "$TESTS" in
6013 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%lowport%*|*%$NAME%*)
6014 TEST="$NAME: security of SSL-L over TCP/IPv6 with LOWPORT option"
6015 if ! eval $NUMCOND; then :;
6016 elif ! testaddrs openssl >/dev/null; then
6017 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6018 numCANT=$((numCANT+1))
6019 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
6020 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6021 numCANT=$((numCANT+1))
6022 else
6023 gentestcert6 testsrv6
6024 testserversec "$N" "$TEST" "$opts -s" "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
6025 fi ;; # NUMCOND, feats
6026 esac
6027 PORT=$((PORT+1))
6028 N=$((N+1))
6029  
6030 NAME=OPENSSLTCP6_TCPWRAP
6031 case "$TESTS" in
6032 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
6033 TEST="$NAME: security of SSL-L over TCP/IPv6 with TCPWRAP option"
6034 if ! eval $NUMCOND; then :;
6035 elif ! feat=$(testaddrs ip6 tcp libwrap openssl) || ! runsip6 >/dev/null; then
6036 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6037 numCANT=$((numCANT+1))
6038 else
6039 gentestcert6 testsrv6
6040 ha="$td/hosts.allow"
6041 hd="$td/hosts.deny"
6042 $ECHO "socat: [::2]" >"$ha"
6043 $ECHO "ALL: ALL" >"$hd"
6044 testserversec "$N" "$TEST" "$opts -s" "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
6045 fi ;; # NUMCOND, feats
6046 esac
6047 PORT=$((PORT+1))
6048 N=$((N+1))
6049  
6050  
6051 # test security with the openssl-commonname option on client side
6052 NAME=OPENSSL_CN_CLIENT_SECURITY
6053 case "$TESTS" in
6054 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6055 TEST="$NAME: security of client openssl-commonname option"
6056 # connect using non matching server name/address with commonname
6057 # options, this should succeed. Then without this option, should fail
6058 if ! eval $NUMCOND; then :;
6059 elif ! testaddrs openssl >/dev/null; then
6060 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6061 numCANT=$((numCANT+1))
6062 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6063 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6064 numCANT=$((numCANT+1))
6065 else
6066 gentestcert testsrv
6067 gentestcert testcli
6068 testserversec "$N" "$TEST" "$opts" "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 "" 0
6069 fi ;; # testaddrs, NUMCOND
6070 esac
6071 PORT=$((PORT+1))
6072 N=$((N+1))
6073  
6074 # test security with the openssl-commonname option on server side
6075 NAME=OPENSSL_CN_SERVER_SECURITY
6076 case "$TESTS" in
6077 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6078 TEST="$NAME: security of server openssl-commonname option"
6079 # connect using with client certificate to server, this should succeed.
6080 # Then use the server with a non matching openssl-commonname option,
6081 # this must fail
6082 if ! eval $NUMCOND; then :;
6083 elif ! testaddrs openssl >/dev/null; then
6084 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6085 numCANT=$((numCANT+1))
6086 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6087 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6088 numCANT=$((numCANT+1))
6089 else
6090 gentestcert testsrv
6091 gentestcert testcli
6092 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt" "" "commonname=onlyyou" "SSL:$LOCALHOST:$PORT,verify=0,cafile=testsrv.crt,cert=testcli.crt,key=testcli.key" 4 tcp "" 0
6093 fi ;; # testaddrs, NUMCOND
6094 esac
6095 PORT=$((PORT+1))
6096 N=$((N+1))
6097  
6098  
6099 NAME=OPENSSL_FIPS_SECURITY
6100 case "$TESTS" in
6101 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6102 TEST="$NAME: OpenSSL restrictions by FIPS"
6103 if ! eval $NUMCOND; then :;
6104 elif ! testaddrs openssl >/dev/null; then
6105 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6106 numCANT=$((numCANT+1))
6107 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6108 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6109 numCANT=$((numCANT+1))
6110 elif ! testoptions fips >/dev/null; then
6111 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
6112 numCANT=$((numCANT+1))
6113 else
6114 gentestcert testsrv
6115 gentestcert testcli
6116 # openssl client accepts a "normal" certificate only when not in fips mode
6117 testserversec "$N" "$TEST" "$opts -s" "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
6118 fi ;; # testaddrs, NUMCOND
6119 esac
6120 PORT=$((PORT+1))
6121 N=$((N+1))
6122  
6123  
6124 NAME=UNIEXECEOF
6125 case "$TESTS" in
6126 *%$N%*|*%functions%*|*%$NAME%*)
6127 TEST="$NAME: give exec'd write-only process a chance to flush (-u)"
6128 testod "$N" "$TEST" "" exec:"$OD_C" "$opts -u"
6129 esac
6130 N=$((N+1))
6131  
6132  
6133 NAME=REVEXECEOF
6134 case "$TESTS" in
6135 *%$N%*|*%functions%*|*%$NAME%*)
6136 TEST="$NAME: give exec'd write-only process a chance to flush (-U)"
6137 testod "$N" "$TEST" exec:"$OD_C" "-" "$opts -U"
6138 esac
6139 N=$((N+1))
6140  
6141  
6142 NAME=FILANDIR
6143 case "$TESTS" in
6144 *%filan%*|*%$NAME%*)
6145 TEST="$NAME: check type printed for directories"
6146 if ! eval $NUMCOND; then :; else
6147 te="$td/test$N.stderr"
6148 printf "test $F_n $TEST... " $N
6149 type=$($FILAN -f . 2>$te |tail -n 1 |awk '{print($2);}')
6150 if [ "$type" = "dir" ]; then
6151 $PRINTF "$OK\n"
6152 numOK=$((numOK+1))
6153 else
6154 $PRINTF "$FAILED\n"
6155 cat "$te"
6156 numFAIL=$((numFAIL+1))
6157 listFAIL="$listFAIL $N"
6158 fi
6159 fi ;; # NUMCOND
6160 esac
6161 N=$((N+1))
6162  
6163  
6164 NAME=FILANSOCKET
6165 case "$TESTS" in
6166 *%filan%*|*%$NAME%*)
6167 TEST="$NAME: capability to analyze named unix socket"
6168 if ! eval $NUMCOND; then :; else
6169 ts="$td/test$N.socket"
6170 te1="$td/test$N.stderr1" # socat
6171 te2="$td/test$N.stderr2" # filan
6172 printf "test $F_n $TEST... " $N
6173 $TRACE $SOCAT unix-l:"$ts" /dev/null </dev/null 2>"$te1" &
6174 spid=$!
6175 waitfile "$ts" 1
6176 type=$($FILAN -f "$ts" 2>$te2 |tail -n 1 |awk '{print($2);}')
6177 if [ "$type" = "socket" ]; then
6178 $PRINTF "$OK\n"
6179 numOK=$((numOK+1))
6180 else
6181 $PRINTF "$FAILED\n"
6182 cat "$te1"
6183 cat "$te2"
6184 numFAIL=$((numFAIL+1))
6185 listFAIL="$listFAIL $N"
6186 fi
6187 kill $spid 2>/dev/null
6188 wait
6189 fi ;; # NUMCOND
6190 esac
6191 N=$((N+1))
6192  
6193  
6194 testptywaitslave () {
6195 local N="$1"
6196 local TEST="$2"
6197 local PTYTYPE="$3" # ptmx or openpty
6198 local opts="$4"
6199  
6200 local tp="$td/test$N.pty"
6201 local ts="$td/test$N.socket"
6202 local tf="$td/test$N.file"
6203 local tdiff="$td/test$N.diff"
6204 local te1="$td/test$N.stderr1"
6205 local te2="$td/test$N.stderr2"
6206 local te3="$td/test$N.stderr3"
6207 local te4="$td/test$N.stderr4"
6208 local da="test$N $(date) $RANDOM"
6209 printf "test $F_n $TEST... " $N
6210 # first generate a pty, then a socket
6211 ($TRACE $SOCAT $opts -lpsocat1 pty,$PTYTYPE,pty-wait-slave,link="$tp" unix-listen:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev/null &
6212 pid=$!
6213 waitfile "$tp"
6214 # if pty was non-blocking, the socket is active, and socat1 will term
6215 $TRACE $SOCAT $opts -T 10 -lpsocat2 file:/dev/null unix-connect:"$ts" 2>"$te2"
6216 # if pty is blocking, first socat is still active and we get a connection now
6217 #((echo "$da"; sleep 2) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6218 ( (waitfile "$ts"; echo "$da"; sleep 1) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6219 waitfile "$ts"
6220 # but we need an echoer on the socket
6221 $TRACE $SOCAT $opts -lpsocat4 unix:"$ts" echo 2>"$te4"
6222 # now $tf file should contain $da
6223 #kill $pid 2>/dev/null
6224 wait
6225 #
6226 if echo "$da" |diff - "$tf"> "$tdiff"; then
6227 $PRINTF "$OK\n"
6228 numOK=$((numOK+1))
6229 else
6230 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
6231 cat "$te1"
6232 #cat "$te2" # not of interest
6233 cat "$te3"
6234 cat "$te4"
6235 cat "$tdiff"
6236 numCANT=$((numCANT+1))
6237 fi
6238 }
6239  
6240 NAME=PTMXWAITSLAVE
6241 PTYTYPE=ptmx
6242 case "$TESTS" in
6243 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6244 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6245 if ! eval $NUMCOND; then :; else
6246 if ! feat=$(testaddrs pty); then
6247 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6248 numCANT=$((numCANT+1))
6249 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6250 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6251 numCANT=$((numCANT+1))
6252 else
6253 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6254 fi
6255 fi ;; # NUMCOND
6256 esac
6257 N=$((N+1))
6258  
6259 NAME=OPENPTYWAITSLAVE
6260 PTYTYPE=openpty
6261 case "$TESTS" in
6262 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6263 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6264 if ! eval $NUMCOND; then :;
6265 elif ! feat=$(testaddrs pty); then
6266 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6267 numCANT=$((numCANT+1))
6268 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6269 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6270 numCANT=$((numCANT+1))
6271 else
6272 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6273 fi ;; # NUMCOND, feats
6274 esac
6275 N=$((N+1))
6276  
6277  
6278 NAME=CONNECTTIMEOUT
6279 case "$TESTS" in
6280 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6281 TEST="$NAME: test the connect-timeout option"
6282 if ! eval $NUMCOND; then :;
6283 elif ! feat=$(testaddrs tcp); then
6284 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6285 numCANT=$((numCANT+1))
6286 elif ! feat=$(testoptions connect-timeout); then
6287 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6288 numCANT=$((numCANT+1))
6289 else
6290 # we need a hanging connection attempt, guess an address for this
6291 case "$UNAME" in
6292 Linux) HANGIP=1.0.0.1 ;;
6293 *) HANGIP=255.255.255.254 ;;
6294 esac
6295 te1="$td/test$N.stderr1"
6296 tk1="$td/test$N.kill1"
6297 te2="$td/test$N.stderr2"
6298 tk2="$td/test$N.kill2"
6299 $PRINTF "test $F_n $TEST... " $N
6300 # first, try to make socat hang and see if it can be killed
6301 #$TRACE $SOCAT $opts - tcp:$HANGIP:1 >"$te1" 2>&1 </dev/null &
6302 CMD="$TRACE $SOCAT $opts - tcp:$HANGIP:1"
6303 $CMD >"$te1" 2>&1 </dev/null &
6304 pid1=$!
6305 sleep 2
6306 if ! kill $pid1 2>"$tk1"; then
6307 $PRINTF "${YELLOW}does not hang${NORMAL}\n"
6308 numCANT=$((numCANT+1))
6309 else
6310 # second, set connect-timeout and see if socat exits before kill
6311 $TRACE $SOCAT $opts - tcp:$HANGIP:1,connect-timeout=1.0 >"$te2" 2>&1 </dev/null &
6312 pid2=$!
6313 sleep 2
6314 if kill $pid2 2>"$tk2"; then
6315 $PRINTF "$FAILED\n"
6316 echo "$CMD"
6317 cat "$te1"
6318 cat "$te2"
6319 numFAIL=$((numFAIL+1))
6320 listFAIL="$listFAIL $N"
6321 else
6322 $PRINTF "$OK\n"
6323 numOK=$((numOK+1))
6324 fi
6325 fi
6326 wait
6327 fi ;; # testaddrs, NUMCOND
6328 esac
6329 N=$((N+1))
6330  
6331  
6332 # version 1.7.0.0 had a bug with the connect-timeout option: while it correctly
6333 # terminated a hanging connect attempt, it prevented a successful connection
6334 # establishment from being recognized by socat, instead the timeout occurred
6335 NAME=CONNECTTIMEOUT_CONN
6336 if ! eval $NUMCOND; then :; else
6337 case "$TESTS" in
6338 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6339 TEST="$NAME: TCP4 connect-timeout option when server replies"
6340 # just try a connection that is expected to succeed with the usual data
6341 # transfer; with the bug it will fail
6342 tf="$td/test$N.stdout"
6343 te="$td/test$N.stderr"
6344 tdiff="$td/test$N.diff"
6345 tsl=$PORT
6346 ts="127.0.0.1:$tsl"
6347 da="test$N $(date) $RANDOM"
6348 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE"
6349 CMD2="$TRACE $SOCAT $opts STDIO TCP4:$ts,connect-timeout=1"
6350 printf "test $F_n $TEST... " $N
6351 $CMD1 >"$tf" 2>"${te}1" &
6352 pid1=$!
6353 waittcp4port $tsl 1
6354 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6355 if [ $? -ne 0 ]; then
6356 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6357 echo "$CMD1 &"
6358 cat "${te}1"
6359 echo "$CMD2"
6360 cat "${te}2"
6361 numFAIL=$((numFAIL+1))
6362 listFAIL="$listFAIL $N"
6363 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6364 $PRINTF "$FAILED\n"
6365 cat "$tdiff"
6366 numFAIL=$((numFAIL+1))
6367 listFAIL="$listFAIL $N"
6368 else
6369 $PRINTF "$OK\n"
6370 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
6371 numOK=$((numOK+1))
6372 fi
6373 kill $pid1 2>/dev/null
6374 wait ;;
6375 esac
6376 PORT=$((PORT+1))
6377 fi # NUMCOND
6378 N=$((N+1))
6379  
6380  
6381 NAME=OPENSSLLISTENDSA
6382 case "$TESTS" in
6383 *%$N%*|*%functions%*|*%chain%*|*%openssl%*|*%tcp%*|*%$NAME%*)
6384 TEST="$NAME: openssl listen with DSA certificate"
6385 if ! eval $NUMCOND; then :;
6386 elif ! testaddrs openssl >/dev/null; then
6387 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6388 numCANT=$((numCANT+1))
6389 else
6390 SRVCERT=testsrvdsa
6391 gentestdsacert $SRVCERT
6392 tf="$td/test$N.stdout"
6393 te="$td/test$N.stderr"
6394 tdiff="$td/test$N.diff"
6395 da="test$N $(date) $RANDOM"
6396 #CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe"
6397 CMD2="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr ^OPENSSL-LISTEN,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0\|pipe"
6398 #CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
6399 CMD="$TRACE $SOCAT $opts - openssl,verify=0,$SOCAT_EGD|tcp4:$LOCALHOST:$PORT"
6400 $PRINTF "test $F_n $TEST... " $N
6401 eval "$CMD2 2>\"${te}1\" &"
6402 pid=$! # background process id
6403 waittcp4port $PORT
6404 echo "$da" |$CMD >$tf 2>"${te}2"
6405 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
6406 $PRINTF "$FAILED\n"
6407 echo "$CMD2 &"
6408 echo "$CMD"
6409 cat "${te}1"
6410 cat "${te}2"
6411 cat "$tdiff"
6412 numFAIL=$((numFAIL+1))
6413 listFAIL="$listFAIL $N"
6414 else
6415 $PRINTF "$OK\n"
6416 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
6417 numOK=$((numOK+1))
6418 fi
6419 kill $pid 2>/dev/null
6420 wait
6421 fi ;; # testaddrs, NUMCOND
6422 esac
6423 PORT=$((PORT+1))
6424 N=$((N+1))
6425  
6426  
6427 # derive signal number from signal name
6428 # kill -l should provide the info
6429 signum () {
6430 if [ ! "$BASH_VERSION" -o -o posix ]; then
6431 # we expect:
6432 for i in $(POSIXLY_CORRECT=1 kill -l); do echo "$i"; done |grep -n -i "^$1$" |cut -d: -f1
6433 else
6434 # expect:
6435 # " 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL"
6436 signam="$1"
6437 kill -l </dev/null |
6438 while read l; do printf "%s %s\n%s %s\n%s %s\n%s %s\n" $l; done |
6439 grep -e "SIG$signam\$" |
6440 cut -d ')' -f 1
6441 fi
6442 }
6443  
6444 # problems with QUIT, INT (are blocked in system() )
6445 for signam in TERM ILL; do
6446 NAME=EXITCODESIG$signam
6447 case "$TESTS" in
6448 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6449 TEST="$NAME: exit status when dying on SIG$signam"
6450 if ! eval $NUMCOND; then :;
6451 elif ! feat=$(testaddrs pty); then
6452 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
6453 numCANT=$((numCANT+1))
6454 else
6455 SIG="$(signum $signam)"
6456 te="$td/test$N.stderr"
6457 tpp="$td/test$N.ppid"
6458 tp="$td/test$N.pid"
6459 $PRINTF "test $F_n $TEST... " $N
6460 (sleep 1; kill -"$SIG" "$(cat "$tpp")") &
6461 # a simple "system:echo $PPID..." does not work on NetBSD, OpenBSD
6462 #$TRACE $SOCAT $opts echo system:'exec /bin/bash -c "echo \$PPID '">$tpp"'; echo \$$ '">$tp; read x\"",nofork 2>"$te"; stat=$?
6463 tsh="$td/test$N.sh"
6464 cat <<EOF >"$tsh"
6465 #! /bin/bash
6466 echo \$PPID >"$tpp"
6467 echo \$\$ >"$tp"
6468 read x
6469 EOF
6470 chmod a+x "$tsh"
6471 $TRACE $SOCAT $opts echo system:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"; stat=$?
6472 sleep 1; kill -INT $(cat $tp)
6473 wait
6474 if [ "$stat" -eq $((128+$SIG)) ]; then
6475 $PRINTF "$OK\n"
6476 numOK=$((numOK+1))
6477 else
6478 $PRINTF "$FAILED\n"
6479 cat "$te"
6480 numFAIL=$((numFAIL+1))
6481 listFAIL="$listFAIL $N"
6482 fi
6483 wait
6484 fi ;; # NUMCOND, feats
6485 esac
6486 N=$((N+1))
6487 done
6488  
6489  
6490 NAME=READBYTES
6491 #set -vx
6492 case "$TESTS" in
6493 *%$N%*|*%functions%*|*%$NAME%*)
6494 TEST="$NAME: restrict reading from file with bytes option"
6495 if ! eval $NUMCOND; then :;
6496 elif false; then
6497 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6498 numCANT=$((numCANT+1))
6499 else
6500 tr="$td/test$N.ref"
6501 ti="$td/test$N.in"
6502 to="$td/test$N.out"
6503 te="$td/test$N.err"
6504 tdiff="$td/test$N.diff"
6505 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
6506 # the feature that we really want to test is in the readline.sh script:
6507 CMD="$TRACE $SOCAT $opts -u open:$ti,readbytes=100 -"
6508 printf "test $F_n $TEST... " $N
6509 rm -f "$tf" "$ti" "$to"
6510 #
6511 echo "AAAAAAAAAAAAAAAAAAAAAAAA
6512 AAAAAAAAAAAAAAAAAAAAAAAA
6513 AAAAAAAAAAAAAAAAAAAAAAAA
6514 AAAAAAAAAAAAAAAAAAAAAAAA" >"$tr" # 100 bytes
6515 cat "$tr" "$tr" >"$ti" # 200 bytes
6516 $CMD >"$to" 2>"$te"
6517 if ! diff "$tr" "$to" >"$tdiff" 2>&1; then
6518 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6519 echo "$CMD"
6520 cat "$te"
6521 cat "$tdiff"
6522 numFAIL=$((numFAIL+1))
6523 listFAIL="$listFAIL $N"
6524 else
6525 $PRINTF "$OK\n"
6526 if [ -n "$debug" ]; then cat $te; fi
6527 numOK=$((numOK+1))
6528 fi
6529 fi ;; # NUMCOND, feats
6530 esac
6531 N=$((N+1))
6532  
6533  
6534 NAME=UDPLISTENFORK
6535 case "$TESTS" in
6536 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%listen%*|*%fork%*|*%$NAME%*)
6537 TEST="$NAME: UDP socket rebinds after first connection"
6538 if ! eval $NUMCOND; then :; else
6539 tf="$td/test$N.stdout"
6540 te="$td/test$N.stderr"
6541 tdiff="$td/test$N.diff"
6542 da1="test$N $(date) $RANDOM"
6543 da2="test$N $(date) $RANDOM"
6544 #establish a listening and forking udp socket in background
6545 #processes hang forever without -T
6546 SRV="$TRACE $SOCAT -T 5 $opts -lpserver UDP4-LISTEN:$PORT,bind=$LOCALHOST,fork PIPE"
6547 #make a first and a second connection
6548 CLI="$TRACE $SOCAT $opts -lpclient - UDP4-CONNECT:$LOCALHOST:$PORT"
6549 $PRINTF "test $F_n $TEST... " $N
6550 eval "$SRV 2>${te}s &"
6551 pids=$!
6552 waitudp4port "$PORT"
6553 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6554 if [ $? -ne 0 ]; then
6555 kill "$pids" 2>/dev/null
6556 $PRINTF "$NO_RESULT (first conn failed):\n"
6557 echo "$SRV &"
6558 echo "$CLI"
6559 cat "${te}s" "${te}1"
6560 numCANT=$((numCANT+1))
6561 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6562 kill "$pids" 2>/dev/null
6563 $PRINTF "$NO_RESULT (first conn failed); diff:\n"
6564 cat "$tdiff"
6565 numCANT=$((numCANT+1))
6566 else
6567 sleep 2 # UDP-LISTEN sleeps 1s
6568 echo "$da2" |eval "$CLI" >"${tf}2" 2>"${te}2"
6569 rc="$?"; kill "$pids" 2>/dev/null
6570 if [ $rc -ne 0 ]; then
6571 $PRINTF "$FAILED:\n"
6572 echo "$SRV &"
6573 echo "$CLI"
6574 cat "${te}s" "${te}2"
6575 numFAIL=$((numFAIL+1))
6576 listFAIL="$listFAIL $N"
6577 elif ! echo "$da2" |diff - "${tf}2" >"$tdiff"; then
6578 $PRINTF "$FAILED: diff\n"
6579 cat "$tdiff"
6580 numFAIL=$((numFAIL+1))
6581 listFAIL="$listFAIL $N"
6582 else
6583 $PRINTF "$OK\n"
6584 numOK=$((numOK+1))
6585 fi # !( $? -ne 0)
6586 fi # !(rc -ne 0)
6587 wait
6588 fi ;; # NUMCOND, feats
6589 esac
6590 PORT=$((PORT+1))
6591 N=$((N+1))
6592  
6593  
6594 NAME=UNIXLISTENFORK
6595 # is a listen address capable of forking to child processes and have both
6596 # active?
6597 while read PROTOV MAJADDR MINADDR; do
6598 if [ -z "$PROTOV" ] || [[ "$PROTOV" == \#* ]]; then continue; fi
6599 protov="$(echo "$PROTOV" |tr A-Z a-z)"
6600 proto="${protov%%[0-9]}"
6601 NAME=${PROTOV}LISTENFORK
6602 case "$TESTS" in
6603 *%$N%*|*%functions%*|*%$protov%*|*%$proto%*|*%listen%*|*%fork%*|*%$NAME%*)
6604 TEST="$NAME: $PROTOV listen handles 2 concurrent connections"
6605 # have a listening address with fork option. connect with client1, send a piece
6606 # of data, wait 1s, connect with client2, send another piece of data, wait 1s,
6607 # and send another piece of data with client1. The server processes append all
6608 # data to the same file. Check all data are written to the file in correct
6609 # order.
6610 if ! eval $NUMCOND; then :;
6611 #elif ! feat=$(testaddrs $PROTOV); then
6612 # $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$PROTOV" |tr a-z A-Z) not available${NORMAL}\n" $N
6613 # numCANT=$((numCANT+1))
6614 elif ! runs$protov; then
6615 $PRINTF "test $F_n $TEST... ${YELLOW}$PROTOV not available${NORMAL}\n" $N
6616 numCANT=$((numCANT+1))
6617 else
6618 ts="$td/test$N.sock"
6619 tref="$td/test$N.ref"
6620 tf="$td/test$N.stdout"
6621 te="$td/test$N.stderr"
6622 tdiff="$td/test$N.diff"
6623 da1a="test$N $(date) 1a $RANDOM"
6624 da1b="test$N $(date) 1b $RANDOM"
6625 da2="test$N $(date) 2 $RANDOM"
6626 case "$MAJADDR" in
6627 "FILE")
6628 tla="$ts"
6629 tca="$ts"
6630 waitproto="file"
6631 waitfor="$ts" ;;
6632 esac
6633 case "$MINADDR" in
6634 "PORT")
6635 tla="$PORT,bind=$MAJADDR"
6636 tca="$MAJADDR:$PORT"
6637 waitproto="${protov}port"
6638 waitfor="$PORT" ;;
6639 esac
6640 #set -xv
6641 echo -e "$da1a\n$da2\n$da1b" >"$tref"
6642 # establish a listening and forking listen socket in background
6643 # UDP processes hang forever without -T
6644 CMD0="$TRACE $SOCAT -T 5 $opts -lpserver $PROTOV-LISTEN:$tla,fork PIPE"
6645 # make a first and a second connection
6646 CMD1="$TRACE $SOCAT $opts -lpclient - $PROTOV-CONNECT:$tca"
6647 $PRINTF "test $F_n $TEST... " $N
6648 eval "$CMD0 2>${te}0 &"
6649 pid0=$!
6650 wait$waitproto "$waitfor" 1 2
6651 (echo "$da1a"; sleep 2; echo "$da1b") |eval "$CMD1" >>"${tf}" 2>"${te}1" &
6652 sleep 1
6653 # trailing sleep req for sctp because no half close
6654 (echo "$da2"; sleep 1) |eval "$CMD1" >>"${tf}" 2>"${te}2" &
6655 sleep 2
6656 kill $pid0 2>/dev/null
6657 wait
6658 if ! diff "$tref" "$tf" >"$tdiff"; then
6659 $PRINTF "$FAILED\n"
6660 cat "${te}0" "${te}1" "${te}2"
6661 cat "$tdiff"
6662 numFAIL=$((numFAIL+1))
6663 listFAIL="$listFAIL $N"
6664 else
6665 $PRINTF "$OK\n"
6666 numOK=$((numOK+1))
6667 fi # !(rc -ne 0)
6668 fi ;; # NUMCOND, feats
6669 esac
6670 PORT=$((PORT+1))
6671 N=$((N+1))
6672 done <<<"
6673 TCP4 $LOCALHOST PORT
6674 TCP6 $LOCALHOST6 PORT
6675 UDP4 $LOCALHOST PORT
6676 UDP6 $LOCALHOST6 PORT
6677 SCTP4 $LOCALHOST PORT
6678 SCTP6 $LOCALHOST6 PORT
6679 UNIX FILE ,
6680 "
6681  
6682  
6683 NAME=UNIXTOSTREAM
6684 case "$TESTS" in
6685 *%$N%*|*%functions%*|*%unix%*|*%listen%*|*%$NAME%*)
6686 TEST="$NAME: generic UNIX client connects to stream socket"
6687 if ! eval $NUMCOND; then :; else
6688 ts="$td/test$N.socket"
6689 tf="$td/test$N.stdout"
6690 te="$td/test$N.stderr"
6691 tdiff="$td/test$N.diff"
6692 da1="test$N $(date) $RANDOM"
6693 #establish a listening unix socket in background
6694 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
6695 #make a connection
6696 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts\""
6697 $PRINTF "test $F_n $TEST... " $N
6698 eval "$SRV 2>${te}s &"
6699 pids=$!
6700 waitfile "$ts"
6701 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6702 if [ $? -ne 0 ]; then
6703 kill "$pids" 2>/dev/null
6704 $PRINTF "$FAILED:\n"
6705 echo "$SRV &"
6706 echo "$CLI"
6707 cat "${te}s" "${te}1"
6708 numFAIL=$((numFAIL+1))
6709 listFAIL="$listFAIL $N"
6710 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6711 kill "$pids" 2>/dev/null
6712 $PRINTF "$FAILED; diff:\n"
6713 cat "$tdiff"
6714 numFAIL=$((numFAIL+1))
6715 listFAIL="$listFAIL $N"
6716 else
6717 $PRINTF "$OK\n"
6718 numOK=$((numOK+1))
6719 fi # !(rc -ne 0)
6720 wait
6721 fi ;; # NUMCOND
6722 esac
6723 N=$((N+1))
6724  
6725  
6726 NAME=UNIXTODGRAM
6727 case "$TESTS" in
6728 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%recv%*|*%$NAME%*)
6729 TEST="$NAME: generic UNIX client connects to datagram socket"
6730 if ! eval $NUMCOND; then :; else
6731 ts1="$td/test$N.socket1"
6732 ts2="$td/test$N.socket2"
6733 tf="$td/test$N.stdout"
6734 te="$td/test$N.stderr"
6735 tdiff="$td/test$N.diff"
6736 da1="test$N $(date) $RANDOM"
6737 #establish a receiving unix datagram socket in background
6738 SRV="$TRACE $SOCAT $opts -lpserver UNIX-RECVFROM:\"$ts1\" PIPE"
6739 #make a connection
6740 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\",bind=\"$ts2\""
6741 #CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\""
6742 $PRINTF "test $F_n $TEST... " $N
6743 eval "$SRV 2>${te}s &"
6744 pids=$!
6745 waitfile "$ts1"
6746 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6747 rc=$?
6748 wait
6749 if [ $rc -ne 0 ]; then
6750 kill "$pids" 2>/dev/null
6751 $PRINTF "$FAILED:\n"
6752 echo "$SRV &"
6753 cat "${te}s"
6754 echo "$CLI"
6755 cat "${te}1" "${te}1"
6756 numFAIL=$((numFAIL+1))
6757 listFAIL="$listFAIL $N"
6758 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6759 kill "$pids" 2>/dev/null
6760 $PRINTF "$FAILED:\n"
6761 echo "$SRV &"
6762 cat "${te}s"
6763 echo "$CLI"
6764 cat "${te}1"
6765 cat "$tdiff"
6766 numFAIL=$((numFAIL+1))
6767 listFAIL="$listFAIL $N"
6768 else
6769 $PRINTF "$OK\n"
6770 numOK=$((numOK+1))
6771 fi # !(rc -ne 0)
6772 fi ;; # NUMCOND
6773 esac
6774 N=$((N+1))
6775  
6776  
6777 # there was an error in address EXEC with options pipes,stderr
6778 NAME=EXECPIPESSTDERR
6779 case "$TESTS" in
6780 *%$N%*|*%functions%*|*%$NAME%*)
6781 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
6782 # this test is known to fail when logging is enabled with OPTS/opts env var.
6783 SAVE_opts="$opts"
6784 opts="$(echo "$opts" |sed 's/-d//g')"
6785 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6786 opts="$SAVE_opts"
6787 esac
6788 N=$((N+1))
6789  
6790 # EXEC and SYSTEM with stderr injected socat messages into the data stream.
6791 NAME=EXECSTDERRLOG
6792 case "$TESTS" in
6793 *%$N%*|*%functions%*|*%$NAME%*)
6794 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
6795 SAVE_opts="$opts"
6796 # make sure at least two -d are there
6797 case "$opts" in
6798 *-d*-d*) ;;
6799 *-d*) opts="$opts -d" ;;
6800 *) opts="-d -d" ;;
6801 esac
6802 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6803 opts="$SAVE_opts"
6804 esac
6805 N=$((N+1))
6806  
6807  
6808 NAME=SIMPLEPARSE
6809 case "$TESTS" in
6810 *%$N%*|*%functions%*|*%PARSE%*|*%$NAME%*)
6811 TEST="$NAME: invoke socat from socat"
6812 testecho "$N" "$TEST" "" exec:"$SOCAT - exec\:$CAT,pipes" "$opts"
6813 esac
6814 N=$((N+1))
6815  
6816  
6817 NAME=FULLPARSE
6818 case "$TESTS" in
6819 *%$N%*|*%functions%*|*%parse%*|*%$NAME%*)
6820 TEST="$NAME: correctly parse special chars"
6821 if ! eval $NUMCOND; then :; else
6822 $PRINTF "test $F_n $TEST... " $N
6823 tf="$td/test$N.stdout"
6824 te="$td/test$N.stderr"
6825 tdiff="$td/test$N.diff"
6826 # a string where commas are hidden in nesting lexical constructs
6827 # if they are scanned incorrectly, socat will see an "unknown option"
6828 dain='(,)[,]{,}","([),])hugo'
6829 daout='(,)[,]{,},([),])hugo'
6830 $TRACE $SOCAT $opts -u "exec:echo $dain" - >"$tf" 2>"$te"
6831 rc=$?
6832 echo "$daout" |diff "$tf" - >"$tdiff"
6833 if [ "$rc" -ne 0 ]; then
6834 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6835 echo "$TRACE $SOCAT" -u "exec:echo $da" -
6836 cat "$te"
6837 numFAIL=$((numFAIL+1))
6838 listFAIL="$listFAIL $N"
6839 elif [ -s "$tdiff" ]; then
6840 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6841 echo diff:
6842 cat "$tdiff"
6843 if [ -n "$debug" ]; then cat $te; fi
6844 numFAIL=$((numFAIL+1))
6845 listFAIL="$listFAIL $N"
6846 else
6847 $PRINTF "$OK\n"
6848 if [ -n "$debug" ]; then cat $te; fi
6849 numOK=$((numOK+1))
6850 fi
6851 fi ;; # NUMCOND
6852 esac
6853 N=$((N+1))
6854  
6855 NAME=NESTEDSOCATEXEC
6856 case "$TESTS" in
6857 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
6858 TEST="$NAME: does lexical analysis work sensibly (exec)"
6859 testecho "$N" "$TEST" "" "exec:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
6860 esac
6861 N=$((N+1))
6862  
6863 NAME=NESTEDSOCATSYSTEM
6864 case "$TESTS" in
6865 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
6866 TEST="$NAME: does lexical analysis work sensibly (system)"
6867 testecho "$N" "$TEST" "" "system:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
6868 esac
6869 N=$((N+1))
6870  
6871  
6872 NAME=TCP6BYTCP4
6873 case "$TESTS" in
6874 *%$N%*|*%functions%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
6875 TEST="$NAME: TCP4 mapped into TCP6 address space"
6876 if ! eval $NUMCOND; then :;
6877 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
6878 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6879 numCANT=$((numCANT+1))
6880 else
6881 tf="$td/test$N.stdout"
6882 te="$td/test$N.stderr"
6883 tdiff="$td/test$N.diff"
6884 tsl=$PORT
6885 ts="127.0.0.1:$tsl"
6886 da="test$N $(date) $RANDOM"
6887 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,reuseaddr PIPE"
6888 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP6:$ts"
6889 printf "test $F_n $TEST... " $N
6890 $CMD1 >"$tf" 2>"${te}1" &
6891 pid=$! # background process id
6892 waittcp6port $tsl 1
6893 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6894 if [ $? -ne 0 ]; then
6895 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6896 echo "$CMD1 &"
6897 echo "$CMD2"
6898 cat "${te}1"
6899 cat "${te}2"
6900 numFAIL=$((numFAIL+1))
6901 listFAIL="$listFAIL $N"
6902 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6903 $PRINTF "$FAILED: diff:\n"
6904 cat "$tdiff"
6905 numFAIL=$((numFAIL+1))
6906 listFAIL="$listFAIL $N"
6907 else
6908 $PRINTF "$OK\n"
6909 if [ -n "$debug" ]; then cat $te; fi
6910 numOK=$((numOK+1))
6911 fi
6912 kill $pid 2>/dev/null; wait
6913 fi ;; # NUMCOND, feats
6914 esac
6915 PORT=$((PORT+1))
6916 N=$((N+1))
6917  
6918  
6919 # test the UDP4-SENDTO and UDP4-RECVFROM addresses together
6920 NAME=UDP4DGRAM
6921 case "$TESTS" in
6922 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%$NAME%*)
6923 TEST="$NAME: UDP/IPv4 sendto and recvfrom"
6924 # start a UDP4-RECVFROM process that echoes data, and send test data using
6925 # UDP4-SENDTO. The sent data should be returned.
6926 if ! eval $NUMCOND; then :; else
6927 tf="$td/test$N.stdout"
6928 te="$td/test$N.stderr"
6929 tdiff="$td/test$N.diff"
6930 ts1p=$PORT; PORT=$((PORT+1))
6931 ts1a="127.0.0.1"
6932 ts1="$ts1a:$ts1p"
6933 ts2p=$PORT; PORT=$((PORT+1))
6934 ts2="127.0.0.1:$ts2p"
6935 da="test$N $(date) $RANDOM"
6936 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
6937 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2"
6938 printf "test $F_n $TEST... " $N
6939 $CMD1 2>"${te}1" &
6940 pid1="$!"
6941 waitudp4port $ts1p 1
6942 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6943 rc2="$?"
6944 kill "$pid1" 2>/dev/null; wait;
6945 if [ "$rc2" -ne 0 ]; then
6946 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6947 echo "$CMD1 &"
6948 cat "${te}1"
6949 echo "$CMD2"
6950 cat "${te}2"
6951 numFAIL=$((numFAIL+1))
6952 listFAIL="$listFAIL $N"
6953 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6954 $PRINTF "$FAILED\n"
6955 cat "$tdiff"
6956 echo "$CMD1 &"
6957 cat "${te}1"
6958 echo "$CMD2"
6959 cat "${te}2"
6960 numFAIL=$((numFAIL+1))
6961 listFAIL="$listFAIL $N"
6962 else
6963 $PRINTF "$OK\n"
6964 if [ -n "$debug" ]; then cat $te; fi
6965 numOK=$((numOK+1))
6966 fi
6967 fi # NUMCOND
6968 ;;
6969 esac
6970 PORT=$((PORT+1))
6971 N=$((N+1))
6972  
6973  
6974 NAME=UDP6DGRAM
6975 case "$TESTS" in
6976 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%$NAME%*)
6977 TEST="$NAME: UDP/IPv6 datagram"
6978 if ! eval $NUMCOND; then :;
6979 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
6980 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6981 numCANT=$((numCANT+1))
6982 else
6983 tf="$td/test$N.stdout"
6984 te="$td/test$N.stderr"
6985 tdiff="$td/test$N.diff"
6986 ts1p=$PORT; PORT=$((PORT+1))
6987 tsa="[::1]"
6988 ts1="$tsa:$ts1p"
6989 ts2p=$PORT; PORT=$((PORT+1))
6990 ts2="$tsa:$ts2p"
6991 da="test$N $(date) $RANDOM"
6992 CMD1="$TRACE $SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
6993 CMD2="$TRACE $SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2"
6994 printf "test $F_n $TEST... " $N
6995 $CMD1 2>"${te}1" &
6996 waitudp6port $ts1p 1
6997 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6998 if [ $? -ne 0 ]; then
6999 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7000 echo "$CMD1 &"
7001 echo "$CMD2"
7002 cat "${te}1"
7003 cat "${te}2"
7004 numFAIL=$((numFAIL+1))
7005 listFAIL="$listFAIL $N"
7006 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7007 $PRINTF "$FAILED\n"
7008 cat "$tdiff"
7009 numFAIL=$((numFAIL+1))
7010 listFAIL="$listFAIL $N"
7011 else
7012 $PRINTF "$OK\n"
7013 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
7014 numOK=$((numOK+1))
7015 fi
7016 fi ;; # NUMCOND, feats
7017 esac
7018 PORT=$((PORT+1))
7019 N=$((N+1))
7020  
7021  
7022 NAME=RAWIP4RECVFROM
7023 case "$TESTS" in
7024 *%$N%*|*%functions%*|*%ip%*|*%ip4%*|*%rawip%*|*%rawip4%*|*%dgram%*|*%root%*|*%$NAME%*)
7025 TEST="$NAME: raw IPv4 datagram"
7026 if ! eval $NUMCOND; then :;
7027 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7028 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7029 numCANT=$((numCANT+1))
7030 else
7031 tf="$td/test$N.stdout"
7032 te="$td/test$N.stderr"
7033 tdiff="$td/test$N.diff"
7034 ts1p=$PROTO; PROTO=$((PROTO+1))
7035 ts1a="127.0.0.1"
7036 ts1="$ts1a:$ts1p"
7037 ts2a="$SECONDADDR"
7038 ts2="$ts2a:$ts2p"
7039 da="test$N $(date) $RANDOM"
7040 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
7041 CMD2="$TRACE $SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a"
7042 printf "test $F_n $TEST... " $N
7043 $CMD1 2>"${te}1" &
7044 pid1=$!
7045 waitip4proto $ts1p 1
7046 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7047 rc2=$?
7048 kill $pid1 2>/dev/null; wait
7049 if [ $rc2 -ne 0 ]; then
7050 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7051 echo "$CMD1 &"
7052 echo "$CMD2"
7053 cat "${te}1"
7054 cat "${te}2"
7055 numFAIL=$((numFAIL+1))
7056 listFAIL="$listFAIL $N"
7057 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7058 $PRINTF "$FAILED\n"
7059 cat "$tdiff"
7060 numFAIL=$((numFAIL+1))
7061 listFAIL="$listFAIL $N"
7062 else
7063 $PRINTF "$OK\n"
7064 if [ -n "$debug" ]; then cat $te; fi
7065 numOK=$((numOK+1))
7066 fi
7067 fi ;; # root, NUMCOND
7068 esac
7069 N=$((N+1))
7070  
7071  
7072 if false; then
7073 NAME=RAWIP6RECVFROM
7074 case "$TESTS" in
7075 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%dgram%*|*%root%*|*%$NAME%*)
7076 TEST="$NAME: raw IPv6 datagram by self addressing"
7077 if ! eval $NUMCOND; then :;
7078 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7079 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7080 numCANT=$((numCANT+1))
7081 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7082 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7083 numCANT=$((numCANT+1))
7084 else
7085 tf="$td/test$N.stdout"
7086 te="$td/test$N.stderr"
7087 tdiff="$td/test$N.diff"
7088 ts1p=$PROTO; PROTO=$((PROTO+1))
7089 tsa="[::1]"
7090 ts1="$tsa:$ts1p"
7091 ts2="$tsa"
7092 da="test$N $(date) $RANDOM"
7093 #CMD1="$TRACE $SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
7094 CMD2="$TRACE $SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2"
7095 printf "test $F_n $TEST... " $N
7096 #$CMD1 2>"${te}1" &
7097 waitip6proto $ts1p 1
7098 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7099 if [ $? -ne 0 ]; then
7100 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7101 # echo "$CMD1 &"
7102 # cat "${te}1"
7103 echo "$CMD2"
7104 cat "${te}2"
7105 numFAIL=$((numFAIL+1))
7106 listFAIL="$listFAIL $N"
7107 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7108 $PRINTF "$FAILED\n"
7109 cat "$tdiff"
7110 numFAIL=$((numFAIL+1))
7111 listFAIL="$listFAIL $N"
7112 else
7113 $PRINTF "$OK\n"
7114 if [ -n "$debug" ]; then cat "$te"; fi
7115 numOK=$((numOK+1))
7116 fi
7117 fi ;; # root, NUMCOND
7118 esac
7119 N=$((N+1))
7120 fi #false
7121  
7122  
7123 NAME=UNIXDGRAM
7124 case "$TESTS" in
7125 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%dgram%*|*%$NAME%*)
7126 TEST="$NAME: UNIX datagram"
7127 if ! eval $NUMCOND; then :; else
7128 tf="$td/test$N.stdout"
7129 te="$td/test$N.stderr"
7130 tdiff="$td/test$N.diff"
7131 ts1="$td/test$N.socket1"
7132 ts2="$td/test$N.socket2"
7133 da="test$N $(date) $RANDOM"
7134 CMD1="$TRACE $SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE"
7135 CMD2="$TRACE $SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2"
7136 printf "test $F_n $TEST... " $N
7137 $CMD1 2>"${te}1" &
7138 pid1="$!"
7139 waitfile $ts1 1
7140 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7141 rc2=$?
7142 kill "$pid1" 2>/dev/null; wait
7143 if [ $rc2 -ne 0 ]; then
7144 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7145 echo "$CMD1 &"
7146 cat "${te}1"
7147 echo "$CMD2"
7148 cat "${te}2"
7149 numFAIL=$((numFAIL+1))
7150 listFAIL="$listFAIL $N"
7151 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7152 $PRINTF "$FAILED\n"
7153 cat "$tdiff"
7154 numFAIL=$((numFAIL+1))
7155 listFAIL="$listFAIL $N"
7156 else
7157 $PRINTF "$OK\n"
7158 if [ -n "$debug" ]; then cat $te; fi
7159 numOK=$((numOK+1))
7160 fi
7161 fi # NUMCOND
7162 ;;
7163 esac
7164 N=$((N+1))
7165  
7166  
7167 NAME=UDP4RECV
7168 case "$TESTS" in
7169 *%$N%*|*%functions%*|*%engine%*|*%ip4%*|*%dgram%*|*%udp%*|*%udp4%*|*%recv%*|*%$NAME%*)
7170 TEST="$NAME: UDP/IPv4 receive"
7171 if ! eval $NUMCOND; then :; else
7172 tf="$td/test$N.stdout"
7173 te="$td/test$N.stderr"
7174 tdiff="$td/test$N.diff"
7175 ts1p=$PORT; PORT=$((PORT+1))
7176 ts1a="127.0.0.1"
7177 ts1="$ts1a:$ts1p"
7178 da="test$N $(date) $RANDOM"
7179 CMD1="$TRACE $SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -"
7180 CMD2="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1"
7181 printf "test $F_n $TEST... " $N
7182 $CMD1 >"$tf" 2>"${te}1" &
7183 pid1="$!"
7184 waitudp4port $ts1p 1
7185 echo "$da" |$CMD2 2>>"${te}2"
7186 rc2="$?"
7187 #ls -l $tf
7188 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7189 kill "$pid1" 2>/dev/null; wait
7190 if [ "$rc2" -ne 0 ]; then
7191 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7192 echo "$CMD1 &"
7193 echo "$CMD2"
7194 cat "${te}1"
7195 cat "${te}2"
7196 numFAIL=$((numFAIL+1))
7197 listFAIL="$listFAIL $N"
7198 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7199 $PRINTF "$FAILED\n"
7200 cat "$tdiff"
7201 echo "$CMD1 &"
7202 echo "$CMD2"
7203 cat "${te}1"
7204 cat "${te}2"
7205 numFAIL=$((numFAIL+1))
7206 listFAIL="$listFAIL $N"
7207 else
7208 $PRINTF "$OK\n"
7209 if [ -n "$debug" ]; then cat $te; fi
7210 numOK=$((numOK+1))
7211 fi
7212 fi # NUMCOND
7213 ;;
7214 esac
7215 N=$((N+1))
7216  
7217  
7218 NAME=UDP6RECV
7219 case "$TESTS" in
7220 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%udp%*|*%udp6%*|*%recv%*|*%$NAME%*)
7221 TEST="$NAME: UDP/IPv6 receive"
7222 if ! eval $NUMCOND; then :;
7223 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
7224 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7225 numCANT=$((numCANT+1))
7226 else
7227 tf="$td/test$N.stdout"
7228 te="$td/test$N.stderr"
7229 tdiff="$td/test$N.diff"
7230 ts1p=$PORT; PORT=$((PORT+1))
7231 ts1a="[::1]"
7232 ts1="$ts1a:$ts1p"
7233 da="test$N $(date) $RANDOM"
7234 CMD1="$TRACE $SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -"
7235 CMD2="$TRACE $SOCAT $opts -u - UDP6-SENDTO:$ts1"
7236 printf "test $F_n $TEST... " $N
7237 $CMD1 >"$tf" 2>"${te}1" &
7238 pid1="$!"
7239 waitudp6port $ts1p 1
7240 echo "$da" |$CMD2 2>>"${te}2"
7241 rc2="$?"
7242 #ls -l $tf
7243 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7244 kill "$pid1" 2>/dev/null; wait
7245 if [ "$rc2" -ne 0 ]; then
7246 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7247 echo "$CMD1 &"
7248 echo "$CMD2"
7249 cat "${te}1"
7250 cat "${te}2"
7251 numFAIL=$((numFAIL+1))
7252 listFAIL="$listFAIL $N"
7253 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7254 $PRINTF "$FAILED\n"
7255 cat "$tdiff"
7256 numFAIL=$((numFAIL+1))
7257 listFAIL="$listFAIL $N"
7258 else
7259 $PRINTF "$OK\n"
7260 if [ -n "$debug" ]; then cat $te; fi
7261 numOK=$((numOK+1))
7262 fi
7263 fi ;; # NUMCOND, feats
7264 esac
7265 N=$((N+1))
7266  
7267  
7268 NAME=RAWIP4RECV
7269 case "$TESTS" in
7270 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
7271 TEST="$NAME: raw IPv4 receive"
7272 if ! eval $NUMCOND; then :;
7273 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7274 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7275 numCANT=$((numCANT+1))
7276 else
7277 tf="$td/test$N.stdout"
7278 te="$td/test$N.stderr"
7279 tdiff="$td/test$N.diff"
7280 ts1p=$PROTO; PROTO=$((PROTO+1))
7281 ts1a="127.0.0.1"
7282 ts1="$ts1a:$ts1p"
7283 da="test$N $(date) $RANDOM"
7284 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -"
7285 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
7286 printf "test $F_n $TEST... " $N
7287 $CMD1 >"$tf" 2>"${te}1" &
7288 pid1="$!"
7289 waitip4proto $ts1p 1
7290 echo "$da" |$CMD2 2>>"${te}2"
7291 rc2="$?"
7292 #ls -l $tf
7293 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7294 kill "$pid1" 2>/dev/null; wait
7295 if [ "$rc2" -ne 0 ]; then
7296 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7297 echo "$CMD1 &"
7298 echo "$CMD2"
7299 cat "${te}1"
7300 cat "${te}2"
7301 numFAIL=$((numFAIL+1))
7302 listFAIL="$listFAIL $N"
7303 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7304 $PRINTF "$FAILED\n"
7305 cat "$tdiff"
7306 numFAIL=$((numFAIL+1))
7307 listFAIL="$listFAIL $N"
7308 else
7309 $PRINTF "$OK\n"
7310 if [ -n "$debug" ]; then cat $te; fi
7311 numOK=$((numOK+1))
7312 fi
7313 fi ;; # NUMCOND, root
7314 esac
7315 N=$((N+1))
7316  
7317  
7318 NAME=RAWIP6RECV
7319 case "$TESTS" in
7320 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%rawip%*|*%rawip6%*|*%recv%*|*%root%*|*%$NAME%*)
7321 TEST="$NAME: raw IPv6 receive"
7322 if ! eval $NUMCOND; then :;
7323 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7324 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7325 numCANT=$((numCANT+1))
7326 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7327 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7328 numCANT=$((numCANT+1))
7329 else
7330 tf="$td/test$N.stdout"
7331 te="$td/test$N.stderr"
7332 tdiff="$td/test$N.diff"
7333 ts1p=$PROTO; PROTO=$((PROTO+1))
7334 ts1a="[::1]"
7335 ts1="$ts1a:$ts1p"
7336 da="test$N $(date) $RANDOM"
7337 CMD1="$TRACE $SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -"
7338 CMD2="$TRACE $SOCAT $opts -u - IP6-SENDTO:$ts1"
7339 printf "test $F_n $TEST... " $N
7340 $CMD1 >"$tf" 2>"${te}1" &
7341 pid1="$!"
7342 waitip6proto $ts1p 1
7343 echo "$da" |$CMD2 2>>"${te}2"
7344 rc2="$?"
7345 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7346 kill "$pid1" 2>/dev/null; wait
7347 if [ "$rc2" -ne 0 ]; then
7348 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7349 echo "$CMD1 &"
7350 echo "$CMD2"
7351 cat "${te}1"
7352 cat "${te}2"
7353 numFAIL=$((numFAIL+1))
7354 listFAIL="$listFAIL $N"
7355 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7356 $PRINTF "$FAILED\n"
7357 cat "$tdiff"
7358 numFAIL=$((numFAIL+1))
7359 listFAIL="$listFAIL $N"
7360 else
7361 $PRINTF "$OK\n"
7362 if [ -n "$debug" ]; then cat $te; fi
7363 numOK=$((numOK+1))
7364 fi
7365 fi ;; # NUMCOND, root
7366 esac
7367 N=$((N+1))
7368  
7369  
7370 NAME=UNIXRECV
7371 case "$TESTS" in
7372 *%$N%*|*%functions%*|*%unix%*|*%dgram%*|*%recv%*|*%$NAME%*)
7373 TEST="$NAME: UNIX receive"
7374 if ! eval $NUMCOND; then :; else
7375 ts="$td/test$N.socket"
7376 tf="$td/test$N.stdout"
7377 te="$td/test$N.stderr"
7378 tdiff="$td/test$N.diff"
7379 ts1="$ts"
7380 da="test$N $(date) $RANDOM"
7381 CMD1="$TRACE $SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -"
7382 CMD2="$TRACE $SOCAT $opts -u - UNIX-SENDTO:$ts1"
7383 printf "test $F_n $TEST... " $N
7384 $CMD1 >"$tf" 2>"${te}1" &
7385 pid1="$!"
7386 waitfile $ts1 1
7387 echo "$da" |$CMD2 2>>"${te}2"
7388 rc2="$?"
7389 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7390 kill "$pid1" 2>/dev/null; wait
7391 if [ "$rc2" -ne 0 ]; then
7392 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7393 echo "$CMD1 &"
7394 echo "$CMD2"
7395 cat "${te}1"
7396 cat "${te}2"
7397 numFAIL=$((numFAIL+1))
7398 listFAIL="$listFAIL $N"
7399 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7400 $PRINTF "$FAILED\n"
7401 cat "$tdiff"
7402 numFAIL=$((numFAIL+1))
7403 listFAIL="$listFAIL $N"
7404 else
7405 $PRINTF "$OK\n"
7406 if [ -n "$debug" ]; then cat $te; fi
7407 numOK=$((numOK+1))
7408 fi
7409 fi # NUMCOND
7410 ;;
7411 esac
7412 N=$((N+1))
7413  
7414  
7415 NAME=UDP4RECVFROM_SOURCEPORT
7416 case "$TESTS" in
7417 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7418 TEST="$NAME: security of UDP4-RECVFROM with SOURCEPORT option"
7419 if ! eval $NUMCOND; then :;
7420 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7421 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7422 numCANT=$((numCANT+1))
7423 else
7424 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7425 fi ;; # NUMCOND, feats
7426 esac
7427 PORT=$((PORT+1))
7428 N=$((N+1))
7429  
7430 NAME=UDP4RECVFROM_LOWPORT
7431 case "$TESTS" in
7432 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7433 TEST="$NAME: security of UDP4-RECVFROM with LOWPORT option"
7434 if ! eval $NUMCOND; then :;
7435 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7436 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7437 numCANT=$((numCANT+1))
7438 else
7439 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7440 fi ;; # NUMCOND, feats
7441 esac
7442 PORT=$((PORT+1))
7443 N=$((N+1))
7444  
7445 NAME=UDP4RECVFROM_RANGE
7446 case "$TESTS" in
7447 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7448 TEST="$NAME: security of UDP4-RECVFROM with RANGE option"
7449 #testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7450 if ! eval $NUMCOND; then :; else
7451 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7452 fi ;; # NUMCOND
7453 esac
7454 PORT=$((PORT+1))
7455 N=$((N+1))
7456  
7457 NAME=UDP4RECVFROM_TCPWRAP
7458 case "$TESTS" in
7459 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7460 TEST="$NAME: security of UDP4-RECVFROM with TCPWRAP option"
7461 if ! eval $NUMCOND; then :;
7462 elif ! feat=$(testaddrs ip4 udp libwrap) || ! runsip4 >/dev/null; then
7463 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7464 numCANT=$((numCANT+1))
7465 else
7466 ha="$td/hosts.allow"
7467 hd="$td/hosts.deny"
7468 $ECHO "socat: $SECONDADDR" >"$ha"
7469 $ECHO "ALL: ALL" >"$hd"
7470 #testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "tcpwrap=$d" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7471 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7472 fi ;; # NUMCOND, feats
7473 esac
7474 PORT=$((PORT+1))
7475 N=$((N+1))
7476  
7477  
7478 NAME=UDP4RECV_SOURCEPORT
7479 case "$TESTS" in
7480 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7481 TEST="$NAME: security of UDP4-RECV with SOURCEPORT option"
7482 if ! eval $NUMCOND; then :;
7483 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7484 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7485 numCANT=$((numCANT+1))
7486 else
7487 PORT1=$PORT; PORT=$((PORT+1))
7488 PORT2=$PORT; PORT=$((PORT+1))
7489 PORT3=$PORT
7490 # we use the forward channel (PORT1) for testing, and have a backward channel
7491 # (PORT2) to get the data back, so we get the classical echo behaviour
7492 testserversec "$N" "$TEST" "$opts -s" "udp4-sendto:127.0.0.1:$PORT2%udp4-recv:$PORT1,reuseaddr" "" "sp=$PORT3" "udp4-sendto:127.0.0.1:$PORT1%udp4-recv:$PORT2" 4 udp $PORT1 0
7493 fi ;; # NUMCOND, feats
7494 esac
7495 PORT=$((PORT+1))
7496 N=$((N+1))
7497  
7498 NAME=UDP4RECV_LOWPORT
7499 case "$TESTS" in
7500 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7501 TEST="$NAME: security of UDP4-RECV with LOWPORT option"
7502 if ! eval $NUMCOND; then :;
7503 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7504 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7505 numCANT=$((numCANT+1))
7506 else
7507 PORT1=$PORT; PORT=$((PORT+1))
7508 PORT2=$PORT
7509 # we use the forward channel (PORT1) for testing, and have a backward channel
7510 # (PORT2) to get the data back, so we get the classical echo behaviour
7511 testserversec "$N" "$TEST" "$opts -s" "udp4-sendto:127.0.0.1:$PORT2%udp4-recv:$PORT1,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT1%udp4-recv:$PORT2" 4 udp $PORT1 0
7512 fi ;; # NUMCOND, feats
7513 esac
7514 PORT=$((PORT+1))
7515 N=$((N+1))
7516  
7517 NAME=UDP4RECV_RANGE
7518 case "$TESTS" in
7519 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7520 TEST="$NAME: security of UDP4-RECV with RANGE option"
7521 if ! eval $NUMCOND; then :;
7522 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7523 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7524 numCANT=$((numCANT+1))
7525 else
7526 PORT1=$PORT; PORT=$((PORT+1))
7527 PORT2=$PORT
7528 # we use the forward channel (PORT1) for testing, and have a backward channel
7529 # (PORT2) to get the data back, so we get the classical echo behaviour
7530 testserversec "$N" "$TEST" "$opts -s" "udp4-sendto:127.0.0.1:$PORT2%udp4-recv:$PORT1,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT1%udp4-recv:$PORT2" 4 udp $PORT1 0
7531 fi ;; # NUMCOND, feats
7532 esac
7533 PORT=$((PORT+1))
7534 N=$((N+1))
7535  
7536 NAME=UDP4RECV_TCPWRAP
7537 case "$TESTS" in
7538 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7539 TEST="$NAME: security of UDP4-RECV with TCPWRAP option"
7540 if ! eval $NUMCOND; then :;
7541 elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
7542 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7543 numCANT=$((numCANT+1))
7544 else
7545 PORT1=$PORT; PORT=$((PORT+1))
7546 PORT2=$PORT
7547 ha="$td/hosts.allow"
7548 hd="$td/hosts.deny"
7549 $ECHO "socat: $SECONDADDR" >"$ha"
7550 $ECHO "ALL: ALL" >"$hd"
7551 # we use the forward channel (PORT1) for testing, and have a backward channel
7552 # (PORT2) to get the data back, so we get the classical echo behaviour
7553 testserversec "$N" "$TEST" "$opts -s" "udp4-sendto:127.0.0.1:$PORT2%udp4-recv:$PORT1,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT1%udp4-recv:$PORT2" 4 udp $PORT1 0
7554 fi ;; # NUMCOND, feats
7555 esac
7556 PORT=$((PORT+1))
7557 N=$((N+1))
7558  
7559  
7560 NAME=UDP6RECVFROM_SOURCEPORT
7561 case "$TESTS" in
7562 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7563 TEST="$NAME: security of UDP6-RECVFROM with SOURCEPORT option"
7564 if ! eval $NUMCOND; then :;
7565 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7566 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7567 numCANT=$((numCANT+1))
7568 else
7569 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7570 fi ;; # NUMCOND, feats
7571 esac
7572 PORT=$((PORT+1))
7573 N=$((N+1))
7574  
7575 NAME=UDP6RECVFROM_LOWPORT
7576 case "$TESTS" in
7577 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7578 TEST="$NAME: security of UDP6-RECVFROM with LOWPORT option"
7579 if ! eval $NUMCOND; then :;
7580 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7581 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7582 numCANT=$((numCANT+1))
7583 else
7584 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7585 fi ;; # NUMCOND, feats
7586 esac
7587 PORT=$((PORT+1))
7588 N=$((N+1))
7589  
7590 NAME=UDP6RECVFROM_RANGE
7591 case "$TESTS" in
7592 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7593 TEST="$NAME: security of UDP6-RECVFROM with RANGE option"
7594 if ! eval $NUMCOND; then :;
7595 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
7596 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7597 numCANT=$((numCANT+1))
7598 else
7599 #testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr,fork" "" "range=[::2/128]" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7600 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "range=[::2/128]" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7601 fi ;; # NUMCOND, feats
7602 esac
7603 PORT=$((PORT+1))
7604 N=$((N+1))
7605  
7606 NAME=UDP6RECVFROM_TCPWRAP
7607 case "$TESTS" in
7608 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7609 TEST="$NAME: security of UDP6-RECVFROM with TCPWRAP option"
7610 if ! eval $NUMCOND; then :;
7611 elif ! feat=$(testaddrs udp ip6 libwrap) || ! runsip6 >/dev/null; then
7612 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7613 numCANT=$((numCANT+1))
7614 else
7615 ha="$td/hosts.allow"
7616 hd="$td/hosts.deny"
7617 $ECHO "socat: [::2]" >"$ha"
7618 $ECHO "ALL: ALL" >"$hd"
7619 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7620 fi ;; # NUMCOND, feats
7621 esac
7622 PORT=$((PORT+1))
7623 N=$((N+1))
7624  
7625  
7626 NAME=UDP6RECV_SOURCEPORT
7627 case "$TESTS" in
7628 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7629 TEST="$NAME: security of UDP6-RECV with SOURCEPORT option"
7630 if ! eval $NUMCOND; then :;
7631 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7632 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7633 numCANT=$((numCANT+1))
7634 else
7635 PORT1=$PORT; PORT=$((PORT+1))
7636 PORT2=$PORT; PORT=$((PORT+1))
7637 PORT3=$PORT
7638 # we use the forward channel (PORT1) for testing, and have a backward channel
7639 # (PORT2) to get the data back, so we get the classical echo behaviour
7640 testserversec "$N" "$TEST" "$opts -s" "udp6-sendto:[::1]:$PORT2%udp6-recv:$PORT1,reuseaddr" "" "sp=$PORT3" "udp6-sendto:[::1]:$PORT1%udp6-recv:$PORT2" 6 udp $PORT1 0
7641 fi ;; # NUMCOND, feats
7642 esac
7643 PORT=$((PORT+1))
7644 N=$((N+1))
7645  
7646 NAME=UDP6RECV_LOWPORT
7647 case "$TESTS" in
7648 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7649 TEST="$NAME: security of UDP6-RECV with LOWPORT option"
7650 if ! eval $NUMCOND; then :;
7651 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7652 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7653 numCANT=$((numCANT+1))
7654 else
7655 PORT1=$PORT; PORT=$((PORT+1))
7656 PORT2=$PORT
7657 # we use the forward channel (PORT1) for testing, and have a backward channel
7658 # (PORT2) to get the data back, so we get the classical echo behaviour
7659 testserversec "$N" "$TEST" "$opts -s" "udp6-sendto:[::1]:$PORT2%udp6-recv:$PORT1,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT1%udp6-recv:$PORT2" 6 udp $PORT1 0
7660 fi ;; # NUMCOND, feats
7661 esac
7662 PORT=$((PORT+1))
7663 N=$((N+1))
7664  
7665 NAME=UDP6RECV_RANGE
7666 case "$TESTS" in
7667 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7668 TEST="$NAME: security of UDP6-RECV with RANGE option"
7669 if ! eval $NUMCOND; then :;
7670 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7671 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7672 numCANT=$((numCANT+1))
7673 else
7674 PORT1=$PORT; PORT=$((PORT+1))
7675 PORT2=$PORT
7676 # we use the forward channel (PORT1) for testing, and have a backward channel
7677 # (PORT2) to get the data back, so we get the classical echo behaviour
7678 testserversec "$N" "$TEST" "$opts -s" "udp6-sendto:[::1]:$PORT2%udp6-recv:$PORT1,reuseaddr" "" "range=[::2/128]" "udp6-sendto:[::1]:$PORT1%udp6-recv:$PORT2" 6 udp $PORT1 0
7679 fi ;; # NUMCOND, feats
7680 esac
7681 PORT=$((PORT+1))
7682 N=$((N+1))
7683  
7684 NAME=UDP6RECV_TCPWRAP
7685 case "$TESTS" in
7686 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7687 TEST="$NAME: security of UDP6-RECV with TCPWRAP option"
7688 if ! eval $NUMCOND; then :;
7689 elif ! feat=$(testaddrs udp ip6 libwrap) || ! runsip6 >/dev/null; then
7690 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7691 numCANT=$((numCANT+1))
7692 else
7693 ha="$td/hosts.allow"
7694 hd="$td/hosts.deny"
7695 $ECHO "socat: [::2]" >"$ha"
7696 $ECHO "ALL: ALL" >"$hd"
7697 PORT1=$PORT; PORT=$((PORT+1))
7698 PORT2=$PORT
7699 # we use the forward channel (PORT1) for testing, and have a backward channel
7700 # (PORT2) to get the data back, so we get the classical echo behaviour
7701 testserversec "$N" "$TEST" "$opts -s" "udp6-sendto:[::1]:$PORT2%udp6-recv:$PORT1,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT1%udp6-recv:$PORT2" 6 udp $PORT1 0
7702 fi ;; # NUMCOND, feats
7703 esac
7704 PORT=$((PORT+1))
7705 N=$((N+1))
7706  
7707  
7708 NAME=IP4RECVFROM_RANGE
7709 case "$TESTS" in
7710 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
7711 TEST="$NAME: security of IP4-RECVFROM with RANGE option"
7712 if ! eval $NUMCOND; then :;
7713 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
7714 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7715 numCANT=$((numCANT+1))
7716 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7717 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7718 numCANT=$((numCANT+1))
7719 else
7720 #testserversec "$N" "$TEST" "$opts -s" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7721 testserversec "$N" "$TEST" "$opts -s" "udp4-sendto:127.0.0.1:$PORT%ip4-recvfrom:$PROTO,reuseaddr" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO%udp4-recv:$PORT" 4 ip $PROTO 0
7722 fi ;; # NUMCOND, feats, root
7723 esac
7724 PROTO=$((PROTO+1))
7725 PORT=$((PORT+1))
7726 N=$((N+1))
7727  
7728 NAME=IP4RECVFROM_TCPWRAP
7729 case "$TESTS" in
7730 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7731 TEST="$NAME: security of IP4-RECVFROM with TCPWRAP option"
7732 if ! eval $NUMCOND; then :;
7733 elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
7734 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7735 numCANT=$((numCANT+1))
7736 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7737 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7738 numCANT=$((numCANT+1))
7739 else
7740 ha="$td/hosts.allow"
7741 hd="$td/hosts.deny"
7742 $ECHO "socat: $SECONDADDR" >"$ha"
7743 $ECHO "ALL: ALL" >"$hd"
7744 #testserversec "$N" "$TEST" "$opts -s" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7745 testserversec "$N" "$TEST" "$opts -s" "udp4-sendto:127.0.0.1:$PORT%ip4-recvfrom:$PROTO,reuseaddr" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO%udp4-recv:$PORT" 4 ip $PROTO 0
7746 fi # NUMCOND, feats, root
7747 ;;
7748 esac
7749 PROTO=$((PROTO+1))
7750 PORT=$((PORT+1))
7751 N=$((N+1))
7752  
7753  
7754 NAME=IP4RECV_RANGE
7755 case "$TESTS" in
7756 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
7757 TEST="$NAME: security of IP4-RECV with RANGE option"
7758 if ! eval $NUMCOND; then :;
7759 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
7760 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
7761 numCANT=$((numCANT+1))
7762 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7763 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7764 numCANT=$((numCANT+1))
7765 else
7766 PROTO1=$PROTO; PROTO=$((PROTO+1))
7767 PROTO2=$PROTO
7768 # we use the forward channel (PROTO1) for testing, and have a backward channel
7769 # (PROTO2) to get the data back, so we get the classical echo behaviour
7770 testserversec "$N" "$TEST" "$opts -s" "ip4-sendto:127.0.0.1:$PROTO2%ip4-recv:$PROTO1,reuseaddr" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO1%ip4-recv:$PROTO2" 4 ip $PROTO1 0
7771 fi ;; # NUMCOND, feats, root
7772 esac
7773 PROTO=$((PROTO+1))
7774 N=$((N+1))
7775  
7776  
7777 NAME=IP4RECV_TCPWRAP
7778 case "$TESTS" in
7779 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7780 TEST="$NAME: security of IP4-RECV with TCPWRAP option"
7781 if ! eval $NUMCOND; then :;
7782 elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
7783 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7784 numCANT=$((numCANT+1))
7785 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7786 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7787 numCANT=$((numCANT+1))
7788 else
7789 PROTO1=$PROTO; PROTO=$((PROTO+1))
7790 PROTO2=$PROTO
7791 ha="$td/hosts.allow"
7792 hd="$td/hosts.deny"
7793 $ECHO "socat: $SECONDADDR" >"$ha"
7794 $ECHO "ALL: ALL" >"$hd"
7795 # we use the forward channel (PROTO1) for testing, and have a backward channel
7796 # (PROTO2) to get the data back, so we get the classical echo behaviour
7797 testserversec "$N" "$TEST" "$opts -s" "ip4-sendto:127.0.0.1:$PROTO2%ip4-recv:$PROTO1,reuseaddr" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO1%ip4-recv:$PROTO2" 4 ip $PROTO1 0
7798 fi ;; # NUMCOND, feats, root
7799 esac
7800 PROTO=$((PROTO+1))
7801 N=$((N+1))
7802  
7803  
7804 NAME=IP6RECVFROM_RANGE
7805 case "$TESTS" in
7806 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
7807 TEST="$NAME: security of IP6-RECVFROM with RANGE option"
7808 if ! eval $NUMCOND; then :;
7809 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7810 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7811 numCANT=$((numCANT+1))
7812 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7813 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7814 numCANT=$((numCANT+1))
7815 else
7816 #testserversec "$N" "$TEST" "$opts -s" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "range=[::2/128]" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7817 testserversec "$N" "$TEST" "$opts -s" "udp6-sendto:[::1]:$PORT%ip6-recvfrom:$PROTO,reuseaddr" "" "range=[::2/128]" "ip6-sendto:[::1]:$PROTO%udp6-recv:$PORT" 6 ip $PROTO 0
7818 fi ;; # NUMCOND, feats
7819 esac
7820 PROTO=$((PROTO+1))
7821 PORT=$((PORT+1))
7822 N=$((N+1))
7823  
7824 NAME=IP6RECVFROM_TCPWRAP
7825 case "$TESTS" in
7826 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7827 TEST="$NAME: security of IP6-RECVFROM with TCPWRAP option"
7828 if ! eval $NUMCOND; then :;
7829 elif ! feat=$(testaddrs ip6 rawip libwrap) || ! runsip6 >/dev/null; then
7830 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7831 numCANT=$((numCANT+1))
7832 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7833 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7834 numCANT=$((numCANT+1))
7835 else
7836 ha="$td/hosts.allow"
7837 hd="$td/hosts.deny"
7838 $ECHO "socat: [::2]" >"$ha"
7839 $ECHO "ALL: ALL" >"$hd"
7840 #testserversec "$N" "$TEST" "$opts -s" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7841 testserversec "$N" "$TEST" "$opts -s" "udp6-sendto:[::1]:$PORT%ip6-recvfrom:$PROTO,reuseaddr" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO%udp6-recv:$PORT" 6 ip $PROTO 0
7842 fi ;; # NUMCOND, feats
7843 esac
7844 PROTO=$((PROTO+1))
7845 PORT=$((PORT+1))
7846 N=$((N+1))
7847  
7848  
7849 NAME=IP6RECV_RANGE
7850 case "$TESTS" in
7851 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
7852 TEST="$NAME: security of IP6-RECV with RANGE option"
7853 if ! eval $NUMCOND; then :;
7854 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7855 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP6 not available${NORMAL}\n" $N
7856 numCANT=$((numCANT+1))
7857 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7858 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7859 numCANT=$((numCANT+1))
7860 else
7861 PROTO1=$PROTO; PROTO=$((PROTO+1))
7862 PROTO2=$PROTO
7863 # we use the forward channel (PROTO1) for testing, and have a backward channel
7864 # (PROTO2) to get the data back, so we get the classical echo behaviour
7865 testserversec "$N" "$TEST" "$opts -s" "ip6-sendto:[::1]:$PROTO2%ip6-recv:$PROTO1,reuseaddr" "" "range=[::2/128]" "ip6-sendto:[::1]:$PROTO1%ip6-recv:$PROTO2" 6 ip $PROTO1 0
7866 fi ;; # NUMCOND, feats
7867 esac
7868 PROTO=$((PROTO+1))
7869 N=$((N+1))
7870  
7871 NAME=IP6RECV_TCPWRAP
7872 case "$TESTS" in
7873 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7874 TEST="$NAME: security of IP6-RECV with TCPWRAP option"
7875 if ! eval $NUMCOND; then :;
7876 elif ! feat=$(testaddrs ip6 rawip libwrap) || ! runsip6 >/dev/null; then
7877 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7878 numCANT=$((numCANT+1))
7879 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7880 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7881 numCANT=$((numCANT+1))
7882 else
7883 PROTO1=$PROTO; PROTO=$((PROTO+1))
7884 PROTO2=$PROTO
7885 ha="$td/hosts.allow"
7886 hd="$td/hosts.deny"
7887 $ECHO "socat: [::2]" >"$ha"
7888 $ECHO "ALL: ALL" >"$hd"
7889 # we use the forward channel (PROTO1) for testing, and have a backward channel
7890 # (PROTO2) to get the data back, so we get the classical echo behaviour
7891 testserversec "$N" "$TEST" "$opts -s" "ip6-sendto:[::1]:$PROTO2%ip6-recv:$PROTO1,reuseaddr" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO1%ip6-recv:$PROTO2" 6 ip $PROTO1 0
7892 fi ;; # NUMCOND, feats
7893 esac
7894 PROTO=$((PROTO+1))
7895 N=$((N+1))
7896  
7897  
7898 NAME=O_NOATIME_FILE
7899 case "$TESTS" in
7900 *%$N%*|*%functions%*|*%open%*|*%noatime%*|*%$NAME%*)
7901 TEST="$NAME: option O_NOATIME on file"
7902 # idea: create a file with o-noatime option; one second later create a file
7903 # without this option (using touch); one second later read from the first file.
7904 # Then we check which file has the later ATIME stamp. For this check we use
7905 # "ls -ltu" because it is more portable than "test ... -nt ..."
7906 if ! eval $NUMCOND; then :;
7907 elif ! testoptions o-noatime >/dev/null; then
7908 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7909 numCANT=$((numCANT+1))
7910 else
7911 tf="$td/test$N.file"
7912 te="$td/test$N.stderr"
7913 tdiff="$td/test$N.diff"
7914 da="test$N $(date) $RANDOM"
7915 $PRINTF "test $F_n $TEST... " $N
7916 CMD="$TRACE $SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null"
7917 # generate a file
7918 touch "${tf}1"
7919 sleep 1
7920 # generate a reference file
7921 touch "${tf}2"
7922 sleep 1
7923 # read from the first file
7924 $CMD 2>"$te"
7925 if [ $? -ne 0 ]; then # command failed
7926 $PRINTF "${FAILED}:\n"
7927 echo "$CMD"
7928 cat "$te"
7929 numFAIL=$((numFAIL+1))
7930 listFAIL="$listFAIL $N"
7931 else
7932 # check which file has a later atime stamp
7933 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7934 then
7935 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7936 echo "$CMD"
7937 cat "$te"
7938 numFAIL=$((numFAIL+1))
7939 listFAIL="$listFAIL $N"
7940 else
7941 $PRINTF "$OK\n"
7942 if [ -n "$debug" ]; then cat "$te"; fi
7943 numOK=$((numOK+1))
7944 fi # wrong time stamps
7945 fi # command ok
7946 fi ;; # NUMCOND, feats
7947 esac
7948 N=$((N+1))
7949  
7950 NAME=O_NOATIME_FD
7951 case "$TESTS" in
7952 *%$N%*|*%functions%*|*%noatime%*|*%$NAME%*)
7953 TEST="$NAME: option O_NOATIME on file descriptor"
7954 # idea: use a fd of a file with o-noatime option; one second later create a file
7955 # without this option (using touch); one second later read from the first file.
7956 # Then we check which file has the later ATIME stamp. For this check we use
7957 # "ls -ltu" because it is more portable than "test ... -nt ..."
7958 if ! eval $NUMCOND; then :;
7959 elif ! testoptions o-noatime >/dev/null; then
7960 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7961 numCANT=$((numCANT+1))
7962 else
7963 tf="$td/test$N.file"
7964 te="$td/test$N.stderr"
7965 tdiff="$td/test$N.diff"
7966 da="test$N $(date) $RANDOM"
7967 $PRINTF "test $F_n $TEST... " $N
7968 touch ${tf}1
7969 CMD="$TRACE $SOCAT $opts -u -,o-noatime /dev/null <${tf}1"
7970 # generate a file, len >= 1
7971 touch "${tf}1"
7972 sleep 1
7973 # generate a reference file
7974 touch "${tf}2"
7975 sleep 1
7976 # read from the first file
7977 sh -c "$CMD" 2>"$te"
7978 if [ $? -ne 0 ]; then # command failed
7979 $PRINTF "${FAILED}:\n"
7980 echo "$CMD"
7981 cat "$te"
7982 numFAIL=$((numFAIL+1))
7983 listFAIL="$listFAIL $N"
7984 else
7985 # check which file has a later atime stamp
7986 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7987 then
7988 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7989 echo "$CMD"
7990 cat "$te"
7991 numFAIL=$((numFAIL+1))
7992 listFAIL="$listFAIL $N"
7993 else
7994 $PRINTF "$OK\n"
7995 if [ -n "$debug" ]; then cat "$te"; fi
7996 numOK=$((numOK+1))
7997 fi # wrong time stamps
7998 fi # command ok
7999 fi ;; # NUMCOND, feats
8000 esac
8001 N=$((N+1))
8002  
8003 NAME=EXT2_NOATIME
8004 case "$TESTS" in
8005 *%$N%*|*%functions%*|*%ext2%*|*%noatime%*|*%$NAME%*)
8006 TEST="$NAME: extended file system options using ext2fs noatime option"
8007 # idea: create a file with ext2-noatime option; one second later create a file
8008 # without this option (using touch); one second later read from the first file.
8009 # Then we check which file has the later ATIME stamp. For this check we use
8010 # "ls -ltu" because it is more portable than "test ... -nt ..."
8011 if ! eval $NUMCOND; then :;
8012 elif ! testoptions ext2-noatime >/dev/null; then
8013 $PRINTF "test $F_n $TEST... ${YELLOW}ext2-noatime not available${NORMAL}\n" $N
8014 numCANT=$((numCANT+1))
8015 else
8016 ts="$td/test$N.socket"
8017 tf="$td/test$N.file"
8018 te="$td/test$N.stderr"
8019 tdiff="$td/test$N.diff"
8020 ts1="$ts"
8021 da="test$N $(date) $RANDOM"
8022 $PRINTF "test $F_n $TEST... " $N
8023 CMD0="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\""
8024 CMD="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\",ext2-noatime"
8025 # check if this is a capable FS; lsattr does other things on AIX, thus socat
8026 $CMD0 2>"${te}0"
8027 if [ $? -ne 0 ]; then
8028 $PRINTF "${YELLOW} cannot test${NORMAL}\n"
8029 numCANT=$((numCANT+1))
8030 else
8031 # generate a file with noatime, len >= 1
8032 $CMD 2>"$te"
8033 if [ $? -ne 0 ]; then # command failed
8034 $PRINTF "${YELLOW}impotent file system?${NORMAL}\n"
8035 echo "$CMD"
8036 cat "$te"
8037 numCANT=$((numCANT+1))
8038 else
8039 sleep 1
8040 # generate a reference file
8041 touch "${tf}2"
8042 sleep 1
8043 # read from the first file
8044 cat "${tf}1" >/dev/null
8045 # check which file has a later atime stamp
8046 #if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |awk '{print($8);}') != "${tf}2" ];
8047 if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |sed "s|.*\\($td.*\\)|\1|g") != "${tf}2" ];
8048 then
8049 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8050 echo "$CMD"
8051 cat "$te"
8052 numFAIL=$((numFAIL+1))
8053 listFAIL="$listFAIL $N"
8054 else
8055 $PRINTF "$OK\n"
8056 if [ -n "$debug" ]; then cat "$te"; fi
8057 numOK=$((numOK+1))
8058 fi
8059 fi # not impotent
8060 fi # can test
8061 fi ;; # NUMCOND, feats
8062 esac
8063 N=$((N+1))
8064  
8065  
8066 NAME=COOLWRITE
8067 case "$TESTS" in
8068 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
8069 TEST="$NAME: option cool-write"
8070 if ! eval $NUMCOND; then :;
8071 elif ! testoptions cool-write >/dev/null; then
8072 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8073 numCANT=$((numCANT+1))
8074 else
8075 #set -vx
8076 ti="$td/test$N.pipe"
8077 tf="$td/test$N.stdout"
8078 te="$td/test$N.stderr"
8079 tdiff="$td/test$N.diff"
8080 da="test$N $(date) $RANDOM"
8081 # a reader that will terminate after 1 byte
8082 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8083 CMD="$TRACE $SOCAT $opts -u - file:\"$ti\",cool-write"
8084 printf "test $F_n $TEST... " $N
8085 $CMD1 2>"${te}1" &
8086 bg=$! # background process id
8087 sleep 1
8088 (echo .; sleep 1; echo) |$CMD 2>"$te"
8089 rc=$?
8090 kill $bg 2>/dev/null; wait
8091 if [ $rc -ne 0 ]; then
8092 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8093 echo "$CMD &"
8094 cat "$te"
8095 numFAIL=$((numFAIL+1))
8096 listFAIL="$listFAIL $N"
8097 else
8098 $PRINTF "$OK\n"
8099 if [ -n "$debug" ]; then cat "$te"; fi
8100 numOK=$((numOK+1))
8101 fi
8102 fi ;; # NUMCOND, feats
8103 esac
8104 N=$((N+1))
8105  
8106  
8107 # test if option coolwrite can be applied to bidirectional address stdio
8108 # this failed up to socat 1.6.0.0
8109 NAME=COOLSTDIO
8110 case "$TESTS" in
8111 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
8112 TEST="$NAME: option cool-write on bidirectional stdio"
8113 # this test starts a socat reader that terminates after receiving one+
8114 # bytes (option readbytes); and a test process that sends two bytes via
8115 # named pipe to the receiving process and, a second later, sends another
8116 # byte. The last write will fail with "broken pipe"; if option coolwrite
8117 # has been applied successfully, socat will terminate with 0 (OK),
8118 # otherwise with error.
8119 if ! eval $NUMCOND; then :;
8120 elif ! testoptions cool-write >/dev/null; then
8121 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8122 numCANT=$((numCANT+1))
8123 else
8124 #set -vx
8125 ti="$td/test$N.pipe"
8126 tf="$td/test$N.stdout"
8127 te="$td/test$N.stderr"
8128 tdiff="$td/test$N.diff"
8129 da="test$N $(date) $RANDOM"
8130 # a reader that will terminate after 1 byte
8131 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8132 CMD="$TRACE $SOCAT $opts -,cool-write pipe >\"$ti\""
8133 printf "test $F_n $TEST... " $N
8134 $CMD1 2>"${te}1" &
8135 bg=$! # background process id
8136 sleep 1
8137 (echo .; sleep 1; echo) |eval "$CMD" 2>"$te"
8138 rc=$?
8139 kill $bg 2>/dev/null; wait
8140 if [ $rc -ne 0 ]; then
8141 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8142 echo "$CMD &"
8143 cat "$te"
8144 numFAIL=$((numFAIL+1))
8145 listFAIL="$listFAIL $N"
8146 else
8147 $PRINTF "$OK\n"
8148 if [ -n "$debug" ]; then cat "$te"; fi
8149 numOK=$((numOK+1))
8150 fi
8151 fi ;; # NUMCOND, feats
8152 esac
8153 N=$((N+1))
8154  
8155  
8156 # purpose of the shut-none option is to keep a shared socket
8157 # open. with shared we mean that two or more processes use it. usually, when a
8158 # process closes a socket, it performs a shutdown procedure with half close.
8159 # on a shared socket, this would shutdown the socket as a whole, disabling it
8160 # for all processes. the shut-none option does not shutdown but close the
8161 # socket; this just removes the processes reference to the socket but keeps it
8162 # open for the other processes.
8163 NAME=TCP4ENDCLOSE
8164 case "$TESTS" in
8165 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
8166 TEST="$NAME: shut-none keeps TCP V4 socket open"
8167 # this is how we test the shut-none option:
8168 # we have some tcp service (CMD3) that accepts one connection and only receives
8169 # date.
8170 # a multiplexer process (CMD) opens a connection to that service; it accepts
8171 # multiple connections from client processes and merges and forwards their
8172 # data; each client is handled in a sub process with a clone of the forwarder
8173 # socket.
8174 # two client processes connect and send data. normally, the "common" connection
8175 # would terminate when the first client disconnects; with the shut-none option,
8176 # the data of the second process also has to arrive at the target service.
8177 if ! eval $NUMCOND; then :; else
8178 tf="$td/test$N.stdout"
8179 te="$td/test$N.stderr"
8180 tdiff="$td/test$N.diff"
8181 p1=$PORT; PORT=$((PORT+1))
8182 p2=$PORT
8183 da1a="$(date) $RANDOM"
8184 da1b="$(date) $RANDOM"
8185 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$LOCALHOST:$p1"
8186 CMD="$TRACE $SOCAT $opts -U TCP4:$LOCALHOST:$p2,shut-none TCP4-LISTEN:$p1,bind=$LOCALHOST,reuseaddr,fork"
8187 CMD3="$TRACE $SOCAT $opts -u TCP4-LISTEN:$p2,reuseaddr,bind=$LOCALHOST -"
8188 printf "test $F_n $TEST... " $N
8189 $CMD3 >"$tf" 2>"${te}3" &
8190 pid3=$!
8191 waittcp4port $p2 1
8192 $CMD 2>"${te}2" &
8193 pid2=$!
8194 usleep $MICROS
8195 waittcp4port $p1 1
8196 echo "$da1a" |$CMD1 2>>"${te}1a"
8197 echo "$da1b" |$CMD1 2>>"${te}1b"
8198 sleep 1
8199 kill "$pid3" "$pid2" 2>/dev/null
8200 wait
8201 if [ $? -ne 0 ]; then
8202 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8203 echo "$CMD1 &"
8204 echo "$CMD2"
8205 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8206 numFAIL=$((numFAIL+1))
8207 listFAIL="$listFAIL $N"
8208 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8209 $PRINTF "$FAILED\n"
8210 cat "$tdiff"
8211 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8212 numFAIL=$((numFAIL+1))
8213 listFAIL="$listFAIL $N"
8214 else
8215 $PRINTF "$OK\n"
8216 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2" "${te}3"; fi
8217 numOK=$((numOK+1))
8218 fi
8219 fi ;; # NUMCOND
8220 esac
8221 PORT=$((PORT+1))
8222 N=$((N+1))
8223  
8224 # purpose: see above; here we do not test against a TCP socket but an exec'd
8225 # sub process (socketpair)
8226 NAME=EXECENDCLOSE
8227 case "$TESTS" in
8228 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
8229 TEST="$NAME: end-close keeps EXEC child running"
8230 # this is how we test the shut-none option:
8231 # we have a server process (CMD) that runs a program (cat); the process accepts
8232 # multiple connections from client processes and merges and forwards their
8233 # data; each client is handled in a sub process with a clone of the forwarder
8234 # socket.
8235 # two client processes connect and send data. normally, the "common" connection
8236 # to the cat sub process would terminate when the first client disconnects;
8237 # with the shut-none option, the data of the second process also has to arrive
8238 # at the target service.
8239 if ! eval $NUMCOND; then :; else
8240 tf="$td/test$N.stdout"
8241 te="$td/test$N.stderr"
8242 ts="$td/test$N.sock"
8243 tdiff="$td/test$N.diff"
8244 da1a="$(date) $RANDOM"
8245 da1b="$(date) $RANDOM"
8246 CMD1="$TRACE $SOCAT $opts - UNIX-CONNECT:$ts"
8247 CMD="$TRACE $SOCAT -t0.1 $opts EXEC:"$CAT",shut-none,end-close UNIX-LISTEN:$ts,fork"
8248 printf "test $F_n $TEST... " $N
8249 $CMD 2>"${te}2" &
8250 pid2=$!
8251 waitfile $ts 1
8252 echo "$da1a" |$CMD1 2>>"${te}1a" >"$tf"
8253 usleep $MICROS
8254 echo "$da1b" |$CMD1 2>>"${te}1b" >>"$tf"
8255 #usleep $MICROS
8256 kill "$pid2" 2>/dev/null
8257 wait
8258 if [ $? -ne 0 ]; then
8259 $PRINTF "$FAILED\n"
8260 echo "$CMD1 &"
8261 echo "$CMD"
8262 cat "${te}1a" "${te}1b" "${te}2"
8263 numFAIL=$((numFAIL+1))
8264 listFAIL="$listFAIL $N"
8265 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8266 $PRINTF "$FAILED\n"
8267 echo "$CMD1 &"
8268 echo "$CMD"
8269 cat "$tdiff"
8270 cat "${te}1a" "${te}1b" "${te}2"
8271 numFAIL=$((numFAIL+1))
8272 listFAIL="$listFAIL $N"
8273 else
8274 $PRINTF "$OK\n"
8275 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2"; fi
8276 numOK=$((numOK+1))
8277 fi
8278 fi ;; # NUMCOND
8279 esac
8280 N=$((N+1))
8281  
8282  
8283 # up to 1.7.0.0 option end-close led to an error with some address types due to
8284 # bad internal handling. here we check it for address PTY
8285 NAME=PTYENDCLOSE
8286 case "$TESTS" in
8287 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
8288 TEST="$NAME: PTY handles option end-close"
8289 # with the bug, socat exits with error. we invoke socat in a no-op mode and
8290 # check its return status.
8291 if ! eval $NUMCOND; then :;
8292 else
8293 tf="$td/test$N.stout"
8294 te="$td/test$N.stderr"
8295 CMD="$TRACE $SOCAT $opts /dev/null pty,end-close"
8296 printf "test $F_n $TEST... " $N
8297 $CMD 2>"${te}"
8298 rc=$?
8299 if [ "$rc" = 0 ]; then
8300 $PRINTF "$OK\n"
8301 numOK=$((numOK+1))
8302 else
8303 $PRINTF "$FAILED\n"
8304 echo "$CMD"
8305 cat "${te}"
8306 numFAIL=$((numFAIL+1))
8307 listFAIL="$listFAIL $N"
8308 fi
8309 fi # NUMCOND
8310 ;;
8311 esac
8312 N=$((N+1))
8313  
8314  
8315 # test the shut-null and null-eof options
8316 NAME=SHUTNULLEOF
8317 case "$TESTS" in
8318 *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
8319 TEST="$NAME: options shut-null and null-eof"
8320 # run a receiving background process with option null-eof.
8321 # start a sending process with option shut-null that sends a test record to the
8322 # receiving process and then terminates.
8323 # send another test record.
8324 # whe the receiving process just got the first test record the test succeeded
8325 if ! eval $NUMCOND; then :; else
8326 tf="$td/test$N.stout"
8327 te="$td/test$N.stderr"
8328 tdiff="$td/test$N.diff"
8329 da="test$N $(date) $RANDOM"
8330 CMD0="$TRACE $SOCAT $opts -u UDP-RECV:$PORT,null-eof CREAT:$tf"
8331 CMD1="$TRACE $SOCAT $opts -u - UDP-SENDTO:127.0.0.1:$PORT,shut-null"
8332 printf "test $F_n $TEST... " $N
8333 $CMD0 >/dev/null 2>"${te}0" &
8334 pid0=$!
8335 waitudp4port $PORT 1
8336 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
8337 rc1=$?
8338 echo "xyz" |$CMD1 >"${tf}2" 2>"${te}2"
8339 rc2=$?
8340 kill $pid0 2>/dev/null; wait
8341 if [ $rc1 != 0 -o $rc2 != 0 ]; then
8342 $PRINTF "$FAILED\n"
8343 echo "$CMD0 &"
8344 echo "$CMD1"
8345 cat "${te}0"
8346 cat "${te}1"
8347 cat "${te}2"
8348 numFAIL=$((numFAIL+1))
8349 listFAIL="$listFAIL $N"
8350 elif echo "$da" |diff - "${tf}" >"$tdiff"; then
8351 $PRINTF "$OK\n"
8352 numOK=$((numOK+1))
8353 else
8354 $PRINTF "$FAILED\n"
8355 echo "$CMD0 &"
8356 echo "$CMD1"
8357 cat "${te}0"
8358 cat "${te}1"
8359 cat "${tdiff}"
8360 numFAIL=$((numFAIL+1))
8361 listFAIL="$listFAIL $N"
8362 fi
8363 fi # NUMCOND
8364 ;;
8365 esac
8366 N=$((N+1))
8367  
8368  
8369 NAME=UDP6LISTENBIND
8370 # this tests for a bug in (up to) 1.5.0.0:
8371 # with udp*-listen, the bind option supported only IPv4
8372 case "$TESTS" in
8373 *%$N%*|*%functions%*|*%bugs%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
8374 TEST="$NAME: UDP6-LISTEN with bind"
8375 if ! eval $NUMCOND; then :;
8376 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
8377 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8378 numCANT=$((numCANT+1))
8379 else
8380 tf="$td/test$N.stdout"
8381 te="$td/test$N.stderr"
8382 tdiff="$td/test$N.diff"
8383 tsl=$PORT
8384 ts="$LOCALHOST6:$tsl"
8385 da="test$N $(date) $RANDOM"
8386 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,reuseaddr,bind=$LOCALHOST6 PIPE"
8387 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
8388 printf "test $F_n $TEST... " $N
8389 $CMD1 >"$tf" 2>"${te}1" &
8390 pid1=$!
8391 waitudp6port $tsl 1
8392 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8393 rc2=$?
8394 kill $pid1 2>/dev/null; wait
8395 if [ $rc2 -ne 0 ]; then
8396 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8397 echo "$CMD1 &"
8398 echo "$CMD2"
8399 cat "${te}1" "${te}2"
8400 numFAIL=$((numFAIL+1))
8401 listFAIL="$listFAIL $N"
8402 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8403 $PRINTF "$FAILED\n"
8404 cat "$tdiff"
8405 numFAIL=$((numFAIL+1))
8406 listFAIL="$listFAIL $N"
8407 else
8408 $PRINTF "$OK\n"
8409 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8410 numOK=$((numOK+1))
8411 fi
8412 fi ;; # NUMCOND, feats
8413 esac
8414 PORT=$((PORT+1))
8415 N=$((N+1))
8416  
8417  
8418 NAME=TCPWRAPPERS_MULTIOPTS
8419 # this tests for a bug in 1.5.0.0 that let socat fail when more than one
8420 # tcp-wrappers related option was specified in one address
8421 case "$TESTS" in
8422 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
8423 TEST="$NAME: use of multiple tcpwrapper enabling options"
8424 if ! eval $NUMCOND; then :;
8425 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
8426 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8427 numCANT=$((numCANT+1))
8428 else
8429 tf="$td/test$N.stdout"
8430 te="$td/test$N.stderr"
8431 tdiff="$td/test$N.diff"
8432 da="test$N $(date) $RANDOM"
8433 ha="$td/hosts.allow"
8434 $ECHO "test : ALL : allow" >"$ha"
8435 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr,hosts-allow=$ha,tcpwrap=test pipe"
8436 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
8437 printf "test $F_n $TEST... " $N
8438 $CMD1 2>"${te}1" &
8439 waittcp4port $PORT
8440 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8441 if [ $? -ne 0 ]; then
8442 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8443 echo "$CMD1 &"
8444 echo "$CMD2"
8445 cat "${te}1"
8446 cat "${te}2"
8447 numFAIL=$((numFAIL+1))
8448 listFAIL="$listFAIL $N"
8449 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8450 $PRINTF "$FAILED\n"
8451 cat "$tdiff"
8452 numFAIL=$((numFAIL+1))
8453 listFAIL="$listFAIL $N"
8454 else
8455 $PRINTF "$OK\n"
8456 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8457 numOK=$((numOK+1))
8458 fi
8459 fi ;; # NUMCOND, feats
8460 esac
8461 PORT=$((PORT+1))
8462 N=$((N+1))
8463  
8464  
8465 NAME=TCPWRAPPERS_TCP6ADDR
8466 # this tests for a bug in 1.5.0.0 that brought false results with tcp-wrappers
8467 # and IPv6 when
8468 case "$TESTS" in
8469 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
8470 TEST="$NAME: specification of TCP6 address in hosts.allow"
8471 if ! eval $NUMCOND; then :;
8472 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
8473 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8474 numCANT=$((numCANT+1))
8475 else
8476 tf="$td/test$N.stdout"
8477 te="$td/test$N.stderr"
8478 tdiff="$td/test$N.diff"
8479 da="test$N $(date) $RANDOM"
8480 ha="$td/hosts.allow"
8481 hd="$td/hosts.deny"
8482 $ECHO "socat : [::1] : allow" >"$ha"
8483 $ECHO "ALL : ALL : deny" >"$hd"
8484 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$PORT,reuseaddr,tcpwrap-etc=$td,tcpwrappers=socat pipe"
8485 CMD2="$TRACE $SOCAT $opts - TCP6:[::1]:$PORT"
8486 printf "test $F_n $TEST... " $N
8487 $CMD1 2>"${te}1" &
8488 pid1=$!
8489 waittcp6port $PORT
8490 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8491 kill $pid1 2>/dev/null; wait
8492 if [ $? -ne 0 ]; then
8493 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8494 echo "$CMD1 &"
8495 echo "$CMD2"
8496 cat "${te}1"
8497 cat "${te}2"
8498 numFAIL=$((numFAIL+1))
8499 listFAIL="$listFAIL $N"
8500 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8501 $PRINTF "$FAILED\n"
8502 cat "$tdiff"
8503 numFAIL=$((numFAIL+1))
8504 listFAIL="$listFAIL $N"
8505 else
8506 $PRINTF "$OK\n"
8507 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8508 numOK=$((numOK+1))
8509 fi
8510 fi ;; # NUMCOND, feats
8511 esac
8512 PORT=$((PORT+1))
8513 N=$((N+1))
8514  
8515  
8516 NAME=UDP4BROADCAST
8517 case "$TESTS" in
8518 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%$NAME%*)
8519 TEST="$NAME: UDP/IPv4 broadcast"
8520 if ! eval $NUMCOND; then :;
8521 elif [ -z "$BCADDR" ]; then
8522 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8523 numCANT=$((numCANT+1))
8524 else
8525 tf="$td/test$N.stdout"
8526 te="$td/test$N.stderr"
8527 tdiff="$td/test$N.diff"
8528 ts1p=$PORT; PORT=$((PORT+1))
8529 #ts1="$BCADDR/8:$ts1p"
8530 ts1="$BCADDR:$ts1p"
8531 ts2p=$PORT; PORT=$((PORT+1))
8532 ts2="$BCIFADDR:$ts2p"
8533 da="test$N $(date) $RANDOM"
8534 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE"
8535 #CMD2="$TRACE $SOCAT $opts - UDP4-BROADCAST:$ts1"
8536 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast"
8537 printf "test $F_n $TEST... " $N
8538 $CMD1 2>"${te}1" &
8539 pid1="$!"
8540 waitudp4port $ts1p 1
8541 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8542 rc2="$?"
8543 kill "$pid1" 2>/dev/null; wait;
8544 if [ "$rc2" -ne 0 ]; then
8545 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8546 echo "$CMD1 &"
8547 echo "$CMD2"
8548 cat "${te}1"
8549 cat "${te}2"
8550 numFAIL=$((numFAIL+1))
8551 listFAIL="$listFAIL $N"
8552 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8553 $PRINTF "$FAILED\n"
8554 cat "$tdiff"
8555 numFAIL=$((numFAIL+1))
8556 listFAIL="$listFAIL $N"
8557 else
8558 $PRINTF "$OK\n"
8559 if [ -n "$tut" ]; then
8560 echo "$CMD1 &"
8561 echo "$CMD2"
8562 fi
8563 if [ -n "$debug" ]; then cat $te; fi
8564 numOK=$((numOK+1))
8565 fi
8566 fi ;; # NUMCOND, feats
8567 esac
8568 N=$((N+1))
8569  
8570  
8571 NAME=IP4BROADCAST
8572 # test a local broadcast of a raw IPv4 protocol.
8573 # because we receive - in addition to the regular reply - our own broadcast,
8574 # we use a token XXXX that is changed to YYYY in the regular reply packet.
8575 case "$TESTS" in
8576 *%$N%*|*%functions%*|*%engine%*|*%rawip%*|*%rawip4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%root%*|*%$NAME%*)
8577 TEST="$NAME: raw IPv4 broadcast"
8578 if ! eval $NUMCOND; then :;
8579 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8580 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP4 not available${NORMAL}\n" $N
8581 numCANT=$((numCANT+1))
8582 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8583 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8584 numCANT=$((numCANT+1))
8585 elif [ -z "$BCADDR" ]; then
8586 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8587 else
8588 tf="$td/test$N.stdout"
8589 te="$td/test$N.stderr"
8590 tdiff="$td/test$N.diff"
8591 ts1p=$PROTO
8592 #ts1="$BCADDR/8:$ts1p"
8593 ts1="$BCADDR:$ts1p"
8594 ts2p=$ts1p
8595 ts2="$BCIFADDR"
8596 da="test$N $(date) $RANDOM XXXX"
8597 sh="$td/test$N-sed.sh"
8598 echo 'sed s/XXXX/YYYY/' >"$sh"
8599 chmod a+x "$sh"
8600 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,broadcast exec:$sh"
8601 #CMD2="$TRACE $SOCAT $opts - IP4-BROADCAST:$ts1"
8602 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:$ts1,broadcast"
8603 printf "test $F_n $TEST... " $N
8604 $CMD1 2>"${te}1" &
8605 pid1="$!"
8606 waitip4port $ts1p 1
8607 echo "$da" |$CMD2 2>>"${te}2" |grep -v XXXX >>"$tf"
8608 rc2="$?"
8609 kill "$pid1" 2>/dev/null; wait;
8610 if [ "$rc2" -ne 0 ]; then
8611 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8612 echo "$CMD1 &"
8613 echo "$CMD2"
8614 cat "${te}1"
8615 cat "${te}2"
8616 numFAIL=$((numFAIL+1))
8617 listFAIL="$listFAIL $N"
8618 elif ! echo "$da" | sed 's/XXXX/YYYY/'|diff - "$tf" >"$tdiff"; then
8619 $PRINTF "$FAILED\n"
8620 cat "$tdiff"
8621 numFAIL=$((numFAIL+1))
8622 listFAIL="$listFAIL $N"
8623 else
8624 $PRINTF "$OK\n"
8625 if [ -n "$debug" ]; then cat $te; fi
8626 numOK=$((numOK+1))
8627 fi
8628 fi ;; # NUMCOND, feats
8629 esac
8630 PROTO=$((PROTO+1))
8631 N=$((N+1))
8632  
8633  
8634 #NAME=UDP4BROADCAST_RANGE
8635 #case "$TESTS" in
8636 #*%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%range%*|*%$NAME%*)
8637 #TEST="$NAME: security of UDP4-BROADCAST with RANGE option"
8638 #if ! eval $NUMCOND; then :;
8639 #elif [ -z "$BCADDR" ]; then
8640 # $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8641 #else
8642 #testserversec "$N" "$TEST" "$opts -s" "UDP4-BROADCAST:$BCADDR/8:$PORT" "" "range=127.1.0.0:255.255.0.0" "udp4:127.1.0.0:$PORT" 4 udp $PORT 0
8643 #fi ;; # NUMCOND, feats
8644 #esac
8645 #PORT=$((PORT+1))
8646 #N=$((N+1))
8647  
8648  
8649 NAME=UDP4MULTICAST_UNIDIR
8650 case "$TESTS" in
8651 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8652 TEST="$NAME: UDP/IPv4 multicast, send only"
8653 if ! eval $NUMCOND; then :;
8654 elif ! feat=$(testaddrs ip4 udp) || ! runsip4 >/dev/null; then
8655 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8656 numCANT=$((numCANT+1))
8657 else
8658 tf="$td/test$N.stdout"
8659 te="$td/test$N.stderr"
8660 tdiff="$td/test$N.diff"
8661 ts1p=$PORT; PORT=$((PORT+1))
8662 ts1a="$SECONDADDR"
8663 ts1="$ts1a:$ts1p"
8664 da="test$N $(date) $RANDOM"
8665 CMD1="$TRACE $SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8666 CMD2="$TRACE $SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8667 printf "test $F_n $TEST... " $N
8668 $CMD1 2>"${te}1" >"${tf}" &
8669 pid1="$!"
8670 waitudp4port $ts1p 1
8671 echo "$da" |$CMD2 2>>"${te}2"
8672 rc2="$?"
8673 usleep $MICROS
8674 kill "$pid1" 2>/dev/null; wait;
8675 if [ "$rc2" -ne 0 ]; then
8676 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8677 echo "$CMD1 &"
8678 echo "$CMD2"
8679 cat "${te}1"
8680 cat "${te}2"
8681 numFAIL=$((numFAIL+1))
8682 listFAIL="$listFAIL $N"
8683 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8684 $PRINTF "$FAILED\n"
8685 cat "$tdiff"
8686 numFAIL=$((numFAIL+1))
8687 listFAIL="$listFAIL $N"
8688 else
8689 $PRINTF "$OK\n"
8690 if [ -n "$debug" ]; then cat $te; fi
8691 numOK=$((numOK+1))
8692 fi
8693 fi ;; # NUMCOND, feats
8694 esac
8695 N=$((N+1))
8696  
8697 NAME=IP4MULTICAST_UNIDIR
8698 case "$TESTS" in
8699 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
8700 TEST="$NAME: IPv4 multicast"
8701 if ! eval $NUMCOND; then :;
8702 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8703 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8704 numCANT=$((numCANT+1))
8705 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8706 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8707 numCANT=$((numCANT+1))
8708 else
8709 tf="$td/test$N.stdout"
8710 te="$td/test$N.stderr"
8711 tdiff="$td/test$N.diff"
8712 ts1p=$PROTO
8713 ts1a="$SECONDADDR"
8714 ts1="$ts1a:$ts1p"
8715 da="test$N $(date) $RANDOM"
8716 CMD1="$TRACE $SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8717 CMD2="$TRACE $SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8718 printf "test $F_n $TEST... " $N
8719 $CMD1 2>"${te}1" >"${tf}" &
8720 pid1="$!"
8721 waitip4proto $ts1p 1
8722 usleep $((10*MICROS))
8723 echo "$da" |$CMD2 2>>"${te}2"
8724 rc2="$?"
8725 #usleep $MICROS
8726 sleep 1
8727 kill "$pid1" 2>/dev/null; wait;
8728 if [ "$rc2" -ne 0 ]; then
8729 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8730 echo "$CMD1 &"
8731 echo "$CMD2"
8732 cat "${te}1"
8733 cat "${te}2"
8734 numFAIL=$((numFAIL+1))
8735 listFAIL="$listFAIL $N"
8736 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8737 $PRINTF "$FAILED\n"
8738 cat "$tdiff"
8739 numFAIL=$((numFAIL+1))
8740 listFAIL="$listFAIL $N"
8741 else
8742 $PRINTF "$OK\n"
8743 if [ -n "$debug" ]; then cat $te; fi
8744 numOK=$((numOK+1))
8745 fi
8746 fi ;; # NUMCOND, feats
8747 esac
8748 PROTO=$((PROTO+1))
8749 N=$((N+1))
8750  
8751 if false; then
8752 NAME=UDP6MULTICAST_UNIDIR
8753 case "$TESTS" in
8754 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8755 TEST="$NAME: UDP/IPv6 multicast"
8756 if ! eval $NUMCOND; then :;
8757 elif ! feat=$(testaddrs ip6 udp) || ! runsip6 >/dev/null; then
8758 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8759 numCANT=$((numCANT+1))
8760 else
8761 tf="$td/test$N.stdout"
8762 te="$td/test$N.stderr"
8763 tdiff="$td/test$N.diff"
8764 ts1p=$PORT; PORT=$((PORT+1))
8765 if1="$MCINTERFACE"
8766 ts1a="[::1]"
8767 da="test$N $(date) $RANDOM"
8768 CMD1="$TRACE $SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -"
8769 CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a"
8770 printf "test $F_n $TEST... " $N
8771 $CMD1 2>"${te}1" >"${tf}" &
8772 pid1="$!"
8773 waitudp6port $ts1p 1
8774 echo "$da" |$CMD2 2>>"${te}2"
8775 rc2="$?"
8776 usleep $MICROS
8777 kill "$pid1" 2>/dev/null; wait;
8778 if [ "$rc2" -ne 0 ]; then
8779 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8780 echo "$CMD1 &"
8781 echo "$CMD2"
8782 cat "${te}1"
8783 cat "${te}2"
8784 numFAIL=$((numFAIL+1))
8785 listFAIL="$listFAIL $N"
8786 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8787 $PRINTF "$FAILED\n"
8788 cat "$tdiff"
8789 numFAIL=$((numFAIL+1))
8790 listFAIL="$listFAIL $N"
8791 else
8792 $PRINTF "$OK\n"
8793 if [ -n "$debug" ]; then cat $te; fi
8794 numOK=$((numOK+1))
8795 fi
8796 fi ;; # NUMCOND, feats
8797 esac
8798 N=$((N+1))
8799 fi # false
8800  
8801 NAME=UDP4MULTICAST_BIDIR
8802 case "$TESTS" in
8803 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8804 TEST="$NAME: UDP/IPv4 multicast, with reply"
8805 if ! eval $NUMCOND; then :; else
8806 tf="$td/test$N.stdout"
8807 te="$td/test$N.stderr"
8808 tdiff="$td/test$N.diff"
8809 ts1p=$PORT; PORT=$((PORT+1))
8810 ts1a="$SECONDADDR"
8811 ts1="$ts1a:$ts1p"
8812 ts2p=$PORT; PORT=$((PORT+1))
8813 ts2="$BCIFADDR:$ts2p"
8814 da="test$N $(date) $RANDOM"
8815 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8816 #CMD2="$TRACE $SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8817 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8818 printf "test $F_n $TEST... " $N
8819 $CMD1 2>"${te}1" &
8820 pid1="$!"
8821 waitudp4port $ts1p 1
8822 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8823 rc2="$?"
8824 kill "$pid1" 2>/dev/null; wait;
8825 if [ "$rc2" -ne 0 ]; then
8826 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8827 echo "$CMD1 &"
8828 echo "$CMD2"
8829 cat "${te}1"
8830 cat "${te}2"
8831 numFAIL=$((numFAIL+1))
8832 listFAIL="$listFAIL $N"
8833 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8834 $PRINTF "$FAILED\n"
8835 cat "$tdiff"
8836 numFAIL=$((numFAIL+1))
8837 listFAIL="$listFAIL $N"
8838 else
8839 $PRINTF "$OK\n"
8840 if [ -n "$tut" ]; then
8841 echo "$CMD1 &"
8842 echo "$CMD2"
8843 fi
8844 if [ -n "$debug" ]; then cat $te; fi
8845 numOK=$((numOK+1))
8846 fi
8847 fi ;; # NUMCOND
8848 esac
8849 N=$((N+1))
8850  
8851 NAME=IP4MULTICAST_BIDIR
8852 case "$TESTS" in
8853 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
8854 TEST="$NAME: IPv4 multicast, with reply"
8855 if ! eval $NUMCOND; then :;
8856 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8857 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8858 numCANT=$((numCANT+1))
8859 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8860 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8861 numCANT=$((numCANT+1))
8862 else
8863 tf="$td/test$N.stdout"
8864 te="$td/test$N.stderr"
8865 tdiff="$td/test$N.diff"
8866 ts1p=$PROTO
8867 ts1a="$SECONDADDR"
8868 ts1="$ts1a:$ts1p"
8869 da="test$N $(date) $RANDOM"
8870 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8871 #CMD2="$TRACE $SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8872 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8873 printf "test $F_n $TEST... " $N
8874 $CMD1 2>"${te}1" &
8875 pid1="$!"
8876 waitip4port $ts1p 1
8877 usleep 100000 # give process a chance to add multicast membership
8878 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8879 rc2="$?"
8880 kill "$pid1" 2>/dev/null; wait;
8881 if [ "$rc2" -ne 0 ]; then
8882 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8883 echo "$CMD1 &"
8884 echo "$CMD2"
8885 cat "${te}1"
8886 cat "${te}2"
8887 numFAIL=$((numFAIL+1))
8888 listFAIL="$listFAIL $N"
8889 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8890 $PRINTF "$FAILED\n"
8891 cat "$tdiff"
8892 numFAIL=$((numFAIL+1))
8893 listFAIL="$listFAIL $N"
8894 else
8895 $PRINTF "$OK\n"
8896 if [ -n "$tut" ]; then
8897 echo "$CMD1 &"
8898 echo "$CMD2"
8899 fi
8900 if [ -n "$debug" ]; then cat $te; fi
8901 numOK=$((numOK+1))
8902 fi
8903 fi ;; # NUMCOND, feats
8904 esac
8905 PROTO=$((PROTO+1))
8906 N=$((N+1))
8907  
8908  
8909 NAME=TUNREAD
8910 case "$TESTS" in
8911 *%$N%*|*%functions%*|*%tun%*|*%root%*|*%$NAME%*)
8912 TEST="$NAME: reading data sent through tun interface"
8913 #idea: create a TUN interface and send a datagram to one of the addresses of
8914 # its virtual network. On the tunnel side, read the packet and compare its last
8915 # bytes with the datagram payload
8916 if ! eval $NUMCOND; then :;
8917 elif ! feat=$(testaddrs ip4 tun) || ! runsip4 >/dev/null; then
8918 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8919 numCANT=$((numCANT+1))
8920 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8921 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8922 numCANT=$((numCANT+1))
8923 else
8924 tf="$td/test$N.stdout"
8925 te="$td/test$N.stderr"
8926 tdiff="$td/test$N.diff"
8927 tl="$td/test$N.lock"
8928 da="test$N $(date) $RANDOM"
8929 dalen=$((${#da}+1))
8930 TUNNET=10.255.255
8931 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT"
8932 #CMD="$TRACE $SOCAT $opts -u -L $tl TUN,ifaddr=$TUNNET.1,netmask=255.255.255.0,iff-up=1 -"
8933 CMD="$TRACE $SOCAT $opts -u -L $tl TUN:$TUNNET.1/24,iff-up=1 -"
8934 printf "test $F_n $TEST... " $N
8935 $CMD 2>"${te}" |tail --bytes=$dalen >"${tf}" &
8936 sleep 1
8937 echo "$da" |$CMD1 2>"${te}1"
8938 sleep 1
8939 kill "$(cat $tl)" 2>/dev/null
8940 wait
8941 if [ $? -ne 0 ]; then
8942 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8943 echo "$CMD &"
8944 echo "$CMD1"
8945 cat "${te}" "${te}1"
8946 numFAIL=$((numFAIL+1))
8947 listFAIL="$listFAIL $N"
8948 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8949 $PRINTF "$FAILED\n"
8950 cat "$tdiff"
8951 cat "${te}" "${te}1"
8952 numFAIL=$((numFAIL+1))
8953 listFAIL="$listFAIL $N"
8954 else
8955 $PRINTF "$OK\n"
8956 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8957 numOK=$((numOK+1))
8958 fi
8959 fi ;; # NUMCOND, feats
8960 esac
8961 PORT=$((PORT+1))
8962 N=$((N+1))
8963  
8964  
8965 # use the INTERFACE address on a tun/tap device and transfer data fully
8966 # transparent
8967 NAME=TUNINTERFACE
8968 case "$TESTS" in
8969 *%$N%*|*%functions%*|*%tun%*|*%interface%*|*%root%*|*%$NAME%*)
8970 TEST="$NAME: pass data through tun interface using INTERFACE"
8971 #idea: create a TUN interface and send a raw packet on the interface side.
8972 # It should arrive unmodified on the tunnel side.
8973 if ! eval $NUMCOND; then :;
8974 elif ! feat=$(testaddrs ip4 tun interface) || ! runsip4 >/dev/null; then
8975 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8976 numCANT=$((numCANT+1))
8977 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8978 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8979 numCANT=$((numCANT+1))
8980 else
8981 tf="$td/test$N.stdout"
8982 te="$td/test$N.stderr"
8983 tdiff="$td/test$N.diff"
8984 tl="$td/test$N.lock"
8985 da="$(date) $RANDOM"
8986 dalen=$((${#da}+1))
8987 TUNNET=10.255.255
8988 TUNNAME=tun9
8989 CMD1="$TRACE $SOCAT $opts -L $tl TUN:$TUNNET.1/24,iff-up=1,tun-type=tun,tun-name=$TUNNAME echo"
8990 CMD="$TRACE $SOCAT $opts - INTERFACE:$TUNNAME"
8991 printf "test $F_n $TEST... " $N
8992 $CMD1 2>"${te}1" &
8993 pid1="$!"
8994 #waitinterface "$TUNNAME"
8995 sleep 1
8996 echo "$da" |$CMD 2>"${te}1" >"$tf" 2>"${te}"
8997 kill $pid1 2>/dev/null
8998 wait
8999 if [ $? -ne 0 ]; then
9000 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9001 echo "$CMD &"
9002 echo "$CMD1"
9003 cat "${te}" "${te}1"
9004 numFAIL=$((numFAIL+1))
9005 listFAIL="$listFAIL $N"
9006 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9007 $PRINTF "$FAILED\n"
9008 cat "$tdiff"
9009 cat "${te}" "${te}1"
9010 numFAIL=$((numFAIL+1))
9011 listFAIL="$listFAIL $N"
9012 else
9013 $PRINTF "$OK\n"
9014 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
9015 numOK=$((numOK+1))
9016 fi
9017 fi ;; # NUMCOND, feats
9018 esac
9019 PORT=$((PORT+1))
9020 N=$((N+1))
9021  
9022  
9023 NAME=ABSTRACTSTREAM
9024 case "$TESTS" in
9025 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%connect%*|*%listen%*|*%$NAME%*)
9026 TEST="$NAME: abstract UNIX stream socket, listen and connect"
9027 if ! eval $NUMCOND; then :;
9028 elif ! feat=$(testaddrs abstract-unixsocket); then
9029 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9030 numCANT=$((numCANT+1))
9031 else
9032 ts="$td/test$N.socket"
9033 tf="$td/test$N.stdout"
9034 te="$td/test$N.stderr"
9035 tdiff="$td/test$N.diff"
9036 da1="test$N $(date) $RANDOM"
9037 #establish a listening abstract unix socket
9038 SRV="$TRACE $SOCAT $opts -lpserver ABSTRACT-LISTEN:\"$ts\" PIPE"
9039 #make a connection
9040 CMD="$TRACE $SOCAT $opts - ABSTRACT-CONNECT:$ts"
9041 $PRINTF "test $F_n $TEST... " $N
9042 touch "$ts" # make a file with same name, so non-abstract fails
9043 eval "$SRV 2>${te}s &"
9044 pids=$!
9045 #waitfile "$ts"
9046 sleep 1
9047 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
9048 if [ $? -ne 0 ]; then
9049 kill "$pids" 2>/dev/null
9050 $PRINTF "$FAILED:\n"
9051 echo "$SRV &"
9052 cat "${te}s"
9053 echo "$CMD"
9054 cat "${te}1"
9055 numFAIL=$((numFAIL+1))
9056 listFAIL="$listFAIL $N"
9057 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
9058 kill "$pids" 2>/dev/null
9059 $PRINTF "$FAILED:\n"
9060 echo "$SRV &"
9061 cat "${te}s"
9062 echo "$CMD"
9063 cat "${te}1"
9064 cat "$tdiff"
9065 numFAIL=$((numFAIL+1))
9066 listFAIL="$listFAIL $N"
9067 else
9068 $PRINTF "$OK\n"
9069 if [ -n "$debug" ]; then cat $te; fi
9070 numOK=$((numOK+1))
9071 fi # !(rc -ne 0)
9072 wait
9073 fi ;; # NUMCOND, feats
9074 esac
9075 N=$((N+1))
9076  
9077  
9078 NAME=ABSTRACTDGRAM
9079 case "$TESTS" in
9080 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%$NAME%*)
9081 TEST="$NAME: abstract UNIX datagram"
9082 if ! eval $NUMCOND; then :;
9083 elif ! feat=$(testaddrs abstract-unixsocket); then
9084 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9085 numCANT=$((numCANT+1))
9086 else
9087 tf="$td/test$N.stdout"
9088 te="$td/test$N.stderr"
9089 tdiff="$td/test$N.diff"
9090 ts1="$td/test$N.socket1"
9091 ts2="$td/test$N.socket2"
9092 da="test$N $(date) $RANDOM"
9093 CMD1="$TRACE $SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE"
9094 #CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9095 CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9096 printf "test $F_n $TEST... " $N
9097 touch "$ts1" # make a file with same name, so non-abstract fails
9098 $CMD1 2>"${te}1" &
9099 pid1="$!"
9100 sleep 1
9101 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9102 rc2=$?
9103 kill "$pid1" 2>/dev/null; wait
9104 if [ $rc2 -ne 0 ]; then
9105 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9106 echo "$CMD1 &"
9107 cat "${te}1"
9108 echo "$CMD2"
9109 cat "${te}2"
9110 numFAIL=$((numFAIL+1))
9111 listFAIL="$listFAIL $N"
9112 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9113 $PRINTF "$FAILED\n"
9114 cat "$tdiff"
9115 numFAIL=$((numFAIL+1))
9116 listFAIL="$listFAIL $N"
9117 else
9118 $PRINTF "$OK\n"
9119 if [ -n "$debug" ]; then cat $te; fi
9120 numOK=$((numOK+1))
9121 fi
9122 fi ;; # NUMCOND, feats
9123 esac
9124 N=$((N+1))
9125  
9126  
9127 NAME=ABSTRACTRECV
9128 case "$TESTS" in
9129 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%recv%*|*%$NAME%*)
9130 TEST="$NAME: abstract UNIX datagram receive"
9131 if ! eval $NUMCOND; then :;
9132 elif ! feat=$(testaddrs abstract-unixsocket); then
9133 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9134 numCANT=$((numCANT+1))
9135 else
9136 ts="$td/test$N.socket"
9137 tf="$td/test$N.stdout"
9138 te="$td/test$N.stderr"
9139 tdiff="$td/test$N.diff"
9140 ts1="$ts"
9141 da="test$N $(date) $RANDOM"
9142 CMD1="$TRACE $SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -"
9143 CMD2="$TRACE $SOCAT $opts -u - ABSTRACT-SENDTO:$ts1"
9144 printf "test $F_n $TEST... " $N
9145 touch "$ts1" # make a file with same name, so non-abstract fails
9146 $CMD1 >"$tf" 2>"${te}1" &
9147 pid1="$!"
9148 #waitfile $ts1 1
9149 sleep 1
9150 echo "$da" |$CMD2 2>>"${te}2"
9151 rc2="$?"
9152 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9153 kill "$pid1" 2>/dev/null; wait
9154 if [ "$rc2" -ne 0 ]; then
9155 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9156 echo "$CMD1 &"
9157 echo "$CMD2"
9158 cat "${te}1"
9159 cat "${te}2"
9160 numFAIL=$((numFAIL+1))
9161 listFAIL="$listFAIL $N"
9162 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9163 $PRINTF "$FAILED\n"
9164 echo "$CMD1 &"
9165 cat "${te}1"
9166 cat "$tdiff"
9167 numFAIL=$((numFAIL+1))
9168 listFAIL="$listFAIL $N"
9169 else
9170 $PRINTF "$OK\n"
9171 if [ -n "$debug" ]; then cat $te; fi
9172 numOK=$((numOK+1))
9173 fi
9174 fi ;; # NUMCOND, feats
9175 esac
9176 N=$((N+1))
9177  
9178  
9179 # bind with Linux abstract UNIX domain addresses bound to filesystem socket
9180 # instead of abstract namespace
9181 NAME=ABSTRACT_BIND
9182 case "$TESTS" in
9183 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
9184 TEST="$NAME: abstract bind"
9185 # open an abstract client address with bind option, bind to the target socket.
9186 # send a datagram.
9187 # when socat outputs the datagram it got the test succeeded
9188 if ! eval $NUMCOND; then :;
9189 elif [ "$UNAME" != Linux ]; then
9190 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
9191 numCANT=$((numCANT+1))
9192 else
9193 tf="$td/test$N.stdout"
9194 te="$td/test$N.stderr"
9195 tdiff="$td/test$N.diff"
9196 ts1="$td/test$N.sock1"
9197 da="test$N $(date) $RANDOM"
9198 CMD1="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts1"
9199 printf "test $F_n $TEST... " $N
9200 echo "$da" |$CMD1 >$tf 2>"${te}1"
9201 rc1=$?
9202 if [ $rc1 -ne 0 ]; then
9203 $PRINTF "$FAILED\n"
9204 echo "$CMD1" >&2
9205 echo "rc=$rc1" >&2
9206 cat "${te}1" >&2
9207 numFAIL=$((numFAIL+1))
9208 listFAIL="$listFAIL $N"
9209 elif echo "$da" |diff -q - $tf; then
9210 $PRINTF "$OK\n"
9211 numOK=$((numOK+1))
9212 else
9213 $PRINTF "$FAILED\n"
9214 echo "$CMD1" >&2
9215 cat "${te}1" >&2
9216 echo "$da" |diff - "$tf" >&2
9217 numFAIL=$((numFAIL+1))
9218 listFAIL="$listFAIL $N"
9219 fi
9220 fi # NUMCOND
9221 ;;
9222 esac
9223 PORT=$((PORT+1))
9224 N=$((N+1))
9225  
9226  
9227 NAME=OPENSSLREAD
9228 # socat determined availability of data using select(). With openssl, the
9229 # following situation might occur:
9230 # a SSL data block with more than 8192 bytes (socats default blocksize)
9231 # arrives; socat calls SSL_read, and the SSL routine reads the complete block.
9232 # socat then reads 8192 bytes from the SSL layer, the rest remains buffered.
9233 # If the TCP connection stays idle for some time, the data in the SSL layer
9234 # keeps there and is not transferred by socat until the socket indicates more
9235 # data or EOF.
9236 case "$TESTS" in
9237 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
9238 TEST="$NAME: socat handles data buffered by openssl"
9239 #idea: have a socat process (server) that gets an SSL block that is larger than
9240 # socat transfer block size; keep the socket connection open and kill the
9241 # server process after a short time; if not the whole data block has been
9242 # transferred, the test has failed.
9243 if ! eval $NUMCOND; then :;
9244 elif ! feat=$(testaddrs openssl) >/dev/null; then
9245 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9246 numCANT=$((numCANT+1))
9247 else
9248 tf="$td/test$N.out"
9249 te="$td/test$N.err"
9250 tdiff="$td/test$N.diff"
9251 da="test$N $(date) $RANDOM"
9252 SRVCERT=testsrv
9253 gentestcert "$SRVCERT"
9254 CMD1="$TRACE $SOCAT $opts -u -T 1 -b $($ECHO "$da\c" |wc -c) OPENSSL-LISTEN:$PORT,reuseaddr,cert=$SRVCERT.pem,verify=0 -"
9255 CMD2="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
9256 printf "test $F_n $TEST... " $N
9257 #
9258 $CMD1 2>"${te}1" >"$tf" &
9259 pid=$! # background process id
9260 waittcp4port $PORT
9261 (echo "$da"; sleep 2) |$CMD2 2>"${te}2"
9262 kill "$pid" 2>/dev/null; wait
9263 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9264 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9265 echo "$CMD1"
9266 cat "${te}1"
9267 echo "$CMD2"
9268 cat "${te}2"
9269 cat "$tdiff"
9270 numFAIL=$((numFAIL+1))
9271 listFAIL="$listFAIL $N"
9272 else
9273 $PRINTF "$OK\n"
9274 if [ -n "$debug" ]; then cat $te; fi
9275 numOK=$((numOK+1))
9276 fi
9277 wait
9278 fi # NUMCOND, featsesac
9279 ;;
9280 esac
9281 N=$((N+1))
9282  
9283  
9284 # test: there is a bug with the readbytes option: when the socket delivered
9285 # exacly that many bytes as specified with readbytes and the stays idle (no
9286 # more data, no EOF), socat waits for more data instead of generating EOF on
9287 # this in put stream.
9288 NAME=READBYTES_EOF
9289 #set -vx
9290 case "$TESTS" in
9291 *%$N%*|*%functions%*|*%$NAME%*)
9292 TEST="$NAME: trigger EOF after that many bytes, even when socket idle"
9293 #idea: we deliver that many bytes to socat; the process should terminate then.
9294 # we try to transfer data in the other direction then; if transfer succeeds,
9295 # the process did not terminate and the bug is still there.
9296 if ! eval $NUMCOND; then :;
9297 elif false; then
9298 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9299 numCANT=$((numCANT+1))
9300 else
9301 tr="$td/test$N.ref"
9302 ti="$td/test$N.in"
9303 to="$td/test$N.out"
9304 te="$td/test$N.err"
9305 tdiff="$td/test$N.diff"
9306 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
9307 CMD="$TRACE $SOCAT $opts -%system:\"echo A; sleep $((2*SECONDs))\",readbytes=2 /dev/null%-"
9308 printf "test $F_n $TEST... " $N
9309 (usleep $((2*MICROS)); echo) |eval "$CMD" >"$to" 2>"$te"
9310 if test -s "$to"; then
9311 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9312 echo "$CMD"
9313 numFAIL=$((numFAIL+1))
9314 listFAIL="$listFAIL $N"
9315 else
9316 $PRINTF "$OK\n"
9317 if [ -n "$debug" ]; then cat $te; fi
9318 numOK=$((numOK+1))
9319 fi
9320 fi ;; # NUMCOND, feats
9321 esac
9322 N=$((N+1))
9323  
9324  
9325 # test: there was a bug with exec:...,pty that did not kill the exec'd sub
9326 # process under some circumstances.
9327 NAME=EXECPTYKILL
9328 case "$TESTS" in
9329 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
9330 TEST="$NAME: exec:...,pty explicitely kills sub process"
9331 # we want to check if the exec'd sub process is killed in time
9332 # for this we have a shell script that generates a file after two seconds;
9333 # it should be killed after one second, so if the file was generated the test
9334 # has failed
9335 if ! eval $NUMCOND; then :; else
9336 tf="$td/test$N.stdout"
9337 te="$td/test$N.stderr"
9338 ts="$td/test$N.sock"
9339 tda="$td/test$N.data"
9340 tsh="$td/test$N.sh"
9341 tdiff="$td/test$N.diff"
9342 cat >"$tsh" <<EOF
9343 sleep $SECONDs; echo; sleep $SECONDs; touch "$tda"; echo
9344 EOF
9345 chmod a+x "$tsh"
9346 CMD1="$TRACE $SOCAT $opts -t $SECONDs -U UNIX-LISTEN:$ts,fork EXEC:$tsh,pty"
9347 CMD="$TRACE $SOCAT $opts -t $SECONDs /dev/null UNIX-CONNECT:$ts"
9348 printf "test $F_n $TEST... " $N
9349 $CMD1 2>"${te}2" &
9350 pid1=$!
9351 sleep $SECONDs
9352 waitfile $ts $SECONDs
9353 $CMD 2>>"${te}1" >>"$tf"
9354 sleep $((2*SECONDs))
9355 kill "$pid1" 2>/dev/null
9356 wait
9357 if [ $? -ne 0 ]; then
9358 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9359 echo "$CMD1 &"
9360 echo "$CMD2"
9361 cat "${te}1" "${te}2"
9362 numFAIL=$((numFAIL+1))
9363 listFAIL="$listFAIL $N"
9364 elif [ -f "$tda" ]; then
9365 $PRINTF "$FAILED\n"
9366 cat "${te}1" "${te}2"
9367 numFAIL=$((numFAIL+1))
9368 listFAIL="$listFAIL $N"
9369 else
9370 $PRINTF "$OK\n"
9371 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9372 numOK=$((numOK+1))
9373 fi
9374 fi ;; # NUMCOND
9375 esac
9376 PORT=$((PORT+1))
9377 N=$((N+1))
9378  
9379  
9380 # test if service name resolution works; this was buggy in 1.5 and 1.6.0.0
9381 NAME=TCP4SERVICE
9382 case "$TESTS" in
9383 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
9384 TEST="$NAME: echo via connection to TCP V4 socket"
9385 # select a tcp entry from /etc/services, have a server listen on the port
9386 # number and connect using the service name; with the bug, connection will to a
9387 # wrong port
9388 if ! eval $NUMCOND; then :; else
9389 tf="$td/test$N.stdout"
9390 te="$td/test$N.stderr"
9391 tdiff="$td/test$N.diff"
9392 # find a service entry we do not need root for (>=1024; here >=1100 for ease)
9393 SERVENT="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)"
9394 SERVICE="$(echo $SERVENT |cut -d' ' -f1)"
9395 _PORT="$PORT"
9396 PORT="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')"
9397 tsl="$PORT"
9398 ts="127.0.0.1:$SERVICE"
9399 da="test$N $(date) $RANDOM"
9400 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE"
9401 CMD2="$TRACE $SOCAT $opts stdout%stdin TCP4:$ts"
9402 printf "test $F_n $TEST... " $N
9403 $CMD1 >"$tf" 2>"${te}1" &
9404 pid1=$!
9405 waittcp4port $tsl 1
9406 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9407 if [ $? -ne 0 ]; then
9408 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9409 echo "$CMD1 &"
9410 cat "${te}1"
9411 echo "$CMD2"
9412 cat "${te}2"
9413 numFAIL=$((numFAIL+1))
9414 listFAIL="$listFAIL $N"
9415 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9416 $PRINTF "$FAILED\n"
9417 cat "$tdiff"
9418 numFAIL=$((numFAIL+1))
9419 listFAIL="$listFAIL $N"
9420 else
9421 $PRINTF "$OK\n"
9422 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9423 numOK=$((numOK+1))
9424 fi
9425 kill $pid1 2>/dev/null
9426 wait
9427 PORT="$_PORT"
9428 fi ;; # NUMCOND
9429 esac
9430 N=$((N+1))
9431  
9432  
9433 # test: up to socat 1.6.0.0, the highest file descriptor supported in socats
9434 # transfer engine was FOPEN_MAX-1; this usually worked fine but would fail when
9435 # socat was invoked with many file descriptors already opened. socat would
9436 # just hang in the select() call. Thanks to Daniel Lucq for reporting this
9437 # problem.
9438 # FOPEN_MAX on different OS's:
9439 # OS FOPEN_ ulimit ulimit FD_
9440 # MAX -H -n -S -n SETSIZE
9441 # Linux 2.6: 16 1024 1024 1024
9442 # HP-UX 11.11: 60 2048 2048 2048
9443 # FreeBSD: 20 11095 11095 1024
9444 # Cygwin: 20 unlimit 256 64
9445 # AIX: 32767 65534 65534
9446 # SunOS 8: 20 1024
9447 NAME=EXCEED_FOPEN_MAX
9448 case "$TESTS" in
9449 *%$N%*|*%functions%*|*%maxfds%*|*%$NAME%*)
9450 TEST="$NAME: more than FOPEN_MAX FDs in use"
9451 # this test opens a number of FDs before socat is invoked. socat will have to
9452 # allocate higher FD numbers and thus hang if it cannot handle them.
9453 if ! eval $NUMCOND; then :; else
9454 REDIR=
9455 #set -vx
9456 FOPEN_MAX=$($PROCAN -c 2>/dev/null |grep '^#define[ ][ ]*FOPEN_MAX' |awk '{print($3);}')
9457 if [ -z "$FOPEN_MAX" ]; then
9458 $PRINTF "test $F_n $TEST... ${YELLOW}could not determine FOPEN_MAX${NORMAL}\n" "$N"
9459 numCANT=$((numCANT+1))
9460 else
9461 OPEN_FILES=$FOPEN_MAX # more than the highest FOPEN_MAX
9462 i=3; while [ "$i" -lt "$OPEN_FILES" ]; do
9463 REDIR="$REDIR $i>&2"
9464 i=$((i+1))
9465 done
9466 #echo "$REDIR"
9467 #testecho "$N" "$TEST" "" "pipe" "$opts -T 3" "" 1
9468 #set -vx
9469 eval testecho "\"$N\"" "\"$TEST\"" "\"\"" "pipe" "\"$opts -T $((2*SECONDs))\"" 1 $REDIR
9470 #set +vx
9471 fi # could determine FOPEN_MAX
9472 fi ;; # NUMCOND
9473 esac
9474 N=$((N+1))
9475  
9476  
9477 # there was a bug with udp-listen and fork: terminating sub processes became
9478 # zombies because the master process did not catch SIGCHLD
9479 NAME=UDP4LISTEN_SIGCHLD
9480 case "$TESTS" in
9481 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%zombie%*|*%$NAME%*)
9482 TEST="$NAME: test if UDP4-LISTEN child becomes zombie"
9483 # idea: run a udp-listen process with fork and -T. Connect once, so a sub
9484 # process is forked off. Make some transfer and wait until the -T timeout is
9485 # over. Now check for the child process: if it is zombie the test failed.
9486 # Correct is that child process terminated
9487 if ! eval $NUMCOND; then :; else
9488 tf="$td/test$N.stdout"
9489 te="$td/test$N.stderr"
9490 tdiff="$td/test$N.diff"
9491 tsl=$PORT
9492 ts="$LOCALHOST:$tsl"
9493 da="test$N $(date) $RANDOM"
9494 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,reuseaddr,fork PIPE"
9495 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
9496 printf "test $F_n $TEST... " $N
9497 $CMD1 >"$tf" 2>"${te}1" &
9498 pid1=$!
9499 waitudp4port $tsl 1
9500 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9501 rc2=$?
9502 sleep 1
9503 #read -p ">"
9504 l="$(childprocess $pid1)"
9505 kill $pid1 2>/dev/null; wait
9506 if [ $rc2 -ne 0 ]; then
9507 $PRINTF "$NO_RESULT (client failed)\n" # already handled in test UDP4STREAM
9508 numCANT=$((numCANT+1))
9509 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9510 $PRINTF "$NO_RESULT (diff failed)\n" # already handled in test UDP4STREAM
9511 numCANT=$((numCANT+1))
9512 elif $(isdefunct "$l"); then
9513 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9514 echo "$CMD1 &"
9515 echo "$CMD2"
9516 cat "${te}1" "${te}2"
9517 numFAIL=$((numFAIL+1))
9518 listFAIL="$listFAIL $N"
9519 else
9520 $PRINTF "$OK\n"
9521 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9522 numOK=$((numOK+1))
9523 fi
9524 fi ;; # NUMCOND
9525 esac
9526 PORT=$((PORT+1))
9527 N=$((N+1))
9528 #set +vx
9529  
9530 # there was a bug with udp-recvfrom and fork: terminating sub processes became
9531 # zombies because the master process caught SIGCHLD but did not wait()
9532 NAME=UDP4RECVFROM_SIGCHLD
9533 case "$TESTS" in
9534 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%zombie%*|*%$NAME%*)
9535 TEST="$NAME: test if UDP4-RECVFROM child becomes zombie"
9536 # idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a
9537 # sub process is forked off. Make some transfer and wait until the -T timeout
9538 # is over. Now check for the child process: if it is zombie the test failed.
9539 # Correct is that child process terminated
9540 if ! eval $NUMCOND; then :; else
9541 tf="$td/test$N.stdout"
9542 te="$td/test$N.stderr"
9543 tdiff="$td/test$N.diff"
9544 tsl=$PORT
9545 ts="$LOCALHOST:$tsl"
9546 da="test$N $(date) $RANDOM"
9547 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE"
9548 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts"
9549 printf "test $F_n $TEST... " $N
9550 $CMD1 >"$tf" 2>"${te}1" &
9551 pid1=$!
9552 waitudp4port $tsl 1
9553 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9554 rc2=$?
9555 sleep 1
9556 #read -p ">"
9557 l="$(childprocess $pid1)"
9558 kill $pid1 2>/dev/null; wait
9559 if [ $rc2 -ne 0 ]; then
9560 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9561 numCANT=$((numCANT+1))
9562 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9563 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9564 numCANT=$((numCANT+1))
9565 elif $(isdefunct "$l"); then
9566 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9567 echo "$CMD1 &"
9568 echo "$CMD2"
9569 cat "${te}1" "${te}2"
9570 numFAIL=$((numFAIL+1))
9571 listFAIL="$listFAIL $N"
9572 else
9573 $PRINTF "$OK\n"
9574 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9575 numOK=$((numOK+1))
9576 fi
9577 fi ;; # NUMCOND
9578 esac
9579 PORT=$((PORT+1))
9580 N=$((N+1))
9581  
9582  
9583 # test: there was a bug with ip*-recv and bind option: it would not bind, and
9584 # with the first received packet an error:
9585 # socket_init(): unknown address family 0
9586 # occurred
9587 NAME=RAWIP4RECVBIND
9588 case "$TESTS" in
9589 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
9590 TEST="$NAME: raw IPv4 receive with bind"
9591 # idea: start a socat process with ip4-recv:...,bind=... and send it a packet
9592 # if the packet passes the test succeeded
9593 if ! eval $NUMCOND; then :;
9594 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9595 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9596 numCANT=$((numCANT+1))
9597 else
9598 tf="$td/test$N.stdout"
9599 te="$td/test$N.stderr"
9600 tdiff="$td/test$N.diff"
9601 ts1p=$PROTO; PROTO=$((PROTO+1))
9602 ts1a="127.0.0.1"
9603 ts1="$ts1a:$ts1p"
9604 da="test$N $(date) $RANDOM"
9605 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -"
9606 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
9607 printf "test $F_n $TEST... " $N
9608 $CMD1 >"$tf" 2>"${te}1" &
9609 pid1="$!"
9610 waitip4proto $ts1p 1
9611 echo "$da" |$CMD2 2>>"${te}2"
9612 rc2="$?"
9613 #ls -l $tf
9614 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9615 kill "$pid1" 2>/dev/null; wait
9616 if [ "$rc2" -ne 0 ]; then
9617 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9618 echo "$CMD1 &"
9619 echo "$CMD2"
9620 cat "${te}1"
9621 cat "${te}2"
9622 numFAIL=$((numFAIL+1))
9623 listFAIL="$listFAIL $N"
9624 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9625 $PRINTF "$FAILED\n"
9626 cat "$tdiff"
9627 numFAIL=$((numFAIL+1))
9628 listFAIL="$listFAIL $N"
9629 else
9630 $PRINTF "$OK\n"
9631 if [ -n "$debug" ]; then cat $te; fi
9632 numOK=$((numOK+1))
9633 fi
9634 fi ;; # NUMCOND, root
9635 esac
9636 PROTO=$((PROTO+1))
9637 N=$((N+1))
9638  
9639  
9640 # there was a bug in *-recvfrom with fork: due to an error in the appropriate
9641 # signal handler the master process would hang after forking off the first
9642 # child process.
9643 NAME=UDP4RECVFROM_FORK
9644 case "$TESTS" in
9645 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
9646 TEST="$NAME: test if UDP4-RECVFROM handles more than one packet"
9647 # idea: run a UDP4-RECVFROM process with fork and -T. Send it one packet;
9648 # send it a second packet and check if this is processed properly. If yes, the
9649 # test succeeded.
9650 if ! eval $NUMCOND; then :; else
9651 tf="$td/test$N.stdout"
9652 te="$td/test$N.stderr"
9653 tdiff="$td/test$N.diff"
9654 tsp=$PORT
9655 ts="$LOCALHOST:$tsp"
9656 da="test$N $(date) $RANDOM"
9657 CMD1="$TRACE $SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE"
9658 CMD2="$TRACE $SOCAT $opts -T 1 - UDP4-SENDTO:$ts"
9659 printf "test $F_n $TEST... " $N
9660 $CMD1 >/dev/null 2>"${te}1" &
9661 pid1=$!
9662 waitudp4port $tsp 1
9663 echo "$da" |$CMD2 >/dev/null 2>>"${te}2" # this should always work
9664 rc2a=$?
9665 sleep 1
9666 echo "$da" |$CMD2 >"$tf" 2>>"${te}3" # this would fail when bug
9667 rc2b=$?
9668 kill $pid1 2>/dev/null; wait
9669 if [ $rc2b -ne 0 ]; then
9670 $PRINTF "$NO_RESULT\n"
9671 numCANT=$((numCANT+1))
9672 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9673 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9674 echo "$CMD1 &"
9675 echo "$CMD2"
9676 cat "${te}1" "${te}2" "${te}3"
9677 cat "$tdiff"
9678 numFAIL=$((numFAIL+1))
9679 listFAIL="$listFAIL $N"
9680 else
9681 $PRINTF "$OK\n"
9682 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3"; fi
9683 numOK=$((numOK+1))
9684 fi
9685 fi ;; # NUMCOND
9686 esac
9687 PORT=$((PORT+1))
9688 N=$((N+1))
9689  
9690  
9691 # there was a bug in parsing the arguments of exec: consecutive spaces resulted
9692 # in additional empty arguments
9693 NAME=EXECSPACES
9694 case "$TESTS" in
9695 *%$N%*|*%functions%*|*%exec%*|*%parse%*|*%$NAME%*)
9696 TEST="$NAME: correctly parse exec with consecutive spaces"
9697 if ! eval $NUMCOND; then :; else
9698 $PRINTF "test $F_n $TEST... " $N
9699 tf="$td/test$N.stdout"
9700 te="$td/test$N.stderr"
9701 da="test$N $(date) $RANDOM" # with a double space
9702 tdiff="$td/test$N.diff"
9703 # put the test data as first argument after two spaces. expect the data in the
9704 # first argument of the exec'd command.
9705 $TRACE $SOCAT $opts -u "exec:\"bash -c \\\"echo \\\\\\\"\$1\\\\\\\"\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te"
9706 rc=$?
9707 echo "$da" |diff - "$tf" >"$tdiff"
9708 if [ "$rc" -ne 0 ]; then
9709 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9710 cat "$te"
9711 numFAIL=$((numFAIL+1))
9712 listFAIL="$listFAIL $N"
9713 elif [ -s "$tdiff" ]; then
9714 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9715 echo diff:
9716 cat "$tdiff"
9717 if [ -n "$debug" ]; then cat $te; fi
9718 numFAIL=$((numFAIL+1))
9719 listFAIL="$listFAIL $N"
9720 else
9721 $PRINTF "$OK\n"
9722 if [ -n "$debug" ]; then cat $te; fi
9723 numOK=$((numOK+1))
9724 fi
9725 fi ;; # NUMCOND
9726 esac
9727 N=$((N+1))
9728  
9729  
9730 # a bug was found in the way UDP-LISTEN handles the listening socket:
9731 # when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
9732 # range option, the old listen socket would not be closed but a new one created.
9733 NAME=UDP4LISTENCONT
9734 case "$TESTS" in
9735 *%$N%*|*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*)
9736 TEST="$NAME: let range drop a packet and see if old socket is closed"
9737 # idea: run a UDP4-LISTEN process with range option. Send it one packet from an
9738 # address outside range and check if two listening sockets are open then
9739 if ! eval $NUMCOND; then :; else
9740 tf="$td/test$N.stdout"
9741 te="$td/test$N.stderr"
9742 tdiff="$td/test$N.diff"
9743 while [ "$(netstat -an |grep "^udp.*127.0.0.1:$PORT" |wc -l)" -ne 0 ]; do
9744 PORT=$((PORT+1))
9745 done
9746 tp=$PORT
9747 da1="test$N $(date) $RANDOM"
9748 a1="$LOCALHOST"
9749 a2="$SECONDADDR"
9750 #CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
9751 CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,range=$a2/32 PIPE"
9752 CMD1="$TRACE $SOCAT $opts - UDP-CONNECT:$a1:$tp"
9753 printf "test $F_n $TEST... " $N
9754 $CMD0 >/dev/null 2>"${te}0" &
9755 pid1=$!
9756 waitudp4port $tp 1
9757 echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail
9758 rc1=$?
9759 waitudp4port $tp 1
9760 nsocks="$(netstat -an |grep "^udp.*[:.]$PORT" |wc -l)"
9761 kill $pid1 2>/dev/null; wait
9762 if [ $rc1 -ne 0 ]; then
9763 $PRINTF "$NO_RESULT\n"
9764 numCANT=$((numCANT+1))
9765 elif [ $nsocks -eq 0 ]; then
9766 $PRINTF "$NO_RESULT\n"
9767 numCANT=$((numCANT+1))
9768 elif [ $nsocks -ne 1 ]; then
9769 $PRINTF "$FAILED ($nsocks listening sockets)\n"
9770 echo "$CMD0 &"
9771 echo "$CMD1"
9772 cat "${te}0" "${te}1"
9773 numFAIL=$((numFAIL+1))
9774 listFAIL="$listFAIL $N"
9775 else
9776 $PRINTF "$OK\n"
9777 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
9778 numOK=$((numOK+1))
9779 fi
9780 fi ;; # NUMCOND
9781 esac
9782 PORT=$((PORT+1))
9783 N=$((N+1))
9784  
9785  
9786 # during wait for next poll time option ignoreeof blocked the data transfer in
9787 # the reverse direction
9788 NAME=IGNOREEOFNOBLOCK
9789 case "$TESTS" in
9790 *%$N%*|*%functions%*|*%engine%*|*%socket%*|*%ignoreeof%*|*%$NAME%*)
9791 TEST="$NAME: ignoreeof does not block other direction"
9792 # have socat poll in ignoreeof mode. while it waits one second for next check,
9793 # we send data in the reverse direction and then the total timeout fires.
9794 # it the data has passed, the test succeeded.
9795 if ! eval $NUMCOND; then :; else
9796 tf="$td/test$N.stout"
9797 te="$td/test$N.stderr"
9798 tdiff="$td/test$N.diff"
9799 da="test$N $(date) $RANDOM"
9800 CMD0="$TRACE $SOCAT $opts -%/dev/null,ignoreeof /dev/null%-"
9801 printf "test $F_n $TEST... " $N
9802 (usleep 333333; echo "$da") |$CMD0 >"$tf" 2>"${te}0"
9803 rc0=$?
9804 if [ $rc0 != 0 ]; then
9805 $PRINTF "$FAILED\n"
9806 echo "$CMD0 &"
9807 echo "$CMD1"
9808 cat "${te}0"
9809 cat "${te}1"
9810 numFAIL=$((numFAIL+1))
9811 listFAIL="$listFAIL $N"
9812 elif echo "$da" |diff - "$tf" >/dev/null; then
9813 $PRINTF "$OK\n"
9814 numOK=$((numOK+1))
9815 else
9816 $PRINTF "$FAILED\n"
9817 echo "$CMD0 &"
9818 echo "$CMD1"
9819 cat "${te}0"
9820 numFAIL=$((numFAIL+1))
9821 listFAIL="$listFAIL $N"
9822 fi
9823 fi ;; # NUMCOND
9824 esac
9825 N=$((N+1))
9826  
9827  
9828 # test the escape option
9829 NAME=ESCAPE
9830 case "$TESTS" in
9831 *%$N%*|*%functions%*|*%engine%*|*%escape%*|*%$NAME%*)
9832 TEST="$NAME: escape character triggers EOF"
9833 # idea: start socat just echoing input, but apply escape option. send a string
9834 # containing the escape character and check if the output is truncated
9835 if ! eval $NUMCOND; then :; else
9836 tf="$td/test$N.stdout"
9837 te="$td/test$N.stderr"
9838 tdiff="$td/test$N.diff"
9839 da="test$N $(date) $RANDOM"
9840 CMD="$TRACE $SOCAT $opts -,escape=26 pipe"
9841 printf "test $F_n $TEST... " $N
9842 $ECHO "$da\n\x1aXYZ" |$CMD >"$tf" 2>"$te"
9843 if [ $? -ne 0 ]; then
9844 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9845 echo "$CMD"
9846 cat "$te"
9847 numFAIL=$((numFAIL+1))
9848 listFAIL="$listFAIL $N"
9849 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9850 $PRINTF "$FAILED: diff:\n"
9851 cat "$tdiff"
9852 numFAIL=$((numFAIL+1))
9853 listFAIL="$listFAIL $N"
9854 else
9855 $PRINTF "$OK\n"
9856 if [ -n "$debug" ]; then cat $te; fi
9857 numOK=$((numOK+1))
9858 fi
9859 fi ;; # NUMCOND
9860 esac
9861 N=$((N+1))
9862  
9863 # test the escape option combined with ignoreeof
9864 NAME=ESCAPE_IGNOREEOF
9865 case "$TESTS" in
9866 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%escape%*|*%$NAME%*)
9867 TEST="$NAME: escape character triggers EOF"
9868 # idea: start socat just echoing input, but apply escape option. send a string
9869 # containing the escape character and check if the output is truncated
9870 if ! eval $NUMCOND; then :; else
9871 ti="$td/test$N.file"
9872 tf="$td/test$N.stdout"
9873 te="$td/test$N.stderr"
9874 tdiff="$td/test$N.diff"
9875 da="test$N $(date) $RANDOM"
9876 CMD="$TRACE $SOCAT -T 5 $opts -%file:$ti,ignoreeof,escape=26 pipe"
9877 printf "test $F_n $TEST... " $N
9878 >"$ti"
9879 $CMD >"$tf" 2>"$te" &
9880 $ECHO "$da\n\x1aXYZ" >>"$ti"
9881 sleep 1
9882 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9883 $PRINTF "$FAILED: diff:\n"
9884 cat "$tdiff"
9885 cat "$te"
9886 numFAIL=$((numFAIL+1))
9887 listFAIL="$listFAIL $N"
9888 else
9889 $PRINTF "$OK\n"
9890 if [ -n "$debug" ]; then cat $te; fi
9891 numOK=$((numOK+1))
9892 fi
9893 fi ;; # NUMCOND
9894 esac
9895 N=$((N+1))
9896  
9897  
9898 # test: logging of ancillary message
9899 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_TYPE SCM_NAME ROOT SCM_VALUE
9900 do
9901 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
9902 #
9903 pf="$(echo "$PF" |tr A-Z a-z)"
9904 proto="$(echo "$KEYW" |tr A-Z a-z)"
9905 NAME=${KEYW}SCM_$SCM_TYPE
9906 case "$TESTS" in
9907 *%$N%*|*%functions%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%$ROOT%*|*%$NAME%*)
9908 TEST="$NAME: $KEYW log ancillary message $SCM_TYPE $SCM_NAME"
9909 # idea: start a socat process with *-RECV:..,... , ev. with ancillary message
9910 # enabling option and send it a packet, ev. with some option. check the info log
9911 # for the appropriate output.
9912 if ! eval $NUMCOND; then :;
9913 #elif [[ "$PF" == "#*" ]]; then :
9914 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9915 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9916 numCANT=$((numCANT+1))
9917 elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null ); then
9918 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
9919 numCANT=$((numCANT+1))
9920 elif ! testoptions $SCM_RECV >/dev/null; then
9921 $PRINTF "test $F_n $TEST... ${YELLOW}option $SCM_RECV not available${NORMAL}\n" $N
9922 numCANT=$((numCANT+1))
9923 else
9924 tf="$td/test$N.stdout"
9925 te="$td/test$N.stderr"
9926 case "X$IPPORT" in
9927 "XPORT")
9928 tra="$PORT" # test recv address
9929 tsa="$ADDR:$PORT" # test sendto address
9930 PORT=$((PORT+1)) ;;
9931 "XPROTO")
9932 tra="$PROTO" # test recv address
9933 tsa="$ADDR:$PROTO" # test sendto address
9934 PROTO=$((PROTO+1)) ;;
9935 *)
9936 tra="$(eval echo "$ADDR")" # resolve $N
9937 tsa="$tra"
9938 esac
9939 CMD0="$TRACE $SOCAT $opts -d -d -d -u $KEYW-RECV:$tra,reuseaddr,$SCM_RECV -"
9940 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
9941 printf "test $F_n $TEST... " $N
9942 # is this option supported?
9943 if $TRACE $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
9944 $CMD0 >"$tf" 2>"${te}0" &
9945 pid0="$!"
9946 wait${proto}port $tra 1
9947 echo "XYZ" |$CMD1 2>"${te}1"
9948 rc1="$?"
9949 sleep 1
9950 i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9951 kill "$pid0" 2>/dev/null; wait
9952 # do not show more messages than requested
9953 case "$opts" in
9954 *-d*-d*-d*-d*) LEVELS="[EWNID]" ;;
9955 *-d*-d*-d*) LEVELS="[EWNI]" ;;
9956 *-d*-d*) LEVELS="[EWN]" ;;
9957 *-d*) LEVELS="[EW]" ;;
9958 *) LEVELS="[E]" ;;
9959 esac
9960 if [ "$SCM_VALUE" = "timestamp" ]; then
9961 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y')"
9962 fi
9963 if [ "$rc1" -ne 0 ]; then
9964 $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
9965 echo "$CMD0 &"
9966 echo "$CMD1"
9967 grep " $LEVELS " "${te}0"
9968 grep " $LEVELS " "${te}1"
9969 numCANT=$((numCANT+1))
9970 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=" ${te}0 >/dev/null; then
9971 $PRINTF "$FAILED\n"
9972 echo "variable $SCM_TYPE: $SCM_NAME not set"
9973 echo "$CMD0 &"
9974 echo "$CMD1"
9975 grep " $LEVELS " "${te}0"
9976 grep " $LEVELS " "${te}1"
9977 numFAIL=$((numFAIL+1))
9978 listFAIL="$listFAIL $N"
9979 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=$SCM_VALUE" ${te}0 >/dev/null; then
9980 $PRINTF "$FAILED\n"
9981 badval="$(grep "ancillary message: $SCM_TYPE: $SCM_NAME" ${te}0 |sed 's/.*=//g')"
9982 echo "variable $SCM_TYPE: $SCM_NAME has value \"$badval\" instead of pattern \"$SCM_VALUE\"" >&2
9983 echo "$CMD0 &"
9984 echo "$CMD1"
9985 grep " $LEVELS " "${te}0"
9986 grep " $LEVELS " "${te}1"
9987 numFAIL=$((numFAIL+1))
9988 listFAIL="$listFAIL $N"
9989 else
9990 $PRINTF "$OK\n"
9991 if [ -n "$debug" ]; then
9992 grep " $LEVELS " "${te}0"; echo; grep " $LEVELS " "${te}1";
9993 fi
9994 numOK=$((numOK+1))
9995 fi
9996 set +vx
9997 else # option is not supported
9998 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
9999 numCANT=$((numCANT+1))
10000 fi # option is not supported
10001 fi # NUMCOND, root, feats
10002 ;;
10003 esac
10004 N=$((N+1))
10005 #
10006 done <<<"
10007 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS options user x01000000
10008 IP4 UDP4 127.0.0.1 PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10009 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL ttl user 53
10010 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS tos user 7
10011 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO locaddr user 127.0.0.1
10012 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO dstaddr user 127.0.0.1
10013 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO if user lo
10014 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_RECVIF if user lo0
10015 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_RECVDSTADDR dstaddr user 127.0.0.1
10016 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS options root x01000000
10017 IP4 IP4 127.0.0.1 PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
10018 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL ttl root 53
10019 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS tos root 7
10020 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO locaddr root 127.0.0.1
10021 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO dstaddr root 127.0.0.1
10022 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO if root lo
10023 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_RECVIF if root lo0
10024 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_RECVDSTADDR dstaddr root 127.0.0.1
10025 IP6 UDP6 [::1] PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10026 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_PKTINFO dstaddr user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10027 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit user 35
10028 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass user xaa000000
10029 IP6 IP6 [::1] PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
10030 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_PKTINFO dstaddr root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10031 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit root 35
10032 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass root xaa000000
10033 #UNIX UNIX $td/test\$N.server - , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10034 "
10035 # this one fails, appearently due to a Linux weakness:
10036 # UNIX so-timestamp
10037  
10038  
10039 # test: setting of environment variables that describe a stream socket
10040 # connection: SOCAT_SOCKADDR, SOCAT_PEERADDR; and SOCAT_SOCKPORT,
10041 # SOCAT_PEERPORT when applicable
10042 while read KEYW FEAT TEST_SOCKADDR TEST_PEERADDR TEST_SOCKPORT TEST_PEERPORT; do
10043 if [ -z "$KEYW" ] || [[ "$KEYW" == \#* ]]; then continue; fi
10044 #
10045 test_proto="$(echo "$KEYW" |tr A-Z a-z)"
10046 NAME=${KEYW}LISTENENV
10047 case "$TESTS" in
10048 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$test_proto%*|*%envvar%*|*%$NAME%*)
10049 TEST="$NAME: $KEYW-LISTEN sets environment variables with socket addresses"
10050 # have a server accepting a connection and invoking some shell code. The shell
10051 # code extracts and prints the SOCAT related environment vars.
10052 # outside code then checks if the environment contains the variables correctly
10053 # describing the peer and local sockets.
10054 if ! eval $NUMCOND; then :;
10055 elif ! feat=$(testaddrs $FEAT); then
10056 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
10057 numCANT=$((numCANT+1))
10058 elif [ "$KEYW" = "TCP6" -o "$KEYW" = "UDP6" -o "$KEYW" = "SCTP6" ] && \
10059 ! runsip6 >/dev/null; then
10060 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10061 numCANT=$((numCANT+1))
10062 else
10063 tf="$td/test$N.stdout"
10064 te="$td/test$N.stderr"
10065 TEST_SOCKADDR="$(echo "$TEST_SOCKADDR" |sed "s/\$N/$N/g")" # actual vars
10066 tsa="$TEST_SOCKADDR" # test server address
10067 tsp="$TEST_SOCKPORT" # test server port
10068 if [ "$tsp" != ',' ]; then
10069 tsa1="$tsp"; tsa2="$tsa"; tsa="$tsa:$tsp" # tsa2 used for server bind=
10070 else
10071 tsa1="$tsa"; tsa2= # tsa1 used for addr parameter
10072 fi
10073 TEST_PEERADDR="$(echo "$TEST_PEERADDR" |sed "s/\$N/$N/g")" # actual vars
10074 tca="$TEST_PEERADDR" # test client address
10075 tcp="$TEST_PEERPORT" # test client port
10076 if [ "$tcp" != ',' ]; then
10077 tca="$tca:$tcp"
10078 fi
10079 #CMD0="$TRACE $SOCAT $opts -u $KEYW-LISTEN:$tsa1 system:\"export -p\""
10080 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-LISTEN:$tsa1 system:\"echo SOCAT_SOCKADDR=\\\$SOCAT_SOCKADDR; echo SOCAT_PEERADDR=\\\$SOCAT_PEERADDR; echo SOCAT_SOCKPORT=\\\$SOCAT_SOCKPORT; echo SOCAT_PEERPORT=\\\$SOCAT_PEERPORT; sleep 1\""
10081 CMD1="$TRACE $SOCAT $opts -u - $KEYW-CONNECT:$tsa,bind=$tca"
10082 printf "test $F_n $TEST... " $N
10083 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
10084 pid0=$!
10085 wait${test_proto}port $tsa1 1
10086 echo |$CMD1 2>"${te}1"
10087 rc1=$?
10088 waitfile "$tf" 2
10089 kill $pid0 2>/dev/null; wait
10090 #set -vx
10091 if [ $rc1 != 0 ]; then
10092 $PRINTF "$NO_RESULT (client failed):\n"
10093 echo "$CMD0 &"
10094 cat "${te}0"
10095 echo "$CMD1"
10096 cat "${te}1"
10097 numCANT=$((numCANT+1))
10098 elif [ "$(grep SOCAT_SOCKADDR "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")" = "$TEST_SOCKADDR" -a \
10099 "$(grep SOCAT_PEERADDR "${tf}" |sed -e 's/^[^=]*=//' -e "s/[\"']//g")" = "$TEST_PEERADDR" -a \
10100 \( "$TEST_SOCKPORT" = ',' -o "$(grep SOCAT_SOCKPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tsp" \) -a \
10101 \( "$TEST_PEERPORT" = ',' -o "$(grep SOCAT_PEERPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tcp" \) \
10102 ]; then
10103 $PRINTF "$OK\n"
10104 if [ "$debug" ]; then
10105 echo "$CMD0 &"
10106 cat "${te}0"
10107 echo "$CMD1"
10108 cat "${te}1"
10109 fi
10110 numOK=$((numOK+1))
10111 else
10112 $PRINTF "$FAILED\n"
10113 echo "$CMD0 &"
10114 cat "${te}0"
10115 echo "$CMD1"
10116 cat "${te}1"
10117 echo -e "SOCAT_SOCKADDR=$TEST_SOCKADDR\nSOCAT_PEERADDR=$TEST_PEERADDR\nSOCAT_SOCKPORT=$TEST_SOCKPORT\nSOCAT_PEERPORT=$TEST_PEERPORT" |
10118 diff - "${tf}"
10119 numFAIL=$((numFAIL+1))
10120 listFAIL="$listFAIL $N"
10121 fi
10122 fi # NUMCOND, feats
10123 ;;
10124 esac
10125 N=$((N+1))
10126 set +xv
10127 #
10128 done <<<"
10129 TCP4 TCP 127.0.0.1 $SECONDADDR $PORT $((PORT+1))
10130 TCP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+2)) $((PORT+3))
10131 UDP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+6)) $((PORT+7))
10132 SCTP4 SCTP 127.0.0.1 $SECONDADDR $((PORT+8)) $((PORT+9))
10133 SCTP6 SCTP [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+10)) $((PORT+11))
10134 UNIX UNIX $td/test\$N.server $td/test\$N.client , ,
10135 "
10136 # this one fails due to weakness in socats UDP4-LISTEN implementation:
10137 #UDP4 $LOCALHOST $SECONDADDR $((PORT+4)) $((PORT+5))
10138  
10139  
10140 # test: environment variables from ancillary message
10141 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_ENVNAME ROOT SCM_VALUE
10142 do
10143 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
10144 #
10145 pf="$(echo "$PF" |tr A-Z a-z)"
10146 proto="$(echo "$KEYW" |tr A-Z a-z)"
10147 NAME=${KEYW}ENV_$SCM_ENVNAME
10148 case "$TESTS" in
10149 *%$N%*|*%functions%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%envvar%*|*%$ROOT%*|*%$NAME%*)
10150 #set -vx
10151 TEST="$NAME: $KEYW ancillary message sets env SOCAT_$SCM_ENVNAME"
10152 # idea: start a socat process with *-RECVFROM:..,... , ev. with ancillary
10153 # message enabling option and send it a packet, ev. with some option. write
10154 # the resulting environment to a file and check its contents for the
10155 # appropriate variable.
10156 if ! eval $NUMCOND; then :;
10157 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
10158 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
10159 numCANT=$((numCANT+1))
10160 elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 ) >/dev/null; then
10161 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10162 numCANT=$((numCANT+1))
10163 else
10164 tf="$td/test$N.stdout"
10165 te="$td/test$N.stderr"
10166 case "X$IPPORT" in
10167 "XPORT")
10168 tra="$PORT" # test recv address
10169 tsa="$ADDR:$PORT" # test sendto address
10170 PORT=$((PORT+1)) ;;
10171 "XPROTO")
10172 tra="$PROTO" # test recv address
10173 tsa="$ADDR:$PROTO" # test sendto address
10174 PROTO=$((PROTO+1)) ;;
10175 *)
10176 tra="$(eval echo "$ADDR")" # resolve $N
10177 tsa="$tra"
10178 esac
10179 #CMD0="$TRACE $SOCAT $opts -u $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV system:\"export -p\""
10180 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV system:\"echo \\\$SOCAT_$SCM_ENVNAME\""
10181 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
10182 printf "test $F_n $TEST... " $N
10183 # is this option supported?
10184 if $TRACE $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
10185 eval "$CMD0 >\"$tf\" 2>\"${te}0\" &"
10186 pid0="$!"
10187 wait${proto}port $tra 1
10188 echo "XYZ" |$CMD1 2>"${te}1"
10189 rc1="$?"
10190 waitfile "$tf" 2
10191 #i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10192 kill "$pid0" 2>/dev/null; wait
10193 # do not show more messages than requested
10194 #set -vx
10195 if [ "$SCM_VALUE" = "timestamp" ]; then
10196 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
10197 fi
10198 if [ "$rc1" -ne 0 ]; then
10199 $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
10200 echo "$CMD0 &"
10201 echo "$CMD1"
10202 cat "${te}0"
10203 cat "${te}1"
10204 numCANT=$((numCANT+1))
10205 #elif ! egrep "^export SOCAT_$SCM_ENVNAME=[\"']?$SCM_VALUE[\"']?\$" ${tf} >/dev/null; then
10206 #elif ! eval echo "$SOCAT_\$SCM_VALUE" |diff - "${tf}" >/dev/null; then
10207 elif ! expr "$(cat "$tf")" : "$(eval echo "\$SCM_VALUE")" >/dev/null; then
10208 $PRINTF "$FAILED\n"
10209 echo "$CMD0 &"
10210 echo "$CMD1"
10211 cat "${te}0"
10212 cat "${te}1"
10213 numFAIL=$((numFAIL+1))
10214 listFAIL="$listFAIL $N"
10215 else
10216 $PRINTF "$OK\n"
10217 if [ -n "$debug" ]; then
10218 cat "${te}0"; echo; cat "${te}1";
10219 fi
10220 numOK=$((numOK+1))
10221 fi
10222 set +vx
10223 else # option is not supported
10224 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
10225 numCANT=$((numCANT+1))
10226 fi # option is not supported
10227 fi ;; # NUMCOND, feats
10228 esac
10229 N=$((N+1))
10230 #
10231 done <<<"
10232 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS user x01000000
10233 IP4 UDP4 127.0.0.1 PORT , so-timestamp TIMESTAMP user timestamp
10234 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL user 53
10235 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS user 7
10236 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_LOCADDR user 127.0.0.1
10237 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_DSTADDR user 127.0.0.1
10238 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_IF user lo
10239 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_IF user lo0
10240 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_DSTADDR user 127.0.0.1
10241 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS root x01000000
10242 IP4 IP4 127.0.0.1 PROTO , so-timestamp TIMESTAMP root timestamp
10243 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL root 53
10244 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS root 7
10245 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_LOCADDR root 127.0.0.1
10246 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_DSTADDR root 127.0.0.1
10247 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_IF root lo
10248 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_IF root lo0
10249 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_DSTADDR root 127.0.0.1
10250 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_DSTADDR user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10251 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT user 35
10252 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS user xaa000000
10253 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_DSTADDR root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10254 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT root 35
10255 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS root xaa000000
10256 #UNIX UNIX $td/test\$N.server - , so-timestamp TIMESTAMP user timestamp
10257 "
10258  
10259  
10260 # test the SOCKET-CONNECT address (against TCP4-LISTEN)
10261 NAME=SOCKET_CONNECT_TCP4
10262 case "$TESTS" in
10263 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10264 TEST="$NAME: socket connect with TCP/IPv4"
10265 # start a TCP4-LISTEN process that echoes data, and send test data using
10266 # SOCKET-CONNECT, selecting TCP/IPv4. The sent data should be returned.
10267 if ! eval $NUMCOND; then :; else
10268 tf="$td/test$N.stdout"
10269 te="$td/test$N.stderr"
10270 tdiff="$td/test$N.diff"
10271 ts0p=$PORT; PORT=$((PORT+1))
10272 ts0a="127.0.0.1"
10273 ts1p=$(printf "%04x" $ts0p);
10274 ts1a="7f000001" # "127.0.0.1"
10275 ts1="x${ts1p}${ts1a}x0000000000000000"
10276 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10277 da="test$N $(date) $RANDOM"
10278 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$ts0p,reuseaddr,bind=$ts0a PIPE"
10279 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:2:6:$ts1,bind=x${ts1b}00000000x0000000000000000"
10280 printf "test $F_n $TEST... " $N
10281 $CMD0 2>"${te}0" &
10282 pid0="$!"
10283 waittcp4port $ts0p 1
10284 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10285 rc1="$?"
10286 kill "$pid0" 2>/dev/null; wait;
10287 if [ "$rc1" -ne 0 ]; then
10288 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10289 echo "$CMD0 &"
10290 cat "${te}0"
10291 echo "$CMD1"
10292 cat "${te}1"
10293 numFAIL=$((numFAIL+1))
10294 listFAIL="$listFAIL $N"
10295 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10296 $PRINTF "$FAILED\n"
10297 cat "$tdiff"
10298 echo "$CMD0 &"
10299 cat "${te}0"
10300 echo "$CMD1"
10301 cat "${te}1"
10302 numFAIL=$((numFAIL+1))
10303 listFAIL="$listFAIL $N"
10304 else
10305 $PRINTF "$OK\n"
10306 if [ -n "$debug" ]; then cat $te; fi
10307 numOK=$((numOK+1))
10308 fi
10309 fi # NUMCOND
10310 ;;
10311 esac
10312 PORT=$((PORT+1))
10313 N=$((N+1))
10314  
10315 PF_INET6="$($PROCAN -c |grep "^#define[[:space:]]*PF_INET6[[:space:]]" |cut -d' ' -f3)"
10316  
10317 # test the SOCKET-CONNECT address (against TCP6-LISTEN)
10318 NAME=SOCKET_CONNECT_TCP6
10319 case "$TESTS" in
10320 *%$N%*|*%functions%*|*%generic%*|*%tcp6%*|*%socket%*|*%$NAME%*)
10321 TEST="$NAME: socket connect with TCP/IPv6"
10322 if ! eval $NUMCOND; then :;
10323 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
10324 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
10325 numCANT=$((numCANT+1))
10326 else
10327 # start a TCP6-LISTEN process that echoes data, and send test data using
10328 # SOCKET-CONNECT, selecting TCP/IPv6. The sent data should be returned.
10329 tf="$td/test$N.stdout"
10330 te="$td/test$N.stderr"
10331 tdiff="$td/test$N.diff"
10332 ts0p=$PORT; PORT=$((PORT+1))
10333 ts0a="[::1]"
10334 ts1p=$(printf "%04x" $ts0p);
10335 ts1a="00000000000000000000000000000001" # "[::1]"
10336 ts1="x${ts1p}x00000000x${ts1a}x00000000"
10337 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10338 da="test$N $(date) $RANDOM"
10339 CMD0="$TRACE $SOCAT $opts TCP6-LISTEN:$ts0p,reuseaddr,bind=$ts0a PIPE"
10340 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:$PF_INET6:6:$ts1,bind=x${ts1b}x00000000x00000000000000000000000000000000x00000000"
10341 printf "test $F_n $TEST... " $N
10342 $CMD0 2>"${te}0" &
10343 pid0="$!"
10344 waittcp6port $ts0p 1
10345 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10346 rc1="$?"
10347 kill "$pid0" 2>/dev/null; wait;
10348 if [ "$rc1" -ne 0 ]; then
10349 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10350 echo "$CMD0 &"
10351 cat "${te}0"
10352 echo "$CMD1"
10353 cat "${te}1"
10354 numFAIL=$((numFAIL+1))
10355 listFAIL="$listFAIL $N"
10356 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10357 $PRINTF "$FAILED\n"
10358 cat "$tdiff"
10359 echo "$CMD0 &"
10360 cat "${te}0"
10361 echo "$CMD1"
10362 cat "${te}1"
10363 numFAIL=$((numFAIL+1))
10364 listFAIL="$listFAIL $N"
10365 else
10366 $PRINTF "$OK\n"
10367 if [ -n "$debug" ]; then cat $te; fi
10368 numOK=$((numOK+1))
10369 fi
10370 fi ;; # NUMCOND
10371 esac
10372 PORT=$((PORT+1))
10373 N=$((N+1))
10374  
10375 # test the SOCKET-CONNECT address (against UNIX-LISTEN)
10376 NAME=SOCKET_CONNECT_UNIX
10377 case "$TESTS" in
10378 *%$N%*|*%functions%*|*%generic%*|*%unix%*|*%socket%*|*%$NAME%*)
10379 TEST="$NAME: socket connect with UNIX domain"
10380 # start a UNIX-LISTEN process that echoes data, and send test data using
10381 # SOCKET-CONNECT, selecting UNIX socket. The sent data should be returned.
10382 if ! eval $NUMCOND; then :; else
10383 tf="$td/test$N.stdout"
10384 te="$td/test$N.stderr"
10385 tdiff="$td/test$N.diff"
10386 ts0="$td/test$N.server"
10387 ts1="$td/test$N.client"
10388 da="test$N $(date) $RANDOM"
10389 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts0,reuseaddr PIPE"
10390 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:1:0:\\\"$ts0\\\0\\\",bind=\\\"$ts1\\\0\\\""
10391 printf "test $F_n $TEST... " $N
10392 $CMD0 2>"${te}0" &
10393 pid0="$!"
10394 waitfile $ts0 1
10395 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10396 rc1="$?"
10397 kill "$pid0" 2>/dev/null; wait;
10398 if [ "$rc1" -ne 0 ]; then
10399 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10400 echo "$CMD0 &"
10401 cat "${te}0"
10402 echo "$CMD1"
10403 cat "${te}1"
10404 numFAIL=$((numFAIL+1))
10405 listFAIL="$listFAIL $N"
10406 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10407 $PRINTF "$FAILED\n"
10408 cat "$tdiff"
10409 echo "$CMD0 &"
10410 cat "${te}0"
10411 echo "$CMD1"
10412 cat "${te}1"
10413 numFAIL=$((numFAIL+1))
10414 listFAIL="$listFAIL $N"
10415 else
10416 $PRINTF "$OK\n"
10417 if [ -n "$debug" ]; then cat $te; fi
10418 numOK=$((numOK+1))
10419 fi
10420 fi ;; # NUMCOND
10421 esac
10422 N=$((N+1))
10423  
10424 # test the SOCKET-LISTEN address (with TCP4-CONNECT)
10425 NAME=SOCKET_LISTEN
10426 case "$TESTS" in
10427 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10428 TEST="$NAME: socket recvfrom with TCP/IPv4"
10429 # start a SOCKET-LISTEN process that uses TCP/IPv4 and echoes data, and
10430 # send test data using TCP4-CONNECT. The sent data should be returned.
10431 if ! eval $NUMCOND; then :; else
10432 tf="$td/test$N.stdout"
10433 te="$td/test$N.stderr"
10434 tdiff="$td/test$N.diff"
10435 ts1p=$PORT; PORT=$((PORT+1))
10436 ts1a="127.0.0.1"
10437 ts0p=$(printf "%04x" $ts1p);
10438 ts0a="7f000001" # "127.0.0.1"
10439 ts0="x${ts0p}${ts0a}x0000000000000000"
10440 ts1b=$PORT; PORT=$((PORT+1))
10441 ts1="$ts1a:$ts1p"
10442 da="test$N $(date) $RANDOM"
10443 CMD0="$TRACE $SOCAT $opts SOCKET-LISTEN:2:6:$ts0,reuseaddr PIPE"
10444 CMD1="$TRACE $SOCAT $opts - TCP4-CONNECT:$ts1,bind=:$ts1b"
10445 printf "test $F_n $TEST... " $N
10446 $CMD0 2>"${te}0" &
10447 pid0="$!"
10448 #sleep 1
10449 waittcp4port $ts1p 1
10450 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10451 rc1="$?"
10452 kill "$pid0" 2>/dev/null; wait;
10453 if [ "$rc1" -ne 0 ]; then
10454 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10455 echo "$CMD0 &"
10456 cat "${te}0"
10457 echo "$CMD1"
10458 cat "${te}1"
10459 numFAIL=$((numFAIL+1))
10460 listFAIL="$listFAIL $N"
10461 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10462 $PRINTF "$FAILED\n"
10463 cat "$tdiff"
10464 echo "$CMD0 &"
10465 cat "${te}0"
10466 echo "$CMD1"
10467 cat "${te}1"
10468 numFAIL=$((numFAIL+1))
10469 listFAIL="$listFAIL $N"
10470 else
10471 $PRINTF "$OK\n"
10472 if [ -n "$debug" ]; then cat $te; fi
10473 numOK=$((numOK+1))
10474 fi
10475 fi ;; # NUMCOND
10476 esac
10477 PORT=$((PORT+1))
10478 N=$((N+1))
10479  
10480 SOCK_DGRAM="$($PROCAN -c |grep "^#define[[:space:]]*SOCK_DGRAM[[:space:]]" |cut -d' ' -f3)"
10481  
10482 # test the SOCKET-SENDTO address (against UDP4-RECVFROM)
10483 NAME=SOCKET_SENDTO
10484 case "$TESTS" in
10485 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10486 TEST="$NAME: socket sendto with UDP/IPv4"
10487 # start a UDP4-RECVFROM process that echoes data, and send test data using
10488 # SOCKET-SENDTO, selecting UDP/IPv4. The sent data should be returned.
10489 if ! eval $NUMCOND; then :; else
10490 tf="$td/test$N.stdout"
10491 te="$td/test$N.stderr"
10492 tdiff="$td/test$N.diff"
10493 ts0p=$PORT; PORT=$((PORT+1))
10494 ts0a="127.0.0.1"
10495 ts1p=$(printf "%04x" $ts0p);
10496 ts1a="7f000001" # "127.0.0.1"
10497 ts1="x${ts1p}${ts1a}x0000000000000000"
10498 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10499 da="test$N $(date) $RANDOM"
10500 CMD0="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts0p,reuseaddr,bind=$ts0a PIPE"
10501 CMD1="$TRACE $SOCAT $opts - SOCKET-SENDTO:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10502 printf "test $F_n $TEST... " $N
10503 $CMD0 2>"${te}0" &
10504 pid0="$!"
10505 waitudp4port $ts0p 1
10506 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10507 rc1="$?"
10508 kill "$pid0" 2>/dev/null; wait;
10509 if [ "$rc1" -ne 0 ]; then
10510 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10511 echo "$CMD0 &"
10512 cat "${te}0"
10513 echo "$CMD1"
10514 cat "${te}1"
10515 numFAIL=$((numFAIL+1))
10516 listFAIL="$listFAIL $N"
10517 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10518 $PRINTF "$FAILED\n"
10519 cat "$tdiff"
10520 echo "$CMD0 &"
10521 cat "${te}0"
10522 echo "$CMD1"
10523 cat "${te}1"
10524 numFAIL=$((numFAIL+1))
10525 listFAIL="$listFAIL $N"
10526 else
10527 $PRINTF "$OK\n"
10528 if [ -n "$debug" ]; then cat $te; fi
10529 numOK=$((numOK+1))
10530 fi
10531 fi ;; # NUMCOND
10532 esac
10533 PORT=$((PORT+1))
10534 N=$((N+1))
10535  
10536 # test the SOCKET-RECVFROM address (with UDP4-SENDTO)
10537 NAME=SOCKET_RECVFROM
10538 case "$TESTS" in
10539 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10540 TEST="$NAME: socket recvfrom with UDP/IPv4"
10541 # start a SOCKET-RECVFROM process that uses UDP/IPv4 and echoes data, and
10542 # send test data using UDP4-SENDTO. The sent data should be returned.
10543 if ! eval $NUMCOND; then :; else
10544 tf="$td/test$N.stdout"
10545 te="$td/test$N.stderr"
10546 tdiff="$td/test$N.diff"
10547 ts1p=$PORT; PORT=$((PORT+1))
10548 ts1a="127.0.0.1"
10549 ts0p=$(printf "%04x" $ts1p);
10550 ts0a="7f000001" # "127.0.0.1"
10551 ts0="x${ts0p}${ts0a}x0000000000000000"
10552 ts1b=$PORT; PORT=$((PORT+1))
10553 ts1="$ts1a:$ts1p"
10554 da="test$N $(date) $RANDOM"
10555 CMD0="$TRACE $SOCAT $opts SOCKET-RECVFROM:2:$SOCK_DGRAM:17:$ts0,reuseaddr PIPE"
10556 CMD1="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=:$ts1b"
10557 printf "test $F_n $TEST... " $N
10558 $CMD0 2>"${te}0" &
10559 pid0="$!"
10560 sleep 1 # waitudp4port $ts1p 1
10561 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10562 rc1="$?"
10563 kill "$pid0" 2>/dev/null; wait;
10564 if [ "$rc1" -ne 0 ]; then
10565 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10566 echo "$CMD0 &"
10567 cat "${te}0"
10568 echo "$CMD1"
10569 cat "${te}1"
10570 numFAIL=$((numFAIL+1))
10571 listFAIL="$listFAIL $N"
10572 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10573 $PRINTF "$FAILED\n"
10574 cat "$tdiff"
10575 echo "$CMD0 &"
10576 cat "${te}0"
10577 echo "$CMD1"
10578 cat "${te}1"
10579 numFAIL=$((numFAIL+1))
10580 listFAIL="$listFAIL $N"
10581 else
10582 $PRINTF "$OK\n"
10583 if [ -n "$debug" ]; then cat $te; fi
10584 numOK=$((numOK+1))
10585 fi
10586 fi ;; # NUMCOND
10587 esac
10588 PORT=$((PORT+1))
10589 N=$((N+1))
10590  
10591  
10592 # test the SOCKET-RECV address (with UDP4-SENDTO)
10593 NAME=SOCKET_RECV
10594 case "$TESTS" in
10595 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10596 TEST="$NAME: socket recv with UDP/IPv4"
10597 # start a SOCKET-RECV process that uses UPD/IPv4 and writes received data to file, and
10598 # send test data using UDP4-SENDTO.
10599 if ! eval $NUMCOND; then :; else
10600 tf="$td/test$N.stdout"
10601 te="$td/test$N.stderr"
10602 tdiff="$td/test$N.diff"
10603 ts1p=$PORT; PORT=$((PORT+1))
10604 ts1a="127.0.0.1"
10605 ts0p=$(printf "%04x" $ts1p);
10606 ts0a="7f000001" # "127.0.0.1"
10607 ts0="x${ts0p}${ts0a}x0000000000000000"
10608 ts1b=$PORT; PORT=$((PORT+1))
10609 ts1="$ts1a:$ts1p"
10610 da="test$N $(date) $RANDOM"
10611 CMD0="$TRACE $SOCAT $opts -u SOCKET-RECV:2:$SOCK_DGRAM:17:$ts0,reuseaddr -"
10612 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1,bind=:$ts1b"
10613 printf "test $F_n $TEST... " $N
10614 $CMD0 2>"${te}0" >"$tf" &
10615 pid0="$!"
10616 sleep 1 # waitudp4port $ts1p 1
10617 echo "$da" |$CMD1 2>>"${te}1"
10618 rc1="$?"
10619 sleep 1
10620 kill "$pid0" 2>/dev/null; wait;
10621 if [ "$rc1" -ne 0 ]; then
10622 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10623 echo "$CMD0 &"
10624 cat "${te}0"
10625 echo "$CMD1"
10626 cat "${te}1"
10627 numFAIL=$((numFAIL+1))
10628 listFAIL="$listFAIL $N"
10629 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10630 $PRINTF "$FAILED\n"
10631 cat "$tdiff"
10632 echo "$CMD0 &"
10633 cat "${te}0"
10634 echo "$CMD1"
10635 cat "${te}1"
10636 numFAIL=$((numFAIL+1))
10637 listFAIL="$listFAIL $N"
10638 else
10639 $PRINTF "$OK\n"
10640 if [ -n "$debug" ]; then cat $te; fi
10641 numOK=$((numOK+1))
10642 fi
10643 fi ;; # NUMCOND
10644 esac
10645 PORT=$((PORT+1))
10646 N=$((N+1))
10647  
10648 # test SOCKET-DATAGRAM (with UDP4-DATAGRAM)
10649 NAME=SOCKET_DATAGRAM
10650 case "$TESTS" in
10651 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10652 TEST="$NAME: socket datagram via UDP/IPv4"
10653 # start a UDP4-DATAGRAM process that echoes data, and send test data using
10654 # SOCKET-DATAGRAM, selecting UDP/IPv4. The sent data should be returned.
10655 if ! eval $NUMCOND; then :; else
10656 tf="$td/test$N.stdout"
10657 te="$td/test$N.stderr"
10658 tdiff="$td/test$N.diff"
10659 ts0p=$PORT; PORT=$((PORT+1))
10660 ts1p=$PORT; PORT=$((PORT+1))
10661 ts0a="127.0.0.1"
10662 ts1b=$(printf "%04x" $ts0p);
10663 ts1a="7f000001" # "127.0.0.1"
10664 ts0b=$(printf "%04x" $ts0p)
10665 ts1b=$(printf "%04x" $ts1p)
10666 ts1="x${ts0b}${ts1a}x0000000000000000"
10667 da="test$N $(date) $RANDOM"
10668 CMD0="$TRACE $SOCAT $opts UDP4-DATAGRAM:$ts0a:$ts1p,bind=:$ts0p,reuseaddr PIPE"
10669 CMD1="$TRACE $SOCAT $opts - SOCKET-DATAGRAM:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10670 printf "test $F_n $TEST... " $N
10671 $CMD0 2>"${te}0" &
10672 pid0="$!"
10673 waitudp4port $ts0p 1
10674 echo "$da" |$CMD1 2>>"${te}1" >"$tf"
10675 rc1="$?"
10676 kill "$pid0" 2>/dev/null; wait;
10677 if [ "$rc1" -ne 0 ]; then
10678 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10679 echo "$CMD0 &"
10680 cat "${te}0"
10681 echo "$CMD1"
10682 cat "${te}1"
10683 numFAIL=$((numFAIL+1))
10684 listFAIL="$listFAIL $N"
10685 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10686 $PRINTF "$FAILED\n"
10687 cat "$tdiff"
10688 echo "$CMD0 &"
10689 cat "${te}0"
10690 echo "$CMD1"
10691 cat "${te}1"
10692 numFAIL=$((numFAIL+1))
10693 listFAIL="$listFAIL $N"
10694 else
10695 $PRINTF "$OK\n"
10696 if [ -n "$debug" ]; then cat $te; fi
10697 numOK=$((numOK+1))
10698 fi
10699 fi ;; # NUMCOND
10700 esac
10701 PORT=$((PORT+1))
10702 N=$((N+1))
10703  
10704 NAME=SOCKETRANGEMASK
10705 case "$TESTS" in
10706 *%$N%*|*%functions%*|*%security%*|*%generic%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%socket%*|*%range%*|*%$NAME%*)
10707 TEST="$NAME: security of generic socket-listen with RANGE option"
10708 if ! eval $NUMCOND; then :;
10709 elif [ -z "$SECONDADDR" ]; then
10710 # we need access to more loopback addresses
10711 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
10712 numCANT=$((numCANT+1))
10713 else
10714 ts1p=$(printf "%04x" $PORT);
10715 testserversec "$N" "$TEST" "$opts -s" "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
10716 fi ;; # NUMCOND, $SECONDADDR
10717 esac
10718 PORT=$((PORT+1))
10719 N=$((N+1))
10720  
10721  
10722 TIOCEXCL="$($PROCAN -c |grep "^#define[[:space:]]*TIOCEXCL[[:space:]]" |cut -d' ' -f3)"
10723  
10724 # test the generic ioctl-void option
10725 NAME=IOCTL_VOID
10726 case "$TESTS" in
10727 *%$N%*|*%functions%*|*%pty%*|*%generic%*|*%$NAME%*)
10728 TEST="$NAME: test the ioctl-void option"
10729 # there are not many ioctls that apply to non global resources and do not
10730 # require root. TIOCEXCL seems to fit:
10731 # process 0 provides a pty;
10732 # process 1 opens it with the TIOCEXCL ioctl;
10733 # process 2 opens it too and fails with "device or resource busy" only when the
10734 # previous ioctl was successful
10735 if ! eval $NUMCOND; then :;
10736 elif [ -z "$TIOCEXCL" ]; then
10737 # we use the numeric value of TIOCEXL which is system dependent
10738 $PRINTF "test $F_n $TEST... ${YELLOW}no value of TIOCEXCL${NORMAL}\n" $N
10739 numCANT=$((numCANT+1))
10740 else
10741 tp="$td/test$N.pty"
10742 tf="$td/test$N.stdout"
10743 te="$td/test$N.stderr"
10744 tdiff="$td/test$N.diff"
10745 da="test$N $(date) $RANDOM"
10746 CMD0="$TRACE $SOCAT $opts PTY,LINK=$tp pipe"
10747 CMD1="$TRACE $SOCAT $opts - file:$tp,ioctl-void=$TIOCEXCL,raw,echo=0"
10748 CMD2="$TRACE $SOCAT $opts - file:$tp,raw,echo=0"
10749 printf "test $F_n $TEST... " $N
10750 $CMD0 >/dev/null 2>"${te}0" &
10751 pid0=$!
10752 waitfile $tp 1
10753 (echo "$da"; sleep 2) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
10754 pid1=$!
10755 usleep 1000000
10756 $CMD2 >/dev/null 2>"${te}2" </dev/null
10757 rc2=$?
10758 kill $pid0 $pid1 2>/dev/null; wait
10759 if ! echo "$da" |diff - "$tf" >/dev/null; then
10760 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10761 echo "$CMD0 &"
10762 echo "$CMD1"
10763 echo "$da" |diff - "$tf"
10764 numCANT=$((numCANT+1))
10765 elif [ $rc2 -eq 0 ]; then
10766 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10767 echo "$CMD0 &"
10768 echo "$CMD1"
10769 echo "$CMD2"
10770 cat "${te}0" "${te}1" "${te}2"
10771 numFAIL=$((numFAIL+1))
10772 listFAIL="$listFAIL $N"
10773 else
10774 $PRINTF "$OK\n"
10775 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
10776 numOK=$((numOK+1))
10777 fi
10778 fi # NUMCOND, TIOCEXCL
10779 ;;
10780 esac
10781 N=$((N+1))
10782  
10783  
10784 SOL_SOCKET="$($PROCAN -c |grep "^#define[[:space:]]*SOL_SOCKET[[:space:]]" |cut -d' ' -f3)"
10785 SO_REUSEADDR="$($PROCAN -c |grep "^#define[[:space:]]*SO_REUSEADDR[[:space:]]" |cut -d' ' -f3)"
10786  
10787 # test the generic setsockopt-int option
10788 if false; then
10789 # this test no longer works due to fix for options on listening sockets
10790 NAME=SETSOCKOPT_INT
10791 case "$TESTS" in
10792 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%generic%*|*%$NAME%*)
10793 TEST="$NAME: test the setsockopt-int option"
10794 # there are not many socket options that apply to non global resources, do not
10795 # require root, do not require a network connection, and can easily be
10796 # tested. SO_REUSEADDR seems to fit:
10797 # process 0 provides a tcp listening socket with reuseaddr;
10798 # process 1 connects to this port; thus the port is connected but no longer
10799 # listening
10800 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
10801 # (generically specified) SO_REUSEADDR socket options did not work
10802 # process 3 connects to this port; only if it is successful the test is ok
10803 if ! eval $NUMCOND; then :;
10804 elif [ -z "SO_REUSEADDR" ]; then
10805 # we use the numeric value of SO_REUSEADDR which might be system dependent
10806 $PRINTF "test $F_n $TEST... ${YELLOW}value of SO_REUSEADDR not known${NORMAL}\n" $N
10807 numCANT=$((numCANT+1))
10808 else
10809 tp="$PORT"
10810 tf="$td/test$N.stdout"
10811 te="$td/test$N.stderr"
10812 tdiff="$td/test$N.diff"
10813 da="test$N $(date) $RANDOM"
10814 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,setsockopt-int=$SOL_SOCKET:$SO_REUSEADDR:1 PIPE"
10815 CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
10816 CMD2="$CMD0"
10817 CMD3="$CMD1"
10818 printf "test $F_n $TEST... " $N
10819 $CMD0 >/dev/null 2>"${te}0" &
10820 pid0=$!
10821 waittcp4port $tp 1
10822 (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
10823 pid1=$!
10824 usleep 1000000
10825 $CMD2 >/dev/null 2>"${te}2" &
10826 pid2=$!
10827 waittcp4port $tp 1
10828 (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
10829 rc3=$?
10830 kill $pid0 $pid1 $pid2 2>/dev/null; wait
10831 if ! echo "$da" |diff - "$tf"; then
10832 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10833 echo "$CMD0 &"
10834 echo "$CMD1"
10835 numCANT=$((numCANT+1))
10836 elif [ $rc3 -ne 0 ]; then
10837 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10838 echo "$CMD2 &"
10839 echo "$CMD3"
10840 cat "${te}2" "${te}3"
10841 numFAIL=$((numFAIL+1))
10842 listFAIL="$listFAIL $N"
10843 elif ! echo "$da" |diff - "${tf}3"; then
10844 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10845 echo "$CMD2 &"
10846 echo "$CMD3"
10847 echo "$da" |diff - "${tf}3"
10848 numCANT=$((numCANT+1))
10849 else
10850 $PRINTF "$OK\n"
10851 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
10852 numOK=$((numOK+1))
10853 fi
10854 fi # NUMCOND, SO_REUSEADDR
10855 ;;
10856 esac
10857 PORT=$((PORT+1))
10858 N=$((N+1))
10859 #
10860 fi
10861  
10862  
10863 NAME=SCTP4STREAM
10864 case "$TESTS" in
10865 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
10866 TEST="$NAME: echo via connection to SCTP V4 socket"
10867 PORT="$((PORT+1))"
10868 if ! eval $NUMCOND; then :;
10869 elif ! testaddrs sctp ip4 >/dev/null || ! runsip4 >/dev/null || ! runssctp4 "$((PORT-1))" >/dev/null; then
10870 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
10871 numCANT=$((numCANT+1))
10872 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
10873 # RHEL5 based systems became unusable when an sctp socket was created but
10874 # module sctp not loaded
10875 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10876 numCANT=$((numCANT+1))
10877 else
10878 tf="$td/test$N.stdout"
10879 te="$td/test$N.stderr"
10880 tdiff="$td/test$N.diff"
10881 tsl=$PORT
10882 ts="127.0.0.1:$tsl"
10883 da=$(date)
10884 CMD1="$TRACE $SOCAT $opts SCTP4-LISTEN:$tsl,reuseaddr PIPE"
10885 CMD2="$TRACE $SOCAT $opts stdout%stdin SCTP4:$ts"
10886 printf "test $F_n $TEST... " $N
10887 $CMD1 >"$tf" 2>"${te}1" &
10888 pid1=$!
10889 waitsctp4port $tsl 1
10890 # SCTP does not seem to support half close, so we give it 1s to finish
10891 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
10892 if [ $? -ne 0 ]; then
10893 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10894 echo "$CMD1 &"
10895 cat "${te}1"
10896 echo "$CMD2"
10897 cat "${te}2"
10898 numFAIL=$((numFAIL+1))
10899 listFAIL="$listFAIL $N"
10900 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10901 $PRINTF "$FAILED\n"
10902 cat "$tdiff"
10903 numFAIL=$((numFAIL+1))
10904 listFAIL="$listFAIL $N"
10905 else
10906 $PRINTF "$OK\n"
10907 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10908 numOK=$((numOK+1))
10909 fi
10910 kill $pid1 2>/dev/null
10911 wait
10912 fi # NUMCOND, feats
10913 ;;
10914 esac
10915 PORT=$((PORT+1))
10916 N=$((N+1))
10917  
10918 NAME=SCTP6STREAM
10919 case "$TESTS" in
10920 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
10921 TEST="$NAME: echo via connection to SCTP V6 socket"
10922 PORT="$((PORT+1))"
10923 if ! eval $NUMCOND; then :;
10924 elif ! testaddrs sctp ip6 >/dev/null || ! runsip6 >/dev/null || ! runssctp6 "$((PORT-1))" >/dev/null; then
10925 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP6 not available${NORMAL}\n" $N
10926 numCANT=$((numCANT+1))
10927 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
10928 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10929 numCANT=$((numCANT+1))
10930 else
10931 tf="$td/test$N.stdout"
10932 te="$td/test$N.stderr"
10933 tdiff="$td/test$N.diff"
10934 tsl=$PORT
10935 ts="[::1]:$tsl"
10936 da=$(date)
10937 CMD1="$TRACE $SOCAT $opts SCTP6-listen:$tsl,reuseaddr PIPE"
10938 CMD2="$TRACE $SOCAT $opts stdout%stdin SCTP6:$ts"
10939 printf "test $F_n $TEST... " $N
10940 $CMD1 >"$tf" 2>"${te}1" &
10941 pid=$! # background process id
10942 waitsctp6port $tsl 1
10943 # SCTP does not seem to support half close, so we give it 1s to finish
10944 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
10945 if [ $? -ne 0 ]; then
10946 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10947 echo "$CMD1 &"
10948 cat "${te}1"
10949 echo "$CMD2"
10950 cat "${te}2"
10951 numFAIL=$((numFAIL+1))
10952 listFAIL="$listFAIL $N"
10953 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10954 $PRINTF "$FAILED: diff:\n"
10955 cat "$tdiff"
10956 numFAIL=$((numFAIL+1))
10957 listFAIL="$listFAIL $N"
10958 else
10959 $PRINTF "$OK\n"
10960 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10961 numOK=$((numOK+1))
10962 fi
10963 kill $pid 2>/dev/null
10964 fi # NUMCOND, feats
10965 ;;
10966 esac
10967 PORT=$((PORT+1))
10968 N=$((N+1))
10969  
10970  
10971 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
10972 # performed a renegotiation. Test if this is fixed.
10973 NAME=OPENSSLRENEG1
10974 case "$TESTS" in
10975 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
10976 TEST="$NAME: OpenSSL connections survive renogotiation"
10977 # connect with s_client to socat ssl-l; force a renog, then transfer data. When
10978 # data is passed the test succeeded
10979 if ! eval $NUMCOND; then :; else
10980 tf="$td/test$N.stdout"
10981 te="$td/test$N.stderr"
10982 tdiff="$td/test$N.diff"
10983 da="test$N $(date) $RANDOM"
10984 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
10985 CMD1="openssl s_client -port $PORT -verify 0"
10986 printf "test $F_n $TEST... " $N
10987 $CMD0 >/dev/null 2>"${te}0" &
10988 pid0=$!
10989 waittcp4port $PORT 1
10990 (echo "R"; sleep 1; echo "$da"; sleep 1) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
10991 rc1=$?
10992 kill $pid0 2>/dev/null; wait
10993 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
10994 $PRINTF "$OK\n"
10995 numOK=$((numOK+1))
10996 else
10997 $PRINTF "$FAILED\n"
10998 echo "$CMD0 &"
10999 echo "$CMD1"
11000 cat "${te}0"
11001 # cat "${te}1"
11002 cat "$tdiff"
11003 numFAIL=$((numFAIL+1))
11004 listFAIL="$listFAIL $N"
11005 fi
11006 fi # NUMCOND
11007 ;;
11008 esac
11009 N=$((N+1))
11010  
11011  
11012 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
11013 # performed a renegotiation. The first temporary fix to this problem might
11014 # leave socat in a blocking ssl-read state. Test if this has been fixed.
11015 NAME=OPENSSLRENEG2
11016 case "$TESTS" in
11017 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
11018 TEST="$NAME: OpenSSL connections do not block after renogotiation"
11019 # connect with s_client to socat ssl-l; force a renog, then transfer data from
11020 # socat to the peer. When data is passed this means that the former ssl read no
11021 # longer blocks and the test succeeds
11022 if ! eval $NUMCOND; then :; else
11023 tf="$td/test$N.stdout"
11024 te="$td/test$N.stderr"
11025 tdiff="$td/test$N.diff"
11026 da="test$N $(date) $RANDOM"
11027 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
11028 CMD1="openssl s_client -port $PORT -verify 0"
11029 printf "test $F_n $TEST... " $N
11030 eval "$CMD0 >/dev/null 2>\"${te}0\" &"
11031 pid0=$!
11032 waittcp4port $PORT 1
11033 (echo "R"; sleep 2) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
11034 rc1=$?
11035 kill $pid0 2>/dev/null; wait
11036 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
11037 $PRINTF "$OK\n"
11038 numOK=$((numOK+1))
11039 else
11040 $PRINTF "$FAILED\n"
11041 echo "$CMD0 &"
11042 echo "$CMD1"
11043 cat "${te}0"
11044 # cat "${te}1"
11045 cat "$tdiff"
11046 numFAIL=$((numFAIL+1))
11047 listFAIL="$listFAIL $N"
11048 fi
11049 fi # NUMCOND
11050 ;;
11051 esac
11052 N=$((N+1))
11053  
11054  
11055 while read KEYW PF LO
11056 do
11057 if [ -z "$KEYW" ] || [[ "$KEYW" == \#* ]]; then continue; fi
11058 #
11059 pf="$(echo $PF |tr A-Z a-z)"
11060 proto="$(echo $KEYW |tr A-Z a-z)"
11061 NAME=OPENSSL_${KEYW}_FORK
11062 case "$TESTS" in
11063 *%$N%*|*%functions%*|*%chain%*|*%openssl%*|*%sctp%*|*%$pf%*|*%$NAME%*)
11064 TEST="$NAME: openssl over SCTP with server fork"
11065 if ! eval $NUMCOND; then :;
11066 elif ! testaddrs openssl >/dev/null; then
11067 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11068 numCANT=$((numCANT+1))
11069 elif ! testaddrs listen sctp $pf >/dev/null || ! runs$pf >/dev/null; then
11070 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP/$PF not available${NORMAL}\n" $N
11071 numCANT=$((numCANT+1))
11072 else
11073 gentestcert testsrv
11074 tf="$td/test$N.stdout"
11075 te="$td/test$N.stderr"
11076 tdiff="$td/test$N.diff"
11077 da1="test$N $(date) $RANDOM"
11078 da2="test$N $(date) $RANDOM"
11079 CMD0="$TRACE $SOCAT $opts ${KEYW}-LISTEN:$PORT,reuseaddr,fork ^OPENSSL-LISTEN,$SOCAT_EGD',cert=testsrv.crt,key=testsrv.key,verify=0|pipe'"
11080 CMD1="$TRACE $SOCAT $opts - openssl,verify=0,$SOCAT_EGD|${KEYW}:$LOCALHOST:$PORT"
11081 printf "test $F_n $TEST... " $N
11082 eval "$CMD0 2>\"${te}0\" &"
11083 pid0=$! # background process id
11084 wait${proto}port $PORT
11085 (echo "$da1"; sleep 1) |$CMD1 >${tf}1 2>"${te}1"
11086 (echo "$da2"; sleep 1) |$CMD1 >${tf}2 2>"${te}2"
11087 kill $pid0 2>/dev/null
11088 if ! echo "$da2" |diff - "${tf}2" >"$tdiff"; then
11089 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11090 echo "$CMD0 &"
11091 echo "$CMD1"
11092 cat "${te}0"
11093 cat "${te}1"
11094 cat "${te}2"
11095 cat "$tdiff"
11096 numFAIL=$((numFAIL+1))
11097 listFAIL="$listFAIL $N"
11098 else
11099 $PRINTF "$OK\n"
11100 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
11101 numOK=$((numOK+1))
11102 fi
11103 wait
11104 fi ;; # NUMCOND, feats
11105 esac
11106 PORT=$((PORT+1))
11107 N=$((N+1))
11108 #
11109 done <<<"
11110 SCTP4 IP4 127.0.0.1
11111 SCTP6 IP6 [::1]
11112 "
11113  
11114  
11115 # tests with inter address exec (`exec2')
11116 while read c commname
11117 do
11118 if [ -z "$c" ] || [[ "$c" == \#* ]]; then continue; fi
11119 COMMNAME="$(echo $commname |tr 'a-z ' 'A-Z_')"
11120 #
11121 for exec in exec system; do
11122 EXEC="$(echo $exec |tr 'a-z' 'A-Z')"
11123 #
11124  
11125 NAME=${EXEC}2_$COMMNAME
11126 case "$TESTS" in
11127 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}2%*|*%$NAME%*)
11128 TEST="$NAME: bidirectional $exec in simple chain ($commname)"
11129 testecho "$N" "$TEST" "STDIO" "$EXEC:bin/cat2.sh|PIPE" "$opts -c$c" "$val_t"
11130 esac
11131 N=$((N+1))
11132  
11133 NAME=${EXEC}2UNI_$COMMNAME
11134 case "$TESTS" in
11135 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%{exec}2%*|*%$NAME%*)
11136 TEST="$NAME: unidirectional $exec in simple chain ($commname)"
11137 testecho "$N" "$TEST" "STDIO" "$EXEC:bin/cat2.sh|STDIO" "$opts -u -c$c" "$val_t"
11138 esac
11139 N=$((N+1))
11140  
11141 NAME=${EXEC}2CHAIN_$COMMNAME
11142 case "$TESTS" in
11143 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}2%*|*%$NAME%*)
11144 TEST="$NAME: $exec in chain with endpoint $exec ($commname)"
11145 testecho "$N" "$TEST" "STDIO" "$EXEC:bin/predialog.sh|$EXEC:./proxyecho.sh" "$opts -c$c" "$val_t"
11146 esac
11147 N=$((N+1))
11148  
11149 NAME=${EXEC}1BI_FORWARD_$COMMNAME
11150 case "$TESTS" in
11151 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11152 TEST="$NAME: ${exec}1 in birectional chain, forward ($commname)"
11153 testecho "$N" "$TEST" "STDIO" "${EXEC}1:cat%NOP|PIPE" "$opts -c$c" "$val_t"
11154 esac
11155 N=$((N+1))
11156  
11157 NAME=${EXEC}1UNI_FORWARD_$COMMNAME
11158 case "$TESTS" in
11159 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11160 TEST="$NAME: ${exec}1 in unrectional chain, forward ($commname)"
11161 testecho "$N" "$TEST" "STDIN" "${EXEC}1:cat|STDOUT" "$opts -u -c$c" "$val_t"
11162 esac
11163 N=$((N+1))
11164  
11165 NAME=${EXEC}1UNI_BACKWARD_$COMMNAME
11166 case "$TESTS" in
11167 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11168 TEST="$NAME: ${exec}1 in unrectional chain, backward ($commname)"
11169 testecho "$N" "$TEST" "STDOUT" "^${EXEC}1:cat|STDIN" "$opts -U -c$c" "$val_t"
11170 esac
11171 N=$((N+1))
11172  
11173 case "$commname" in
11174 "ptys") ;;
11175 *)
11176 NAME=${EXEC}1BI_FORWARD_HALFCLOSE_$COMMNAME
11177 case "$TESTS" in
11178 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11179 TEST="$NAME: ${exec}1 in birectional chain, forward ($commname)"
11180 testod "$N" "$TEST" "STDIO" "${EXEC}1:$OD_C%NOP|PIPE" "$opts -c$c" "$val_t"
11181 esac
11182 N=$((N+1))
11183 ;;
11184 esac
11185  
11186 case "$commname" in
11187 "ptys") ;;
11188 *)
11189 NAME=${EXEC}1UNI_FORWARD_HALFCLOSE_$COMMNAME
11190 case "$TESTS" in
11191 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11192 TEST="$NAME: ${exec}1 in unrectional chain, forward ($commname)"
11193 testod "$N" "$TEST" "STDIN" "${EXEC}1:$OD_C|STDOUT" "$opts -u -c$c" "$val_t"
11194 esac
11195 N=$((N+1))
11196 ;;
11197 esac
11198  
11199 case "$commname" in
11200 "ptys") ;;
11201 *)
11202 NAME=${EXEC}1UNI_BACKWARD_HALFCLOSE_$COMMNAME
11203 case "$TESTS" in
11204 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11205 TEST="$NAME: ${exec}1 in unrectional chain, backward ($commname)"
11206 testod "$N" "$TEST" "STDOUT" "^${EXEC}1:$OD_C|STDIN" "$opts -U -c$c" "$val_t"
11207 esac
11208 N=$((N+1))
11209 ;;
11210 esac
11211  
11212 if [ "$commname" != "pipes" ]; then
11213 NAME=${EXEC}2REV_$COMMNAME
11214 case "$TESTS" in
11215 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}2%*|*%$NAME%*)
11216 TEST="$NAME: bidirectional reverse $exec in simple chain ($commname)"
11217 testecho "$N" "$TEST" "STDIO" "^$EXEC:bin/cat2.sh|PIPE" "$opts -c$c" "$val_t"
11218 esac
11219 N=$((N+1))
11220 fi # ! pipes
11221  
11222 if [ "$commname" != "pipes" ]; then
11223 NAME=${EXEC}2UNIREV_$COMMNAME
11224 case "$TESTS" in
11225 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}2%*|*%$NAME%*)
11226 TEST="$NAME: unidirectional reverse $exec in simple chain ($commname)"
11227 testecho "$N" "$TEST" "STDIO" "^$EXEC:bin/cat2.sh|STDIO" "$opts -u -c$c" "$val_t"
11228 esac
11229 N=$((N+1))
11230 fi # ! pipes
11231  
11232 case "$commname" in
11233 "pipes") ;;
11234 "ptys") ;;
11235 *)
11236 NAME=${EXEC}2DUAL_$COMMNAME
11237 case "$TESTS" in
11238 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}2%*|*%$NAME%*)
11239 TEST="$NAME: dual $exec in simple chain ($commname)"
11240 testecho "$N" "$TEST" "STDIO" "$EXEC:bin/cat2.sh%$EXEC:bin/cat2.sh|PIPE" "$opts -c$c"
11241 esac
11242 N=$((N+1))
11243 ;;
11244 esac
11245  
11246  
11247 case "$commname" in
11248 "pipes") ;;
11249 "ptys") ;;
11250 *)
11251 NAME=${EXEC}1BI_BACKWARD_$COMMNAME
11252 case "$TESTS" in
11253 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11254 TEST="$NAME: ${exec}1 in birectional chain, backward ($commname)"
11255 testecho "$N" "$TEST" "STDIO" "NOP%${EXEC}1:cat|PIPE" "$opts -c$c" "$val_t"
11256 esac
11257 N=$((N+1))
11258 ;;
11259 esac
11260  
11261 done # for EXEC in EXEC SYSTEM
11262  
11263 # we are still in the commname loop
11264  
11265 # here are tests that do not work with SYSTEM
11266 for exec in exec; do
11267 EXEC="$(echo $exec |tr 'a-z' 'A-Z')"
11268 #
11269  
11270 case "$commname" in
11271 "ptys") ;;
11272 *)
11273 NAME=${EXEC}1BI_BACKWARD_HALFCLOSE_$COMMNAME
11274 case "$TESTS" in
11275 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11276 TEST="$NAME: ${exec}1 in birectional chain, backward ($commname)"
11277 testod "$N" "$TEST" "STDIO" "NOP%${EXEC}1:$OD_C|PIPE" "$opts -c$c" "$val_t"
11278 esac
11279 N=$((N+1))
11280 ;;
11281 esac
11282  
11283 case "$commname" in
11284 "ptys") ;;
11285 *)
11286 # currently failes with socketpair, tcp when cat is used because dual mode with
11287 # single fd communication has an implicit half close problem
11288 NAME=${EXEC}1BI_CAT_OD_HALFCLOSE_$COMMNAME
11289 case "$TESTS" in
11290 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11291 TEST="$NAME: ${exec}1 in birectional chain, both directions ($commname)"
11292 testod "$N" "$TEST" "STDIO" "${EXEC}1:$SOCAT -u - -%${EXEC}1:$OD_C|PIPE" "$opts -c$c" "$val_t"
11293 esac
11294 N=$((N+1))
11295 ;;
11296 esac
11297  
11298 NAME=${EXEC}1BI_BOTH_$COMMNAME
11299 case "$TESTS" in
11300 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11301 TEST="$NAME: ${exec}1 in birectional chain, both directions ($commname)"
11302 testecho "$N" "$TEST" "STDIO" "${EXEC}1:cat%${EXEC}1:cat|PIPE" "$opts -c$c" "$val_t"
11303 esac
11304 N=$((N+1))
11305  
11306 case "$commname" in
11307 "ptys") ;;
11308 *)
11309 NAME=${EXEC}1BI_OD_CAT_HALFCLOSE_$COMMNAME
11310 case "$TESTS" in
11311 *%$N%*|*%functions%*|*%chain%*|*%$exec%*|*%${exec}1%*|*%$NAME%*)
11312 TEST="$NAME: ${exec}1 in birectional chain, both directions ($commname)"
11313 testod "$N" "$TEST" "STDIO" "${EXEC}1:$OD_C%${EXEC}1:cat|PIPE" "$opts -c$c" "$val_t"
11314 esac
11315 N=$((N+1))
11316 ;;
11317 esac
11318  
11319 done # for EXEC in EXEC SYSTEM
11320  
11321 done <<<"
11322 S two socketpairs
11323 p pipes
11324 s socketpair
11325 Y ptys
11326 t TCP
11327 "
11328 #c=S
11329 #commname=socketpairs
11330  
11331 # -u exec1
11332 # -U exec1
11333  
11334  
11335 # socat up to 1.7.1.2 and from 2.0.0-b1 to 2.0.0-b3 had a stack overflow vulnerability that occurred when
11336 # command line arguments (whole addresses, host names, file names) were longer
11337 # than 512 bytes.
11338 NAME=HOSTNAMEOVFL
11339 case "$TESTS" in
11340 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11341 TEST="$NAME: stack overflow on overly long host name"
11342 # provide a long host name to TCP-CONNECT and check socats exit code
11343 if ! eval $NUMCOND; then :; else
11344 tf="$td/test$N.stdout"
11345 te="$td/test$N.stderr"
11346 tdiff="$td/test$N.diff"
11347 da="test$N $(date) $RANDOM"
11348 # prepare long data - perl might not be installed
11349 rm -f "$td/test$N.dat"
11350 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11351 CMD0="$TRACE $SOCAT $opts TCP-CONNECT:$(cat "$td/test$N.dat"):$PORT STDIO"
11352 printf "test $F_n $TEST... " $N
11353 $CMD0 </dev/null 1>&0 2>"${te}0"
11354 rc0=$?
11355 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11356 $PRINTF "$OK\n"
11357 numOK=$((numOK+1))
11358 else
11359 $PRINTF "$FAILED\n"
11360 echo "$CMD0"
11361 cat "${te}0"
11362 numFAIL=$((numFAIL+1))
11363 listFAIL="$listFAIL $N"
11364 fi
11365 fi # NUMCOND
11366 ;;
11367 esac
11368 PORT=$((PORT+1))
11369 N=$((N+1))
11370  
11371 #set -vx
11372 # socat up to 1.7.1.2 and from 2.0.0-b1 to 2.0.0-b3 had a stack overflow vulnerability that occurred when
11373 # command line arguments (whole addresses, host names, file names) were longer
11374 # than 512 bytes.
11375 NAME=FILENAMEOVFL
11376 case "$TESTS" in
11377 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%openssl%*|*%$NAME%*)
11378 TEST="$NAME: stack overflow on overly long file name"
11379 # provide a 600 bytes long key file option to SSL-CONNECT and check socats exit code
11380 if ! eval $NUMCOND; then :; else
11381 tf="$td/test$N.stdout"
11382 te="$td/test$N.stderr"
11383 tdiff="$td/test$N.diff"
11384 da="test$N $(date) $RANDOM"
11385 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11386 CMD0="$TRACE $SOCAT $opts OPENSSL:localhost:$PORT,key=$(cat "$td/test$N.dat") STDIO"
11387 printf "test $F_n $TEST... " $N
11388 $CMD0 </dev/null 1>&0 2>"${te}0"
11389 rc0=$?
11390 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11391 $PRINTF "$OK\n"
11392 numOK=$((numOK+1))
11393 else
11394 $PRINTF "$FAILED\n"
11395 echo "$CMD0"
11396 cat "${te}0"
11397 numFAIL=$((numFAIL+1))
11398 listFAIL="$listFAIL $N"
11399 fi
11400 fi # NUMCOND
11401 ;;
11402 esac
11403 PORT=$((PORT+1))
11404 N=$((N+1))
11405  
11406  
11407 # test for a bug in gopen that lead to crash or warning when opening a unix
11408 # domain socket with GOPEN
11409 NAME=GOPEN_UNIX_CRASH
11410 case "$TESTS" in
11411 *%$N%*|*%functions%*|*%bugs%*|*%gopen%*|*%unix%*|*%socket%*|*%$NAME%*)
11412 TEST="$NAME: check crash when connecting to a unix domain socket using address GOPEN"
11413 # a unix domain server is started in background. the check process connects to
11414 # its socket. when this process crashes or issues a warning the bug is present.
11415 # please note that a clean behaviour does not proof anything; behaviour of bug
11416 # depends on the value of an uninitialized var
11417 #set -vx
11418 if ! eval $NUMCOND; then :; else
11419 tf="$td/test$N.stdout"
11420 te="$td/test$N.stderr"
11421 ts="$td/test$N.sock"
11422 tdiff="$td/test$N.diff"
11423 da="test$N $(date) $RANDOM"
11424 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
11425 CMD1="$TRACE $SOCAT $opts -d - GOPEN:$ts"
11426 printf "test $F_n $TEST... " $N
11427 $CMD0 >/dev/null 2>"${te}0" </dev/null &
11428 pid0=$!
11429 waitunixport "$ts" 1
11430 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11431 rc1=$?
11432 kill $pid0 2>/dev/null; wait
11433 if [ $rc1 -ne 0 ]; then
11434 $PRINTF "$FAILED\n"
11435 echo "$CMD0 &"
11436 echo "$CMD1"
11437 cat "${te}0"
11438 cat "${te}1"
11439 numFAIL=$((numFAIL+1))
11440 listFAIL="$listFAIL $N"
11441 elif grep -q ' W ' "${te}1"; then
11442 $PRINTF "$FAILED\n"
11443 echo "$CMD0 &"
11444 echo "$CMD1"
11445 cat "${te}0"
11446 cat "${te}1"
11447 numFAIL=$((numFAIL+1))
11448 listFAIL="$listFAIL $N"
11449 elif ! echo "$da" |diff - ${tf}1 >"$tdiff"; then
11450 $PRINTF "$FAILED\n"
11451 echo "$CMD0 &"
11452 echo "$CMD1"
11453 cat "${te}0"
11454 cat "${te}1"
11455 cat "$tdiff"
11456 numFAIL=$((numFAIL+1))
11457 listFAIL="$listFAIL $N"
11458 else
11459 $PRINTF "$OK\n"
11460 numOK=$((numOK+1))
11461 fi
11462 fi # NUMCOND
11463 ;;
11464 esac
11465 N=$((N+1))
11466  
11467  
11468 # test if socat keeps an existing file where it wanted to create a UNIX socket
11469 NAME=UNIXLISTEN_KEEPFILE
11470 case "$TESTS" in
11471 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
11472 TEST="$NAME: socat keeps an existing file where it wanted to create a UNIX socket"
11473 # we create a file and start socat with UNIX-LISTEN on this file. expected
11474 # behaviour: socat exits immediately with error, but keeps the file
11475 # up to 1.7.1.3, it removed the file
11476 if ! eval $NUMCOND; then :; else
11477 tf="$td/test$N.file"
11478 te="$td/test$N.stderr"
11479 CMD0="$TRACE $SOCAT $opts -u UNIX-LISTEN:$tf /dev/null"
11480 printf "test $F_n $TEST... " $N
11481 rm -f "$tf"; touch "$tf"
11482 $CMD0 >/dev/null 2>"${te}0"
11483 rc0=$?
11484 if [ $rc0 -ne 0 -a -f "$tf" ]; then
11485 $PRINTF "$OK\n"
11486 numOK=$((numOK+1))
11487 else
11488 $PRINTF "$FAILED\n"
11489 echo "$CMD0"
11490 cat "${te}0"
11491 numFAIL=$((numFAIL+1))
11492 listFAIL="$listFAIL $N"
11493 fi
11494 fi # NUMCOND
11495 ;;
11496 esac
11497 N=$((N+1))
11498  
11499  
11500 # incomplete writes were reported but led to data loss
11501 NAME=INCOMPLETE_WRITE
11502 case "$TESTS" in
11503 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
11504 TEST="$NAME: check if incomplete writes are handled properly"
11505 # write to a nonblocking fd a block that is too large for atomic write
11506 # and check if all data arrives
11507 if ! eval $NUMCOND; then :; else
11508 tf="$td/test$N.stdout"
11509 te="$td/test$N.stderr"
11510 tp="$td/test$N.pipe"
11511 tw="$td/test$N.wc-c"
11512 # this is the size we write() in one call; data is never stored on disk, so
11513 # make it large enough to exceed any atomic write size; but higher number might
11514 # take much time
11515 bytes=100000 # for Linux 2.6.? this must be >65536
11516 CMD0="$TRACE $SOCAT $opts -u PIPE:$tp STDOUT"
11517 CMD1="$TRACE $SOCAT $opts -u -b $bytes OPEN:/dev/zero,readbytes=$bytes FILE:$tp,o-nonblock"
11518 printf "test $F_n $TEST... " $N
11519 $CMD0 2>"${te}0" |wc -c >"$tw" &
11520 pid=$!
11521 waitfile "$tp"
11522 $CMD1 2>"${te}1" >"${tf}1"
11523 rc1=$?
11524 wait
11525 if [ $rc1 -ne 0 ]; then
11526 $PRINTF "$NO_RESULT\n"
11527 numCANT=$((numCANT+1))
11528 elif [ ! -e "$tw" ]; then
11529 $PRINTF "$NO_RESULT\n"
11530 numCANT=$((numCANT+1))
11531 elif [ "$bytes" -eq $(cat "$tw") ]; then
11532 $PRINTF "$OK\n"
11533 numOK=$((numOK+1))
11534 else
11535 $PRINTF "$FAILED\n"
11536 echo "transferred only $(cat $tw) of $bytes bytes" >&2
11537 numFAIL=$((numFAIL+1))
11538 listFAIL="$listFAIL $N"
11539 fi
11540 fi # NUMCOND
11541 ;;
11542 esac
11543 N=$((N+1))
11544  
11545  
11546 NAME=OPENSSL_ANULL
11547 case "$TESTS" in
11548 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
11549 TEST="$NAME: OpenSSL server with cipher aNULL "
11550 if ! eval $NUMCOND; then :;
11551 elif ! testaddrs openssl >/dev/null; then
11552 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11553 numCANT=$((numCANT+1))
11554 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11555 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11556 numCANT=$((numCANT+1))
11557 else
11558 tf="$td/test$N.stdout"
11559 te="$td/test$N.stderr"
11560 tdiff="$td/test$N.diff"
11561 da="test$N $(date) $RANDOM"
11562 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,$SOCAT_EGD,ciphers=aNULL,verify=0 pipe"
11563 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,ciphers=aNULL,verify=0,$SOCAT_EGD"
11564 printf "test $F_n $TEST... " $N
11565 eval "$CMD2 2>\"${te}1\" &"
11566 pid=$! # background process id
11567 waittcp4port $PORT
11568 echo "$da" |$CMD >$tf 2>"${te}2"
11569 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
11570 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11571 echo "$CMD2 &"
11572 echo "$CMD"
11573 cat "${te}1"
11574 cat "${te}2"
11575 cat "$tdiff"
11576 numFAIL=$((numFAIL+1))
11577 listFAIL="$listFAIL $N"
11578 else
11579 $PRINTF "$OK\n"
11580 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11581 numOK=$((numOK+1))
11582 fi
11583 kill $pid 2>/dev/null
11584 wait
11585 fi ;; # NUMCOND, feats
11586 esac
11587 PORT=$((PORT+1))
11588 N=$((N+1))
11589  
11590  
11591 # test the max-children option
11592 NAME=MAXCHILDREN
11593 case "$TESTS" in
11594 *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
11595 TEST="$NAME: max-children option"
11596 # start a listen process with max-children=1; connect with a client, let it
11597 # sleep some time before sending data; connect with second client that sends
11598 # data immediately. If max-children is working correctly the first data should
11599 # arrive first because the second process has to wait.
11600 if ! eval $NUMCOND; then :; else
11601 ts="$td/test$N.sock"
11602 tf="$td/test$N.stdout"
11603 te="$td/test$N.stderr"
11604 tdiff="$td/test$N.diff"
11605 da="test$N $(date) $RANDOM"
11606 CMD0="$TRACE $SOCAT $opts -U FILE:$tf,o-trunc,o-creat,o-append UNIX-L:$ts,fork,max-children=1"
11607 CMD1="$TRACE $SOCAT $opts -u - UNIX-CONNECT:$ts"
11608 printf "test $F_n $TEST... " $N
11609 $CMD0 >/dev/null 2>"${te}0" &
11610 pid0=$!
11611 waitunixport $ts 1
11612 (sleep 2; echo "$da 1") |$CMD1 >"${tf}1" 2>"${te}1" &
11613 pid1=$!
11614 sleep 1
11615 echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2"
11616 rc2=$?
11617 sleep 2
11618 kill $pid0 $pid1 2>/dev/null; wait
11619 if echo -e "$da 1\n$da 2" |diff - $tf >$tdiff; then
11620 $PRINTF "$OK\n"
11621 numOK=$((numOK+1))
11622 else
11623 $PRINTF "$FAILED\n"
11624 echo "$CMD0 &"
11625 echo "(sleep 2; echo \"$da 1\") |$CMD1"
11626 echo "echo \"$da 2\" |$CMD1"
11627 cat "${te}0"
11628 cat "${te}1"
11629 cat "${te}2"
11630 cat "$tdiff"
11631 numFAIL=$((numFAIL+1))
11632 listFAIL="$listFAIL $N"
11633 fi
11634 fi # NUMCOND
11635 ;;
11636 esac
11637 N=$((N+1))
11638  
11639  
11640 # socat up to 1.7.2.0 and 2.0.0-b4 had a bug in xioscan_readline() that could
11641 # be exploited
11642 # to overflow a heap based buffer (socat security advisory 3)
11643 # problem reported by Johan Thillemann
11644 NAME=READLINE_OVFL
11645 case "$TESTS" in
11646 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%$NAME%*)
11647 TEST="$NAME: test for buffer overflow in readline prompt handling"
11648 # address 1 is the readline where write data was handled erroneous
11649 # address 2 provides data to trigger the buffer overflow
11650 # when no SIGSEGV or so occurs the test succeeded (bug fixed)
11651 if ! eval $NUMCOND; then :; else
11652 tf="$td/test$N.stdout"
11653 te="$td/test$N.stderr"
11654 ti="$td/test$N.data"
11655 CMD0="$TRACE $SOCAT $opts READLINE $ti"
11656 printf "test $F_n $TEST... " $N
11657 # prepare long data - perl might not be installed
11658 #perl -e 'print "\r","Z"x513' >"$ti"
11659 echo $E -n "\rA" >"$ti"
11660 i=0; while [ $i -lt 32 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$ti"; let i=i+1; done
11661 $TRACE $SOCAT - system:"$CMD0; echo rc=\$? >&2",pty >/dev/null 2>"${te}0"
11662 rc=$?
11663 rc0="$(grep ^rc= "${te}0" |sed 's/.*=//')"
11664 if [ $rc -ne 0 ]; then
11665 $PRINTF "${YELLOW}framework failed${NORMAL}\n"
11666 elif [ $rc0 -eq 0 ]; then
11667 $PRINTF "$OK\n"
11668 numOK=$((numOK+1))
11669 else
11670 $PRINTF "$FAILED\n"
11671 echo "$CMD0"
11672 grep -v ^rc= "${te}0"
11673 numFAIL=$((numFAIL+1))
11674 listFAIL="$listFAIL $N"
11675 fi
11676 fi # NUMCOND
11677 ;;
11678 esac
11679 PORT=$((PORT+1))
11680 N=$((N+1))
11681  
11682  
11683 # socat up to 1.7.2.1 did only shutdown() but not close() an accept() socket
11684 # that was rejected due to range, tcpwrap, lowport, or sourceport option.
11685 # This file descriptor leak could be used for a denial of service attack.
11686 NAME=FDLEAK
11687 case "$TESTS" in
11688 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11689 TEST="$NAME: file descriptor leak with range option"
11690 # have a TCP-LISTEN with range option; connect with wrong source address until
11691 # "open files" limit would exceed. When server continues operation the bug is
11692 # not present.
11693 if ! eval $NUMCOND; then :; else
11694 tf="$td/test$N.stdout"
11695 te="$td/test$N.stderr"
11696 tdiff="$td/test$N.diff"
11697 da="test$N $(date) $RANDOM"
11698 RLIMIT_NOFILE="$(ulimit -n)"
11699 if ! [[ "$RLIMIT_NOFILE" =~ ^[0-9][0-9]*$ ]]; then
11700 $PRINTF "${YELLOW}cannot determine ulimit -n"
11701 else
11702 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,reuseaddr,range=$LOCALHOST:255.255.255.255 PIPE"
11703 CMD1="$TRACE $SOCAT $opts -t 0 /dev/null TCP:$SECONDADDR:$PORT,bind=$SECONDADDR"
11704 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
11705 printf "test $F_n $TEST... " $N
11706 $CMD0 >/dev/null 2>"${te}0" &
11707 pid0=$!
11708 waittcp4port $PORT 1
11709 while [ $RLIMIT_NOFILE -gt 0 ]; do
11710 $CMD1 >/dev/null 2>>"${te}1"
11711 let RLIMIT_NOFILE=RLIMIT_NOFILE-1
11712 done
11713 echo "$da" |$CMD2 >"${tf}2" 2>"${te}2"
11714 rc2=$?
11715 kill $pid0 2>/dev/null; wait
11716 echo -e "$da" |diff "${tf}2" - >$tdiff
11717 if [ $rc2 -ne 0 ]; then
11718 $PRINTF "$FAILED\n"
11719 echo "$CMD2 &"
11720 cat "${te}2"
11721 numFAIL=$((numFAIL+1))
11722 listFAIL="$listFAIL $N"
11723 elif [ -f "$tdiff" -a ! -s "$tdiff" ]; then
11724 $PRINTF "$OK\n"
11725 numOK=$((numOK+1))
11726 else
11727 $PRINTF "$FAILED\n"
11728 echo "$CMD0 &"
11729 echo "$CMD1"
11730 echo "$CMD2"
11731 cat "${te}0"
11732 cat "${te}1"
11733 cat "${te}2"
11734 numFAIL=$((numFAIL+1))
11735 listFAIL="$listFAIL $N"
11736 fi
11737 fi # ulimit -n
11738 fi # NUMCOND
11739 ;;
11740 esac
11741 PORT=$((PORT+1))
11742 N=$((N+1))
11743  
11744  
11745 if false; then # this overflow is not reliably reproducable
11746 # socat up to 1.7.2.2 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.
11747 NAME=PROXY_ADDR_OVFL
11748 case "$TESTS" in
11749 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11750 TEST="$NAME: proxy address parameters overflow"
11751 # invoke socat PROXY-CONNECT with long proxy server and target server names. If it terminates with exit code >= 128 it is vulnerable
11752 # 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
11753 if ! eval $NUMCOND; then :; else
11754 tf="$td/test$N.stdout"
11755 te="$td/test$N.stderr"
11756 tdiff="$td/test$N.diff"
11757 da="test$N $(date) $RANDOM"
11758 EF=; for p in ef; do
11759 if type ef >/dev/null 2>&1; then
11760 EF="ef "; break
11761 fi
11762 done
11763 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,reuseaddr FILE:/dev/null"
11764 #CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$(perl -e "print 'A' x 256"):$(perl -e "print 'A' x 256"):80"
11765 CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:localhost:$(perl -e "print 'A' x 384"):80,proxyport=$PORT"
11766 printf "test $F_n $TEST... " $N
11767 $CMD0 >/dev/null 2>"${te}0" &
11768 pid0=$!
11769 waittcp4port $PORT 1
11770 $CMD1 >/dev/null 2>"${te}1"
11771 rc1=$?
11772 if [ $rc1 -lt 128 ]; then
11773 if [ "$EF" ]; then
11774 $PRINTF "$OK\n"
11775 numOK=$((numOK+1))
11776 else
11777 $PRINTF "$UNKNOWN $RED(install ElectricFEnce!)$NORMAL\n"
11778 numCANT=$((num+1))
11779 fi
11780 else
11781 $PRINTF "$FAILED\n"
11782 echo "$CMD1"
11783 cat "${te}"
11784 numFAIL=$((numFAIL+1))
11785 listFAIL="$listFAIL $N"
11786 fi
11787 fi # NUMCOND
11788 ;;
11789 esac
11790 PORT=$((PORT+1))
11791 N=$((N+1))
11792 fi # false
11793  
11794  
11795 # LISTEN addresses in socat up to 1.7.2.1 and 2.0.0-b7 applied many file
11796 # descriptor, socket, and TCP options only to the listening socket instead of the
11797 # connection socket.
11798 NAME=LISTEN_KEEPALIVE
11799 case "$TESTS" in
11800 *%functions%*|*%bugs%*|*%listen%*|*%keepalive%*|*%socket%*|*%$NAME%*)
11801 TEST="$NAME: keepalive option is applied to connection socket"
11802 # instance 0 has TCP-LISTEN with option so-keepalive and invokes filan after
11803 # accept(). filan writes its output to the socket. instance 1 connects to
11804 # instance 0. The value of the sockets so-keepalive option is checked, it must
11805 # be 1
11806 if ! eval $NUMCOND; then :; else
11807 tf="$td/test$N.stdout"
11808 te="$td/test$N.stderr"
11809 #tdiff="$td/test$N.diff"
11810 #da="test$N $(date) $RANDOM"
11811 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr,so-keepalive EXEC:\"$FILAN -i 1\",nofork"
11812 CMD1="$TRACE $SOCAT $opts - TCP4:$LOCALHOST:$PORT"
11813 printf "test $F_n $TEST... " $N
11814 eval $CMD0 >/dev/null 2>"${te}0" &
11815 pid0=$!
11816 waittcp4port $PORT 1
11817 $CMD1 >"${tf}1" 2>"${te}1"
11818 KEEPALIVE="$(cat "${tf}1" |tail -n +2 |sed -e "s/.*KEEPALIVE=//" -e "s/[[:space:]].*//")"
11819 rc1=$?
11820 kill $pid0 2>/dev/null; wait
11821 if [ -z "$KEEPALIVE" ]; then
11822 $PRINTF "$NO_RESULT\n"
11823 echo "$CMD0 &"
11824 echo "$CMD1"
11825 cat "${te}0"
11826 cat "${te}1"
11827 numWARN=$((numWARN+1))
11828 elif [ "$KEEPALIVE" = "1" ]; then
11829 $PRINTF "$OK\n";
11830 numOK=$((numOK+1))
11831 else
11832 $PRINTF "$FAILED\n"
11833 echo "$CMD0 &"
11834 echo "$CMD1"
11835 cat "${te}0"
11836 cat "${te}1"
11837 numFAIL=$((numFAIL+1))
11838 listFAIL="$listFAIL $N"
11839 fi
11840 fi # NUMCOND
11841 ;;
11842 esac
11843 PORT=$((PORT+1))
11844 N=$((N+1))
11845  
11846  
11847 # OPENSSL-CONNECT with bind option failed on some systems (eg.FreeBSD, but not
11848 # Linux) with "Invalid argument".
11849 NAME=OPENSSL_CONNECT_BIND
11850 case "$TESTS" in
11851 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
11852 TEST="$NAME: test OPENSSL-CONNECT with bind option"
11853 # have a simple SSL server that just echoes data.
11854 # connect with socat using OPENSSL-CONNECT with bind, send data and check if the
11855 # reply is identical.
11856 if ! eval $NUMCOND; then :; else
11857 tf0="$td/test$N.0.stdout"
11858 te0="$td/test$N.0.stderr"
11859 tf1="$td/test$N.1.stdout"
11860 te1="$td/test$N.1.stderr"
11861 tdiff="$td/test$N.diff"
11862 da="test$N $(date) $RANDOM"
11863 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,ciphers=aNULL,verify=0, PIPE"
11864 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,bind=$LOCALHOST,ciphers=aNULL,verify=0"
11865 printf "test $F_n $TEST... " $N
11866 $CMD0 >/dev/null 2>"$te0" &
11867 pid0=$!
11868 waittcp4port $PORT 1
11869 echo "$da" |$CMD1 >"$tf1" 2>"$te1"
11870 rc1=$?
11871 kill $pid0 2>/dev/null; wait
11872 if [ "$rc1" -ne 0 ]; then
11873 $PRINTF "$FAILED\n"
11874 echo "$CMD0 &"
11875 echo "$CMD1"
11876 cat "$te0"
11877 cat "$te1"
11878 numFAIL=$((numFAIL+1))
11879 listFAIL="$listFAIL $N"
11880 elif ! echo "$da" |diff - $tf1 >"$tdiff"; then
11881 $PRINTF "$FAILED\n"
11882 echo "$CMD0 &"
11883 echo "$CMD1"
11884 cat "${te}0"
11885 cat "${te}1"
11886 cat "$tdiff"
11887 numFAIL=$((numFAIL+1))
11888 listFAIL="$listFAIL $N"
11889 else
11890 $PRINTF "$OK\n"
11891 numOK=$((numOK+1))
11892 fi
11893 fi # NUMCOND
11894 ;;
11895 esac
11896 PORT=$((PORT+1))
11897 N=$((N+1))
11898  
11899  
11900 # socat up to version 1.7.2.3
11901 # had a bug that converted a bit mask of 0 internally to 0xffffffff
11902 NAME=TCP4RANGE_0BITS
11903 case "$TESTS" in
11904 *%$N%*|*%functions%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
11905 TEST="$NAME: correct evaluation of range mask 0"
11906 if ! eval $NUMCOND; then :;
11907 elif [ -z "$SECONDADDR" ]; then
11908 # we need access to a second addresses
11909 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
11910 numCANT=$((numCANT+1))
11911 else
11912 tf="$td/test$N.stdout"
11913 tdiff="$td/test$N.diff"
11914 da="test$N $(date) $RANDOM"
11915 #testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
11916 CMD0="$TRACE $SOCAT $opts -u TCP4-LISTEN:$PORT,reuseaddr,range=127.0.0.1/0 CREATE:$tf"
11917 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$SECONDADDR:$PORT,bind=$SECONDADDR"
11918 printf "test $F_n $TEST... " $N
11919 $CMD0 2>"${te}0" &
11920 pid0=$!
11921 waittcp4port $PORT 1
11922 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11923 rc1=$?
11924 kill $pid0 2>/dev/null; wait
11925 if [ $rc1 != 0 ]; then
11926 $PRINTF "${YELLOW}invocation failed${NORMAL}\n"
11927 numCANT=$((numCANT+1))
11928 elif ! [ -f "$tf" ]; then
11929 $PRINTF "$FAILED\n"
11930 echo "$CMD0 &"
11931 echo "$CMD1"
11932 cat "${te}0"
11933 cat "${te}1"
11934 numFAIL=$((numFAIL+1))
11935 listFAIL="$listFAIL $N"
11936 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11937 $PRINTF "${YELLOW}diff failed${NORMAL}\n"
11938 numCANT=$((numCANT+1))
11939 else
11940 $PRINTF "$OK\n"
11941 numOK=$((numOK+1))
11942 fi
11943  
11944 fi ;; # $SECONDADDR, NUMCOND
11945 esac
11946 PORT=$((PORT+1))
11947 N=$((N+1))
11948  
11949  
11950 # test: OPENSSL sets of environment variables with important values of peer certificate
11951 while read ssldist MODE MODULE FIELD TESTADDRESS PEERADDRESS VALUE; do
11952 if [ -z "$ssldist" ] || [[ "$ssldist" == \#* ]]; then continue; fi
11953 #
11954 SSLDIST=${ssldist^^*}
11955 NAME="ENV_${SSLDIST}_${MODE}_${MODULE}_${FIELD}"
11956 case "$TESTS" in
11957 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$ssldist%*|*%envvar%*|*%$NAME%*)
11958 TEST="$NAME: $SSLDIST sets env SOCAT_${SSLDIST}_${MODULE}_${FIELD}"
11959 # have a server accepting a connection and invoking some shell code. The shell
11960 # code extracts and prints the SOCAT related environment vars.
11961 # outside code then checks if the environment contains the variables correctly
11962 # describing the desired field.
11963 if ! eval $NUMCOND; then :;
11964 elif ! feat=$(testaddrs $FEAT); then
11965 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
11966 numCANT=$((numCANT+1))
11967 else
11968 tf="$td/test$N.stdout"
11969 te="$td/test$N.stderr"
11970 gentestcert testsrv
11971 gentestcert testcli
11972 test_proto=tcp4
11973 case "$MODE" in
11974 SERVER)
11975 CMD0="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11976 CMD1="$SOCAT $opts -u /dev/null $PEERADDRESS"
11977 printf "test $F_n $TEST... " $N
11978 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
11979 pid0=$!
11980 wait${test_proto}port $PORT 1
11981 $CMD1 2>"${te}1"
11982 rc1=$?
11983 waitfile "$tf" 2
11984 kill $pid0 2>/dev/null; wait
11985 ;;
11986 CLIENT)
11987 CMD0="$SOCAT $opts -u /dev/null $PEERADDRESS"
11988 CMD1="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11989 printf "test $F_n $TEST... " $N
11990 $CMD0 2>"${te}0" &
11991 pid0=$!
11992 wait${test_proto}port $PORT 1
11993 eval "$CMD1 2>\"${te}1\" >\"$tf\""
11994 rc1=$?
11995 waitfile "$tf" 2
11996 kill $pid0 2>/dev/null; wait
11997 ;;
11998 esac
11999 if [ $rc1 != 0 ]; then
12000 $PRINTF "$NO_RESULT (client failed):\n"
12001 echo "$CMD0 &"
12002 cat "${te}0"
12003 echo "$CMD1"
12004 cat "${te}1"
12005 numCANT=$((numCANT+1))
12006 elif effval="$(grep SOCAT_${SSLDIST}_${MODULE}_${FIELD} "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")";
12007 [ "$effval" = "$VALUE" ]; then
12008 $PRINTF "$OK\n"
12009 if [ "$debug" ]; then
12010 echo "$CMD0 &"
12011 cat "${te}0"
12012 echo "$CMD1"
12013 cat "${te}1"
12014 fi
12015 numOK=$((numOK+1))
12016 else
12017 $PRINTF "$FAILED\n"
12018 echo "expected \"$VALUE\", got \"$effval\"" >&2
12019 echo "$CMD0 &"
12020 cat "${te}0"
12021 echo "$CMD1"
12022 cat "${te}1"
12023 numFAIL=$((numFAIL+1))
12024 listFAIL="$listFAIL $N"
12025 fi
12026 fi # NUMCOND, feats
12027 ;;
12028 esac
12029 N=$((N+1))
12030 #
12031 done <<<"
12032 openssl SERVER X509 ISSUER OPENSSL-LISTEN:$PORT,so-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
12033 openssl SERVER X509 SUBJECT OPENSSL-LISTEN:$PORT,so-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
12034 openssl SERVER X509 COMMONNAME OPENSSL-LISTEN:$PORT,so-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
12035 openssl SERVER X509 COUNTRYNAME OPENSSL-LISTEN:$PORT,so-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
12036 openssl SERVER X509 LOCALITYNAME OPENSSL-LISTEN:$PORT,so-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
12037 openssl SERVER X509 ORGANIZATIONALUNITNAME OPENSSL-LISTEN:$PORT,so-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
12038 openssl SERVER X509 ORGANIZATIONNAME OPENSSL-LISTEN:$PORT,so-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
12039 openssl CLIENT X509 SUBJECT OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,so-reuseaddr,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_SUBJECT
12040 openssl CLIENT X509 ISSUER OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,so-reuseaddr,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_ISSUER
12041 "
12042  
12043  
12044 ###############################################################################
12045 # tests: option umask with "passive" NAMED group addresses
12046 while read addr fileopt addropts proto diropt ADDR2; do
12047 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12048 # some passive (listening...) filesystem based addresses did not implement the
12049 # umask option
12050 ADDR=${addr^^*}
12051 ADDR_=${ADDR/-/_}
12052 PROTO=${proto^^*}
12053 if [ "$diropt" = "." ]; then diropt=; fi
12054 if [ "$fileopt" = "." ]; then fileopt=; fi
12055 if [ "$addropts" = "." ]; then addropts=; fi
12056 NAME=${ADDR_}_UMASK
12057 case "$TESTS" in
12058 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%$NAME%*)
12059 TEST="$NAME: $ADDR applies option umask"
12060 # start a socat process with passive/listening file system entry. Check the
12061 # permissions of the FS entry, then terminate the process.
12062 # Test succeeds when FS entry exists and has expected permissions.
12063 if ! eval $NUMCOND; then :; else
12064 if [ $ADDR = PTY ]; then set -xv; fi
12065 tlog="$td/test$N.log"
12066 te0="$td/test$N.0.stderr"
12067 tsock="$td/test$N.sock"
12068 if [ -z "$fileopt" ]; then
12069 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
12070 else
12071 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
12072 fi
12073 printf "test $F_n $TEST... " $N
12074 $CMD0 >/dev/null 2>"$te0" &
12075 pid0=$!
12076 wait${proto} $tsock 1 2>"$tlog"
12077 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12078 perms=$(fileperms "$tsock")
12079 kill $pid0 2>>"$tlog"
12080 wait
12081 if [ "$ERRNOENT" ]; then
12082 $PRINTF "${RED}no entry${NORMAL}\n"
12083 echo "$CMD0 &"
12084 cat "$te0"
12085 cat "$tlog"
12086 let numFAIL=numFAIL+1
12087 listFAIL="$listFAIL $N"
12088 elif [ "$perms" != "600" ]; then
12089 $PRINTF "${RED}perms \"$perms\", expected \"600\" ${NORMAL}\n"
12090 echo "$CMD0 &"
12091 cat "$te0"
12092 let numFAIL=numFAIL+1
12093 listFAIL="$listFAIL $N"
12094 else
12095 $PRINTF "$OK\n"
12096 let numOK=numOK+1
12097 fi
12098 fi # NUMCOND
12099 ;;
12100 esac
12101 PORT=$((PORT+1))
12102 N=$((N+1))
12103 #
12104 done <<<"
12105 # address fileopt addropts waitfor direction ADDR2
12106 create . . file -U FILE:/dev/null
12107 open . creat file . FILE:/dev/null
12108 gopen . creat file . FILE:/dev/null
12109 unix-listen . . unixport . FILE:/dev/null
12110 unix-recvfrom . . unixport . FILE:/dev/null
12111 unix-recv . . unixport -u FILE:/dev/null
12112 pipe . . file -u FILE:/dev/null
12113 # pty does not seem to honor umask:
12114 #pty link . file . PIPE
12115 "
12116  
12117  
12118 # tests: option perm with "passive" NAMED group addresses
12119 while read addr fileopt addropts proto diropt; do
12120 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12121 # test if passive (listening...) filesystem based addresses implement option perm
12122 ADDR=${addr^^*}
12123 ADDR_=${ADDR/-/_}
12124 PROTO=${proto^^*}
12125 if [ "$diropt" = "." ]; then diropt=; fi
12126 if [ "$fileopt" = "." ]; then fileopt=; fi
12127 if [ "$addropts" = "." ]; then addropts=; fi
12128 NAME=${ADDR_}_PERM
12129 case "$TESTS" in
12130 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%ignoreeof%*|*%$NAME%*)
12131 TEST="$NAME: $ADDR applies option perm"
12132 # start a socat process with passive/listening file system entry. Check the
12133 # permissions of the FS entry, then terminate the process.
12134 # Test succeeds when FS entry exists and has expected permissions.
12135 if ! eval $NUMCOND; then :; else
12136 tlog="$td/test$N.log"
12137 te0="$td/test$N.0.stderr"
12138 tsock="$td/test$N.sock"
12139 #set -vx
12140 if [ -z "$fileopt" ]; then
12141 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
12142 else
12143 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
12144 fi
12145 printf "test $F_n $TEST... " $N
12146 $CMD0 >/dev/null 2>"$te0" &
12147 pid0=$!
12148 wait${proto} $tsock 1 2>"$tlog"
12149 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12150 perms=$(fileperms "$tsock")
12151 kill $pid0 2>>"$tlog"
12152 wait
12153 if [ "$ERRNOENT" ]; then
12154 $PRINTF "${RED}no entry${NORMAL}\n"
12155 echo "$CMD0 &"
12156 cat "$te0"
12157 cat "$tlog"
12158 let numFAIL=numFAIL+1
12159 listFAIL="$listFAIL $N"
12160 elif [ "$perms" != "511" ]; then
12161 $PRINTF "${RED}perms \"$perms\", expected \"511\" ${NORMAL}\n"
12162 echo "$CMD0 &"
12163 cat "$te0"
12164 let numFAIL=numFAIL+1
12165 listFAIL="$listFAIL $N"
12166 else
12167 $PRINTF "$OK\n"
12168 let numOK=numOK+1
12169 fi
12170 set +vx
12171 fi # NUMCOND
12172 ;;
12173 esac
12174 PORT=$((PORT+1))
12175 N=$((N+1))
12176 #
12177 done <<<"
12178 # address fileopt addropts waitfor direction
12179 create . . file -U
12180 open . creat file .
12181 gopen . creat file .
12182 unix-listen . . unixport .
12183 unix-recvfrom . . unixport .
12184 unix-recv . . unixport -u
12185 pipe . . file -u
12186 pty link . file .
12187 "
12188  
12189  
12190 # tests: option user with "passive" NAMED group addresses
12191 while read addr fileopt addropts proto diropt; do
12192 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12193 # test if passive (listening...) filesystem based addresses implement option user
12194 ADDR=${addr^^*}
12195 ADDR_=${ADDR/-/_}
12196 PROTO=${proto^^*}
12197 if [ "$diropt" = "." ]; then diropt=; fi
12198 if [ "$fileopt" = "." ]; then fileopt=; fi
12199 if [ "$addropts" = "." ]; then addropts=; fi
12200 NAME=${ADDR_}_USER
12201 case "$TESTS" in
12202 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%root%*|*%ignoreeof%*|*%$NAME%*)
12203 TEST="$NAME: $ADDR applies option user"
12204 # start a socat process with passive/listening file system entry with user option.
12205 # Check the owner of the FS entry, then terminate the process.
12206 # Test succeeds when FS entry exists and has expected owner.
12207 if ! eval $NUMCOND; then :;
12208 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
12209 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
12210 numCANT=$((numCANT+1))
12211 else
12212 tlog="$td/test$N.log"
12213 te0="$td/test$N.0.stderr"
12214 tsock="$td/test$N.sock"
12215 # set -vx
12216 if [ -z "$fileopt" ]; then
12217 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
12218 else
12219 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
12220 fi
12221 printf "test $F_n $TEST... " $N
12222 $CMD0 >/dev/null 2>"$te0" &
12223 pid0=$!
12224 wait${proto} $tsock 1 2>"$tlog"
12225 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12226 user=$(fileuser "$tsock")
12227 kill $pid0 2>>"$tlog"
12228 wait
12229 if [ "$ERRNOENT" ]; then
12230 $PRINTF "${RED}no entry${NORMAL}\n"
12231 echo "$CMD0 &"
12232 cat "$te0"
12233 cat "$tlog"
12234 let numFAIL=numFAIL+1
12235 listFAIL="$listFAIL $N"
12236 elif [ "$user" != "$SUBSTUSER" ]; then
12237 $PRINTF "${RED}user \"$user\", expected \"$SUBSTUSER\" ${NORMAL}\n"
12238 echo "$CMD0 &"
12239 cat "$te0"
12240 let numFAIL=numFAIL+1
12241 listFAIL="$listFAIL $N"
12242 else
12243 $PRINTF "$OK\n"
12244 let numOK=numOK+1
12245 fi
12246 set +vx
12247 fi # NUMCOND
12248 ;;
12249 esac
12250 PORT=$((PORT+1))
12251 N=$((N+1))
12252 #
12253 done <<<"
12254 # address fileopt addropts waitfor direction
12255 create . . file -U
12256 open . creat file .
12257 gopen . creat file .
12258 unix-listen . . unixport .
12259 unix-recvfrom . . unixport .
12260 unix-recv . . unixport -u
12261 pipe . . file -u
12262 pty link . file .
12263 "
12264  
12265  
12266 # tests: is "passive" filesystem entry removed at the end? (without fork)
12267 while read addr fileopt addropts proto diropt crit ADDR2; do
12268 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12269 # some passive (listening...) filesystem based addresses did not remove the file
12270 # system entry at the end
12271 ADDR=${addr^^*}
12272 ADDR_=${ADDR/-/_}
12273 PROTO=${proto^^*}
12274 if [ "$diropt" = "." ]; then diropt=; fi
12275 if [ "$fileopt" = "." ]; then fileopt=; fi
12276 if [ "$addropts" = "." ]; then addropts=; fi
12277 # $ADDR removes the file system entry when the process is terminated
12278 NAME=${ADDR_}_REMOVE
12279 case "$TESTS" in
12280 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12281 TEST="$NAME: $ADDR removes socket entry when terminated during accept"
12282 # start a socat process with listening unix domain socket etc. Terminate the
12283 # process and check if the file system socket entry still exists.
12284 # Test succeeds when entry does not exist.
12285 if ! eval $NUMCOND; then :; else
12286 tlog="$td/test$N.log"
12287 te0="$td/test$N.0.stderr"
12288 tsock="$td/test$N.sock"
12289 if [ -z "$fileopt" ]; then
12290 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts $ADDR2"
12291 else
12292 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts $ADDR2"
12293 fi
12294 printf "test $F_n $TEST... " $N
12295 $CMD0 >/dev/null 2>"$te0" &
12296 pid0=$!
12297 wait${proto} "$crit" $tsock 1 2>"$tlog"
12298 kill $pid0 2>>"$tlog"
12299 rc1=$?
12300 wait >>"$tlog"
12301 if [ $rc1 != 0 ]; then
12302 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
12303 echo "$CMD0 &"
12304 cat "$te0"
12305 cat "$tlog"
12306 let numCANT=numCANT+1
12307 elif ! [ $crit $tsock ]; then
12308 $PRINTF "$OK\n"
12309 let numOK=numOK+1
12310 else
12311 $PRINTF "$FAILED\n"
12312 echo "$CMD0 &"
12313 cat "$te0"
12314 cat "$tlog"
12315 let numFAIL=numFAIL+1
12316 listFAIL="$listFAIL $N"
12317 fi
12318 fi # NUMCOND
12319 ;;
12320 esac
12321 PORT=$((PORT+1))
12322 N=$((N+1))
12323 #
12324 done <<<"
12325 # address fileopt addropts waitfor direction crit ADDR2
12326 unix-listen . . unixport . -e FILE:/dev/null
12327 unix-recvfrom . . unixport . -e FILE:/dev/null
12328 unix-recv . . unixport -u -e FILE:/dev/null
12329 pipe . . file -u -e FILE:/dev/null
12330 pty link . file . -L PIPE
12331 "
12332  
12333  
12334 # tests: is "passive" filesystem entry removed at the end? (with fork)
12335 while read addr fileopt addropts proto diropt crit ADDR2; do
12336 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12337 # some passive (listening...) filesystem based addresses with fork did not remove
12338 # the file system entry at the end
12339 ADDR=${addr^^*}
12340 ADDR_=${ADDR/-/_}
12341 PROTO=${proto^^*}
12342 if [ "$diropt" = "." ]; then diropt=; fi
12343 if [ "$fileopt" = "." ]; then fileopt=; fi
12344 if [ "$addropts" = "." ]; then addropts=; fi
12345 # $ADDR with fork removes the file system entry when the process is terminated
12346 NAME=${ADDR_}_REMOVE_FORK
12347 case "$TESTS" in
12348 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12349 TEST="$NAME: $ADDR with fork removes socket entry when terminated during accept"
12350 # start a socat process with listening unix domain socket etc and option fork.
12351 # Terminate the process and check if the file system socket entry still exists.
12352 # Test succeeds when entry does not exist.
12353 if ! eval $NUMCOND; then :; else
12354 tlog="$td/test$N.log"
12355 te0="$td/test$N.0.stderr"
12356 tsock="$td/test$N.sock"
12357 if [ -z "$fileopt" ]; then
12358 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,fork,$addropts $ADDR2"
12359 else
12360 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,fork,$fileopt=$tsock,$addropts $ADDR2"
12361 fi
12362 printf "test $F_n $TEST... " $N
12363 $CMD0 >/dev/null 2>"$te0" &
12364 pid0=$!
12365 wait${proto} "$crit" $tsock 1 2>"$tlog"
12366 kill $pid0 2>>"$tlog"
12367 rc1=$?
12368 wait
12369 if [ $rc1 != 0 ]; then
12370 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
12371 echo "$CMD0 &"
12372 cat "$te0"
12373 cat "$tlog"
12374 let numCANT=numCANT+1
12375 elif ! [ $crit $tsock ]; then
12376 $PRINTF "$OK\n"
12377 let numOK=numOK+1
12378 else
12379 $PRINTF "$FAILED\n"
12380 echo "$CMD0 &"
12381 cat "$te0"
12382 cat "$tlog"
12383 let numFAIL=numFAIL+1
12384 listFAIL="$listFAIL $N"
12385 fi
12386 fi # NUMCOND
12387 ;;
12388 esac
12389 PORT=$((PORT+1))
12390 N=$((N+1))
12391 #
12392 done <<<"
12393 # address fileopt addropts waitfor direction crit ADDR2
12394 unix-listen . . unixport . -e FILE:/dev/null
12395 unix-recvfrom . . unixport . -e FILE:/dev/null
12396 "
12397  
12398  
12399 # bug fix: SYSTEM address child process shut down parents sockets including
12400 # SSL connection under some circumstances.
12401 NAME=SYSTEM_SHUTDOWN
12402 case "$TESTS" in
12403 *%$N%*|*%functions%*|*%bugs%*|*%system%*|*%openssl%*|*%socket%*|*%$NAME%*)
12404 TEST="$NAME: SYSTEM address does not shutdown its parents addresses"
12405 # start an OpenSSL echo server using SYSTEM:cat
12406 # start an OpenSSL client that sends data
12407 # when the client recieves its data and terminates without error the test succeeded
12408 # in case of the bug the client issues an error like:
12409 # SSL_connect(): error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
12410 if ! eval $NUMCOND; then :; else
12411 tf="$td/test$N.stdout"
12412 te="$td/test$N.stderr"
12413 tdiff="$td/test$N.diff"
12414 da="test$N $(date) $RANDOM"
12415 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,cipher=aNULL,verify=0 SYSTEM:cat"
12416 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,cipher=aNULL,verify=0"
12417 printf "test $F_n $TEST... " $N
12418 $CMD0 >/dev/null 2>"${te}0" &
12419 pid0=$!
12420 waittcp4port $PORT 1
12421 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12422 rc1=$?
12423 kill $pid0 2>/dev/null; wait
12424 if [ $rc1 -ne 0 ]; then
12425 $PRINTF "$FAILED\n"
12426 echo "rc1=$rc1"
12427 echo "$CMD0 &"
12428 echo "$CMD1"
12429 cat "${te}0"
12430 cat "${te}1"
12431 numFAIL=$((numFAIL+1))
12432 listFAIL="$listFAIL $N"
12433 elif ! echo "$da" |diff - "${tf}1" >"$tdiff" 2>&1; then
12434 $PRINTF "$FAILED\n"
12435 echo "diff:"
12436 cat "$tdiff"
12437 echo "$CMD0 &"
12438 echo "$CMD1"
12439 cat "${te}0"
12440 cat "${te}1"
12441 numFAIL=$((numFAIL+1))
12442 listFAIL="$listFAIL $N"
12443 else
12444 $PRINTF "$OK\n"
12445 numOK=$((numOK+1))
12446 fi
12447 fi # NUMCOND
12448 ;;
12449 esac
12450 PORT=$((PORT+1))
12451 N=$((N+1))
12452  
12453  
12454 # test if TCP4-LISTEN with empty port arg terminates with error
12455 NAME=TCP4_NOPORT
12456 case "$TESTS" in
12457 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*)
12458 TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out"
12459 # run socat with TCP4-LISTEN with empty port arg. Check if it terminates
12460 # immediately with return code 1
12461 if ! eval $NUMCOND; then :; else
12462 tf="$td/test$N.stdout"
12463 te="$td/test$N.stderr"
12464 t0rc="$td/test$N.rc"
12465 tdiff="$td/test$N.diff"
12466 da="test$N $(date) $RANDOM"
12467 CMD0="$SOCAT $opts TCP4-LISTEN: /dev/null"
12468 printf "test $F_n $TEST... " $N
12469 { $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null
12470 pid0=$!
12471 sleep 1
12472 kill $pid0 2>/dev/null; wait
12473 if [ ! -f "$t0rc" ]; then
12474 $PRINTF "$FAILED\n"
12475 echo "no return code of CMD0 stored" >&2
12476 echo "$CMD0 &"
12477 cat "${te}0"
12478 numFAIL=$((numFAIL+1))
12479 listFAIL="$listFAIL $N"
12480 elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then
12481 $PRINTF "$FAILED\n"
12482 echo "CMD0 exited with $(cat $t0rc), expected 1"
12483 echo "$CMD0 &"
12484 cat "${te}0"
12485 numFAIL=$((numFAIL+1))
12486 listFAIL="$listFAIL $N"
12487 else
12488 $PRINTF "$OK\n"
12489 numOK=$((numOK+1))
12490 fi
12491 fi # NUMCOND
12492 ;;
12493 esac
12494 PORT=$((PORT+1))
12495 N=$((N+1))
12496  
12497  
12498 # test if the various SSL methods can be used with OpenSSL
12499 # DTLS1 hangs on Fedora-20
12500 for method in SSL3 SSL23 TLS1 TLS1.1 TLS1.2; do
12501 #for method in SSL3 SSL23 TLS1 TLS1.1 TLS1.2 DTLS1; do
12502  
12503 NAME=OPENSSL_METHOD_$method
12504 case "$TESTS" in
12505 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12506 TEST="$NAME: test OpenSSL method $method"
12507 # Start a socat process listening with OpenSSL and echoing data,
12508 # using the selected method
12509 # Start a second socat process connecting to the listener using
12510 # the same method, send some data and catch the reply.
12511 # If the reply is identical to the sent data the test succeeded.
12512 if ! eval $NUMCOND; then :; else
12513 tf="$td/test$N.stdout"
12514 te="$td/test$N.stderr"
12515 tdiff="$td/test$N.diff"
12516 da="test$N $(date) $RANDOM"
12517 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,method=$method,cipher=aNULL,verify=0 PIPE"
12518 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,method=$method,cipher=aNULL,verify=0"
12519 printf "test $F_n $TEST... " $N
12520 $CMD0 >/dev/null 2>"${te}0" &
12521 pid0=$!
12522 waittcp4port $PORT 1
12523 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12524 rc1=$?
12525 kill $pid0 2>/dev/null; wait
12526 if echo "$da" |diff - "${tf}1"; then
12527 $PRINTF "$OK\n"
12528 numOK=$((numOK+1))
12529 else
12530 $PRINTF "$FAILED\n"
12531 echo "$CMD0 &"
12532 echo "$CMD1"
12533 cat "${te}0"
12534 cat "${te}1"
12535 numFAIL=$((numFAIL+1))
12536 listFAIL="$listFAIL $N"
12537 fi
12538 fi # NUMCOND
12539 ;;
12540 esac
12541 PORT=$((PORT+1))
12542 N=$((N+1))
12543  
12544 done
12545  
12546  
12547 # test if option fdout in write only context issues an error
12548 NAME=FDOUT_ERROR
12549 case "$TESTS" in
12550 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
12551 TEST="$NAME: fdout bails out in write-only context"
12552 # use EXEC in write-only context with option fdout. Expected behaviour: error
12553 if ! eval $NUMCOND; then :; else
12554 tf="$td/test$N.stdout"
12555 te="$td/test$N.stderr"
12556 tdiff="$td/test$N.diff"
12557 da="test$N $(date) $RANDOM"
12558 CMD="$SOCAT $opts -u /dev/null EXEC:cat,fdout=1"
12559 printf "test $F_n $TEST... " $N
12560 $CMD >/dev/null 2>"${te}"
12561 rc=$?
12562 if [ $rc -eq 1 ]; then
12563 $PRINTF "$OK\n"
12564 numOK=$((numOK+1))
12565 else
12566 $PRINTF "$FAILED\n"
12567 echo "$CMD"
12568 cat "${te}"
12569 echo "command did not terminate with error!"
12570 numFAIL=$((numFAIL+1))
12571 listFAIL="$listFAIL $N"
12572 fi
12573 fi # NUMCOND
12574 ;;
12575 esac
12576 PORT=$((PORT+1))
12577 N=$((N+1))
12578  
12579  
12580 ###############################################################################
12581 # here come tests that might affect your systems integrity. Put normal tests
12582 # before this paragraph.
12583 # tests must be explicitely selected by roottough or name (not number)
12584  
12585 NAME=PTYGROUPLATE
12586 case "$TESTS" in
12587 *%roottough%*|*%$NAME%*)
12588 TEST="$NAME: pty with group-late works on pty"
12589 # up to socat 1.7.1.1 address pty changed the ownership of /dev/ptmx instead of
12590 # the pty with options user-late, group-late, or perm-late.
12591 # here we check for correct behaviour.
12592 # ATTENTION: in case of failure of this test the
12593 # group of /dev/ptmx might be changed!
12594 if ! eval $NUMCOND; then :; else
12595 # save current /dev/ptmx properties
12596 F=
12597 for f in /dev/ptmx /dev/ptc; do
12598 if [ -e $f ]; then
12599 F=$(echo "$f" |tr / ..)
12600 ls -l $f >"$td/test$N.$F.ls-l"
12601 break
12602 fi
12603 done
12604 printf "test $F_n $TEST... " $N
12605 if [ -z "$F" ]; then
12606 echo -e "${YELLOW}no /dev/ptmx or /dev/ptc${NORMAL}"
12607 else
12608 GROUP=daemon
12609 tf="$td/test$N.stdout"
12610 te="$td/test$N.stderr"
12611 tl="$td/test$N.pty"
12612 tdiff="$td/test$N.diff"
12613 da="test$N $(date) $RANDOM"
12614 CMD0="$TRACE $SOCAT $opts pty,link=$tl,group-late=$GROUP,escape=0x1a PIPE"
12615 CMD1="$TRACE $SOCAT $opts - $tl,raw,echo=0"
12616 $CMD0 >/dev/null 2>"${te}0" &
12617 pid0=$!
12618 waitfile $tl
12619 (echo "$da"; usleep $MICROS; echo -e "\x1a") |$CMD1 >"${tf}1" 2>"${te}1" >"$tf"
12620 rc1=$?
12621 usleep $((2*MICROS))
12622 kill $pid0 2>/dev/null; wait
12623 if [ $rc1 -ne 0 ]; then
12624 $PRINTF "$FAILED\n"
12625 echo "$CMD0 &"
12626 echo "$CMD1"
12627 cat "${te}0"
12628 cat "${te}1"
12629 numFAIL=$((numFAIL+1))
12630 listFAIL="$listFAIL $N"
12631 elif echo "$da" |diff - "$tf" >$tdiff; then
12632 $PRINTF "$OK\n"
12633 numOK=$((numOK+1))
12634 else
12635 $PRINTF "$FAILED\n"
12636 cat "$tdiff"
12637 numFAIL=$((numFAIL+1))
12638 listFAIL="$listFAIL $N"
12639 fi
12640 if ! ls -l $f |diff "$td/test$N.$F.ls-l" -; then
12641 $PRINTF "${RED}this test changed properties of $f!${NORMAL}\n"
12642 fi
12643 fi # no /dev/ptmx
12644 fi # NUMCOND
12645 ;;
12646 esac
12647 N=$((N+1))
12648  
12649  
12650 NAME=FD_BI_WRITE
12651 case "$TESTS" in
12652 *%$N%*|*%functions%*|*%chain%*|*%$NAME%*)
12653 TEST="$NAME: FD address in birectional context is"
12654 testecho "$N" "$TEST" "FD:0" "FD:1" "-T 2 $opts" "$val_t"
12655 esac
12656 N=$((N+1))
12657  
12658  
12659 # in version 2.0.0-b7 (and earlier?) dual type addresses terminated when for
12660 # a short time no data was transferred (EOF-timeout)
12661 NAME=DUAL_IDLE
12662 case "$TESTS" in
12663 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
12664 TEST="$NAME: do dual type addresses survive idle phases"
12665 # use a dual type address and check if it transfers data after some idle time
12666 if ! eval $NUMCOND; then :; else
12667 tf="$td/test$N.stdout"
12668 te="$td/test$N.stderr"
12669 tdiff="$td/test$N.diff"
12670 da="test$N $(date) $RANDOM"
12671 CMD0="$SOCAT $opts TCP-LISTEN:$PORT;reuseaddr PIPE"
12672 CMD1="$SOCAT $opts STDOUT%STDIN TCP-CONNECT:$LOCALHOST:$PORT"
12673 printf "test $F_n $TEST... " $N
12674 $CMD0 >/dev/null 2>"${te}0" &
12675 pid0=$!
12676 waittcp4port $PORT 1
12677 (sleep 1; echo "$da") |$CMD1 >"${tf}0" 2>"${te}1"
12678 rc1=$?
12679 kill $pid0 2>/dev/null; wait
12680 if echo "$da" |diff - "${tf}0" >"${tdiff}"; then
12681 $PRINTF "$OK\n"
12682 numOK=$((numOK+1))
12683 else
12684 $PRINTF "$FAILED\n"
12685 echo "$CMD0 &"
12686 echo "$CMD1"
12687 cat "${te}0"
12688 cat "${te}1"
12689 cat "$tdiff"
12690 numFAIL=$((numFAIL+1))
12691 listFAIL="$listFAIL $N"
12692 fi
12693 fi # NUMCOND
12694 ;;
12695 esac
12696 PORT=$((PORT+1))
12697 N=$((N+1))
12698  
12699  
12700 echo "summary: $((N-1)) tests, $((numOK+numFAIL+numCANT)) selected; $numOK ok, $numFAIL failed, $numCANT could not be performed"
12701  
12702 if [ "$numFAIL" -gt 0 ]; then
12703 echo "FAILED: $listFAIL"
12704 exit 1
12705 fi
12706 exit 0
12707  
12708 #==============================================================================
12709  
12710 rm -f testsrv.* testcli.* testsrvdsa* testsrvfips* testclifips*
12711  
12712 # end
12713  
12714 # too dangerous - run as root and having a shell problem, it might purge your
12715 # file systems
12716 #rm -r "$td"
12717  
12718 # sometimes subprocesses hang; we want to see this
12719 wait
12720  
12721 exit
12722  
12723 # test template
12724  
12725 # give a description of what is tested (a bugfix, a new feature...)
12726 NAME=SHORT_UNIQUE_TESTNAME
12727 case "$TESTS" in
12728 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
12729 TEST="$NAME: give a one line description of test"
12730 # describe how the test is performed, and what's the success criteria
12731 if ! eval $NUMCOND; then :; else
12732 tf="$td/test$N.stdout"
12733 te="$td/test$N.stderr"
12734 tdiff="$td/test$N.diff"
12735 da="test$N $(date) $RANDOM"
12736 CMD0="$TRACE $SOCAT $opts server-address PIPE"
12737 CMD1="$TRACE $SOCAT $opts - client-address"
12738 printf "test $F_n $TEST... " $N
12739 $CMD0 >/dev/null 2>"${te}0" &
12740 pid0=$!
12741 wait<something>port $xy 1
12742 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12743 rc1=$?
12744 kill $pid0 2>/dev/null; wait
12745 if [ !!! ]; then
12746 $PRINTF "$OK\n"
12747 numOK=$((numOK+1))
12748 else
12749 $PRINTF "$FAILED\n"
12750 echo "$CMD0 &"
12751 echo "$CMD1"
12752 cat "${te}0"
12753 cat "${te}1"
12754 numFAIL=$((numFAIL+1))
12755 listFAIL="$listFAIL $N"
12756 fi
12757 fi # NUMCOND
12758 ;;
12759 esac
12760 #PORT=$((PORT+1))
12761 N=$((N+1))