From 0f8302635ad3f7bea70044df823ea783b6bcf4d6 Mon Sep 17 00:00:00 2001 From: Harsha Sharma Date: Sat, 23 Dec 2017 11:45:25 -0800 Subject: src: print 'handle' attribute in tables Print 'handle' attribute in tables, when listing via '-a' option For eg. nft list ruleset -a table ip test-ip4 { chain input { ip saddr 8.8.8.8 counter packets 0 bytes 0 # handle 3 } # handle 1} table ip filter { chain output { tcp dport ssh counter packets 0 bytes 0 # handle 4 } # handle 2} table ip xyz { # handle 3} Signed-off-by: Harsha Sharma Signed-off-by: Pablo Neira Ayuso --- src/netlink.c | 6 +++++- src/rule.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/netlink.c b/src/netlink.c index d4ed09bf..728b6fdf 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -126,6 +126,8 @@ struct nftnl_table *alloc_nftnl_table(const struct handle *h) nftnl_table_set_u32(nlt, NFTNL_TABLE_FAMILY, h->family); if (h->table != NULL) nftnl_table_set(nlt, NFTNL_TABLE_NAME, h->table); + if (h->handle.id) + nftnl_table_set_u64(nlt, NFTNL_TABLE_HANDLE, h->handle.id); return nlt; } @@ -140,7 +142,7 @@ struct nftnl_chain *alloc_nftnl_chain(const struct handle *h) nftnl_chain_set_u32(nlc, NFTNL_CHAIN_FAMILY, h->family); nftnl_chain_set_str(nlc, NFTNL_CHAIN_TABLE, h->table); - if (h->handle.id != 0) + if (h->handle.id) nftnl_chain_set_u64(nlc, NFTNL_CHAIN_HANDLE, h->handle.id); if (h->chain != NULL) nftnl_chain_set_str(nlc, NFTNL_CHAIN_NAME, h->chain); @@ -810,6 +812,7 @@ static struct table *netlink_delinearize_table(struct netlink_ctx *ctx, table->handle.family = nftnl_table_get_u32(nlt, NFTNL_TABLE_FAMILY); table->handle.table = xstrdup(nftnl_table_get_str(nlt, NFTNL_TABLE_NAME)); table->flags = nftnl_table_get_u32(nlt, NFTNL_TABLE_FLAGS); + table->handle.handle.id = nftnl_table_get_u64(nlt, NFTNL_TABLE_HANDLE); return table; } @@ -838,6 +841,7 @@ int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h, return 0; } + ctx->data = h; nftnl_table_list_foreach(table_cache, list_table_cb, ctx); nftnl_table_list_free(table_cache); return 0; diff --git a/src/rule.c b/src/rule.c index 771b2a12..52b6adac 100644 --- a/src/rule.c +++ b/src/rule.c @@ -879,6 +879,8 @@ static void table_print(const struct table *table, struct output_ctx *octx) chain_print(chain, octx); delim = "\n"; } + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, table->handle.handle.id); nft_print(octx, "}\n"); } -- cgit v1.2.3