Skip to content

chore(nat): Improve AllocatorError variants and messages#1491

Merged
qmonnet merged 2 commits intomainfrom
pr/qmonnet/nat-error-fix
Apr 29, 2026
Merged

chore(nat): Improve AllocatorError variants and messages#1491
qmonnet merged 2 commits intomainfrom
pr/qmonnet/nat-error-fix

Conversation

@qmonnet
Copy link
Copy Markdown
Member

@qmonnet qmonnet commented Apr 22, 2026

AllocatorError::NoFreePort is not about no port block being available, but not ports being available in a block. The message is confusing: let's fix it. It's been so confusing that we used the error at a location where the error is not related (passing it an incorrect argument): let's add a new variant for that location, to make it easier to troubleshoot errors.

@qmonnet qmonnet self-assigned this Apr 22, 2026
@qmonnet qmonnet requested a review from a team as a code owner April 22, 2026 15:29
Copilot AI review requested due to automatic review settings April 22, 2026 15:29
@qmonnet qmonnet added the area/nat Related to Network Address Translation (NAT) label Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce confusion when diagnosing stateful NAT allocator failures by refining AllocatorError variants and improving associated error messages.

Changes:

  • Clarifies the AllocatorError::NoFreePort error message to reflect “no free port in a block” (not “no free block”).
  • Introduces a new AllocatorError::PortReservationFailed variant for port reservation failures.
  • Updates stateful NAT error-to-DoneReason translation to account for the new variant.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
nat/src/stateful/allocation.rs Updates allocator error messages and adds PortReservationFailed.
nat/src/stateful/mod.rs Extends translate_error to handle the new allocator error variant.
Comments suppressed due to low confidence (1)

nat/src/stateful/mod.rs:517

confidence: 7
tags: [logic]

`AllocatorError::PortReservationFailed(_)` is currently translated to `DoneReason::NatFailure`, but reservation failures are typically a resource/collision condition similar to `NoFreePort(_)` (which maps to `NatOutOfResources`). If `PortReservationFailed` is meant to represent “requested port already in use / not available”, consider translating it to `NatOutOfResources` for consistent drop reason semantics (or add a brief rationale for why this should be `NatFailure`).
    | StatefulNatError::AllocationFailure(
        AllocatorError::PortAllocationFailed(_)
        | AllocatorError::PortReservationFailed(_)
        | AllocatorError::UnsupportedIcmpCategory
        | AllocatorError::MissingDiscriminant
        | AllocatorError::UnsupportedDiscriminant,
    ) => DoneReason::NatFailure,
</details>

Comment thread nat/src/stateful/allocation.rs
@qmonnet qmonnet force-pushed the pr/qmonnet/nat-error-fix branch from 50ef711 to 07cf6ba Compare April 22, 2026 15:34
@qmonnet qmonnet enabled auto-merge April 24, 2026 09:59
AllocatorError::NoFreePort is not about no port block being available,
but not ports being available in a block. The message is confusing:
let's fix it. It's been so confusing that we used the error at a
location where the error is not related (passing it an incorrect
argument): let's add a new variant for that location, to make it easier
to troubleshoot errors.

Signed-off-by: Quentin Monnet <qmo@qmon.net>
@qmonnet qmonnet force-pushed the pr/qmonnet/nat-error-fix branch from 07cf6ba to fd19678 Compare April 27, 2026 08:34
In commit 19af92e ("feat(stateful-nat): move NF to nf.rs") we moved
the code for the NetworkFunction for masquerading NAT to a dedicated
file, but we left the related tests behind; move them along, as it makes
no sense to keep them in the near-empty mod.rs.

Also remove the tracing imports from mod.rs given that there's no more
code in that file.

Signed-off-by: Quentin Monnet <qmo@qmon.net>
Comment thread nat/src/stateful/allocation.rs
@mvachhar mvachhar self-requested a review April 29, 2026 15:55
@qmonnet qmonnet added this pull request to the merge queue Apr 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 29, 2026
@qmonnet qmonnet added this pull request to the merge queue Apr 29, 2026
Merged via the queue into main with commit 036a8a8 Apr 29, 2026
30 checks passed
@qmonnet qmonnet deleted the pr/qmonnet/nat-error-fix branch April 29, 2026 21:38
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.

4 participants