Redundant calls for mwan3.user script

Hi, I've been playing around with mwan3.user script and also learned about the hotplug scripts for handling different events. Eventually I've written log scripts for both mwan3.user and the hotplug scripts like the below:

/etc/mwan3.user:

logger -t mwan3-action-script $(env)

/etc/hotplug.d/iface/00-logger:

logger -t hotplug-iface $(env)

/etc/hotplug.d/net/00-logger (and similar for the other folders in hotplud.d):

logger -t hotplug-net $(env)

The current versions I have are the following:

  • OpenWrt: "OpenWrt 21.02.0 r16279-5cc0535800"
  • mwan3: mwan3 - 2.10.13-1

Then I ran ifdown followed by ifup on the interface and checked the output of logread:

ifdown:

Tue Nov  1 14:54:40 2022 daemon.notice netifd: Network device 'wanc' link is down
Tue Nov  1 14:54:40 2022 user.notice hotplug-iface: USER=root ACTION=ifdown SHLVL=1 HOME=/ HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= TERM=linux BOOT_IMAGE=/boot/vmlinuz PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/
Tue Nov  1 14:54:40 2022 user.notice hotplug-net: USER=root ACTION=remove SHLVL=1 HOME=/ SEQNUM=1831 IFINDEX=30 HOTPLUG_TYPE=net DEVPATH=/devices/virtual/net/wanc LOGNAME=root DEVICENAME=wanc TERM=linux SUBSYSTEM=net BOOT_IMAGE=/boot/vmlinuz PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVTYPE=wireguard
Tue Nov  1 14:54:40 2022 user.notice mwan3-hotplug[28958]: Execute ifdown event on interface wanc (unknown)
Tue Nov  1 14:54:40 2022 daemon.notice netifd: Interface 'wanc' is now down
Tue Nov  1 14:54:40 2022 user.notice ModemManager: hotplug: remove network interface wanc: event processed
Tue Nov  1 14:54:40 2022 user.notice ModemManager: hotplug: event reported: action=remove, name=wanc, subsystem=net
Tue Nov  1 14:54:40 2022 user.info mwan3track[5487]: Detect ifdown event on interface wanc (wanc)
Tue Nov  1 14:54:40 2022 user.notice mwan3track[5487]: Interface wanc (wanc) is offline
Tue Nov  1 14:54:40 2022 user.notice hotplug-iface: USER=root ACTION=disconnected SHLVL=1 HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:40 2022 user.notice mwan3-hotplug[29086]: Execute disconnected event on interface wanc (wanc)
Tue Nov  1 14:54:40 2022 user.notice mwan3-action-script: ACTION=ifdown SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=
Tue Nov  1 14:54:40 2022 user.notice mwan3-action-script: ACTION=disconnected SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=wanc

ifup:

Tue Nov  1 14:54:53 2022 daemon.notice netifd: Interface 'wanc' is setting up now
Tue Nov  1 14:54:53 2022 daemon.notice netifd: Interface 'wanc' is now up
Tue Nov  1 14:54:53 2022 daemon.notice netifd: Network device 'wanc' link is up
Tue Nov  1 14:54:53 2022 user.notice hotplug-iface: USER=root ACTION=ifup SHLVL=1 HOME=/ HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= TERM=linux BOOT_IMAGE=/boot/vmlinuz PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.notice hotplug-net: USER=root ACTION=add SHLVL=1 HOME=/ SEQNUM=1832 IFINDEX=31 HOTPLUG_TYPE=net DEVPATH=/devices/virtual/net/wanc LOGNAME=root DEVICENAME=wanc TERM=linux SUBSYSTEM=net BOOT_IMAGE=/boot/vmlinuz PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVTYPE=wireguard
Tue Nov  1 14:54:53 2022 user.notice ModemManager: hotplug: add network interface wanc: event processed
Tue Nov  1 14:54:53 2022 user.notice mwan3-hotplug[29741]: Execute ifup event on interface wanc (wanc)
Tue Nov  1 14:54:53 2022 user.notice ModemManager: hotplug: event reported: action=add, name=wanc, subsystem=net
Tue Nov  1 14:54:53 2022 user.notice ModemManager: hotplug: error: parent device sysfspath not found
Tue Nov  1 14:54:53 2022 user.info mwan3track[5487]: Detect ifup event on interface wanc (wanc)
Tue Nov  1 14:54:53 2022 user.notice mwan3-action-script: ACTION=ifup SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.notice firewall: Reloading firewall due to ifup of wanc (wanc)
Tue Nov  1 14:54:53 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.8.8" on interface wanc (wanc). Current score: 0
Tue Nov  1 14:54:53 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.4.4" on interface wanc (wanc). Current score: 0
Tue Nov  1 14:54:53 2022 user.notice mwan3track[5487]: Interface wanc (wanc) is connecting
Tue Nov  1 14:54:53 2022 user.notice hotplug-iface: USER=root ACTION=connecting SHLVL=1 HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.notice mwan3-action-script: ACTION=connecting SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.notice mwan3track[5487]: Interface wanc (wanc) is online
Tue Nov  1 14:54:53 2022 user.notice hotplug-iface: USER=root ACTION=connected SHLVL=1 FIRSTCONNECT=1 HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.notice mwan3-action-script: ACTION=connected SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.8.8" on interface wanc (wanc). Current score: 1
Tue Nov  1 14:54:53 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.4.4" on interface wanc (wanc). Current score: 1
Tue Nov  1 14:54:53 2022 user.notice mwan3track[5487]: Interface wanc (wanc) is connecting
Tue Nov  1 14:54:53 2022 user.notice hotplug-iface: USER=root ACTION=connecting SHLVL=1 HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:53 2022 user.notice mwan3-action-script: ACTION=connecting SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:58 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.8.8" on interface wanc (wanc). Current score: 2
Tue Nov  1 14:54:58 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.4.4" on interface wanc (wanc). Current score: 2
Tue Nov  1 14:54:58 2022 user.notice mwan3track[5487]: Interface wanc (wanc) is online
Tue Nov  1 14:54:58 2022 user.notice hotplug-iface: USER=root ACTION=connected SHLVL=1 FIRSTCONNECT= HOTPLUG_TYPE=iface LOGNAME=root DEVICENAME= PATH=/usr/sbin:/usr/bin:/sbin:/bin INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:54:58 2022 user.notice mwan3-hotplug[30579]: Execute connected event on interface wanc (wanc)
Tue Nov  1 14:54:59 2022 user.notice mwan3-action-script: ACTION=connected SHLVL=1 INTERFACE=wanc PWD=/ DEVICE=wanc
Tue Nov  1 14:55:04 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.8.8" on interface wanc (wanc). Current score: 3
Tue Nov  1 14:55:04 2022 user.info mwan3track[5487]: Check (ping) success for target "8.8.4.4" on interface wanc (wanc). Current score: 3

I found something confusing for me in the logs of ifup, the mwan3.user script was called twice for each of the actions connecting and connected. To me it appears that as if the first call was redundant/unnecessary as the logic within mwan3 wouldn't have kicked in yet. Looking at the iface hotplug logger output, there is a difference with the variable FIRSTCONNECT, the first time the event is fired it is set to 1 while the second time the same event is fired it is unset. Shouldn't the mwan3 hotplug /etc/hotplug.d/iface/16-mwan3-user take this into consideration and either pass the FIRSTCONNECT variable to mwan3.user script or not call mwan3.user script if FIRSTCONNECT=1?

Though the FIRSTCONNECT variable only appears to be useful for the action connected, there doesn't seem to be a way to differentiate between the duplicate events for connecting. :confused:

Personally I could handle duplicate connecting events being triggered, however duplicate connected could make my handling of the event complicated if there aren't any indication of the difference between them.

Appreciate your feedback and replies. Thanks!

After some thinking, it seems to me that I will be better off in making a hotplug script rather than implementing logic in mwan3.user script, since initially the mwan3.user script is actually run by a hotplug script.