dont leave UDP-LISTEN socket open after reject

This commit is contained in:
Gerhard Rieger 2008-09-04 23:30:59 +02:00
parent a1c0e96592
commit e142c3da6b
4 changed files with 61 additions and 3 deletions

View file

@ -1,5 +1,9 @@
corrections: 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 there was a bug in ip*-recv with bind option: it did not bind, and
with the first received packet an error occurred: with the first received packet an error occurred:
socket_init(): unknown address family 0 socket_init(): unknown address family 0

View file

@ -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"

57
test.sh
View file

@ -8032,9 +8032,9 @@ else
numOK=$((numOK+1)) numOK=$((numOK+1))
fi fi
kill $pid1 2>/dev/null kill $pid1 2>/dev/null
wait ;; wait
PORT="$_PORT" ;;
esac esac
PORT="$_PORT"
N=$((N+1)) N=$((N+1))
@ -8317,6 +8317,59 @@ esac
N=$((N+1)) 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" echo "summary: $((N-1)) tests; $numOK ok, $numFAIL failed, $numCANT could not be performed"
if [ "$numFAIL" -gt 0 ]; then if [ "$numFAIL" -gt 0 ]; then

View file

@ -231,6 +231,7 @@ int xioopen_ipdgram_listen(int argc, const char *argv[], struct opt *opts,
/* drop packet */ /* drop packet */
char buff[512]; char buff[512];
Recv(fd->stream.fd, buff, sizeof(buff), 0); Recv(fd->stream.fd, buff, sizeof(buff), 0);
Close(fd->stream.fd);
continue; continue;
} }
Info1("permitting UDP connection from %s", Info1("permitting UDP connection from %s",