mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 08:23:56 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
[ "$ACTION" = ifup -o "$ACTION" = ifupdate -o "$ACTION" = ifdown -o "$ACTION" = iflink -o "$ACTION" = link-up -o "$ACTION" = link-down ] || exit 0
|
||||
#[ "$ACTION" = ifupdate -a -z "$IFUPDATE_ADDRESSES" -a -z "$IFUPDATE_DATA" ] && exit 0
|
||||
|
||||
|
||||
/etc/init.d/mptcp enabled || exit 0
|
||||
|
||||
if [ "$ACTION" = ifupdate -a -n "$IFUPDATE_ADDRESSES" ] && [ -n "$(uci -q get network.$INTERFACE.multipath)" ] && [ "$(uci -q get network.$INTERFACE.multipath)" != "off" ]; then
|
||||
logger -t "mptcp" "New IP ($IFUPDATE_ADDRESSES) for $INTERFACE ($DEVICE)"
|
||||
multipath $DEVICE off 2>&1 >/dev/null || exit 0
|
||||
multipath $DEVICE on 2>&1 >/dev/null || exit 0
|
||||
elif [ "$ACTION" = ifupdate ] && [ -n "$(uci -q get network.$INTERFACE.multipath)" ] && [ "$(uci -q get network.$INTERFACE.multipath)" != "off" ]; then
|
||||
logger -t "mptcp" "Update of $INTERFACE ($DEVICE)"
|
||||
multipath $DEVICE off 2>&1 >/dev/null || exit 0
|
||||
multipath $DEVICE on 2>&1 >/dev/null || exit 0
|
||||
elif [ "$ACTION" = ifup -o "$ACTION" = iflink -o "$ACTION" = link-up ] && [ -z "$(echo $DEVICE | grep oip | grep gre)" ] && [ -n "$(uci -q get network.$INTERFACE.multipath)" ] && [ "$(uci -q get network.$INTERFACE.multipath)" != "off" ]; then
|
||||
logger -t "mptcp" "Reloading mptcp config due to $ACTION of $INTERFACE ($DEVICE)"
|
||||
/etc/init.d/mptcp reload "$DEVICE" >/dev/null || exit 0
|
||||
elif [ "$ACTION" = ifdown -o "$ACTION" = link-down ]; then
|
||||
multipath $DEVICE off 2>&1 >/dev/null || exit 0
|
||||
fi
|
||||
|
||||
Executable
+681
@@ -0,0 +1,681 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
||||
# Released under GPL 3. See LICENSE for the full terms.
|
||||
|
||||
START=50
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
. /usr/lib/unbound/iptools.sh
|
||||
. /lib/functions/network.sh
|
||||
|
||||
global_multipath_settings() {
|
||||
local multipath mptcp_path_manager mptcp_scheduler mptcp_subflows mptcp_debug mptcp_add_addr_accepted congestion mptcp_checksum mptcp_syn_retries mptcp_fullmesh_num_subflows mptcp_fullmesh_create_on_err mptcp_ndiffports_num_subflows mptcp_rr_cwnd_limited mptcp_rr_num_segments
|
||||
local 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 mptcp_subflows globals mptcp_subflows "3"
|
||||
config_get mptcp_add_addr_accepted globals mptcp_add_addr_accepted "1"
|
||||
config_get mptcp_add_addr_timeout globals mptcp_add_addr_timeout "120"
|
||||
config_get mptcp_debug globals mptcp_debug
|
||||
config_get congestion globals congestion
|
||||
config_get mptcp_checksum globals mptcp_checksum
|
||||
config_get mptcp_syn_retries globals mptcp_syn_retries
|
||||
config_get mptcp_fullmesh_num_subflows globals mptcp_fullmesh_num_subflows
|
||||
config_get mptcp_fullmesh_create_on_err globals mptcp_fullmesh_create_on_err
|
||||
config_get mptcp_ndiffports_num_subflows globals mptcp_ndiffports_num_subflows
|
||||
config_get mptcp_rr_cwnd_limited globals mptcp_rr_cwnd_limited
|
||||
config_get mptcp_rr_num_segments globals mptcp_rr_num_segments
|
||||
config_get mptcp_version globals mptcp_version "0"
|
||||
config_get mptcp_stale_loss_cnt globals mptcp_stale_loss_cnt "4"
|
||||
config_get mptcp_pm_type globals mptcp_pm_type "1"
|
||||
config_get mptcp_allow_join_initial_addr_port globals mptcp_allow_join_initial_addr_port "1"
|
||||
config_get mptcp_close_timeout globals mptcp_close_timeout "60"
|
||||
config_get mptcp_blackhole_timeout globals mptcp_blackhole_timeout "3600"
|
||||
config_get mptcp_syn_retrans_before_tcp_fallback globals mptcp_syn_retrans_before_tcp_fallback "2"
|
||||
|
||||
[ "$multipath" = "enable" ] && multipath_status=1
|
||||
|
||||
# Global MPTCP configuration
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_enabled ]; then
|
||||
sysctl -qew net.mptcp.mptcp_enabled="$multipath_status"
|
||||
if [ -z "$(grep net.mptcp.mptcp_enabled /etc/sysctl.d/zzz_openmptcprouter.conf)" ]; then
|
||||
echo "net.mptcp.mptcp_enabled=${multipath_status}" >> /etc/sysctl.d/zzz_openmptcprouter.conf
|
||||
else
|
||||
sed -i "s:^net.mptcp.mptcp_enabled=[0-1]*:net.mptcp.mptcp_enabled=${multipath_status}:" /etc/sysctl.d/zzz_openmptcprouter.conf
|
||||
fi
|
||||
[ -z "$mptcp_path_manager" ] || sysctl -qew net.mptcp.mptcp_path_manager="$mptcp_path_manager"
|
||||
[ -z "$mptcp_scheduler" ] || sysctl -qew net.mptcp.mptcp_scheduler="$mptcp_scheduler"
|
||||
[ -z "$mptcp_checksum" ] || sysctl -qew net.mptcp.mptcp_checksum="$mptcp_checksum"
|
||||
[ -z "$mptcp_debug" ] || sysctl -qew net.mptcp.mptcp_debug="$mptcp_debug"
|
||||
[ -z "$mptcp_syn_retries" ] || sysctl -qew net.mptcp.mptcp_syn_retries="$mptcp_syn_retries"
|
||||
[ -z "$mptcp_fullmesh_num_subflows" ] || sysctl -qew /sys/module/mptcp_fullmesh/parameters/num_subflows="$mptcp_fullmesh_num_subflows"
|
||||
[ -z "$mptcp_fullmesh_create_on_err" ] || sysctl -qew /sys/module/mptcp_fullmesh/parameters/create_on_err="$mptcp_fullmesh_create_on_err"
|
||||
[ -z "$mptcp_ndiffports_num_subflows" ] || sysctl -qew /sys/module/mptcp_ndiffports/parameters/num_subflows="$mptcp_ndiffports_num_subflows"
|
||||
[ -z "$mptcp_rr_cwnd_limited" ] || sysctl -qew /sys/module/mptcp_rr/parameters/cwnd_limited="$mptcp_rr_cwnd_limited"
|
||||
[ -z "$mptcp_rr_num_segments" ] || sysctl -qew /sys/module/mptcp_rr/parameters/num_segments="$mptcp_rr_num_segments"
|
||||
[ -z "$mptcp_version" ] || sysctl -qew net.mptcp.mptcp_version="$mptcp_version"
|
||||
elif [ -f /proc/sys/net/mptcp/enabled ]; then
|
||||
sysctl -qew net.mptcp.enabled="$multipath_status"
|
||||
if [ -z "$(grep net.mptcp.enabled /etc/sysctl.d/zzz_openmptcprouter.conf)" ]; then
|
||||
echo "net.mptcp.enabled=${multipath_status}" >> /etc/sysctl.d/zzz_openmptcprouter.conf
|
||||
else
|
||||
sed -i "s:^net.mptcp.enabled=[0-1]*:net.mptcp.enabled=${multipath_status}:" /etc/sysctl.d/zzz_openmptcprouter.conf
|
||||
fi
|
||||
ip mptcp limits set add_addr_accepted $mptcp_add_addr_accepted subflows $mptcp_subflows >/dev/null 2>&1
|
||||
#[ -z "$mptcp_debug" ] || sysctl -qew net.mptcp.mptcp_debug="$mptcp_debug"
|
||||
[ -z "$mptcp_add_addr_timeout" ] || sysctl -qew net.mptcp.add_addr_timeout="$mptcp_add_addr_timeout"
|
||||
[ -z "$mptcp_checksum" ] || sysctl -qew net.mptcp.checksum_enabled="$mptcp_checksum"
|
||||
[ -z "$mptcp_stale_loss_cnt" ] || sysctl -qew net.mptcp.stale_loss_cnt="$mptcp_stale_loss_cnt"
|
||||
[ -z "$mptcp_pm_type" ] || sysctl -qew net.mptcp.pm_type="$mptcp_pm_type"
|
||||
[ -z "$mptcp_allow_join_initial_addr_port" ] || sysctl -qew net.mptcp.allow_join_initial_addr_port="$mptcp_allow_initial_addr_port"
|
||||
[ -z "$mptcp_close_timeout" ] || sysctl -qew net.mptcp.close_timeout="$mptcp_close_timeout"
|
||||
[ -z "$mptcp_syn_retrans_before_tcp_fallback" ] || sysctl -qew net.mptcp.syn_retrans_before_tcp_fallback="$mptcp_syn_retrans_before_tcp_fallback"
|
||||
[ -z "$mptcp_blackhole_timeout" ] || sysctl -qew net.mptcp.blackhole_timeout="$mptcp_blackhole_timeout"
|
||||
if [ -n "$mptcp_scheduler" ] && [ -d /usr/share/bpf/scheduler ]; then
|
||||
for scheduler in $(ls -1 /usr/share/bpf/scheduler/*.o); do
|
||||
bpftool struct_ops register $scheduler >/dev/null 2>&1
|
||||
done
|
||||
sysctl -qew net.mptcp.scheduler="$(echo $mptcp_scheduler | sed -e 's/mptcp_//' -e 's/.o//')" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
[ -z "$congestion" ] || sysctl -qew net.ipv4.tcp_congestion_control="$congestion"
|
||||
}
|
||||
|
||||
interface_macaddr_count() {
|
||||
local intf="$1"
|
||||
local dmacaddr="$2"
|
||||
config_get macaddr "$intf" macaddr
|
||||
[ "$macaddr" = "$dmacaddr" ] && [ -z "$(echo $intf | grep '\.')" ] && nbmac=$((nbmac+1))
|
||||
}
|
||||
|
||||
interface_max_metric() {
|
||||
local config="$1"
|
||||
if [ "$1" != "omrvpn" ] && [ "$1" != "omr6in4" ] && [ "$1" != "lan" ] && [ "$1" != "loopback" ]; then
|
||||
config_get metric "$config" ip4table
|
||||
if [ "$metric" -gt "$count" ] && [ "$metric" -lt "1000" ]; then
|
||||
count=$metric
|
||||
fi
|
||||
elif [ "$1" = "omrvpn" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.${config}.metric=1500
|
||||
set network.${config}.ip4table=1500
|
||||
set network.${config}.ip6table=61500
|
||||
commit network
|
||||
set openmptcprouter.${config}.metric=1500
|
||||
commit openmptcprouter
|
||||
EOF
|
||||
elif [ "$1" = "omr6in4" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.${config}.metric=1201
|
||||
set network.${config}.ip4table=1201
|
||||
set network.${config}.ip6table=61201
|
||||
commit network
|
||||
set openmptcprouter.${config}.metric=1201
|
||||
commit openmptcprouter
|
||||
EOF
|
||||
elif [ "$1" = "lan" ]; then
|
||||
sed -i 's:50 lan:9999 lan:g' /etc/iproute2/rt_tables
|
||||
fi
|
||||
}
|
||||
|
||||
interface_multipath_settings() {
|
||||
local mode iface proto metric ip4table
|
||||
local config="$1"
|
||||
local intf="$2"
|
||||
local enabled
|
||||
|
||||
network_get_device iface $config
|
||||
[ -z "$iface" ] && network_get_physdev iface $config
|
||||
[ -z "$iface" ] && iface=$(ifstatus "$config" | jsonfilter -q -e '@["l3_device"]')
|
||||
[ -z "$iface" ] && config_get iface "$config" ifname
|
||||
[ -n "$intf" ] && [ "$iface" != "$intf" ] && return 0
|
||||
|
||||
config_get enabled "$config" auto "1"
|
||||
config_get txqueuelen "$config" txqueuelen
|
||||
[ -n "$(echo $iface | grep '@')" ] && iface=$(ifstatus "$config" | jsonfilter -q -e '@["device"]')
|
||||
if [ "$(uci -q get openmptcprouter.${config}.metric)" = "" ] || [ "$(uci -q get openmptcprouter.${config}.metric)" = "1" ]; then
|
||||
count=$((count+1))
|
||||
metric=$count
|
||||
else
|
||||
metric="$(uci -q get openmptcprouter.${config}.metric)"
|
||||
fi
|
||||
[ "$metric" -gt 1000 ] && [ "${config}" != "omrvpn" ] && [ "${config}" != "omr6in4" ] && [ "${config}" != "loopback" ] && metric=$((metric-1000))
|
||||
if [ "${config}" = "lan" ] || [ "$(uci -q get network.${config}.ip4table)" = "lan" ] || [ "$(uci -q get network.${config}.ip4table)" = "9999" ]; then
|
||||
metric="9999"
|
||||
elif [ "${config}" = "omrvpn" ]; then
|
||||
metric="1500"
|
||||
elif [ "${config}" = "omr6in4" ]; then
|
||||
metric="1201"
|
||||
# elif [ "$(uci -q get network.${config}.multipath)" = "off" ]; then
|
||||
# metric="9998"
|
||||
fi
|
||||
config_set "$config" metric $metric
|
||||
uci -q set network.${config}.metric=$metric
|
||||
uci -q set network.${config}.ip4table=$metric
|
||||
uci -q set network.${config}.ip6table=6$metric
|
||||
uci -q set openmptcprouter.${config}.metric=$metric
|
||||
config_get mode "$config" multipath
|
||||
config_get disabled "$config" disabled
|
||||
[ "$disabled" = "1" ] && mode="off"
|
||||
id=$metric
|
||||
ip4table=$metric
|
||||
ip6table=6$metric
|
||||
[ -n "$iface" ] && {
|
||||
gro=$(uci -q get network.${config}.gro)
|
||||
[ "$gro" = "1" ] && ethtool -K $iface gro on >/dev/null 2>&1
|
||||
[ "$gro" = "0" ] && ethtool -K $iface gro off >/dev/null 2>&1
|
||||
gso=$(uci -q get network.${config}.gso)
|
||||
[ "$gso" = "1" ] && ethtool -K $iface gso on >/dev/null 2>&1
|
||||
[ "$gso" = "0" ] && ethtool -K $iface gso off >/dev/null 2>&1
|
||||
lro=$(uci -q get network.${config}.lro)
|
||||
[ "$lro" = "1" ] && ethtool -K $iface lro on >/dev/null 2>&1
|
||||
[ "$lro" = "0" ] && ethtool -K $iface lro off >/dev/null 2>&1
|
||||
ufo=$(uci -q get network.${config}.ufo)
|
||||
[ "$ufo" = "1" ] && ethtool -K $iface ufo on >/dev/null 2>&1
|
||||
[ "$ufo" = "0" ] && ethtool -K $iface ufo off >/dev/null 2>&1
|
||||
tso=$(uci -q get network.${config}.tso)
|
||||
[ "$tso" = "1" ] && ethtool -K $iface tso on >/dev/null 2>&1
|
||||
[ "$tso" = "0" ] && ethtool -K $iface tso off >/dev/null 2>&1
|
||||
}
|
||||
[ "$mode" = "" ] && {
|
||||
mode="$(uci -q get openmptcprouter.${config}.multipath)"
|
||||
[ -n "$mode" ] && uci -q set network.${config}.multipath="$mode"
|
||||
}
|
||||
[ "$mode" = "" ] && {
|
||||
[ "$config" = "lan" ] && mode="off"
|
||||
[ "$config" = "omrvpn" ] && mode="off"
|
||||
[ "$config" = "omr6in4" ] && mode="off"
|
||||
[ "$mode" = "" ] && mode="off"
|
||||
logger -t "MPTCP" "Multipath not defined for $config set to $mode"
|
||||
uci -q set network.${config}.multipath="$mode"
|
||||
uci -q set openmptcprouter.${config}.multipath="$mode"
|
||||
}
|
||||
[ "$mode" != "off" ] && {
|
||||
[ -n "$mptcpintf" ] && mptcpintf="$mptcpintf $iface"
|
||||
[ -z "$mptcpintf" ] && mptcpintf="$iface"
|
||||
[ -z "$mptcpmintf" ] && mptcpmintf="$config"
|
||||
uci -q set network.${config}.defaultroute=0
|
||||
uci -q set network.${config}.peerdns=0
|
||||
uci -q delete network.${config}.dns=0
|
||||
echo '' > /etc/resolv.conf >/dev/null 2>&1
|
||||
}
|
||||
[ "$mode" = "master" ] && {
|
||||
# Force that only one interface is master
|
||||
if [ "$master" != "" ]; then
|
||||
logger -t "MPTCP" "Multipath master already set, disable master for $config"
|
||||
mode="on"
|
||||
config_set "$config" multipath "on"
|
||||
uci -q set network.${config}.multipath="on"
|
||||
uci -q set openmptcprouter.${config}.multipath="on"
|
||||
else
|
||||
master="$config"
|
||||
fi
|
||||
}
|
||||
uci -q set openmptcprouter.${config}="interface"
|
||||
uci -q set openmptcprouter.${config}.multipath="$mode"
|
||||
|
||||
config_get macaddr "$config" macaddr ""
|
||||
[ -n "$macaddr" ] && {
|
||||
nbmac=0
|
||||
config_foreach interface_macaddr_count interface $macaddr
|
||||
[ "$nbmac" != "1" ] && {
|
||||
logger -t "MPTCP" "Duplicate MAC saved, removing"
|
||||
uci -q delete network.${config}.macaddr
|
||||
}
|
||||
}
|
||||
|
||||
[ "$enabled" = "0" ] && return 0
|
||||
[ -n "$intf" ] && [ "$iface" != "$intf" ] && return 0
|
||||
[ -z "$iface" ] && return 0
|
||||
#[ "$config" = "omrvpn" ] && return 0
|
||||
[ "$config" = "omrvpn" ] && mode="off"
|
||||
#[ -n "$(ifconfig | grep $iface)" ] || return 0
|
||||
[ -n "$(ip link show dev $iface)" ] || return 0
|
||||
[ "$(echo $iface | grep _dev)" != "" ] && return 0
|
||||
[ "$(echo $iface | grep '^if')" != "" ] && return 0
|
||||
[ "$iface" = "lo" ] && return 0
|
||||
status=`ifstatus $config | jsonfilter -q -e "@.up" | tr -d "\n"`
|
||||
[ "$status" = "false" ] && return 0
|
||||
|
||||
|
||||
#echo "îface: $iface"
|
||||
|
||||
#[ "$mode" = "off" ] && {
|
||||
# ip rule del table $id > /dev/null 2>&1
|
||||
# ip route flush $id > /dev/null 2>&1
|
||||
# return 1
|
||||
#}
|
||||
|
||||
# IPv4 Updates:
|
||||
local ipaddr
|
||||
local gateway
|
||||
local network
|
||||
local netmask
|
||||
local proto
|
||||
config_get proto $config proto
|
||||
if [ "$proto" = "static" ]; then
|
||||
config_get ipaddr $config ipaddr
|
||||
config_get gateway $config gateway
|
||||
config_get netmask $config netmask
|
||||
[ -n "$ipaddr" ] && [ -n "$netmask" ] && netmask=`ipcalc.sh $ipaddr/$netmask | sed -n '/PREFIX=/{;s/.*=//;s/ .*//;p;}'`
|
||||
[ -n "$ipaddr" ] && [ -n "$netmask" ] && network=`ipcalc.sh $ipaddr/$netmask | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
|
||||
elif [ "$proto" != "gre" ]; then
|
||||
network_get_ipaddr ipaddr $config
|
||||
[ -z "$ipaddr" ] && ipaddr=$(ip -4 addr show dev $iface | awk '/inet / {print $2; exit}' | cut -d/ -f1 | tr -d "\n")
|
||||
network_get_gateway gateway $config true
|
||||
[ -z "$gateway" ] && 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 -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
|
||||
if [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway )" != "ok" ]; then
|
||||
gateway=$(ubus call network.interface.$config status | jsonfilter -q -l 1 -e '@.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
|
||||
fi
|
||||
if [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway )" != "ok" ]; then
|
||||
gateway=$(ubus call network.interface.${config}_4 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
|
||||
fi
|
||||
if [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway )" != "ok" ]; then
|
||||
gateway=$(ubus call network.interface.${config}_4 status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
|
||||
fi
|
||||
if [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway )" != "ok" ]; then
|
||||
gateway=$(ip -4 r list dev "$iface" | awk '/via/ {print $3;exit}' | tr -d "\n")
|
||||
fi
|
||||
if [ -z "$gateway" ] || [ "$( valid_subnet4 $gateway )" != "ok" ]; then
|
||||
gateway=$(traceroute -m1 -i $iface 8.8.8.8 2>/dev/null | awk 'FNR==2{ print $2 }')
|
||||
[ "$gateway" = "*" ] && gateway=""
|
||||
fi
|
||||
network_get_subnet netmask $config
|
||||
[ -n "$netmask" ] && [ "$(echo $netmask | grep '/')" != "" ] && netmask=""
|
||||
[ -z "$netmask" ] && netmask=$(ip -4 addr show dev $iface | awk '/peer/ {print $4; exit}' | cut -d/ -f2 | tr -d "\n")
|
||||
[ -z "$netmask" ] && netmask=$(ip -4 addr show dev $iface | awk '/inet / {print $2;exit}' | cut -d/ -f2 | tr -d "\n")
|
||||
[ -n "$ipaddr" ] && ipaddr=$(echo $ipaddr | cut -d/ -f1 | tr -d "\n")
|
||||
[ -n "$ipaddr" ] && [ -n "$netmask" ] && netmask=`ipcalc.sh $ipaddr/$netmask | sed -n '/PREFIX=/{;s/.*=//;s/ .*//;p;}'`
|
||||
[ -n "$ipaddr" ] && [ -n "$netmask" ] && network=`ipcalc.sh $ipaddr/$netmask | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
|
||||
fi
|
||||
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.${config}_rule
|
||||
delete network.${config}_route
|
||||
delete network.${config}_route_default
|
||||
commit network
|
||||
EOF
|
||||
else
|
||||
[ -n "$(ip rule list | grep $id)" ] && ip rule del table $ip4table > /dev/null 2>&1
|
||||
ip route flush $id > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ -n "$gateway" ] && [ -n "$network" ]; then
|
||||
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.${config}_rule
|
||||
set network.${config}_rule=rule
|
||||
set network.${config}_rule.lookup=${id}
|
||||
set network.${config}_rule.priority=0
|
||||
set network.${config}_rule.src="${ipaddr}/32"
|
||||
set network.${config}_rule.created=mptcp
|
||||
delete network.${config}_route
|
||||
set network.${config}_route=route
|
||||
set network.${config}_route.interface=${config}
|
||||
set network.${config}_route.target=${network}
|
||||
set network.${config}_route.netmask=${netmask}
|
||||
set network.${config}_route.table=${ip4table}
|
||||
set network.${config}_route.created=mptcp
|
||||
delete network.${config}_route_default
|
||||
set network.${config}_route_default=route
|
||||
set network.${config}_route_default.interface=${config}
|
||||
set network.${config}_route_default.target='0.0.0.0'
|
||||
set network.${config}_route_default.netmask='0.0.0.0'
|
||||
set network.${config}_route_default.gateway=$gateway
|
||||
set network.${config}_route_default.table=${ip4table}
|
||||
set network.${config}_route_default.created=mptcp
|
||||
commit network
|
||||
EOF
|
||||
else
|
||||
[ -n "$ipaddr" ] && [ -z "$(ip rule show from $ipaddr table $ip4table)" ] && ip rule add from $ipaddr table $ip4table pref 0
|
||||
[ -z "$(ip rule show oif $iface table $ip4table)" ] && ip rule add oif $iface table $ip4table pref 0
|
||||
ip route replace $network/$netmask dev $iface scope link metric $id $initcwrwnd >/dev/null 2>&1
|
||||
ip route replace $network/$netmask dev $iface scope link table $ip4table $initcwrwnd >/dev/null 2>&1
|
||||
ip route replace $gateway dev $iface table $ip4table $initcwrwnd >/dev/null 2>&1
|
||||
ip route replace default via $gateway dev $iface table $ip4table $initcwrwnd >/dev/null 2>&1
|
||||
[ "$(uci -q get openmptcprouter.settings.defaultgw)" != "0" ] && {
|
||||
ip route replace $gateway dev $iface metric $id $initcwrwnd >/dev/null 2>&1
|
||||
ip route replace default via $gateway dev $iface metric $id $initcwrwnd >/dev/null 2>&1
|
||||
}
|
||||
#ip route flush cache $id >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
#config_get mode "$config" multipath ""
|
||||
#[ "$mode" = "" ] && mode="$(uci -q get openmptcprouter.${config}.multipath)"
|
||||
#[ "$mode" = "master" ] && {
|
||||
# #echo "ip route replace default via $gateway dev $iface"
|
||||
# ip route replace default via $gateway dev $iface >/dev/null 2>&1
|
||||
#}
|
||||
if [ "$txqueuelen" != "" ]; then
|
||||
#ifconfig $iface txqueuelen $txqueuelen > /dev/null 2>&1
|
||||
ip link set dev $iface txqueuelen $txqueuelen > /dev/null 2>&1
|
||||
else
|
||||
#ifconfig $iface txqueuelen 1000 > /dev/null 2>&1
|
||||
ip link set dev $iface txqueuelen 1000 > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
if [ -z "$gateway" ] && [ -n "$network" ]; then
|
||||
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.${config}_rule
|
||||
set network.${config}_rule=rule
|
||||
set network.${config}_rule.lookup=${id}
|
||||
set network.${config}_rule.priority=0
|
||||
set network.${config}_rule.src="${ipaddr}/32"
|
||||
set network.${config}_rule.created=mptcp
|
||||
delete network.${config}_route
|
||||
set network.${config}_route=route
|
||||
set network.${config}_route.interface=${config}
|
||||
set network.${config}_route.target=${network}
|
||||
set network.${config}_route.netmask=${netmask}
|
||||
set network.${config}_route.table=${ip4table}
|
||||
set network.${config}_route.created=mptcp
|
||||
delete network.${config}_route_default
|
||||
commit network
|
||||
EOF
|
||||
else
|
||||
[ -n "$ipaddr" ] && [ -z "$(ip rule show from $ipaddr table $ip4table)" ] && ip rule add from $ipaddr table $ip4table pref 0
|
||||
[ -z "$(ip rule show oif $iface table $ip4table)" ] && ip rule add oif $iface table $ip4table pref 0
|
||||
ip route replace $network/$netmask dev $iface scope link metric $id $initcwrwnd >/dev/null 2>&1
|
||||
ip route replace $network/$netmask dev $iface scope link table $ip4table $initcwrwnd >/dev/null 2>&1
|
||||
#ip route flush cache $id >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ "$txqueuelen" != "" ]; then
|
||||
#ifconfig $iface txqueuelen $txqueuelen > /dev/null 2>&1
|
||||
ip link set dev $iface txqueuelen $txqueuelen > /dev/null 2>&1
|
||||
else
|
||||
#ifconfig $iface txqueuelen 1000 > /dev/null 2>&1
|
||||
ip link set dev $iface txqueuelen 1000 > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" != "1" ] && [ "$config" != "omr6in4" ]; then
|
||||
# IPv6 Updates:
|
||||
local ip6addr
|
||||
local ipaddr6
|
||||
local gateway6
|
||||
local network6
|
||||
local netmask6
|
||||
config_get ipaddr6 $config ip6addr
|
||||
config_get gateway6 $config ip6gw
|
||||
if [ -n "$ipaddr6" ]; then
|
||||
ip6addr=`echo "$ipaddr6" | cut -d/ -f1 | tr -d "\n"`
|
||||
netmask6=`ipcalc -p $ipaddr6 | sed -n '/PREFIX=/{;s/.*=//;s/ .*//;p;}'`
|
||||
network6=`ipcalc -n $ip6addr | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
|
||||
fi
|
||||
if [ -z "$ip6addr" ] || [ -z "$gateway6" ]; then
|
||||
[ -z "$ip6addr" ] && network_get_ipaddr6 ip6addr $config
|
||||
[ -z "$ip6addr" ] && ip6addr=$(ip -6 addr show dev $iface | grep -v 'scope link' | awk '/inet6/ {print $2; exit}' | cut -d/ -f1 | tr -d "\n")
|
||||
[ -z "$gateway6" ] && network_get_gateway6 gateway6 $config true
|
||||
[ -z "$gateway6" ] && gateway6=$(ip -6 r list dev $iface | grep -v default | awk '/proto static/ {print $1; exit}' | tr -d "\n")
|
||||
[ -z "$gateway6" ] && gateway6=$(uci -q get "network.$config.ip6gw")
|
||||
[ -z "$gateway6" ] && gateway6=$(ubus call network.interface.$config status | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n")
|
||||
#if [ -z "$gateway6" ] || [ "$( valid_subnet6 $gateway6 )" != "ok" ]; then
|
||||
# gateway6=$(ubus call network.interface.$config status | jsonfilter -q -l 1 -e '@.route[@.target="::"].nexthop' | tr -d "\n")
|
||||
#fi
|
||||
#if [ -z "$gateway6" ] || [ "$( valid_subnet6 $gateway6 )" != "ok" ]; then
|
||||
# echo "ipv6 not ok"
|
||||
# gateway6=$(ubus call network.interface.${config}_6 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n")
|
||||
#fi
|
||||
gateway6=$(echo $gateway6 | cut -d/ -f1 | tr -d "\n")
|
||||
netmask6=$(ubus call network.interface.$config status | jsonfilter -q -l 1 -e '@["ipv6-prefix"][0].mask' | tr -d "\n")
|
||||
network6=$(ubus call network.interface.$config status | jsonfilter -q -l 1 -e '@[".ipv6-prefix"][0].address' | tr -d "\n")
|
||||
[ -z "$netmask6" ] && [ -n "$ip6addr" ] && netmask6=$(ip -6 addr show dev $iface | grep $ip6addr | awk '/inet6/ {print $2; exit}' | cut -d/ -f2 | tr -d "\n")
|
||||
[ -z "$network6" ] && [ -n "$ip6addr" ] && [ -n "$netmask6" ] && network6=`/usr/sbin/ipcalc -n ${ip6addr}/${netmask6} | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
|
||||
fi
|
||||
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.${config}_rule6
|
||||
delete network.${config}_route6
|
||||
delete network.${config}_route6_default
|
||||
commit network
|
||||
EOF
|
||||
else
|
||||
[ -n "$(ip -6 rule list | grep 6$id)" ] && ip -6 rule del table $ip6table > /dev/null 2>&1
|
||||
ip -6 route flush 6$id > /dev/null 2>&1
|
||||
fi
|
||||
if [ -n "$gateway6" ] && [ -n "$network6" ]; then
|
||||
#echo "gateway6: $gateway6 - network6: $network6 -> ok"
|
||||
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.${config}_rule6
|
||||
set network.${config}_rule6=rule6
|
||||
set network.${config}_rule6.lookup=6${id}
|
||||
set network.${config}_rule6.priority=0
|
||||
set network.${config}_rule6.src="${ipaddr6}/127"
|
||||
set network.${config}_rule6.created=mptcp
|
||||
delete network.${config}_route6
|
||||
set network.${config}_route6=route6
|
||||
set network.${config}_route6.interface=${config}
|
||||
set network.${config}_route6.target=${network6}/${netmask6}
|
||||
set network.${config}_route6.table=${ip6table}
|
||||
set network.${config}_route6.created=mptcp
|
||||
delete network.${config}_route6_default
|
||||
set network.${config}_route6_default=route6
|
||||
set network.${config}_route6_default.interface=${config}
|
||||
set network.${config}_route6_default.target='::'
|
||||
set network.${config}_route6_default.gateway=$gateway6
|
||||
set network.${config}_route6_default.table=${ip6table}
|
||||
set network.${config}_route6_default.created=mptcp
|
||||
commit network
|
||||
EOF
|
||||
else
|
||||
[ -n "$ip6addr" ] && ip -6 rule add from $ip6addr table $ip6table pref 0 >/dev/null 2>&1
|
||||
[ -z "$(ip rule show pref 0 table $ip6table oif $iface)" ] && ip rule add oif $iface table $ip6table pref 0
|
||||
ip -6 route replace $network6/$netmask6 dev $iface scope link metric 6$id $initcwrwnd >/dev/null 2>&1
|
||||
ip -6 route replace $network6/$netmask6 dev $iface scope link table $ip6table $initcwrwnd >/dev/null 2>&1
|
||||
ip -6 route replace $gateway6 dev $iface table $ip6table $initcwrwnd >/dev/null 2>&1
|
||||
ip -6 route replace default via $gateway6 dev $iface table $ip6table $initcwrwnd >/dev/null 2>&1
|
||||
[ "$(uci -q get openmptcprouter.settings.defaultgw)" != "0" ] && {
|
||||
ip -6 route replace $gateway6 dev $iface metric 6$id $initcwrwnd >/dev/null 2>&1
|
||||
ip -6 route replace default via $gateway6 dev $iface metric 6$id $initcwrwnd >/dev/null 2>&1
|
||||
}
|
||||
#ip -6 route flush cache 6$id >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
#config_get mode "$config" multipath "off"
|
||||
#[ "$mode" = "master" ] && {
|
||||
# ip -6 route replace default via $gateway6 dev $iface >/dev/null 2>&1
|
||||
#}
|
||||
#[ "$mode" = "off" ] && {
|
||||
# ifconfig $iface txqueuelen 50 > /dev/null 2>&1
|
||||
#} || {
|
||||
# ifconfig $iface txqueuelen 100 > /dev/null 2>&1
|
||||
#}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$(uci -q get openmptcprouter.settings.force_multipath)" != "0" ] && [ -n "$(ip a show dev $iface | grep inet)" ]; then
|
||||
if ([ "$mode" = "master" ] || [ "$mode" = "on" ]) && [ -z "$(multipath $iface | grep default)" ]; then
|
||||
logger -t "MPTCP" "Set $iface to $mode from $(multipath $iface)"
|
||||
multipath "$iface" "on"
|
||||
elif ([ "$mode" = "off" ] || [ -z "$mode" ]) && [ -z "$(multipath $iface | grep deactivated)" ]; then
|
||||
logger -t "MPTCP" "Set $iface to $mode from $(multipath $iface)"
|
||||
multipath "$iface" "$mode"
|
||||
elif [ "$mode" = "backup" ] && [ -z "$(multipath $iface | grep backup)" ]; then
|
||||
logger -t "MPTCP" "Set $iface to $mode from $(multipath $iface)"
|
||||
multipath "$iface" "$mode"
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
load_interfaces() {
|
||||
network_get_device ifname $1
|
||||
[ -z "$ifname" ] && network_get_physdev ifname $1
|
||||
[ -z "$ifname" ] && config_get ifname "$1" device
|
||||
[ -z "$ifname" ] && config_get ifname "$1" ifname
|
||||
config_get multipath "$1" multipath ""
|
||||
[ -z "$multipath" ] && multipath="$(uci -q get openmptcprouter.$1.multipath)"
|
||||
[ "$multipath" != "off" ] && [ "$multipath" != "" ] && interfaces=" ${ifname} ${interfaces}"
|
||||
}
|
||||
|
||||
set_multipath() {
|
||||
ls -1 /sys/class/net/ | while read iface; do
|
||||
exist=0
|
||||
for ifacemptcp in $mptcpintf; do
|
||||
if [ "$iface" = "$ifacemptcp" ]; then
|
||||
exist=1
|
||||
fi
|
||||
done
|
||||
[ "$exist" = "0" ] && [ -z "$(multipath $iface | grep deactivated)" ] && [ "$iface" != "bonding_master" ] && [ -n "$(multipath $iface)" ] && {
|
||||
logger -t "MPTCP" "Disabling MPTCP on interface $iface not found in enabled multipath list"
|
||||
multipath $iface off >/dev/null 2>&1
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
add_route() {
|
||||
config_get disabled "$1" disabled
|
||||
[ "$disabled" = "1" ] && return 0
|
||||
config_get target "$1" target
|
||||
routeset="$target"
|
||||
config_get netmask "$1" netmask
|
||||
[ -n "$target" ] && [ -n "$netmask" ] && {
|
||||
netmask=`ipcalc.sh $target/$netmask | sed -n '/PREFIX=/{;s/.*=//;s/ .*//;p;}'`
|
||||
network=`ipcalc.sh $target/$netmask | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
|
||||
[ -n "$netmask" ] && [ "$target" = "$network" ] && routeset="$routeset/$netmask"
|
||||
}
|
||||
config_get gateway "$1" gateway
|
||||
[ -n "$gateway" ] && routeset="$routeset via $gateway"
|
||||
config_get metric "$1" metric
|
||||
[ -n "$metric" ] && routeset="$routeset metric $metric"
|
||||
config_get mtu "$1" mtu
|
||||
[ -n "$mtu" ] && routeset="$routeset mtu $mtu"
|
||||
config_get type "$1" type
|
||||
[ -n "$type" ] && routeset="$routeset type $type"
|
||||
config_get table "$1" table
|
||||
[ -n "$table" ] && routeset="table $table"
|
||||
config_get interface "$1" interface
|
||||
iface=$(ifstatus "$interface" | jsonfilter -q -e '@["l3_device"]')
|
||||
[ -n "$(echo $iface | grep '@')" ] && iface=$(ifstatus "$interface" | jsonfilter -q -e '@["device"]')
|
||||
[ -n "$iface" ] && routeset="$routeset dev $iface"
|
||||
logger -t "MPTCP" "Add route $routeset"
|
||||
[ -n "$routeset" ] && {
|
||||
ip route replace ${routeset} >/dev/null 2>&1
|
||||
}
|
||||
}
|
||||
|
||||
add_route6() {
|
||||
config_get disabled "$1" disabled
|
||||
[ "$disabled" = "1" ] && return 0
|
||||
config_get target "$1" target
|
||||
routeset="$target"
|
||||
config_get gateway "$1" gateway
|
||||
[ -n "$gateway" ] && routeset="$routeset via $gateway"
|
||||
config_get metric "$1" metric
|
||||
[ -n "$metric" ] && routeset="$routeset metric $metric"
|
||||
config_get mtu "$1" mtu
|
||||
[ -n "$mtu" ] && routeset="$routeset mtu $mtu"
|
||||
config_get type "$1" type
|
||||
[ -n "$type" ] && routeset="$routeset type $type"
|
||||
config_get table "$1" table
|
||||
[ -n "$table" ] && routeset="table $table"
|
||||
config_get interface "$1" interface
|
||||
iface=$(ifstatus "$interface" | jsonfilter -q -e '@["l3_device"]')
|
||||
[ -n "$(echo $iface | grep '@')" ] && iface=$(ifstatus "$interface" | jsonfilter -q -e '@["device"]')
|
||||
[ -n "$iface" ] && routeset="$routeset dev $iface"
|
||||
logger -t "MPTCP" "Add IPv6 route $routeset"
|
||||
[ -n "$routeset" ] && {
|
||||
ip -6 route replace ${routeset} >/dev/null 2>&1
|
||||
}
|
||||
}
|
||||
|
||||
remove() {
|
||||
logger -t "MPTCP" "Remove network.$1"
|
||||
uci -q delete network.$1
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local intf=$1
|
||||
local id intfmaster
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/network.sh
|
||||
#[ -n "$intf" ] && multipath "${intf}" off >/dev/null 2>&1
|
||||
[ -z "$intf" ] && global_multipath_settings
|
||||
|
||||
[ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep '3-model-b')" ] && [ "$(ip link show eth0 | grep UP)" = "" ] && {
|
||||
# RPI 3 workaround no network at boot
|
||||
ethtool eth0 > /dev/null 2>&1
|
||||
ethtool -s eth0 autoneg off > /dev/null 2>&1
|
||||
ip link set eth0 up > /dev/null 2>&1
|
||||
ethtool -s eth0 autoneg on > /dev/null 2>&1
|
||||
}
|
||||
|
||||
mptcpintf=""
|
||||
mptcpmintf=""
|
||||
master=""
|
||||
count=0
|
||||
config_load openmptcprouter
|
||||
config_foreach interface_max_metric interface
|
||||
|
||||
initcwrwnd=""
|
||||
config_load network
|
||||
#config_foreach remove route
|
||||
#config_foreach remove route6
|
||||
#config_foreach remove rule
|
||||
#config_foreach remove rule6
|
||||
#[ -z "$intf" ] && [ -n "$(uci -q get network.@route[-1])" ] && {
|
||||
## logger -t "MPTCP" "Flush main table"
|
||||
## ip route flush table main
|
||||
## ip -6 route flush table main
|
||||
# logger -t "MPTCP" "Flush route cache"
|
||||
# ip route flush cache
|
||||
# ip -6 route flush cache
|
||||
#}
|
||||
if [ "$(uci -q get network.globals.mptcp_disable_initial_config)" != "1" ]; then
|
||||
config_foreach interface_multipath_settings interface $intf
|
||||
config_foreach add_route route
|
||||
config_foreach add_route6 route6
|
||||
[ -z "$intf" ] && set_multipath
|
||||
|
||||
# If no master is defined, one interface is defined as master
|
||||
if [ "$master" = "" ] && [ -z "$intf" ]; then
|
||||
intfmaster="$mptcpmintf"
|
||||
[ "$intfmaster" != "" ] && [ "$(uci -q show network | grep \"multipath='master'\")" ] && {
|
||||
logger -t "MPTCP" "No master multipath defined, setting it to $intfmaster"
|
||||
uci -q set network.${intfmaster}.multipath="master"
|
||||
uci -q set openmptcprouter.${intfmaster}.multipath="master"
|
||||
}
|
||||
fi
|
||||
fi
|
||||
[ -n "$(uci -q changes network)" ] && uci -q commit network
|
||||
[ -n "$(uci -q changes openmptcprouter)" ] && uci -q commit openmptcprouter
|
||||
[ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep raspberry)" ] && [ -z "$(ubus call system board | jsonfilter -e '@.board_name' | grep '4-model-b')" ] && [ -z "$(ubus call system board | jsonfilter -e '@.board_name' | grep '5')" ] && {
|
||||
ethtool --offload eth0 rx off tx off > /dev/null 2>&1
|
||||
}
|
||||
[ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep -i r2s)" ] && {
|
||||
ethtool -K eth0 rx off tx off > /dev/null 2>&1
|
||||
ethtool -K eth1 rx off tx off > /dev/null 2>&1
|
||||
}
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
rc_procd start_service "$@"
|
||||
return 0
|
||||
}
|
||||
|
||||
service_triggers_load_interface() { ifaces="${ifaces}${1} "; }
|
||||
|
||||
service_triggers() {
|
||||
local ifaces n
|
||||
config_load network
|
||||
config_foreach service_triggers_load_interface 'interface';
|
||||
procd_add_reload_trigger "network"
|
||||
procd_open_trigger
|
||||
for n in $ifaces; do
|
||||
network_get_device iface "$n"
|
||||
[ -z "$iface" ] && network_get_physdev iface "$n"
|
||||
[ -z "$iface" ] && iface=$(ifstatus "$n" | jsonfilter -q -e '@["l3_device"]')
|
||||
[ -z "$iface" ] && config_get iface "$n" ifname
|
||||
[ -z "$iface" ] && continue
|
||||
procd_add_reload_interface_trigger "$n"
|
||||
procd_add_interface_trigger "interface.*" "$n" /etc/init.d/mptcp reload "$iface"
|
||||
done
|
||||
procd_close_trigger
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-mptcp.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-mptcp.json << EEOF
|
||||
{
|
||||
"config": "mptcp",
|
||||
"init": "mptcp"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
if [ "$(uci -q get network.globals.mptcp_path_manager)" = "" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.multipath='enable'
|
||||
set network.globals.mptcp_path_manager='fullmesh'
|
||||
set network.globals.mptcp_scheduler='blest'
|
||||
set network.globals.congestion='bbr2'
|
||||
set network.globals.mptcp_checksum=0
|
||||
set network.globals.mptcp_debug=0
|
||||
set network.globals.mptcp_syn_retries=4
|
||||
set network.globals.mptcp_subflows=8
|
||||
set network.globals.mptcp_add_addr_accepted=1
|
||||
set network.globals.mptcp_add_addr_timeout=120
|
||||
set network.globals.mptcp_pm_type=0
|
||||
set network.globals.mptcp_disable_initial_config=0
|
||||
set network.globals.mptcp_force_multipath=1
|
||||
set network.globals.mptcpd_enable=0
|
||||
set network.globals.mptcp_close_timeout=60
|
||||
set network.globals.mptcp_blackhole_timeout=0
|
||||
set network.globals.mptcp_syn_retrans_before_tcp_fallback=2
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
# BBRv2 is replaced by BBRv3
|
||||
if [ "$(uci -q get network.globals.congestion)" = "bbr2" ] && [ -z "$(uname -a | grep 5.4)" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.congestion='bbr'
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_syn_retries)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_syn_retries=4
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_checksum)" != "0" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_checksum=0
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_checksum)" = "enable" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_checksum=1
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_checksum)" = "disable" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_checksum=0
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_debug)" != "0" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_debug=0
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ "$(uci -q show network.globals | grep mptcp_fullmesh)" = "" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_fullmesh_num_subflows=1
|
||||
set network.globals.mptcp_fullmesh_create_on_err=1
|
||||
set network.globals.mptcp_ndiffports_num_subflows=1
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_subflows)" = "" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_subflows=8
|
||||
set network.globals.mptcp_add_addr_accepted=8
|
||||
set network.globals.mptcp_add_addr_timeout=120
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_add_addr_accepted)" = "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_add_addr_accepted=8
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@mptcp[-1]
|
||||
add ucitrack mptcp
|
||||
set ucitrack.@mptcp[-1].init=mptcp
|
||||
commit ucitrack
|
||||
EOF
|
||||
if [ "$(uci -q get ucitrack.@network[-1].affects | grep mptcp)" = "" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
add_list ucitrack.@network[-1].affects=mptcp
|
||||
commit ucitrack
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q get network.globals.mptcp_close_timeout)" = "" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.mptcp_close_timeout=60
|
||||
set network.globals.mptcp_blackhole_timeout=0
|
||||
set network.globals.mptcp_syn_retrans_before_tcp_fallback=2
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
exit 0
|
||||
Executable
+246
@@ -0,0 +1,246 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Update the MPTCP flags with or without the pached iproute2
|
||||
#
|
||||
# Author: Mario Krueger <openwrt at xedp3x.de>
|
||||
# Ycarus (Yannick Chabanois) for OpenMPTCProuter <contact@openmptcprouter.com>
|
||||
# Released under GPL 3 or later
|
||||
|
||||
if [ -d "/proc/sys/net/mptcp" ]; then
|
||||
if ([ -f /proc/sys/net/mptcp/mptcp_enabled ] && [ `cat /proc/sys/net/mptcp/mptcp_enabled` = 0 ]) || ([ -f /proc/sys/net/mptcp/enabled ] && [ `cat /proc/sys/net/mptcp/enabled` = 0 ]); then
|
||||
echo "MPTCP is disabled!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Your device don't support multipath-TCP."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"-h")
|
||||
echo " Multipath-TCP configuration tool"
|
||||
echo "show/update flags:"
|
||||
echo " multipath [device]"
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_enabled ]; then
|
||||
echo " multipath device {on | off | backup }"
|
||||
else
|
||||
echo " multipath device {on | off | signal | backup }"
|
||||
fi
|
||||
echo
|
||||
echo "show established conections: -c"
|
||||
echo "show fullmesh info: -f"
|
||||
echo "show kernel config: -k"
|
||||
echo "show MPTCP info: -m"
|
||||
if [ -f /proc/sys/net/mptcp/enabled ]; then
|
||||
echo "verify MPTCP interface: -v device"
|
||||
fi
|
||||
echo
|
||||
echo "Flag on the device, to enable/disable MPTCP for this interface. The backup-flag"
|
||||
echo "will allow a subflow to be established across this interface, but only be used"
|
||||
echo "as backup."
|
||||
echo
|
||||
exit 0 ;;
|
||||
"-c")
|
||||
if [ -f /proc/net/mptcp_net/mptcp ]; then
|
||||
cat /proc/net/mptcp_net/mptcp
|
||||
else
|
||||
ss -M
|
||||
fi
|
||||
exit 0;;
|
||||
"-f")
|
||||
if [ -f /proc/net/mptcp_fullmesh ]; then
|
||||
cat /proc/net/mptcp_fullmesh
|
||||
else
|
||||
ip mptcp endpoint | grep fullmesh
|
||||
fi
|
||||
exit 0;;
|
||||
"-k")
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_enabled ]; then
|
||||
echo Enabled: `cat /proc/sys/net/mptcp/mptcp_enabled`
|
||||
elif [ -f /proc/sys/net/mptcp/enabled ]; then
|
||||
echo Enabled: `cat /proc/sys/net/mptcp/enabled`
|
||||
fi
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_path_manager ]; then
|
||||
echo Path Manager: `cat /proc/sys/net/mptcp/mptcp_path_manager`
|
||||
fi
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_checksum ]; then
|
||||
echo Use checksum: `cat /proc/sys/net/mptcp/mptcp_checksum`
|
||||
else
|
||||
echo Use checksum: `cat /proc/sys/net/mptcp/checksum_enabled`
|
||||
fi
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_scheduler ]; then
|
||||
echo Scheduler: `cat /proc/sys/net/mptcp/mptcp_scheduler`
|
||||
fi
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_syn_retries ]; then
|
||||
echo Syn retries: `cat /proc/sys/net/mptcp/mptcp_syn_retries`
|
||||
fi
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_debug ]; then
|
||||
echo Debugmode: `cat /proc/sys/net/mptcp/mptcp_debug`
|
||||
fi
|
||||
echo
|
||||
exit 0 ;;
|
||||
"-m")
|
||||
if [ -f /proc/net/mptcp_net/snmp ]; then
|
||||
cat /proc/net/mptcp_net/snmp
|
||||
else
|
||||
nstat -z | grep -i mptcp
|
||||
fi
|
||||
exit 0 ;;
|
||||
"-v")
|
||||
if [ -f /proc/sys/net/mptcp/enabled ]; then
|
||||
DEVICE="$2"
|
||||
endpoint="$(ip mptcp endpoint show)"
|
||||
if [ -f /usr/bin/jsonfilter ]; then
|
||||
IP=$(ip -j a show $DEVICE scope global | jsonfilter -e '@[0].addr_info[*].local')
|
||||
elif [ -f /usr/bin/jq ]; then
|
||||
IP=$(ip -j a show $DEVICE scope global | jq -r '.[0].addr_info[].local')
|
||||
else
|
||||
echo "jsonfilter or jq are required"
|
||||
exit 1
|
||||
fi
|
||||
[ -n "$IP" ] && [ -n "$endpoint" ] && ID=$(echo "${endpoint}" show | grep "$IP " | awk '{print $3}')
|
||||
fi
|
||||
if [ -n "$ID" ]; then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "NOK"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"")
|
||||
for ifpath in /sys/class/net/*; do
|
||||
$0 ${ifpath##*/}
|
||||
done
|
||||
exit 0;;
|
||||
*);;
|
||||
esac
|
||||
|
||||
DEVICE="$1"
|
||||
TYPE="$2"
|
||||
#FLAG_PATH=`find /sys/devices/ -path "*/net/$DEVICE/flags"`
|
||||
|
||||
[ -e "/sys/class/net/$DEVICE/" ] || {
|
||||
#echo "Device '$DEVICE' can't found!"
|
||||
#echo "Use the hardware name like in ifconfig"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -f /proc/sys/net/mptcp/mptcp_enabled ]; then
|
||||
FLAG_PATH="/sys/class/net/$DEVICE/flags"
|
||||
IFF=`cat $FLAG_PATH`
|
||||
|
||||
IFF_OFF="0x80000"
|
||||
IFF_ON="0x00"
|
||||
IFF_BACKUP="0x100000"
|
||||
IFF_HANDOVER="0x200000"
|
||||
IFF_MASK="0x380000"
|
||||
|
||||
case $TYPE in
|
||||
"off") FLAG=$IFF_OFF;;
|
||||
"on") FLAG=$IFF_ON;;
|
||||
"backup") FLAG=$IFF_BACKUP;;
|
||||
"handover") FLAG=$IFF_HANDOVER;;
|
||||
"")
|
||||
IFF=`printf "0x%02x" $(($IFF&$IFF_MASK))`
|
||||
case "$IFF" in
|
||||
$IFF_OFF) echo $DEVICE is deactivated;;
|
||||
$IFF_ON) echo $DEVICE is in default mode;;
|
||||
$IFF_BACKUP) echo $DEVICE is in backup mode;;
|
||||
$IFF_HANDOVER) echo $DEVICE is in handover mode;;
|
||||
*) echo "Unkown state!" && exit 1;;
|
||||
esac
|
||||
exit 0;;
|
||||
*) echo "Unkown flag! Use 'multipath -h' for help" && exit 1;;
|
||||
esac
|
||||
|
||||
printf "0x%02x" $(($(($IFF^$(($IFF&$IFF_MASK))))|$FLAG)) > $FLAG_PATH
|
||||
else
|
||||
endpoint="$(ip mptcp endpoint show)"
|
||||
if [ -n "$TYPE" ]; then
|
||||
# Remove not needed if* interfaces in MPTCP
|
||||
[ -n "$endpoint" ] && oldintfs=$(echo "${endpoint}" | grep "dev if" | awk '{ print $3 }')
|
||||
[ -n "$oldintfs" ] && {
|
||||
for oldintf in $oldintfs; do
|
||||
ip mptcp endpoint delete id $oldintf >/dev/null 2>&1
|
||||
done
|
||||
endpoint="$(ip mptcp endpoint show)"
|
||||
}
|
||||
fi
|
||||
if [ -n "$endpoint" ]; then
|
||||
ID=$(echo "${endpoint}" | sort | grep "dev $DEVICE " | awk '{print $3}')
|
||||
IFF=$(echo "${endpoint}" | sort | grep -m 1 -E "dev $DEVICE " | awk '{print $4; exit}')
|
||||
IFF2=$(echo "${endpoint}" | sort | grep -m 1 -E "dev $DEVICE " | awk '{print $5; exit}')
|
||||
fi
|
||||
if [ -n "$TYPE" ]; then
|
||||
#IP=$(ip a show $DEVICE | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
|
||||
if [ -f /usr/bin/jsonfilter ]; then
|
||||
IP=$(ip -j a show $DEVICE scope global | jsonfilter -e '@[0].addr_info[*].local')
|
||||
elif [ -f /usr/bin/jq ]; then
|
||||
IP=$(ip -j a show $DEVICE scope global | jq -r '.[0].addr_info[].local')
|
||||
else
|
||||
echo "jsonfilter or jq are required"
|
||||
exit 1
|
||||
fi
|
||||
[ -z "$ID" ] && [ -n "$IP" ] && [ -n "$endpoint" ] && ID=$(echo "${endpoint}" show | grep "$IP " | awk '{print $3}')
|
||||
[ -n "$endpoint" ] && RMID=$(echo "${endpoint}" | grep '::ffff' | awk '{ print $3 }')
|
||||
[ -n "$RMID" ] && ip mptcp endpoint delete id $RMID >/dev/null 2>&1
|
||||
fi
|
||||
case $TYPE in
|
||||
"off")
|
||||
[ -n "$ID" ] && {
|
||||
for i in $ID; do
|
||||
ip mptcp endpoint delete id $i >/dev/null 2>&1
|
||||
done
|
||||
}
|
||||
exit 0;;
|
||||
"on")
|
||||
[ -n "$ID" ] && {
|
||||
for i in $ID; do
|
||||
ip mptcp endpoint delete id $i >/dev/null 2>&1
|
||||
done
|
||||
}
|
||||
for i in $IP; do
|
||||
ip mptcp endpoint add $i dev $DEVICE subflow fullmesh
|
||||
done
|
||||
exit 0;;
|
||||
"signal")
|
||||
[ -n "$ID" ] && {
|
||||
for i in $ID; do
|
||||
ip mptcp endpoint delete id $i >/dev/null 2>&1
|
||||
done
|
||||
}
|
||||
for i in $IP; do
|
||||
#ip mptcp endpoint add $i dev $DEVICE signal subflow fullmesh
|
||||
ip mptcp endpoint add $i dev $DEVICE signal
|
||||
done
|
||||
exit 0;;
|
||||
"backup")
|
||||
[ -n "$ID" ] && {
|
||||
for i in $ID; do
|
||||
ip mptcp endpoint delete id $i >/dev/null 2>&1
|
||||
done
|
||||
}
|
||||
for i in $IP; do
|
||||
ip mptcp endpoint add $i dev $DEVICE subflow backup fullmesh
|
||||
done
|
||||
exit 0;;
|
||||
"")
|
||||
case "$IFF" in
|
||||
"") echo $DEVICE is deactivated;;
|
||||
"subflow")
|
||||
case "$IFF2" in
|
||||
"backup") echo $DEVICE is in backup mode;;
|
||||
"fullmesh") echo $DEVICE is in default mode;;
|
||||
"") echo $DEVICE is in subflow mode;;
|
||||
esac
|
||||
;;
|
||||
"signal") echo $DEVICE is in signal mode;;
|
||||
*) echo "$DEVICE Unkown state!" && exit 1;;
|
||||
esac
|
||||
exit 0;;
|
||||
*) echo "Unkown flag! Use 'multipath -h' for help" && exit 1;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user