mwan3: Error when running "mwan3 policies"
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 4.6k
- Forks
- 4k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 134
Description
Maintainer: @feckert
Environment: OpenWrt 23.05.3 r23809-234f1a2efa on a Linksys WRT3200ACM with ARMv7 Processor rev 1 (v7l)
Description:
Heya,
I've run into an issue where calling mwan3 policies errors with an arithmetic syntax error:
root@OpenWrt:~# mwan3 policies
Current ipv4 policies:
twan_wan:
/usr/sbin/mwan3: line 1150: arithmetic syntax error
After some debugging, I found out that I've accidentally set up two members with the same configuration, and used them in the same policy:
twan6_m1_w3 had the wrong interface selected (should've been twan6, not twan)
This created an extra iptables entry:
root@OpenWrt:~# iptables -t mangle -w -S "mwan3_policy_twan_wan"
-N mwan3_policy_twan_wan
-A mwan3_policy_twan_wan -m mark --mark 0x0/0x3f00 -m statistic --mode random --probability 0.50000000000 -m comment --comment "twan 3 6" -j MARK --set-xmark 0x300/0x3f00
-A mwan3_policy_twan_wan -m mark --mark 0x0/0x3f00 -m comment --comment "twan 3 3" -j MARK --set-xmark 0x300/0x3f00
Which made the percentage calculation on L1150 fail because this command: https://github.com/openwrt/packages/blob/openwrt-22.03/net/mwan3/files/lib/mwan3/mwan3.sh#L1149 returned two numbers separated by a newline:
root@OpenWrt:~# iptables -t mangle -w -S "mwan3_policy_twan_wan" | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '$1 == "'twan'"' | awk '{print $2}'
3
3
After fixing the root cause, mwan3 policies works as expected and the output of the two commands above are also clean:
root@OpenWrt:~# iptables -t mangle -w -S "mwan3_policy_twan_wan"
-N mwan3_policy_twan_wan
-A mwan3_policy_twan_wan -m mark --mark 0x0/0x3f00 -m comment --comment "twan 3 3" -j MARK --set-xmark 0x300/0x3f00
root@OpenWrt:~# iptables -t mangle -w -S "mwan3_policy_twan_wan" | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '$1 == "'twan'"' | awk '{print $2}'
3
While this was ultimately a configuration issue on my side, I thought I'd report it because this extra entry might also be created by other means.
Cheers and Ty,
David
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/mwan3/mwan3.sh around lines 1149-1150 and reproduce the failure with the reported mwan3 policies command. Inspect how the iptables output is parsed when duplicate member entries return multiple values. Done means policy listing no longer produces an arithmetic syntax error for that case and still works with the normal single-entry output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100