misc masquerade fixes - #1640
Conversation
Fredi-raspall
commented
Jul 17, 2026
- Contains logging improvements and clean-up in masquerading code
- Improves logic to admit / deny existing masquerading flows on reconfigs.
- remove unused error variant - polish logs to provide extra information - rename variables Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChangesMasquerade allocation now uses destination VPC discriminants consistently, reports missing pools distinctly, adjusts reservation logging, and validates both NAT coverage and source-IP inclusion when checking existing masquerading flows. Masquerade allocation and flow validation
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@nat/src/masquerade/flows.rs`:
- Around line 121-130: The masquerade flow-retention check in the peering
`valexp()` loop must honor negative ranges before retaining a flow. Update the
`nat.as_range` and `expose.ips()` matching logic to use the effective expose
matcher or otherwise reject IPs covered by `nat.not_as` and source IPs covered
by `expose.nots`, while preserving the existing positive-range requirements.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ab46ef3f-33cc-48f4-8fda-d389a5498a04
📒 Files selected for processing (6)
nat/src/masquerade/allocation.rsnat/src/masquerade/apalloc/display.rsnat/src/masquerade/apalloc/mod.rsnat/src/masquerade/apalloc/port_alloc.rsnat/src/masquerade/apalloc/test_alloc.rsnat/src/masquerade/flows.rs
There was a problem hiding this comment.
Pull request overview
This PR refines the NAT masquerade subsystem’s reconfiguration behavior and observability, focusing on clearer logging and more accurate validation of whether existing masqueraded flows remain admissible after config changes.
Changes:
- Adjust flow revalidation logic to require both the existing masquerade IP and the flow source IP to still be permitted by a matching expose during reconfig.
- Improve/standardize allocator and flow logging, and add a dedicated
NoPoolFoundallocator error for re-reserve paths. - Rename allocator pool table key field
dst_id→dst_vpcdfor clarity/consistency (including tests and display output).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| nat/src/masquerade/flows.rs | Tightens reconfig validation for existing masquerade flows and improves related logging. |
| nat/src/masquerade/apalloc/test_alloc.rs | Updates tests to match dst_vpcd field rename. |
| nat/src/masquerade/apalloc/port_alloc.rs | Minor logging tweak for explicit well-known port reservation denial. |
| nat/src/masquerade/apalloc/mod.rs | Renames pool key field; improves re-reserve behavior with NoPoolFound and warn-level logging. |
| nat/src/masquerade/apalloc/display.rs | Updates display output to match dst_vpcd rename. |
| nat/src/masquerade/allocation.rs | Adjusts error messages and introduces NoPoolFound mapped to DoneReason::Filtered. |
a5511d6 to
ea41ce1
Compare
| } | ||
| } | ||
|
|
||
| if compatible_expose_found { |
There was a problem hiding this comment.
Would be cleaner with early exit here instead:
if !alloced_ip_valid {
debug!("Flow is no longer valid for masquerading between {src_vpcd} -- {dst_vpcd}");
flow_info.invalidate_pair();
return;
}
if !compatible_expose_found {
debug!("Masquerade ip {ip} is no longer allowed over peering {src_vpcd} -- {dst_vpcd}");
flow_info.invalidate_pair();
return;
}Then less indent for the last block - the code would be less nested, the conditions easier to follow.
Rewrite the logic to admit a masqueraded flow after a config change. The prior logic checked if the masquerading address was still a valid one under the new configuration but did not check if the source of the flow was still allowed in the new configuration; a check that was indirectly made by the allocator. Make the restriction explicit, instead of relying on the allocator to do so. Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
ea41ce1 to
123b742
Compare