Skip to content

[1/3] [nat] move PortRange to struct - #334

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

[1/3] [nat] move PortRange to struct#334
nicolaskagami merged 1 commit into
mainfrom
nsk/nat-1-portrange

Conversation

@nicolaskagami

@nicolaskagami nicolaskagami commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

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.

@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.

Overall looks good! Just a few comments.

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

@taspelund taspelund 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.

LGTM, although I'd like to see an approval from @internet-diglett as well before merging

@nicolaskagami
nicolaskagami merged commit 5fef0b7 into main Aug 14, 2026
6 checks passed
@nicolaskagami
nicolaskagami deleted the nsk/nat-1-portrange branch August 14, 2026 11:47
nicolaskagami added a commit that referenced this pull request Aug 14, 2026
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.
- #334
- #335
- #336

Obs: Changes are almost entirely equivalent, except for the ordering of
some things and the log message `nat tables` -> `nat table`.
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.

4 participants