From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 1/2] src: mnl: prepare for listing all device netdev device hooks
Date: Wed, 21 Aug 2024 00:12:26 +0200 [thread overview]
Message-ID: <20240820221230.7014-2-fw@strlen.de> (raw)
In-Reply-To: <20240820221230.7014-1-fw@strlen.de>
Change output foramt slightly so device name is included for netdev
family.
% nft list hooks netdev device eth0
family netdev {
hook ingress device eth0 {
0000000000 chain inet ingress in_public [nf_tables]
0000000000 chain netdev ingress in_public [nf_tables]
}
hook egress device eth0 {
0000000000 chain netdev ingress out_public [nf_tables]
}
}
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/mnl.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/mnl.c b/src/mnl.c
index 3cacb47e7242..e585241d9395 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -45,6 +45,7 @@ struct basehook {
const char *hookfn;
const char *table;
const char *chain;
+ const char *devname;
int family;
int chain_family;
uint32_t num;
@@ -2179,9 +2180,24 @@ static void basehook_free(struct basehook *b)
free_const(b->hookfn);
free_const(b->chain);
free_const(b->table);
+ free_const(b->devname);
free(b);
}
+static bool basehook_eq(const struct basehook *prev, const struct basehook *hook)
+{
+ if (prev->num != hook->num)
+ return false;
+
+ if (prev->devname != NULL && hook->devname != NULL)
+ return strcmp(prev->devname, hook->devname) == 0;
+
+ if (prev->devname == NULL && prev->devname == NULL)
+ return true;
+
+ return false;
+}
+
static void basehook_list_add_tail(struct basehook *b, struct list_head *head)
{
struct basehook *hook;
@@ -2310,6 +2326,7 @@ static int dump_nf_attr_bpf_cb(const struct nlattr *attr, void *data)
struct dump_nf_hook_data {
struct list_head *hook_list;
+ const char *devname;
int family;
};
@@ -2331,6 +2348,7 @@ static int dump_nf_hooks(const struct nlmsghdr *nlh, void *_data)
hook = basehook_alloc();
hook->prio = ntohl(mnl_attr_get_u32(tb[NFNLA_HOOK_PRIORITY]));
+ hook->devname = data->devname ? xstrdup(data->devname) : NULL;
if (tb[NFNLA_HOOK_FUNCTION_NAME])
hook->hookfn = xstrdup(mnl_attr_get_str(tb[NFNLA_HOOK_FUNCTION_NAME]));
@@ -2420,6 +2438,7 @@ static int __mnl_nft_dump_nf_hooks(struct netlink_ctx *ctx, uint8_t query_family
char buf[MNL_SOCKET_BUFFER_SIZE];
struct dump_nf_hook_data data = {
.hook_list = hook_list,
+ .devname = devname,
.family = query_family,
};
struct nlmsghdr *nlh;
@@ -2459,7 +2478,7 @@ static void print_hooks(struct netlink_ctx *ctx, int family, struct list_head *h
continue;
if (prev) {
- if (prev->num == hook->num) {
+ if (basehook_eq(prev, hook)) {
fprintf(fp, "\n");
same = true;
} else {
@@ -2472,8 +2491,12 @@ static void print_hooks(struct netlink_ctx *ctx, int family, struct list_head *h
prev = hook;
if (!same) {
- fprintf(fp, "\thook %s {\n",
- hooknum2str(family, hook->num));
+ if (hook->devname)
+ fprintf(fp, "\thook %s device %s {\n",
+ hooknum2str(family, hook->num), hook->devname);
+ else
+ fprintf(fp, "\thook %s {\n",
+ hooknum2str(family, hook->num));
}
prio = hook->prio;
--
2.44.2
next prev parent reply other threads:[~2024-08-20 22:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 22:12 [PATCH 0/2 nft] mnl: query netdevices for in/egress hooks Florian Westphal
2024-08-20 22:12 ` Florian Westphal [this message]
2024-08-20 22:12 ` [PATCH nft 2/2] src: mnl: always dump all netdev hooks if no interface name was given Florian Westphal
2024-08-21 8:48 ` [PATCH 0/2 nft] mnl: query netdevices for in/egress hooks Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240820221230.7014-2-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.