Mwan3: mwan3.user does not handle the disconnected action

Hey,
cant find any solution for my configuration problem.
WAN_A = QMI Cellular Interface
WAN_B = LAN Interface with IPv4 to Modem

Both WAN connections are configured in luci and are visible in the XYZ file:
grep "interface" /etc/config/mwan3

config interface 'wan4g_o2'
config interface 'lan_2_lan'
        option interface 'wan4g_o2'
        option interface 'lan_2_lan'

mwan3 detects a fault, but treatment like defined in mwan3.user does not take place.

vi /etc/mwan3.user

#!/bin/sh
# RESTART if INTERFACE  WAN_A  is detected as DOWN in mwan3;
if [ "${ACTION}" = "disconnected" ] && [ "${INTERFACE}" = "wan4g_o2" ] ; then
	/bin/sleep 10
	ifdown /dev/cdc-wdm0
	/bin/sleep 20
	ifup /dev/cdc-wdm0
	/bin/sleep 150
fi

Stop && restarting by hand in luci solved the problem.

Could you support me?

Mwan3 uses hotplug events.

https://openwrt.org/docs/guide-user/base-system/hotplug#iface

Iface doesn't have the action of disconnected, try ifdown.

You could also echo the variables in your script to a file so you can see what's in action when your issue occurs.

"disconnected" is a special environment variable, set by mwan3, before executing mwan3.user. Nothing to do with hotplug event.

1 Like

Insert some "debug" statements, to dump environment variables to system log. Just for verification purposes.
Anyway, I had similar effect to yours myself. Issue was, that the script is executed within context of mwan3 itself. Which created problems: Sending mwan3 to sleep :-). Solution was, simply to start another detached process (shell script), doing the work. In your case, edit mwan3.user only to contain the line "/etc/myscript.sh &"
and /etc/myscript.sh then contains your
/bin/sleep 10
ifdown /dev/cdc-wdm0
/bin/sleep 20
ifup /dev/cdc-wdm0
/bin/sleep 150

1 Like

In case, your issue is fixed now, please flag it as "solved"

Hey @reinerotto,
sry your solution do not fix my problem at all.

I have two devices of the same router. Both have the same problem with the interface and mwan3.

root@gw001x:~# uptime
17:40:20 up 7 days, 12:21, load average: 0.08, 0.08, 0.02
root@gw001x:~#
root@gw001x:~#
root@gw001x:~#
root@gw001x:~# dmesg | tail
[ 42.738571] Switch: port 9(phy0-ap3) entered disabled state
[ 42.829401] Switch: port 9(phy0-ap3) entered blocking state
[ 42.835086] Switch: port 9(phy0-ap3) entered disabled state
[ 42.840911] mt7603e 0000:01:00.0 phy0-ap3: entered allmulticast mode
[ 42.848463] mt7603e 0000:01:00.0 phy0-ap3: entered promiscuous mode
[ 42.855673] Switch: port 9(phy0-ap3) entered blocking state
[ 42.861479] Switch: port 9(phy0-ap3) entered forwarding state
[ 42.950160] Switch: port 9(phy0-ap3) entered disabled state
[ 43.120373] Switch: port 9(phy0-ap3) entered blocking state
[ 43.126002] Switch: port 9(phy0-ap3) entered forwarding state
root@gw001x:~#
root@gw001x:~#
root@gw001x:~#
root@gw001x:~#
root@gw001x:~# qmicli -d /dev/cdc-wdm0 --wds-get-packet-service-status
[/dev/cdc-wdm0] Connection status: 'connected'
root@gw001x:~#
root@gw001x:~#
root@gw001x:~#
root@gw001x:~# ping google.de
PING google.de (142.250.186.35): 56 data bytes
64 bytes from 142.250.186.35: seq=0 ttl=117 time=17.828 ms
64 bytes from 142.250.186.35: seq=1 ttl=117 time=29.176 ms
64 bytes from 142.250.186.35: seq=2 ttl=117 time=36.808 ms
^C
--- google.de ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 17.828/27.937/36.808 ms
root@gw001x:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default WANGATEWAYIP 0.0.0.0 UG 1 0 0 wwan0
10.20.0.0 * 255.254.0.0 U 2 0 0 wan
LTEWANIP * 255.255.255.224 U 1 0 0 wwan0
172.30.20.0 * 255.255.255.0 U 0 0 0 Switch.20
172.30.30.0 * 255.255.255.0 U 0 0 0 Switch.30
192.168.1.0 * 255.255.255.0 U 0 0 0 Switch.1
195.90.221.36 WANGATEWAYIP 255.255.255.255 UGH 1 0 0 wwan0
195.90.223.26 WANGATEWAYIP 255.255.255.255 UGH 1 0 0 wwan0

root@gw001x:~# mwan3 interfaces
Interface status:
interface wan4g_o2 is offline and tracking is active (16)
interface lan_2_lan is offline and tracking is active (16)

root@gw001x:~#

Just stop and start in the WEBGui luci can solve the connection problem.

or

root@gw001x:~# mwan3 stop wan4g_o2
root@gw001x:~# mwan3 start wan4g_o2

I think, that there es a miss configuration in mwan3.

This is my mwan3 config:

root@gw001x:~# cat /etc/config/mwan3

config globals 'globals'
option mmx_mask '0x3F00'

config rule 'default_rule_v4'
option dest_ip '0.0.0.0/0'
option use_policy 'wan4g_to_wan'
option family 'ipv4'
option proto 'all'
option sticky '1'
option timeout '100'

config rule 'default_rule_v6'
option dest_ip '::/0'
option use_policy 'wan4g_to_wan'
option family 'ipv6'
option proto 'all'
option sticky '1'
option timeout '100'

config interface 'wan4g_o2'
option enabled '1'
option initial_state 'offline'
option family 'ipv4'
list track_ip '1.0.0.1'
list track_ip '1.1.1.1'
list track_ip '8.8.4.4'
list track_ip '8.8.8.8'
list track_ip '1.0.0.2'
list track_ip '1.1.1.2'
list track_ip '149.112.112.112'
list track_ip '9.9.9.9'
list track_ip '1.0.0.3'
list track_ip '1.1.1.3'
list track_ip '208.67.220.220'
list track_ip '208.67.222.222'
list track_ip '84.200.70.40'
list track_ip '84.200.69.80'
option track_method 'ping'
option reliability '3'
option count '2'
option size '56'
option max_ttl '60'
option check_quality '0'
option timeout '4'
option interval '30'
option failure_interval '5'
option recovery_interval '10'
option down '5'
option up '5'
list flush_conntrack 'ifup'

config interface 'lan_2_lan'
option enabled '1'
option initial_state 'offline'
option family 'ipv4'
option track_method 'ping'
option reliability '3'
option count '2'
option size '56'
option max_ttl '60'
option timeout '3'
option interval '30'
option failure_interval '5'
option recovery_interval '10'
option down '5'
option up '5'
list track_ip '1.0.0.1'
list track_ip '1.1.1.1'
list track_ip '8.8.4.4'
list track_ip '8.8.8.8'
list track_ip '1.0.0.2'
list track_ip '1.1.1.2'
list track_ip '149.112.112.112'
list track_ip '9.9.9.9'
list track_ip '1.0.0.3'
list track_ip '1.1.1.3'
list track_ip '208.67.220.220'
list track_ip '208.67.222.222'
list track_ip '84.200.70.40'
list track_ip '84.200.69.80'

config member 'wan4g_m1_w3'
option interface 'wan4g_o2'
option metric '1'
option weight '3'

config member 'wan_m2_w3'
option interface 'lan_2_lan'
option metric '2'
option weight '3'

config policy 'wan4g_to_wan'
list use_member 'wan4g_m1_w3'
list use_member 'wan_m2_w3'
option last_resort 'unreachable'

root@gw001x:~#

First of all, I am shure, you need my fix to get the functionality, you are looking at. But this can only work, in case mwan3 properly started before, which seems not to be done automatically for you. Thus, please provide system log, from boot until/including your luci activity. But before doing this, you might dirty tricks: Disable auto-start of mwan3, and start it by hand, when boot completed. When this works, instead of manual start of mwan3 (mwan3 autostart still disabled), edit /etc/rc.local and start mwan3 from there (/etc/init.d/mwan3 start) Does this help ? Unfortunately, there are possible race conditions when starting services (mwan3, network) and setting up slow interfaces (LTE) . General flaw of the non-sequential startup sequence of all the services.

Hi @reinerotto, your ideas didn't solve the problem.
I tested everything the last days, great thanks.
I deactivate the autostart and start the service 60 seconds after the boot process. I could not find any delay start in mwan3. Am I right?
I have tested my configuration with different versions of OpenWRT (SNAPSHOT / 24.10.0 / 23.05.05). Same error everytime.

I think the error comes from a misconfiguration.

I have also found further entries on my error here.

https://github.com/openwrt/packages/issues/16817
But no solution anywhere...

Can you please provide your mwan3 configuration?

I use the OpenWRT Firmware Selector with this settings:
{removed pkgs}
odhcp6c odhcpd-ipv6only ppp ppp-mod-pppoe

In the country where I live, providers still only use ipv4 via LTE!

{optional pkgs for LTE via QMI}
luci-proto-qmi kmod-usb-net-qmi-wwan uqmi

UPDATE: 3 p.m.
The OpenWRT Firmware Selector has the following errors when installing these two PKGs.
{optional pkgs for wman3}
luci-mwan3 iptables-nft

Signature check passed.
Collected errors:
 * opkg_install_cmd: Cannot install package luci-mwan3.

Sorry, can't provide my config, because heavily customized for a commercial app, built from source without LuCI, 3 interfaces for failback (wan,wwan,wifiwan) , openwrt 22.04.4, no openwrt-firewall ...
I suggest you drastically simplify your mwan3-config to minimal settings/options, to provide failover, to begin testing with.
And your mwan3.user ONLY to contain some log messages, to dump environment variables to be available via logread.
In case, this minimal setup still does not work, pls provide system log, with mwan3.user log messages.