From d27456460a2867d69a6bbed8aa0019f65ab42eac Mon Sep 17 00:00:00 2001 From: Alvaro Neira Date: Thu, 12 Mar 2015 17:33:09 +0100 Subject: ruleset: add nft_ruleset_ctx_free 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 Signed-off-by: Pablo Neira Ayuso --- src/libnftnl.map | 1 + src/ruleset.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/libnftnl.map b/src/libnftnl.map index 7c74fbc..c0b2031 100644 --- a/src/libnftnl.map +++ b/src/libnftnl.map @@ -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; diff --git a/src/ruleset.c b/src/ruleset.c index c8747b6..e7f9204 100644 --- a/src/ruleset.c +++ b/src/ruleset.c @@ -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); -- cgit v1.2.3