aboutgitcodebugslistschat
path: root/flow_table.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-30 13:02:14 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-12-04 09:51:14 +0100
commitdf96a4cb5d4f3907f1019ba50511ee9787443acf (patch)
treec196c13637346995bf9f02ae32788e3397a7071b /flow_table.h
parenteb8b1a233beee1e11eb700e2201becc34f913f9e (diff)
downloadpasst-df96a4cb5d4f3907f1019ba50511ee9787443acf.tar
passt-df96a4cb5d4f3907f1019ba50511ee9787443acf.tar.gz
passt-df96a4cb5d4f3907f1019ba50511ee9787443acf.tar.bz2
passt-df96a4cb5d4f3907f1019ba50511ee9787443acf.tar.lz
passt-df96a4cb5d4f3907f1019ba50511ee9787443acf.tar.xz
passt-df96a4cb5d4f3907f1019ba50511ee9787443acf.tar.zst
passt-df96a4cb5d4f3907f1019ba50511ee9787443acf.zip
flow: Introduce 'sidx' type to represent one side of one flow
In a number of places, we use indices into the flow table to identify a specific flow. We also have cases where we need to identify a particular side of a particular flow, and we expect those to become more common as we generalise the flow table to cover more things. To assist with that, introduces flow_sidx_t, an index type which identifies a specific side of a specific flow in the table. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> [sbrivio: Suppress false cppcheck positive in flow_sidx()] Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'flow_table.h')
-rw-r--r--flow_table.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/flow_table.h b/flow_table.h
index 5e897bd..0dee66f 100644
--- a/flow_table.h
+++ b/flow_table.h
@@ -47,4 +47,42 @@ static inline unsigned flow_idx(const struct flow_common *f)
*/
#define FLOW(idx) (&flowtab[(idx)])
+/** flow_at_sidx - Flow entry for a given sidx
+ * @sidx: Flow & side index
+ *
+ * Return: pointer to the corresponding flow entry, or NULL
+ */
+static inline union flow *flow_at_sidx(flow_sidx_t sidx)
+{
+ if (sidx.flow >= FLOW_MAX)
+ return NULL;
+ return FLOW(sidx.flow);
+}
+
+/** flow_sidx_t - Index of one side of a flow from common structure
+ * @f: Common flow fields pointer
+ * @side: Which side to refer to (0 or 1)
+ *
+ * Return: index of @f and @side in the flow table
+ */
+static inline flow_sidx_t flow_sidx(const struct flow_common *f,
+ int side)
+{
+ /* cppcheck-suppress [knownConditionTrueFalse, unmatchedSuppression] */
+ ASSERT(side == !!side);
+
+ return (flow_sidx_t){
+ .side = side,
+ .flow = flow_idx(f),
+ };
+}
+
+/** FLOW_SIDX - Find the index of one side of a flow
+ * @f_: Flow pointer, either union flow * or protocol specific
+ * @side: Which side to index (0 or 1)
+ *
+ * Return: index of @f and @side in the flow table
+ */
+#define FLOW_SIDX(f_, side) (flow_sidx(&(f_)->f, (side)))
+
#endif /* FLOW_TABLE_H */