net/mwan3: on startup mark interface online only if track_ip are reachable

Add new interface config option "inital_state".

If interface comeing up the first time(mwan3 start, boot),
there are now two option for interface behaviour:

- online (default as is now)
  Set up interface regardless wether tracking ip are reachable or not.

- offline
  Set up interface first to ping tracking ip and if they are reachable set up
  the interface completely.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert
2017-07-24 10:59:50 +02:00
parent 6d99b602fd
commit 815e83d461
3 changed files with 35 additions and 10 deletions
+24 -6
View File
@@ -3,6 +3,7 @@
. /lib/functions.sh
. /lib/functions/network.sh
. /lib/mwan3/mwan3.sh
. /usr/share/libubox/jshn.sh
[ "$ACTION" == "ifup" -o "$ACTION" == "ifdown" ] || exit 1
[ -n "$INTERFACE" ] || exit 2
@@ -15,6 +16,7 @@ mwan3_set_connected_iptables
config_load mwan3
config_get enabled $INTERFACE enabled 0
config_get initial_state $INTERFACE initial_state "online"
[ "$enabled" == "1" ] || exit 0
if [ "$ACTION" == "ifup" ]; then
@@ -42,6 +44,17 @@ if [ "$ACTION" == "ifup" ]; then
[ -n "$gateway" ] || exit 9
fi
if [ "$initial_state" = "offline" ]; then
json_load "$(ubus call mwan3 status '{"section":"interfaces"}')"
json_select "interfaces"
json_select "${INTERFACE}"
json_get_var running running
json_get_var status status
else
status=online
running=1
fi
mwan3_lock
$LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})"
@@ -49,13 +62,18 @@ case "$ACTION" in
ifup)
mwan3_set_general_rules
mwan3_set_general_iptables
mwan3_create_iface_rules $INTERFACE $DEVICE
mwan3_create_iface_iptables $INTERFACE $DEVICE
mwan3_create_iface_route $INTERFACE $DEVICE
mwan3_track $INTERFACE $DEVICE ${src_ip}
mwan3_set_policies_iptables
mwan3_set_user_rules
mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
if [ ${running} -eq 1 -a "${status}" = "online" ]; then
mwan3_create_iface_rules $INTERFACE $DEVICE
mwan3_create_iface_route $INTERFACE $DEVICE
mwan3_track $INTERFACE $DEVICE ${src_ip} "online"
mwan3_set_policies_iptables
mwan3_set_user_rules
mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
else
$LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
mwan3_track $INTERFACE $DEVICE "offline"
fi
;;
ifdown)
mwan3_delete_iface_rules $INTERFACE