aboutgitcodebugslistschat
path: root/flow_table.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-30 13:02:10 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-12-04 09:51:04 +0100
commite2e8219f13b80cef257134ebcb4d2616b2f1578c (patch)
tree4d2c09fe1030a42d67d18035850565f40123d0d6 /flow_table.h
parentf08ce92a134e83e7c36050f4482b140b937c8dbb (diff)
downloadpasst-e2e8219f13b80cef257134ebcb4d2616b2f1578c.tar
passt-e2e8219f13b80cef257134ebcb4d2616b2f1578c.tar.gz
passt-e2e8219f13b80cef257134ebcb4d2616b2f1578c.tar.bz2
passt-e2e8219f13b80cef257134ebcb4d2616b2f1578c.tar.lz
passt-e2e8219f13b80cef257134ebcb4d2616b2f1578c.tar.xz
passt-e2e8219f13b80cef257134ebcb4d2616b2f1578c.tar.zst
passt-e2e8219f13b80cef257134ebcb4d2616b2f1578c.zip
flow, tcp: Consolidate flow pointer<->index helpers
Both tcp.c and tcp_splice.c define CONN_IDX() variants to find the index of their connection structures in the connection table, now become the unified flow table. We can easily combine these into a common helper. While we're there, add some trickery for some additional type safety. They also define their own CONN() versions, which aren't so easily combined since they need to return different types, but we can have them use a common helper. In the process, we standardise on always using an unsigned type to store the connection / flow index, which makes more sense. tcp.c's conn_at_idx() remains for now, but we change its parameter to unsigned to match. That in turn means we can remove a check for negative values from it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'flow_table.h')
-rw-r--r--flow_table.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/flow_table.h b/flow_table.h
index c4c646b..5e897bd 100644
--- a/flow_table.h
+++ b/flow_table.h
@@ -22,4 +22,29 @@ union flow {
/* Global Flow Table */
extern union flow flowtab[];
+
+/** flow_idx - Index of flow from common structure
+ * @f: Common flow fields pointer
+ *
+ * Return: index of @f in the flow table
+ */
+static inline unsigned flow_idx(const struct flow_common *f)
+{
+ return (union flow *)f - flowtab;
+}
+
+/** FLOW_IDX - Find the index of a flow
+ * @f_: Flow pointer, either union flow * or protocol specific
+ *
+ * Return: index of @f in the flow table
+ */
+#define FLOW_IDX(f_) (flow_idx(&(f_)->f))
+
+/** FLOW - Flow entry at a given index
+ * @idx: Flow index
+ *
+ * Return: pointer to entry @idx in the flow table
+ */
+#define FLOW(idx) (&flowtab[(idx)])
+
#endif /* FLOW_TABLE_H */