netfilter: conntrack: use siphash_4u64
[platform/kernel/linux-starfive.git] / net / netfilter / nf_conntrack_core.c
index f97bda0..057ebdc 100644 (file)
@@ -211,28 +211,24 @@ static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple,
                              unsigned int zoneid,
                              const struct net *net)
 {
-       struct {
-               struct nf_conntrack_man src;
-               union nf_inet_addr dst_addr;
-               unsigned int zone;
-               u32 net_mix;
-               u16 dport;
-               u16 proto;
-       } __aligned(SIPHASH_ALIGNMENT) combined;
+       u64 a, b, c, d;
 
        get_random_once(&nf_conntrack_hash_rnd, sizeof(nf_conntrack_hash_rnd));
 
-       memset(&combined, 0, sizeof(combined));
+       /* The direction must be ignored, handle usable tuplehash members manually */
+       a = (u64)tuple->src.u3.all[0] << 32 | tuple->src.u3.all[3];
+       b = (u64)tuple->dst.u3.all[0] << 32 | tuple->dst.u3.all[3];
 
-       /* The direction must be ignored, so handle usable members manually. */
-       combined.src = tuple->src;
-       combined.dst_addr = tuple->dst.u3;
-       combined.zone = zoneid;
-       combined.net_mix = net_hash_mix(net);
-       combined.dport = (__force __u16)tuple->dst.u.all;
-       combined.proto = tuple->dst.protonum;
+       c = (__force u64)tuple->src.u.all << 32 | (__force u64)tuple->dst.u.all << 16;
+       c |= tuple->dst.protonum;
 
-       return (u32)siphash(&combined, sizeof(combined), &nf_conntrack_hash_rnd);
+       d = (u64)zoneid << 32 | net_hash_mix(net);
+
+       /* IPv4: u3.all[1,2,3] == 0 */
+       c ^= (u64)tuple->src.u3.all[1] << 32 | tuple->src.u3.all[2];
+       d += (u64)tuple->dst.u3.all[1] << 32 | tuple->dst.u3.all[2];
+
+       return (u32)siphash_4u64(a, b, c, d, &nf_conntrack_hash_rnd);
 }
 
 static u32 scale_hash(u32 hash)