1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Fix routes

This commit is contained in:
Ycarus (Yannick Chabanois) 2020-06-02 17:19:40 +02:00
parent f4c2ddf9c4
commit 2630b9e357

View file

@ -59,7 +59,6 @@ delete_server_default_route() {
set_routes_intf() { set_routes_intf() {
local multipath_config_route local multipath_config_route
local INTERFACE=$1 local INTERFACE=$1
nbintf=$((nbintf+1))
multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath) multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off") [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off")
interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
@ -80,6 +79,7 @@ set_routes_intf() {
fi fi
#if [ "$interface_gw" != "" ] && [ "$interface_if" != "" ] && [ "$(ip route show $serverip | grep $interface_if)" = "" ]; then #if [ "$interface_gw" != "" ] && [ "$interface_if" != "" ] && [ "$(ip route show $serverip | grep $interface_if)" = "" ]; then
if [ "$interface_gw" != "" ] && [ "$interface_if" != "" ]; then if [ "$interface_gw" != "" ] && [ "$interface_if" != "" ]; then
nbintf=$((nbintf+1))
if [ "$multipath_config_route" = "master" ]; then if [ "$multipath_config_route" = "master" ]; then
weight=10 weight=10
else else
@ -97,7 +97,6 @@ set_routes_intf() {
set_route_balancing() { set_route_balancing() {
local multipath_config_route interface_gw interface_if local multipath_config_route interface_gw interface_if
INTERFACE=$1 INTERFACE=$1
nbintf=$((nbintf+1))
multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath) multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off") [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off")
interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
@ -116,6 +115,7 @@ set_route_balancing() {
interface_gw=$(ubus call network.interface.${INTERFACE}_4 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.${INTERFACE}_4 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
fi fi
if [ "$interface_gw" != "" ] && [ "$interface_if" != "" ]; then if [ "$interface_gw" != "" ] && [ "$interface_if" != "" ]; then
nbintf=$((nbintf+1))
if [ "$(uci -q get network.$INTERFACE.weight)" != "" ]; then if [ "$(uci -q get network.$INTERFACE.weight)" != "" ]; then
weight=$(uci -q get network.$INTERFACE.weight) weight=$(uci -q get network.$INTERFACE.weight)
elif [ "$(uci -q get openmtpcprouter.$INTERFACE.weight)" != "" ]; then elif [ "$(uci -q get openmtpcprouter.$INTERFACE.weight)" != "" ]; then
@ -150,11 +150,11 @@ set_server_all_routes() {
nbintf=0 nbintf=0
config_load network config_load network
config_foreach set_routes_intf interface config_foreach set_routes_intf interface
[ -n "$routesintf" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show $serverip | tr -d '\t' | tr -d '\n')" != "$serverip $routesintf " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show $serverip | grep $OMR_TRACKER_INTERFACE)" = "" ]) && { [ -n "$routesintf" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show $serverip | tr -d '\t' | tr -d '\n')" != "$serverip $routesintf " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show $serverip | grep $OMR_TRACKER_DEVICE)" = "" ]) && {
_log "Set server $server ($serverip) default route $serverip $routesintf" _log "Set server $server ($serverip) default route $serverip $routesintf"
ip route replace $serverip scope global $routesintf ip route replace $serverip scope global $routesintf
} }
[ -n "$routesintfbackup" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show $serverip | tr -d '\t' | tr -d '\n')" != "$serverip $routesintfbackup " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show $serverip | grep $OMR_TRACKER_INTERFACE)" = "" ]) && { [ -n "$routesintfbackup" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show $serverip | tr -d '\t' | tr -d '\n')" != "$serverip $routesintfbackup " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show $serverip | grep $OMR_TRACKER_DEVICE)" = "" ]) && {
_log "Set server $server ($serverip) default route $serverip $routesintf" _log "Set server $server ($serverip) default route $serverip $routesintf"
ip route replace $serverip scope global metric 999 $routesintf ip route replace $serverip scope global metric 999 $routesintf
} }
@ -455,16 +455,21 @@ if [ "$multipath_config" = "master" ]; then
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337 ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337
routesbalancing="" routesbalancing=""
routesbalancingbackup="" routesbalancingbackup=""
nbintf=0
config_load network config_load network
config_foreach set_route_balancing interface config_foreach set_route_balancing interface
[ -n "$routesbalancing" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show default metric 0 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancing " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show default metric 0 | grep $OMR_TRACKER_INTERFACE)" = "" ]) && { [ -n "$routesbalancing" ] && {
([ "$nbintf" -gt "1" ] && [ "$(ip r show default metric 0 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancing " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show default metric 0 | grep $OMR_TRACKER_DEVICE)" = "" ]) && {
_log "Set ip route replace default scope global $routesbalancing" _log "Set ip route replace default scope global $routesbalancing"
ip route replace default scope global $routesbalancing ip route replace default scope global $routesbalancing
} }
[ -n "$routesbalancingbackup" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show default metric 999 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancingbackup " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show default metric 999 | grep $OMR_TRACKER_INTERFACE)" = "" ]) && { }
_log "Set ip route replace default scope global $routesbalancingbackup" [ -n "$routesbalancingbackup" ] && {
([ "$nbintf" -gt "1" ] && [ "$(ip r show default metric 999 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancingbackup " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show default metric 999 | grep $OMR_TRACKER_DEVICE)" = "" ]) && {
_log "Set backup ip route replace default scope global $routesbalancingbackup"
ip route replace default scope global metric 999 $routesbalancingbackup ip route replace default scope global metric 999 $routesbalancingbackup
} }
}
fi fi
fi fi
if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ] || [ $(($(date +"%s") + $((10 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q show openmptcprouter | grep get_config=\'1\')" != "" ] || [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" != "" ]; then if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ] || [ $(($(date +"%s") + $((10 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q show openmptcprouter | grep get_config=\'1\')" != "" ] || [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" != "" ]; then