netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nf_tables PATCH 1/6 v5] netfilter: nf_tables: refactor rule deletion helper
@ 2014-09-02 14:42 Arturo Borrero Gonzalez
  2014-09-02 14:42 ` [nft PATCH 6/6] src: add `flush ruleset' Arturo Borrero Gonzalez
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Arturo Borrero Gonzalez @ 2014-09-02 14:42 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, kaber, Arturo Borrero Gonzalez

This helper function always schedule the rule to be removed in the following
transaction.
In follow-up patches, it is interesting to handle separately the logic of rule
activation/disactivation from the transaction mechanism.

So, this patch simply splits the original nf_tables_delrule_one() in two
functions, allowing further control.

While at it, for the sake of homigeneize the function naming scheme, let's
rename nf_tables_delrule_one() to nft_delrule().

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
v2: no changes, resending the series.
v3: change 'disactivate' and use 'deactivate'. Requested by Patrick.
v4: no changes, resending the series because v3 series is invalid.
v5: no changes, resending the series.

 net/netfilter/nf_tables_api.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index deeb95f..3664bab 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1868,12 +1868,10 @@ err1:
 }
 
 static int
-nf_tables_delrule_one(struct nft_ctx *ctx, struct nft_rule *rule)
+nf_tables_delrule_deactivate(struct nft_ctx *ctx, struct nft_rule *rule)
 {
 	/* You cannot delete the same rule twice */
 	if (nft_rule_is_active_next(ctx->net, rule)) {
-		if (nft_trans_rule_add(ctx, NFT_MSG_DELRULE, rule) == NULL)
-			return -ENOMEM;
 		nft_rule_disactivate_next(ctx->net, rule);
 		ctx->chain->use--;
 		return 0;
@@ -1881,13 +1879,31 @@ nf_tables_delrule_one(struct nft_ctx *ctx, struct nft_rule *rule)
 	return -ENOENT;
 }
 
+static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
+{
+	struct nft_trans *trans;
+	int err;
+
+	trans = nft_trans_rule_add(ctx, NFT_MSG_DELRULE, rule);
+	if (trans == NULL)
+		return -ENOMEM;
+
+	err = nf_tables_delrule_deactivate(ctx, rule);
+	if (err < 0) {
+		nft_trans_destroy(trans);
+		return err;
+	}
+
+	return 0;
+}
+
 static int nf_table_delrule_by_chain(struct nft_ctx *ctx)
 {
 	struct nft_rule *rule;
 	int err;
 
 	list_for_each_entry(rule, &ctx->chain->rules, list) {
-		err = nf_tables_delrule_one(ctx, rule);
+		err = nft_delrule(ctx, rule);
 		if (err < 0)
 			return err;
 	}
@@ -1932,7 +1948,7 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,
 			if (IS_ERR(rule))
 				return PTR_ERR(rule);
 
-			err = nf_tables_delrule_one(&ctx, rule);
+			err = nft_delrule(&ctx, rule);
 		} else {
 			err = nf_table_delrule_by_chain(&ctx);
 		}
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-09-09 15:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-02 14:42 [nf_tables PATCH 1/6 v5] netfilter: nf_tables: refactor rule deletion helper Arturo Borrero Gonzalez
2014-09-02 14:42 ` [nft PATCH 6/6] src: add `flush ruleset' Arturo Borrero Gonzalez
2014-09-02 14:42 ` [nf_tables PATCH 2/6 v5] netfilter: nf_tables: add helper to unregister chain hooks Arturo Borrero Gonzalez
2014-09-03  9:46   ` Pablo Neira Ayuso
2014-09-02 14:42 ` [nf_tables PATCH 3/6 v5] netfilter: nf_tables: rename nf_table_delrule_by_chain() Arturo Borrero Gonzalez
2014-09-03  9:46   ` Pablo Neira Ayuso
2014-09-02 14:42 ` [nf_tables PATCH 4/6 v5] netfilter: nf_tables: add helpers to schedule objects deletion Arturo Borrero Gonzalez
2014-09-02 15:20   ` Patrick McHardy
2014-09-02 15:47     ` Pablo Neira Ayuso
2014-09-09 14:04   ` Pablo Neira Ayuso
2014-09-02 14:42 ` [nf_tables PATCH 5/6 v5] netfilter: nf_tables: extend NFT_MSG_DELTABLE to support flushing the ruleset Arturo Borrero Gonzalez
2014-09-02 15:12   ` Patrick McHardy
2014-09-02 15:28     ` Pablo Neira Ayuso
2014-09-09 15:03   ` Pablo Neira Ayuso
2014-09-03  9:46 ` [nf_tables PATCH 1/6 v5] netfilter: nf_tables: refactor rule deletion helper Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).