Skip to content

Commit

Permalink
Merge pull request #3466 from balena-os/mtoman/shared-remove-duplicat…
Browse files Browse the repository at this point in the history
…e-rules

NetworkManager: remove duplicate rules in shared dispatcher script
  • Loading branch information
flowzone-app[bot] authored Jul 19, 2024
2 parents 359a462 + 90093d5 commit b7bbc15
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ then
exit 0
fi

# Safeguard, this should never happen
# Exactly 0 or 1 rule should match, bail out if there are more & investigate
if [ "$(echo "${FW_RULE_ARGS}" | wc -l)" -gt 1 ]
# Sometimes on NetworkManager restart a new rule is added
# but the old one is not properly cleand up
# Remove the duplicates here as the rules are all the same
DUPS=0
while [ "$(echo "${FW_RULE_ARGS}" | wc -l)" -gt 1 ]
do
DUPS=$(("${DUPS}" + 1))
FIRST_FW_RULE_ARGS="$(echo "${FW_RULE_ARGS}" | head -n 1)"
${IPTABLES} -D ${FIRST_FW_RULE_ARGS#-A }
FW_RULE_ARGS=$(${IPTABLES} -S FORWARD | grep "sh-fw-${IFNAME}" | grep "${FW_RULE_COMMENT}")
done

if [ "${DUPS}" -gt 0 ]
then
fail "More than one rule matched when looking for '${FW_RULE_COMMENT}', bailing out"
info "Removed ${DUPS} duplicate '${FW_RULE_COMMENT}' rules"
fi

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

0 comments on commit b7bbc15

Please sign in to comment.