From c872189d666f92a1611cd389a1a1f0eb2ae880df Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 4 Aug 2017 13:23:39 +0200 Subject: [PATCH] net/mwan3: add hotplug script for hidden self interface generation Add new globals config section with option local_source. With this config option the self interface generation will be done now automatically on hotplug event. You can specify which interface (ip) sould be used for router traffic. To replace the self intereface in the config set local_source to "lan". The default option is none, so it will not change default behavior if a "self" interface is configured in the network section. Signed-off-by: Florian Eckert --- net/mwan3/files/etc/hotplug.d/iface/14-mwan3 | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 net/mwan3/files/etc/hotplug.d/iface/14-mwan3 diff --git a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 new file mode 100644 index 000000000..1ddf0acca --- /dev/null +++ b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 @@ -0,0 +1,45 @@ +#!/bin/sh + +. /lib/functions.sh +. /lib/mwan3/mwan3.sh +. /lib/functions/network.sh + +[ "$ACTION" = "ifup" -o "$ACTION" = "ifdown" ] || exit 1 +[ -n "$INTERFACE" ] || exit 2 + +if [ "$ACTION" = "ifup" ]; then + [ -n "$DEVICE" ] || exit 3 +fi + +config_load mwan3 +config_get local_source globals local_source 'none' +[ "${local_source}" = "none" ] && { + exit 0 +} + +[ "${local_source}" = "$INTERFACE" ] || { + exit 0 +} + +mwan3_lock +src_ip=$(uci -q -P /var/state get mwan3.globals.src_ip 2>/dev/null) +[ "${src_ip}" != "" ] && { + ip route del default via "${src_ip}" dev lo 1>/dev/null 2>&1 + ip addr del "${src_ip}/32" dev lo 1>/dev/null 2>&1 +} + +usleep 10000 + +[ "$ACTION" = "ifup" ] && { + network_get_ipaddr src_ip "${local_source}" + if [ "${src_ip}" = "" ]; then + $LOG warn "Unable to set source ip for own initiated traffic (${local_source})" + else + ip addr add "${src_ip}/32" dev lo + ip route add default via "${src_ip}" dev lo + uci -q -P /var/state set mwan3.globals.src_ip="${src_ip}" + fi +} +mwan3_unlock + +exit 0