1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 11:01:50 +00:00
openmptcprouter-feeds/luci-app-openmptcprouter/root/bin/omr-mptcp-intf
2021-09-02 19:51:18 +02:00

75 lines
2.4 KiB
Bash
Executable file

#!/bin/sh
. /lib/functions.sh
intf=$1
timeout="$(uci -q get openmptcprouter.settings.status_vps_timeout)"
[ -z "$timeout" ] && timeout="1"
[ -z "$intf" ] && return
get_mptcp_from_server() {
serverport=$(uci -q get openmptcprouter.$1.port)
get_mptcp() {
serverip=$1
if [ "$(echo $serverip | grep :)" ]; then
if [ -f /proc/sys/net/mptcp/enabled ]; then
support="$(mptcpize run curl -s -k -6 -m ${timeout} --interface $intf https://[$serverip]:$serverport/mptcpsupport)"
else
support="$(curl -s -k -6 -m ${timeout} --interface $intf https://[$serverip]:$serverport/mptcpsupport)"
fi
else
if [ -f /proc/sys/net/mptcp/enabled ]; then
support="$(mptcpize run curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/mptcpsupport)"
else
support="$(curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/mptcpsupport)"
fi
fi
[ -n "$support" ] && {
support=$(echo $support | jsonfilter -e '@.mptcp')
break
}
}
config_list_foreach $1 ip get_mptcp
[ -n "$support" ] && break
}
get_mptcp_from_website() {
multipathip=$(dig +short A multipath-tcp.org | tr -d "\n")
ipset add ss_rules_dst_bypass_all $multipathip > /dev/null 2>&1
support="$(curl -s -4 -m ${timeout} --interface $intf http://www.multipath-tcp.org)"
ipset del ss_rules_dst_bypass_all $multipathip > /dev/null 2>&1
[ -n "$support" ] && {
if [ "$support" = "Yay, you are MPTCP-capable! You can now rest in peace." ]; then
support="working"
else
support="not working"
fi
}
}
get_mptcp_from_website6() {
multipathip=$(dig +short AAAA multipath-tcp.org | tr -d "\n")
ipset add ss_rules6_dst_bypass_all $multipathip > /dev/null 2>&1
support="$(curl -s -6 -m ${timeout} --interface $intf http://www.multipath-tcp.org)"
ipset del ss_rules6_dst_bypass_all $multipathip > /dev/null 2>&1
[ -n "$support" ] && {
if [ "$support" = "Yay, you are MPTCP-capable! You can now rest in peace." ]; then
support="working"
else
support="not working"
fi
}
}
support=""
config_load openmptcprouter
config_foreach get_mptcp_from_server server
if [ ! -f /proc/sys/net/mptcp/enabled ] && [ -z "$support" ]; then
[ -n "$(ip -4 a show dev $intf)" ] && get_mptcp_from_website
[ -n "$(ip -6 a show dev $intf)" ] && get_mptcp_from_website6
fi
if [ "$support" = "working" ]; then
echo "MPTCP enabled"
elif [ "$support" = "not working" ]; then
echo "MPTCP disabled"
fi