Move FlowKey & FlowInfo to net and embed Flowkey in FlowInfo#1315
Move FlowKey & FlowInfo to net and embed Flowkey in FlowInfo#1315Fredi-raspall merged 5 commits intomainfrom
Conversation
39b3904 to
b576aee
Compare
|
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
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. Problem
So:
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>
b576aee to
fcd2eef
Compare
mvachhar
left a comment
There was a problem hiding this comment.
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. |
We want the flow info's to include the keys they are stored with in the flow-table.
This:
To do that, however, we need to solve circular dependencies.
This PR: