src: simplify chain_alloc()
Pablo Neira Ayuso
maintainerPATCH 1/2 src: simplify chain_alloc()
Remove parameter to set the chain name which is only used from netlink path.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/rule.h | 2 +- src/evaluate.c | 2 +- src/netlink.c | 4 +++- src/parser_bison.y | 2 +- src/parser_json.c | 4 ++-- src/rule.c | 4 +--- 6 files changed, 9 insertions(+), 9 deletions(-)
include/rule.h +1 -1
@@ -260,7 +260,7 @@ struct chain {extern int std_prio_lookup (const char *std_prio_name,int family,int hook);extern const char *chain_type_name_lookup (const char *name);extern const char *chain_hookname_lookup (const char *name); -extern struct chain *chain_alloc (const char *name); +extern struct chain *chain_alloc (void );extern struct chain *chain_get (struct chain *chain);extern void chain_free (struct chain *chain); extern struct chain *chain_lookup_fuzzy(const struct handle *h,
src/evaluate.c +1 -1
@@ -5005,7 +5005,7 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)if (chain ==NULL ) {if (!chain_cache_find (table, ctx->cmd->handle.chain.name)) { - chain =chain_alloc (NULL ); + chain =chain_alloc ();handle_merge (&chain->handle, &ctx->cmd->handle);chain_cache_add (chain, table); }
src/netlink.c +3 -1
@@ -626,11 +626,13 @@ struct chain *netlink_delinearize_chain(struct netlink_ctx *ctx,const char *udata;uint32_t ulen; - chain =chain_alloc (nftnl_chain_get_str (nlc,NFTNL_CHAIN_NAME )); + chain =chain_alloc (); chain->handle.family =nftnl_chain_get_u32 (nlc,NFTNL_CHAIN_FAMILY ); chain->handle.table.name =xstrdup (nftnl_chain_get_str (nlc,NFTNL_CHAIN_TABLE )); + chain->handle.chain.name = +xstrdup (nftnl_chain_get_str (nlc,NFTNL_CHAIN_NAME )); chain->handle.handle.id =nftnl_chain_get_u64 (nlc,NFTNL_CHAIN_HANDLE );if (nftnl_chain_is_set (nlc,NFTNL_CHAIN_FLAGS ))
src/parser_bison.y +1 -1
@@ -2029,7 +2029,7 @@ table_block : /* empty */ { $$ = $<table>-1; } chain_block_alloc : /* empty */ { - $$ = chain_alloc(NULL); + $$ = chain_alloc(); if (open_scope(state, &$$->scope) < 0) { erec_queue(error(&@$, "too many levels of nesting"), state->msgs);
src/parser_json.c +2 -2
@@ -2965,7 +2965,7 @@ static struct cmd *json_parse_cmd_add_chain(struct json_ctx *ctx, json_t *root, h.chain.name =xstrdup (h.chain.name);if (comment) { - chain =chain_alloc (NULL ); + chain =chain_alloc ();handle_merge (&chain->handle, &h); chain->comment =xstrdup (comment); }
@@ -2978,7 +2978,7 @@ static struct cmd *json_parse_cmd_add_chain(struct json_ctx *ctx, json_t *root,return cmd_alloc (op, obj, &h, int_loc, chain);if (!chain) - chain =chain_alloc (NULL ); + chain =chain_alloc (); chain->flags |=CHAIN_F_BASECHAIN ; chain->type.str =xstrdup (type);
src/rule.c +1 -3
@@ -700,7 +700,7 @@ const char *chain_hookname_lookup(const char *name)/* internal ID to uniquely identify a set in the batch */ static uint32_t chain_id; -struct chain *chain_alloc (const char *name) +struct chain *chain_alloc (void ) {struct chain *chain;
@@ -709,8 +709,6 @@ struct chain *chain_alloc(const char *name) chain->handle.chain_id = ++chain_id;init_list_head (&chain->rules);init_list_head (&chain->scope.symbols); -if (name !=NULL ) - chain->handle.chain.name =xstrdup (name); chain->policy =NULL ;return chain;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/2 rule: set internal_location for table and chain
JSON parser does not seem to set on this, better provide a default location.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/rule.c | 2 ++ 1 file changed, 2 insertions(+)
src/rule.c +2 -0
@@ -705,6 +705,7 @@ struct chain *chain_alloc(void)struct chain *chain; chain =xzalloc (sizeof (*chain)); + chain->location = internal_location; chain->refcnt =1 ; chain->handle.chain_id = ++chain_id;init_list_head (&chain->rules);
@@ -1125,6 +1126,7 @@ struct table *table_alloc(void)struct table *table; table =xzalloc (sizeof (*table)); + table->location = internal_location;init_list_head (&table->chains);init_list_head (&table->sets);init_list_head (&table->objs);
Signature · 1 line
2.30.2