Skip to content

Sync iptables rules with an event-driven loop - #8215

Open
hongliangl wants to merge 1 commit into
antrea-io:mainfrom
hongliangl:unified-event-driven-iptables-sync
Open

Sync iptables rules with an event-driven loop#8215
hongliangl wants to merge 1 commit into
antrea-io:mainfrom
hongliangl:unified-event-driven-iptables-sync

Conversation

@hongliangl

@hongliangl hongliangl commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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
hongliangl force-pushed the unified-event-driven-iptables-sync branch 3 times, most recently from 3814b46 to 8e33873 Compare July 28, 2026 03:29
@hongliangl hongliangl changed the title Sync iptables and nftables rules with event-driven loops Sync Egress SNAT rules with an event-driven iptables loop Jul 28, 2026
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 hongliangl changed the title Sync Egress SNAT rules with an event-driven iptables loop Sync iptables and nftables rules with event-driven loops Jul 28, 2026
@hongliangl
hongliangl force-pushed the unified-event-driven-iptables-sync branch from 8e33873 to be8e561 Compare July 28, 2026 06:36
@hongliangl hongliangl changed the title Sync iptables and nftables rules with event-driven loops Sync iptables rules with an event-driven loop Jul 28, 2026
@hongliangl
hongliangl marked this pull request as ready for review July 28, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant