Browse Source

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>
lilik-openwrt-22.03
Florian Eckert 8 years ago
parent
commit
815e83d461
3 changed files with 35 additions and 10 deletions
  1. +24
    -6
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  2. +1
    -1
      net/mwan3/files/lib/mwan3/mwan3.sh
  3. +10
    -3
      net/mwan3/files/usr/sbin/mwan3track

+ 24
- 6
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 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


+ 1
- 1
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -457,7 +457,7 @@ mwan3_track()
kill $(pgrep -f "mwan3track $1 $2") &> /dev/null
if [ -n "$track_ips" ]; then
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track "$1" "$2" "$3" $track_ips &
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track "$1" "$2" "$3" "$4" $track_ips &
fi
}


+ 10
- 3
net/mwan3/files/usr/sbin/mwan3track View File

@ -47,10 +47,11 @@ main() {
local recovery_interval down up size
local keep_failure_interval
[ -z "$3" ] && echo "Error: should not be started manually" && exit 0
[ -z "$5" ] && echo "Error: should not be started manually" && exit 0
INTERFACE=$1
DEVICE=$2
STATUS=$3
mkdir -p /var/run/mwan3track/$1
trap clean_up SIGINT SIGTERM
trap if_down SIGUSR1
@ -73,13 +74,18 @@ main() {
config_get recovery_interval $1 recovery_interval $interval
local score=$(($down+$up))
local track_ips=$(echo $* | cut -d ' ' -f 4-99)
local track_ips=$(echo $* | cut -d ' ' -f 5-99)
local host_up_count=0
local lost=0
local sleep_time=0
local turn=0
echo "offline" > /var/run/mwan3track/$1/STATUS
if [ "$STATUS" = "offline" ]; then
echo "offline" > /var/run/mwan3track/$1/STATUS
score=0
else
echo "online" > /var/run/mwan3track/$1/STATUS
fi
while true; do
sleep_time=$interval
@ -137,6 +143,7 @@ main() {
if [ $score -eq $up ]; then
$LOG notice "Interface $1 ($2) is online"
echo "online" > /var/run/mwan3track/$1/STATUS
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
exit 0
fi


Loading…
Cancel
Save