]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: add 'list flow tables' support
authorPablo M. Bermudo Garay <pablombg@gmail.com>
Thu, 19 May 2016 12:46:03 +0000 (14:46 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 20 May 2016 09:40:01 +0000 (11:40 +0200)
This commit adds a new command that lists flow tables:

    # nft list flow tables [family]

Only the declaration is displayed. If no family is specified, all flow
tables of all families are listed.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/rule.h
src/evaluate.c
src/parser_bison.y
src/rule.c

index bfe398d6cf9b9a170a942b4efaae091feecfc596..ae77c4c16eaf81a36004d109fad0c1be68362ccc 100644 (file)
@@ -316,6 +316,7 @@ enum cmd_obj {
        CMD_OBJ_EXPR,
        CMD_OBJ_MONITOR,
        CMD_OBJ_EXPORT,
+       CMD_OBJ_FLOWTABLES,
 };
 
 struct export {
index c317761fba5136389282c98627a2693903524cd5..3600ad0083a5e55a3054c35dad4669bee71fc871 100644 (file)
@@ -2689,6 +2689,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_CHAINS:
        case CMD_OBJ_SETS:
        case CMD_OBJ_RULESET:
+       case CMD_OBJ_FLOWTABLES:
                return 0;
        default:
                BUG("invalid command object type %u\n", cmd->obj);
index 76cf65cb4a822b0a330adc343a14ff35b09b53fa..c71f6df03d05d4314c0d8398dc22425fa8ffefd0 100644 (file)
@@ -836,6 +836,10 @@ list_cmd           :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_RULESET, &$2, &@$, NULL);
                        }
+                       |       FLOW TABLES     ruleset_spec
+                       {
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_FLOWTABLES, &$3, &@$, NULL);
+                       }
                        ;
 
 flush_cmd              :       TABLE           table_spec
index b2f58f434e426b3b642d2acd1515cf42eced05cd..1bc5c6851ac1a33867c3aa20203716245cdc68e9 100644 (file)
@@ -258,7 +258,13 @@ static void set_print_declaration(const struct set *set,
        const char *type;
        uint32_t flags;
 
-       type = set->flags & SET_F_MAP ? "map" : "set";
+       if (set->flags & SET_F_MAP)
+               type = "map";
+       else if (set->flags & SET_F_EVAL)
+               type = "flow table";
+       else
+               type = "set";
+
        printf("%s%s", opts->tab, type);
 
        if (opts->family != NULL)
@@ -1067,7 +1073,11 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
                       table->handle.table);
 
                list_for_each_entry(set, &table->sets, list) {
-                       if (set->flags & SET_F_ANONYMOUS)
+                       if (cmd->obj == CMD_OBJ_SETS &&
+                           set->flags & SET_F_ANONYMOUS)
+                               continue;
+                       if (cmd->obj == CMD_OBJ_FLOWTABLES &&
+                           !(set->flags & SET_F_EVAL))
                                continue;
                        set_print_declaration(set, &opts);
                        printf("%s}%s", opts.tab, opts.nl);
@@ -1202,6 +1212,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
                return do_list_set(ctx, cmd, table);
        case CMD_OBJ_RULESET:
                return do_list_ruleset(ctx, cmd);
+       case CMD_OBJ_FLOWTABLES:
+               return do_list_sets(ctx, cmd);
        default:
                BUG("invalid command object type %u\n", cmd->obj);
        }