Skip to content

Commit c0362b5

Browse files
ffmanceraummakynes
authored andcommitted
netfilter: nf_conncount: make nf_conncount_gc_list() to disable BH
For convenience when performing GC over the connection list, make nf_conncount_gc_list() to disable BH. This unifies the behavior with nf_conncount_add() and nf_conncount_count(). Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent be102eb commit c0362b5

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

net/netfilter/nf_conncount.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ void nf_conncount_list_init(struct nf_conncount_list *list)
278278
EXPORT_SYMBOL_GPL(nf_conncount_list_init);
279279

280280
/* Return true if the list is empty. Must be called with BH disabled. */
281-
bool nf_conncount_gc_list(struct net *net,
282-
struct nf_conncount_list *list)
281+
static bool __nf_conncount_gc_list(struct net *net,
282+
struct nf_conncount_list *list)
283283
{
284284
const struct nf_conntrack_tuple_hash *found;
285285
struct nf_conncount_tuple *conn, *conn_n;
@@ -291,10 +291,6 @@ bool nf_conncount_gc_list(struct net *net,
291291
if ((u32)jiffies == READ_ONCE(list->last_gc))
292292
return false;
293293

294-
/* don't bother if other cpu is already doing GC */
295-
if (!spin_trylock(&list->list_lock))
296-
return false;
297-
298294
list_for_each_entry_safe(conn, conn_n, &list->head, node) {
299295
found = find_or_evict(net, list, conn);
300296
if (IS_ERR(found)) {
@@ -323,7 +319,21 @@ bool nf_conncount_gc_list(struct net *net,
323319
if (!list->count)
324320
ret = true;
325321
list->last_gc = (u32)jiffies;
326-
spin_unlock(&list->list_lock);
322+
323+
return ret;
324+
}
325+
326+
bool nf_conncount_gc_list(struct net *net,
327+
struct nf_conncount_list *list)
328+
{
329+
bool ret;
330+
331+
/* don't bother if other cpu is already doing GC */
332+
if (!spin_trylock_bh(&list->list_lock))
333+
return false;
334+
335+
ret = __nf_conncount_gc_list(net, list);
336+
spin_unlock_bh(&list->list_lock);
327337

328338
return ret;
329339
}

net/netfilter/nft_connlimit.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,8 @@ static void nft_connlimit_destroy_clone(const struct nft_ctx *ctx,
223223
static bool nft_connlimit_gc(struct net *net, const struct nft_expr *expr)
224224
{
225225
struct nft_connlimit *priv = nft_expr_priv(expr);
226-
bool ret;
227226

228-
local_bh_disable();
229-
ret = nf_conncount_gc_list(net, priv->list);
230-
local_bh_enable();
231-
232-
return ret;
227+
return nf_conncount_gc_list(net, priv->list);
233228
}
234229

235230
static struct nft_expr_type nft_connlimit_type;

0 commit comments

Comments
 (0)