Merge pull request #7191 from TDT-AG/pr/20181012-mwan3

mwan3: improvments
This commit is contained in:
Hannu Nyman 2018-10-12 16:29:03 +03:00 committed by GitHub
commit bb6f3564bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 8 deletions

View file

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3 PKG_NAME:=mwan3
PKG_VERSION:=2.7.3 PKG_VERSION:=2.7.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de> PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPLv2 PKG_LICENSE:=GPLv2

View file

@ -346,7 +346,7 @@ mwan3_delete_iface_iptables()
mwan3_create_iface_route() mwan3_create_iface_route()
{ {
local id route_args local id route_args metric
config_get family $1 family ipv4 config_get family $1 family ipv4
mwan3_get_iface_id id $1 mwan3_get_iface_id id $1
@ -366,6 +366,11 @@ mwan3_create_iface_route()
route_args="" route_args=""
fi fi
network_get_metric metric $1
if [ -n "$metric" -a "$metric" != "0" ]; then
route_args="$route_args metric $metric"
fi
$IP4 route flush table $id $IP4 route flush table $id
$IP4 route add table $id default $route_args dev $2 $IP4 route add table $id default $route_args dev $2
mwan3_rtmon_ipv4 mwan3_rtmon_ipv4
@ -384,6 +389,11 @@ mwan3_create_iface_route()
route_args="" route_args=""
fi fi
network_get_metric metric $1
if [ -n "$metric" -a "$metric" != "0" ]; then
route_args="$route_args metric $metric"
fi
$IP6 route flush table $id $IP6 route flush table $id
$IP6 route add table $id default $route_args dev $2 $IP6 route add table $id default $route_args dev $2
mwan3_rtmon_ipv6 mwan3_rtmon_ipv6

View file

@ -36,7 +36,9 @@ get_mwan3_status() {
local iface_select="${2}" local iface_select="${2}"
local running="0" local running="0"
local age=0 local age=0
local pid device time_p time_n local uptime=0
local downtime=0
local pid device time_p time_n time_u time_d
network_get_device device $1 network_get_device device $1
@ -52,8 +54,22 @@ get_mwan3_status() {
let age=time_n-time_p let age=time_n-time_p
} }
time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/UPTIME")"
[ -z "${time_u}" ] || [ "${time_u}" = "0" ] || {
time_n="$(get_uptime)"
let uptime=time_n-time_u
}
time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/DOWNTIME")"
[ -z "${time_d}" ] || [ "${time_d}" = "0" ] || {
time_n="$(get_uptime)"
let downtime=time_n-time_d
}
json_add_object "${iface}" json_add_object "${iface}"
json_add_int age "$age" json_add_int age "$age"
json_add_int uptime "${uptime}"
json_add_int downtime "${downtime}"
json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")" json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")"
json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")" json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")"
json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")" json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")"

View file

@ -43,7 +43,7 @@ ifdown()
ifup() ifup()
{ {
local device enabled up l3_device local device enabled up l3_device status
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' 0 config_get_bool enabled globals 'enabled' 0
@ -67,13 +67,18 @@ ifup()
exit 0 exit 0
} }
json_load $(ubus -S call network.interface.$1 status) status=$(ubus -S call network.interface.$1 status)
json_get_vars up l3_device [ -n "$status" ] && {
json_load $status
json_get_vars up l3_device
}
config_get enabled "$1" enabled 0 config_get enabled "$1" enabled 0
if [ "$up" -eq 1 ] \
if [ "$up" = "1" ] \
&& [ -n "$l3_device" ] \ && [ -n "$l3_device" ] \
&& [ "$enabled" -eq 1 ]; then && [ "$enabled" = "1" ]; then
ACTION=ifup INTERFACE=$1 DEVICE=$l3_device /sbin/hotplug-call iface ACTION=ifup INTERFACE=$1 DEVICE=$l3_device /sbin/hotplug-call iface
fi fi
} }

View file

@ -108,9 +108,13 @@ main() {
if [ "$STATUS" = "unknown" ]; then if [ "$STATUS" = "unknown" ]; then
echo "unknown" > /var/run/mwan3track/$1/STATUS echo "unknown" > /var/run/mwan3track/$1/STATUS
echo "0" > /var/run/mwan3track/$1/UPTIME
echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME
score=0 score=0
else else
echo "online" > /var/run/mwan3track/$1/STATUS echo "online" > /var/run/mwan3track/$1/STATUS
echo "0" > /var/run/mwan3track/$1/DOWNTIME
echo "$(get_uptime)" > /var/run/mwan3track/$1/UPTIME
env -i ACTION="connected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface env -i ACTION="connected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface
fi fi
while true; do while true; do
@ -199,6 +203,8 @@ main() {
if [ $score -eq $up ]; then if [ $score -eq $up ]; then
echo "offline" > /var/run/mwan3track/$1/STATUS echo "offline" > /var/run/mwan3track/$1/STATUS
echo "0" > /var/run/mwan3track/$1/UPTIME
echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME
$LOG notice "Interface $1 ($2) is offline" $LOG notice "Interface $1 ($2) is offline"
env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface
@ -240,6 +246,8 @@ main() {
if [ "${IFDOWN_EVENT}" -eq 1 ]; then if [ "${IFDOWN_EVENT}" -eq 1 ]; then
echo "offline" > /var/run/mwan3track/$1/STATUS echo "offline" > /var/run/mwan3track/$1/STATUS
echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME
echo "0" > /var/run/mwan3track/$1/UPTIME
$LOG notice "Interface $1 ($2) is offline" $LOG notice "Interface $1 ($2) is offline"
env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface
score=0 score=0