Script if mwan3 WAN "offline" switch interface and restart the offline interface?

Hello!

I have been troubleshooting issues using mwan3 and wireguard and I think I have identified one of my problems.

I have 2 WANs - WAN (ethernet) and UWAN (usb tether).

I reboot OpenWrt and I am connected to WAN and WireGuard is working (I have rules set in mwan3 to point one local lan address to the tunnel).

I disconnect the ethernet cable on WAN and UWAN picks up the routing, except WireGuard doesn't work. It will try and transmit packets, but none are received. At this point if I ifdown WAN WireGuard instantly comes back to life using UWAN.

When I perform the same scenario in reverse, I start with UWAN connected using WireGuard, everything is working, I plug WAN back in and pull the USB from UWAN, it looses its IP and is "down" on its own.

However, this got me thinking, if a mwan3 thinks an interface is down, unless that interface is ifdown'd, WireGuard won't reconnect using the up interface.

What I would like to do is run a script when mwan3 changes the interface, to automatically ifdown the interface it switched from, wait 10 seconds and then ifup. That way if a device is turned off, or has its cord pulled, or is getting no ping back, WireGuard will switch to the working interface.

I really hope this makes sense!

1 Like

Does wireguard-watchdog help with this?

I will look but I know restarting the wg interface does not fix it either. Only ifdown wan makes it move. :frowning:

Just in case anyone else has this problem, it seems to be associated with the fact that WAN is actually eth0.2, or a virtual adapter (I think).

Regardless, in /etc/hotplug.d/iface/15-mwan I added the following lines -

...
mwan3_set_user_rules
mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
ifdown $INTERFACE
sleep 8
ifup $INTERFACE
$LOG notice "Recycled $INTERFACE..."

;;

This works perfectly as it actually downs the WAN connection and WG to allow WG to re-establish on the active WAN. I will just have to remember I did this anytime I update :open_mouth:

1 Like