mwan3: Fix awk expression in mwan3_delete_iface_rules
authorMaxim Mikityanskiy <maxtram95@gmail.com>
Mon, 1 Apr 2024 22:01:48 +0000 (01:01 +0300)
committerMaxim Mikityanskiy <maxtram95@gmail.com>
Wed, 31 Jul 2024 17:27:28 +0000 (20:27 +0300)
The awk expression in mwan3_delete_iface_rules splits the `ip rule list`
output by spaces, therefore $1 contains the trailing colon (e.g., "1:",
"1000:"). The < and > operators compare such values as strings instead
of numbers, producing unexpected results (for example, "1:" > "1000").

Change the field separator to ":" for correct number comparison, so that
the right rules are removed.

An example error message that may appear before the fix:

Error: argument "1:" is wrong: preference value is invalid

It happens because `substr($1,0,4)` selects short numbers along with
the colon. In other cases wrong rules may be removed, for example, if
there is rule 10051, then rule 1005 will be removed.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
net/mwan3/Makefile
net/mwan3/files/lib/mwan3/mwan3.sh

index 3d4dd36a14fc412df5a62909a8529751608b37f6..9743edcb92e714dd25f17c399f595dc047742fc3 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=mwan3
 PKG_VERSION:=2.11.13
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>, \
                Aaron Goodman <aaronjg@alumni.stanford.edu>
 PKG_LICENSE:=GPL-2.0
index c69f381ea851345e5182e85cd741e0eacee8e3e0..475d1a07336a044dafd85024f777fd4d051998ba 100644 (file)
@@ -549,7 +549,7 @@ mwan3_delete_iface_rules()
                return
        fi
 
-       for rule_id in $(ip rule list | awk '$1 % 1000 == '$id' && $1 > 1000 && $1 < 4000 {print substr($1,0,4)}'); do
+       for rule_id in $(ip rule list | awk -F : '$1 % 1000 == '$id' && $1 > 1000 && $1 < 4000 {print $1}'); do
                $IP rule del pref $rule_id
        done
 }