Raspberry Pi 4 Model B Rev 1.2
Openwrt 21.02.3 r16554-1d4dea6d4f / LuCI openwrt-21.02 branch git-22.213.35964-87836ca
Setup with only using the one network connection and a manageable switch, so my wan and lan are both vlan’s and not physical ones.
My problem;
When I disconnect the wan cable from my modem, my router doesn’t see this and stays up. Offcourse with loss of the internet connection.
I do have a backup wwan that becomes my default wan (by vpn-policy-routing) thanks to @trendySee this threat but because my router doesn’t see the disconnect it doesn’t switch from wan to wwan,
When I manually stop the wan interface, it goes to wwan perfectly.
There is no way for the Pi to be aware that the link has gone down on your wired WAN if it is connected through a switch. There is nothing you can do about this since the Pi has no way to obtain the link-down information.
You will have to use a watchdog type script to determine when that link has gone down -- it is possible your switch can be queried about the status of that port -- check the switch documentation.
The best way to handle your situation would be to make a direct connection to the Pi -- you could do this using a USB-ethernet dongle for your WAN. This way the dongle can report directly to the Pi and you can trigger on ifup/ifdown/hotplug events.
I have no vested interest in suggesting this particular adapter, but he TP-Link UE300 has been pretty well regarded in the OpenWrt + Pi4 setups because it can sustain 1Gbps and has drivers available in the OpenWrt repo. I cannot speak to latency, but certainly the overall bandwidth performance of this device is considered more that sufficient.
#!/bin/sh
while false; do
if ping -c 1 1.1.1.1 &> /dev/null
then
Do nothing?
else
Ifdown wan
fi
sleep 900 && ifup wan (and if it succeeds) && sleep 10 && ifdown wwan && ifup wwan &
done
Not really a clu what I’m doing
But the idea is that there is a ping check on wan, if it is there, it’s ok. (Or a few pings)
If the ping is false than take the interface wan down (then my backup wwan kicks in, that allready works when I manually stop the wan interface)
After some time (say 15 minutes) ifup wan, if successful, restart wwan after 10 seconds (to reset my Wireguard vpn, otherwise it stays on my wwan, by a restart it goes back to the wan interface)
If not successful do nothing so wwan stays default.
An idea I have is to use the custom scripts in mwan3. When wan is detected as connected and switches over as primary to run a script to remove the static route for the wireguard endpoint and add it again via the wan interface.
It works fine when there is a manual ifdown on wan. But when there is a disconnect (in mwan3) nothing happens. Mwan3 tells me that wan is offline and wwan is online, but there is no route.
Any idea what the cli command is to flush the default route. I assume that a ifup event on wwan makes a new one.
So flush default route on disconnect wan, then ifup wwan and flush default route on connect wan and then ifup wan.
You don't need to delete the default route and you probably won't achieve much like this.
Just to remove the route to the wireguard server is enough. Then wireguard will recreate it via the wan interface.
When I manually ifdown wan / ifup wan it works flawlessly, so I thought, It only does not work at disconnecting the wan cable. I noticed that 'disconnected' and 'connected' was logged.
So when I disconnected the cable, waiting for the disconnected moment and then manual 'restart' the wan interface in Luci it al worked.
So now I have this little script in place in /etc/mwan3.user. so just the ifup (restart in Luci) command
#!/bin/sh
if [ "${ACTION}" = "disconnected" ] && [ "${INTERFACE}" = "wan" ] ; then
ifup wan
fi
I think because of the ifup, that offcourse is not working, because there is no connection, the routing goes through wwan.
maybe there is a better / cleaner way to do this, but it works. And it is not the case that my wan connection drops every 2 days. (but when it happens I'm not there offcourse)