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

Add mptcp support

This commit is contained in:
Ycarus 2018-01-23 15:35:00 +01:00
parent ec6e530e52
commit 40fdd921b9
7 changed files with 375 additions and 0 deletions

View file

@ -0,0 +1,91 @@
#!/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
ip route del default
ip route add default scope global nexthop via $gateway dev $iface || {
#Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE
ip route add default scope global nexthop via $gateway dev $INTERFACE
logger -t multipath Faild 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 fount!
echo device $INTERFACE not fount!
exit 1
}
mode=`uci -q get network.$INTERFACE.multipath` || mode='off'
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:
local ipaddr
local gateway
local network
local netmask
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

View file

@ -0,0 +1,36 @@
#!/bin/sh
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
. /lib/functions.sh
multipath=
mptcp_path_manager=
mptcp_schdeduler=
congestion=
multipath_status=0
config_load network
config_get multipath globals multipath
config_get mptcp_path_manager globals mptcp_path_manager
config_get mptcp_scheduler globals mptcp_scheduler
config_get congestion globals congestion
[ "$multipath" = "enable" ] && multipath_status=1
# Global MPTCP configuration
sysctl -qw net.mptcp.mptcp_enabled="$multipath_status"
[ "$multipath_status" = "0" ] && exit 0
[ -z "$mptcp_path_manager" ] || sysctl -qw net.mptcp.mptcp_path_manager="$mptcp_path_manager"
[ -z "$mptcp_scheduler" ] || sysctl -qw net.mptcp.mptcp_scheduler="$mptcp_scheduler"
[ -z "$congestion" ] || sysctl -qw net.ipv4.tcp_congestion_control="$congestion"
# Configuration by interface
_setup_interface() {
device=
config_get device "$1" ifname
[ -z "$device" ] && return 0
if_multipath=
config_get if_multipath "$1" multipath "off"
[ "$if_multipath" = "master" ] && if_multipath="on"
multipath "$device" "$if_multipath"
}
config_foreach _setup_interface interface