From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 04/12] ip route: Remove rtnl_rtcache_request
Date: Wed, 19 Dec 2018 19:54:19 -0800 [thread overview]
Message-ID: <20181220035427.14453-5-dsahern@kernel.org> (raw)
In-Reply-To: <20181220035427.14453-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Add a filter option to rtnl_routedump_req and use it to set rtm_flags
removing the need for rtnl_rtcache_request for dump requests.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
include/libnetlink.h | 7 ++++---
ip/ipmroute.c | 2 +-
ip/iproute.c | 43 ++++++++++++++-----------------------------
lib/libnetlink.c | 12 +++++++++++-
4 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 138840d5c892..b0051f390980 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -47,11 +47,14 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
void rtnl_close(struct rtnl_handle *rth);
+typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
+
int rtnl_addrdump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
-int rtnl_routedump_req(struct rtnl_handle *rth, int family)
+int rtnl_routedump_req(struct rtnl_handle *rth, int family,
+ req_filter_fn_t filter_fn)
__attribute__((warn_unused_result));
int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
@@ -71,8 +74,6 @@ int rtnl_linkdump_req(struct rtnl_handle *rth, int fam)
int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
__attribute__((warn_unused_result));
-typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
-
int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam,
req_filter_fn_t fn)
__attribute__((warn_unused_result));
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index 4d8867d3219f..de7a035f852f 100644
--- a/ip/ipmroute.c
+++ b/ip/ipmroute.c
@@ -283,7 +283,7 @@ static int mroute_list(int argc, char **argv)
filter.iif = idx;
}
- if (rtnl_routedump_req(&rth, filter.af) < 0) {
+ if (rtnl_routedump_req(&rth, filter.af, NULL) < 0) {
perror("Cannot send dump request");
return 1;
}
diff --git a/ip/iproute.c b/ip/iproute.c
index d34724692553..3c0be0a96d4e 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1535,24 +1535,6 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
return 0;
}
-static int rtnl_rtcache_request(struct rtnl_handle *rth, int family)
-{
- struct {
- struct nlmsghdr nlh;
- struct rtmsg rtm;
- } req = {
- .nlh.nlmsg_len = sizeof(req),
- .nlh.nlmsg_type = RTM_GETROUTE,
- .nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_REQUEST,
- .nlh.nlmsg_seq = rth->dump = ++rth->seq,
- .rtm.rtm_family = family,
- .rtm.rtm_flags = RTM_F_CLONED,
- };
- struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
-
- return sendto(rth->fd, (void *)&req, sizeof(req), 0, (struct sockaddr *)&nladdr, sizeof(nladdr));
-}
-
static int iproute_flush_cache(void)
{
#define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
@@ -1644,7 +1626,7 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn)
filter.flushe = sizeof(flushb);
for (;;) {
- if (rtnl_routedump_req(&rth, do_ipv6) < 0) {
+ if (rtnl_routedump_req(&rth, do_ipv6, NULL) < 0) {
perror("Cannot send dump request");
return -2;
}
@@ -1684,6 +1666,16 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn)
}
}
+static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
+{
+ struct rtmsg *rtm = NLMSG_DATA(nlh);
+
+ if (filter.cloned)
+ rtm->rtm_flags |= RTM_F_CLONED;
+
+ return 0;
+}
+
static int iproute_list_flush_or_save(int argc, char **argv, int action)
{
int do_ipv6 = preferred_family;
@@ -1889,16 +1881,9 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (action == IPROUTE_FLUSH)
return iproute_flush(do_ipv6, filter_fn);
- if (!filter.cloned) {
- if (rtnl_routedump_req(&rth, do_ipv6) < 0) {
- perror("Cannot send dump request");
- return -2;
- }
- } else {
- if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
- perror("Cannot send dump request");
- return -2;
- }
+ if (rtnl_routedump_req(&rth, do_ipv6, iproute_dump_filter) < 0) {
+ perror("Cannot send dump request");
+ return -2;
}
new_json_obj(json);
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index b9c37fd36211..56a1cadeb3db 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -266,11 +266,13 @@ int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
return send(rth->fd, &req, sizeof(req), 0);
}
-int rtnl_routedump_req(struct rtnl_handle *rth, int family)
+int rtnl_routedump_req(struct rtnl_handle *rth, int family,
+ req_filter_fn_t filter_fn)
{
struct {
struct nlmsghdr nlh;
struct rtmsg rtm;
+ char buf[128];
} req = {
.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
.nlh.nlmsg_type = RTM_GETROUTE,
@@ -279,6 +281,14 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family)
.rtm.rtm_family = family,
};
+ if (filter_fn) {
+ int err;
+
+ err = filter_fn(&req.nlh, sizeof(req));
+ if (err)
+ return err;
+ }
+
return send(rth->fd, &req, sizeof(req), 0);
}
--
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 ` [PATCH iproute2-next 03/12] libnetlink: linkdump_req: Only AF_UNSPEC family expects an ext_filter_mask David Ahern
2018-12-20 3:54 ` David Ahern [this message]
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-5-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 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.