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

New version of OMR-Tracker

This commit is contained in:
Ycarus (Yannick Chabanois) 2024-01-12 17:28:40 +01:00
parent bb64827a1e
commit f5b3aa6831
15 changed files with 831 additions and 318 deletions

View file

@ -1,6 +1,6 @@
#
# OpenMPTCProuter tracker is a modified version of OverTheBox tracker from OVH
# Copyright (C) 2017-2019 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
# Copyright (C) 2017-2023 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
@ -9,7 +9,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=omr-tracker
PKG_VERSION:=1.7
PKG_VERSION:=2.0
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk

View file

@ -17,6 +17,9 @@ export OMR_TRACKER_INTERFACE
export OMR_TRACKER_HOST
export OMR_TRACKER_HOST6
export OMR_TRACKER_TIMEOUT
export OMR_TRACKER_SIZE
export OMR_TRACKER_MAX_TTL
export OMR_TRACKER_LOSS
export OMR_TRACKER_STATUS
export OMR_TRACKER_STATUS_MSG
export OMR_TRACKER_PREV_STATUS
@ -150,6 +153,8 @@ _ping() {
ret=$(ping -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \
-c "$OMR_TRACKER_COUNT" \
-s "$OMR_TRACKER_SIZE" \
-t "$OMR_TRACKER_MAX_TTL" \
-Q 184 \
"${host}" 2>&1
) && echo "$ret" | grep -sq " 0% packet loss" && {
@ -163,15 +168,20 @@ _ping() {
ret=$(ping -B -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \
-c "$OMR_TRACKER_COUNT" \
-s "$OMR_TRACKER_SIZE" \
-t "$OMR_TRACKER_MAX_TTL" \
-Q 184 \
"${host}" 2>&1
) && echo "$ret" | grep -sq " 0% packet loss" && {
)
loss=$(echo "$ret" | grep 'packet loss' | sed -ne 's/.*\([0-9]\+\)% packet loss.*/\1/p')
if [ -n "$loss" ] && [ "$loss" -ne 100 ]; then
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
OMR_TRACKER_LOSS="$loss"
_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
fi
#) && echo "$ret" | grep -sq "bytes from" && {
fi
false
@ -242,6 +252,7 @@ while true; do
OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_LATENCY=
OMR_TRACKER_LOSS=
#OMR_TRACKER_TIMEOUT=$((rto / 1000 + (rto % 1000 ? 1 : 0)))
OMR_TRACKER_LIST_HOSTS=""
OMR_TRACKER_DEVICE_GATEWAY=
@ -259,7 +270,7 @@ while true; do
if [ -n "$OMR_TRACKER_DEVICE" ] && [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
if [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep UP)" ]; then
# retrieve iface ip and gateway
if [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
if ([ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
if [ -z "$OMR_TRACKER_DEVICE_IP" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 addr show dev "$OMR_TRACKER_DEVICE" | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1)
@ -305,7 +316,7 @@ while true; do
OMR_TRACKER_DEVICE_GATEWAY=$(ip -4 r list dev "$OMR_TRACKER_DEVICE" | awk '/via/ {print $3}' | tr -d "\n")
fi
fi
if [ "$OMR_TRACKER_IPV6" = "1" ] || [ "$OMR_TRACKER_IPV6" = "auto" ]; then
if ([ "$OMR_TRACKER_IPV6" = "1" ] || [ "$OMR_TRACKER_IPV6" = "auto" ] || [ -z "$OMR_TRACKER_IPV6" ]) && ([ "$OMR_TRACKER_FAMILY" = "ipv6" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]); then
#OMR_TRACKER_DEVICE_IP6=$(ip -6 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
#if [ -z "$OMR_TRACKER_DEVICE_IP6" ]; then
OMR_TRACKER_DEVICE_IP6=$(ip -6 addr show dev "$OMR_TRACKER_DEVICE" | sort -r | grep -m 1 inet6 | awk '{print $2}' | cut -d'/' -s -f1)
@ -331,9 +342,13 @@ while true; do
fi
# execute specific tracker
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
if ([ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
# setup loop variable
tries="$OMR_TRACKER_TRIES"
if [ "$OMR_TRACKER_PREV_STATUS" = "ERROR" ]; then
tries="$OMR_TRACKER_TRIES"
else
tries="$OMR_TRACKER_TRIES_UP"
fi
# loop until tries attempts have been reached
while [ "$tries" -gt 0 ]; do
if [ -n "$OMR_TRACKER_DEVICE_ROUTE" ]; then
@ -430,9 +445,14 @@ while true; do
sleep "$OMR_TRACKER_INTERVAL_TRIES"
done
fi
if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; then
#if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; then
if ([ "$OMR_TRACKER_FAMILY" = "ipv6" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; then
# setup loop variable
tries="$OMR_TRACKER_TRIES"
if [ "$OMR_TRACKER_PREV_STATUS" = "ERROR" ]; then
tries="$OMR_TRACKER_TRIES"
else
tries="$OMR_TRACKER_TRIES_UP"
fi
# loop until tries attempts have been reached
while [ "$tries" -gt 0 ]; do
#if [ -n "$OMR_TRACKER_DEVICE_ROUTE" ]; then
@ -534,7 +554,7 @@ while true; do
[ -z "$OMR_TRACKER_STATUS_MSG" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_INTERFACE may have ip issues"
[ -z "$OMR_TRACKER_DEVICE_IP" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv4"
[ -z "$OMR_TRACKER_DEVICE_GATEWAY" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv4 gateway"
if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ]; then
if ([ "$OMR_TRACKER_IPV6" = "1" ] || [ "$OMR_TRACKER_IPV6" = "auto" ] || [ -z "$OMR_TRACKER_IPV6" ]) && ([ "$OMR_TRACKER_FAMILY" = "ipv6" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]); then
[ -z "$OMR_TRACKER_DEVICE_IP6" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv6"
[ -z "$OMR_TRACKER_DEVICE_GATEWAY6" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv6 gateway"
fi
@ -558,6 +578,26 @@ while true; do
OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG and $OMR_TRACKER_TYPE from $OMR_TRACKER_DEVICE_IP error ($OMR_TRACKER_LIST_HOSTS6)"
fi
fi
if [ "$OMR_TRACKER_CHECK_QUALITY" = "1" ]; then
if [ "$OMR_TRACKER_PREV_STATUS" = "OK" ]; then
if [ -n "$OMR_TRACKER_LOSS" ] && [ "$OMR_TRACKER_LOSS" -ge "$OMR_TRACKER_LOSS_FAILURE" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG="Packet loss is $OMR_TRACKER_LOSS this is more than limit defined at $OMR_TRACKER_LOSS_FAILURE"
fi
if [ -n "$OMR_TRACKER_LATENCY" ] && [ "$OMR_TRACKER_LATENCY" -ge "$OMR_TRACKER_LATENCY_FAILURE" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG="Latency is $OMR_TRACKER_LATENCY this is more than limit defined at $OMR_TRACKER_LATENCY_FAILURE"
fi
elif [ "$OMR_TRACKER_PREV_STATUS" = "ERROR" ]; then
OMR_TRACKER_STATUS="ERROR"
if [ -n "$OMR_TRACKER_LOSS" ] && [ "$OMR_TRACKER_LOSS" -le "$OMR_TRACKER_LOSS_RECOVERY" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="OK"
fi
if [ -n "$OMR_TRACKER_LATENCY" ] && [ "$OMR_TRACKER_LATENCY" -ge "$OMR_TRACKER_LATENCY_RECOVERY" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="OK"
fi
fi
fi
#[ "$OMR_TRACKER_HOSTS" = "$initial_hosts" ] || [ "$OMR_TRACKER_STATUS" = "OK" ] && _post_tracking
#[ "$OMR_TRACKER_STATUS" = "ERROR" ] && _restart
@ -567,5 +607,9 @@ while true; do
OMR_TRACKER_PREV_STATUS="$OMR_TRACKER_STATUS"
_restart
sleep "$OMR_TRACKER_INTERVAL"
if [ "$OMR_TRACKER_STATUS" = "ERROR" ]; then
sleep "$OMR_TRACKER_FAILURE_INTERVAL"
else
sleep "$OMR_TRACKER_INTERVAL"
fi
done

View file

@ -1,32 +1,38 @@
config defaults 'defaults'
option enabled '1'
list hosts '4.2.2.1'
list hosts '8.8.8.8'
list hosts '80.67.169.12'
list hosts '8.8.4.4'
list hosts '9.9.9.9'
list hosts '1.0.0.1'
list hosts '114.114.115.115'
list hosts '1.2.4.8'
list hosts '80.67.169.40'
list hosts '114.114.114.114'
list hosts '1.1.1.1'
list hosts6 '2606:4700:4700::1111'
list hosts6 '2606:4700:4700::1001'
list hosts6 '2620:fe::fe'
list hosts6 '2620:fe::9'
list hosts6 '2001:4860:4860::8888'
list hosts6 '2001:4860:4860::8844'
option timeout '2'
option count '2'
option tries '3'
option interval '2'
option interval_tries '1'
option type 'ping'
option wait_test '0'
option server_http_test '0'
option restart_down '0'
option mail_alert '0'
list hosts '4.2.2.1'
list hosts '8.8.8.8'
list hosts '80.67.169.12'
list hosts '8.8.4.4'
list hosts '9.9.9.9'
list hosts '1.0.0.1'
list hosts '114.114.115.115'
list hosts '1.2.4.8'
list hosts '80.67.169.40'
list hosts '114.114.114.114'
list hosts '1.1.1.1'
list hosts6 '2606:4700:4700::1111'
list hosts6 '2606:4700:4700::1001'
list hosts6 '2620:fe::fe'
list hosts6 '2620:fe::9'
list hosts6 '2001:4860:4860::8888'
list hosts6 '2001:4860:4860::8844'
option timeout '2'
option count '2'
option tries '3'
option interval '2'
option interval_tries '1'
option type 'ping'
option wait_test '0'
option server_http_test '0'
option restart_down '0'
option mail_alert '0'
option initial_state 'online'
option family 'ipv4'
option reliability '1'
option count '2'
option failure_interval '5'
option tries_up '5'
config proxy 'proxy'
option enabled '1'
@ -43,6 +49,8 @@ config proxy 'proxy'
option interval_tries '1'
option interval '10'
option mail_alert '0'
option initial_state 'online'
option family 'ipv4ipv6'
config server 'server'
option enabled '1'
@ -51,3 +59,4 @@ config server 'server'
option wait_test '0'
option interval '5'
option mail_alert '0'
option initial_state 'online'

View file

@ -16,34 +16,54 @@
. /lib/functions/network.sh
_validate_section() {
local tmp_hosts=$hosts tmp_hosts6=$hosts6 tmp_timeout=$timeout tmp_count=$count tmp_tries=$tries
local tmp_interval=$interval tmp_interval_tries=$interval_tries tmp_options=$options tmp_type=$type tmp_enabled=$enabled tmp_wait_test=$wait_test tmp_server_http_test=$server_http_test
local tmp_hosts=$hosts tmp_hosts6=$hosts6 tmp_timeout=$timeout tmp_count=$count tmp_tries=$tries tmp_size=$size tmp_max_ttl=$max_ttl tmp_failure_loss=$failure_loss tmp_failure_latency=$failure_latency tmp_recovery_loss=$recovery_loss tmp_recovery_latency=$recovery_latency
local tmp_interval=$interval tmp_interval_tries=$interval_tries tmp_options=$options tmp_type=$type tmp_enabled=$enabled tmp_wait_test=$wait_test tmp_server_http_test=$server_http_test tmp_check_quality=$check_quality tmp_failure_interval=$failure_interval tmp_tries_up=$tries_up tmp_family=$family
uci_validate_section omr-tracker "$1" "$2" \
'hosts:list(host)' \
'hosts6:list(host)' \
'timeout:uinteger' \
'size:uinteger' \
'max_ttl:uinteger' \
'failure_loss:uinteger' \
'failure_latency:uinteger' \
'recovery_loss:uinteger' \
'recovery_latency:uinteger' \
'check_quality:bool:0' \
'count:uinteger' \
'tries:uinteger' \
'tries_up:uinteger' \
'interval:uinteger' \
'interval_tries:uinteger' \
'failure_interval:uinteger' \
'wait_test:uinteger' \
'type:string:undef' \
'enabled:bool:1' \
'server_http_test:bool:0' \
'family:string' \
'options:string'
[ -z "$hosts" ] && hosts=$tmp_hosts
[ -z "$hosts6" ] && hosts6=$tmp_hosts6
[ -z "$timeout" ] && timeout=$tmp_timeout
[ -z "$count" ] && count=$tmp_count
[ -z "$size" ] && size=$tmp_size
[ -z "$failure_loss" ] && failure_loss=$tmp_failure_loss
[ -z "$failure_latency" ] && failure_latency=$tmp_failure_latency
[ -z "$failure_interval" ] && failure_interval=$tmp_failure_interval
[ -z "$recovery_loss" ] && recovery_loss=$tmp_recovery_loss
[ -z "$recovery_latency" ] && recovery_latency=$tmp_recovery_latency
[ -z "$check_quality" ] && check_quality=$tmp_check_quality
[ -z "$max_ttl" ] && max_ttl=$tmp_max_ttl
[ -z "$tries" ] && tries=$tmp_tries
[ -z "$tries_up" ] && tries_up=$tmp_tries_up
[ -z "$interval" ] && interval=$tmp_interval
[ -z "$interval_tries" ] && interval_tries=$tmp_interval_tries
[ -z "$wait_test" ] && wait_test=$tmp_wait_test
[ -z "$options" ] && options=$tmp_options
[ "$type" = "undef" ] && type=${tmp_type:-ping}
[ -z "$server_http_test" ] && server_http_test=$tmp_server_http_test
[ -z "$family" ] && family=$tmp_family
[ -z "$enabled" ] && enabled=$tmp_enabled
}
@ -52,7 +72,7 @@ _launch_tracker() {
loopback|lan*|if0*) return;;
esac
[ -z "$1" ] && return
local hosts hosts6 timeout count tries interval interval_tries options type enabled wait_test ipv6 proto server_http_test
local hosts hosts6 timeout count tries tries_up interval interval_tries options type enabled wait_test ipv6 proto server_http_test size max_ttl failure_loss failure_interval failure_latency recovery_loss recovery_latency family
_validate_section "defaults" "defaults"
_validate_section "interface" "$1"
@ -80,6 +100,11 @@ _launch_tracker() {
#[ "${ifstatus}" = "false" ] && [ -z "${ifdevice}" ] && return
[ -z "${interval_tries}" ] && interval_tries=1
[ -z "${count}" ] && count=2
[ -z "${max_ttl}" ] && max_ttl=60
[ -z "${size}" ] && size=56
[ -z "${check_quality}" ] && check_quality=0
[ -z "${tries}" ] && tries=5
[ -z "${tries_up}" ] && tries_up=${tries}
procd_open_instance
# shellcheck disable=SC2086
@ -87,14 +112,24 @@ _launch_tracker() {
procd_append_param env "OMR_TRACKER_HOSTS=$hosts"
procd_append_param env "OMR_TRACKER_HOSTS6=$hosts6"
procd_append_param env "OMR_TRACKER_TIMEOUT=$timeout"
procd_append_param env "OMR_TRACKER_SIZE=$size"
procd_append_param env "OMR_TRACKER_CHECK_QUALITY=$check_quality"
procd_append_param env "OMR_TRACKER_MAX_TTL=$max_ttl"
procd_append_param env "OMR_TRACKER_FAILURE_LOSS=$failure_loss"
procd_append_param env "OMR_TRACKER_FAILURE_LATENCY=$failure_latency"
procd_append_param env "OMR_TRACKER_RECOVERY_LOSS=$recovery_loss"
procd_append_param env "OMR_TRACKER_RECOVERY_LATENCY=$recovery_latency"
procd_append_param env "OMR_TRACKER_COUNT=$count"
procd_append_param env "OMR_TRACKER_TRIES=$tries"
procd_append_param env "OMR_TRACKER_TRIES_UP=$tries_up"
procd_append_param env "OMR_TRACKER_INTERVAL=$interval"
procd_append_param env "OMR_TRACKER_FAILURE_INTERVAL=$failure_interval"
procd_append_param env "OMR_TRACKER_INTERVAL_TRIES=$interval_tries"
procd_append_param env "OMR_TRACKER_TABLE=$ip4table"
procd_append_param env "OMR_TRACKER_DEVICE=$ifname"
procd_append_param env "OMR_TRACKER_DEVICE_GATEWAY=$gateway"
procd_append_param env "OMR_TRACKER_TYPE=$type"
procd_append_param env "OMR_TRACKER_FAMILY=$family"
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"

View file

@ -106,4 +106,26 @@ if [ "$(uci -q get omr-tracker.defaults.server_http_test)" = "" ]; then
EOF
fi
if [ "$(uci -q get omr-tracker.defaults.family)" = "" ]; then
uci -q batch <<-EOF >/dev/null
set omr-tracker.defaults.initial_state='online'
set omr-tracker.defaults.family='ipv4ipv6'
set omr-tracker.defaults.reliability='1'
set omr-tracker.defaults.interval='1'
set omr-tracker.defaults.failure_interval='5'
set omr-tracker.defaults.count='1'
set omr-tracker.defaults.tries_up='5'
set omr-tracker.omrvpn.initial_state='online'
set omr-tracker.omrvpn.family='ipv4'
set omr-tracker.omrvpn.reliability='1'
set omr-tracker.omrvpn.failure_interval='5'
set omr-tracker.omrvpn.tries_up='5'
set omr-tracker.omrvpn.count='1'
set omr-tracker.proxy.initial_state='online'
set omr-tracker.proxy.family='ipv4ipv6'
set omr-tracker.server.initial_state='online'
commit omr-tracker
EOF
fi
exit 0