Re: closing half-open connections

Mike Khaw (teknowledge-vaxc!
1 Oct 87 07:22:15 GMT

Here's a /bin/sh driven adb script posted to the net a while back that
forces a socket to close:

<--- cut here --->
#! /bin/sh

# original from cdjohns@NSWC-G.ARPA
# TIMETODEATH expressed in decimal instead of hex
# --

# Use this script to force sockets in FIN_WAIT_2 state to close.
# It works by setting the 2MSL timer in the TCP Protocol Control Block (PCB)
# to a non-zero value. The kernel then begins to decrement this value until
# it reaches zero, at which point the kernel forces a close on the socket and
# deletes the TCP PCB. If both sides of the connection are hung, clearing one
# side will possibly clear the other.

# MSLOFFSET is the offset in the tcpcb record for the 2MSL timer.
# <netinet/tcp_var.h> describes the tcpcb record.
# This value is the number of bytes offset, expressed in hexadecimal.


# TIMETODEATH is the number of half seconds until the connection is
# closed. This value is expressed in decimal and must be greater
# than zero.


# Display netstat to get PCB addresses (first column).
echo 'Active connections
PCB Proto Recv-Q Send-Q Local Address Foreign Address (state)'
netstat -A | fgrep FIN_WAIT_2

echo -n 'PCB address to terminate? '
read addr

# Use adb on kernel to display the PCB of the specified address
adb -k /vmunix /dev/mem << SHAR_EOF

# Check to see if this was the correct address and PCB. state should be
# 8 for LAST_ACK, 9 for FIN_WAIT_2
echo 'state = 9 = FIN_WAIT_2'
echo -n 'Is this the correct PCB (y/n)? '
read ans
case $ans in
        echo 'No Changes.'

# Use adb on kernel to set the 2MSL timer for the PCB
adb -k -w /vmunix /dev/mem << SHAR_EOF

# Use these lines in place of the above for testing the script.
#adb -k /vmunix /dev/mem << SHAR_EOF

echo 'Connection will be terminated in `expr $TIMETODEATH / 2` seconds.'
<--- cut here --->

Mike Khaw

usenet:	   {uunet|sun|ucbvax|decwrl|uw-beaver}!
USnail:	   Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

This archive was generated by hypermail 2.0b3 on Thu Mar 09 2000 - 14:39:34 GMT