]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: missing object maps handling in list and flush commands
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 11 Jul 2019 13:49:09 +0000 (15:49 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 16 Jul 2019 17:53:43 +0000 (19:53 +0200)
NFT_SET_OBJECT tells there is an object map.

 # nft list ruleset
 table inet filter {
        map countermap {
                type ipv4_addr : counter
        }
 }

The following command fails:

 # nft flush set inet filter countermap

This patch checks for NFT_SET_OBJECT from new set_is_literal() and
map_is_literal() functions. This patch also adds tests for this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/rule.h
src/evaluate.c
tests/shell/testcases/listing/0017objects_0 [new file with mode: 0755]
tests/shell/testcases/listing/0018data_0 [new file with mode: 0755]
tests/shell/testcases/listing/0019set_0 [new file with mode: 0755]

index bee1d44742165a8a93254601791d8214e7fc308d..42d29b7c910e659d608ca79c36b48750feb5f0f9 100644 (file)
@@ -337,6 +337,21 @@ static inline bool set_is_map(uint32_t set_flags)
        return set_is_datamap(set_flags) || set_is_objmap(set_flags);
 }
 
+static inline bool set_is_anonymous(uint32_t set_flags)
+{
+       return set_flags & NFT_SET_ANONYMOUS;
+}
+
+static inline bool set_is_literal(uint32_t set_flags)
+{
+       return !(set_is_anonymous(set_flags) || set_is_map(set_flags));
+}
+
+static inline bool map_is_literal(uint32_t set_flags)
+{
+       return !(set_is_anonymous(set_flags) || !set_is_map(set_flags));
+}
+
 #include <statement.h>
 
 struct counter {
index e1a827e723aef01e6be2205483b0624c9fb360fb..f915187165ccf13ee663733421c06b75f0be7e12 100644 (file)
@@ -3630,8 +3630,8 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
                if (set == NULL)
                        return set_not_found(ctx, &ctx->cmd->handle.set.location,
                                             ctx->cmd->handle.set.name);
-               else if (set->flags & (NFT_SET_MAP | NFT_SET_ANONYMOUS))
-                       return cmd_error(ctx,  &ctx->cmd->handle.set.location,
+               else if (!set_is_literal(set->flags))
+                       return cmd_error(ctx, &ctx->cmd->handle.set.location,
                                         "%s", strerror(ENOENT));
 
                return 0;
@@ -3659,8 +3659,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
                if (set == NULL)
                        return set_not_found(ctx, &ctx->cmd->handle.set.location,
                                             ctx->cmd->handle.set.name);
-               else if (!(set->flags & NFT_SET_MAP) ||
-                        set->flags & NFT_SET_ANONYMOUS)
+               else if (!map_is_literal(set->flags))
                        return cmd_error(ctx, &ctx->cmd->handle.set.location,
                                         "%s", strerror(ENOENT));
 
@@ -3752,10 +3751,9 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
                if (set == NULL)
                        return set_not_found(ctx, &ctx->cmd->handle.set.location,
                                             ctx->cmd->handle.set.name);
-               else if (set->flags & (NFT_SET_MAP | NFT_SET_ANONYMOUS))
+               else if (!set_is_literal(set->flags))
                        return cmd_error(ctx, &ctx->cmd->handle.set.location,
                                         "%s", strerror(ENOENT));
-
                return 0;
        case CMD_OBJ_MAP:
                table = table_lookup(&cmd->handle, &ctx->nft->cache);
@@ -3766,8 +3764,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
                if (set == NULL)
                        return set_not_found(ctx, &ctx->cmd->handle.set.location,
                                             ctx->cmd->handle.set.name);
-               else if (!(set->flags & NFT_SET_MAP) ||
-                        set->flags & NFT_SET_ANONYMOUS)
+               else if (!map_is_literal(set->flags))
                        return cmd_error(ctx, &ctx->cmd->handle.set.location,
                                         "%s", strerror(ENOENT));
 
diff --git a/tests/shell/testcases/listing/0017objects_0 b/tests/shell/testcases/listing/0017objects_0
new file mode 100755 (executable)
index 0000000..14d6143
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+EXPECTED="table inet filter {
+       map countermap {
+               type ipv4_addr : counter
+       }
+}"
+
+set -e
+
+$NFT -f - <<< $EXPECTED
+$NFT flush map inet filter countermap
+
+GET="$($NFT list map inet filter countermap)"
+if [ "$EXPECTED" != "$GET" ] ; then
+       DIFF="$(which diff)"
+       [ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET")
+       exit 1
+fi
diff --git a/tests/shell/testcases/listing/0018data_0 b/tests/shell/testcases/listing/0018data_0
new file mode 100755 (executable)
index 0000000..767fe13
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+EXPECTED="table inet filter {
+       map ipmap {
+               type ipv4_addr : ipv4_addr
+       }
+}"
+
+set -e
+
+$NFT -f - <<< $EXPECTED
+$NFT flush map inet filter ipmap
+
+GET="$($NFT list map inet filter ipmap)"
+if [ "$EXPECTED" != "$GET" ] ; then
+       DIFF="$(which diff)"
+       [ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET")
+       exit 1
+fi
diff --git a/tests/shell/testcases/listing/0019set_0 b/tests/shell/testcases/listing/0019set_0
new file mode 100755 (executable)
index 0000000..04eb0fa
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+EXPECTED="table inet filter {
+       set ipset {
+               type ipv4_addr
+       }
+}"
+
+set -e
+
+$NFT -f - <<< $EXPECTED
+$NFT flush set inet filter ipset
+
+GET="$($NFT list set inet filter ipset)"
+if [ "$EXPECTED" != "$GET" ] ; then
+       DIFF="$(which diff)"
+       [ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET")
+       exit 1
+fi