mwan3: cleanup function mwan3_create_iface_route

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
(cherry picked from commit d0c248a7da)
This commit is contained in:
Florian Eckert 2020-07-14 12:02:01 +02:00
parent db3c8326fe
commit 2f2044ecb0

View file

@ -483,56 +483,44 @@ mwan3_delete_iface_iptables()
mwan3_create_iface_route() mwan3_create_iface_route()
{ {
local id route_args metric local id via metric
config_get family $1 family ipv4 config_get family "$1" family ipv4
mwan3_get_iface_id id $1 mwan3_get_iface_id id "$1"
[ -n "$id" ] || return 0 [ -n "$id" ] || return 0
if [ "$family" = "ipv4" ]; then if [ "$family" = "ipv4" ]; then
if ubus call network.interface.${1}_4 status &>/dev/null; then if ubus call "network.interface.${1}_4" status &>/dev/null; then
network_get_gateway route_args ${1}_4 network_get_gateway via "${1}_4"
else else
network_get_gateway route_args $1 network_get_gateway via "$1"
fi fi
if [ -n "$route_args" -a "$route_args" != "0.0.0.0" ]; then network_get_metric metric "$1"
route_args="via $route_args"
else
route_args=""
fi
network_get_metric metric $1 $IP4 route flush table "$id"
if [ -n "$metric" -a "$metric" != "0" ]; then $IP4 route add table "$id" default \
route_args="$route_args metric $metric" ${via:+via} $via \
fi ${metric:+metric} $metric \
dev "$2"
$IP4 route flush table $id
$IP4 route add table $id default $route_args dev $2
mwan3_rtmon_ipv4 mwan3_rtmon_ipv4
fi fi
if [ "$family" = "ipv6" ]; then if [ "$family" = "ipv6" ]; then
if ubus call network.interface.${1}_6 status &>/dev/null; then if ubus call "network.interface.${1}_6" status &>/dev/null; then
network_get_gateway6 route_args ${1}_6 network_get_gateway6 via "${1}_6"
else else
network_get_gateway6 route_args $1 network_get_gateway6 via "$1"
fi fi
if [ -n "$route_args" -a "$route_args" != "::" ]; then network_get_metric metric "$1"
route_args="via $route_args"
else
route_args=""
fi
network_get_metric metric $1 $IP6 route flush table "$id"
if [ -n "$metric" -a "$metric" != "0" ]; then $IP6 route add table "$id" default \
route_args="$route_args metric $metric" ${via:+via} $via \
fi ${metric:+metric} $metric \
dev "$2"
$IP6 route flush table $id
$IP6 route add table $id default $route_args dev $2
mwan3_rtmon_ipv6 mwan3_rtmon_ipv6
fi fi
} }