]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netfilter: flowtable: add hash offset field to tuple
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 25 Jan 2021 17:56:01 +0000 (18:56 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 26 Jan 2021 00:10:07 +0000 (01:10 +0100)
Add a placeholder field to calculate hash tuple offset. Similar to
89c365785ff0 ("netfilter: conntrack: avoid gcc-10 zero-length-bounds
warning").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_flow_table.h
net/netfilter/nf_flow_table_core.c

index 16e8b2f8d006aaefc2a7f3d54d507e9499c0abed..54c4d5c908a5282acaca82e7df6d53b1eef66cfd 100644 (file)
@@ -107,6 +107,10 @@ struct flow_offload_tuple {
 
        u8                              l3proto;
        u8                              l4proto;
+
+       /* All members above are keys for lookups, see flow_offload_hash(). */
+       struct { }                      __hash;
+
        u8                              dir;
 
        u16                             mtu;
index 513f78db3cb2f0812956b06e89e329b3f6243700..55fca71ace262888ecb2aa961142260a9a4174c1 100644 (file)
@@ -191,14 +191,14 @@ static u32 flow_offload_hash(const void *data, u32 len, u32 seed)
 {
        const struct flow_offload_tuple *tuple = data;
 
-       return jhash(tuple, offsetof(struct flow_offload_tuple, dir), seed);
+       return jhash(tuple, offsetof(struct flow_offload_tuple, __hash), seed);
 }
 
 static u32 flow_offload_hash_obj(const void *data, u32 len, u32 seed)
 {
        const struct flow_offload_tuple_rhash *tuplehash = data;
 
-       return jhash(&tuplehash->tuple, offsetof(struct flow_offload_tuple, dir), seed);
+       return jhash(&tuplehash->tuple, offsetof(struct flow_offload_tuple, __hash), seed);
 }
 
 static int flow_offload_hash_cmp(struct rhashtable_compare_arg *arg,
@@ -207,7 +207,7 @@ static int flow_offload_hash_cmp(struct rhashtable_compare_arg *arg,
        const struct flow_offload_tuple *tuple = arg->key;
        const struct flow_offload_tuple_rhash *x = ptr;
 
-       if (memcmp(&x->tuple, tuple, offsetof(struct flow_offload_tuple, dir)))
+       if (memcmp(&x->tuple, tuple, offsetof(struct flow_offload_tuple, __hash)))
                return 1;
 
        return 0;