]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netfilter: ctnetlink: remove expired entries first
authorFlorian Westphal <fw@strlen.de>
Thu, 9 Dec 2021 16:39:26 +0000 (17:39 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 16 Dec 2021 13:10:52 +0000 (14:10 +0100)
When dumping conntrack table to userspace via ctnetlink, check if the ct has
already expired before doing any of the 'skip' checks.

This expires dead entries faster.
/proc handler also removes outdated entries first.

Reported-by: Vitaly Zuevsky <vzuevsky@ns1.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conntrack_netlink.c

index 81d03acf68d4df95c65642d89aa03a418fd8fc9f..ec4164c32d27034284e7415c3668b77a8f9e0dbe 100644 (file)
@@ -1195,8 +1195,6 @@ restart:
                }
                hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[cb->args[0]],
                                           hnnode) {
-                       if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-                               continue;
                        ct = nf_ct_tuplehash_to_ctrack(h);
                        if (nf_ct_is_expired(ct)) {
                                if (i < ARRAY_SIZE(nf_ct_evict) &&
@@ -1208,6 +1206,9 @@ restart:
                        if (!net_eq(net, nf_ct_net(ct)))
                                continue;
 
+                       if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
+                               continue;
+
                        if (cb->args[1]) {
                                if (ct != last)
                                        continue;