aboutgitcodebugslistschat
path: root/flow_table.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-07-17 14:52:18 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-07-17 15:27:27 +0200
commit9b125e7776333326b91adfc4cfd54298737004cd (patch)
tree39ce4a14dacb89248652fdb7f0e7f1bfc7446a25 /flow_table.h
parent2fa91ee391b7bbed960bf404a405573c64d836aa (diff)
downloadpasst-9b125e7776333326b91adfc4cfd54298737004cd.tar
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.gz
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.bz2
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.lz
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.xz
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.zst
passt-9b125e7776333326b91adfc4cfd54298737004cd.zip
flow, icmp, tcp: Clean up helpers for getting flow from index
TCP (both regular and spliced) and ICMP both have macros to retrieve the relevant protcol specific flow structure from a flow index. In most cases what we actually want is to get the specific flow from a sidx. Replace those simple macros with a more precise inline, which also asserts that the flow is of the type we expect. While we're they're also add a pif_at_sidx() helper to get the interface of a specific flow & side, which is useful in some places. Finally, fix some minor style issues in the comments on some of the existing sidx related helpers. 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.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/flow_table.h b/flow_table.h
index 226ddbd..ab73e44 100644
--- a/flow_table.h
+++ b/flow_table.h
@@ -42,7 +42,7 @@ extern unsigned flow_first_free;
extern union flow flowtab[];
-/** flow_idx - Index of flow from common structure
+/** flow_idx() - Index of flow from common structure
* @f: Common flow fields pointer
*
* Return: index of @f in the flow table
@@ -52,21 +52,21 @@ static inline unsigned flow_idx(const struct flow_common *f)
return (union flow *)f - flowtab;
}
-/** FLOW_IDX - Find the index of a flow
+/** 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
+/** FLOW() - Flow entry at a given index
* @idx: Flow index
*
* Return: pointer to entry @idx in the flow table
*/
#define FLOW(idx) (&flowtab[(idx)])
-/** flow_at_sidx - Flow entry for a given sidx
+/** flow_at_sidx() - Flow entry for a given sidx
* @sidx: Flow & side index
*
* Return: pointer to the corresponding flow entry, or NULL
@@ -78,7 +78,21 @@ static inline union flow *flow_at_sidx(flow_sidx_t sidx)
return FLOW(sidx.flow);
}
-/** flow_sidx_t - Index of one side of a flow from common structure
+/** pif_at_sidx() - Interface for a given flow and side
+ * @sidx: Flow & side index
+ *
+ * Return: pif for the flow & side given by @sidx
+ */
+static inline uint8_t pif_at_sidx(flow_sidx_t sidx)
+{
+ const union flow *flow = flow_at_sidx(sidx);
+
+ if (!flow)
+ return PIF_NONE;
+ return flow->f.pif[sidx.side];
+}
+
+/** flow_sidx() - Index of one side of a flow from common structure
* @f: Common flow fields pointer
* @side: Which side to refer to (0 or 1)
*
@@ -96,7 +110,7 @@ static inline flow_sidx_t flow_sidx(const struct flow_common *f,
};
}
-/** FLOW_SIDX - Find the index of one side of a flow
+/** 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)
*