feat: Improve iptables rule cleanup (#86)

This commit is contained in:
Kroese
2026-07-12 21:59:05 +02:00
committed by GitHub
parent 20f1a4ab5d
commit 1719d6f76b
+9 -3
View File
@@ -576,7 +576,7 @@ clearTables() {
local table=""
local line=""
local rules=""
local args=()
local failed="N"
local rule_tag="remove"
local re="--comment[[:space:]]+\"?$rule_tag\"?([[:space:]]|\$)"
@@ -598,12 +598,18 @@ clearTables() {
esac
if [[ "$line" == -A* ]] && [[ "$line" =~ $re ]]; then
read -ra args <<< "${line/-A /-D }"
iptables -t "$table" "${args[@]}" > /dev/null 2>&1 || :
line="${line/-A /-D }"
# Parse the quoting produced by iptables-save before deleting the rule.
if ! printf '%s\n' "$line" |
xargs -r iptables -t "$table" > /dev/null 2>&1; then
failed="Y"
fi
fi
done <<< "$rules"
enabled "$failed" && return 1
return 0
}