mirror of
https://passt.top/passt
synced 2025-06-17 04:35:35 +02:00
tcp, flow: Replace TCP specific hash function with general flow hash
Currently we match TCP packets received on the tap connection to a TCP connection via a hash table based on the forwarding address and both ports. We hope in future to allow for multiple guest side addresses, or for multiple interfaces which means we may need to distinguish based on the endpoint address and pif as well. We also want a unified hash table to cover multiple protocols, not just TCP. Replace the TCP specific hash function with one suitable for general flows, or rather for one side of a general flow. This includes all the information from struct flowside, plus the pif and the L4 protocol number. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
f19a8f71f9
commit
163a339214
4 changed files with 65 additions and 53 deletions
35
flow.c
35
flow.c
|
@ -116,9 +116,9 @@ static struct timespec flow_timer_run;
|
|||
* @faddr: Forwarding address (pointer to in_addr or in6_addr)
|
||||
* @fport: Forwarding port
|
||||
*/
|
||||
static void flowside_from_af(struct flowside *side, sa_family_t af,
|
||||
const void *eaddr, in_port_t eport,
|
||||
const void *faddr, in_port_t fport)
|
||||
void flowside_from_af(struct flowside *side, sa_family_t af,
|
||||
const void *eaddr, in_port_t eport,
|
||||
const void *faddr, in_port_t fport)
|
||||
{
|
||||
if (faddr)
|
||||
inany_from_af(&side->faddr, af, faddr);
|
||||
|
@ -401,6 +401,35 @@ void flow_alloc_cancel(union flow *flow)
|
|||
flow_new_entry = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* flow_hash() - Calculate hash value for one side of a flow
|
||||
* @c: Execution context
|
||||
* @proto: Protocol of this flow (IP L4 protocol number)
|
||||
* @pif: pif of the side to hash
|
||||
* @side: Flowside (must not have unspecified parts)
|
||||
*
|
||||
* Return: hash value
|
||||
*/
|
||||
uint64_t flow_hash(const struct ctx *c, uint8_t proto, uint8_t pif,
|
||||
const struct flowside *side)
|
||||
{
|
||||
struct siphash_state state = SIPHASH_INIT(c->hash_secret);
|
||||
|
||||
/* For the hash table to work, we need complete endpoint information,
|
||||
* and at least a forwarding port.
|
||||
*/
|
||||
ASSERT(pif != PIF_NONE && !inany_is_unspecified(&side->eaddr) &&
|
||||
side->eport != 0 && side->fport != 0);
|
||||
|
||||
inany_siphash_feed(&state, &side->faddr);
|
||||
inany_siphash_feed(&state, &side->eaddr);
|
||||
|
||||
return siphash_final(&state, 38, (uint64_t)proto << 40 |
|
||||
(uint64_t)pif << 32 |
|
||||
(uint64_t)side->fport << 16 |
|
||||
(uint64_t)side->eport);
|
||||
}
|
||||
|
||||
/**
|
||||
* flow_defer_handler() - Handler for per-flow deferred and timed tasks
|
||||
* @c: Execution context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue