diff options
Diffstat (limited to 'src/rule.c')
-rw-r--r-- | src/rule.c | 44 |
1 files changed, 24 insertions, 20 deletions
@@ -411,7 +411,7 @@ const char *family2str(unsigned int family) return "unknown"; } -static const char *hooknum2str(unsigned int family, unsigned int hooknum) +const char *hooknum2str(unsigned int family, unsigned int hooknum) { switch (family) { case NFPROTO_IPV4: @@ -476,15 +476,16 @@ static void chain_print(const struct chain *chain) printf("\tchain %s {\n", chain->handle.chain); if (chain->flags & CHAIN_F_BASECHAIN) { if (chain->dev != NULL) { - printf("\t\ttype %s hook %s device %s priority %d;\n", + printf("\t\ttype %s hook %s device %s priority %d; policy %s;\n", chain->type, hooknum2str(chain->handle.family, chain->hooknum), - chain->dev, chain->priority); + chain->dev, chain->priority, + chain_policy2str(chain->policy)); } else { - printf("\t\ttype %s hook %s priority %d;\n", + printf("\t\ttype %s hook %s priority %d; policy %s;\n", chain->type, hooknum2str(chain->handle.family, chain->hooknum), - chain->priority); + chain->priority, chain_policy2str(chain->policy)); } } list_for_each_entry(rule, &chain->rules, list) { @@ -505,8 +506,7 @@ void chain_print_plain(const struct chain *chain) if (chain->flags & CHAIN_F_BASECHAIN) { printf(" { type %s hook %s priority %d; policy %s; }", - chain->type, - hooknum2str(chain->handle.family, chain->hooknum), + chain->type, chain->hookstr, chain->priority, chain_policy2str(chain->policy)); } @@ -919,6 +919,21 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd) return 0; } +static int do_list_tables(struct netlink_ctx *ctx, struct cmd *cmd) +{ + struct table *table; + + if (netlink_list_tables(ctx, &cmd->handle, &cmd->location) < 0) + return -1; + + list_for_each_entry(table, &ctx->list, list) + printf("table %s %s\n", + family2str(table->handle.family), + table->handle.table); + + return 0; +} + static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd) { struct table *table = NULL; @@ -936,19 +951,8 @@ 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, - &cmd->location) < 0) - return -1; - - list_for_each_entry(table, &ctx->list, list) { - printf("table %s\n", table->handle.table); - } - return 0; - } + if (!cmd->handle.table) + return do_list_tables(ctx, cmd); return do_list_table(ctx, cmd, table); case CMD_OBJ_CHAIN: return do_list_table(ctx, cmd, table); |