mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Detect and set best MTU, set some settings before status page
This commit is contained in:
parent
5cd9511df6
commit
910c6f5ee9
7 changed files with 88 additions and 19 deletions
|
@ -6,7 +6,7 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI Support for OpenMPTCProuter
|
||||
LUCI_DEPENDS:=+luci-lib-json +rdisc6 +curl +whois +bind-dig +tracebox
|
||||
LUCI_DEPENDS:=+luci-lib-json +rdisc6 +curl +bind-dig +tracebox
|
||||
PKG_LICENSE:=GPLv3
|
||||
|
||||
include ../luci/luci.mk
|
||||
|
|
|
@ -502,14 +502,14 @@ function interfaces_status()
|
|||
peer = ut.trim(sys.exec("ip -4 r list dev " .. tun_dev .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'"))
|
||||
end
|
||||
if peer ~= "" then
|
||||
local tunnel_ping_test = ut.trim(sys.exec("ping -W 1 -c 1 " .. peer .. " -I " .. tun_dev .. " | grep '100% packet loss'"))
|
||||
local tunnel_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 -I " .. tun_dev .. " " .. peer .. " | grep '100% packet loss'"))
|
||||
if tunnel_ping_test == "" then
|
||||
mArray.openmptcprouter["tun_state"] = "UP"
|
||||
else
|
||||
mArray.openmptcprouter["tun_state"] = "DOWN"
|
||||
end
|
||||
if mArray.openmptcprouter["ipv6"] == "enabled" then
|
||||
local tunnel_ping6_test = ut.trim(sys.exec("ping6 -W 1 -c 1 fe80::a00:1 -I 6in4-omr6in4 | grep '100% packet loss'"))
|
||||
local tunnel_ping6_test = ut.trim(sys.exec("ping6 -w 1 -c 1 -I 6in4-omr6in4 fe80::a00:1 | grep '100% packet loss'"))
|
||||
if tunnel_ping6_test == "" then
|
||||
mArray.openmptcprouter["tun6_state"] = "UP"
|
||||
else
|
||||
|
@ -633,7 +633,7 @@ function interfaces_status()
|
|||
end
|
||||
end
|
||||
if connectivity ~= "ERROR" and gateway ~= "" then
|
||||
local gw_ping_test = ut.trim(sys.exec("ping -W 1 -c 1 " .. gateway .. " | grep '100% packet loss'"))
|
||||
local gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway .. " | grep '100% packet loss'"))
|
||||
if gw_ping_test ~= "" then
|
||||
gw_ping = "DOWN"
|
||||
if connectivity == "OK" then
|
||||
|
@ -648,7 +648,7 @@ function interfaces_status()
|
|||
local latency = ""
|
||||
local server_ping = ""
|
||||
if connectivity ~= "ERROR" and ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" then
|
||||
local server_ping_test = sys.exec("ping -W 1 -c 1 -I " .. ifname .. " " .. mArray.openmptcprouter["service_addr"])
|
||||
local server_ping_test = sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. mArray.openmptcprouter["service_addr"])
|
||||
local server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'"))
|
||||
if server_ping_result ~= "" then
|
||||
server_ping = "DOWN"
|
||||
|
@ -664,13 +664,17 @@ function interfaces_status()
|
|||
local multipath_available
|
||||
if connectivity ~= "ERROR" and mArray.openmptcprouter["dns"] == true and ifname ~= nil and ifname ~= "" and gateway ~= "" and gw_ping == "UP" then
|
||||
-- Test if multipath can work on the connection
|
||||
local multipath_available_state = ""
|
||||
if mArray.openmptcprouter["service_addr"] ~= "" then
|
||||
multipath_available_state = ut.trim(sys.exec("omr-tracebox-mptcp " .. mArray.openmptcprouter["service_addr"] .. " " .. ifname .. " | grep 'MPTCP enabled'"))
|
||||
local multipath_available_state = uci:get("openmptcprouter",interface,"publicip") or ""
|
||||
if multipath_available_state == "" then
|
||||
--if mArray.openmptcprouter["service_addr"] ~= "" then
|
||||
multipath_available_state = ut.trim(sys.exec("omr-tracebox-mptcp " .. mArray.openmptcprouter["service_addr"] .. " " .. ifname .. " | grep 'MPTCP disabled'"))
|
||||
--else
|
||||
multipath_available_state = ut.trim(sys.exec("omr-mptcp-intf " .. ifname .. " | grep 'Nay, Nay, Nay'"))
|
||||
--end
|
||||
else
|
||||
multipath_available_state = ut.trim(sys.exec("omr-mptcp-intf " .. ifname .. " | grep 'you are MPTCP-capable'"))
|
||||
multipath_available_state = ut.trim(sys.exec("echo " .. multipath_available_state .. " | grep 'MPTCP disabled'"))
|
||||
end
|
||||
if multipath_available_state ~= "" then
|
||||
if multipath_available_state == "" then
|
||||
multipath_available = "OK"
|
||||
else
|
||||
if mArray.openmptcprouter["service_addr"] ~= "" then
|
||||
|
@ -717,10 +721,17 @@ function interfaces_status()
|
|||
end
|
||||
end
|
||||
|
||||
local publicIP = ut.trim(sys.exec("omr-ip-intf " .. ifname))
|
||||
local publicIP = uci:get("openmptcprouter",interface,"publicip") or ""
|
||||
if publicIP == "" then
|
||||
publicIP = ut.trim(sys.exec("omr-ip-intf " .. ifname))
|
||||
end
|
||||
local whois = ""
|
||||
if publicIP ~= "" then
|
||||
whois = ut.trim(sys.exec("whois " .. publicIP .. " | grep -i 'netname' | awk '{print $2}'"))
|
||||
whois = uci:get("openmptcprouter",interface,"asn") or ""
|
||||
if whois == "" then
|
||||
--whois = ut.trim(sys.exec("whois " .. publicIP .. " | grep -i 'netname' | awk '{print $2}'"))
|
||||
whois = ut.trim(sys.exec("wget -4 -qO- -T 1 'http://api.iptoasn.com/v1/as/ip/" .. publicIP .. "' | jsonfilter -e '@.as_description'"))
|
||||
end
|
||||
end
|
||||
|
||||
local data = {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
INTERFACE=$2
|
||||
if [ -z "$INTERFACE" ]; then
|
||||
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' else print 'MPTCP disabled' end" $1
|
||||
tracebox -m 30 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' else print 'MPTCP disabled' end" $1
|
||||
else
|
||||
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' else print 'MPTCP disabled' end" -i $INTERFACE $1
|
||||
tracebox -m 30 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' else print 'MPTCP disabled' end" -i $INTERFACE $1
|
||||
fi
|
|
@ -4,6 +4,15 @@ START=5
|
|||
|
||||
USE_PROCD=1
|
||||
|
||||
omr_intf_del() {
|
||||
uci -q delete openmptcprouter.$1
|
||||
}
|
||||
omr_intf_set() {
|
||||
config_get multipath "$1" multipath
|
||||
[ -z "$multipath" ] || [ "$multipath" = "off" ] && return
|
||||
uci -q set openmptcprouter.$1=interface
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local scaling_min_freq scaling_max_freq
|
||||
config_load openmptcprouter
|
||||
|
@ -28,6 +37,10 @@ start_service() {
|
|||
# remove sysctl already defined in /etc/sysctl.d/
|
||||
sed -i -e '/tcp_fin_timeout/d' -e '/tcp_keepalive_time/d' -e '/nf_conntrack_max/d' /etc/sysctl.conf
|
||||
sed -i -e '/tcp_fin_timeout/d' -e '/tcp_keepalive_time/d' -e '/nf_conntrack_max/d' /etc/sysctl.d/10-default.conf
|
||||
|
||||
config_foreach omr_intf_del interface
|
||||
config_load network
|
||||
config_foreach omr_intf_set interface
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
|
|
|
@ -21,3 +21,9 @@ if [ "$(uci -q get qos.serverin.target)" = "" ]; then
|
|||
commit qos
|
||||
EOF
|
||||
fi
|
||||
if [ "$(uci -q ucitrack.@network[-1].affects | grep openmptcprouter)" = "" ]; then
|
||||
uci -q batch <<-EOF
|
||||
add_list ucitrack.@network[-1].affects="openmptcprouter"
|
||||
commit ucitrack
|
||||
EOF
|
||||
fi
|
|
@ -214,11 +214,33 @@ if [ "$(uci -q get omr-bypass.defaults.ifname)" = "$OMR_TRACKER_DEVICE" ] && [ "
|
|||
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337
|
||||
fi
|
||||
|
||||
|
||||
[ "$multipath_config" = "on" ] && glorytun-udp path $OMR_TRACKER_DEVICE_IP dev tun0 up > /dev/null 2>&1
|
||||
[ "$multipath_config" = "backup" ] && glorytun-udp path $OMR_TRACKER_DEVICE_IP dev tun0 backup > /dev/null 2>&1
|
||||
[ "$multipath_status" = "$multipath_config" ] && exit 0
|
||||
if [ "$(sysctl -n net.mptcp.mptcp_enabled | tr -d '\n')" = "1" ]; then
|
||||
[ "$multipath_status" = "$multipath_config" ] || {
|
||||
if [ "$(sysctl -n net.mptcp.mptcp_enabled | tr -d '\n')" = "1" ]; then
|
||||
_log "Multipath $OMR_TRACKER_DEVICE switched to $multipath_config"
|
||||
multipath "$OMR_TRACKER_DEVICE" "$multipath_config"
|
||||
fi
|
||||
}
|
||||
|
||||
# Save wan settings for status page
|
||||
if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.omr_lc)" = "" ] || [ $(($(date +"%s") - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.omr_lc))) -gt 3600 ]; then
|
||||
local ipaddr="$(omr-ip-intf $OMR_TRACKER_DEVICE)"
|
||||
[ -n "$ipaddr" ] && {
|
||||
local asn="$(wget -4 -qO- -T 5 http://api.iptoasn.com/v1/as/ip/$ipaddr | jsonfilter -e '@.as_description')"
|
||||
local serverip=$(uci -q get shadowsocks-libev.sss0.server)
|
||||
uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.mptcp_status="$(omr-tracebox-mptcp $serverip $OMR_TRACKER_DEVICE)"
|
||||
uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.publicip="$ipaddr"
|
||||
[ -n "$asn" ] && {
|
||||
uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.asn="$asn"
|
||||
}
|
||||
local mtu=$(omr-mtu $OMR_TRACKER_DEVICE_IP $serverip)
|
||||
[ -n "$mtu" ] && {
|
||||
uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.mtu=$mtu
|
||||
ip link set dev $OMR_TRACKER_DEVICE mtu $mtu > /dev/null 2>&1
|
||||
}
|
||||
[ -n "$mtu" ] && [ -n "$asn" ] && {
|
||||
uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.lc=$(date +"%s")
|
||||
}
|
||||
}
|
||||
fi
|
||||
|
|
17
openmptcprouter/files/bin/omr-mtu
Executable file
17
openmptcprouter/files/bin/omr-mtu
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
PKT_SIZE=1472
|
||||
INTERFACE="$1"
|
||||
HOSTNAME="$2"
|
||||
|
||||
count=$(ping -q -w 1 -M do -c 1 -s $PKT_SIZE -I $INTERFACE $HOSTNAME | grep -cE 'Message too long|100% packet loss')
|
||||
|
||||
while [ $count -eq 1 ]; do
|
||||
PKT_SIZE=$((PKT_SIZE - 1))
|
||||
if [ "$PKT_SIZE" -lt "1200" ]; then
|
||||
exit 0
|
||||
fi
|
||||
count=$(ping -q -w 1 -M do -c 1 -s $PKT_SIZE -I $INTERFACE $HOSTNAME | grep -cE 'Message too long|100% packet loss')
|
||||
done
|
||||
|
||||
printf "$((PKT_SIZE + 28))"
|
Loading…
Add table
Add a link
Reference in a new issue