From 18d7fb2f9df0f69c314659d301d0bdac761d9c54 Mon Sep 17 00:00:00 2001 From: suyuan168 <175338101@qq.com> Date: Fri, 17 Jun 2022 15:24:19 +0800 Subject: [PATCH] fix --- mptcp/files/etc/init.d/mptcp | 33 ++-- mptcp/files/usr/bin/multipath | 11 -- .../share/omr/post-tracking.d/post-tracking | 162 +++++++----------- 3 files changed, 77 insertions(+), 129 deletions(-) diff --git a/mptcp/files/etc/init.d/mptcp b/mptcp/files/etc/init.d/mptcp index d7646364d..ac2b7496d 100755 --- a/mptcp/files/etc/init.d/mptcp +++ b/mptcp/files/etc/init.d/mptcp @@ -10,7 +10,7 @@ USE_PROCD=1 . /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 mptcp_path_manager mptcp_schdeduler mptcp_debug 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 @@ -44,7 +44,7 @@ global_multipath_settings() { [ -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" - elif [ -f /proc/sys/net/mptcp/enabled ]; then + else sysctl -qew net.mptcp.enabled="$multipath_status" ip mptcp limits set add_addr_accepted $mptcp_add_addr_accepted subflows $mptcp_subflows 2>&1 >/dev/null [ -z "$mptcp_add_addr_timeout" ] || sysctl -qew net.mptcp.add_addr_timeout="$mptcp_add_addr_timeout" @@ -97,9 +97,10 @@ interface_multipath_settings() { config_get enabled "$config" auto "1" 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" device [ -z "$iface" ] && config_get iface "$config" ifname config_get txqueuelen "$config" txqueuelen + [ -z "$iface" ] && iface=$(ifstatus "$config" | jsonfilter -q -e '@["l3_device"]') [ -n "$(echo $iface | grep '@')" ] && iface=$(ifstatus "$config" | jsonfilter -q -e '@["device"]') if [ "$(uci -q get openmptcprouter.${config}.metric)" = "" ]; then count=$((count+1)) @@ -266,10 +267,10 @@ interface_multipath_settings() { #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 2>&1 >/dev/null - #} + [ "$mode" = "master" ] && { + #echo "ip route replace default via $gateway dev $iface" + ip route replace default via $gateway dev $iface 2>&1 >/dev/null + } if [ "$txqueuelen" != "" ]; then ifconfig $iface txqueuelen $txqueuelen > /dev/null 2>&1 else @@ -291,10 +292,8 @@ interface_multipath_settings() { network6=`ipcalc $ip6addr | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'` fi if [ -z "$ip6addr" ] || [ -z "$network6" ]; then - [ -z "$ip6addr" ] && network_get_ipaddr6 ip6addr $config - [ -z "$ip6addr" ] && ip6addr=$(ip -6 addr show dev $iface | grep -v 'scope link' | grep inet6 | awk '{print $2}' | 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}' | tr -d "\n") + ip6addr=$(ip -6 addr show dev $iface | grep -v 'scope link' | grep inet6 | awk '{print $2}' | cut -d/ -f1 | tr -d "\n") + gateway6=$(ip -6 r list dev $iface | grep -v default | awk '/proto static/ {print $1}' | 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 @@ -304,7 +303,7 @@ interface_multipath_settings() { gateway6=$(ubus call network.interface.${config}_6 status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="::"].nexthop' | tr -d "\n") fi netmask6=$(ip -6 addr show dev $iface | grep -v 'scope link' | grep inet6 | awk '{print $2}' | cut -d/ -f2 | tr -d "\n") - [ -n "$ip6addr" ] && network6=`ipcalc $ip6addr | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'` + network6=`ipcalc $ip6addr | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'` fi if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then uci -q batch <<-EOF >/dev/null @@ -351,9 +350,9 @@ interface_multipath_settings() { fi #config_get mode "$config" multipath "off" - #[ "$mode" = "master" ] && { - # ip -6 route replace default via $gateway6 dev $iface 2>&1 >/dev/null - #} + [ "$mode" = "master" ] && { + ip -6 route replace default via $gateway6 dev $iface 2>&1 >/dev/null + } #[ "$mode" = "off" ] && { # ifconfig $iface txqueuelen 50 > /dev/null 2>&1 #} || { @@ -491,10 +490,6 @@ start_service() { [ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep raspberry)" ] && [ -z "$(ubus call system board | jsonfilter -e '@.board_name' | grep '4-model-b')" ] && { 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() { diff --git a/mptcp/files/usr/bin/multipath b/mptcp/files/usr/bin/multipath index c616044e4..62e029da5 100755 --- a/mptcp/files/usr/bin/multipath +++ b/mptcp/files/usr/bin/multipath @@ -29,7 +29,6 @@ case $1 in echo "show established conections: -c" echo "show fullmesh info: -f" echo "show kernel config: -k" - echo "show MPTCP info: -m" 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" @@ -76,13 +75,6 @@ case $1 in 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 ;; "") for ifpath in /sys/class/net/*; do $0 ${ifpath##*/} @@ -134,9 +126,6 @@ else ID=$(ip mptcp endpoint show | grep "dev $DEVICE" | awk '{print $3}') IFF=$(ip mptcp endpoint show | grep "dev $DEVICE" | awk '{print $4}') IP=$(ifconfig $DEVICE | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') - [ -z "$ID" ] && ID=$(ip mptcp endpoint show | grep "$IP" | awk '{print $3}') - RMID=$(ip mptcp endpoint show | grep '::ffff' | awk '{ print $3 }') - [ -n "$RMID" ] && ip mptcp endpoint delete id $RMID 2>&1 >/dev/null case $TYPE in "off") [ -n "$ID" ] && ip mptcp endpoint delete id $ID 2>&1 >/dev/null diff --git a/mptcp/files/usr/share/omr/post-tracking.d/post-tracking b/mptcp/files/usr/share/omr/post-tracking.d/post-tracking index 0e8ca6953..b54139b8c 100755 --- a/mptcp/files/usr/share/omr/post-tracking.d/post-tracking +++ b/mptcp/files/usr/share/omr/post-tracking.d/post-tracking @@ -664,7 +664,7 @@ disable_pihole() { commit dhcp EOF fi - /etc/init.d/dnsmasq restart 2>&1 >/dev/null + /etc/init.d/dnsmasq restart fi } @@ -725,9 +725,7 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ] || [ "$interface_up" != "true" ]; then else _log "$OMR_TRACKER_INTERFACE ($OMR_TRACKER_DEVICE) switched off because $OMR_TRACKER_STATUS_MSG" fi - if [ -n "$OMR_TRACKER_INTERFACE" ]; then - uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.state='down' - fi + uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.state='down' #if [ "$(sysctl -n net.mptcp.mptcp_enabled | tr -d '\n')" = "1" ]; then # multipath "$OMR_TRACKER_DEVICE" off > /dev/null 2>&1 #fi @@ -740,13 +738,11 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ] || [ "$interface_up" != "true" ]; then if [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ] && [ "$(uci -q get openmptcprouter.settings.mptcpovervpn)" = "openvpn" ]; then VPN_BASE_INTF="$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.baseintf)" VPN_BASE_INTF_IP=$(ubus call network.interface.$VPN_BASE_INTF status | jsonfilter -e '@["ipv4-address"][0].address' | tr -d "\n") - if [ -n "$VPN_BASE_INTF" ]; then - uci -q batch <<-EOF >/dev/null - set openvpn.$VPN_BASE_INTF.local=$VPN_BASE_INTF_IP - commit openvpn - EOF - fi - /etc/init.d/openvpn restart $VPN_BASE_INTF 2>&1 >/dev/null + uci -q batch <<-EOF >/dev/null + set openvpn.$VPN_BASE_INTF.local=$VPN_BASE_INTF_IP + commit openvpn + EOF + /etc/init.d/openvpn restart $VPN_BASE_INTF fi config_load openmptcprouter config_foreach del_server_route server @@ -773,11 +769,7 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ] || [ "$interface_up" != "true" ]; then config_foreach set_route6 interface $OMR_TRACKER_INTERFACE "no" fi fi - - mail_alert="" - if [ -n "$OMR_TRACKER_INTERFACE" ]; then - mail_alert="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.mail_alert)" - fi + mail_alert="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.mail_alert)" [ -z "$mail_alert" ] && mail_alert="$(uci -q get omr-tracker.defaults.mail_alert)" [ "$mail_alert" = "1" ] && [ -n "$(uci -q get mail.default.to)" ] && { OMR_SYSNAME="$(uci -q get system.@system[0].hostname)" @@ -791,16 +783,10 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ] || [ "$interface_up" != "true" ]; then echo -e "Subject: $OMR_SYSNAME: $OMR_TRACKER_INTERFACE ($OMR_TRACKER_DEVICE) is down\n\nConnection failure of $OMR_TRACKER_INTERFACE ($OMR_TRACKER_DEVICE) detected. The reason is \"$OMR_TRACKER_STATUS_MSG\"." | sendmail $(uci -q get mail.default.to) fi } - script_alert_down="" - if [ -n "$OMR_TRACKER_INTERFACE" ]; then - script_alert_down="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.script_alert_down)" - fi + script_alert_down="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.script_alert_down)" [ -n "$script_alert_down" ] && eval $script_alert_down - restart_down="" - if [ -n "$OMR_TRACKER_INTERFACE" ]; then - restart_down="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.restart_down)" - fi + restart_down="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.restart_down)" [ -z "$restart_down" ] && restart_down="$(uci -q get omr-tracker.defaults.restart_down)" [ "$restart_down" = "1" ] && { _log "Restart $OMR_TRACKER_INTERFACE" @@ -824,25 +810,25 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ] || [ "$interface_up" != "true" ]; then _log "Tunnel down use ShadowSocks for UDP" uci -q set shadowsocks-libev.ss_rules.redir_udp='hi1' if /etc/init.d/shadowsocks-libev rules_exist ; then - /etc/init.d/shadowsocks-libev rules_down 2>&1 >/dev/null - /etc/init.d/shadowsocks-libev rules_up 2>&1 >/dev/null + /etc/init.d/shadowsocks-libev rules_down + /etc/init.d/shadowsocks-libev rules_up fi fi if [ "$(uci -q get dsvpn.vpn.enable)" = "1" ]; then _log "DSVPN down, restart it" - /etc/init.d/dsvpn restart 2>&1 >/dev/null + /etc/init.d/dsvpn restart fi if [ "$(uci -q get mlvpn.general.enable)" = "1" ]; then _log "MLVPN down, restart it" - /etc/init.d/mlvpn restart 2>&1 >/dev/null + /etc/init.d/mlvpn restart fi if [ "$(uci -q get glorytun.vpn.enable)" = "1" ]; then _log "Glorytun VPN down, restart it" - /etc/init.d/glorytun restart 2>&1 >/dev/null + /etc/init.d/glorytun restart fi if [ "$(uci -q get glorytun-udp.vpn.enable)" = "1" ]; then _log "Glorytun UDP VPN down, restart it" - /etc/init.d/glorytun-udp restart 2>&1 >/dev/null + /etc/init.d/glorytun-udp restart fi config_load openmptcprouter config_foreach disable_pihole server @@ -853,9 +839,7 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ] || [ "$interface_up" != "true" ]; then fi fi dns_flush - if [ -n "$OMR_TRACKER_INTERFACE" ]; then - uci -q delete openmptcprouter.$OMR_TRACKER_INTERFACE.lc - fi + uci -q delete openmptcprouter.$OMR_TRACKER_INTERFACE.lc uci -q commit openmptcprouter #ubus call network reload @@ -935,12 +919,12 @@ if [ "$OMR_TRACKER_INTERFACE" = "glorytun" ] || [ "$OMR_TRACKER_INTERFACE" = "om config_load openmptcprouter config_foreach enable_pihole server #config_foreach delete_server_default_route server - [ "$nbserver" = "$piholeenabled" ] && /etc/init.d/openmptcprouter-vps set_pihole 2>&1 >/dev/null + [ "$nbserver" = "$piholeenabled" ] && /etc/init.d/openmptcprouter-vps set_pihole #ubus call network reload exit 0 fi -if [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ]; then +if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ]; then if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.state)" != "up" ]; then uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.state='up' uci -q commit openmptcprouter @@ -948,7 +932,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACK exit 0 fi -if [ "$OMR_TRACKER_PREV_STATUS" != "" ] && [ "$OMR_TRACKER_PREV_STATUS" != "$OMR_TRACKER_STATUS" ] && [ -n "$OMR_TRACKER_INTERFACE" ]; then +if [ "$OMR_TRACKER_PREV_STATUS" != "" ] && [ "$OMR_TRACKER_PREV_STATUS" != "$OMR_TRACKER_STATUS" ]; then _log "$OMR_TRACKER_INTERFACE ($OMR_TRACKER_DEVICE) switched up" mail_alert="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.mail_alert)" [ -z "$mail_alert" ] && mail_alert="$(uci -q get omr-tracker.defaults.mail_alert)" @@ -967,20 +951,18 @@ if [ "$OMR_TRACKER_PREV_STATUS" != "" ] && [ "$OMR_TRACKER_PREV_STATUS" != "$OMR script_alert_up="$(uci -q get omr-tracker.$OMR_TRACKER_INTERFACE.script_alert_up)" [ -n "$script_alert_up" ] && eval $script_alert_up fi -if [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.state)" != "up" ]; then +if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.state)" != "up" ]; then uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.state='up' uci -q commit openmptcprouter dns_flush fi -if [ -n "$OMR_TRACKER_INTERFACE" ]; then - multipath_config=$(uci -q get "openmtpcprouter.$OMR_TRACKER_INTERFACE.multipath") - [ -z "$multipath_config" ] && multipath_config=$(uci -q get "network.$OMR_TRACKER_INTERFACE.multipath" || echo "off") - [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.multipathvpn)" = "1" ] && { - [ "$(uci -q get openmptcprouter.settings.mptcpovervpn)" = "openvpn" ] && multipath_config_route="$(uci -q get openmptcprouter.ovpn${OMR_TRACKER_INTERFACE}.multipath || echo "off")" - [ "$(uci -q get openmptcprouter.settings.mptcpovervpn)" = "wireguard" ] && multipath_config_route="$(uci -q get openmptcprouter.wg${OMR_TRACKER_INTERFACE}.multipath || echo "off")" - } -fi +multipath_config=$(uci -q get "openmtpcprouter.$OMR_TRACKER_INTERFACE.multipath") +[ -z "$multipath_config" ] && multipath_config=$(uci -q get "network.$OMR_TRACKER_INTERFACE.multipath" || echo "off") +[ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.multipathvpn)" = "1" ] && { + [ "$(uci -q get openmptcprouter.settings.mptcpovervpn)" = "openvpn" ] && multipath_config_route="$(uci -q get openmptcprouter.ovpn${OMR_TRACKER_INTERFACE}.multipath || echo "off")" + [ "$(uci -q get openmptcprouter.settings.mptcpovervpn)" = "wireguard" ] && multipath_config_route="$(uci -q get openmptcprouter.wg${OMR_TRACKER_INTERFACE}.multipath || echo "off")" +} if [ "$multipath_config" = "master" ]; then #if ([ "$default_gw" != "$OMR_TRACKER_DEVICE_GATEWAY" ] || [ "$default_gw" = "" ]) && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && ([ "$(uci -q get openmptcprouter.settings.master)" != "balancing" ] || [ "$(uci -q get openmptcprouter.settings.vpn)" = "mlvpn" ]); then @@ -1028,7 +1010,7 @@ if [ "$multipath_config" = "master" ]; then config_foreach set_route_balancing interface config_foreach set_route_balancing6 interface [ -n "$routesbalancing" ] && { - ([ "$nbintf" -gt "1" ] && [ "$(ip r show default metric 1 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancing " ]) || ([ "$nbintf" = "1" ] && ([ "$(ip r show default metric 1 | grep $OMR_TRACKER_DEVICE)" = "" ] || ([ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ])) && [ -n "$OMR_TRACKER_DEVICE_IP" ]) && { + ([ "$nbintf" -gt "1" ] && [ "$(ip r show default metric 1 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancing " ]) || ([ "$nbintf" = "1" ] && ([ "$(ip r show default metric 1 | grep $OMR_TRACKER_DEVICE)" = "" ] || [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ]) && [ -n "$OMR_TRACKER_DEVICE_IP" ]) && { _log "Change in routes, set ip route replace default scope global $routesbalancing (omrvpn_intf: $omrvpn_intf)" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Current route: $(ip r)" ip route replace default scope global metric 1 $routesbalancing 2>&1 >/dev/null @@ -1042,7 +1024,7 @@ if [ "$multipath_config" = "master" ]; then } } [ -n "$routesbalancingbackup" ] && { - ([ "$nbintfb" -gt "1" ] && [ "$(ip r show default metric 999 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancingbackup " ]) || ([ "$nbintf" = "1" ] && ([ "$(ip r show default metric 999 | grep $OMR_TRACKER_DEVICE)" = "" ] || ([ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ])) && [ -n "$OMR_TRACKER_DEVICE_IP" ]) && { + ([ "$nbintfb" -gt "1" ] && [ "$(ip r show default metric 999 | tr -d '\t' | tr -d '\n')" != "default via $routesbalancingbackup " ]) || ([ "$nbintf" = "1" ] && ([ "$(ip r show default metric 999 | grep $OMR_TRACKER_DEVICE)" = "" ] || [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.vpn)" = "1" ]) && [ -n "$OMR_TRACKER_DEVICE_IP" ]) && { _log "Set backup ip route replace default scope global metric 999 $routesbalancingbackup" ip route replace default scope global metric 999 $routesbalancingbackup 2>&1 >/dev/null } @@ -1061,7 +1043,7 @@ if [ "$multipath_config" = "master" ]; then if [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip -6 r show table 991337)" != "default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE " ]; then ip -6 route replace default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE table 991337 2>&1 >/dev/null fi - if ([ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ]) || [ $(($(date +"%s") + $((10 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q show openmptcprouter | grep get_config=\'1\')" != "" ] || [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" != "" ]; then + if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ] || [ $(($(date +"%s") + $((10 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q show openmptcprouter | grep get_config=\'1\')" != "" ] || [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" != "" ]; then [ "$(pgrep openmptcprouter-vps)" = "" ] && /etc/init.d/openmptcprouter-vps restart >/dev/null 2>&1 fi multipath_config="on" @@ -1075,7 +1057,7 @@ if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then elif [ "$(uci -q get openmptcprouter.settings.master)" != "failover" ]; then config_foreach set_server_route server fi - if [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip r show dev $OMR_TRACKER_DEVICE | grep default)" = "" ] && [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.metric)" != "" ]; then + if [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip r show dev $OMR_TRACKER_DEVICE | grep default)" = "" ] && [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.metric)" != "" ]; then _log "Interface route not yet set, set route ip r add default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $(uci -q get network.$OMR_TRACKER_INTERFACE.metric)" ip r add default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $(uci -q get network.$OMR_TRACKER_INTERFACE.metric) >/dev/null 2>&1 fi @@ -1088,12 +1070,12 @@ if [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; th elif [ "$(uci -q get openmptcprouter.settings.master)" != "failover" ]; then config_foreach set_server_route6 server fi - if [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip -6 r show dev $OMR_TRACKER_DEVICE | grep default)" = "" ] && [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.metric)" != "" ]; then + if [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip -6 r show dev $OMR_TRACKER_DEVICE | grep default)" = "" ] && [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.metric)" != "" ]; then ip -6 r replace default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE metric $(uci -q get network.$OMR_TRACKER_INTERFACE.metric) >/dev/null 2>&1 fi fi -if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$multipath_config" = "on" ] || [ "$multipath_config" = "backup" ]); then +if [ "$multipath_config" = "on" ] || [ "$multipath_config" = "backup" ]; then download="$(uci -q get network.$OMR_TRACKER_INTERFACE.downloadspeed)" [ -z "$download" ] && download="$(uci -q get sqm.$OMR_TRACKER_INTERFACE.download)" upload="$(uci -q get network.$OMR_TRACKER_INTERFACE.uploadspeed)" @@ -1162,7 +1144,7 @@ fi #ubus call network reload # Save wan settings for status page -if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ] || [ $(($(date +"%s") + $((30 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.state)" = "down" ]); then +if [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ] || [ $(($(date +"%s") + $((30 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.state)" = "down" ]; then [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && _log "Get status and settings for $OMR_TRACKER_INTERFACE..." local ipaddr="" local ip6addr="" @@ -1200,7 +1182,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC if [ "$(uci -q get openmptcprouter.settings.external_check)" != "0" ]; then #local asn="$(wget -4 -qO- -T 4 http://api.iptoasn.com/v1/as/ip/$ipaddr | jsonfilter -q -e '@.as_description')" #[ -z "$asn" ] && { - local asn="$(timeout 2 whois $ipaddr 2>/dev/null | grep -m 1 -i 'netname' | awk '{print $2}')" + local asn="$(whois $ipaddr 2>/dev/null | grep -m 1 -i 'netname' | awk '{print $2}')" #} fi [ -z "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE)" ] && { @@ -1215,16 +1197,9 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC uci -q set openmptcprouter.latest_versions.lc=$(date +"%s") } fi - [ -n "$ipaddr" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.publicip)" != "$ipaddr" ] && { - _log "New public ip detected for $OMR_TRACKER_INTERFACE ($OMR_TRACKER_DEVICE): $ipaddr" - /etc/init.d/mptcp enabled && { - _log "Reload MPTCP for $OMR_TRACKER_DEVICE" - /etc/init.d/mptcp reload "$OMR_TRACKER_DEVICE" 2>&1 >/dev/null - } - uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.publicip="$ipaddr" - } + [ -n "$ipaddr" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.publicip="$ipaddr" [ -n "$OMR_TRACKER_LATENCY" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.latency="$OMR_TRACKER_LATENCY" - [ -n "$asn" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.asn)" != "$asn" ] && { + [ -n "$asn" ] && { uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.asn="$asn" } @@ -1232,7 +1207,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC local lanip="$(uci -q get network.lan.ipaddr)" local masterip get_master_ip() { - if [ -n "$1" ] && [ "$(uci -q get openmptcprouter.$1.multipath)" = "master" ]; then + if [ "$(uci -q get openmptcprouter.$1.multipath)" = "master" ]; then masterip="$(uci -q get openmptcprouter.$1.publicip)" fi } @@ -1241,8 +1216,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC if [ -n "$lanip" ] && [ -n "$masterip" ] && [ -n "$ipaddr" ] && [ "$ipaddr" = "$masterip" ] && [ "$(uci -q get openmptcprouter.settings.disableloopdetection)" != "1" ]; then loop=0 routingloop() { - vpsip="" - [ -n "$1"] && vpsip="$(uci -q get openmptcprouter.$1.ip)" + vpsip="$(uci -q get openmptcprouter.$1.ip)" if [ -n "$vpsip" ] && [ "$(omr-routing-loop $vpsip $lanip $OMR_TRACKER_DEVICE)" = "detected" ]; then loop=1 fi @@ -1268,9 +1242,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC } if [ "$OMR_TRACKER_INTERFACE" != "omrvpn" ] && [ "$(uci -q get glorytun.vpn.enable)" != "1" ] && [ "$(uci -q get glorytun-udp.vpn.enable)" != "1" ] && [ -n "$OMR_TRACKER_DEVICE" ]; then if [ -n "$(uci -q get network.$(find_network_device ${OMR_TRACKER_INTERFACE}).mtu)" ]; then - network_device=$(find_network_device ${OMR_TRACKER_INTERFACE}) - mtu="" - [ -n "$network_device" ] && mtu=$(uci -q get network.${network_device}.mtu) + mtu=$(uci -q get network.$(find_network_device ${OMR_TRACKER_INTERFACE}).mtu) [ -n "$mtu" ] && { uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.mtu=$mtu ip link set dev $OMR_TRACKER_DEVICE mtu $mtu > /dev/null 2>&1 @@ -1296,7 +1268,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC } config_load openmptcprouter config_foreach traceboxmtutest server - [ "$(uci -q get openmptcprouter.settings.tracebox)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE" ] && { + [ "$(uci -q get openmptcprouter.settings.tracebox)" = "0" ] && { mptcpsupport="$(omr-mptcp-intf $OMR_TRACKER_DEVICE)" [ -n "$mptcpsupport" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.mptcp_status="$mptcpsupport" } @@ -1319,14 +1291,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC uci -q set openmptcprouter.latest_versions.lc=$(date +"%s") } fi - [ -n "$ip6addr" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.publicip)" != "$ip6addr" ] && { - _log "New public ip detected for $OMR_TRACKER_INTERFACE ($OMR_TRACKER_DEVICE): $ip6addr" - /etc/init.d/mptcp enabled && { - _log "Reload MPTCP for $OMR_TRACKER_DEVICE" - /etc/init.d/mptcp reload "$OMR_TRACKER_DEVICE" 2>&1 >/dev/null - } - uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.publicip="$ip6addr" - } + [ -n "$ipaddr" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.publicip6="$ip6addr" [ -n "$OMR_TRACKER_LATENCY" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.latency="$OMR_TRACKER_LATENCY" [ -n "$asn" ] && { uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.asn="$asn" @@ -1340,8 +1305,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC [ -n "$omrtracebox" ] && [ -z "$(echo $omrtracebox | grep error)" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.mptcp_status="$omrtracebox" } if [ "$OMR_TRACKER_INTERFACE" != "omrvpn" ] && [ "$(uci -q get glorytun.vpn.enable)" != "1" ] && [ "$(uci -q get glorytun-udp.vpn.enable)" != "1" ] && [ -n "$OMR_TRACKER_DEVICE" ]; then - network_device=$(find_network_device ${OMR_TRACKER_INTERFACE}) - if [ -n "$network_device" ] && [ -n "$(uci -q get network.${network_device}.mtu)" ]; then + if [ -n "$(uci -q get network.$(find_network_device ${OMR_TRACKER_INTERFACE}).mtu)" ]; then mtu=$(uci -q get network.$(find_network_device ${OMR_TRACKER_INTERFACE}).mtu) [ -n "$mtu" ] && { uci -q set openmptcprouter.${OMR_TRACKER_INTERFACE}.mtu=$mtu @@ -1412,7 +1376,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get openmptcprouter.$OMR_TRAC dns_flush fi -[ -n "$OMR_TRACKER_INTERFACE" ] && [ -n "$OMR_TRACKER_LATENCY" ] && { +[ -n "$OMR_TRACKER_LATENCY" ] && { [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.latency)" != "" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.latency_previous="$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.latency)" uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.latency="$OMR_TRACKER_LATENCY" #[ -z "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.latency_max)" ] && uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.latency_max="$OMR_TRACKER_LATENCY" @@ -1421,7 +1385,7 @@ fi masterintf="$(uci -q show openmptcprouter | grep -m 1 multipath=\'master\' | cut -d'.' -f2)" [ -z "$masterintf" ] && masterintf="$(uci -q show network | grep -m 1 multipath=\'master\' | cut -d'.' -f2)" masterlatency="$(uci -q get openmptcprouter.$masterintf.latency | tr -d '\n')" - if [ -z "$masterlatency" ] || ([ -n "$masterintf" ] && [ "$(uci -q get openmptcprouter.$masterintf.state)" = "down" ]); then + if [ -z "$masterlatency" ] || [ "$(uci -q get openmptcprouter.$masterintf.state)" = "down" ]; then masterlatency=1000 fi if [ -n "$masterintf" ] && ([ "$masterlatency" != "" ] || [ "$(uci -q get openmptcprouter.$masterintf.state)" = "down" ]); then @@ -1449,22 +1413,22 @@ fi # If a service is down, force restart it if [ "$(pgrep ss-redir)" = "" ] && [ "$(pgrep ss-local)" = "" ] && [ "$(uci -q get shadowsocks-libev.sss0.disabled)" != "1" ] && [ "$(uci -q get shadowsocks-libev.sss0.server)" != "" ] && [ "$(uci -q get shadowsocks-libev.sss0.server)" != "192.18.1.3" ] && [ "$(uci -q get shadowsocks-libev.sss0.key)" != "" ]; then _log "Can't find Shadowsocks, restart it..." - /etc/init.d/shadowsocks-libev restart 2>&1 >/dev/null + /etc/init.d/shadowsocks-libev restart sleep 5 fi if [ "$(pgrep glorytun)" = "" ] && [ "$(uci -q get glorytun.vpn.enable)" = "1" ] && [ -f /etc/init.d/glorytun ] && [ "$(uci -q get glorytun.vpn.key)" != "" ]; then _log "Can't find Glorytun, restart it..." - /etc/init.d/glorytun restart 2>&1 >/dev/null + /etc/init.d/glorytun restart sleep 5 fi if [ "$(pgrep glorytun-udp)" = "" ] && [ "$(uci -q get glorytun-usp.vpn.enable)" = "1" ] && [ -f /etc/init.d/glorytun-udp ] && [ "$(uci -q get glorytun-udp.vpn.key)" != "" ]; then _log "Can't find Glorytun UDP, restart it..." - /etc/init.d/glorytun-udp restart 2>&1 >/dev/null + /etc/init.d/glorytun-udp restart sleep 5 fi if [ "$(pgrep unbound)" = "" ] && [ -f /etc/init.d/unbound ] && [ "$(uci -q get unbound.@unbound[0].enabled)" = "1" ]; then - /etc/init.d/unbound restart 2>&1 >/dev/null + /etc/init.d/unbound restart sleep 5 fi @@ -1477,53 +1441,53 @@ if [ "$(pgrep openvpn)" = "" ] && [ -f /etc/init.d/openvpn ]; then config_foreach openvpn_enabled openvpn if [ "$openvpn_enable" = "1" ]; then _log "Can't find OpenVPN, restart it" - /etc/init.d/openvpn restart 2>&1 >/dev/null + /etc/init.d/openvpn restart sleep 5 fi fi if [ "$(pgrep mlvpn)" = "" ] && [ "$(uci -q get mlvpn.general.enable)" = "1" ] && [ -f /etc/init.d/mlvpn ] && [ "$(uci -q get mlvpn.general.password)" != "" ]; then _log "Can't find MLVPN, restart it..." - /etc/init.d/mlvpn restart 2>&1 >/dev/null + /etc/init.d/mlvpn restart sleep 5 fi if [ "$(pgrep dsvpn)" = "" ] && [ "$(uci -q get dsvpn.vpn.enable)" = "1" ] && [ -f /etc/init.d/dsvpn ] && [ "$(uci -q get dsvpn.vpn.key)" != "" ]; then _log "Can't find DSVPN, restart it..." - /etc/init.d/dsvpn restart 2>&1 >/dev/null + /etc/init.d/dsvpn restart sleep 5 fi if [ "$(pgrep v2ray)" = "" ] && [ "$(uci -q get v2ray.main.enabled)" = "1" ] && [ -f /etc/init.d/v2ray ]; then _log "Can't find V2Ray, restart it..." - /etc/init.d/v2ray restart 2>&1 >/dev/null + /etc/init.d/v2ray restart sleep 5 fi if [ "$(pgrep miniupnpd)" = "" ] && [ "$(uci -q get upnpd.config.enabled)" = "1" ] && [ -f /etc/init.d/miniupnpd ]; then _log "Can't find miniupnpd, restart it..." - /etc/init.d/miniupnpd restart 2>&1 >/dev/null + /etc/init.d/miniupnpd restart sleep 5 fi if [ "$(pgrep rpcd)" = "" ] && [ -f /etc/init.d/rpcd ]; then _log "Can't find rpcd, restart it..." - /etc/init.d/rpcd restart 2>&1 >/dev/null + /etc/init.d/rpcd restart sleep 5 fi if [ "$(pgrep uhttpd)" = "" ] && [ -f /etc/init.d/uhttpd ]; then _log "Can't find uhttpd, restart it..." - /etc/init.d/uhttpd restart 2>&1 >/dev/null + /etc/init.d/uhttpd restart sleep 5 fi #if [ "$(pgrep ModemManager)" = "" ] && [ -f /etc/init.d/modemmanager ] && [ -n "$(uci -q show network | grep modemmanager)" ] && [ "$(uci -q get openmptcprouter.settings.modemmanager)" != "0" ]; then # _log "Can't find ModemManager, restart it..." -# /etc/init.d/modemmanager restart 2>&1 >/dev/null +# /etc/init.d/modemmanager restart # sleep 5 #fi if [ "$(uci -q get v2ray.main.enabled)" = "1" ] && [ -f /etc/init.d/v2ray ] && [ "$(pgrep -f omr-tracker-v2ray)" = "" ] && [ "$(pgrep -f '/etc/init.d/omr-tracker')" = "" ]; then _log "Can't find omr-tracker-v2ray, restart omr-tracker..." - /etc/init.d/omr-tracker restart 2>&1 >/dev/null + /etc/init.d/omr-tracker restart fi set_get_config() { @@ -1539,7 +1503,7 @@ fi if [ "$(uci -q get shadowsocks-libev.sss0.disabled)" != "1" ] && [ "$(uci -q get shadowsocks-libev.sss0.key)" != "" ] && [ "$(uci -q get shadowsocks-libev.sss0.server)" != "" ] && [ "$(uci -q get shadowsocks-libev.sss0.server)" != "192.18.1.3" ] && [ "$(pgrep -f omr-tracker-ss)" = "" ] && [ "$(pgrep -f '/etc/init.d/omr-tracker')" = "" ]; then _log "Can't find omr-tracker-ss, restart omr-tracker..." - /etc/init.d/omr-tracker restart 2>&1 >/dev/null + /etc/init.d/omr-tracker restart fi if [ "$(uci -q get glorytun.vpn.enable)" = "1" ] && [ "$(uci -q get glorytun.vpn.key)" = "" ]; then @@ -1563,12 +1527,12 @@ fi if [ "$(iptables-save | grep omr-bypass)" = "" ] && [ "$(pgrep omr-bypass)" = "" ]; then _log "Can't find omr-bypass rules, restart omr-bypass..." - /etc/init.d/omr-bypass 2>&1 >/dev/null + /etc/init.d/omr-bypass fi if [ -f /etc/backup/installed_packages.txt ]; then _log "Reinstall packages..." - /etc/init.d/sysupgrade restart 2>&1 >/dev/null + /etc/init.d/sysupgrade restart fi if [ "$(pgrep openmptcprouter-vps)" = "" ] && ([ "$(uci -q show openmptcprouter | grep get_config=\'1\')" != "" ] || [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" != "" ]); then @@ -1577,12 +1541,12 @@ if [ "$(pgrep openmptcprouter-vps)" = "" ] && ([ "$(uci -q show openmptcprouter fi -if [ "$(uci -q show openmptcprouter | grep server)" != "" ] && [ "$(pgrep openmptcprouter-vps)" = "" ] && [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" = "" ] && ([ "$(uci -q show openmptcprouter | grep set_firewall=\'1\')" != "" ] || [ -z "$(iptables-save | grep omr_dst_bypass_${OMR_TRACKER_DEVICE})" ]); then +if [ "$(pgrep openmptcprouter-vps)" = "" ] && [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" = "" ] && ([ "$(uci -q show openmptcprouter | grep set_firewall=\'1\')" != "" ] || [ -z "$(iptables-save | grep omr_dst_bypass_${OMR_TRACKER_DEVICE})" ]); then _log "Set firewall on server" /etc/init.d/openmptcprouter-vps set_vps_firewall >/dev/null 2>&1 run_fw_include() { - [ -n "$1" ] && [ "$(uci -q get firewall.$1.reload)" = "0" ] && sh $(uci -q get firewall.$1.path) >/dev/null 2>&1 + [ "$(uci -q get firewall.$1.reload)" = "0" ] && sh $(uci -q get firewall.$1.path) >/dev/null 2>&1 } config_load firewall config_foreach run_fw_include include