aboutgitcodebugslistschat
path: root/flow.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-07-18 15:26:36 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-07-19 18:33:01 +0200
commit508adde342f65efc3d58c51beaabb9ae8ecd8137 (patch)
treee9cb9e1dbfe08d27003fc31dc04d1b7b3dd8051e /flow.c
parentacca4235c46f0b2ecceb991d75a09616309afb3c (diff)
downloadpasst-508adde342f65efc3d58c51beaabb9ae8ecd8137.tar
passt-508adde342f65efc3d58c51beaabb9ae8ecd8137.tar.gz
passt-508adde342f65efc3d58c51beaabb9ae8ecd8137.tar.bz2
passt-508adde342f65efc3d58c51beaabb9ae8ecd8137.tar.lz
passt-508adde342f65efc3d58c51beaabb9ae8ecd8137.tar.xz
passt-508adde342f65efc3d58c51beaabb9ae8ecd8137.tar.zst
passt-508adde342f65efc3d58c51beaabb9ae8ecd8137.zip
tcp: Re-use flow hash for initial sequence number generation
We generate TCP initial sequence numbers, when we need them, from a hash of the source and destination addresses and ports, plus a timestamp. Moments later, we generate another hash of the same information plus some more to insert the connection into the flow hash table. With some tweaks to the flow_hash_insert() interface and changing the order we can re-use that hash table hash for the initial sequence number, rather than calculating another one. It won't generate identical results, but that doesn't matter as long as the sequence numbers are well scattered. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'flow.c')
-rw-r--r--flow.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/flow.c b/flow.c
index b291f25..8eea861 100644
--- a/flow.c
+++ b/flow.c
@@ -455,16 +455,16 @@ static uint64_t flow_sidx_hash(const struct ctx *c, flow_sidx_t sidx)
}
/**
- * flow_hash_probe() - Find hash bucket for a flow
- * @c: Execution context
+ * flow_hash_probe_() - Find hash bucket for a flow, given hash
+ * @hash: Raw hash value for flow & side
* @sidx: Flow and side to find bucket for
*
* Return: If @sidx is in the hash table, its current bucket, otherwise a
* suitable free bucket for it.
*/
-static inline unsigned flow_hash_probe(const struct ctx *c, flow_sidx_t sidx)
+static inline unsigned flow_hash_probe_(uint64_t hash, flow_sidx_t sidx)
{
- unsigned b = flow_sidx_hash(c, sidx) % FLOW_HASH_SIZE;
+ unsigned b = hash % FLOW_HASH_SIZE;
/* Linear probing */
while (flow_sidx_valid(flow_hashtab[b]) &&
@@ -475,17 +475,35 @@ static inline unsigned flow_hash_probe(const struct ctx *c, flow_sidx_t sidx)
}
/**
+ * flow_hash_probe() - Find hash bucket for a flow
+ * @c: Execution context
+ * @sidx: Flow and side to find bucket for
+ *
+ * Return: If @sidx is in the hash table, its current bucket, otherwise a
+ * suitable free bucket for it.
+ */
+static inline unsigned flow_hash_probe(const struct ctx *c, flow_sidx_t sidx)
+{
+ return flow_hash_probe_(flow_sidx_hash(c, sidx), sidx);
+}
+
+/**
* flow_hash_insert() - Insert side of a flow into into hash table
* @c: Execution context
* @sidx: Flow & side index
+ *
+ * Return: raw (un-modded) hash value of side of flow
*/
-void flow_hash_insert(const struct ctx *c, flow_sidx_t sidx)
+uint64_t flow_hash_insert(const struct ctx *c, flow_sidx_t sidx)
{
- unsigned b = flow_hash_probe(c, sidx);
+ uint64_t hash = flow_sidx_hash(c, sidx);
+ unsigned b = flow_hash_probe_(hash, sidx);
flow_hashtab[b] = sidx;
flow_dbg(flow_at_sidx(sidx), "Side %u hash table insert: bucket: %u",
sidx.sidei, b);
+
+ return hash;
}
/**