Skip to content

NAT: Split stateful/stateless, move to own crate #635

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 4 commits into from
Jun 26, 2025

Conversation

qmonnet
Copy link
Member

@qmonnet qmonnet commented Jun 25, 2025

Please see individual commit descriptions for details.

@qmonnet qmonnet added this to the GW R1 milestone Jun 25, 2025
@qmonnet qmonnet self-assigned this Jun 25, 2025
@qmonnet qmonnet requested a review from a team as a code owner June 25, 2025 17:20
@qmonnet qmonnet added the area/nat Related to Network Address Translation (NAT) label Jun 25, 2025
@qmonnet qmonnet force-pushed the pr/qmonnet/refactor-nat branch from 2a08309 to b5e75a6 Compare June 25, 2025 19:44
Copy link
Contributor

@Fredi-raspall Fredi-raspall left a comment

Choose a reason for hiding this comment

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

LGTM @qmonnet!!. There seems to be a small issue with the rust docs. Can you please fix it so that we can merge? Thanks!

qmonnet added 4 commits June 26, 2025 12:49
Move the NAT code to a dedicated crate to keep the dataplane a thin
binary relying on libraries (rather than implementing all the NAT logics
inside of the dataplane package).

Suggested-by: Fredi Raspall <[email protected]>
Signed-off-by: Quentin Monnet <[email protected]>
Most of the code for stateful and stateless NAT is already dissociated,
but the two modes share a common infrastructure whitin the "Nat" object.
This commit separates them entirely, by duplicating the shared code to
create a copy in the "stateless" submodule, and introducing a new
StatelessNat object. The remaining code in lib.rs for stateful NAT is to
be moved in a future commit.

Motivations for separating the two modes into distinct pipeline stages
include:

- They have little code in common anyway
- It will be clearer, when programming the dataplane, to explicitly
  handle a stateless or statefull object
- The structures used by the two modes, in terms of configuration and
  internal state (for stateful NAT), are not the same. As a consequence,
  having both modes in a same object means instances need to keep some
  useless empty context for the chosen running mode, and it also makes
  it more difficult to protect the different objects for concurrent
  access.

Signed-off-by: Quentin Monnet <[email protected]>
Following the separation of stateful and stateless NAT code into two
different pipeline stages, rename the object for stateful NAT as
StatefulNat, and move it to the dedicated module.

Signed-off-by: Quentin Monnet <[email protected]>
Following the move of the NAT code to a dedicated crate, let's make sure
we pass the correct directives to Clippy and for rustdoc. Also fix the
minor reports for Clippy, and make it ignore "dead_code" only in the
stateful module where it's relevant, not the whole crate.

Also fix two rustdoc warnings emitted from the "routing" package.

Signed-off-by: Quentin Monnet <[email protected]>
@qmonnet qmonnet force-pushed the pr/qmonnet/refactor-nat branch from b5e75a6 to 98c6439 Compare June 26, 2025 11:54
@qmonnet
Copy link
Member Author

qmonnet commented Jun 26, 2025

@Fredi-raspall sorry I thought these checks had run locally (they hadn't) and I didn't check CI results yesterday. It should be addressed now, let's see. Thanks for the review!

@qmonnet qmonnet requested a review from Fredi-raspall June 26, 2025 11:55
@qmonnet qmonnet enabled auto-merge June 26, 2025 12:09
@qmonnet qmonnet added this pull request to the merge queue Jun 26, 2025
Merged via the queue into main with commit 9347911 Jun 26, 2025
16 checks passed
@qmonnet qmonnet deleted the pr/qmonnet/refactor-nat branch June 26, 2025 12:43
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.

2 participants