Skip to content

Pr/fredi/adapt port fw flows with keys#1318

Merged
qmonnet merged 3 commits intomainfrom
pr/fredi/adapt-port-fw-flows-with-keys
Mar 5, 2026
Merged

Pr/fredi/adapt port fw flows with keys#1318
qmonnet merged 3 commits intomainfrom
pr/fredi/adapt-port-fw-flows-with-keys

Conversation

@Fredi-raspall
Copy link
Contributor

This goes on top of #1315, which should be merged first.

  • Adapt port-forwarding code to the case where flowInfos contain keys.
  • This PR does not make any use of the fact that flows contain keys.. It just prepares for subsequent PRs

@Fredi-raspall Fredi-raspall requested a review from mvachhar March 4, 2026 21:44
@Fredi-raspall Fredi-raspall requested a review from a team as a code owner March 4, 2026 21:44
Copy link
Contributor

@mvachhar mvachhar left a comment

Choose a reason for hiding this comment

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

I am fine with these changes, but I think @qmonnet should give his approval for merge.

Base automatically changed from pr/fredi/move_flowkey_and_info_and_embed_keys to main March 5, 2026 10:50
Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

I'm mostly concerned with the non-debug assert; it looks good otherwise, I just have a few nits.

It also needs a rebase of course.

Copy link
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 adapts the port-forwarding code to work with FlowInfo objects that embed FlowKeys, and consolidates the flow-info crate into the net crate alongside the flow_key module (which was moved from flow-entry). This is a preparatory refactoring that does not yet make functional use of embedded keys but sets the groundwork for subsequent PRs.

Changes:

  • Consolidates the flow-info crate and flow_key module into net/src/flows/, removing the standalone flow-info crate and updating all imports across the codebase.
  • Extends FlowInfo to embed an Option<FlowKey>, updates FlowInfo::related_pair() to require two distinct keys, and adds validation in FlowTable::insert/insert_from_arc to ensure key consistency.
  • Refactors port-forwarding flow creation to pre-compute both forward and reverse flow keys before packet mutation, extracting key-building logic into a new build_portfw_flow_keys function.

Reviewed changes

Copilot reviewed 28 out of 31 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Cargo.toml Removes flow-info from workspace members and dependencies
Cargo.lock Updated lock file reflecting flow-info removal and net gaining its dependencies
net/Cargo.toml Adds atomic-instant-full, downcast-rs, ahash (dev) dependencies previously in flow-info
net/src/lib.rs Adds flows module and re-exports FlowKey, FlowKeyData, and related types
net/src/flows/mod.rs New module aggregating flow keys, flow info, flow info items, and atomic instant
net/src/flows/flow_key.rs Moved from flow-entry, adds new accessors (src_port, dst_port, ports, proto), setters, and From impls
net/src/flows/flow_key_display.rs Moved Display impls for FlowKeyData and FlowKey
net/src/flows/flow_info.rs Moved from flow-info crate; adds flowkey field to FlowInfo, updates related_pair to require keys
net/src/flows/flow_info_item.rs Moved from flow-info crate (trait and helpers for downcasting flow info items)
net/src/flows/atomic_instant.rs Moved from flow-info crate
net/src/packet/meta.rs Updates FlowInfo import path
flow-info/Cargo.toml Deleted
flow-entry/Cargo.toml Removes flow-info dependency
flow-entry/src/flow_table/mod.rs Removes flow_key submodule, updates re-exports to use net::flows
flow-entry/src/flow_table/table.rs Adds key validation assertions in insert and insert_from_arc; embeds key in insert if absent
flow-entry/src/flow_table/display.rs Removes moved Display impls, updates imports
flow-entry/src/flow_table/nf_lookup.rs Updates imports and test call sites for related_pair
flow-entry/src/flow_table/nf_expirations.rs Updates imports
flow-filter/Cargo.toml Removes flow-info dependency
flow-filter/src/lib.rs Updates imports to net::flows
nat/Cargo.toml Removes flow-info dependency
nat/src/portfw/nf.rs Refactors do_port_forwarding to pre-build keys, passes keys to related_pair
nat/src/portfw/flow_state.rs Adds build_portfw_flow_keys; refactors setup_forward_flow/setup_reverse_flow to accept pre-built keys
nat/src/portfw/test.rs Updates imports
nat/src/portfw/portfwtable/objects.rs Adds comment to dst_vpcd, reformats alignment
nat/src/stateful/mod.rs Updates imports
nat/src/stateful/allocator.rs Updates imports
nat/src/stateful/apalloc/mod.rs Updates imports
nat/src/stateful/apalloc/natip_with_bitmap.rs Updates imports
nat/src/stateful/apalloc/test_alloc.rs Updates imports
nat/src/stateful/test.rs Updates imports
Comments suppressed due to low confidence (3)

net/src/flows/flow_key.rs:369

confidence: 8
tags: [logic, style]


Using `unreachable!()` inside a `From` trait implementation is problematic. The `From` trait is expected to be a total (infallible) conversion in Rust. Passing any `NextHeader` variant other than TCP or UDP (e.g., ICMP, ICMP6, or any other protocol) will panic at runtime. Consider using `TryFrom` instead, which returns a `Result` and properly signals to callers that the conversion may not succeed. This would also force callers to handle the error case explicitly rather than relying on a runtime panic.
**net/src/flows/flow_key.rs:521**
* ```yaml
confidence: 8
tags: [logic]

The proto() method returns NextHeader::ICMP for all IcmpProtoKey variants, but IcmpProtoKey is used for both ICMPv4 and ICMPv6 flows (via new_icmp_v4 and new_icmp_v6 constructors). For ICMPv6 flows, this would incorrectly return NextHeader::ICMP (protocol 1) instead of NextHeader::ICMP6 (protocol 58). While the TODO acknowledges this, any caller using proto() on an ICMPv6 flow key will get the wrong protocol number. Consider at minimum documenting that this only works correctly for ICMPv4, or storing the IP version in the IcmpProtoKey so the correct protocol can be returned.
net/src/flows/mod.rs:4

confidence: 7
tags: [docs]


The module-level doc comment says "Definitions for flow keys" but this module also contains flow info (`flow_info.rs`), flow info items (`flow_info_item.rs`), and `AtomicInstant`. Consider updating the doc comment to reflect the broader scope, e.g., "Definitions for flow keys, flow information, and related types".
</details>

@Fredi-raspall Fredi-raspall force-pushed the pr/fredi/adapt-port-fw-flows-with-keys branch from b5b1250 to 0dedd26 Compare March 5, 2026 13:25
These are needed later on.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Reorganize the code so that the keys for the pair of related flows
can be computed before creating those, so that these are built
with the keys set.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
@Fredi-raspall Fredi-raspall force-pushed the pr/fredi/adapt-port-fw-flows-with-keys branch from 0dedd26 to c978b73 Compare March 5, 2026 13:27
@Fredi-raspall Fredi-raspall requested a review from qmonnet March 5, 2026 13:27
@Fredi-raspall
Copy link
Contributor Author

@qmonnet I think I addressed all comments and rebased on latest main.

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +201 to +202
debug_assert!(
key1 != key2,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
debug_assert!(
key1 != key2,
debug_assert_ne!(
key1,
key2,

@qmonnet qmonnet enabled auto-merge March 5, 2026 14:02
@qmonnet qmonnet added this pull request to the merge queue Mar 5, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@qmonnet qmonnet added this pull request to the merge queue Mar 5, 2026
Merged via the queue into main with commit 4c2f504 Mar 5, 2026
35 of 39 checks passed
@qmonnet qmonnet deleted the pr/fredi/adapt-port-fw-flows-with-keys branch March 5, 2026 15:16
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