From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 03/12] libnetlink: linkdump_req: Only AF_UNSPEC family expects an ext_filter_mask
Date: Wed, 19 Dec 2018 19:54:18 -0800 [thread overview]
Message-ID: <20181220035427.14453-4-dsahern@kernel.org> (raw)
In-Reply-To: <20181220035427.14453-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Only AF_UNSPEC handled by rtnl_dump_ifinfo expects an ext_filter_mask
on a dump request. Update the linkdump request functions to only set
and send ext_filter_mask for AF_UNSPEC.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
lib/libnetlink.c | 93 ++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 60 insertions(+), 33 deletions(-)
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 8ab2355fc26b..b9c37fd36211 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -380,58 +380,85 @@ int rtnl_nsiddump_req(struct rtnl_handle *rth, int family)
return send(rth->fd, &req, sizeof(req), 0);
}
-int rtnl_linkdump_req(struct rtnl_handle *rth, int family)
-{
- return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF);
-}
-
-int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int family,
- __u32 filt_mask)
+static int __rtnl_linkdump_req(struct rtnl_handle *rth, int family)
{
struct {
struct nlmsghdr nlh;
struct ifinfomsg ifm;
- /* attribute has to be NLMSG aligned */
- struct rtattr ext_req __aligned(NLMSG_ALIGNTO);
- __u32 ext_filter_mask;
} req = {
- .nlh.nlmsg_len = sizeof(req),
+ .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.nlh.nlmsg_type = RTM_GETLINK,
.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
.nlh.nlmsg_seq = rth->dump = ++rth->seq,
.ifm.ifi_family = family,
- .ext_req.rta_type = IFLA_EXT_MASK,
- .ext_req.rta_len = RTA_LENGTH(sizeof(__u32)),
- .ext_filter_mask = filt_mask,
};
return send(rth->fd, &req, sizeof(req), 0);
}
+int rtnl_linkdump_req(struct rtnl_handle *rth, int family)
+{
+ if (family == AF_UNSPEC)
+ return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF);
+
+ return __rtnl_linkdump_req(rth, family);
+}
+
+int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int family,
+ __u32 filt_mask)
+{
+ if (family == AF_UNSPEC) {
+ struct {
+ struct nlmsghdr nlh;
+ struct ifinfomsg ifm;
+ /* attribute has to be NLMSG aligned */
+ struct rtattr ext_req __aligned(NLMSG_ALIGNTO);
+ __u32 ext_filter_mask;
+ } req = {
+ .nlh.nlmsg_len = sizeof(req),
+ .nlh.nlmsg_type = RTM_GETLINK,
+ .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
+ .nlh.nlmsg_seq = rth->dump = ++rth->seq,
+ .ifm.ifi_family = family,
+ .ext_req.rta_type = IFLA_EXT_MASK,
+ .ext_req.rta_len = RTA_LENGTH(sizeof(__u32)),
+ .ext_filter_mask = filt_mask,
+ };
+
+ return send(rth->fd, &req, sizeof(req), 0);
+ }
+
+ return __rtnl_linkdump_req(rth, family);
+}
+
int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int family,
req_filter_fn_t filter_fn)
{
- struct {
- struct nlmsghdr nlh;
- struct ifinfomsg ifm;
- char buf[1024];
- } req = {
- .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
- .nlh.nlmsg_type = RTM_GETLINK,
- .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
- .nlh.nlmsg_seq = rth->dump = ++rth->seq,
- .ifm.ifi_family = family,
- };
- int err;
-
- if (!filter_fn)
- return -EINVAL;
+ if (family == AF_UNSPEC) {
+ struct {
+ struct nlmsghdr nlh;
+ struct ifinfomsg ifm;
+ char buf[1024];
+ } req = {
+ .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+ .nlh.nlmsg_type = RTM_GETLINK,
+ .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
+ .nlh.nlmsg_seq = rth->dump = ++rth->seq,
+ .ifm.ifi_family = family,
+ };
+ int err;
+
+ if (!filter_fn)
+ return -EINVAL;
+
+ err = filter_fn(&req.nlh, sizeof(req));
+ if (err)
+ return err;
- err = filter_fn(&req.nlh, sizeof(req));
- if (err)
- return err;
+ return send(rth->fd, &req, req.nlh.nlmsg_len, 0);
+ }
- return send(rth->fd, &req, req.nlh.nlmsg_len, 0);
+ return __rtnl_linkdump_req(rth, family);
}
int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
--
2.11.0
next prev parent reply other threads:[~2018-12-20 3:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-20 3:54 [PATCH iproute2-next 00/12] Updates for strict checking and kernel side filtering David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 01/12] libnetlink: dump extack string in done message David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 02/12] libnetlink: Use NLMSG_LENGTH to set nlmsg_len David Ahern
2018-12-20 3:54 ` David Ahern [this message]
2018-12-20 3:54 ` [PATCH iproute2-next 04/12] ip route: Remove rtnl_rtcache_request David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 05/12] ip route: Add protocol, table id and device to dump request David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 06/12] mroute: fix up family handling David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 07/12] mroute: Add table id attribute for kernel side filtering David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 08/12] ip address: Split ip_linkaddr_list into link and addr functions David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 09/12] ip address: Set device index in dump request David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 10/12] ip bridge: Set NETLINK_DUMP_STRICT_CHK on socket David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 11/12] ip route: Rename do_ipv6 to dump_family David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 12/12] neighbor: Add support for protocol attribute David Ahern
2018-12-30 14:17 ` [PATCH iproute2-next 00/12] Updates for strict checking and kernel side filtering Ido Schimmel
2018-12-30 15:10 ` David Ahern
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=20181220035427.14453-4-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).