Merge pull request #5033 from yangfl/master
net/mwan3: fix empty gateway when creating routing table
This commit is contained in:
commit
c81a75125a
4 changed files with 35 additions and 38 deletions
|
@ -8,7 +8,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=mwan3
|
PKG_NAME:=mwan3
|
||||||
PKG_VERSION:=2.6.6
|
PKG_VERSION:=2.6.7
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
|
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
|
||||||
PKG_LICENSE:=GPLv2
|
PKG_LICENSE:=GPLv2
|
||||||
|
|
|
@ -26,24 +26,20 @@ if [ "$ACTION" == "ifup" ]; then
|
||||||
if [ "$family" = "ipv4" ]; then
|
if [ "$family" = "ipv4" ]; then
|
||||||
ubus call network.interface.${INTERFACE}_4 status &>/dev/null
|
ubus call network.interface.${INTERFACE}_4 status &>/dev/null
|
||||||
if [ "$?" -eq "0" ]; then
|
if [ "$?" -eq "0" ]; then
|
||||||
network_get_gateway gateway ${INTERFACE}_4
|
|
||||||
network_get_ipaddr src_ip ${INTERFACE}_4
|
network_get_ipaddr src_ip ${INTERFACE}_4
|
||||||
else
|
else
|
||||||
network_get_gateway gateway $INTERFACE
|
|
||||||
network_get_ipaddr src_ip ${INTERFACE}
|
network_get_ipaddr src_ip ${INTERFACE}
|
||||||
fi
|
fi
|
||||||
|
[ -n "$src_ip" ] || src_ip="0.0.0.0"
|
||||||
elif [ "$family" = "ipv6" ]; then
|
elif [ "$family" = "ipv6" ]; then
|
||||||
ubus call network.interface.${INTERFACE}_6 status &>/dev/null
|
ubus call network.interface.${INTERFACE}_6 status &>/dev/null
|
||||||
if [ "$?" -eq "0" ]; then
|
if [ "$?" -eq "0" ]; then
|
||||||
network_get_gateway6 gateway ${INTERFACE}_6
|
|
||||||
network_get_ipaddr6 src_ip ${INTERFACE}_6
|
network_get_ipaddr6 src_ip ${INTERFACE}_6
|
||||||
else
|
else
|
||||||
network_get_gateway6 gateway ${INTERFACE}
|
|
||||||
network_get_ipaddr6 src_ip ${INTERFACE}
|
network_get_ipaddr6 src_ip ${INTERFACE}
|
||||||
fi
|
fi
|
||||||
|
[ -n "$src_ip" ] || src_ip="::"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -n "$gateway" ] || exit 9
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$initial_state" = "offline" ]; then
|
if [ "$initial_state" = "offline" ]; then
|
||||||
|
|
|
@ -195,7 +195,7 @@ mwan3_set_general_iptables()
|
||||||
|
|
||||||
mwan3_create_iface_iptables()
|
mwan3_create_iface_iptables()
|
||||||
{
|
{
|
||||||
local id family src_ip src_ipv6
|
local id family
|
||||||
|
|
||||||
config_get family $1 family ipv4
|
config_get family $1 family ipv4
|
||||||
mwan3_get_iface_id id $1
|
mwan3_get_iface_id id $1
|
||||||
|
@ -203,14 +203,6 @@ mwan3_create_iface_iptables()
|
||||||
[ -n "$id" ] || return 0
|
[ -n "$id" ] || return 0
|
||||||
|
|
||||||
if [ "$family" == "ipv4" ]; then
|
if [ "$family" == "ipv4" ]; then
|
||||||
|
|
||||||
ubus call network.interface.${1}_4 status &>/dev/null
|
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
network_get_ipaddr src_ip ${1}_4
|
|
||||||
else
|
|
||||||
network_get_ipaddr src_ip $1
|
|
||||||
fi
|
|
||||||
|
|
||||||
$IPS -! create mwan3_connected list:set
|
$IPS -! create mwan3_connected list:set
|
||||||
|
|
||||||
if ! $IPT4 -S mwan3_ifaces_in &> /dev/null; then
|
if ! $IPT4 -S mwan3_ifaces_in &> /dev/null; then
|
||||||
|
@ -237,21 +229,13 @@ mwan3_create_iface_iptables()
|
||||||
$IPT4 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
|
$IPT4 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
|
||||||
|
|
||||||
$IPT4 -F mwan3_iface_out_$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 -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
|
$IPT4 -A mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$family" == "ipv6" ]; then
|
if [ "$family" == "ipv6" ]; then
|
||||||
|
|
||||||
ubus call network.interface.${1}_6 status &>/dev/null
|
|
||||||
if [ "$?" -eq "0" ]; 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
|
$IPS -! create mwan3_connected_v6 hash:net family inet6
|
||||||
|
|
||||||
if ! $IPT6 -S mwan3_ifaces_in &> /dev/null; then
|
if ! $IPT6 -S mwan3_ifaces_in &> /dev/null; then
|
||||||
|
@ -278,7 +262,7 @@ mwan3_create_iface_iptables()
|
||||||
$IPT6 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
|
$IPT6 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
|
||||||
|
|
||||||
$IPT6 -F mwan3_iface_out_$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 -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
|
$IPT6 -A mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1
|
||||||
|
@ -322,32 +306,37 @@ mwan3_create_iface_route()
|
||||||
[ -n "$id" ] || return 0
|
[ -n "$id" ] || return 0
|
||||||
|
|
||||||
if [ "$family" == "ipv4" ]; then
|
if [ "$family" == "ipv4" ]; then
|
||||||
ubus call network.interface.${1}_4 status &>/dev/null
|
if ubus call network.interface.${1}_4 status &>/dev/null; then
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
network_get_gateway route_args ${1}_4
|
network_get_gateway route_args ${1}_4
|
||||||
else
|
else
|
||||||
network_get_gateway route_args $1
|
network_get_gateway route_args $1
|
||||||
fi
|
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 flush table $id
|
||||||
$IP4 route add table $id default $route_args
|
$IP4 route add table $id default $route_args dev $2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$family" == "ipv6" ]; then
|
if [ "$family" == "ipv6" ]; then
|
||||||
|
if ubus call network.interface.${1}_6 status &>/dev/null; then
|
||||||
ubus call network.interface.${1}_6 status &>/dev/null
|
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
network_get_gateway6 route_args ${1}_6
|
network_get_gateway6 route_args ${1}_6
|
||||||
else
|
else
|
||||||
network_get_gateway6 route_args $1
|
network_get_gateway6 route_args $1
|
||||||
fi
|
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 flush table $id
|
||||||
$IP6 route add table $id default $route_args
|
$IP6 route add table $id default $route_args dev $2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,10 @@ if_down() {
|
||||||
validate_track_method() {
|
validate_track_method() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
ping)
|
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)
|
arping)
|
||||||
which arping 1>/dev/null 2>&1 || {
|
which arping 1>/dev/null 2>&1 || {
|
||||||
|
@ -34,6 +37,10 @@ validate_track_method() {
|
||||||
$LOG warn "Missing httping. Please install httping package."
|
$LOG warn "Missing httping. Please install httping package."
|
||||||
return 1
|
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"
|
$LOG warn "Unsupported tracking method: $track_method"
|
||||||
|
@ -59,9 +66,14 @@ main() {
|
||||||
|
|
||||||
config_load mwan3
|
config_load mwan3
|
||||||
config_get track_method $1 track_method ping
|
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
|
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 reliability $1 reliability 1
|
||||||
config_get count $1 count 1
|
config_get count $1 count 1
|
||||||
|
|
Loading…
Reference in a new issue