OpenWrt Forum Archive

Topic: dnsmasq lease renewal resets TCP connections

The content of this topic has been archived on 14 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have a Linksys WRTSL54GS running WR 0.9.  About once an hour, all my ssh sessions will reset.  The resets coincide with the following log messages:

Mar  5 21:54:00 (none) kern.info dnsmasq[795]: reading /tmp/resolv.conf.auto
Mar  5 21:54:00 (none) kern.info dnsmasq[795]: using nameserver 207.172.3.9#53
Mar  5 21:54:00 (none) kern.info dnsmasq[795]: using nameserver 207.172.3.8#53
Mar  5 21:54:00 (none) kern.info dnsmasq[795]: using local addresses only for domain lan

The problem seems very similar to the one discussed here: http://forum.openwrt.org/viewtopic.php?id=6434

But the suggested fix is not working for me.  I haven't tried yet to edit /usr/share/udhcpc/default.script.

Do I have something misconfigured?  Do I need to provide more info?  Any assistance would be much appreciated.

I have the same problem. 'logread' says the same. Client computers drop off  for short time all irc, MSN, etc connections.

What about 'dnsmasq -n' ? (-n or --no-poll = "Do NOT poll /etc/resolv.conf file, reload only on SIGHUP.")

I added some more logging to /usr/share/udhcpc/default.script to try to track why the disconnects are happening.  Basically any time the 'deconfig' target is called, all my active TCP connections drop.  It looks like this:

Mar 27 20:28:58 (none) user.notice root: ===> deconfig called by:
Mar 27 20:28:58 (none) user.notice root: ===>   PID  Uid     VmSize Stat Command
Mar 27 20:28:59 (none) user.notice root: ===>   576 root        380 S   udhcpc -i eth1 -b -p /var/run/eth1.pid -t 0 -R

Occasionally it does seem linked to dnsmasq updates of some sort:

Mar 27 17:48:59 (none) user.notice root: ===> deconfig called by:
Mar 27 17:48:59 (none) user.notice root: ===>   PID  Uid     VmSize Stat Command
Mar 27 17:48:59 (none) user.notice root: ===>   576 root        380 S   udhcpc -i eth1 -b -p /var/run/eth1.pid -t 0 -R 
Mar 27 17:48:59 (none) kern.info dnsmasq[690]: reading /tmp/resolv.conf.auto
Mar 27 17:48:59 (none) kern.info dnsmasq[690]: using nameserver 207.172.3.9#53
Mar 27 17:48:59 (none) kern.info dnsmasq[690]: using nameserver 207.172.3.8#53
Mar 27 17:48:59 (none) kern.info dnsmasq[690]: using local addresses only for domain lan

I haven't yet tried disabling the 'deconfig' target entirely, since I assume that the default udhcpc script works for most people.  How do I figure out why it's not working for me?  I assume there are side effects to disabling 'deconfig' but I don't know what they are.

You might check into hotplug.  On my router, a hotplug script was being executed each time my router renewed its dhcp lease.  The script is designed to reset my firewall upon iface events.  I modified the script slightly on only run when the IP address changes.  Perhaps you have something similar...

I have had this problem for a very long time with my WRT54GS. Everytime I stream media every hour when the DHCP renewed I'd lose the connection.

bene wrote:

I haven't yet tried disabling the 'deconfig' target entirely...

I went ahead and commented out the 'deconfig' target commands, and the router has been working great for the last few days with no TCP resets.

So should I consider this a long-term fix?  Can I retrieve some better information that would help fix this for everyone?

Some DHCP relays respond to the RENEW request with the broadcast address. Last I checked, this behavior is indeed RFC-compliant. I've encountered similar problems and fixed them by allowing

iptables        -A input_wan    -p udp --dport 68 -j ACCEPT

in /etc/firewall.user

The problem is indeed in "udhcpc". On every DHCP renewal, it calls an external script to do some stuff. Here is a snippet from "udhcpc --help":

-s,--script=file        Run file at DHCP events (default /usr/share/udhcpc/default.script)

So this file is run twice on DHCP renewal which triggers the following two events:
* deconfig - the wan interface is brought down
* renew|bond - the wan interface is brought up and IP configured

The above happens even if the IP does not change (which is not very clever).

All connections drop because OpenWRT uses MASQUERADE by default for NAT - MASQUERADE forgets old connections when interface goes down.

If your IP address does not change often, it's better to use SNAT which does not drop connections if the interface goes up/down for a short period of time and your IP address is still the same.

My solution was to use the hook which OpenWRT developers left in "/usr/share/udhcpc/default.script". On "renew|bond" if a user script named "/etc/udhcpc.user" exists, it is called. So here is what I put in "/etc/udhcpc.user":

#!/bin/bash

echo 'Custom SNAT (disabling default MASQUERADE which drops connections on every DHCP renewal)'
/usr/sbin/iptables -t nat -F zone_wan_nat
/usr/sbin/iptables -t nat -I zone_wan_nat -o "$interface" -j SNAT --to-source "$ip"

The discussion might have continued from here.