mwan3: fix bug when one interface is a prefix of another
authorAaron Goodman <redacted>
Mon, 31 Aug 2020 19:51:25 +0000 (15:51 -0400)
committerAaron Goodman <redacted>
Fri, 16 Oct 2020 13:54:48 +0000 (09:54 -0400)
correctly terminate interface status checks with new lines so that
interface status does not get confused when one interface is a prefix
of another interface.

Signed-off-by: Aaron Goodman <redacted>
net/mwan3/files/lib/mwan3/mwan3.sh

index 7f5200d155772c54d54bde22a87cc7b26b6781e6..111fea0672d1822fc09a3b03d588538b8219810e 100644 (file)
@@ -361,7 +361,7 @@ mwan3_set_general_iptables()
        local IPT current update error
        for IPT in "$IPT4" "$IPT6"; do
                [ "$IPT" = "$IPT6" ] && [ $NO_IPV6 -ne 0 ] && continue
-               current="$($IPT -S)"
+               current="$($IPT -S)"$'\n'
                update="*mangle"
                if [ -n "${current##*-N mwan3_ifaces_in*}" ]; then
                        mwan3_push_update -N mwan3_ifaces_in
@@ -463,13 +463,14 @@ mwan3_create_iface_iptables()
        else
                return
        fi
-       current="$($IPT -S)"
+
+       current="$($IPT -S)"$'\n'
        update="*mangle"
        if [ -n "${current##*-N mwan3_ifaces_in*}" ]; then
                mwan3_push_update -N mwan3_ifaces_in
        fi
 
-       if [ -n "${current##*-N mwan3_iface_in_$1*}" ]; then
+       if [ -n "${current##*-N mwan3_iface_in_$1$'\n'*}" ]; then
                mwan3_push_update -N "mwan3_iface_in_$1"
        else
                mwan3_push_update -F "mwan3_iface_in_$1"
@@ -487,7 +488,7 @@ mwan3_create_iface_iptables()
                          -m comment --comment "$1" \
                          -j MARK --set-xmark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK"
 
-       if [ -n "${current##*-A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_${1}*}" ]; then
+       if [ -n "${current##*-A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_${1}$'\n'*}" ]; then
                mwan3_push_update -A mwan3_ifaces_in \
                                  -m mark --mark 0x0/$MMX_MASK \
                                  -j "mwan3_iface_in_$1"
@@ -705,7 +706,7 @@ mwan3_set_policy()
                IPT="$IPT6"
                IPTR="$IPT6R"
        fi
-       current="$($IPT -S)"
+       current="$($IPT -S)"$'\n'
        update="*mangle"
 
        if [ "$family" = "ipv4" ] && [ $is_offline -eq 0 ]; then
@@ -784,9 +785,9 @@ mwan3_create_policies_iptables()
 
        for IPT in "$IPT4" "$IPT6"; do
                [ "$IPT" = "$IPT6" ] && [ $NO_IPV6 -ne 0 ] && continue
-               current="$($IPT -S)"
+               current="$($IPT -S)"$'\n'
                update="*mangle"
-               if [ -n "${current##*-N mwan3_policy_$1*}" ]; then
+               if [ -n "${current##*-N mwan3_policy_$1$'\n'*}" ]; then
                        mwan3_push_update -N "mwan3_policy_$1"
                fi
 
@@ -844,7 +845,7 @@ mwan3_set_sticky_iptables()
                        mwan3_get_iface_id id "$1"
 
                        [ -n "$id" ] || return 0
-                       if [ -z "${current##*-N mwan3_iface_in_$1*}" ]; then
+                       if [ -z "${current##*-N mwan3_iface_in_$1$'\n'*}" ]; then
                                mwan3_push_update -I "mwan3_rule_$rule" \
                                                  -m mark --mark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" \
                                                  -m set ! --match-set "mwan3_sticky_$rule" src,src \
@@ -946,12 +947,12 @@ mwan3_set_user_iptables_rule()
                fi
        fi
 
-       if [ $rule_policy -eq 1 ] && [ -n "${current##*-N $policy*}" ]; then
+       if [ $rule_policy -eq 1 ] && [ -n "${current##*-N $policy$'\n'*}" ]; then
                mwan3_push_update -N "$policy"
        fi
 
        if [ $rule_policy -eq 1 ] && [ "$sticky" -eq 1 ]; then
-               if [ -n "${current##*-N mwan3_rule_$1*}" ]; then
+               if [ -n "${current##*-N mwan3_rule_$1$'\n'*}" ]; then
                        mwan3_push_update -N "mwan3_rule_$1"
                fi
 
@@ -1046,7 +1047,7 @@ mwan3_set_user_rules()
                fi
                [ "$ipv" = "ipv6" ] && [ $NO_IPV6 -ne 0 ] && continue
                update="*mangle"
-               current="$($IPT -S)"
+               current="$($IPT -S)"$'\n'
 
 
                if [ -n "${current##*-N mwan3_rules*}" ]; then
git clone https://git.99rst.org/PROJECT