fix(masquerade): fix flow genid for masqueraded flows - #1702
fix(masquerade): fix flow genid for masqueraded flows#1702Fredi-raspall wants to merge 4 commits into
Conversation
📝 WalkthroughWalkthroughMasquerade generation IDs now belong to ChangesMasquerade generation ID refactor
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes masqueraded-flow generation ID (genid) handling so flow genids track the main config generation, even when NAT peerings don’t change and the NAT allocator instance is reused.
Changes:
- Removes
genidfromMasqueradeConfigand passes genid separately through allocator update paths. - Stores/serves genid on
NatAllocator(withset_genid) and updates it even when the allocator is kept. - Updates flow genid comparisons to use
NatAllocator::genid()rather thanMasqueradeConfig::genid().
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| nat/src/test.rs | Updates test pipeline setup to the new MasqueradeConfig::new and update_nat_allocator(..., genid, ...) APIs. |
| nat/src/masquerade/test.rs | Adjusts masquerade tests for the new genid plumbing and allocator update signature. |
| nat/src/masquerade/nf.rs | Uses allocator-served genid when creating flow pairs (instead of deriving it from allocations). |
| nat/src/masquerade/flows.rs | Switches flow-vs-config generation checks to compare against allocator.genid(). |
| nat/src/masquerade/apalloc/test_alloc.rs | Updates allocator construction in tests to pass genid explicitly. |
| nat/src/masquerade/apalloc/port_alloc.rs | Removes per-allocation genid tracking from allocated port objects (now allocator-owned). |
| nat/src/masquerade/apalloc/mod.rs | Adds allocator-level genid storage and accessors; removes allocation-level genid setters/getters. |
| nat/src/masquerade/allocator_writer.rs | Changes config equality semantics (genid removed) and updates allocator update API to accept genid separately and advance it when reusing allocator. |
| mgmt/src/processor/proc.rs | Updates management-plane config application to pass genid into allocator updates separately from peerings config. |
| acl-filter/src/tests.rs | Updates integration tests to the new allocator update API. |
| // The generation the installed allocator serves | ||
| let genid = allocator.genid(); | ||
|
|
There was a problem hiding this comment.
That's fair and is precisely what the previous code granted. Will fix.
qmonnet
left a comment
There was a problem hiding this comment.
Looks good. Do we have a non-regression test (if not, could you maybe create one please?) to ensure that the genid gets incremented even when no allocators change on a config bump?
We were setting the flow genid from the genid of the allocator. That idea was not bad, but had an issue: a config change that would not change the masquerading peerings would not create a new NAT allocator. So, its genid will fall behind the genid of the config. Fix this by keeping the genid in the Masquerade NF instead and update it even if the allocator does not change so that it always represents the main config generation id. Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Add test that checks if the Masquerade NF genid is updated on config changes, whether the allocator is replaced or not. Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
6fcf157 to
410f47f
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
nat/src/masquerade/nf.rs (1)
429-464: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd replacement-allocator regression coverage.
check_masquerading_flowcallsset_genid_pair(current.genid())after successful re-reservation. Test a replacement allocator that accepts the existing allocation and assert that both flows use its generation ID.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@nat/src/masquerade/nf.rs` around lines 429 - 464, Add regression coverage for recheck_flow with a replacement allocator that accepts the existing allocation. Verify check_masquerading_flow successfully re-reserves the flow and that both paired flows have the replacement allocator’s generation ID via genid().Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@nat/src/masquerade/nf.rs`:
- Around line 429-464: Add regression coverage for recheck_flow with a
replacement allocator that accepts the existing allocation. Verify
check_masquerading_flow successfully re-reserves the flow and that both paired
flows have the replacement allocator’s generation ID via genid().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 237d9ce9-a154-4f60-a144-c8c85b8f6db7
📒 Files selected for processing (2)
nat/src/masquerade/nf.rsnat/src/masquerade/test.rs
We were setting the flow genid from the genid of the allocator. That idea was not bad, but had an issue: a config change that would not change the masquerading peerings would not create a new NAT allocator. So, its genid will fall behind the genid of the config. Fix this by keeping the genid in the Masquerade NF instead and update it even if the allocator does not change so that it always represents the main config generation id.
Fixes: https://github.com/githedgehog/internal/issues/463