rule: missing family when listing of tables
Pablo Neira Ayuso
maintainerPATCH 2/3 src: set chain->hookstr from delinearization
In reply to Pablo Neira AyusoSet human readable hookname chain->hookstr field from delinearize.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/rule.h | 1 + src/netlink.c | 2 ++ src/rule.c | 8 +++----- 3 files changed, 6 insertions(+), 5 deletions(-)
include/rule.h +1 -0
@@ -138,6 +138,7 @@ extern struct chain *chain_lookup(const struct table *table, const struct handle *h);extern const char *family2str (unsigned int family); +extern const char *hooknum2str (unsigned int family,unsigned int hooknum);extern void chain_print_plain (const struct chain *chain);/**
src/netlink.c +2 -0
@@ -691,6 +691,8 @@ static struct chain *netlink_delinearize_chain(struct netlink_ctx *ctx, nft_chain_attr_is_set(nlc, NFT_CHAIN_ATTR_POLICY)) { chain->hooknum =nft_chain_attr_get_u32 (nlc,NFT_CHAIN_ATTR_HOOKNUM ); + chain->hookstr = +hooknum2str (chain->handle.family, chain->hooknum); chain->priority =nft_chain_attr_get_s32 (nlc,NFT_CHAIN_ATTR_PRIO ); chain->type =
src/rule.c +3 -5
@@ -408,7 +408,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 :
@@ -466,8 +466,7 @@ static void chain_print(const struct chain *chain)printf ("\tchain %s {\n" , chain->handle.chain);if (chain->flags &CHAIN_F_BASECHAIN ) {printf ("\t\ttype %s hook %s priority %d; policy %s;\n" , - chain->type, -hooknum2str (chain->handle.family, chain->hooknum), + chain->type, chain->hookstr, chain->priority,chain_policy2str (chain->policy)); }list_for_each_entry (rule, &chain->rules, list) {
@@ -488,8 +487,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)); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/3 rule: add do_list_tables()
In reply to Pablo Neira AyusoWrap code to list existing tables in a function.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/rule.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
src/rule.c +14 -15
@@ -900,6 +900,18 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd)return 0 ; } +static int do_list_tables (void ) +{ +struct table *table; + +list_for_each_entry (table, &table_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 ;
@@ -917,21 +929,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 %s\n" , -family2str (table->handle.family), - table->handle.table); - } -return 0 ; - } +if (!cmd->handle.table) +return do_list_tables ();return do_list_table (ctx, cmd, table);case CMD_OBJ_CHAIN :return do_list_table (ctx, cmd, table);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/3 rule: missing family when listing of tables
# nft list tables table ip nat
instead of:
# nft list tables table nat
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/rule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/rule.c +3 -1
@@ -928,7 +928,9 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)return -1 ;list_for_each_entry (table, &ctx->list, list) { -printf ("table %s\n" , table->handle.table); +printf ("table %s %s\n" , +family2str (table->handle.family), + table->handle.table); }return 0 ; }
Signature · 1 line
1.7.10.4