mirror of
https://passt.top/passt
synced 2024-11-09 14:19:56 +00:00
flow: Add flow_sidx_valid() helper
To implement the TCP hash table, we need an invalid (NULL-like) value for flow_sidx_t. We use FLOW_SIDX_NONE for that, but for defensiveness, we treat (usually) anything with an out of bounds flow index the same way. That's not always done consistently though. In flow_at_sidx() we open code a check on the flow index. In tcp_hash_probe() we instead compare against FLOW_SIDX_NONE, and in some other places we use the fact that flow_at_sidx() will return NULL in this case, even if we don't otherwise need the flow it returns. Clean this up a bit, by adding an explicit flow_sidx_valid() test function. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
74c1c5efcf
commit
8f8eb73482
11
flow.h
11
flow.h
@ -176,6 +176,17 @@ static_assert(sizeof(flow_sidx_t) <= sizeof(uint32_t),
|
|||||||
|
|
||||||
#define FLOW_SIDX_NONE ((flow_sidx_t){ .flow = FLOW_MAX })
|
#define FLOW_SIDX_NONE ((flow_sidx_t){ .flow = FLOW_MAX })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flow_sidx_valid() - Test if a sidx is valid
|
||||||
|
* @sidx: sidx value
|
||||||
|
*
|
||||||
|
* Return: true if @sidx refers to a valid flow & side
|
||||||
|
*/
|
||||||
|
static inline bool flow_sidx_valid(flow_sidx_t sidx)
|
||||||
|
{
|
||||||
|
return sidx.flow < FLOW_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* flow_sidx_eq() - Test if two sidx values are equal
|
* flow_sidx_eq() - Test if two sidx values are equal
|
||||||
* @a, @b: sidx values
|
* @a, @b: sidx values
|
||||||
|
@ -73,7 +73,7 @@ static inline unsigned flow_idx(const struct flow_common *f)
|
|||||||
*/
|
*/
|
||||||
static inline union flow *flow_at_sidx(flow_sidx_t sidx)
|
static inline union flow *flow_at_sidx(flow_sidx_t sidx)
|
||||||
{
|
{
|
||||||
if (sidx.flow >= FLOW_MAX)
|
if (!flow_sidx_valid(sidx))
|
||||||
return NULL;
|
return NULL;
|
||||||
return FLOW(sidx.flow);
|
return FLOW(sidx.flow);
|
||||||
}
|
}
|
||||||
|
7
tcp.c
7
tcp.c
@ -880,8 +880,7 @@ static inline unsigned tcp_hash_probe(const struct ctx *c,
|
|||||||
flow_sidx_t sidx = FLOW_SIDX(conn, TAPSIDE(conn));
|
flow_sidx_t sidx = FLOW_SIDX(conn, TAPSIDE(conn));
|
||||||
|
|
||||||
/* Linear probing */
|
/* Linear probing */
|
||||||
while (!flow_sidx_eq(tc_hash[b], FLOW_SIDX_NONE) &&
|
while (flow_sidx_valid(tc_hash[b]) && !flow_sidx_eq(tc_hash[b], sidx))
|
||||||
!flow_sidx_eq(tc_hash[b], sidx))
|
|
||||||
b = mod_sub(b, 1, TCP_HASH_TABLE_SIZE);
|
b = mod_sub(b, 1, TCP_HASH_TABLE_SIZE);
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
@ -909,9 +908,9 @@ static void tcp_hash_remove(const struct ctx *c,
|
|||||||
const struct tcp_tap_conn *conn)
|
const struct tcp_tap_conn *conn)
|
||||||
{
|
{
|
||||||
unsigned b = tcp_hash_probe(c, conn), s;
|
unsigned b = tcp_hash_probe(c, conn), s;
|
||||||
union flow *flow = flow_at_sidx(tc_hash[b]);
|
union flow *flow;
|
||||||
|
|
||||||
if (!flow)
|
if (!flow_sidx_valid(tc_hash[b]))
|
||||||
return; /* Redundant remove */
|
return; /* Redundant remove */
|
||||||
|
|
||||||
flow_dbg(conn, "hash table remove: sock %i, bucket: %u", conn->sock, b);
|
flow_dbg(conn, "hash table remove: sock %i, bucket: %u", conn->sock, b);
|
||||||
|
Loading…
Reference in New Issue
Block a user