]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: simplify chain_alloc()
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 30 Aug 2023 15:03:13 +0000 (17:03 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 31 Aug 2023 14:38:14 +0000 (16:38 +0200)
Remove parameter to set the chain name which is only used from netlink
path.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/rule.h
src/evaluate.c
src/netlink.c
src/parser_bison.y
src/parser_json.c
src/rule.c

index 8e876d0a42ed5bf71cf6423b94da4a7db1500eaa..5ceb3ae62288d45f53cf4230650533ea46ca9cf5 100644 (file)
@@ -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,
index b5326d7df4ba2dee8c4d6a9ca1899d0db9bc1830..4c23bba3fdb3a395a5902eaff0be36c3b31b1dbb 100644 (file)
@@ -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);
                }
index 1afe162ec79bf926d839630522c4e14fa4fd7d9c..af6fd427bd571ec290a15ee928bfd7cbcf710535 100644 (file)
@@ -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))
index a248b335b01dbec80d967a4c9e029bc8f7e99a32..4a0c09a2912aa1740560f3485b39bf3bd4cafedb 100644 (file)
@@ -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);
index 01d42283961a3603c3947a364a410d95dca2b5d8..e8a175de8067638d222730d433f745eff437fe87 100644 (file)
@@ -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);
index 35f6d8f28aee6285ab1322c4176d977c53feb28f..fa4c72adab064fe5ac605a33b3db1364be99be03 100644 (file)
@@ -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;