Merge tag 'for-linus-20190524' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / net / netfilter / nf_flow_table_core.c
index 7aabfd4..948b4eb 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -185,14 +186,25 @@ static const struct rhashtable_params nf_flow_offload_rhash_params = {
 
 int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
 {
-       flow->timeout = (u32)jiffies;
+       int err;
 
-       rhashtable_insert_fast(&flow_table->rhashtable,
-                              &flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
-                              nf_flow_offload_rhash_params);
-       rhashtable_insert_fast(&flow_table->rhashtable,
-                              &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
-                              nf_flow_offload_rhash_params);
+       err = rhashtable_insert_fast(&flow_table->rhashtable,
+                                    &flow->tuplehash[0].node,
+                                    nf_flow_offload_rhash_params);
+       if (err < 0)
+               return err;
+
+       err = rhashtable_insert_fast(&flow_table->rhashtable,
+                                    &flow->tuplehash[1].node,
+                                    nf_flow_offload_rhash_params);
+       if (err < 0) {
+               rhashtable_remove_fast(&flow_table->rhashtable,
+                                      &flow->tuplehash[0].node,
+                                      nf_flow_offload_rhash_params);
+               return err;
+       }
+
+       flow->timeout = (u32)jiffies;
        return 0;
 }
 EXPORT_SYMBOL_GPL(flow_offload_add);
@@ -232,6 +244,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
 {
        struct flow_offload_tuple_rhash *tuplehash;
        struct flow_offload *flow;
+       struct flow_offload_entry *e;
        int dir;
 
        tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
@@ -244,6 +257,10 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
        if (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN))
                return NULL;
 
+       e = container_of(flow, struct flow_offload_entry, flow);
+       if (unlikely(nf_ct_is_dying(e->ct)))
+               return NULL;
+
        return tuplehash;
 }
 EXPORT_SYMBOL_GPL(flow_offload_lookup);
@@ -290,8 +307,10 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)
 static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
 {
        struct nf_flowtable *flow_table = data;
+       struct flow_offload_entry *e;
 
-       if (nf_flow_has_expired(flow) ||
+       e = container_of(flow, struct flow_offload_entry, flow);
+       if (nf_flow_has_expired(flow) || nf_ct_is_dying(e->ct) ||
            (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN)))
                flow_offload_del(flow_table, flow);
 }