From 6f38affd0c0a41c68a6249e9e934ffa718b1500d Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 28 Oct 2017 22:48:38 +0800 Subject: [PATCH] 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 27033d582d..3ef856580d 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 32c9f7888a..cacef1ceaa 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 } -- 2.30.2