1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-15 03:51:51 +00:00
openmptcprouter-feeds/mptcp/files/usr/share/omr/post-tracking.d/post-tracking

54 lines
2.2 KiB
Text
Raw Normal View History

2018-01-23 14:35:00 +00:00
# vim: set ft=sh noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
SETROUTE=false
set_route() {
local multipath_config interface_gw interface_if
INTERFACE=$1
multipath_config=$(uci -q get "network.$INTERFACE.multipath" || echo "off")
2018-02-15 08:33:27 +00:00
multipath_current_config=$(multipath $INTERFACE | grep deactivated)
if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ] && [ "$multipath_current_config" = "" ]; then
#if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ]; then
2018-01-23 14:35:00 +00:00
interface_gw=$(uci -q get "network.$INTERFACE.gateway")
interface_if=$(uci -q get "network.$INTERFACE.ifname")
_log "Replace default route by $interface_gw dev $interface_if"
2018-01-23 14:35:00 +00:00
ip route replace default scope global nexthop via $interface_gw dev $interface_if && SETROUTE=true
fi
}
# Get the current multipath status
multipath_status="off"
case "$(multipath "$OMR_TRACKER_DEVICE")" in
*default*) multipath_status="on" ;;
*backup*) multipath_status="backup" ;;
*handover*) multipath_status="handover" ;;
esac
default_gw=$(ip route show default | grep -v metric | awk '/default/ {print $3}')
current_interface_gw=$(uci -q get "network.$OMR_TRACKER_INTERFACE.gateway")
# An interface in error will never be used in MPTCP
if [ "$OMR_TRACKER_STATUS" = "ERROR" ]; then
2018-02-15 08:33:27 +00:00
#[ "$multipath_status" = "off" ] && exit 0
#_log "$OMR_TRACKER_DEVICE switched off"
2018-01-23 14:35:00 +00:00
multipath "$OMR_TRACKER_DEVICE" off
if [ "$default_gw" = "$current_interface_gw" ] || [ "$default_gw" = "" ]; then
config_load network
config_foreach set_route interface
fi
exit 0
fi
multipath_config=$(uci -q get "network.$OMR_TRACKER_INTERFACE.multipath" || echo "off")
2018-02-15 16:24:13 +00:00
[ "$multipath_config" = "master" ] && [ "$multipath_status" = "on" ] && exit 0
2018-01-23 14:35:00 +00:00
[ "$multipath_status" = "$multipath_config" ] && exit 0
_log "$OMR_TRACKER_DEVICE switched to $multipath_config"
if [ "$multipath_config" = "master" ]; then
2018-02-15 18:42:21 +00:00
if [ "$default_gw" != "$current_interface_gw" ] || [ "$default_gw" = "" ]; then
_log "Master up : Replace default route by $current_interface_gw dev $OMR_TRACKER_INTERFACE"
ip route replace default scope global nexthop via $current_interface_gw dev $OMR_TRACKER_INTERFACE
fi
multipath_config="on"
fi
2018-01-23 14:35:00 +00:00
multipath "$OMR_TRACKER_DEVICE" "$multipath_config"