netfilter: nf_conncount: merge lookup and add functions
authorFlorian Westphal <fw@strlen.de>
Fri, 28 Dec 2018 00:24:46 +0000 (01:24 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Jan 2019 20:40:29 +0000 (21:40 +0100)
commitbdc6c893ba378a1b391ddbb4acea24047b6373d0
treec1e7044b89dffdbdf68fe60ee0f541c601f3c30b
parent13c639424bc2eeacd1348bfbe17efd5fa275b119
netfilter: nf_conncount: merge lookup and add functions

commit df4a902509766897f7371fdfa4c3bf8bc321b55d upstream.

'lookup' is always followed by 'add'.
Merge both and make the list-walk part of nf_conncount_add().

This also avoids one unneeded unlock/re-lock pair.

Extra care needs to be taken in count_tree, as we only hold rcu
read lock, i.e. we can only insert to an existing tree node after
acquiring its lock and making sure it has a nonzero count.

As a zero count should be rare, just fall back to insert_tree()
(which acquires tree lock).

This issue and its solution were pointed out by Shawn Bohrer
during patch review.

Reviewed-by: Shawn Bohrer <sbohrer@cloudflare.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/net/netfilter/nf_conntrack_count.h
net/netfilter/nf_conncount.c
net/netfilter/nft_connlimit.c