]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: add 'list maps' support
authorPablo M. Bermudo Garay <pablombg@gmail.com>
Tue, 31 May 2016 10:37:06 +0000 (12:37 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 31 May 2016 10:42:05 +0000 (12:42 +0200)
This commit adds a new command that lists maps:

  # nft list maps [family]

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

Example:

  # nft list maps

  table ip filter {
          map test {
                  type ipv4_addr : inet_service
          }
  }
  table ip6 filter {
          map test {
                  type ipv6_addr : inet_service
          }
  }

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
src/scanner.l

index 7e8daac947eaee7c9a1a12c2263aefc6eaefe39b..d96f47476eaf40e647e13c56efd21ec88f54e59f 100644 (file)
@@ -318,6 +318,7 @@ enum cmd_obj {
        CMD_OBJ_EXPORT,
        CMD_OBJ_FLOWTABLE,
        CMD_OBJ_FLOWTABLES,
+       CMD_OBJ_MAPS,
 };
 
 struct export {
index cb4d2a56dcddba9678d6e75731b1d00a439afca8..ea1a63dc37f5b75fc1fbc9eb6b97e79f0c47c251 100644 (file)
@@ -2701,6 +2701,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_SETS:
        case CMD_OBJ_RULESET:
        case CMD_OBJ_FLOWTABLES:
+       case CMD_OBJ_MAPS:
                return 0;
        default:
                BUG("invalid command object type %u\n", cmd->obj);
index dfdf23777e747d839de2b08c6a05cdbea526c81c..59d7fd38b6d64d45fe5e969233b5e9e90e8a1518 100644 (file)
@@ -178,6 +178,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token SET                     "set"
 %token ELEMENT                 "element"
 %token MAP                     "map"
+%token MAPS                    "maps"
 %token HANDLE                  "handle"
 %token RULESET                 "ruleset"
 
@@ -844,6 +845,10 @@ list_cmd           :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_FLOWTABLE, &$3, &@$, NULL);
                        }
+                       |       MAPS            ruleset_spec
+                       {
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_MAPS, &$2, &@$, NULL);
+                       }
                        ;
 
 flush_cmd              :       TABLE           table_spec
index 5613f966e30dd314adbd9dfbf858d6311785ab87..38fd66458c2e567dd77d08047ef993df36f8e6ec 100644 (file)
@@ -1074,11 +1074,15 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
 
                list_for_each_entry(set, &table->sets, list) {
                        if (cmd->obj == CMD_OBJ_SETS &&
-                           set->flags & SET_F_ANONYMOUS)
+                           (set->flags & SET_F_ANONYMOUS ||
+                           set->flags & SET_F_MAP))
                                continue;
                        if (cmd->obj == CMD_OBJ_FLOWTABLES &&
                            !(set->flags & SET_F_EVAL))
                                continue;
+                       if (cmd->obj == CMD_OBJ_MAPS &&
+                           !(set->flags & SET_F_MAP))
+                               continue;
                        set_print_declaration(set, &opts);
                        printf("%s}%s", opts.tab, opts.nl);
                }
@@ -1216,6 +1220,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
                return do_list_sets(ctx, cmd);
        case CMD_OBJ_FLOWTABLE:
                return do_list_set(ctx, cmd, table);
+       case CMD_OBJ_MAPS:
+               return do_list_sets(ctx, cmd);
        default:
                BUG("invalid command object type %u\n", cmd->obj);
        }
index b0221145b479ffe1b5c9958656eacb8972e3c4bc..88669d0e6e5f66ce89301e5ea5d7fe0d1d1150c2 100644 (file)
@@ -245,6 +245,7 @@ addrstring  ({macaddr}|{ip4addr}|{ip6addr})
 "set"                  { return SET; }
 "element"              { return ELEMENT; }
 "map"                  { return MAP; }
+"maps"                 { return MAPS; }
 "handle"               { return HANDLE; }
 "ruleset"              { return RULESET; }