]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
debug: include kernel set information on cache fill
authorFlorian Westphal <fw@strlen.de>
Tue, 8 Apr 2025 14:21:30 +0000 (16:21 +0200)
committerFlorian Westphal <fw@strlen.de>
Sun, 22 Jun 2025 19:40:34 +0000 (21:40 +0200)
Honor --debug=netlink flag also when doing initial set dump
from the kernel.

With recent libnftnl update this will include the chosen
set backend name that is used by the kernel.

Because set names are scoped by table and protocol family,
also include the family protocol number.

Dumping this information breaks tests/py as the recorded
debug output no longer matches, this is fixed in previous
change.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/mnl.c
src/netlink.c

index 6565341fa6e392823a1a92b07472279fc4119d25..8a8dc4d6ef1c2a71c963b6b443c627aa28328992 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -1396,9 +1396,15 @@ int mnl_nft_set_del(struct netlink_ctx *ctx, struct cmd *cmd)
        return 0;
 }
 
+struct set_cb_args {
+       struct netlink_ctx *ctx;
+       struct nftnl_set_list *list;
+};
+
 static int set_cb(const struct nlmsghdr *nlh, void *data)
 {
-       struct nftnl_set_list *nls_list = data;
+       struct set_cb_args *args = data;
+       struct nftnl_set_list *nls_list = args->list;
        struct nftnl_set *s;
 
        if (check_genid(nlh) < 0)
@@ -1411,6 +1417,8 @@ static int set_cb(const struct nlmsghdr *nlh, void *data)
        if (nftnl_set_nlmsg_parse(nlh, s) < 0)
                goto err_free;
 
+       netlink_dump_set(s, args->ctx);
+
        nftnl_set_list_add_tail(s, nls_list);
        return MNL_CB_OK;
 
@@ -1429,6 +1437,7 @@ mnl_nft_set_dump(struct netlink_ctx *ctx, int family,
        struct nlmsghdr *nlh;
        struct nftnl_set *s;
        int ret;
+       struct set_cb_args args;
 
        s = nftnl_set_alloc();
        if (s == NULL)
@@ -1450,7 +1459,9 @@ mnl_nft_set_dump(struct netlink_ctx *ctx, int family,
        if (nls_list == NULL)
                memory_allocation_error();
 
-       ret = nft_mnl_talk(ctx, nlh, nlh->nlmsg_len, set_cb, nls_list);
+       args.list = nls_list;
+       args.ctx  = ctx;
+       ret = nft_mnl_talk(ctx, nlh, nlh->nlmsg_len, set_cb, &args);
        if (ret < 0 && errno != ENOENT)
                goto err;
 
index 73fe579a477cf7e39c1cc002301f233072993754..68f1b90c0a056d99f5e28d3e8c9321a51221dbd1 100644 (file)
@@ -856,10 +856,13 @@ static const struct datatype *dtype_map_from_kernel(enum nft_data_types type)
 void netlink_dump_set(const struct nftnl_set *nls, struct netlink_ctx *ctx)
 {
        FILE *fp = ctx->nft->output.output_fp;
+       uint32_t family;
 
        if (!(ctx->nft->debug_mask & NFT_DEBUG_NETLINK) || !fp)
                return;
 
+       family = nftnl_set_get_u32(nls, NFTNL_SET_FAMILY);
+       fprintf(fp, "family %d ", family);
        nftnl_set_fprintf(fp, nls, 0, 0);
        fprintf(fp, "\n");
 }