Skip to content

tx/dispatch: extract compute_forwarded_egress_ptb (#4408 increment 1)#4642

Merged
psaab merged 1 commit into
masterfrom
refactor/4408-increment-1
Jul 8, 2026
Merged

tx/dispatch: extract compute_forwarded_egress_ptb (#4408 increment 1)#4642
psaab merged 1 commit into
masterfrom
refactor/4408-increment-1

Conversation

@psaab

@psaab psaab commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Addresses #4408 (increment 1: extract compute_forwarded_egress_ptb from enqueue_pending_forwards; further increments tracked).

What

Pure code-motion outlining of the first cohesive sub-block out of the
1,131-LOC enqueue_pending_forwards TX-drain orchestrator in
userspace-dp/src/afxdp/tx/dispatch/mod.rs.

The #2301/#2330/#2845 egress-MTU Path-MTU-Discovery block (93 interior
lines) was already a self-contained scoped { ... } unit inside the
!copied_source_frame branch. It reads only immutable inputs
(source_frame, request.meta, request.decision, forwarding, the
is_nat64 / uses_native_tunnel flags, ingress_ident,
recent_exceptions), mutates neither target_binding nor the tx
pipeline, has no early return / continue / break, and its only
outputs are the two locals ptb_reply and mtu_signalled.

It moves verbatim into a new private helper:

#[inline]
fn compute_forwarded_egress_ptb(...) -> (Option<Vec<u8>>, bool)

The call site becomes (ptb_reply, mtu_signalled) = compute_forwarded_egress_ptb(...).

Why it is pure code-motion (behaviour-identical)

Hot-path invariants untouched: no new allocation, the non-NAT64
zero-copy path is unchanged, and the helper only runs on the already
oversized-frame slow path. This increment deliberately does NOT touch
the single-recycle invariant or the CoS guarantee-guard.

Validation

  • Full userspace-dp cargo test: 3830 passed, 0 failed.
  • cargo check clean (no new warnings).
  • cargo fmt was intentionally NOT run on the tree: it is not canonical
    under the locally installed rustfmt (it would rewrite ~1474 unrelated
    files). The added lines were hand-matched to the surrounding style.

Scope

Bounded single increment. #4408 continues with further outlining
(cold segmentation / mirror paths, the select_exact_cos_guarantee_queue_waterfill
split). Docs updated: userspace-dp/src/afxdp/tx/README.md (new
"Ongoing refactor" section) + _Log.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi

Pure code-motion outlining of the first cohesive sub-block out of the
1,131-LOC enqueue_pending_forwards TX-drain orchestrator, the first
bounded increment of the #4408 hot-path god-function refactor.

The #2301/#2330/#2845 egress-MTU Path-MTU-Discovery block (93 interior
lines) was already a self-contained scoped { ... } unit inside the
non-copied-source-frame branch: it reads only immutable inputs
(source_frame, request.meta, request.decision, forwarding, the is_nat64
/ uses_native_tunnel flags, ingress_ident, recent_exceptions), mutates
neither target_binding nor the tx pipeline, has no early return /
continue / break, and its only outputs are the two locals ptb_reply and
mtu_signalled. That makes it an ideal extract-function target.

It moves verbatim into a new private #[inline] helper

    fn compute_forwarded_egress_ptb(...) -> (Option<Vec<u8>>, bool)

returning (ptb_reply, mtu_signalled). The call site becomes a
destructuring assignment to the same outer mut locals, so behaviour is
identical: same inner-MTU derivation via the #2300/#2331 GRE/WG/NAT64
SSOT helpers, the same forwarded_egress_mtu_decision, the same RFC 792 /
RFC 4443 + #2472 rate-limit suppression, the same PTB build, and the
same egress_mtu_exceeded exception recording with identical arguments
and ordering. The moved body is character-identical modulo the
request.meta -> meta and &request.decision -> decision field-to-param
substitution.

Hot-path invariants are untouched: no new allocation, the non-NAT64
zero-copy path is unchanged, and the helper only runs on the already
oversized-frame slow path. Bounded single increment; #4408 continues
with further outlining (segmentation / mirror paths, the waterfill
split). The detailed #2301/#2330 rationale comment moves onto the
helper's doc comment; the call site keeps a short pointer.

Validation: full userspace-dp cargo test 3830/0. cargo fmt was NOT run
on the tree (it is not canonical under the locally installed rustfmt,
which would rewrite ~1474 unrelated files); the added lines were
hand-matched to the surrounding style.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi
Copilot AI review requested due to automatic review settings July 8, 2026 09:38
@psaab
psaab merged commit c6990eb into master Jul 8, 2026
1 check passed

Copilot AI 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.

Pull request overview

This PR implements #4408 increment 1 by extracting the forwarded egress-MTU / PMTUD (ICMP PTB / Frag Needed) sub-block out of the large enqueue_pending_forwards TX dispatcher into a dedicated private helper, keeping behavior and side-effect ordering intact.

Changes:

  • Extracted the PMTUD decision + PTB construction + exception recording logic into compute_forwarded_egress_ptb(...) -> (Option<Vec<u8>>, bool) and replaced the inline block with a tuple assignment at the call site.
  • Added internal documentation describing the ongoing outlining effort and the invariants being preserved.
  • Logged the edit per repo process in _Log.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
userspace-dp/src/afxdp/tx/dispatch/mod.rs Moves the forwarded egress-MTU/PTB logic into compute_forwarded_egress_ptb and wires it back into enqueue_pending_forwards as pure code motion.
userspace-dp/src/afxdp/tx/README.md Documents the #4408 outlining effort and describes increment 1’s extracted helper and invariants.
_Log.md Records the refactor increment and touched files per the project’s action logging convention.

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.

2 participants