1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00
openmptcprouter-feeds/mptcp/files/etc/hotplug.d/iface/30-mptcp
2018-02-23 13:53:33 +01:00

89 lines
2.3 KiB
Bash

#!/bin/sh
#
# Load the multipath config
#
# Author: Mario Krueger <openwrt at xedp3x.de>
# Released under GPL 3 or later
[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0
enable=`uci -q get network.globals.multipath` || exit 0
[ "$enable" = "enable" ] || exit 0
. /lib/functions.sh
. /lib/functions/network.sh
id=0
count=1
set_default() {
local mode
local config="$1"
count=$(($count+1))
local iface
config_get iface "$config" ifname
[ "$iface" = "$INTERFACE" ] && id=$count
config_get mode "$config" multipath
[ "$mode" = "master" ] && {
local gateway
network_get_gateway gateway $config || {
logger -t multipath master device $DEVICE has no gateway!
#Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE
config=$INTERFACE
}
local iface
config_get iface "$config" ifname
[ -n "gateway" ] && {
ip route replace default via $gateway dev $iface || {
#Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE
ip route replace default via $gateway dev $INTERFACE
logger -t multipath Failed to set default multipath device! Use $INTERFACE as fallback...
}
}
}
}
config_load network
config_foreach set_default interface
[ $id = 0 ] && {
logger -t multipath device $INTERFACE not found!
echo device $INTERFACE not found!
exit 1
}
mode=`uci -q get network.$INTERFACE.multipath` || mode='off'
[ -n "$(ifconfig | grep $DEVICE)" ] || exit 0
case "$mode" in
"off")
multipath $DEVICE off
exit 0;;
"master")
mode="on";;
"on");;
"backup");;
"handover");;
*)
logger -t multipath Wrong multipath value for device $DEVICE
exit 1;;
esac
# Update kernel flags
multipath $DEVICE $mode
# IPv4 Updates:
network_get_ipaddr ipaddr $INTERFACE
network_get_gateway gateway $INTERFACE
network_get_subnet network $INTERFACE
__network_ifstatus netmask $INTERFACE "['ipv4-address'][0]['mask']"
network=`ipcalc.sh $network | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
ip rule del table $id
ip route flush $id
ip rule add from $ipaddr table $id
ip route add $network/$netmask dev $DEVICE scope link table $id
ip route add default via $gateway dev $DEVICE table $id
ip route flush $id