summaryrefslogtreecommitdiffstats
path: root/src/netlink.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2020-08-20 17:23:57 +0200
committerFlorian Westphal <fw@strlen.de>2020-08-20 21:00:21 +0200
commitca2e6e0db0b970e56a3c48c73e39c0367f464410 (patch)
treea36167d5159f845a796c9adff65fcc45c7d94c18 /src/netlink.c
parent3926a3369bb5ada5c0706dadcbcf938517822a35 (diff)
nftables: dump raw element info from libnftnl when netlink debugging is on
Example: nft --debug=netlink list ruleset inet firewall @knock_candidates_ipv4 element 0100007f 00007b00 : 0 [end] element 0200007f 0000f1ff : 0 [end] element 0100007f 00007a00 : 0 [end] inet firewall @__set0 element 00000100 : 0 [end] element 00000200 : 0 [end] inet firewall knock-input 3 [ meta load l4proto => reg 1 ] ... Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/netlink.c')
-rw-r--r--src/netlink.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/netlink.c b/src/netlink.c
index 20b3cdf5..77e0d41e 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -1194,6 +1194,42 @@ static int list_setelem_cb(struct nftnl_set_elem *nlse, void *arg)
return netlink_delinearize_setelem(nlse, ctx->set, &ctx->nft->cache);
}
+static int list_setelem_debug_cb(struct nftnl_set_elem *nlse, void *arg)
+{
+ int r;
+
+ r = list_setelem_cb(nlse, arg);
+ if (r == 0) {
+ struct netlink_ctx *ctx = arg;
+ FILE *fp = ctx->nft->output.output_fp;
+
+ fprintf(fp, "\t");
+ nftnl_set_elem_fprintf(fp, nlse, 0, 0);
+ fprintf(fp, "\n");
+ }
+
+ return r;
+}
+
+static int list_setelements(struct nftnl_set *s, struct netlink_ctx *ctx)
+{
+ FILE *fp = ctx->nft->output.output_fp;
+
+ if (fp && (ctx->nft->debug_mask & NFT_DEBUG_NETLINK)) {
+ const char *table, *name;
+ uint32_t family = nftnl_set_get_u32(s, NFTNL_SET_FAMILY);
+
+ table = nftnl_set_get_str(s, NFTNL_SET_TABLE);
+ name = nftnl_set_get_str(s, NFTNL_SET_NAME);
+
+ fprintf(fp, "%s %s @%s\n", family2str(family), table, name);
+
+ return nftnl_set_elem_foreach(s, list_setelem_debug_cb, ctx);
+ }
+
+ return nftnl_set_elem_foreach(s, list_setelem_cb, ctx);
+}
+
int netlink_list_setelems(struct netlink_ctx *ctx, const struct handle *h,
struct set *set)
{
@@ -1221,7 +1257,7 @@ int netlink_list_setelems(struct netlink_ctx *ctx, const struct handle *h,
ctx->set = set;
set->init = set_expr_alloc(&internal_location, set);
- nftnl_set_elem_foreach(nls, list_setelem_cb, ctx);
+ list_setelements(nls, ctx);
if (set->flags & NFT_SET_INTERVAL && set->desc.field_count > 1)
concat_range_aggregate(set->init);
@@ -1265,7 +1301,7 @@ int netlink_get_setelem(struct netlink_ctx *ctx, const struct handle *h,
ctx->set = set;
set->init = set_expr_alloc(loc, set);
- nftnl_set_elem_foreach(nls_out, list_setelem_cb, ctx);
+ list_setelements(nls_out, ctx);
if (set->flags & NFT_SET_INTERVAL && set->desc.field_count > 1)
concat_range_aggregate(set->init);