net/mwan3: registrate SIGUSR1 trap on interface down event

If interface is getting down by netifd (unplug ethernet cable)
mwan3track will not recognize this change. It will also generate an
additional down event when he notice does his tracking interface is offline.

Mwan3track will now be informed by a signal (trap) USR1 during down event
that the interface is already down. An additional down event will not be
generated.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert
2017-04-06 15:41:05 +02:00
parent 84df06e0dc
commit b216fd3642
3 changed files with 34 additions and 0 deletions
+16
View File
@@ -4,6 +4,9 @@
LOG="/usr/bin/logger -t $(basename "$0")[$$] -p"
INTERFACE=""
DEVICE=""
IFDOWN_EVENT=0
clean_up() {
$LOG notice "Stopping mwan3track for interface \"${INTERFACE}\""
@@ -15,6 +18,11 @@ clean_up() {
exit 0
}
if_down() {
$LOG info "Detect ifdown event on interface ${INTERFACE} (${DEVICE})"
IFDOWN_EVENT=1
}
main() {
local reliability count timeout interval failure_interval
local recovery_interval down up size
@@ -22,9 +30,11 @@ main() {
[ -z "$3" ] && echo "Error: should not be started manually" && exit 0
INTERFACE=$1
DEVICE=$2
echo "$$" > /var/run/mwan3track-$1.pid
mkdir -p /var/run/mwan3track/$1
trap clean_up SIGINT SIGTERM
trap if_down SIGUSR1
config_load mwan3
config_get reliability $1 reliability 1
@@ -106,6 +116,12 @@ main() {
host_up_count=0
sleep $sleep_time
if [ "${IFDOWN_EVENT}" -eq 1 ]; then
score=0
echo "offline" > /var/run/mwan3track/$1/STATUS
IFDOWN_EVENT=0
fi
done
}