From 5faa99f3b850c40669f231b45cca7bb7273c3083 Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Mon, 31 Aug 2020 15:51:25 -0400 Subject: [PATCH] mwan3: fix bug when one interface is a prefix of another 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 --- net/mwan3/files/lib/mwan3/mwan3.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 7f5200d155..111fea0672 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -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 -- 2.30.2