Repository navigation
libnetwork/d/bridge: fix cleanup of 27.x iptables - #54129
Merged
thaJeztah merged 2 commits intoNov 4, 2026
Merged
Conversation
When the daemon started with the nftables backend after a release older than 28.0.1 had run with iptables, the iptables cleaner's DelNetwork left the per-bridge rules those releases put in filter-FORWARD: "-i docker0 ! -o docker0 -j ACCEPT" and the ICC rules. The iptables backend deleted them in setupNonInternalNetworkRules and setIcc, but only when adding a network's rules, and DelNetwork returned early for an internal network. Delete all the legacy per-bridge FORWARD rules in deleteLegacyFilterRules, which the iptables backend and the cleaner call for every network. With the iptables backend, setupIPTables deletes the legacy rules after calling setupNonInternalNetworkRules, which used to delete "-i docker0 ! -o docker0 -j ACCEPT" before adding the DOCKER-FORWARD rule that replaces it. Now, for a moment, both rules are present. Both accept outgoing packets from the bridge. Signed-off-by: Cory Snider <csnider@mirantis.com>
When the daemon started with the nftables backend after a release older
than 28.0.0 had run with iptables, NewCleaner deleted the jumps from
filter-FORWARD to DOCKER-FORWARD and DOCKER-ISOLATION-STAGE-1, then
removed Docker's chains. Those releases also jumped from FORWARD to the
filter table's DOCKER chain for each bridge ("-o docker0 -j DOCKER").
iptables refuses to delete a chain that a rule still jumps to, and
removeIPChains ignores the error. The cleaner's DelNetwork deleted the
per-bridge jump later, when the bridge driver restored the network, but
nothing tried to remove the chain again. The empty DOCKER chain
remained.
When the bridge driver has restored its networks and endpoints, call
the cleaner's new Done method, which removes the chains again.
Signed-off-by: Cory Snider <csnider@mirantis.com>
corhere
requested review from
akerouanton,
robmry,
thaJeztah and
vvoland
and
a balanced review from Copilot
November 4, 2026 17:29
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the legacy iptables cleanup changes.
No open issues 🎉
What changed in this PR
This PR improves the bridge driver’s cleanup of legacy iptables rules when switching to nftables, removing per-bridge rules and chains left by older daemon releases.
Changes:
- Centralizes legacy FORWARD-rule cleanup, including internal networks, while preserving outgoing acceptance during iptables setup.
- Adds a cleanup-completion hook to retry chain removal after networks and endpoints are restored.
- Adds IPv4/IPv6 cleaner tests and an integration test simulating a switch from the 27.x firewall layout.
| File | Description |
|---|---|
integration/network/bridge/bridge_linux_test.go |
Tests cleanup when switching from simulated 27.x rules to nftables. |
daemon/libnetwork/drivers/bridge/internal/nftabler/cleaner.go |
Finalizes cleanup before releasing the cleaner. |
daemon/libnetwork/drivers/bridge/internal/iptabler/network.go |
Consolidates legacy per-bridge rule deletion and covers internal networks. |
daemon/libnetwork/drivers/bridge/internal/iptabler/iptabler_test.go |
Tests legacy rule and chain removal for IPv4 and IPv6. |
daemon/libnetwork/drivers/bridge/internal/iptabler/cleaner.go |
Cleans internal-network rules and retries chain deletion after restoration. |
daemon/libnetwork/drivers/bridge/internal/firewaller/firewaller.go |
Adds the cleaner’s Done lifecycle method. |
daemon/libnetwork/drivers/bridge/bridge_store.go |
Invokes cleanup completion after restoring stored networks and endpoints. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the daemon starts with the nftables firewall backend after a release older than 28.0.1 ran with iptables, the iptables cleaner leaves behind the per-bridge ACCEPT and ICC rules that release put in filter-FORWARD. Delete them all as each network is restored, including internal networks.
With the iptables backend, the legacy
-i <bridge> ! -o <bridge> -j ACCEPTrule is now deleted after theDOCKER-FORWARDrule that replaces it is added. For a moment, both are present, and both accept outgoing packets from the bridge.Releases older than 28.0.0 also jumped from filter-FORWARD to the filter table's
DOCKERchain for each bridge. The cleaner can't remove the chain at startup while those jumps exist, and the empty chain remains. Remove Docker's chains again once the bridge driver has restored its networks.Release notes (optional)
Created with: Claude Code