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

Merge pull request #76 from Ysurac/develop

sync
This commit is contained in:
suyuan 2021-02-20 10:55:05 +08:00 committed by GitHub
commit 5174890bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 209 additions and 50 deletions

View file

@ -17,6 +17,8 @@ function index()
entry({"admin", "network", "mptcp", "mptcp_fullmesh_data"}, post("mptcp_fullmesh_data")).leaf = true entry({"admin", "network", "mptcp", "mptcp_fullmesh_data"}, post("mptcp_fullmesh_data")).leaf = true
entry({"admin", "network", "mptcp", "mptcp_connections"}, template("mptcp/mptcp_connections"), _("Established connections"), 6).leaf = true entry({"admin", "network", "mptcp", "mptcp_connections"}, template("mptcp/mptcp_connections"), _("Established connections"), 6).leaf = true
entry({"admin", "network", "mptcp", "mptcp_connections_data"}, post("mptcp_connections_data")).leaf = true entry({"admin", "network", "mptcp", "mptcp_connections_data"}, post("mptcp_connections_data")).leaf = true
entry({"admin", "network", "mptcp", "mptcp_monitor"}, template("mptcp/mptcp_monitor"), _("MPTCP monitoring"), 6).leaf = true
entry({"admin", "network", "mptcp", "mptcp_monitor_data"}, post("mptcp_monitor_data")).leaf = true
end end
function interface_bandwidth(iface) function interface_bandwidth(iface)
@ -206,6 +208,21 @@ function mptcp_fullmesh_data()
return return
end end
function mptcp_monitor_data()
luci.http.prepare_content("text/plain")
local fullmesh
fullmesh = io.popen("cat /proc/net/mptcp_net/snmp")
if fullmesh then
while true do
local ln = fullmesh:read("*l")
if not ln then break end
luci.http.write(ln)
luci.http.write("\n")
end
end
return
end
function mptcp_connections_data() function mptcp_connections_data()
luci.http.prepare_content("text/plain") luci.http.prepare_content("text/plain")
local connections local connections

View file

@ -0,0 +1,42 @@
<%+header%>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.193.28471-ee087a1"></script>
<script type="text/javascript">//<![CDATA[
var stxhr = new XHR();
function update_monitor()
{
var fm = document.getElementById('monitor');
if (fm)
{
fm.innerHTML =
'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' + '<%:Waiting for command to complete...%>'
;
stxhr.post('<%=url('admin/network/mptcp')%>/mptcp_monitor_data/', { token: '<%=token%>' },
function(x)
{
if (x.responseText)
{
fm.innerHTML = String.format('<pre>%s</pre>', x.responseText );
} else {
fm.innerHTML = '<pre><%:Error%></pre>';
}
}
);
}
}
setInterval(function () {
update_monitor();
}, 10000);
//]]></script>
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
<div class="cbi-section">
<span id="monitor"></span>
<script type="text/javascript">//<![CDATA[
update_monitor();
//]]></script>
</div>
<%+footer%>

View file

@ -1116,6 +1116,7 @@ function interfaces_status()
local multipath = section["multipath"] local multipath = section["multipath"]
local enabled = section["auto"] local enabled = section["auto"]
local proto = section["proto"] or "" local proto = section["proto"] or ""
local ipv6 = section["ipv6"] or "0"
--if not ipaddr or not gateway then return end --if not ipaddr or not gateway then return end
-- Don't show if0 in the overview -- Don't show if0 in the overview
@ -1130,8 +1131,8 @@ function interfaces_status()
--end --end
duplicateif = false duplicateif = false
if ifname ~= "" and ifname ~= nil then if ifname ~= "" and ifname ~= nil and not (section["ifname"] ~= nil and section["ifname"]:match("^@.*")) then
if allintf[ifname] and not section["ifname"]:match("^@.*") then if allintf[ifname] then
connectivity = "ERROR" connectivity = "ERROR"
duplicateif = true duplicateif = true
else else
@ -1151,10 +1152,10 @@ function interfaces_status()
if ipaddr == "" and ifname ~= nil and ifname ~= "" and proto ~= "dhcpv6" then if ipaddr == "" and ifname ~= nil and ifname ~= "" and proto ~= "dhcpv6" then
ipaddr = ut.trim(sys.exec("ip -4 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'")) ipaddr = ut.trim(sys.exec("ip -4 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'"))
end end
if ip6addr == "" and ifname ~= nil and ifname ~= "" then if ip6addr == "" and ifname ~= nil and ifname ~= "" and (ipv6 == "1" or ipv6 == "auto") then
ip6addr = ut.trim(sys.exec("ip -6 -br addr ls dev " .. ifname .. " | awk -F'[ /]+' '{print $3}' | tr -d '\n'")) ip6addr = ut.trim(sys.exec("ip -6 -br addr ls dev " .. ifname .. " | awk -F'[ /]+' '{print $3}' | tr -d '\n'"))
end end
if ip6addr == "" and ifname ~= nil and ifname ~= "" then if ip6addr == "" and ifname ~= nil and ifname ~= "" and (ipv6 == "1" or ipv6 == "auto") then
ip6addr = ut.trim(sys.exec("ip -6 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'")) ip6addr = ut.trim(sys.exec("ip -6 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'"))
end end
if ipaddr == "" and ip6addr == "" then if ipaddr == "" and ip6addr == "" then
@ -1199,13 +1200,15 @@ function interfaces_status()
if proto ~= "dhcpv6" then if proto ~= "dhcpv6" then
gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep via | grep -v default | grep -v metric | awk '{print $1}' | tr -d '\n'")) gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep via | grep -v default | grep -v metric | awk '{print $1}' | tr -d '\n'"))
end end
gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep via | grep -v default | grep -v metric | awk '{print $1}' | tr -d '\n'")) if ipv6 == "1" or ipv6 == "auto" then
gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep via | grep -v default | grep -v metric | awk '{print $1}' | tr -d '\n'"))
end
end end
if gateway == "" and proto ~= "dhcpv6" then if gateway == "" and proto ~= "dhcpv6" then
gateway = get_gateway(interface) gateway = get_gateway(interface)
end end
if gateway == "" and ifname ~= nil and ifname ~= "" and proto ~= "dhcpv6" then if gateway == "" and ifname ~= nil and ifname ~= "" and ipv6 ~= "1" and ipv6 ~= "auto" then
if fs.access("/sys/class/net/" .. ifname) then if fs.access("/sys/class/net/" .. ifname) then
gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'")) gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'"))
if gateway == "" then if gateway == "" then
@ -1213,10 +1216,10 @@ function interfaces_status()
end end
end end
end end
if gateway6 == "" then if gateway6 == "" and (ipv6 == "1" or ipv6 == "auto") then
gateway6 = get_gateway6(interface) gateway6 = get_gateway6(interface)
end end
if gateway6 == "" and ifname ~= nil and ifname ~= "" then if gateway6 == "" and ifname ~= nil and ifname ~= "" and (ipv6 == "1" or ipv6 == "auto") then
if fs.access("/sys/class/net/" .. ifname) then if fs.access("/sys/class/net/" .. ifname) then
gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'")) gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'"))
if gateway6 == "" then if gateway6 == "" then

View file

@ -206,13 +206,29 @@ set_routes_intf6() {
#multipath_current_config=$(multipath $interface_if | grep 'deactivated') #multipath_current_config=$(multipath $interface_if | grep 'deactivated')
interface_current_config=$(uci -q get openmptcprouter.$INTERFACE.state || echo "up") interface_current_config=$(uci -q get openmptcprouter.$INTERFACE.state || echo "up")
if [ "$multipath_config_route" != "off" ] && [ "$interface_current_config" = "up" ] && [ "$interface_if" != "" ] && [ "$interface_up" = "true" ]; then if [ "$multipath_config_route" != "off" ] && [ "$interface_current_config" = "up" ] && [ "$interface_if" != "" ] && [ "$interface_up" = "true" ]; then
interface_gw="$(uci -q get network.$INTERFACE.gateway)" interface_gw="$(uci -q get network.$INTERFACE.ip6gw)"
interface_ip6="$(uci -q get network.$INTERFACE.ip6)"
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e "@.inactive.route[@.source=\"${interface_ip6}\"].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e "@.inactive.route[@.source=\"${interface_ip6}/64\"].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e "@.inactive.route[@.source=\"${interface_ip6}/56\"].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n")
fi fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.nexthop="::"].target' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.target="::"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.target="::"].nexthop' | tr -d "\n")
fi fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.nexthop="::"].target' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.${INTERFACE}_6 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.${INTERFACE}_6 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n")
fi fi
@ -300,12 +316,28 @@ set_route_balancing6() {
interface_current_config=$(uci -q get openmptcprouter.$INTERFACE.state || echo "up") interface_current_config=$(uci -q get openmptcprouter.$INTERFACE.state || echo "up")
if [ "$multipath_config_route" != "off" ] && [ "$interface_current_config" = "up" ] && [ "$interface_up" = "true" ]; then if [ "$multipath_config_route" != "off" ] && [ "$interface_current_config" = "up" ] && [ "$interface_up" = "true" ]; then
interface_gw="$(uci -q get network.$INTERFACE.gateway)" interface_gw="$(uci -q get network.$INTERFACE.gateway)"
interface_ip6="$(uci -q get network.$INTERFACE.ip6)"
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e "@.inactive.route[@.source=\"${interface_ip6}\"].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e "@.inactive.route[@.source=\"${interface_ip6}/64\"].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e "@.inactive.route[@.source=\"${interface_ip6}/56\"].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n")
fi fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.nexthop="::"].target' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.target="::"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.target="::"].nexthop' | tr -d "\n")
fi fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.route[@.nexthop="::"].target' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.${INTERFACE}_6 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.${INTERFACE}_6 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n")
fi fi
@ -355,15 +387,15 @@ set_server_all_routes() {
config_foreach set_routes_intf interface config_foreach set_routes_intf interface
uintf="$(echo $routesintf | awk '{print $5}')" uintf="$(echo $routesintf | awk '{print $5}')"
uintfb="$(echo $routesintfbackup | awk '{print $5}')" uintfb="$(echo $routesintfbackup | awk '{print $5}')"
if [ -n "$routesintf" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show $serverip metric 0 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintf " ]) || ([ "$nbintf" = "1" ] && [ "$(ip r show $serverip metric 0 | grep $uintf)" = "" ]); then if [ -n "$routesintf" ] && ([ "$nbintf" -gt "1" ] && [ "$(ip r show $serverip metric 0 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintf " ]) || ([ "$nbintf" = "1" ] && [ -n "$uintf" ] && [ "$(ip r show $serverip metric 1 | grep $uintf)" = "" ]); then
while [ "$(ip r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "$serverip" ] && [ "$(ip r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "" ]; do while [ "$(ip r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "$serverip" ] && [ "$(ip r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "" ]; do
ip r del $serverip ip r del $serverip
done done
[ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) default route $serverip $routesintf" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) default route $serverip $routesintf"
ip route replace $serverip scope global $routesintf ip route replace $serverip scope global metric 1 $routesintf
[ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "New server route is $(ip r show $serverip metric 0 | tr -d '\t' | tr -d '\n')" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "New server route is $(ip r show $serverip metric 1 | tr -d '\t' | tr -d '\n')"
fi fi
if [ -n "$routesintfbackup" ] && ([ "$nbintfb" -gt "1" ] && [ "$(ip r show $serverip metric 999 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintfbackup " ]) || ([ "$nbintfb" = "1" ] && [ "$(ip r show $serverip metric 999 | grep $uintfb)" = "" ]); then if [ -n "$routesintfbackup" ] && ([ "$nbintfb" -gt "1" ] && [ "$(ip r show $serverip metric 999 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintfbackup " ]) || ([ "$nbintfb" = "1" ] && [ -n "$uintfb" ] && [ "$(ip r show $serverip metric 999 | grep $uintfb)" = "" ]); then
[ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) backup default route $serverip $routesintfbackup nbintfb $nbintfb $OMR_TRACKER_DEVICE" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) backup default route $serverip $routesintfbackup nbintfb $nbintfb $OMR_TRACKER_DEVICE"
ip route replace $serverip scope global metric 999 $routesintfbackup ip route replace $serverip scope global metric 999 $routesintfbackup
fi fi
@ -394,20 +426,20 @@ set_server_all_routes6() {
nbintf6=0 nbintf6=0
nbintfb6=0 nbintfb6=0
config_load network config_load network
config_foreach set_routes_intf interface config_foreach set_routes_intf6 interface
uintf="$(echo $routesintf | awk '{print $5}')" uintf="$(echo $routesintf6 | awk '{print $5}')"
uintfb="$(echo $routesintfbackup | awk '{print $5}')" uintfb="$(echo $routesintfbackup6 | awk '{print $5}')"
if [ -n "$routesintf" ] && ([ "$nbintf6" -gt "1" ] && [ "$(ip -6 r show $serverip metric 0 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintf " ]) || ([ "$nbintf6" = "1" ] && [ "$(ip -6 r show $serverip metric 0 | grep $uintf)" = "" ]); then if [ -n "$routesintf6" ] && ([ "$nbintf6" -gt "1" ] && [ "$(ip -6 r show $serverip metric 0 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintf6 " ]) || ([ "$nbintf6" = "1" ] && [ -n "$uintf" ] && [ "$(ip -6 r show $serverip metric 1 | grep $uintf)" = "" ]); then
while [ "$(ip -6 r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "$serverip" ] && [ "$(ip -6 r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "" ]; do while [ "$(ip -6 r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "$serverip" ] && [ "$(ip -6 r show $serverip | grep -v nexthop | sed 's/ //g' | tr -d '\n')" != "" ]; do
ip -6 r del $serverip ip -6 r del $serverip
done done
[ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) default route $serverip $routesintf" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) default route $serverip $routesintf6"
ip -6 route replace $serverip scope global $routesintf ip -6 route replace $serverip scope global metric 1 $routesintf6
[ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "New server route is $(ip -6 r show $serverip metric 0 | tr -d '\t' | tr -d '\n')" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "New server route is $(ip -6 r show $serverip metric 1 | tr -d '\t' | tr -d '\n')"
fi fi
if [ -n "$routesintfbackup" ] && ([ "$nbintfb6" -gt "1" ] && [ "$(ip -6 r show $serverip metric 999 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintfbackup " ]) || ([ "$nbintfb6" = "1" ] && [ "$(ip -6 r show $serverip metric 999 | grep $uintfb)" = "" ]); then if [ -n "$routesintfbackup6" ] && ([ "$nbintfb6" -gt "1" ] && [ "$(ip -6 r show $serverip metric 999 | tr -d '\t' | tr -d '\n')" != "$serverip $routesintfbackup6 " ]) || ([ "$nbintfb6" = "1" ] && [ -n "$uintfb" ] && [ "$(ip -6 r show $serverip metric 999 | grep $uintfb)" = "" ]); then
[ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) backup default route $serverip $routesintfbackup nbintfb $nbintfb6 $OMR_TRACKER_DEVICE" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Set server $server ($serverip) backup default route $serverip $routesintfbackup6 nbintfb $nbintfb6 $OMR_TRACKER_DEVICE"
ip -6 route replace $serverip scope global metric 999 $routesintfbackup ip -6 route replace $serverip scope global metric 999 $routesintfbackup6
fi fi
fi fi
} }

View file

@ -31,6 +31,7 @@ while true; do
uci -q batch <<-EOF uci -q batch <<-EOF
set network.omr6in4.ipaddr=$addr set network.omr6in4.ipaddr=$addr
set network.omr6in4.peeraddr=$peer set network.omr6in4.peeraddr=$peer
set network.omr6in4.metric=1
commit network commit network
EOF EOF
if [ -n "$(ip tunnel | grep omr6in4)" ]; then if [ -n "$(ip tunnel | grep omr6in4)" ]; then
@ -49,7 +50,7 @@ while true; do
#[ -z "$ipv6_gw" ] && ipv6_gw='fe80::aff:ff01' #[ -z "$ipv6_gw" ] && ipv6_gw='fe80::aff:ff01'
ip -6 route add ${ipv6_gw} dev 6in4-omr6in4 > /dev/null 2>&1 ip -6 route add ${ipv6_gw} dev 6in4-omr6in4 > /dev/null 2>&1
ip -6 route 2002::/16 dev 6in4-omr6in4 > /dev/null 2>&1 ip -6 route 2002::/16 dev 6in4-omr6in4 > /dev/null 2>&1
ip -6 route replace default via ${ipv6_gw} dev 6in4-omr6in4 > /dev/null 2>&1 ip -6 route replace default via ${ipv6_gw} dev 6in4-omr6in4 metric 1 > /dev/null 2>&1
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
uci -q batch <<-EOF uci -q batch <<-EOF
set network.omr6in4_route6_default=route6 set network.omr6in4_route6_default=route6

View file

@ -64,6 +64,7 @@ set_ipv6_state() {
set network.lan.ipv6="1" set network.lan.ipv6="1"
set network.lan.delegate="0" set network.lan.delegate="0"
set network.omr6in4.force_link=1 set network.omr6in4.force_link=1
set network.omr6in4.metric=1
delete network.omr6in4.auto delete network.omr6in4.auto
EOF EOF
if [ "$(network.lan.ip6assign)" = "" ]; then if [ "$(network.lan.ip6assign)" = "" ]; then

View file

@ -24,6 +24,8 @@ export OMR_TRACKER_DEVICE_IP
export OMR_TRACKER_DEVICE_IP6 export OMR_TRACKER_DEVICE_IP6
export OMR_TRACKER_DEVICE_GATEWAY export OMR_TRACKER_DEVICE_GATEWAY
export OMR_TRACKER_DEVICE_GATEWAY6 export OMR_TRACKER_DEVICE_GATEWAY6
export OMR_TRACKER_IPV6
export OMR_TRACKER_PROTO
dscp=56 # set DSCP CS7 (56) in outgoing packets dscp=56 # set DSCP CS7 (56) in outgoing packets
initial_hosts="$OMR_TRACKER_HOSTS" initial_hosts="$OMR_TRACKER_HOSTS"
@ -87,16 +89,45 @@ _post_tracking() {
} }
_ping_server() { _ping_server() {
local serverip=$(uci -q get openmptcprouter.$1.ip) local servername=$1
local disabled=$(uci -q get openmptcprouter.$1.disabled)
local device=$2 local device=$2
if [ -n "$serverip" ] && [ -n "$device" ]; then if [ -n "$device" ] && [ "$disabled" != "1" ]; then
_ping $serverip $device "yes" check_ping() {
statusp=$? serverip=$1
if $(exit $statusp); then if [ -n "$serverip" ]; then
serverip_ping=true _ping $serverip $device "yes"
fi statusp=$?
else if $(exit $statusp); then
serverip_ping=false serverip_ping=true
break
fi
fi
}
config_load openmptcprouter
config_list_foreach ${servername} ip check_ping
fi
}
_httping_server() {
local servername=$1
local disabled=$(uci -q get openmptcprouter.$1.disabled)
local port=$(uci -q get openmptcprouter.$1.port)
local device=$2
if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() {
serverip=$1
if [ -n "$serverip" ]; then
_httping "${serverip}:${port}" $device "yes" true
statusp=$?
if $(exit $statusp); then
serverip_ping=true
break
fi
fi
}
config_load openmptcprouter
config_list_foreach ${servername} ip check_ping
fi fi
} }
@ -138,18 +169,34 @@ _httping() {
local host=$1 local host=$1
local deviceip=$2 local deviceip=$2
local localip=$3 local localip=$3
ret=$(httping "${host}" \ local https=$4
-y "${deviceip}" \ if [ -z "$https" ] || [ "$https" = false ]; then
-t "$OMR_TRACKER_TIMEOUT" \ ret=$(httping "${host}" \
-c 1 \ -y "${deviceip}" \
-q -t "$OMR_TRACKER_TIMEOUT" \
) && echo "$ret" | grep -sq "1 ok" && { -c 1 \
if [ "$localip" = "yes" ]; then -q
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1) ) && echo "$ret" | grep -sq "1 ok" && {
_update_rto "$OMR_TRACKER_LATENCY" if [ "$localip" = "yes" ]; then
fi OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
return _update_rto "$OMR_TRACKER_LATENCY"
} fi
return
}
else
ret=$(httping -l "${host}" \
-y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \
-c 1 \
-q
) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
fi
false false
} }
@ -234,6 +281,7 @@ while true; do
OMR_TRACKER_DEVICE_GATEWAY=$(ip -4 r list dev "$OMR_TRACKER_DEVICE" | grep kernel | awk '/proto kernel/ {print $1}' | tr -d "\n") OMR_TRACKER_DEVICE_GATEWAY=$(ip -4 r list dev "$OMR_TRACKER_DEVICE" | grep kernel | awk '/proto kernel/ {print $1}' | tr -d "\n")
fi fi
fi fi
if [ "$OMR_TRACKER_INTERFACE_IPV6" = "1" ] || [ "$OMR_TRACKER_INTERFACE_IPV6" = "auto" ]; then
#OMR_TRACKER_DEVICE_IP6=$(ip -6 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}') #OMR_TRACKER_DEVICE_IP6=$(ip -6 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
#if [ -z "$OMR_TRACKER_DEVICE_IP6" ]; then #if [ -z "$OMR_TRACKER_DEVICE_IP6" ]; then
OMR_TRACKER_DEVICE_IP6=$(ip -6 addr show dev "$OMR_TRACKER_DEVICE" | grep -v 'inet6 f' | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1) OMR_TRACKER_DEVICE_IP6=$(ip -6 addr show dev "$OMR_TRACKER_DEVICE" | grep -v 'inet6 f' | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1)
@ -256,6 +304,7 @@ while true; do
if [ -z "$OMR_TRACKER_DEVICE_GATEWAY6" ] || [ "$OMR_TRACKER_DEVICE_GATEWAY6" = "::" ]; then if [ -z "$OMR_TRACKER_DEVICE_GATEWAY6" ] || [ "$OMR_TRACKER_DEVICE_GATEWAY6" = "::" ]; then
OMR_TRACKER_DEVICE_GATEWAY6=$(ubus call network.interface.$OMR_TRACKER_INTERFACE status | jsonfilter -q -l 1 -e '@.route[@.nexthop="::"].target' | tr -d "\n") OMR_TRACKER_DEVICE_GATEWAY6=$(ubus call network.interface.$OMR_TRACKER_INTERFACE status | jsonfilter -q -l 1 -e '@.route[@.nexthop="::"].target' | tr -d "\n")
fi fi
fi
# execute specific tracker # execute specific tracker
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
@ -283,6 +332,10 @@ while true; do
config_load openmptcprouter config_load openmptcprouter
config_foreach _ping_server server $OMR_TRACKER_DEVICE config_foreach _ping_server server $OMR_TRACKER_DEVICE
fi fi
if [ "$OMR_TRACKER_TYPE" = "httping" ]; then
config_load openmptcprouter
config_foreach _httping_server server $OMR_TRACKER_DEVICE
fi
if [ "$serverip_ping" = false ] && [ -n "$OMR_TRACKER_HOST" ]; then if [ "$serverip_ping" = false ] && [ -n "$OMR_TRACKER_HOST" ]; then
OMR_TRACKER_HOST=$(resolveip -4 -t 5 $OMR_TRACKER_HOST | head -n 1 | tr -d "\n") OMR_TRACKER_HOST=$(resolveip -4 -t 5 $OMR_TRACKER_HOST | head -n 1 | tr -d "\n")
if [ -n "$OMR_TRACKER_HOST" ]; then if [ -n "$OMR_TRACKER_HOST" ]; then
@ -366,6 +419,11 @@ while true; do
config_load openmptcprouter config_load openmptcprouter
config_foreach _ping_server server $OMR_TRACKER_DEVICE config_foreach _ping_server server $OMR_TRACKER_DEVICE
fi fi
if [ "$OMR_TRACKER_TYPE" = "httping" ]; then
config_load openmptcprouter
config_foreach _httping_server server $OMR_TRACKER_DEVICE
fi
if [ "$serverip_ping" = false ] && [ -n "$OMR_TRACKER_HOST6" ]; then if [ "$serverip_ping" = false ] && [ -n "$OMR_TRACKER_HOST6" ]; then
OMR_TRACKER_HOST6=$(resolveip -6 -t 5 $OMR_TRACKER_HOST6 | head -n 1 | tr -d "\n") OMR_TRACKER_HOST6=$(resolveip -6 -t 5 $OMR_TRACKER_HOST6 | head -n 1 | tr -d "\n")
if [ -n "$OMR_TRACKER_HOST6" ]; then if [ -n "$OMR_TRACKER_HOST6" ]; then

View file

@ -19,7 +19,7 @@ _validate_section() {
uci_validate_section omr-tracker "$1" "$2" \ uci_validate_section omr-tracker "$1" "$2" \
'hosts:list(host)' \ 'hosts:list(host)' \
'hosts6:list(host6)' \ 'hosts6:list(host)' \
'timeout:uinteger' \ 'timeout:uinteger' \
'tries:uinteger' \ 'tries:uinteger' \
'interval:uinteger' \ 'interval:uinteger' \
@ -46,7 +46,7 @@ _launch_tracker() {
loopback|lan*|if0*) return;; loopback|lan*|if0*) return;;
esac esac
local hosts hosts6 timeout tries interval interval_tries options type enabled wait_test local hosts hosts6 timeout tries interval interval_tries options type enabled wait_test ipv6 proto
_validate_section "defaults" "defaults" _validate_section "defaults" "defaults"
_validate_section "interface" "$1" _validate_section "interface" "$1"
@ -59,6 +59,8 @@ _launch_tracker() {
config_get multipath "$1" multipath config_get multipath "$1" multipath
config_get ifenabled "$1" auto config_get ifenabled "$1" auto
config_get gateway "$1" gateway config_get gateway "$1" gateway
config_get ipv6 "$1" ipv6
config_get proto "$1" proto
[ -z "$ifname" ] || [ -z "$multipath" ] || [ "$multipath" = "off" ] && [ "$1" != "glorytun" ] && [ "$1" != "omrvpn" ] && [ "$( uci -q get openmptcprouter.$1.multipathvpn)" != "1" ] && return [ -z "$ifname" ] || [ -z "$multipath" ] || [ "$multipath" = "off" ] && [ "$1" != "glorytun" ] && [ "$1" != "omrvpn" ] && [ "$( uci -q get openmptcprouter.$1.multipathvpn)" != "1" ] && return
[ "${ifenabled}" = "0" ] && return [ "${ifenabled}" = "0" ] && return
@ -79,6 +81,8 @@ _launch_tracker() {
procd_append_param env "OMR_TRACKER_DEVICE=$ifname" procd_append_param env "OMR_TRACKER_DEVICE=$ifname"
procd_append_param env "OMR_TRACKER_DEVICE_GATEWAY=$gateway" procd_append_param env "OMR_TRACKER_DEVICE_GATEWAY=$gateway"
procd_append_param env "OMR_TRACKER_TYPE=$type" procd_append_param env "OMR_TRACKER_TYPE=$type"
procd_append_param env "OMR_TRACKER_IPV6=$ipv6"
procd_append_param env "OMR_TRACKER_PROTO=$proto"
procd_append_param env "OMR_TRACKER_WAIT_TEST=$wait_test" procd_append_param env "OMR_TRACKER_WAIT_TEST=$wait_test"
procd_set_param limits nofile="51200 51200" procd_set_param limits nofile="51200 51200"
procd_set_param respawn 0 10 0 procd_set_param respawn 0 10 0

View file

@ -24,7 +24,7 @@ done
echo "Best server is $HOST, running test:" echo "Best server is $HOST, running test:"
trap : HUP INT TERM trap : HUP INT TERM
if [ -z "$INTERFACE" ]; then if [ -z "$INTERFACE" ]; then
curl -4 $HOST >/dev/null || echo curl -4 -o /dev/null $HOST || echo
else else
domain=$(echo $HOST | awk -F/ '{print $3}') domain=$(echo $HOST | awk -F/ '{print $3}')
hostip=$(dig +nocmd +noall +answer A $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ') hostip=$(dig +nocmd +noall +answer A $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ')
@ -33,7 +33,7 @@ else
ipset add ss_rules_dst_bypass_all $ip ipset add ss_rules_dst_bypass_all $ip
done done
fi fi
curl -4 --interface $INTERFACE $HOST >/dev/null || echo curl -4 -o /dev/null --interface $INTERFACE $HOST || echo
if [ -n "$(ipset list 2>/dev/null | grep ss_rules)" ]; then if [ -n "$(ipset list 2>/dev/null | grep ss_rules)" ]; then
for ip in $hostip; do for ip in $hostip; do
ipset del ss_rules_dst_bypass_all $ip ipset del ss_rules_dst_bypass_all $ip

View file

@ -57,8 +57,9 @@ if [ "$(uci -q get shadowsocks-libev.hi3)" != "" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
set shadowsocks-libev.hi$c.local_port=$port set shadowsocks-libev.hi$c.local_port=$port
set shadowsocks-libev.hi$c.server=sss0 set shadowsocks-libev.hi$c.server=sss0
set shadowsocks-libev.hi$((c+1)).local_address="::"
set shadowsocks-libev.hi$((c+1)).local_port=$port set shadowsocks-libev.hi$((c+1)).local_port=$port
set shadowsocks-libev.hi$((c+1)).local_address="::" set shadowsocks-libev.hi$((c+1)).local_address="::"
set shadowsocks-libev.hi$((c+1)).server=sss1 set shadowsocks-libev.hi$((c+1)).server=sss1
commit shadowsocks-libev commit shadowsocks-libev
EOF EOF