From 5688f3e65a802bb41a84545a60fa31a73770f847 Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 30 Oct 2017 21:32:01 +0800 Subject: [PATCH 1/5] mwan3: reduce unnecessary comparisons Signed-off-by: David Yang --- net/mwan3/files/lib/mwan3/mwan3.sh | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index a92cb4687..32c9f7888 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -203,9 +203,7 @@ mwan3_create_iface_iptables() [ -n "$id" ] || return 0 if [ "$family" == "ipv4" ]; then - - ubus call network.interface.${1}_4 status &>/dev/null - if [ "$?" -eq "0" ]; 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 @@ -244,9 +242,7 @@ mwan3_create_iface_iptables() fi if [ "$family" == "ipv6" ]; then - - ubus call network.interface.${1}_6 status &>/dev/null - if [ "$?" -eq "0" ]; 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 @@ -322,8 +318,7 @@ mwan3_create_iface_route() [ -n "$id" ] || return 0 if [ "$family" == "ipv4" ]; then - ubus call network.interface.${1}_4 status &>/dev/null - if [ "$?" -eq "0" ]; then + if ubus call network.interface.${1}_4 status &>/dev/null; then network_get_gateway route_args ${1}_4 else network_get_gateway route_args $1 @@ -336,9 +331,7 @@ mwan3_create_iface_route() fi if [ "$family" == "ipv6" ]; then - - ubus call network.interface.${1}_6 status &>/dev/null - if [ "$?" -eq "0" ]; then + if ubus call network.interface.${1}_6 status &>/dev/null; then network_get_gateway6 route_args ${1}_6 else network_get_gateway6 route_args $1 From 6f38affd0c0a41c68a6249e9e934ffa718b1500d Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 28 Oct 2017 22:48:38 +0800 Subject: [PATCH 2/5] mwan3: fix empty gateway when creating routing table Interfaces of some PtP protocols do not have a real gateway. In that case ubus may fill them with '0.0.0.0' or even leave it blank. This will cause error when adding new routing rule. Signed-off-by: David Yang --- net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 6 +----- net/mwan3/files/lib/mwan3/mwan3.sh | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index 27033d582..3ef856580 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -26,24 +26,20 @@ if [ "$ACTION" == "ifup" ]; then if [ "$family" = "ipv4" ]; then ubus call network.interface.${INTERFACE}_4 status &>/dev/null if [ "$?" -eq "0" ]; then - network_get_gateway gateway ${INTERFACE}_4 network_get_ipaddr src_ip ${INTERFACE}_4 else - network_get_gateway gateway $INTERFACE network_get_ipaddr src_ip ${INTERFACE} fi elif [ "$family" = "ipv6" ]; then ubus call network.interface.${INTERFACE}_6 status &>/dev/null if [ "$?" -eq "0" ]; then - network_get_gateway6 gateway ${INTERFACE}_6 network_get_ipaddr6 src_ip ${INTERFACE}_6 else - network_get_gateway6 gateway ${INTERFACE} network_get_ipaddr6 src_ip ${INTERFACE} fi fi - [ -n "$gateway" ] || exit 9 + [ -n "$src_ip" ] || exit 9 fi if [ "$initial_state" = "offline" ]; then diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 32c9f7888..cacef1cea 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -324,10 +324,14 @@ mwan3_create_iface_route() network_get_gateway route_args $1 fi - route_args="via $route_args dev $2" + if [ -n "$route_args" -a "$route_args" != "0.0.0.0" ]; then + route_args="via $route_args" + else + route_args="" + fi $IP4 route flush table $id - $IP4 route add table $id default $route_args + $IP4 route add table $id default $route_args dev $2 fi if [ "$family" == "ipv6" ]; then @@ -337,10 +341,14 @@ mwan3_create_iface_route() network_get_gateway6 route_args $1 fi - route_args="via $route_args dev $2" + if [ -n "$route_args" -a "$route_args" != "::" ]; then + route_args="via $route_args" + else + route_args="" + fi $IP6 route flush table $id - $IP6 route add table $id default $route_args + $IP6 route add table $id default $route_args dev $2 fi } From e094212b17f46c8199c2a10abe188f182e8f3463 Mon Sep 17 00:00:00 2001 From: David Yang Date: Thu, 2 Nov 2017 09:33:59 +0800 Subject: [PATCH 3/5] 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 --- net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 4 ++-- net/mwan3/files/lib/mwan3/mwan3.sh | 18 +++--------------- net/mwan3/files/usr/sbin/mwan3track | 6 +++++- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index 3ef856580..71d6393b4 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -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 diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index cacef1cea..c24db3cae 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -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 diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index e94ada815..872628e2f 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -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 } From 474e6bbdd7091fa9757194026af3a11629939ffc Mon Sep 17 00:00:00 2001 From: David Yang Date: Thu, 2 Nov 2017 09:44:33 +0800 Subject: [PATCH 4/5] mwan3: add check for ping Signed-off-by: David Yang --- net/mwan3/files/usr/sbin/mwan3track | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 872628e2f..4b744b9fc 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -21,7 +21,10 @@ if_down() { validate_track_method() { case "$1" in ping) - # Assume that ping is installed + which ping 1>/dev/null 2>&1 || { + $LOG warn "Missing ping. Please install iputils-ping package or enable ping util and recompile busybox." + return 1 + } ;; arping) which arping 1>/dev/null 2>&1 || { @@ -64,8 +67,13 @@ main() { config_load mwan3 config_get track_method $1 track_method ping validate_track_method $track_method $SRC_IP || { - $LOG warn "Using ping to track interface $INTERFACE avaliability" track_method=ping + if validate_track_method $track_method; then + $LOG warn "Using ping to track interface $INTERFACE avaliability" + else + $LOG err "No track method avaliable" + exit 1 + fi } config_get reliability $1 reliability 1 config_get count $1 count 1 From 6f0a88f1ed416f0df55887d3a0524d6f8769b27b Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 8 Nov 2017 23:21:39 +0800 Subject: [PATCH 5/5] mwan3: update to version 2.6.7 Signed-off-by: David Yang --- net/mwan3/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 34e38f07c..6c5154336 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.6.6 +PKG_VERSION:=2.6.7 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2