1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-12 18:41:51 +00:00

Fix route creation

This commit is contained in:
Ycarus 2018-12-11 15:01:03 +01:00
parent 1b522d61e3
commit 0c05f504fd
2 changed files with 36 additions and 46 deletions

View file

@ -46,34 +46,31 @@ interface_multipath_settings() {
config_get iface "$config" ifname config_get iface "$config" ifname
count=$(($count+1)) count=$(($count+1))
id=$count id=$count
ip rule del table $id > /dev/null 2>&1
ip route flush $id > /dev/null 2>&1
ip -6 rule del table 6$id > /dev/null 2>&1
ip -6 route flush 6$id > /dev/null 2>&1
[ -z "$iface" ] && iface=$(ifstatus "$config" | jsonfilter -q -e '@["l3_device"]') config_get mode "$config" multipath "off"
[ "$mode" != "off" ] && {
[ -n "$mptcpintf" ] && mptcpintf="$mptcpintf $iface"
[ -z "$mptcpintf" ] && mptcpintf="$iface"
}
[ "$mode" = "master" ] && {
mode="on"
# Force that only one interface is master
if [ "$master" != "" ]; then
logger -t "MPTCP" "Multipath master already set, disable master for $config"
uci -q set network.$config.multipath="on"
uci -q commit network
else
master="$config"
fi
}
[ "$enabled" = "0" ] && return 0 [ "$enabled" = "0" ] && return 0
[ -z "$iface" ] && iface=$(ifstatus "$config" | jsonfilter -q -e '@["l3_device"]')
[ -n "$intf" ] && [ "$iface" != "$intf" ] && return 0 [ -n "$intf" ] && [ "$iface" != "$intf" ] && return 0
[ -z "$iface" ] && return 0 [ -z "$iface" ] && return 0
[ -n "$(ifconfig | grep $iface)" ] || return 0 [ -n "$(ifconfig | grep $iface)" ] || return 0
[ "$(echo $iface | grep _dev)" != "" ] && return 0 [ "$(echo $iface | grep _dev)" != "" ] && return 0
config_get mode "$config" multipath "off"
[ "$mode" = "master" ] && {
mode="on"
# Force that only one interface is master
if [ -n "$master" ]; then
uci -q network.$config.multipath="on"
else
master=$config
fi
}
multipath "$iface" "$mode" multipath "$iface" "$mode"
[ "$mode" != "off" ] && {
[ -z "$mptcpintf" ] && mptcpintf="$iface"
[ -n "$mptcpintf" ] && mptcpintf="$mptcpintf $iface"
}
#[ "$mode" = "off" ] && { #[ "$mode" = "off" ] && {
# ip rule del table $id > /dev/null 2>&1 # ip rule del table $id > /dev/null 2>&1
# ip route flush $id > /dev/null 2>&1 # ip route flush $id > /dev/null 2>&1
@ -117,8 +114,6 @@ interface_multipath_settings() {
ip route flush $id ip route flush $id
config_get mode "$config" multipath "off" config_get mode "$config" multipath "off"
local enabled
config_get enabled "$config" auto "1"
[ "$mode" = "master" ] && { [ "$mode" = "master" ] && {
ip route replace default via $gateway dev $iface ip route replace default via $gateway dev $iface
} }
@ -165,8 +160,6 @@ interface_multipath_settings() {
ip -6 route flush 6$id ip -6 route flush 6$id
config_get mode "$config" multipath "off" config_get mode "$config" multipath "off"
local enabled
config_get enabled "$config" auto "1"
[ "$mode" = "master" ] && { [ "$mode" = "master" ] && {
ip -6 route replace default via $gateway6 dev $iface ip -6 route replace default via $gateway6 dev $iface
} }
@ -199,7 +192,7 @@ set_multipath() {
start_service() { start_service() {
local intf=$1 local intf=$1
local id count local id count intfmaster
. /lib/functions.sh . /lib/functions.sh
. /lib/functions/network.sh . /lib/functions/network.sh
global_multipath_settings global_multipath_settings
@ -210,7 +203,12 @@ start_service() {
set_multipath set_multipath
# If no master is defined, one interface is defined as master # If no master is defined, one interface is defined as master
if [ "$master" = "" ]; then if [ "$master" = "" ]; then
uci -q set network.$(echo $mptcpintf | cut -d' ' -f1 | tr -d "\n").multipath="master" intfmaster="$(echo $mptcpintf | cut -d' ' -f1 | tr -d '\n')"
[ "$intfmaster" != "" ] && {
logger -t "MPTCP" "No master multipath defined, setting it to $intfmaster"
uci -q set network.${intfmaster}.multipath="master"
uci -q commit network
}
fi fi
[ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep raspberry)" ] && { [ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep raspberry)" ] && {
ethtool --offload eth0 rx off tx off ethtool --offload eth0 rx off tx off

View file

@ -42,14 +42,14 @@ set_ss_route() {
nginxip=$(echo $up | cut -d: -f1) nginxip=$(echo $up | cut -d: -f1)
if [ "$nginxip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $nginxip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then if [ "$nginxip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $nginxip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then
_log "Set server $nginxip route via $OMR_TRACKER_DEVICE" _log "Set server $nginxip route via $OMR_TRACKER_DEVICE"
ip route replace $nginxip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric ip route replace $nginxip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric > /dev/null 2>&1
fi fi
done done
else else
if [ "$metric" != "off" ] && [ "$server_ip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $server_ip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then if [ "$metric" != "off" ] && [ "$server_ip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $server_ip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then
_log "Set server $server_ip route via $OMR_TRACKER_DEVICE metric $metric" _log "Set server $server_ip route via $OMR_TRACKER_DEVICE metric $metric"
ip route del $server_ip metric $metric ip route del $server_ip metric $metric > /dev/null 2>&1
ip route replace $server_ip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric ip route replace $server_ip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric > /dev/null 2>&1
fi fi
fi fi
} }
@ -248,24 +248,16 @@ if [ "$multipath_config" = "master" ]; then
fi fi
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337 ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337
fi fi
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
#local metric=$(ip rule show | grep -m 1 "$OMR_TRACKER_DEVICE_IP" | awk '{print $5}')
local metric=$(ip rule show | grep "$OMR_TRACKER_DEVICE_IP" | grep -m 1 "$OMR_TRACKER_DEVICE" | grep -om1 'lookup [[:digit:]]' | awk '{print $2}')
[ -n "$metric" ] && {
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric
}
fi
multipath_config="on" multipath_config="on"
else fi
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
#local metric=$(ip rule show | grep -m 1 "$OMR_TRACKER_DEVICE_IP" | awk '{print $5}') #local metric=$(ip rule show | grep -m 1 "$OMR_TRACKER_DEVICE_IP" | awk '{print $5}')
local metric=$(ip rule show | grep "$OMR_TRACKER_DEVICE_IP" | grep -m 1 "$OMR_TRACKER_DEVICE" | grep -om1 'lookup [[:digit:]]' | awk '{print $2}') local metric=$(ip rule show | grep "$OMR_TRACKER_DEVICE_IP" | grep -m 1 "$OMR_TRACKER_DEVICE" | grep -om1 'lookup [[:digit:]]' | awk '{print $2}')
[ -n "$metric" ] && { [ -n "$metric" ] && {
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric
config_load shadowsocks-libev config_load shadowsocks-libev
config_foreach set_ss_route server $metric config_foreach set_ss_route server $metric
} }
fi
fi fi
[ "$multipath_config" = "on" ] && glorytun-udp path $OMR_TRACKER_DEVICE_IP dev tun0 up > /dev/null 2>&1 [ "$multipath_config" = "on" ] && glorytun-udp path $OMR_TRACKER_DEVICE_IP dev tun0 up > /dev/null 2>&1