I'm working on a travel router. I was configured with default setup from wireguard client - wireguard interface is in 'wan' zone and route_allowed_ips '1'
. It works ok - all traffic goes through wireguard. I need to be able to toggle wireguard via a sliding button on the side of the GL-MT300A. Below is my rc.button/BTN_1:
#!/bin/sh
#logger "the button was ${BUTTON} and the action was ${ACTION}"
WGIF="wg0"
if [ "$ACTION" = "released" ] && [ "$BUTTON" = "BTN_1" ];
then
logger "Wireguard off"
uci set network.${WGIF}.auto="0"
uci commit
/sbin/ifdown ${WGIF}
fi
if [ "$ACTION" = "pressed" ] && [ "$BUTTON" = "BTN_1" ];
then
logger "Wireguard on"
uci set network.${WGIF}.auto="1"
uci commit
/sbin/ifup ${WGIF}
fi
This works almost perfect. When I bring up wg0 I set auto '1' for it so it's brought up on next boot and conversly when I bring it down I set auto '0' and it won't start vpn on next boot. All fine and dandy. Issues arise when I disable wg0. It will drop wg0 interface, but it won't restore default route for wan interface and all the traffic will be stalled. I know I could just manually save the route to a file and restore it from file uppond disabling wg0, but I would like a more openwrt-idiomatic solution for this. Any way to restore those routes properly? Hardcoding them won't solve the problem - I have a dozen of crazy usb modems, radios etc that I want to act as wan on a whim and those routes will be different each time. My priority is fast enable/disable without restarting network and maximum leak prevention. I would like to avoid PBR at the moment.
I tried implementing routing all traffic but it has same issues and requires a lot more uci tweaking in firewall to remove forwards. I tried implementing this without route_allowed_ips '1'
but I don't think it's posisble without PBR which I don't want to bake into my custom image just yet (I initially mistakenly thought that forwarding rules add routes but this is not the case).
Guys, halp, frustration is eating me away