Skip to content

Commit

Permalink
netfilter: nft_set: introduce nft_{hash, rbtree}_deactivate_one()
Browse files Browse the repository at this point in the history
This new function allows us to deactivate one single element, this is
required by the set flush command that comes in a follow up patch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
ummakynes committed Dec 7, 2016
1 parent 1a37ef7 commit 37df530
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
24 changes: 17 additions & 7 deletions net/netfilter/nft_set_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ static void nft_hash_activate(const struct net *net, const struct nft_set *set,
nft_set_elem_clear_busy(&he->ext);
}

static bool nft_hash_deactivate_one(const struct net *net,
const struct nft_set *set, void *priv)
{
struct nft_hash_elem *he = priv;

if (!nft_set_elem_mark_busy(&he->ext) ||
!nft_is_active(net, &he->ext)) {
nft_set_elem_change_active(net, set, &he->ext);
return true;
}
return false;
}

static void *nft_hash_deactivate(const struct net *net,
const struct nft_set *set,
const struct nft_set_elem *elem)
Expand All @@ -181,13 +194,10 @@ static void *nft_hash_deactivate(const struct net *net,

rcu_read_lock();
he = rhashtable_lookup_fast(&priv->ht, &arg, nft_hash_params);
if (he != NULL) {
if (!nft_set_elem_mark_busy(&he->ext) ||
!nft_is_active(net, &he->ext))
nft_set_elem_change_active(net, set, &he->ext);
else
he = NULL;
}
if (he != NULL &&
!nft_hash_deactivate_one(net, set, he))
he = NULL;

rcu_read_unlock();

return he;
Expand Down
11 changes: 10 additions & 1 deletion net/netfilter/nft_set_rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ static void nft_rbtree_activate(const struct net *net,
nft_set_elem_change_active(net, set, &rbe->ext);
}

static bool nft_rbtree_deactivate_one(const struct net *net,
const struct nft_set *set, void *priv)
{
struct nft_rbtree_elem *rbe = priv;

nft_set_elem_change_active(net, set, &rbe->ext);
return true;
}

static void *nft_rbtree_deactivate(const struct net *net,
const struct nft_set *set,
const struct nft_set_elem *elem)
Expand Down Expand Up @@ -204,7 +213,7 @@ static void *nft_rbtree_deactivate(const struct net *net,
parent = parent->rb_right;
continue;
}
nft_set_elem_change_active(net, set, &rbe->ext);
nft_rbtree_deactivate_one(net, set, rbe);
return rbe;
}
}
Expand Down

0 comments on commit 37df530

Please sign in to comment.