[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0a0459d981354797db52a1c037c677f75d24b0e2.1650615982.git.petrm@nvidia.com>
Date: Fri, 22 Apr 2022 10:30:50 +0200
From: Petr Machata <petrm@...dia.com>
To: <netdev@...r.kernel.org>
CC: David Ahern <dsahern@...il.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Ido Schimmel <idosch@...dia.com>,
Petr Machata <petrm@...dia.com>
Subject: [PATCH iproute2-next 01/11] libnetlink: Add filtering to rtnl_statsdump_req_filter()
A number of functions in the rtnl_*_req family accept a caller-provided
callback to set up arbitrary filtering. rtnl_statsdump_req_filter()
currently only allows setting a field in the IFSM header, not custom
attributes. So far these were not necessary, but with introduction of more
detailed filtering settings, the callback becomes necessary.
To that end, add a filter_fn and filter_data arguments to the function.
Unlike the other filters, this one is typed to expect an IFSM pointer, to
permit tweaking the header itself as well.
Pass NULLs in the existing callers.
Signed-off-by: Petr Machata <petrm@...dia.com>
Reviewed-by: Ido Schimmel <idosch@...dia.com>
---
bridge/vlan.c | 6 ++++--
include/libnetlink.h | 11 ++++++++++-
ip/iplink.c | 3 ++-
ip/iplink_xstats.c | 3 ++-
lib/libnetlink.c | 19 ++++++++++++++-----
misc/ifstat.c | 2 +-
6 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/bridge/vlan.c b/bridge/vlan.c
index 8300f353..390a2037 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -1179,7 +1179,8 @@ static int vlan_show(int argc, char **argv, int subject)
__u32 filt_mask;
filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS);
- if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
+ if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask,
+ NULL, NULL) < 0) {
perror("Cannot send dump request");
exit(1);
}
@@ -1194,7 +1195,8 @@ static int vlan_show(int argc, char **argv, int subject)
}
filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE);
- if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
+ if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask,
+ NULL, NULL) < 0) {
perror("Cannot send slave dump request");
exit(1);
}
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 9e4cc101..372c3706 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -37,6 +37,12 @@ struct nlmsg_chain {
struct nlmsg_list *tail;
};
+struct ipstats_req {
+ struct nlmsghdr nlh;
+ struct if_stats_msg ifsm;
+ char buf[128];
+};
+
extern int rcvbuf;
int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)
@@ -88,7 +94,10 @@ int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth,
int rtnl_nsiddump_req_filter_fn(struct rtnl_handle *rth, int family,
req_filter_fn_t filter_fn)
__attribute__((warn_unused_result));
-int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
+int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask,
+ int (*filter_fn)(struct ipstats_req *req,
+ void *data),
+ void *filter_data)
__attribute__((warn_unused_result));
int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req,
int len)
diff --git a/ip/iplink.c b/ip/iplink.c
index dc76a12b..23eb6c6e 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1644,7 +1644,8 @@ static int iplink_afstats(int argc, char **argv)
}
}
- if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
+ if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask,
+ NULL, NULL) < 0) {
perror("Cannont send dump request");
return 1;
}
diff --git a/ip/iplink_xstats.c b/ip/iplink_xstats.c
index c64e6885..1d180b0b 100644
--- a/ip/iplink_xstats.c
+++ b/ip/iplink_xstats.c
@@ -65,7 +65,8 @@ int iplink_ifla_xstats(int argc, char **argv)
else
filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS);
- if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
+ if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask,
+ NULL, NULL) < 0) {
perror("Cannont send dump request");
return -1;
}
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 6d1b1187..4d33e4dd 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -619,12 +619,13 @@ int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth,
return send(rth->fd, &req, sizeof(req), 0);
}
-int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
+int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam,
+ __u32 filt_mask,
+ int (*filter_fn)(struct ipstats_req *req,
+ void *data),
+ void *filter_data)
{
- struct {
- struct nlmsghdr nlh;
- struct if_stats_msg ifsm;
- } req;
+ struct ipstats_req req;
memset(&req, 0, sizeof(req));
req.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct if_stats_msg));
@@ -635,6 +636,14 @@ int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
req.ifsm.family = fam;
req.ifsm.filter_mask = filt_mask;
+ if (filter_fn) {
+ int err;
+
+ err = filter_fn(&req, filter_data);
+ if (err)
+ return err;
+ }
+
return send(rth->fd, &req, sizeof(req), 0);
}
diff --git a/misc/ifstat.c b/misc/ifstat.c
index d4a33429..291f288b 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -202,7 +202,7 @@ static void load_info(void)
ll_init_map(&rth);
filter_mask = IFLA_STATS_FILTER_BIT(filter_type);
if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC,
- filter_mask) < 0) {
+ filter_mask, NULL, NULL) < 0) {
perror("Cannot send dump request");
exit(1);
}
--
2.31.1
Powered by blists - more mailing lists