]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
ruleset: add nft_ruleset_ctx_free
authorAlvaro Neira <alvaroneay@gmail.com>
Thu, 12 Mar 2015 16:33:09 +0000 (17:33 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 13 Mar 2015 11:18:20 +0000 (12:18 +0100)
This function releases the ruleset objects attached in the parse context
structure, ie. struct nft_parse_ctx.

Moreover, this patch updates the nft_parse_ruleset_file to use it.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
examples/nft-ruleset-parse-file.c
include/libnftnl/ruleset.h
src/libnftnl.map
src/ruleset.c

index 7d9086ba4f61a955b3d66a4af085e9c32736342d..cac7d0d07d4cfe5c399faf63f125101aa84b395f 100644 (file)
@@ -77,10 +77,8 @@ static int nft_ruleset_set_elems(const struct nft_parse_ctx *ctx)
        mnl_nlmsg_batch_next(batch);
 
        nft_set_elems_iter_destroy(iter_elems);
-       nft_set_free(set);
        return 0;
 err:
-       nft_set_free(set);
        return -1;
 }
 
@@ -125,7 +123,6 @@ static int nft_ruleset_set(const struct nft_parse_ctx *ctx)
        ret = nft_ruleset_set_elems(ctx);
        return ret;
 err:
-       nft_set_free(set);
        return -1;
 }
 
@@ -184,7 +181,6 @@ static int nft_ruleset_rule(const struct nft_parse_ctx *ctx)
                return -1;
 
        ret = nft_ruleset_rule_build_msg(ctx, cmd, rule);
-       nft_rule_free(rule);
 
        return ret;
 }
@@ -273,10 +269,8 @@ static int nft_ruleset_chain(const struct nft_parse_ctx *ctx)
        nft_chain_nlmsg_build_payload(nlh, chain);
        mnl_nlmsg_batch_next(batch);
 
-       nft_chain_free(chain);
        return 0;
 err:
-       nft_chain_free(chain);
        return -1;
 }
 
@@ -327,7 +321,6 @@ static int nft_ruleset_table(const struct nft_parse_ctx *ctx)
                return -1;
 
        ret = nft_ruleset_table_build_msg(ctx, cmd, table);
-       nft_table_free(table);
 
        return ret;
 }
@@ -377,6 +370,7 @@ static int ruleset_elems_cb(const struct nft_parse_ctx *ctx)
                return -1;
        }
 
+       nft_ruleset_ctx_free(ctx);
        return ret;
 }
 
index aa1d92d85109296c9301c4ab65e036a885036836..fe5e44f923acddc730e60cf7a229a2a4217136d9 100644 (file)
@@ -51,6 +51,7 @@ enum {
 };
 
 struct nft_parse_ctx;
+void nft_ruleset_ctx_free(const struct nft_parse_ctx *ctx);
 bool nft_ruleset_ctx_is_set(const struct nft_parse_ctx *ctx, uint16_t attr);
 void *nft_ruleset_ctx_get(const struct nft_parse_ctx *ctx, uint16_t attr);
 uint32_t nft_ruleset_ctx_get_u32(const struct nft_parse_ctx *ctx,
index 7c74fbc3b30a653808402573d4613db87f4f9519..c0b203104b36eb32cd707f6425f2b49b52e5fa59 100644 (file)
@@ -234,4 +234,5 @@ LIBNFTNL_1.2.0 {
   nft_ruleset_ctx_get_u32;
   nft_ruleset_parse_file_cb;
   nft_ruleset_parse_buffer_cb;
+  nft_ruleset_ctx_free;
 } LIBNFTNL_1.2;
index c8747b6c8d49224084c3fd70dd95f3b0d4514b3e..e7f9204caadec4e1ae73f4000080c97d5deb2a71 100644 (file)
@@ -157,6 +157,29 @@ void *nft_ruleset_attr_get(const struct nft_ruleset *r, uint16_t attr)
 }
 EXPORT_SYMBOL(nft_ruleset_attr_get);
 
+void nft_ruleset_ctx_free(const struct nft_parse_ctx *ctx)
+{
+       switch (ctx->type) {
+       case NFT_RULESET_TABLE:
+               nft_table_free(ctx->table);
+               break;
+       case NFT_RULESET_CHAIN:
+               nft_chain_free(ctx->chain);
+               break;
+       case NFT_RULESET_RULE:
+               nft_rule_free(ctx->rule);
+               break;
+       case NFT_RULESET_SET:
+       case NFT_RULESET_SET_ELEMS:
+               nft_set_free(ctx->set);
+               break;
+       case NFT_RULESET_RULESET:
+       case NFT_RULESET_UNSPEC:
+               break;
+       }
+}
+EXPORT_SYMBOL(nft_ruleset_ctx_free);
+
 bool nft_ruleset_ctx_is_set(const struct nft_parse_ctx *ctx, uint16_t attr)
 {
        return ctx->flags & (1 << attr);