]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: allow to list of existing tables
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Apr 2013 10:28:25 +0000 (12:28 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Apr 2013 13:32:54 +0000 (15:32 +0200)
You can now specify: nft list tables ip

to obtain the list of all existing tables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/netlink.c
src/parser.y
src/rule.c
src/scanner.l

index 4c60c4a2ec8113bd3bfc77a5276e017a666a3b1c..e760ccc9c7fce953a07bb816947e0f1e9a50c167 100644 (file)
@@ -87,7 +87,8 @@ struct nfnl_nft_table *alloc_nft_table(const struct handle *h)
        if (nlt == NULL)
                memory_allocation_error();
        nfnl_nft_table_set_family(nlt, h->family);
-       nfnl_nft_table_set_name(nlt, h->table, strlen(h->table) + 1);
+       if (h->table != NULL)
+               nfnl_nft_table_set_name(nlt, h->table, strlen(h->table) + 1);
        return nlt;
 }
 
index fc72458822447419be6ea5b1996789147e099ea0..87602d9f97a4b757c3e7ecc83a053f4355621937 100644 (file)
@@ -157,6 +157,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token HOOK                    "hook"
 %token <val> HOOKNUM           "hooknum"
 %token TABLE                   "table"
+%token TABLES                  "tables"
 %token CHAIN                   "chain"
 %token RULE                    "rule"
 %token SETS                    "sets"
@@ -332,8 +333,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %type <cmd>                    base_cmd add_cmd insert_cmd delete_cmd list_cmd flush_cmd rename_cmd
 %destructor { cmd_free($$); }  base_cmd add_cmd insert_cmd delete_cmd list_cmd flush_cmd rename_cmd
 
-%type <handle>                 table_spec chain_spec chain_identifier ruleid_spec
-%destructor { handle_free(&$$); } table_spec chain_spec chain_identifier ruleid_spec
+%type <handle>                 table_spec tables_spec chain_spec chain_identifier ruleid_spec
+%destructor { handle_free(&$$); } table_spec tables_spec chain_spec chain_identifier ruleid_spec
 %type <handle>                 set_spec set_identifier
 %destructor { handle_free(&$$); } set_spec set_identifier
 %type <val>                    handle_spec family_spec
@@ -602,6 +603,10 @@ delete_cmd         :       TABLE           table_spec
                        ;
 
 list_cmd               :       TABLE           table_spec
+                       {
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, NULL);
+                       }
+                       |       TABLES          tables_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, NULL);
                        }
@@ -789,6 +794,14 @@ table_spec         :       family_spec     identifier
                        }
                        ;
 
+tables_spec            :       family_spec
+                       {
+                               memset(&$$, 0, sizeof($$));
+                               $$.family       = $1;
+                               $$.table        = NULL;
+                       }
+                       ;
+
 chain_spec             :       table_spec      identifier
                        {
                                $$              = $1;
index 7d0887aae481f14d9d3d785352881d6c4439f1cd..43b683caf4c1ba19dbf86c3234058a1abb38f416 100644 (file)
@@ -477,6 +477,19 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 
        switch (cmd->obj) {
        case CMD_OBJ_TABLE:
+               if (!cmd->handle.table) {
+                       /* List all existing tables */
+                       struct table *table;
+
+                       if (netlink_list_tables(ctx, &cmd->handle) < 0)
+                               return -1;
+
+                       list_for_each_entry(table, &ctx->list, list) {
+                               printf("table %s\n", table->handle.table);
+                       }
+                       return 0;
+               }
+               /* List content of this table */
                if (do_list_sets(ctx, table) < 0)
                        return -1;
                if (netlink_list_chains(ctx, &cmd->handle) < 0)
index 7ceae09d8b3902a28f99f1e70a9b8ad8e863632a..edecf7b69a5391fa26cf5e54f24ec75489a5be46 100644 (file)
@@ -225,6 +225,7 @@ addrstring  ({macaddr}|{ip4addr}|{ip6addr})
 
 "hook"                 { return HOOK; }
 "table"                        { return TABLE; }
+"tables"               { return TABLES; }
 "chain"                        { return CHAIN; }
 "rule"                 { return RULE; }
 "sets"                 { return SETS; }