mwan3: reduce dependency on src_ip
authorDavid Yang <redacted>
Thu, 2 Nov 2017 01:33:59 +0000 (09:33 +0800)
committerDavid Yang <redacted>
Wed, 8 Nov 2017 08:14:52 +0000 (16:14 +0800)
Interfaces may be managed by 3rd-party scripts, thus src_ip may not be
always available in uci.

Signed-off-by: David Yang <redacted>
net/mwan3/files/etc/hotplug.d/iface/15-mwan3
net/mwan3/files/lib/mwan3/mwan3.sh
net/mwan3/files/usr/sbin/mwan3track

index 3ef856580d678f7df24b18e1bdcf15a94b8682c8..71d6393b434ab25e56a359cf1e39cd3caf04a4c8 100644 (file)
@@ -30,6 +30,7 @@ if [ "$ACTION" == "ifup" ]; then
                else
                        network_get_ipaddr src_ip ${INTERFACE}
                fi
+               [ -n "$src_ip" ] || src_ip="0.0.0.0"
        elif [ "$family" = "ipv6" ]; then
                ubus call network.interface.${INTERFACE}_6 status &>/dev/null
                if [ "$?" -eq "0" ]; then
@@ -37,9 +38,8 @@ if [ "$ACTION" == "ifup" ]; then
                else
                        network_get_ipaddr6 src_ip ${INTERFACE}
                fi
+               [ -n "$src_ip" ] || src_ip="::"
        fi
-
-       [ -n "$src_ip" ] || exit 9
 fi
 
 if [ "$initial_state" = "offline" ]; then
index cacef1ceaae0803f0ddb2f38c9b54835257e4b9d..c24db3cae1c40dce08b8dbbb06973175e37bc0fb 100644 (file)
@@ -195,7 +195,7 @@ mwan3_set_general_iptables()
 
 mwan3_create_iface_iptables()
 {
-       local id family src_ip src_ipv6
+       local id family
 
        config_get family $1 family ipv4
        mwan3_get_iface_id id $1
@@ -203,12 +203,6 @@ mwan3_create_iface_iptables()
        [ -n "$id" ] || return 0
 
        if [ "$family" == "ipv4" ]; then
-               if ubus call network.interface.${1}_4 status &>/dev/null; then
-                       network_get_ipaddr src_ip ${1}_4
-               else
-                       network_get_ipaddr src_ip $1
-               fi
-
                $IPS -! create mwan3_connected list:set
 
                if ! $IPT4 -S mwan3_ifaces_in &> /dev/null; then
@@ -235,19 +229,13 @@ mwan3_create_iface_iptables()
                $IPT4 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
 
                $IPT4 -F mwan3_iface_out_$1
-               $IPT4 -A mwan3_iface_out_$1 -s $src_ip -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
+               $IPT4 -A mwan3_iface_out_$1 -o $2 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
 
                $IPT4 -D mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1 &> /dev/null
                $IPT4 -A mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1
        fi
 
        if [ "$family" == "ipv6" ]; then
-               if ubus call network.interface.${1}_6 status &>/dev/null; then
-                       network_get_ipaddr6 src_ipv6 ${1}_6
-               else
-                       network_get_ipaddr6 src_ipv6 $1
-               fi
-
                $IPS -! create mwan3_connected_v6 hash:net family inet6
 
                if ! $IPT6 -S mwan3_ifaces_in &> /dev/null; then
@@ -274,7 +262,7 @@ mwan3_create_iface_iptables()
                $IPT6 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
 
                $IPT6 -F mwan3_iface_out_$1
-               $IPT6 -A mwan3_iface_out_$1 -s $src_ipv6 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
+               $IPT6 -A mwan3_iface_out_$1 -o $2 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
 
                $IPT6 -D mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1 &> /dev/null
                $IPT6 -A mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1
index e94ada815753ceccf271b081e98a085885cc3629..872628e2ff07f5e6a1ddb18fcf6f936c24f7a1e2 100755 (executable)
@@ -34,6 +34,10 @@ validate_track_method() {
                                $LOG warn "Missing httping. Please install httping package."
                                return 1
                        }
+                       [ -n "$2" -a "$2" != "0.0.0.0" -a "$2" != "::" ] || {
+                               $LOG warn "Cannot determine source IP for the interface which is required by httping."
+                               return 1
+                       }
                        ;;
                *)
                        $LOG warn "Unsupported tracking method: $track_method"
@@ -59,7 +63,7 @@ main() {
 
        config_load mwan3
        config_get track_method $1 track_method ping
-       validate_track_method $track_method || {
+       validate_track_method $track_method $SRC_IP || {
                $LOG warn "Using ping to track interface $INTERFACE avaliability"
                track_method=ping
        }
git clone https://git.99rst.org/PROJECT