forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.h
37 lines (31 loc) · 930 Bytes
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2020 Authors of Cilium */
#ifndef __HASH_H_
#define __HASH_H_
#include "common.h"
#include "jhash.h"
/* The daddr is explicitly excluded from the hash here in order to allow for
* backend selection to choose the same backend even on different service VIPs.
*/
static __always_inline __u32 hash_from_tuple_v4(const struct ipv4_ct_tuple *tuple)
{
return jhash_3words(tuple->saddr,
((__u32)tuple->dport << 16) | tuple->sport,
tuple->nexthdr, HASH_INIT4_SEED);
}
static __always_inline __u32 hash_from_tuple_v6(const struct ipv6_ct_tuple *tuple)
{
__u32 a, b, c;
a = tuple->saddr.p1;
b = tuple->saddr.p2;
c = tuple->saddr.p3;
__jhash_mix(a, b, c);
a += tuple->saddr.p4;
b += ((__u32)tuple->dport << 16) | tuple->sport;
c += tuple->nexthdr;
__jhash_mix(a, b, c);
a += HASH_INIT6_SEED;
__jhash_final(a, b, c);
return c;
}
#endif /* __HASH_H_ */