Sync iptables rules with an event-driven loop - #8215
Open
hongliangl wants to merge 1 commit into
Open
Conversation
hongliangl
force-pushed
the
unified-event-driven-iptables-sync
branch
3 times, most recently
from
July 28, 2026 03:29
3814b46 to
8e33873
Compare
iptables rules were managed with two different mechanisms: most features only updated their in-memory caches and waited for the 60s periodic sync to apply them with iptables-restore, while Egress installed and removed its SNAT rules directly with iptables -I / -D. The periodic sync rewrites the whole state from the caches, so it could overwrite a SNAT rule inserted after its snapshot of the caches was taken, leaving the traffic unSNATed until the next sync, up to 60s later. The iptables rules are now synced by a dedicated loop, which syncs when a feature notifies it that the caches have been updated, and when syncNetworkConfig notifies it on its period. Egress only updates the caches and notifies the loop instead of writing to the datapath itself, which removes the race without having to serialize its updates with the sync. The notification channel has a buffer of 1 and the loop waits for 100ms before syncing, so that updates occurring in quick succession are batched into a single call. Any feature updating the caches can now have its rules applied about 100ms later, instead of waiting for the next periodic sync. syncNetworkConfig notifies the loop after syncing the ipsets, keeping the existing ordering: iptables rules reference ipsets, and iptables-restore fails as a whole if one of them is missing. AddSNATRule and DeleteSNATRule become asynchronous: the rules are applied about 100ms after the calls return. snatRuleSpec is removed, as the SNAT rules are now only built by restoreIptablesData. Signed-off-by: Hongliang Liu <hongliang.liu@broadcom.com>
hongliangl
force-pushed
the
unified-event-driven-iptables-sync
branch
from
July 28, 2026 06:36
8e33873 to
be8e561
Compare
hongliangl
marked this pull request as ready for review
July 28, 2026 06:37
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.
iptables rules were managed with two different mechanisms: most features
only updated their in-memory caches and waited for the 60s periodic sync
to apply them with iptables-restore, while Egress installed and removed
its SNAT rules directly with iptables -I / -D. The periodic sync rewrites
the whole state from the caches, so it could overwrite a SNAT rule
inserted after its snapshot of the caches was taken, leaving the traffic
unSNATed until the next sync, up to 60s later.
The iptables rules are now synced by a dedicated loop, which syncs when a
feature notifies it that the caches have been updated, and when
syncNetworkConfig notifies it on its period. Egress only updates the
caches and notifies the loop instead of writing to the datapath itself,
which removes the race without having to serialize its updates with the
sync.
The notification channel has a buffer of 1 and the loop waits for 100ms
before syncing, so that updates occurring in quick succession are batched
into a single call. Any feature updating the caches can now have its
rules applied about 100ms later, instead of waiting for the next periodic
sync.
syncNetworkConfig notifies the loop after syncing the ipsets, keeping the
existing ordering: iptables rules reference ipsets, and iptables-restore
fails as a whole if one of them is missing.
AddSNATRule and DeleteSNATRule become asynchronous: the rules are applied
about 100ms after the calls return. snatRuleSpec is removed, as the SNAT
rules are now only built by restoreIptablesData.
Signed-off-by: Hongliang Liu hongliang.liu@broadcom.com