Fix for TCP disconnects triggered by short DHCP WAN leases

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Author Message
saahbs
DD-WRT Novice


Joined: 14 Dec 2014
Posts: 2

PostPosted: Sun Dec 14, 2014 1:05    Post subject: Fix for TCP disconnects triggered by short DHCP WAN leases Reply with quote
I have "DD-WRT v24-sp2 (03/25/13) std - build 21061" running on "TPLINK TL-WDR4300 v1 " on DMZ behind an Uverse modem.

Uverse DMZ hands out DHCP leases for 10min. This causes my TCP sessions behind dd-wrt to get disconnected. I eventually traced it to /tmp/udhcpc helper flusing the conntrack tables upon receiving new lease.

True fix for this problem would involve not deconfiguring and flushing conntrack tables until a new DHCP lease with a DIFFERENT IP is received. Until then, conntrack should be untouched.

To work around this, I created a replacement /tmp/udhcpc. Upon receiving a lease with new IP address, it restarts the udhcpc deamon and disables itself until after the real helper runs. All activity is logged to /tmp/udhcpc.debug.

To enable, install this startup script:

create_udhcpc () {
rm /tmp/udhcpc
cat <<'EOF' > /tmp/udhcpc
#!/bin/sh

DFN=/tmp/udhcpc.debug
SCRIPT=/tmp/udhcpc
IP=/tmp/udhcpc.ip
EXPIRE=/tmp/udhcpc.expires
DHCPPID=/var/run/udhcpc.pid
FORREAL=/tmp/udhcpc.forreal

run () {

# log invocation
echo ''
date
echo -n 'arguments: '
echo $*
env

export OLDIP=$(cat $IP)
export PID=$(cat $DHCPPID)

# real IP change
if [ -e $FORREAL ]; then
echo 'Running for-real'
if [ $1 = 'bound' ]; then
echo "Got IP: $ip"
echo $ip > $IP
rm $FORREAL
echo "Will exit for-real mode"
fi;
echo "Running real udhcpc with: $*"
/tmp/orig/udhcpc $*
exit 0
fi

# WAN dhcp state change wrapper
if [ $1 = 'bound' ]; then
echo $(cat /proc/uptime) "0 and + $lease + p" | dc > $EXPIRE
if [ "$ip" != "$OLDIP" ]; then
echo 'Changed IP: restarting udhcpc daemon'
touch $FORREAL
rm $DHCPPID
sh -c "sleep 2; udhcpc -i $interface -p $DHCPPID -s $SCRIPT -H ddwrt" &> /dev/null &
kill -9 $PID
exit 0
else
echo 'IP Not Changed: no-op.'
fi;
else
echo 'Ignoring invocation.'
fi

}

# control log file size
cat $DFN | tail -n 200 > $DFN.short
mv $DFN.short $DFN

# log the run
run $* 2>&1 >> $DFN

exit 0
EOF
chmod 755 /tmp/udhcpc

# first run is for-real!
touch /tmp/udhcpc.forreal

# provide original udhcpc handler
rm -f /tmp/orig/udhcpc
mkdir -p /tmp/orig/
ln -s /sbin/rc /tmp/orig/udhcpc
}

create_udhcpc
Sponsor
<Kong>
DD-WRT Guru


Joined: 15 Dec 2010
Posts: 4339
Location: Germany

PostPosted: Sun Dec 14, 2014 11:05    Post subject: Re: Fix for TCP disconnects triggered by short DHCP WAN leas Reply with quote
saahbs wrote:
I have "DD-WRT v24-sp2 (03/25/13) std - build 21061" running on "TPLINK TL-WDR4300 v1 " on DMZ behind an Uverse modem.

Uverse DMZ hands out DHCP leases for 10min. This causes my TCP sessions behind dd-wrt to get disconnected. I eventually traced it to /tmp/udhcpc helper flusing the conntrack tables upon receiving new lease.

True fix for this problem would involve not deconfiguring and flushing conntrack tables until a new DHCP lease with a DIFFERENT IP is received. Until then, conntrack should be untouched.

To work around this, I created a replacement /tmp/udhcpc. Upon receiving a lease with new IP address, it restarts the udhcpc deamon and disables itself until after the real helper runs. All activity is logged to /tmp/udhcpc.debug.

To enable, install this startup script:

create_udhcpc () {
rm /tmp/udhcpc
cat <<'EOF' > /tmp/udhcpc
#!/bin/sh

DFN=/tmp/udhcpc.debug
SCRIPT=/tmp/udhcpc
IP=/tmp/udhcpc.ip
EXPIRE=/tmp/udhcpc.expires
DHCPPID=/var/run/udhcpc.pid
FORREAL=/tmp/udhcpc.forreal

run () {

# log invocation
echo ''
date
echo -n 'arguments: '
echo $*
env

export OLDIP=$(cat $IP)
export PID=$(cat $DHCPPID)

# real IP change
if [ -e $FORREAL ]; then
echo 'Running for-real'
if [ $1 = 'bound' ]; then
echo "Got IP: $ip"
echo $ip > $IP
rm $FORREAL
echo "Will exit for-real mode"
fi;
echo "Running real udhcpc with: $*"
/tmp/orig/udhcpc $*
exit 0
fi

# WAN dhcp state change wrapper
if [ $1 = 'bound' ]; then
echo $(cat /proc/uptime) "0 and + $lease + p" | dc > $EXPIRE
if [ "$ip" != "$OLDIP" ]; then
echo 'Changed IP: restarting udhcpc daemon'
touch $FORREAL
rm $DHCPPID
sh -c "sleep 2; udhcpc -i $interface -p $DHCPPID -s $SCRIPT -H ddwrt" &> /dev/null &
kill -9 $PID
exit 0
else
echo 'IP Not Changed: no-op.'
fi;
else
echo 'Ignoring invocation.'
fi

}

# control log file size
cat $DFN | tail -n 200 > $DFN.short
mv $DFN.short $DFN

# log the run
run $* 2>&1 >> $DFN

exit 0
EOF
chmod 755 /tmp/udhcpc

# first run is for-real!
touch /tmp/udhcpc.forreal

# provide original udhcpc handler
rm -f /tmp/orig/udhcpc
mkdir -p /tmp/orig/
ln -s /sbin/rc /tmp/orig/udhcpc
}

create_udhcpc


This bug has been fixed long time ago, not sure why you don't upgrade to latest release, since you revision has a few security issues.
saahbs
DD-WRT Novice


Joined: 14 Dec 2014
Posts: 2

PostPosted: Sun Dec 14, 2014 17:43    Post subject: Reply with quote
Hi Kong, thanks for the note. I used the ddwrt router database to find a supported firmware.

Are firmwares under the 'other downloads' link on the search results page tested, or are they just blind builds?

Which of these releases is considered well tested and stable?

http://dd-wrt.com/site/support/other-downloads?path=others%2Feko%2FBrainSlayer-V24-preSP2%2F2014%2F12-11-2014-r25628%2Ftplink_tl-wdr4300v1%2F

Thanks! and cheers for the good work. saahbs
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum