-
Notifications
You must be signed in to change notification settings - Fork 9
Misc changes related to flows #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,8 @@ pub enum FlowInfoError { | |||||||||||||
| NoSuchStatus(u8), | ||||||||||||||
| #[error("Timeout unchanged: would go backwards")] | ||||||||||||||
| TimeoutUnchanged, | ||||||||||||||
| #[error("Invalid flow pair: {0}")] | ||||||||||||||
| InvalidPair(String), | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[repr(u8)] | ||||||||||||||
|
|
@@ -140,12 +142,18 @@ impl From<FlowStatus> for AtomicFlowStatus { | |||||||||||||
| bitflags! { | ||||||||||||||
| #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | ||||||||||||||
| pub struct FlowInfoFlags: u8 { | ||||||||||||||
| const REQ_STATIC_NAT_SRC = 0b0000_0001; /* Packet requires static NAT (source) */ | ||||||||||||||
| const REQ_STATIC_NAT_DST = 0b0000_0010; /* Packet requires static NAT (destination) */ | ||||||||||||||
| const INITIATOR = 0b0000_0001; /* the flow is the initiator within a pair */ | ||||||||||||||
| const REQ_STATIC_NAT_SRC = 0b0000_0010; /* Packet requires static NAT (source) */ | ||||||||||||||
| const REQ_STATIC_NAT_DST = 0b0000_0100; /* Packet requires static NAT (destination) */ | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| impl FlowInfoFlags { | ||||||||||||||
| #[must_use] | ||||||||||||||
| pub const fn is_initiator(&self) -> bool { | ||||||||||||||
| self.contains(FlowInfoFlags::INITIATOR) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[must_use] | ||||||||||||||
| pub const fn requires_static_nat_src(self) -> bool { | ||||||||||||||
| self.contains(FlowInfoFlags::REQ_STATIC_NAT_SRC) | ||||||||||||||
|
|
@@ -274,23 +282,28 @@ impl FlowInfo { | |||||||||||||
| /// to call this function when a couple of related flow entries are needed and later insert them in the | ||||||||||||||
| /// flow-table. | ||||||||||||||
| /// | ||||||||||||||
| /// # Panics | ||||||||||||||
| /// This function panics if two equal keys are provided | ||||||||||||||
| /// # Errors | ||||||||||||||
| /// This function fails if two identical keys are provided or if one (and only one) of the flows | ||||||||||||||
| /// is not flagged as initiator | ||||||||||||||
|
Comment on lines
+285
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Correct the The text says that the function fails when exactly one flow is not an initiator. That is the valid state enforced by Lines 302-306. Describe the invalid states instead: identical keys, both flows marked as initiators, or neither flow marked as an initiator. Proposed fix- /// This function fails if two identical keys are provided or if one (and only one) of the flows
- /// is not flagged as initiator
+ /// This function fails if two identical keys are provided or if both flows have the same
+ /// initiator status.As per coding guidelines, find logic errors in the code under review. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You are interacting with an AI system. |
||||||||||||||
| #[allow(clippy::missing_panics_doc)] | ||||||||||||||
| #[must_use] | ||||||||||||||
| #[allow(clippy::unwrap_used)] | ||||||||||||||
| pub fn related_pair( | ||||||||||||||
| expires_at: Instant, | ||||||||||||||
| key1: FlowKey, | ||||||||||||||
| flags1: FlowInfoFlags, | ||||||||||||||
| key2: FlowKey, | ||||||||||||||
| flags2: FlowInfoFlags, | ||||||||||||||
| ) -> (Arc<FlowInfo>, Arc<FlowInfo>) { | ||||||||||||||
| // keys MUST differ | ||||||||||||||
| debug_assert!( | ||||||||||||||
| key1 != key2, | ||||||||||||||
| "Attempted to build two flows with identical key {key1}" | ||||||||||||||
| ); | ||||||||||||||
| ) -> Result<(Arc<FlowInfo>, Arc<FlowInfo>), FlowInfoError> { | ||||||||||||||
| if key1 == key2 { | ||||||||||||||
| return Err(FlowInfoError::InvalidPair(format!( | ||||||||||||||
| "Attempted to build a flow pair with identical keys {key1}" | ||||||||||||||
| ))); | ||||||||||||||
| } | ||||||||||||||
| if flags1.is_initiator() == flags2.is_initiator() { | ||||||||||||||
| return Err(FlowInfoError::InvalidPair( | ||||||||||||||
| "One of the flows must be the initiator".to_string(), | ||||||||||||||
| )); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| let mut one: Arc<MaybeUninit<Self>> = Arc::new_uninit(); | ||||||||||||||
| let mut two: Arc<MaybeUninit<Self>> = Arc::new_uninit(); | ||||||||||||||
|
|
@@ -321,7 +334,7 @@ impl FlowInfo { | |||||||||||||
| .set_related(one_weak), | ||||||||||||||
| ); | ||||||||||||||
| // turn back into Arc's | ||||||||||||||
| (one.assume_init(), two.assume_init()) | ||||||||||||||
| Ok((one.assume_init(), two.assume_init())) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.