Browse Source

mwan3: reduce dependency on src_ip

Interfaces may be managed by 3rd-party scripts, thus src_ip may not be
always available in uci.

Signed-off-by: David Yang <mmyangfl@gmail.com>
lilik-openwrt-22.03
David Yang 7 years ago
parent
commit
e094212b17
3 changed files with 10 additions and 18 deletions
  1. +2
    -2
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  2. +3
    -15
      net/mwan3/files/lib/mwan3/mwan3.sh
  3. +5
    -1
      net/mwan3/files/usr/sbin/mwan3track

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


+ 3
- 15
net/mwan3/files/lib/mwan3/mwan3.sh View 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


+ 5
- 1
net/mwan3/files/usr/sbin/mwan3track View File

@ -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
}


Loading…
Cancel
Save