Skip to content

Commit 5c789e1

Browse files
YiHungWeiummakynes
authored andcommitted
netfilter: nf_conncount: Add list lock and gc worker, and RCU for init tree search
This patch is originally from Florian Westphal. This patch does the following 3 main tasks. 1) Add list lock to 'struct nf_conncount_list' so that we can alter the lists containing the individual connections without holding the main tree lock. It would be useful when we only need to add/remove to/from a list without allocate/remove a node in the tree. With this change, we update nft_connlimit accordingly since we longer need to maintain a list lock in nft_connlimit now. 2) Use RCU for the initial tree search to improve tree look up performance. 3) Add a garbage collection worker. This worker is schedule when there are excessive tree node that needed to be recycled. Moreover,the rbnode reclaim logic is moved from search tree to insert tree to avoid race condition. Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 34848d5 commit 5c789e1

File tree

3 files changed

+196
-91
lines changed

3 files changed

+196
-91
lines changed

include/net/netfilter/nf_conntrack_count.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55

66
struct nf_conncount_data;
77

8+
enum nf_conncount_list_add {
9+
NF_CONNCOUNT_ADDED, /* list add was ok */
10+
NF_CONNCOUNT_ERR, /* -ENOMEM, must drop skb */
11+
NF_CONNCOUNT_SKIP, /* list is already reclaimed by gc */
12+
};
13+
814
struct nf_conncount_list {
15+
spinlock_t list_lock;
916
struct list_head head; /* connections with the same filtering key */
1017
unsigned int count; /* length of list */
18+
bool dead;
1119
};
1220

1321
struct nf_conncount_data *nf_conncount_init(struct net *net, unsigned int family,
@@ -28,11 +36,12 @@ void nf_conncount_lookup(struct net *net, struct nf_conncount_list *list,
2836

2937
void nf_conncount_list_init(struct nf_conncount_list *list);
3038

31-
bool nf_conncount_add(struct nf_conncount_list *list,
32-
const struct nf_conntrack_tuple *tuple,
33-
const struct nf_conntrack_zone *zone);
39+
enum nf_conncount_list_add
40+
nf_conncount_add(struct nf_conncount_list *list,
41+
const struct nf_conntrack_tuple *tuple,
42+
const struct nf_conntrack_zone *zone);
3443

35-
void nf_conncount_gc_list(struct net *net,
44+
bool nf_conncount_gc_list(struct net *net,
3645
struct nf_conncount_list *list);
3746

3847
void nf_conncount_cache_free(struct nf_conncount_list *list);

0 commit comments

Comments
 (0)