Browse Source

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>
lilik-openwrt-22.03
Florian Eckert 8 years ago
parent
commit
b216fd3642
3 changed files with 34 additions and 0 deletions
  1. +1
    -0
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  2. +17
    -0
      net/mwan3/files/lib/mwan3/mwan3.sh
  3. +16
    -0
      net/mwan3/files/usr/sbin/mwan3track

+ 1
- 0
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 View File

@ -64,6 +64,7 @@ case "$ACTION" in
mwan3_delete_iface_iptables $INTERFACE
mwan3_delete_iface_route $INTERFACE
mwan3_delete_iface_ipset_entries $INTERFACE
mwan3_track_signal $INTERFACE $DEVICE
mwan3_set_policies_iptables
mwan3_set_user_rules
mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"


+ 17
- 0
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -399,6 +399,23 @@ mwan3_track()
fi
}
mwan3_track_signal()
{
local pid status
if [ -f "/var/run/mwan3track-${1}.pid" ]; then
pid="$(cat "/var/run/mwan3track-${1}.pid")"
status="$(pgrep -f mwan3track | grep "${pid}")"
if [ "${status}" != "" ]; then
kill -USR1 "${pid}"
else
$LOG warn "Unable to send signal USR1 to mwan3track on interface $1 with pid ${pid}"
fi
else
$LOG warn "Unable to find \"/var/run/mwan3track-${1}.pid\" file for mwan3track on interface $1"
fi
}
mwan3_set_policy()
{
local iface_count id iface family metric probability weight


+ 16
- 0
net/mwan3/files/usr/sbin/mwan3track 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
}


Loading…
Cancel
Save