[Workaround] GL-AR150: No DHCP if LAN cable is not plugged during boot

Yeah, I'm puzzled as well, I patched the init script to show entry and no-carrier exit of dhcp_check() and, on an AR300M-Lite (with cable plugged in its single jack) I see it checking br-lan which is down has no carrier at first, then comes up.

$ diff -u dnsmasq.orig dnsmasq
--- dnsmasq.orig	2019-03-01 09:17:35.000000000 -0800
+++ dnsmasq	2019-03-01 09:17:35.000000000 -0800
@@ -65,12 +65,16 @@
 	local stamp="${BASEDHCPSTAMPFILE_CFG}.${ifname}.dhcp"
 	local rv=0
 
+	logger -t dnsmasq "Entry dhcp_check() $@"
+
 	[ -s "$stamp" ] && return $(cat "$stamp")
 
 	# If there's no carrier yet, skip this interface.
 	# The init script will be called again once the link is up
 	case "$(devstatus "$ifname" | jsonfilter -e @.carrier)" in
-		false) return 1;;
+		false)
+			logger -t dnsmasq "Exit dhcp_check() -- $ifname has no carrier"
+			return 1;;
 	esac
 
 	udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0

root@OpenWrt:~# logread | fgrep dnsmasq
Fri Mar  1 16:50:10 2019 user.notice dnsmasq: DNS rebinding protection is active, will discard upstream RFC1918 responses!
Fri Mar  1 16:50:10 2019 user.notice dnsmasq: Allowing 127.0.0.0/8 responses
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: started, version 2.80 cachesize 150
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: DNS service limited to local subnets
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth no-DNSSEC no-ID loop-detect inotify dumpfile
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain test
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain onion
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain localhost
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain local
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain invalid
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain bind
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: using local addresses only for domain lan
Fri Mar  1 16:50:11 2019 daemon.warn dnsmasq[773]: no servers found in /tmp/resolv.conf.auto, will retry
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: read /etc/hosts - 4 addresses
Fri Mar  1 16:50:11 2019 daemon.info dnsmasq[773]: read /tmp/hosts/dhcp.cfg01411c - 0 addresses
Fri Mar  1 16:50:18 2019 user.notice dnsmasq: Entry dhcp_check() br-lan
Fri Mar  1 16:50:18 2019 user.notice dnsmasq: Exit dhcp_check() -- br-lan has no carrier
Fri Mar  1 16:50:18 2019 daemon.info dnsmasq[773]: read /etc/hosts - 4 addresses
Fri Mar  1 16:50:18 2019 daemon.info dnsmasq[773]: read /tmp/hosts/dhcp.cfg01411c - 0 addresses
Fri Mar  1 16:50:19 2019 user.notice dnsmasq: Entry dhcp_check() br-lan
Fri Mar  1 16:50:22 2019 daemon.info dnsmasq[773]: exiting on receipt of SIGTERM
Fri Mar  1 16:50:22 2019 daemon.info dnsmasq[1229]: started, version 2.80 cachesize 150
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: DNS service limited to local subnets
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth no-DNSSEC no-ID loop-detect inotify dumpfile
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq-dhcp[1229]: DHCP, IP range 192.168.1.100 -- 192.168.1.249, lease time 12h
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain test
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain onion
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain localhost
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain local
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain invalid
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain bind
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: using local addresses only for domain lan
Fri Mar  1 16:50:23 2019 daemon.warn dnsmasq[1229]: no servers found in /tmp/resolv.conf.auto, will retry
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: read /etc/hosts - 4 addresses
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq-dhcp[1229]: read /etc/ethers - 0 addresses
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: read /etc/hosts - 4 addresses
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq[1229]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Fri Mar  1 16:50:23 2019 daemon.info dnsmasq-dhcp[1229]: read /etc/ethers - 0 addresses
1 Like

Looks like /etc/rc.local is too early

(again, this is an AR300M-Lite)

Fri Mar  1 17:26:35 2019 user.info kernel: [   10.301747] kmodloader: done loading kernel modules from /etc/modules.d/*
Fri Mar  1 17:26:35 2019 user.notice dnsmasq: DNS rebinding protection is active, will discard upstream RFC1918 responses!
Fri Mar  1 17:26:35 2019 user.notice dnsmasq: Allowing 127.0.0.0/8 responses
Fri Mar  1 17:26:36 2019 daemon.info dnsmasq[773]: started, version 2.80 cachesize 150

Fri Mar  1 17:26:39 2019 user.notice rc.local: Running rc.local

Fri Mar  1 17:26:41 2019 daemon.notice netifd: Interface 'lan' is enabled
Fri Mar  1 17:26:41 2019 daemon.notice netifd: Interface 'lan' is setting up now
Fri Mar  1 17:26:41 2019 kern.info kernel: [   18.144462] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
Fri Mar  1 17:26:41 2019 daemon.notice netifd: Interface 'lan' is now up

Fri Mar  1 17:26:41 2019 user.notice firewall: Reloading firewall due to ifup of lan (br-lan)

Fri Mar  1 17:26:43 2019 daemon.notice netifd: Network device 'eth0' link is up
Fri Mar  1 17:26:43 2019 daemon.notice netifd: bridge 'br-lan' link is up
Fri Mar  1 17:26:43 2019 daemon.notice netifd: Interface 'lan' has link connectivity
Fri Mar  1 17:26:43 2019 kern.info kernel: [   20.269103] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready

Fri Mar  1 17:26:44 2019 user.notice dnsmasq: Entry dhcp_check() br-lan

Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.255202] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Fri Mar  1 17:26:44 2019 daemon.notice netifd: Network device 'wlan0' link is up

Fri Mar  1 17:26:47 2019 daemon.info dnsmasq[773]: exiting on receipt of SIGTERM
Fri Mar  1 17:26:48 2019 daemon.info dnsmasq[1247]: started, version 2.80 cachesize 150

I tried to add

(sleep 30 && /etc/init.d/dnsmasq restart) &

to /etc/rc.local so that dnsmasq is definitely restarted when everything is finished. I did not plug a LAN cable until I was sure that everything was done. This also does not help. Dnsmasq restarts, but no IPv4 address via DHCP.

1 Like

Have you tried option force_link 1 in the LAN configuration?

This makes no sense though because the MT7620 has an internal switch between eth0 and the physical ports. eth0 always has carrier from the switch whether or not cable(s) are plugged in.

1 Like

Changes nothing. Still no DHCP range set in /var/etc/dnsmasq.conf.cfg01411c if the LAN cable is not plugged during boot.

Also still the same: After plugging and connecting via an IPv6 address (or with an IPv4 address set manually) and then restarting dnsmasq,

dhcp-range=set:lan,192.168.1.100,192.168.1.249,255.255.255.0,12h

appears in /var/etc/dnsmasq.conf.cfg01411c.

It looks like a configuration issue.
See the difference between --bind-interfaces and --bind-dynamic:
http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html

Diagnostics:

# Disconnect the link, reboot, then check
uci show dhcp
ip addr show dev br-lan
pgrep -a -f dnsmasq
netstat -lnp | grep dnsmasq

Workaround:
https://openwrt.org/docs/guide-user/base-system/hotplug

1 Like

Just to say this one more time: This happens on a completely fresh and unchanged OpenWrt installation!

The configuration is thus the default one:

root@OpenWrt:~# uci show dhcp
dhcp.@dnsmasq[0]=dnsmasq
dhcp.@dnsmasq[0].domainneeded='1'
dhcp.@dnsmasq[0].boguspriv='1'
dhcp.@dnsmasq[0].filterwin2k='0'
dhcp.@dnsmasq[0].localise_queries='1'
dhcp.@dnsmasq[0].rebind_protection='1'
dhcp.@dnsmasq[0].rebind_localhost='1'
dhcp.@dnsmasq[0].local='/lan/'
dhcp.@dnsmasq[0].domain='lan'
dhcp.@dnsmasq[0].expandhosts='1'
dhcp.@dnsmasq[0].nonegcache='0'
dhcp.@dnsmasq[0].authoritative='1'
dhcp.@dnsmasq[0].readethers='1'
dhcp.@dnsmasq[0].leasefile='/tmp/dhcp.leases'
dhcp.@dnsmasq[0].resolvfile='/tmp/resolv.conf.auto'
dhcp.@dnsmasq[0].nonwildcard='1'
dhcp.@dnsmasq[0].localservice='1'
dhcp.lan=dhcp
dhcp.lan.interface='lan'
dhcp.lan.start='100'
dhcp.lan.limit='150'
dhcp.lan.leasetime='12h'
dhcp.lan.dhcpv6='server'
dhcp.lan.ra='server'
dhcp.lan.ra_management='1'
dhcp.wan=dhcp
dhcp.wan.interface='wan'
dhcp.wan.ignore='1'
dhcp.odhcpd=odhcpd
dhcp.odhcpd.maindhcp='0'
dhcp.odhcpd.leasefile='/tmp/hosts/odhcpd'
dhcp.odhcpd.leasetrigger='/usr/sbin/odhcpd-update'
dhcp.odhcpd.loglevel='4'

The network bridge is up and running:

root@OpenWrt:~# ip addr show dev br-lan
5: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether e4:95:6e:44:a8:3a brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan
       valid_lft forever preferred_lft forever
    inet6 fd47:463e:b43a::1/60 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::e695:6eff:fe44:a83a/64 scope link 
       valid_lft forever preferred_lft forever

dnsmasq is started:

root@OpenWrt:~# pgrep -a -f dnsmasq
726 /usr/sbin/dnsmasq -C /var/etc/dnsmasq.conf.cfg01411c -k -x /var/run/dnsmasq/dnsmasq.cfg01411c.pid

Well, and for this one, I don't know what it means :wink: Columns aligned:

root@OpenWrt:~# netstat -lnp | grep dnsmasq
tcp    0    0    127.0.0.1:53                    0.0.0.0:*    LISTEN    726/dnsmasq
tcp    0    0    192.168.1.1:53                  0.0.0.0:*    LISTEN    726/dnsmasq
tcp    0    0    fe80::e695:6eff:fe44:a83a:53    :::*         LISTEN    726/dnsmasq
tcp    0    0    fd47:463e:b43a::1:53            :::*         LISTEN    726/dnsmasq
tcp    0    0    ::1:53                          :::*         LISTEN    726/dnsmasq
udp    0    0    127.0.0.1:53                    0.0.0.0:*              726/dnsmasq
udp    0    0    192.168.1.1:53                  0.0.0.0:*              726/dnsmasq
udp    0    0    fe80::e695:6eff:fe44:a83a:53    :::*                   726/dnsmasq
udp    0    0    fd47:463e:b43a::1:53            :::*                   726/dnsmasq
udp    0    0    ::1:53                          :::*                   726/dnsmasq
1 Like

slight off topic

does

/etc/init.d/network restart

restarts dnsmasq too ?

@l3u

This happens on a completely fresh and unchanged OpenWrt installation!

meaning that on a fresh install everything works fine ? or dnsmasq is listening on all the interfaces ?

No, the fresh and untouched installation without any configuration file touched yet behaves like this: No DHCPv4 via LAN (and also not via WLAN if one enables it) if no LAN cable is plugged to the "LAN" port during boot.

That's why I filed a bug about this: This is imo a severe issue because the router lacks fundamental functionality after flashing OpenWrt!

okey @l3u

but correct me if I am wrong (I am mostly wrong, trying to understand openwrt from a zero background on routers and linux)

doesnt

root@OpenWrt:~# netstat -lnp | grep dnsmasq
tcp    0    0    127.0.0.1:53                    0.0.0.0:*    LISTEN    726/dnsmasq
tcp    0    0    192.168.1.1:53                  0.0.0.0:*    LISTEN    726/dnsmasq
tcp    0    0    fe80::e695:6eff:fe44:a83a:53    :::*         LISTEN    726/dnsmasq
tcp    0    0    fd47:463e:b43a::1:53            :::*         LISTEN    726/dnsmasq
tcp    0    0    ::1:53                          :::*         LISTEN    726/dnsmasq
udp    0    0    127.0.0.1:53                    0.0.0.0:*              726/dnsmasq
udp    0    0    192.168.1.1:53                  0.0.0.0:*              726/dnsmasq
udp    0    0    fe80::e695:6eff:fe44:a83a:53    :::*                   726/dnsmasq
udp    0    0    fd47:463e:b43a::1:53            :::*                   726/dnsmasq
udp    0    0    ::1:53                          :::*                   726/dnsmasq

means that dnsmasq is listening on br-lan (IMO both ethernet plug and wifi) ?

Yes, it does listen – only it does not offer IPv4 DHCP addresses. That's what this thread and the bug is all about :stuck_out_tongue:

slight off topic

1- does

/etc/init.d/network restart

restarts dnsmasq too ?

2- okey slowly trying to digest it

does the wifi client get authenticated (I suppose yes)

does the wifi client does everything it needs to do ?

does the ethernet LAN client does everything it needs to do ?

have you Inspected the packets between router and client ?

@Pippo It has been clearly and repeatedly established in multiple ways what is and is not running and when. It has been shown that the config file differs in a line directly related to DHCP. Perhaps if you have basic questions about the operation of OpenWrt they could be asked on your own thread. They are more than “slightly off topic” as you describe them, especially at this point in the thread.

With some coffee in me this morning, let me explain why. /etc/init.d/network is a shell script. Its behavior can be understood by reading the script, or, in your case of a single point of behavior, checked on your own device. The output of netstat does not show a listener for DHCP, so the wireless association or client behavior is irrelevant. If a DHCP server were running, you'd see a line such as

udp        0      0 0.0.0.0:67              0.0.0.0:*

@jeff sorry wasn’t trying to hijack the OP
Just trying to understand a bit more......

Port 53 DNS

Port 67 DHCP

I’ll try last one then start from scratch from

https://en.m.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol

Could the firewall interfere with the DHCP process ?

Thanks as always

I've tried to replicate on my AR300M-Lite. Boot with no Ethernet connected, wireless enabled. I was able to get a DHCP lease on connecting to the AP.

Logs don't show anything unexpectedly different (yes, this is today, early boot uses file-stamp for time, no NTP available to the device)

Fri Mar  1 17:26:35 2019 user.notice dnsmasq: DNS rebinding protection is active, will discard upstream RFC1918 responses!
Fri Mar  1 17:26:35 2019 user.notice dnsmasq: Allowing 127.0.0.0/8 responses
Fri Mar  1 17:26:36 2019 daemon.info dnsmasq[774]: started, version 2.80 cachesize 150

Fri Mar  1 17:26:39 2019 user.notice rc.local: Running rc.local
Fri Mar  1 17:26:41 2019 kern.info kernel: [   18.141954] br-lan: port 1(eth0) entered blocking state
Fri Mar  1 17:26:41 2019 kern.info kernel: [   18.147363] br-lan: port 1(eth0) entered disabled state
Fri Mar  1 17:26:41 2019 kern.info kernel: [   18.153105] device eth0 entered promiscuous mode
Fri Mar  1 17:26:41 2019 daemon.notice netifd: Interface 'lan' is enabled
Fri Mar  1 17:26:41 2019 kern.info kernel: [   18.172405] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
Fri Mar  1 17:26:41 2019 daemon.notice netifd: Interface 'lan' is setting up now
Fri Mar  1 17:26:41 2019 daemon.notice netifd: Interface 'lan' is now up

Fri Mar  1 17:26:42 2019 kern.info kernel: [   19.230347] eth1: link up (1000Mbps/Full duplex)
Fri Mar  1 17:26:42 2019 kern.info kernel: [   19.235158] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
Fri Mar  1 17:26:42 2019 daemon.notice netifd: Network device 'eth1' link is up

Fri Mar  1 17:26:42 2019 daemon.info procd: - init complete -

Fri Mar  1 17:26:44 2019 user.notice dnsmasq: Entry dhcp_check() br-lan
Fri Mar  1 17:26:44 2019 user.notice dnsmasq: Exit dhcp_check() -- br-lan has no carrier

Fri Mar  1 17:26:44 2019 daemon.err hostapd: Configuration file: /var/run/hostapd-phy0.conf
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.175712] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.212651] br-lan: port 2(wlan0) entered blocking state
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.218151] br-lan: port 2(wlan0) entered disabled state
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.224033] device wlan0 entered promiscuous mode
Fri Mar  1 17:26:44 2019 daemon.err hostapd: Using interface wlan0 with hwaddr e4:95:6e:4b:03:4c and ssid "OpenWrt"
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.273911] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.280718] br-lan: port 2(wlan0) entered blocking state
Fri Mar  1 17:26:44 2019 kern.info kernel: [   21.286210] br-lan: port 2(wlan0) entered forwarding state
Fri Mar  1 17:26:44 2019 daemon.notice hostapd: wlan0: interface state UNINITIALIZED->ENABLED
Fri Mar  1 17:26:44 2019 daemon.notice hostapd: wlan0: AP-ENABLED

Fri Mar  1 17:26:45 2019 user.notice dnsmasq: Entry dhcp_check() br-lan
Fri Mar  1 17:26:46 2019 daemon.notice netifd: wan (1128): udhcpc: sending discover
Fri Mar  1 17:26:48 2019 daemon.info dnsmasq[774]: exiting on receipt of SIGTERM
Fri Mar  1 17:26:48 2019 daemon.info dnsmasq[1314]: started, version 2.80 cachesize 150
Fri Mar  1 17:26:48 2019 daemon.info dnsmasq[1314]: DNS service limited to local subnets
Fri Mar  1 17:26:48 2019 daemon.info dnsmasq[1314]: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset 
no-auth no-DNSSEC no-ID loop-detect inotify dumpfile
Fri Mar  1 17:26:48 2019 daemon.info dnsmasq-dhcp[1314]: DHCP, IP range 192.168.1.100 -- 192.168.1.249, lease time 12h

[...]

Fri Mar  1 17:36:22 2019 daemon.info hostapd: wlan0: STA f0:18:98:aa:bb:cc IEEE 802.11: authenticated

Edit: With eth1 being "up" as something generally noteworthy, as the board doesn't populate an Ethernet socket for it.

The problem happens/shows up inside the dhcp_check() function of the init script. I added some debugging messages (similarily to what you did earlier) to find out what exactly happens.

In both cases (plugged/unplugged), this function is called only once, with $ifname set to "br-lan" and $stamp set to "/var/run/dnsmasq.cfg01411c.br-lan.dhcp".

If the LAN cable is plugged, the function completes and returns 0 at the end, which then results in the dhcp-range line being added to the config by dhcp_add().

If no LAN cable is plugged, the function returns at

# If there's no carrier yet, skip this interface.
# The init script will be called again once the link is up
case "$(devstatus "$ifname" | jsonfilter -e @.carrier)" in
    false) return 1;;
esac

This causes dhcp_add() to return before the dhcp-range line is added.

When the device boots up without a LAN cable plugged and one sets an IP address manually (or uses the IPv6 DHCP address which can be obtained in this case), logs in and runs

devstatus br-lan | jsonfilter -e @.carrier

it returns "true".

So I'm pretty sure that this is some hardware-specific timing problem or similar. I'm not deep enough into OpenWrt (yet), but it looks like the LAN bridge does not have a "carrier" without a LAN cable being plugged when it should have one.

2 Likes

What about:

opkg update
opkg list-upgradable
1 Like

https://openwrt.org/toh/gl.inet/gl-ar150

Are the interfaces right as per the page above ?

The list actually contains dnsmasq:

root@OpenWrt:~# opkg list-upgradable
...
dnsmasq - 2.80-1.2 - 2.80-1.4
...

I updated it, but it doesn't change anything. The behavior is still the same.

@Pippo: I'm not sure if I understand your question … yes, this is the router I'm talking about and apart of the WAN/LAN ports having a gray border instead of a yellow one, it looks exacly like the photos of the linked hardware page.

1 Like

Hi I have reported the same problem. I do have work around a service the stop and start the dnsmasq two calls. Reload will not work. I think the problem is in

reload_service() {
	rc_procd start_service "$@"
	procd_send_signal dnsmasq "$@"
}

This must start race problem with dhcp_check I think changing the order and adding sleep will solve the problem, as you could run in to real problems I have not tried it yet. I need to trace a little more.