summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPetr Machata <petrm@nvidia.com>2022-04-22 10:30:50 +0200
committerDavid Ahern <dsahern@kernel.org>2022-04-27 20:12:42 -0600
commita463d6b19107373748f6f930170b4c106bee0c42 (patch)
treed38406546b4360875bb72e1d96b8ec3a39a76d62 /lib
parent38ae12d39632c164835a4b2954344189a58af830 (diff)
downloadiproute2-a463d6b19107373748f6f930170b4c106bee0c42.tar.gz
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@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David Ahern <dsahern@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libnetlink.c19
1 files changed, 14 insertions, 5 deletions
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);
}