From 623f0133a0ba91263b02b343b764454bdd1d63ba Mon Sep 17 00:00:00 2001 From: Ycarus Date: Fri, 26 Oct 2018 16:52:11 +0200 Subject: [PATCH] Support IPv6 for MPTCP --- ipcalc/Makefile | 36 ++++++++++++++++ mptcp/Makefile | 4 +- mptcp/files/etc/init.d/mptcp | 81 +++++++++++++++++++++++++++--------- 3 files changed, 100 insertions(+), 21 deletions(-) create mode 100644 ipcalc/Makefile diff --git a/ipcalc/Makefile b/ipcalc/Makefile new file mode 100644 index 000000000..1cc88ba76 --- /dev/null +++ b/ipcalc/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (C) 2018 Ycarus (Yannick Chabanois) +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=ipcalc +PKG_RELEASE:=1 + +PKG_SOURCE_URL:=https://github.com/nmav/ipcalc.git +PKG_SOURCE_PROTO:=git +PKG_SOURCE_VERSION:=e9f88461f2585575d12fc95f5eeb9996b863f5af +PKG_MAINTAINER:=Ycarus (Yannick Chabanois) +PKG_LICENSE:=GPL-2.0 + +include $(INCLUDE_DIR)/package.mk + +MAKE_FLAGS += USE_GEOIP=no USE_MAXMIND=no + +define Package/ipcalc + SECTION:=net + CATEGORY:=Network + MAINTAINER:=Ycarus (Yannick Chabanois) + TITLE:=Modern tool to assist in network address calculations for IPv4 and IPv6. +endef + +define Package/ipcalc/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipcalc $(1)/usr/sbin/ipcalc +endef + + +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/mptcp/Makefile b/mptcp/Makefile index 9493ee39a..de8f445ff 100644 --- a/mptcp/Makefile +++ b/mptcp/Makefile @@ -20,8 +20,8 @@ include $(INCLUDE_DIR)/package.mk define Package/mptcp SECTION:=net CATEGORY:=Network - TITLE:=Multipath TCP configuration scrips - DEPENDS:=+ip +iptables +ethtool + TITLE:=Multipath TCP configuration scripts + DEPENDS:=+ip +iptables +ethtool +ipcalc KCONFIG:=\ CONFIG_MPTCP=y \ CONFIG_MPTCP_BINDER=y \ diff --git a/mptcp/files/etc/init.d/mptcp b/mptcp/files/etc/init.d/mptcp index a9602eaee..941befb08 100755 --- a/mptcp/files/etc/init.d/mptcp +++ b/mptcp/files/etc/init.d/mptcp @@ -77,31 +77,74 @@ interface_multipath_settings() { gateway=$(ip -4 r list dev $iface | grep -v default | awk '/proto static/ {print $1}' | tr -d "\n") [ -z "$gateway" ] && gateway=$(uci -q get "network.$config.gateway") [ -z "$gateway" ] && gateway=$(ubus call network.interface.$config status | jsonfilter -q -e '@.route[0].nexthop' | tr -d "\n") - [ -z "$gateway" ] && gateway=$(ubus call network.interface.$config status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n") - [ -z "$gateway" ] && gateway=$(ubus call network.interface.${config}_4 status 2>/dev/null | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n") + [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway)" = "ok" ] && gateway=$(ubus call network.interface.$config status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n") + [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway)" = "ok" ] && gateway=$(ubus call network.interface.${config}_4 status 2>/dev/null | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n") netmask=$(ip -4 addr show dev $iface | grep inet | awk '{print $2}' | cut -d/ -f2 | tr -d "\n") network=`ipcalc.sh $ipaddr $netmask | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'` fi ip rule del table $id > /dev/null 2>&1 ip route flush $id > /dev/null 2>&1 - [ -n "$gateway" ] || return 1 - [ -n "$network" ] || return 1 - ip rule add from $ipaddr table $id - ip route replace $network/$netmask dev $iface scope link table $id - ip route replace default via $gateway dev $iface table $id - ip route flush $id + if [ -n "$gateway" ] && [ -n "$network" ]; then + ip rule add from $ipaddr table $id + ip route replace $network/$netmask dev $iface scope link table $id + ip route replace default via $gateway dev $iface table $id + ip route flush $id - config_get mode "$config" multipath "off" - local enabled - config_get enabled "$config" auto "1" - [ "$mode" = "master" ] && { - ip route replace default via $gateway dev $iface - } - [ "$mode" = "off" ] && { - ifconfig $iface txqueuelen 90 > /dev/null 2>&1 - } || { - ifconfig $iface txqueuelen 10000 > /dev/null 2>&1 - } + config_get mode "$config" multipath "off" + local enabled + config_get enabled "$config" auto "1" + [ "$mode" = "master" ] && { + ip route replace default via $gateway dev $iface + } + [ "$mode" = "off" ] && { + ifconfig $iface txqueuelen 90 > /dev/null 2>&1 + } || { + ifconfig $iface txqueuelen 10000 > /dev/null 2>&1 + } + fi + if [ "$(sysctl -n net.ipv6.conf.all.disable_ipv6 | tr -d '\n')" != "1" ]; then + # IPv6 Updates: + local ip6addr + local ipaddr6 + local gateway6 + local network6 + local netmask6 + config_get ipaddr6 $config ip6addr + config_get gateway6 $config ip6gw + ip6addr=`echo $ip6addr | cut -d/ -f1` + netmask6=`ipcalc $ipaddr6 | sed -n '/PREFIX=/{;s/.*=//;s/ .*//;p;}'` + network6=`ipcalc $ip6addr | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'` + if [ -z "$ip6addr" ] || [ -z "$network6" ]; then + ip6addr=$(ip -6 addr show dev $iface | grep -v 'scope link' | grep inet6 | awk '{print $2}' | cut -d/ -f1 | tr -d "\n") + gateway6=$(ip -6 r list dev $iface | grep -v default | awk '/proto static/ {print $1}' | tr -d "\n") + [ -z "$gateway6" ] && gateway6=$(uci -q get "network.$config.ip6gw") + [ -z "$gateway6" ] && gateway6=$(ubus call network.interface.$config status | jsonfilter -q -e '@.route[0].nexthop' | tr -d "\n") + [ -z "$gateway6" ] || [ "$( valid_subnet6 $gateway6)" = "ok" ] && gateway6=$(ubus call network.interface.$config status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n") + [ -z "$gateway6" ] || [ "$( valid_subnet6 $gateway6)" = "ok" ] && gateway6=$(ubus call network.interface.${config}_6 status 2>/dev/null | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n") + netmask6=$(ip -6 addr show dev $iface | grep -v 'scope link' | grep inet6 | awk '{print $2}' | cut -d/ -f2 | tr -d "\n") + network6=`ipcalc $ip6addr | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'` + fi + ip -6 rule del table 6$id > /dev/null 2>&1 + ip -6 route flush 6$id > /dev/null 2>&1 + if [ -n "$gateway6" ] && [ -n "$network6" ]; then + ip -6 rule add from $ip6addr table 6$id + ip -6 route replace $network6/$netmask6 dev $iface scope link table 6$id + ip -6 route replace default via $gateway6 dev $iface table 6$id + ip -6 route flush 6$id + + config_get mode "$config" multipath "off" + local enabled + config_get enabled "$config" auto "1" + [ "$mode" = "master" ] && { + ip -6 route replace default via $gateway6 dev $iface + } + [ "$mode" = "off" ] && { + ifconfig $iface txqueuelen 90 > /dev/null 2>&1 + } || { + ifconfig $iface txqueuelen 10000 > /dev/null 2>&1 + } + fi + fi } load_interfaces() {