From e142c3da6bba3e2e1ba79525a6f03721dae82a51 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Thu, 4 Sep 2008 23:30:59 +0200 Subject: [PATCH] dont leave UDP-LISTEN socket open after reject --- CHANGES | 4 ++++ VERSION | 2 +- test.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- xio-udp.c | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index ed3fa25..9c17a0d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ corrections: + when UDP-LISTEN continued to listen after packet dropped by, e.g., + range option, the old listen socket would not be closed but a new one + created. open sockets could accumulate. + there was a bug in ip*-recv with bind option: it did not bind, and with the first received packet an error occurred: socket_init(): unknown address family 0 diff --git a/VERSION b/VERSION index 2b6e1d9..5393aac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -"1.6.0.1+ip4bind+recvfromfork+x64+execstderr+execspaces+cosmetics+poll" +"1.6.0.1+ip4bind+recvfromfork+x64+execstderr+execspaces+cosmetics+poll+udplistencont" diff --git a/test.sh b/test.sh index 5846503..58b50d3 100755 --- a/test.sh +++ b/test.sh @@ -8032,9 +8032,9 @@ else numOK=$((numOK+1)) fi kill $pid1 2>/dev/null -wait ;; +wait +PORT="$_PORT" ;; esac -PORT="$_PORT" N=$((N+1)) @@ -8317,6 +8317,59 @@ esac N=$((N+1)) +# a bug was found in the way UDP-LISTEN handles the listening socket: +# when UDP-LISTEN continued to listen after a packet had been dropped by, e.g., +# range option, the old listen socket would not be closed but a new one created. +NAME=UDP4LISTENCONT +case "$TESTS" in +*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*) +TEST="$NAME: let range drop a packet and see if old socket is closed" +# idea: run a UDP4-LISTEN process with range option. Send it one packet from an +# address outside range and check if two listening sockets are open then +tf="$td/test$N.stdout" +te="$td/test$N.stderr" +tdiff="$td/test$N.diff" +while [ "$(netstat -an |grep "^udp.*127.0.0.1:$PORT" |wc -l)" -ne 0 ]; do + PORT=$((PORT+1)) +done +tp=$PORT +da1="test$N $(date) $RANDOM" +a1="$LOCALHOST" +a2="$SECONDADDR" +#CMD0="$SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE" +CMD0="$SOCAT $opts UDP4-LISTEN:$tp,range=$a2/32 PIPE" +CMD1="$SOCAT $opts - UDP-CONNECT:$a1:$tp" +printf "test $F_n $TEST... " $N +$CMD0 >/dev/null 2>"${te}0" & +pid1=$! +waitudp4port $tp 1 +echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail +rc1=$? +waitudp4port $tp 1 +nsocks="$(netstat -an |grep "^udp.*[:.]$PORT" |wc -l)" +kill $pid1 2>/dev/null; wait +if [ $rc1 -ne 0 ]; then + $PRINTF "$NO_RESULT\n" + numCANT=$((numCANT+1)) +elif [ $nsocks -eq 0 ]; then + $PRINTF "$NO_RESULT\n" + numCANT=$((numCANT+1)) +elif [ $nsocks -ne 1 ]; then + $PRINTF "$FAILED ($nsocks listening sockets)\n" + echo "$CMD0 &" + echo "$CMD1" + cat "${te}0" "${te}1" + numFAIL=$((numFAIL+1)) +else + $PRINTF "$OK\n" + if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi + numOK=$((numOK+1)) +fi ;; +esac +PORT=$((PORT+1)) +N=$((N+1)) + + echo "summary: $((N-1)) tests; $numOK ok, $numFAIL failed, $numCANT could not be performed" if [ "$numFAIL" -gt 0 ]; then diff --git a/xio-udp.c b/xio-udp.c index 8cedcff..64cf04a 100644 --- a/xio-udp.c +++ b/xio-udp.c @@ -231,6 +231,7 @@ int xioopen_ipdgram_listen(int argc, const char *argv[], struct opt *opts, /* drop packet */ char buff[512]; Recv(fd->stream.fd, buff, sizeof(buff), 0); + Close(fd->stream.fd); continue; } Info1("permitting UDP connection from %s",