mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Fixes and use nping for failover
This commit is contained in:
parent
f9adb2e523
commit
99881d1487
5 changed files with 18 additions and 21 deletions
|
@ -14,10 +14,10 @@ set_route() {
|
||||||
interface_if=$(uci -q get "network.$INTERFACE.ifname")
|
interface_if=$(uci -q get "network.$INTERFACE.ifname")
|
||||||
_log "Replace default route by $interface_gw dev $interface_if"
|
_log "Replace default route by $interface_gw dev $interface_if"
|
||||||
ip route replace default scope global nexthop via $interface_gw dev $interface_if && SETROUTE=true
|
ip route replace default scope global nexthop via $interface_gw dev $interface_if && SETROUTE=true
|
||||||
sleep `expr $RANDOM % 10`
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sleep `expr $RANDOM % 10`
|
||||||
|
|
||||||
# Get the current multipath status
|
# Get the current multipath status
|
||||||
multipath_status="off"
|
multipath_status="off"
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=omr-tracker
|
PKG_NAME:=omr-tracker
|
||||||
PKG_VERSION:=1.12
|
PKG_VERSION:=1.2
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
@ -18,7 +18,7 @@ define Package/$(PKG_NAME)
|
||||||
SECTION:=net
|
SECTION:=net
|
||||||
CATEGORY:=Network
|
CATEGORY:=Network
|
||||||
TITLE:=OpenMPTCProuter tracker
|
TITLE:=OpenMPTCProuter tracker
|
||||||
DEPENDS:=+bind-dig
|
DEPENDS:=+nping
|
||||||
PKGARCH:=all
|
PKGARCH:=all
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
|
@ -86,26 +86,21 @@ while true; do
|
||||||
if [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
|
if [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
|
||||||
# retrieve iface ip and gateway
|
# retrieve iface ip and gateway
|
||||||
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
|
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
|
||||||
|
OMR_TRACKER_DEVICE_GATEWAY_MAC=$(arp $OMR_TRACKER_DEVICE_GATEWAY | awk '{print $4}')
|
||||||
|
|
||||||
# execute specific tracker
|
# execute specific tracker
|
||||||
if [ -n "$OMR_TRACKER_DEVICE_IP" ]; then
|
if [ -n "$OMR_TRACKER_DEVICE_IP" ]; then
|
||||||
retgw=$(ping "$OMR_TRACKER_DEVICE_GATEWAY" \
|
|
||||||
-I "$OMR_TRACKER_DEVICE_IP" \
|
|
||||||
-w 1 \
|
|
||||||
-c 1 \
|
|
||||||
-q
|
|
||||||
) && echo "$retgw" | grep -sq "0% packet loss" && {
|
|
||||||
# setup loop variable
|
# setup loop variable
|
||||||
tries="$OMR_TRACKER_TRIES"
|
tries="$OMR_TRACKER_TRIES"
|
||||||
# loop until tries attempts have been reached
|
# loop until tries attempts have been reached
|
||||||
while [ "$tries" -gt 0 ]; do
|
while [ "$tries" -gt 0 ]; do
|
||||||
ret=$(ping "$OMR_TRACKER_HOST" \
|
ret=$(arpping -c 1 \
|
||||||
-I "$OMR_TRACKER_DEVICE_IP" \
|
-r "$OMR_TRACKER_DEVICE" \
|
||||||
-w "$OMR_TRACKER_TIMEOUT" \
|
-S "$OMR_TRACKER_DEVICE_IP" \
|
||||||
-c 1 \
|
-T "$OMR_TRACKER_HOST" \
|
||||||
-q
|
"$OMR_TRACKER_DEVICE_GATEWAY_MAC")
|
||||||
) && echo "$ret" | grep -sq "0% packet loss" && {
|
) && echo "$ret" | grep -sq "Lost: 0 (0.00%)" && {
|
||||||
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f4 | cut -d "." -f1)
|
OMR_TRACKER_LATENCY=$(echo "$ret" | awk '/Avg/{print $(NF)}' | sed 's:ms::')
|
||||||
_update_rto "$OMR_TRACKER_LATENCY"
|
_update_rto "$OMR_TRACKER_LATENCY"
|
||||||
OMR_TRACKER_STATUS="OK"
|
OMR_TRACKER_STATUS="OK"
|
||||||
break
|
break
|
||||||
|
|
|
@ -43,6 +43,7 @@ _launch_tracker() {
|
||||||
local ifname ip4table
|
local ifname ip4table
|
||||||
config_get ifname "$1" ifname
|
config_get ifname "$1" ifname
|
||||||
config_get multipath "$1" multipath
|
config_get multipath "$1" multipath
|
||||||
|
config_get gateway "$1" gateway
|
||||||
|
|
||||||
[ -z "$ifname" ] || [ -z "$multipath" ] || [ "$multipath" = "off" ] && return
|
[ -z "$ifname" ] || [ -z "$multipath" ] || [ "$multipath" = "off" ] && return
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ _launch_tracker() {
|
||||||
procd_append_param env "OMR_TRACKER_INTERVAL=$interval"
|
procd_append_param env "OMR_TRACKER_INTERVAL=$interval"
|
||||||
procd_append_param env "OMR_TRACKER_TABLE=$ip4table"
|
procd_append_param env "OMR_TRACKER_TABLE=$ip4table"
|
||||||
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_set_param respawn 0 10 0
|
procd_set_param respawn 0 10 0
|
||||||
procd_set_param stderr 1
|
procd_set_param stderr 1
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
|
|
|
@ -131,7 +131,7 @@ ss_mkjson_ss_tunnel_conf() {
|
||||||
EOF
|
EOF
|
||||||
[ "$obfs" = 0 ] && obfs=false || obfs=true
|
[ "$obfs" = 0 ] && obfs=false || obfs=true
|
||||||
if $obfs; then
|
if $obfs; then
|
||||||
obfs_options="--obfs $obfs_type"
|
obfs_options="obfs=$obfs_type"
|
||||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options --obfs-host $obfs_host"
|
[ -z "$obfs_host" ] || obfs_options="$obfs_options --obfs-host $obfs_host"
|
||||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options --obfs-uri $obfs_uri"
|
[ -z "$obfs_uri" ] || obfs_options="$obfs_options --obfs-uri $obfs_uri"
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue