Skip to content

Move FlowKey & FlowInfo to net and embed Flowkey in FlowInfo#1315

Merged
Fredi-raspall merged 5 commits intomainfrom
pr/fredi/move_flowkey_and_info_and_embed_keys
Mar 5, 2026
Merged

Move FlowKey & FlowInfo to net and embed Flowkey in FlowInfo#1315
Fredi-raspall merged 5 commits intomainfrom
pr/fredi/move_flowkey_and_info_and_embed_keys

Conversation

@Fredi-raspall
Copy link
Contributor

We want the flow info's to include the keys they are stored with in the flow-table.
This:

  • avoids unnecessary re-building of keys in NFs, simplifies their code and reduces the possibility of errors.
  • allows determining the key from the flow itself (to which packets have references).

To do that, however, we need to solve circular dependencies.

This PR:

  1. moves the FlowKey out of the flow-entry (flow table) crate into the net crate.
  2. moves the flow-info crate to net as well.
  3. extends FlowInfo type to include a FlowKey.
  • No functional difference should be observed by these changes
  • Subsequent PRs will make use of those changes.

@Fredi-raspall Fredi-raspall requested a review from mvachhar March 4, 2026 16:14
@Fredi-raspall Fredi-raspall requested a review from a team as a code owner March 4, 2026 16:14
@Fredi-raspall Fredi-raspall force-pushed the pr/fredi/move_flowkey_and_info_and_embed_keys branch from 39b3904 to b576aee Compare March 4, 2026 16:28
@mvachhar
Copy link
Contributor

mvachhar commented Mar 4, 2026

Why are we moving the flowkey stuff out of flow_table? Why would be bake it into net when it isn't necessarily universal (e.g., if we change the flow table implementation, maybe we change the flow key implementation too.

@Fredi-raspall
Copy link
Contributor Author

Why are we moving the flowkey stuff out of flow_table? Why would be bake it into net when it isn't necessarily universal (e.g., if we change the flow table implementation, maybe we change the flow key implementation too.

Motivation
We want need the flow entries (FlowInfo) contain them. Right now there are 2 ways how NFs can access the flowInfos:

  • if the key is known, via lookup()
  • packets that matched a flowInfo have a reference to the flowInfo.

The problem is that, there's cases, where we may have a reference to a flowInfo but not know its key. Ofc, you may say, that if you have a reference to a flowInfo, that's because you have a packet and could build a key from it (because that should give you the key that allowed finding the flowinfo in the first place. However, there's cases where we can't do that. For instance, if you have a reference to a flow in the forward direction of port-forwarding, that flow may have a reference to the flow in the reverse direction. We can access that "related" flow, but right know we don't have ways to know what its key is.
So, embedding the key in the flowInfo seems like the right thing to do.

Problem
We can't embed flowkey in flowinfo for circular dependencies:

  • net depends on flow-info (for the metadata reference to flowinfos)
  • flow-entry (where flowkeys live) depends on net.
  • we can't put flowkey in flowinfo as that would make flowinfo depend on flow-entry (terrible) and in turn depend on net.

So:

  • we put flowkey in net. After all a key is just a collection of types from net
  • we put flowinfo in net. Does not cause issues
  • Flow-entry (the actual hash table of flows and lookup NF) depends on net (as it did already).

I agree that defining the flowkey outside of the flowtable is a bit odd. But, OTH, we're already doing that for the flow-info.

Move the FlowKey type to the net crate:
  - net is probably the best place for FlowKeys since their
    contents are built from packet properties and the module
    makes extensive use of net.
  - This change is not cosmetic but to avoid circular dependencies.
    We want to embed the FlowKey in a FlowInfo object. Without this
    change, that is not possible since net depends on flow-info
    and the flow keys are defined in flow-entry which depends on
    net.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Extend the FlowInfo object to include a FlowKey. This way, NFs
need not rebuild the keys if packets refer to a flow-info.
This avoids bugs when building and mangling keys and allows
determining the FlowKey for a FlowInfo from the object itself.

The flowkey is made Optional so as not to break existing APIs
nor use cases where flow infos are created without yet knowing
the keys.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
When inserting a flow-info in the flow-table:
  - stamp the provided FlowKey in the FlowInfo it it has none.
  - if the FlowInfo already had a flowkey, panic if the key differs
    from the one provided to insert it in the table.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
Related pairs of flow entries are immutable: they are Arc'ed
and refer to each other via a Weak reference. Such flows are
inserted already Arc'ed in the flow table so as to preserve
the Weak references. Therefore, for those flows to be able to
embed their keys, these must be provided when building them.

This commit modifies the related_pair() associated function to
accept two keys. Currently, the keys are made optional, but in the
near future they will be mandatory. Creating a pair of flows
with the same key is illegal and will panic.

Also, attempting to insert an Arc<FlowInfo> in the flow table
with a key distinct than that of the FlowInfo (if it contains one)
results in a panic.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
@Fredi-raspall Fredi-raspall force-pushed the pr/fredi/move_flowkey_and_info_and_embed_keys branch from b576aee to fcd2eef Compare March 4, 2026 18:42
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 hate these changes but I don't have a better solution to the circular dependencies that is safe for the near future, so approved.

@mvachhar mvachhar 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
@Fredi-raspall
Copy link
Contributor Author

I hate these changes but I don't have a better solution to the circular dependencies that is safe for the near future, so approved.

I don't think it's that bad, other than enlarging net. Oth both Flow key and FlowInfo aren't that large.
Happy to explore alternatives later on.

@Fredi-raspall Fredi-raspall added this pull request to the merge queue Mar 5, 2026
Merged via the queue into main with commit 5d3b8d9 Mar 5, 2026
27 of 29 checks passed
@Fredi-raspall Fredi-raspall deleted the pr/fredi/move_flowkey_and_info_and_embed_keys branch March 5, 2026 10:50
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