Skip to content

Skeleton for stateful NAT #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 12, 2025
Merged

Skeleton for stateful NAT #560

merged 7 commits into from
Jun 12, 2025

Conversation

qmonnet
Copy link
Member

@qmonnet qmonnet commented Jun 6, 2025

Introduce a very simple skeleton for stateful NAT. There's nothing functional yet, this is just a very early skeleton for the logic. Committing this part first allows us to later create Pull Requests to focus on the more complex components (in particular, IP/port allocation and session management).

It turns out we don't share that much code with the stateless NAT portion of the pipeline stage; we may split stateless and stateful NAT into distinct pipeline stages in the future, this is yet to be determined (and doesn't matter much at this stage).

Follow-ups:

@qmonnet qmonnet added this to the GW R1 milestone Jun 6, 2025
@qmonnet qmonnet requested a review from mvachhar June 6, 2025 14:43
@qmonnet qmonnet requested a review from a team as a code owner June 6, 2025 14:43
@qmonnet qmonnet added the area/nat Related to Network Address Translation (NAT) label Jun 6, 2025
@daniel-noland daniel-noland self-requested a review June 7, 2025 02:12
Copy link
Collaborator

@daniel-noland daniel-noland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a really strong start. I propose we have a meeting at some point and sketch out some refinements before moving too much farther.

}

impl NatState {
fn new(net: &Net, pool: &allocator::NatPool) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we expecting to clone net and pool? I would expect these to be transferred in as owned

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's some detail I didn't pay too much attention to when drafting the skeleton, but you're absolutely correct. I'll change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait I replied too fast, why should they be passed as owned? They won't be part of the generated NatState, they'll just be used read-only to create the new state. So by reference should be the way to go? Otherwise, I've got to clone them before passing them to the NatState::new() method.

@qmonnet qmonnet force-pushed the pr/qmonnet/stateful-nat-skeleton branch 3 times, most recently from 6a64bf4 to eba3905 Compare June 10, 2025 11:19
@qmonnet qmonnet requested a review from daniel-noland June 10, 2025 11:20
qmonnet added 6 commits June 10, 2025 12:21
... In prevision for stateful NAT support.

Signed-off-by: Quentin Monnet <[email protected]>
Make room for stateful NAT: Move all the code dedicated to stateless NAT
into a dedicated file, in preparation for stateful NAT support.

Signed-off-by: Quentin Monnet <[email protected]>
It makes more sense to expose these headers directly as part of the Net
implementation, so that other components can reuse them.

Signed-off-by: Quentin Monnet <[email protected]>
Get started with stateful NAT. There's nothing functional yet, this is
just a very early skeleton for the logic. Committing this part first
allows us to later create Pull Requests to focus on the more complex
components (in particular, IP/port allocation and session management).

Signed-off-by: Quentin Monnet <[email protected]>
Having a trait for the NAT pool (that handles IP and port allocation)
makes it easier to try alternative implementations in the future.

Signed-off-by: Quentin Monnet <[email protected]>
Similarly to what we did for the NAT IP/port allocator, implement the
sesson manager as a trait so that we can quickly experiment with various
implementations in the future.

Signed-off-by: Quentin Monnet <[email protected]>
@qmonnet qmonnet force-pushed the pr/qmonnet/stateful-nat-skeleton branch from eba3905 to f5884fb Compare June 10, 2025 11:21
@qmonnet qmonnet self-assigned this Jun 10, 2025
Instead of using an IpAddr object, make the IP/port allocator and the
session manager use a sealed NatIp trait, to avoid multiple matches for
the exact IP version in the core of the NAT logics.

We need to pass two distinct types to the stateful_nat() function: one
is the type for the original IP address, the second one for the target
IP address.

Suggested-by: Daniel Noland <[email protected]>
Signed-off-by: Quentin Monnet <[email protected]>
@qmonnet
Copy link
Member Author

qmonnet commented Jun 11, 2025

@daniel-noland your feedback should have been addressed, can you please take another look? Are there some additional refinements you were talking about?

@qmonnet qmonnet dismissed daniel-noland’s stale review June 12, 2025 14:42

Feedback addressed, I think

@qmonnet qmonnet added this pull request to the merge queue Jun 12, 2025
Merged via the queue into main with commit 4b631ef Jun 12, 2025
13 checks passed
@qmonnet qmonnet deleted the pr/qmonnet/stateful-nat-skeleton branch June 12, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nat Related to Network Address Translation (NAT)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants