]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: add support for display maps content
authorPablo M. Bermudo Garay <pablombg@gmail.com>
Tue, 31 May 2016 10:37:07 +0000 (12:37 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 31 May 2016 10:42:13 +0000 (12:42 +0200)
This commit adds a new command that displays the definition of a single
map:

  # nft list map [family] <table> <map>

If no family is specified, ip is assumed.

Example:

  # nft list map ip6 filter test

  table ip6 filter {
          map test {
                  type ipv6_addr : inet_service
                  elements = { 2001:db8::ff00:42:8329 : http}
          }
  }

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 d96f47476eaf40e647e13c56efd21ec88f54e59f..99e92ee8672819e364d4acdf24b2f09268a5f5f0 100644 (file)
@@ -318,6 +318,7 @@ enum cmd_obj {
        CMD_OBJ_EXPORT,
        CMD_OBJ_FLOWTABLE,
        CMD_OBJ_FLOWTABLES,
+       CMD_OBJ_MAP,
        CMD_OBJ_MAPS,
 };
 
index ea1a63dc37f5b75fc1fbc9eb6b97e79f0c47c251..423523fe99dcf1671554c053a61e24dafc3b1f52 100644 (file)
@@ -2688,6 +2688,16 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
                        return cmd_error(ctx, "Could not process rule: Flow table '%s' does not exist",
                                         cmd->handle.set);
                return 0;
+       case CMD_OBJ_MAP:
+               table = table_lookup(&cmd->handle);
+               if (table == NULL)
+                       return cmd_error(ctx, "Could not process rule: Table '%s' does not exist",
+                                        cmd->handle.table);
+               set = set_lookup(table, cmd->handle.set);
+               if (set == NULL || !(set->flags & SET_F_MAP))
+                       return cmd_error(ctx, "Could not process rule: Map '%s' does not exist",
+                                        cmd->handle.set);
+               return 0;
        case CMD_OBJ_CHAIN:
                table = table_lookup(&cmd->handle);
                if (table == NULL)
index 59d7fd38b6d64d45fe5e969233b5e9e90e8a1518..d7cba238de890b8802f9a34a446740d0f39e474b 100644 (file)
@@ -849,6 +849,10 @@ list_cmd           :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_MAPS, &$2, &@$, NULL);
                        }
+                       |       MAP             set_spec
+                       {
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_MAP, &$2, &@$, NULL);
+                       }
                        ;
 
 flush_cmd              :       TABLE           table_spec
index 38fd66458c2e567dd77d08047ef993df36f8e6ec..14e57f296fe4a701d18131a96cc973090c13fb4d 100644 (file)
@@ -1222,6 +1222,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
                return do_list_set(ctx, cmd, table);
        case CMD_OBJ_MAPS:
                return do_list_sets(ctx, cmd);
+       case CMD_OBJ_MAP:
+               return do_list_set(ctx, cmd, table);
        default:
                BUG("invalid command object type %u\n", cmd->obj);
        }