Hotplug doesn't handle wan link down

Hi all,
I'm struggling to be notified when the wan interface face a link down state. Hotplug doesn't handle any ifdown in that scenario. I would like to avoid any pingchecker or watchdog approach.

Hm, I'm not 100% sure what you mean there exactly.

Is there something (like a program) that does a "ifdown wan" on your system/router and you want to monitor that? Or is the "wan" interface going down on its own (like when you physically unplug the ethernet cable on the WAN port) and you want to monitor that?

There is a big difference here. But this does heavily depend on what exact device you have and what configuration you have in mind. Because on some devices, the WAN and LAN interface share the same internal link to the switch chip. There, the individual physical connection "plug" and "unplug" events on the WAN/LAN ports don't get propagated to the "virtual lan" ethernet device.

You really need to specify what you are looking for.

Hi Chunkeey,
Thanks to clarify the situation.
I'm in the second scenario.
I'm setting up an hotspot with a captive portal and would like to handle wired and tethering wan.
As such I have a wan and wan2 interface with their respective metric.
wan has a lower metric.
When I remove the cable from the wan port the kernel display a link down message but hotplug is not notified.
However the interface is up, its previous dhcp address is still their and its 'uci -P /var/state -q get network.wan.up' is still set to one. I'm workaround the situation with pingchecker and got descent result.

I guess you are right eth0 got the link down while my wan is eth0.2. Still stuck.

Ah ok, I was about to say that LEDE (and OpenWRT for that matter) actually has a "multiwan" package that would maybe fit your "hot-plug" requirements: , , (etc... just google for multiwan and openwrt/lede).

In any case, you could monitor the eth0.2 link with the help of swconfig. This will look something like:

         # swconfig dev switch0 port 5 get link
         port:5 link:up speed:1000baseT full-duplex txflow rxflow auto

         (if port 5 is your wan port, it could be on another port as well)

Incidentally, I did run into a similar issue with my hardware. Although, I have do have a slightly different usecase than yours: I have the WAN bridged with several WLANs and since the bridge-interface doesn't know from which sub-interface the dhcp was issued, it would never register the unplug/replug and the dhcp lease got stale.

To that end, I wrote a linkwatch script that will poll the switch and specifically check the eth0.2 sub-interface of the br-(wan) bridge. You might be able to salvage some parts of it for your own project.

1 Like

Hi Christian,
Thanks for your input.
I tried mwan3 but with my captive portal setup it was not suitable
However I tried this morning swconfig and it fits nicely.
Here the shell I wrote to handle the situation:


wan_up=`uci -P /var/state -q get network.wan.up`

# MT300A specific
wan_status=`swconfig dev switch0 port 0 get link | sed -r 's/.*link:([[:alnum:]]*).*/\1/'`

# link down not triggered
if [ "$wan_status" == "down" ] && [ $wan_up == 1 ]
	ifdown wan
# link up not triggered
elif [ "$wan_status" == "up" ] && [ $wan_up == 0 ]
	ifup wan

Many thanks.