]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: Allow passing the parent set to set_expr_alloc()
authorPhil Sutter <phil@nwl.cc>
Wed, 12 Jul 2017 12:14:16 +0000 (14:14 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 17 Jul 2017 15:29:32 +0000 (17:29 +0200)
Usually one wants to at least initialize set_flags from the parent, so
make allocation of a set's set expression more convenient.

The idea to do this came when fixing an issue with output formatting of
larger anonymous sets in nft monitor: Since
netlink_events_cache_addset() didn't initialize set_flags,
calculate_delim() didn't detect it's an anonymous set and therefore
added newlines to the output.

Reported-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Fixes: a9dc3ceabc10f ("expression: print sets and maps in pretty format")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/expression.h
src/evaluate.c
src/expression.c
src/netlink.c
src/parser_bison.y
src/rule.c

index 3e67938a639067ca3778c41dc578547e4b161616..68a36e8af792aa84b1ba014ba63168b5753f9c5c 100644 (file)
@@ -409,7 +409,8 @@ extern struct expr *concat_expr_alloc(const struct location *loc);
 
 extern struct expr *list_expr_alloc(const struct location *loc);
 
-extern struct expr *set_expr_alloc(const struct location *loc);
+extern struct expr *set_expr_alloc(const struct location *loc,
+                                  const struct set *set);
 extern int set_to_intervals(struct list_head *msgs, struct set *set,
                            struct expr *init, bool add);
 extern void interval_map_decompose(struct expr *set);
index db18df05ec997d1d22a492bb63d5e69053eacb9d..27feef432ccf2f3997f73682523bc1068ca68a9f 100644 (file)
@@ -1955,7 +1955,7 @@ static int stmt_evaluate_flow(struct eval_ctx *ctx, struct stmt *stmt)
 
        /* Declare an empty set */
        key = stmt->flow.key;
-       set = set_expr_alloc(&key->location);
+       set = set_expr_alloc(&key->location, NULL);
        set->set_flags |= NFT_SET_EVAL;
        if (key->timeout)
                set->set_flags |= NFT_SET_TIMEOUT;
index f90ca6035bd3a1bf71d94b0b610195f11a439770..d41ada39cc0ffb62529e6c3376a75290718aa1bb 100644 (file)
@@ -824,9 +824,17 @@ static const struct expr_ops set_expr_ops = {
        .destroy        = compound_expr_destroy,
 };
 
-struct expr *set_expr_alloc(const struct location *loc)
+struct expr *set_expr_alloc(const struct location *loc, const struct set *set)
 {
-       return compound_expr_alloc(loc, &set_expr_ops);
+       struct expr *set_expr = compound_expr_alloc(loc, &set_expr_ops);
+
+       if (!set)
+               return set_expr;
+
+       set_expr->set_flags = set->flags;
+       set_expr->dtype = set->keytype;
+
+       return set_expr;
 }
 
 static void mapping_expr_print(const struct expr *expr, struct output_ctx *octx)
index 7355036b5d9e2c582b9dc19718766d27a780d94c..e3c90dac8c7a6126f0ece588e67c6572f29013b9 100644 (file)
@@ -1734,10 +1734,8 @@ int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
        }
 
        ctx->set = set;
-       set->init = set_expr_alloc(loc);
+       set->init = set_expr_alloc(loc, set);
        nftnl_set_elem_foreach(nls, list_setelem_cb, ctx);
-       set->init->set_flags = set->flags;
-       set->init->dtype = set->keytype;
 
        if (!(set->flags & NFT_SET_INTERVAL))
                list_expr_sort(&ctx->set->init->expressions);
@@ -2234,7 +2232,7 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
                dummyset = set_alloc(monh->loc);
                dummyset->keytype = set->keytype;
                dummyset->datatype = set->datatype;
-               dummyset->init = set_expr_alloc(monh->loc);
+               dummyset->init = set_expr_alloc(monh->loc, set);
 
                nlsei = nftnl_set_elems_iter_create(nls);
                if (nlsei == NULL)
@@ -2432,7 +2430,7 @@ static void netlink_events_cache_addset(struct netlink_mon_handler *monh,
        s = netlink_delinearize_set(&set_tmpctx, nls);
        if (s == NULL)
                goto out;
-       s->init = set_expr_alloc(monh->loc);
+       s->init = set_expr_alloc(monh->loc, s);
 
        t = table_lookup(&s->handle);
        if (t == NULL) {
index 03b13720877a255c92cba58c6efc07de43c2e115..45b1dc9f94074774ffa8f6c49c71d01b77a9e4b4 100644 (file)
@@ -1796,7 +1796,7 @@ verdict_map_expr  :       '{'     verdict_map_list_expr   '}'
 
 verdict_map_list_expr  :       verdict_map_list_member_expr
                        {
-                               $$ = set_expr_alloc(&@$);
+                               $$ = set_expr_alloc(&@$, NULL);
                                compound_expr_add($$, $1);
                        }
                        |       verdict_map_list_expr   COMMA   verdict_map_list_member_expr
@@ -2581,7 +2581,7 @@ set_expr          :       '{'     set_list_expr           '}'
 
 set_list_expr          :       set_list_member_expr
                        {
-                               $$ = set_expr_alloc(&@$);
+                               $$ = set_expr_alloc(&@$, NULL);
                                compound_expr_add($$, $1);
                        }
                        |       set_list_expr           COMMA   set_list_member_expr
index 7a429bb2f1f2d51f07c821e4c91005ab79aec049..1d89feb9f192459ca76dcf14bca06772bd052470 100644 (file)
@@ -1629,7 +1629,7 @@ static int do_command_monitor(struct netlink_ctx *ctx, struct cmd *cmd)
 
                list_for_each_entry(t, &table_list, list) {
                        list_for_each_entry(s, &t->sets, list)
-                               s->init = set_expr_alloc(&cmd->location);
+                               s->init = set_expr_alloc(&cmd->location, s);
 
                        if (!(cmd->monitor->flags & (1 << NFT_MSG_TRACE)))
                                continue;