Skip to content

Commit b7bbc15

Browse files
Merge pull request #3466 from balena-os/mtoman/shared-remove-duplicate-rules
NetworkManager: remove duplicate rules in shared dispatcher script
2 parents 359a462 + 90093d5 commit b7bbc15

File tree

1 file changed

+14
-4
lines changed
  • meta-balena-common/recipes-connectivity/networkmanager/balena-files

1 file changed

+14
-4
lines changed

meta-balena-common/recipes-connectivity/networkmanager/balena-files/90shared

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,21 @@ then
5858
exit 0
5959
fi
6060

61-
# Safeguard, this should never happen
62-
# Exactly 0 or 1 rule should match, bail out if there are more & investigate
63-
if [ "$(echo "${FW_RULE_ARGS}" | wc -l)" -gt 1 ]
61+
# Sometimes on NetworkManager restart a new rule is added
62+
# but the old one is not properly cleand up
63+
# Remove the duplicates here as the rules are all the same
64+
DUPS=0
65+
while [ "$(echo "${FW_RULE_ARGS}" | wc -l)" -gt 1 ]
66+
do
67+
DUPS=$(("${DUPS}" + 1))
68+
FIRST_FW_RULE_ARGS="$(echo "${FW_RULE_ARGS}" | head -n 1)"
69+
${IPTABLES} -D ${FIRST_FW_RULE_ARGS#-A }
70+
FW_RULE_ARGS=$(${IPTABLES} -S FORWARD | grep "sh-fw-${IFNAME}" | grep "${FW_RULE_COMMENT}")
71+
done
72+
73+
if [ "${DUPS}" -gt 0 ]
6474
then
65-
fail "More than one rule matched when looking for '${FW_RULE_COMMENT}', bailing out"
75+
info "Removed ${DUPS} duplicate '${FW_RULE_COMMENT}' rules"
6676
fi
6777

6878
# If the rule is already last, this will do nothing

0 commit comments

Comments
 (0)