Hello,
I was trying to create a hotplug script to auto update the track ip I have on the lte interface in mwan3.
Does anyone more experienced than me with hotplug and scripts find anything wrong or that can be improved?
CHANGE_TRACK_IP="/root/bin/change_track_ip.sh"
if [ "${ACTION}" = "ifup" ]; then
if [ "${INTERFACE}" = "lte_4" ]; then
${CHANGE_TRACK_IP}
fi
fi
if [ "${ACTION}" = "ifupdate" ]; then
if [ "${INTERFACE}" = "lte_4" ]; then
${CHANGE_TRACK_IP}
fi
fi
While I don't have deeper knowledge about the network.sh internals and I'm far far away from being a pro. The scripts are looking good to me. So I only have one thing you could improve.
For /root/bin/change_track_ip.sh I would suggest to build in a check if the interface is actually up already to avoid an empty value for NET_GW/NET_ADDR. You could check before with something like:
if test -z "$NET_GW" # just checking if empty or not
then
sleep 10 # dev not yet up
else
**your script lines**
fi
--- or ---
while true; do
ethtool lte_4 | grep no | cut -d " " -f 3
if [ $? -eq 0 ]; then
sleep 10 # dev not yet up
else
**your script lines**
fi
done
That what just came in mind. I think there are functions available in network.sh or uci to check if an interface is up to make things nicer then this ugly way I've written down. But I don't have deeper knowledge about the network functions. Sorry. At least a small bump.
For /etc/hotplug.d/iface/97-change-lte-track-ip-mwan3 you could shorten things a bit to make it look nicer.
if [ "${ACTION}" = "ifup" ] && [ "${INTERFACE}" = "lte_4" ];
then
${CHANGE_TRACK_IP}
fi
if [ "${ACTION}" = "ifupdate" ] && [ "${INTERFACE}" = "lte_4" ];
then
${CHANGE_TRACK_IP}
fi
mwan3 is definately a tricky one... i'm surprised they dont have a built in uci-conf flag for use gw ip as track ip...
looking at it's internals... seems there are also some custom hooks points... so the mwan3 dev/s would know the best point to hook into the hotplug logix...
15-mwan3
16-mwan3-user > /etc/mwan3.user
( connected and disconnected internal track events are another complexity / consideration ) my gut tells me to run your logic pre 15-mwan3... but i'm probably wrong... the key concern being avoiding unnecessary service reload/restart aka chicken egg behavior... on that point... you could also likely only set/apply the uci-conf-val if it is different )
That would be nice and maybe @aaronjg would consider it as a future feature.
I thought about adding the script in /etc/mwan3.user but then it would be triggered on every interface event, no?
That sounds interesting, it might make sense to remove the last line from the script (to restart the mwan3 service) so by the time the 15-mwan3 is called, the tracking ip is already there. @pwned and @vgaetera I have squeezed down the hotplug rule according to your suggestions
Using network.sh functions as you do is a bit nicer of a solution than grepping the routing table, however it really should be done in the mwan3track script. Updating the uci script will cause a flash write every time a network is connected/disconnected, which is not ideal.
Yes, I didn't consider that much to be honest.
Then I'll let it be and wait for the commit from ptpt52 to be merged. Feel free to use my script if it is a more elegant way to identify the gateway.
Thank you all for your help!