From 245d1b43c45c245e3b0d962c7cadb9154e328773 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 16 Jul 2024 09:10:17 +0200 Subject: [PATCH 1/6] Fix indentation --- .../usr/share/omr/schedule.d/010-services | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/omr-schedule/files/usr/share/omr/schedule.d/010-services b/omr-schedule/files/usr/share/omr/schedule.d/010-services index 260da9f20f..9b5708adfa 100755 --- a/omr-schedule/files/usr/share/omr/schedule.d/010-services +++ b/omr-schedule/files/usr/share/omr/schedule.d/010-services @@ -148,18 +148,19 @@ restart_omrtracker() { } set_lan_ips() { - config_get ip4table "$1" ip4table - config_get device "$1" device - config_get proto "$1" proto - if [ "$ip4table" != "wan" ] && [ "$ip4table" != "vpn" ] && [ -n "$ip4table" ] && [ -n "$device" ] && ([ "$proto" = "dhcp" ] || [ "$proto" = "static" ]); then - [ -z "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ] && [ -z "$(uci -q get shadowsocks-rust.ss_rules.ifnames | grep $device)" ] && { - uci -q add_list shadowsocks-libev.ss_rules.ifnames="$device" - uci -q add_list shadowsocks-rust.ss_rules.ifnames="$device" - } - elif [ -n "$device" ] && [ -n "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ]; then - uci -q del_list shadowsocks-libev.ss_rules.ifnames="$device" - uci -q del_list shadowsocks-rust.ss_rules.ifnames="$device" - fi + config_get ip4table "$1" ip4table + config_get device "$1" device + config_get proto "$1" proto + [ -n "$(echo $device | grep -)" ] && uci -q set openmptcprouter.settings.restrict_to_lan="0" && uci commit openmptcprouter + if [ "$ip4table" != "wan" ] && [ "$ip4table" != "vpn" ] && [ -n "$ip4table" ] && [ -n "$device" ] && ([ "$proto" = "dhcp" ] || [ "$proto" = "static" ]); then + [ -z "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ] && [ -z "$(uci -q get shadowsocks-rust.ss_rules.ifnames | grep $device)" ] && { + uci -q add_list shadowsocks-libev.ss_rules.ifnames="$device" + uci -q add_list shadowsocks-rust.ss_rules.ifnames="$device" + } + elif [ -n "$device" ] && [ -n "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ]; then + uci -q del_list shadowsocks-libev.ss_rules.ifnames="$device" + uci -q del_list shadowsocks-rust.ss_rules.ifnames="$device" + fi } config_load network config_foreach restart_omrtracker interface From e02a8d8bd22adcc50de71c00011a646269ac5aec Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 16 Jul 2024 09:10:53 +0200 Subject: [PATCH 2/6] Fix latency report on OMR-Tracker when not binding to an interface --- omr-tracker/files/bin/omr-tracker | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/omr-tracker/files/bin/omr-tracker b/omr-tracker/files/bin/omr-tracker index bb582b052d..8d57e6a8a8 100755 --- a/omr-tracker/files/bin/omr-tracker +++ b/omr-tracker/files/bin/omr-tracker @@ -160,13 +160,18 @@ _ping() { -t "$OMR_TRACKER_MAX_TTL" \ -Q 184 \ "${host}" 2>&1 - ) && echo "$ret" | grep -sq " 0% packet loss" && { + ) + if [ -n "$loss" ] && [ "$loss" != "100" ]; then if [ "$localip" = "yes" ]; then - OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') - #_update_rto "$OMR_TRACKER_LATENCY" + latency=$(echo "$ret" | grep rtt | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') + [ -n "$latency" ] && { + OMR_TRACKER_LATENCY="$latency" + #_update_rto "$OMR_TRACKER_LATENCY" + } + OMR_TRACKER_LOSS="$loss" fi return - } + fi else ret=$(ping -B -I "${device}" \ -w "$OMR_TRACKER_TIMEOUT" \ From 98b3f85638f7c8424c0c52f3c7e8c45277239be5 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 16 Jul 2024 09:11:19 +0200 Subject: [PATCH 3/6] Add more log in OMR-Tracker-ss --- omr-tracker/files/bin/omr-tracker-ss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/omr-tracker/files/bin/omr-tracker-ss b/omr-tracker/files/bin/omr-tracker-ss index 5b1ebfc577..dec53015cd 100755 --- a/omr-tracker/files/bin/omr-tracker-ss +++ b/omr-tracker/files/bin/omr-tracker-ss @@ -126,6 +126,7 @@ while true; do _log "Reload Shadowsocks rules" /etc/init.d/shadowsocks-libev rules_up 2> /dev/null if ! /etc/init.d/shadowsocks-libev rules_exist ; then + _log "Rules still not set, restart Shadowsocks" /etc/init.d/shadowsocks-libev restart >/dev/null 2>&1 fi _get_ip @@ -133,6 +134,7 @@ while true; do _log "Reload Shadowsocks Rust rules" /etc/init.d/shadowsocks-rust rules_up 2> /dev/null if ! /etc/init.d/shadowsocks-rust rules_exist ; then + _log "Rules still not set, restart Shadowsocks-Rust" /etc/init.d/shadowsocks-rust restart >/dev/null 2>&1 fi _get_ip From 7fc99ca3bdc8152ecea94a8947c41ff0a25e0cd2 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 16 Jul 2024 09:48:29 +0200 Subject: [PATCH 4/6] Use named instance in omr-tracker interfaces --- omr-tracker/files/etc/init.d/omr-tracker | 92 +++++++++++++----------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/omr-tracker/files/etc/init.d/omr-tracker b/omr-tracker/files/etc/init.d/omr-tracker index 1dd50002bd..a1bb463a4d 100755 --- a/omr-tracker/files/etc/init.d/omr-tracker +++ b/omr-tracker/files/etc/init.d/omr-tracker @@ -79,8 +79,8 @@ _launch_tracker() { _validate_section "interface" "$1" local ifname ip4table - network_get_device ifname $1 - [ -z "$ifname" ] && network_get_physdev ifname $1 + #network_get_device ifname $1 + #[ -z "$ifname" ] && network_get_physdev ifname $1 [ -z "$ifname" ] && ifname=$(ifstatus "$1" | jsonfilter -q -e '@["l3_device"]') [ -z "$ifname" ] && ifname=$(ifstatus "$1_4" | jsonfilter -q -e '@["l3_device"]') #[ -z "$ifname" ] && config_get ifname "$1" device @@ -116,7 +116,7 @@ _launch_tracker() { [ -z "${family}" ] && family='ipv4' #[ -z "${failure_interval}" ] && failure_interval=5 - procd_open_instance + procd_open_instance "$1" # shellcheck disable=SC2086 procd_set_param command /bin/omr-tracker "$1" $options procd_append_param env "OMR_TRACKER_HOSTS=$hosts" @@ -416,49 +416,55 @@ start_interface() { start_service() { local ss_enable=0 local ss_rust_enable=0 - logger -t "omr-tracker" "Launching..." - count=1111 - config_load shadowsocks-libev - config_foreach _initialize_shadowsocks_tracker server - - count=1111 - config_load shadowsocks-rust - config_foreach _initialize_shadowsocks_rust_tracker server - - config_load network - config_foreach _launch_tracker interface - - if [ "$ss_enable" = "1" ]; then + local instance="$1" + if [ -z "$instance" ]; then + logger -t "omr-tracker" "Launching..." + count=1111 config_load shadowsocks-libev - config_foreach _launch_shadowsocks_tracker ss_local - #elif [ "$(uci -q get shadowsocks-libev.sss0.disabled)" != "1" ]; then - # /etc/init.d/shadowsocks-libev rules_down - fi - if [ "$ss_rust_enable" = "1" ]; then + config_foreach _initialize_shadowsocks_tracker server + + count=1111 config_load shadowsocks-rust - config_foreach _launch_shadowsocks_rust_tracker ss_local - fi - config_load v2ray - config_get v2rayenabled main enabled - if [ "$v2rayenabled" = "1" ]; then - _launch_v2ray_tracker - fi - - config_load xray - config_get xrayenabled main enabled - if [ "$xrayenabled" = "1" ]; then - _launch_xray_tracker - fi + config_foreach _initialize_shadowsocks_rust_tracker server - multiserver=false - config_load openmptcprouter - config_foreach _multi_server server - [ "$multiserver" = true ] && _launch_server_tracker - gretunnel=false - config_load network - config_foreach _gre_tunnel interface - [ "$gretunnel" = true ] && _launch_gre_tracker - logger -t "omr-tracker" "Launched" + config_load network + config_foreach _launch_tracker interface + + if [ "$ss_enable" = "1" ]; then + config_load shadowsocks-libev + config_foreach _launch_shadowsocks_tracker ss_local + #elif [ "$(uci -q get shadowsocks-libev.sss0.disabled)" != "1" ]; then + # /etc/init.d/shadowsocks-libev rules_down + fi + if [ "$ss_rust_enable" = "1" ]; then + config_load shadowsocks-rust + config_foreach _launch_shadowsocks_rust_tracker ss_local + fi + config_load v2ray + config_get v2rayenabled main enabled + if [ "$v2rayenabled" = "1" ]; then + _launch_v2ray_tracker + fi + + config_load xray + config_get xrayenabled main enabled + if [ "$xrayenabled" = "1" ]; then + _launch_xray_tracker + fi + + multiserver=false + config_load openmptcprouter + config_foreach _multi_server server + [ "$multiserver" = true ] && _launch_server_tracker + gretunnel=false + config_load network + config_foreach _gre_tunnel interface + [ "$gretunnel" = true ] && _launch_gre_tracker + logger -t "omr-tracker" "Launched" + else + config_load network + _launch_tracker ${instance} + fi } service_triggers() { From 643b87ec63cedec4d49893d569bac4e6beca4514 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 16 Jul 2024 09:49:29 +0200 Subject: [PATCH 5/6] Fix typo on glorytun udp check and don't create route to server via omr6in4/omrvpn --- omr-tracker/files/usr/share/omr/post-tracking.d/003-up | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/omr-tracker/files/usr/share/omr/post-tracking.d/003-up b/omr-tracker/files/usr/share/omr/post-tracking.d/003-up index 9174c55228..a398a35363 100755 --- a/omr-tracker/files/usr/share/omr/post-tracking.d/003-up +++ b/omr-tracker/files/usr/share/omr/post-tracking.d/003-up @@ -195,6 +195,7 @@ set_routes_intf() { local multipath_config_route local INTERFACE=$1 [ -z "$INTERFACE" ] && return + [ "$INTERFACE" = "omrvpn" ] && continue multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath) [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off") [ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && { @@ -252,6 +253,8 @@ set_routes_intf6() { local multipath_config_route local INTERFACE=$1 [ -z "$INTERFACE" ] && return + [ "$INTERFACE" = "omr6in4" ] && continue + [ "$INTERFACE" = "omrvpn" ] && continue multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath) [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off") [ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && { @@ -325,6 +328,7 @@ set_route_balancing() { local multipath_config_route interface_gw interface_if INTERFACE=$1 [ -z "$INTERFACE" ] && return + [ "$INTERFACE" = "omrvpn" ] && continue multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath) [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off") [ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && { @@ -384,6 +388,8 @@ set_route_balancing6() { local multipath_config_route interface_gw interface_if INTERFACE=$1 [ -z "$INTERFACE" ] && return + [ "$INTERFACE" = "omr6in4" ] && continue + [ "$INTERFACE" = "omrvpn" ] && continue multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath) [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off") [ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && { @@ -1036,7 +1042,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && { [ "$multipath_config" = "on" ] || [ "$mu } config_list_foreach $1 ip addpath } - if [ "$(uci -q get glorytun-udp.vpn.enable)" = "1"]; then + if [ "$(uci -q get glorytun-udp.vpn.enable)" = "1" ]; then config_load openmptcprouter config_foreach glorytunudppath server fi From 462fbaae5a80aeb6041caef5b2d2b111fc916e95 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 16 Jul 2024 09:50:31 +0200 Subject: [PATCH 6/6] Manage the case when interface can't be binded in local API for status page --- .../files/usr/libexec/rpcd/openmptcprouter | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/openmptcprouter-api/files/usr/libexec/rpcd/openmptcprouter b/openmptcprouter-api/files/usr/libexec/rpcd/openmptcprouter index b56e88dc97..703e7558d5 100755 --- a/openmptcprouter-api/files/usr/libexec/rpcd/openmptcprouter +++ b/openmptcprouter-api/files/usr/libexec/rpcd/openmptcprouter @@ -1519,11 +1519,25 @@ function interfaces_status() if serverip ~= "" then local server_ping_test = sys.exec("ping -B -w 1 -c 1 -I " .. ifname .. " " .. serverip) local server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'")) + local server_ping_nobind = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep 'Address not available'")) if server_ping_result ~= "" then server_ping = "DOWN" if connectivity == "OK" then connectivity = "WARNING" end + elseif server_ping_nobind ~= "" then + server_ping_test = sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. serverip) + server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'")) + if server_ping_result ~= "" then + server_ping = "DOWN" + if connectivity == "OK" then + connectivity = "WARNING" + end + else + mArray.openmptcprouter["vps_status"] = "UP" + server_ping = "UP" + latency = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | cut -d '/' -s -f5 | cut -d '.' -f1")) + end else mArray.openmptcprouter["vps_status"] = "UP" server_ping = "UP"