Skip to content

Commit

Permalink
mwan3: reduce dependency on src_ip
Browse files Browse the repository at this point in the history
Interfaces may be managed by 3rd-party scripts, thus src_ip may not be
always available in uci.

Signed-off-by: David Yang <[email protected]>
  • Loading branch information
yangfl committed Nov 8, 2017
1 parent 6f38aff commit e094212
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions net/mwan3/files/etc/hotplug.d/iface/15-mwan3
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ 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
network_get_ipaddr6 src_ip ${INTERFACE}_6
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
Expand Down
18 changes: 3 additions & 15 deletions net/mwan3/files/lib/mwan3/mwan3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,14 @@ 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

[ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion net/mwan3/files/usr/sbin/mwan3track
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down

0 comments on commit e094212

Please sign in to comment.