Skip to content

[2/3] [nat] introduce NatAddress trait - #335

Merged
nicolaskagami merged 1 commit into
mainfrom
nsk/nat-2-nat-family
Aug 14, 2026
Merged

[2/3] [nat] introduce NatAddress trait#335
nicolaskagami merged 1 commit into
mainfrom
nsk/nat-2-nat-family

Conversation

@nicolaskagami

@nicolaskagami nicolaskagami commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This PR:

  • Introduces a NatAddress trait, tying each IP address family to its p4 table, match key, and action types. Replaces duplicated per-family entry points.
  • Fixes a bug where we'd clear our internal representation of the mappings if the underlying code failed to reset.

This is the second of 3 PRs simplifying and de-duplicating some of the nat.rs code.

Obs: Changes are almost entirely equivalent, except for the ordering of some things and the log message nat tables -> nat table.

@nicolaskagami nicolaskagami self-assigned this Aug 6, 2026
@nicolaskagami nicolaskagami changed the title [2/3] [nat] introduce NatFamily trait [2/3] [nat] introduce NatAddress trait Aug 6, 2026
@nicolaskagami
nicolaskagami marked this pull request as ready for review August 6, 2026 18:00
Comment thread dpd/src/nat.rs Outdated
Comment thread dpd/src/table/nat.rs
@nicolaskagami
nicolaskagami force-pushed the nsk/nat-2-nat-family branch 2 times, most recently from 22d9c68 to 1b86758 Compare August 7, 2026 13:47
Comment thread dpd/src/nat.rs Outdated
Comment thread dpd/src/nat.rs Outdated
Comment thread dpd/src/table/nat.rs
@nicolaskagami
nicolaskagami force-pushed the nsk/nat-2-nat-family branch 2 times, most recently from 8293a3e to c597b42 Compare August 8, 2026 02:52

@bnaecker bnaecker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, nice cleanup. Just a few questions / nits.

Comment thread dpd/src/nat.rs Outdated
Comment thread dpd/src/nat.rs Outdated
Comment thread dpd/src/table/nat.rs Outdated
Comment thread dpd/src/table/nat.rs

@internet-diglett internet-diglett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks really good, thank you for working on this!

nicolaskagami added a commit that referenced this pull request Aug 14, 2026
This PR:
- Moves the `PortRange` trait into a struct, validating the `low <=
high` invariant by construction.
- Simplifies `overlap` function.

This is the first of 3 PRs simplifying and de-duplicating some of the
`nat.rs` code.
- #334
- #335
- #336

Left for future work:
- Expanding `PortRange` usage further.
- Storing ranges in a way that codifies its non-overlapping invariant
and stores sorted for faster operations.
Base automatically changed from nsk/nat-1-portrange to main August 14, 2026 11:47
Tie each IP address family to its p4 table, match key, and action types
via a trait, with the table operations provided as default methods.
Replaces the duplicated per-family entry points.
@nicolaskagami
nicolaskagami merged commit 7a84c23 into main Aug 14, 2026
6 checks passed
@nicolaskagami
nicolaskagami deleted the nsk/nat-2-nat-family branch August 14, 2026 12:07
nicolaskagami added a commit that referenced this pull request Aug 14, 2026
This PR:
- Introduces a `NatEntry` and `NatMap` to replace duplicated v4/v6 logic
(net -203 LOC).

This is the last of 3 PRs simplifying and de-duplicating some of the
`nat.rs` code.
- #334
- #335
- #336

Obs: 
- I decided to upgrade the IPv6 log error from `trace` to `error` to
match the IPv4 one but I'm happy to do it the other way around.
- Renamed `ipv4_generation` to `generation`, since it applies to both
even though the nexus API nomenclature is out-of-date.
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.

3 participants