netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, christian@brauner.io,
	David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 02/11] libnetlink: Convert GETROUTE dumps to use rtnl_routedump_req
Date: Sat, 29 Sep 2018 10:59:22 -0700	[thread overview]
Message-ID: <20180929175931.18448-3-dsahern@kernel.org> (raw)
In-Reply-To: <20180929175931.18448-1-dsahern@kernel.org>

From: David Ahern <dsahern@gmail.com>

Add rtnl_routedump_req for route dumps using the proper rtmsg
as the header. Convert existing RTM_GETROUTE dumps to use it.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 include/libnetlink.h |  2 ++
 ip/ipmroute.c        |  2 +-
 ip/iproute.c         |  4 ++--
 lib/libnetlink.c     | 16 ++++++++++++++++
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/include/libnetlink.h b/include/libnetlink.h
index 2d9f6190230c..a60af316b505 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -49,6 +49,8 @@ void rtnl_close(struct rtnl_handle *rth);
 
 int rtnl_addrdump_req(struct rtnl_handle *rth, int family)
 	__attribute__((warn_unused_result));
+int rtnl_routedump_req(struct rtnl_handle *rth, int family)
+	__attribute__((warn_unused_result));
 
 int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type)
 	__attribute__((warn_unused_result));
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index bc23cfea7e8b..c5dfa9cb1538 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_wilddump_request(&rth, filter.af, RTM_GETROUTE) < 0) {
+	if (rtnl_routedump_req(&rth, filter.af) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
diff --git a/ip/iproute.c b/ip/iproute.c
index 398322fd1f4f..699635923764 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1645,7 +1645,7 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn)
 	filter.flushe = sizeof(flushb);
 
 	for (;;) {
-		if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
+		if (rtnl_routedump_req(&rth, do_ipv6) < 0) {
 			perror("Cannot send dump request");
 			return -2;
 		}
@@ -1891,7 +1891,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
 		return iproute_flush(do_ipv6, filter_fn);
 
 	if (!filter.cloned) {
-		if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
+		if (rtnl_routedump_req(&rth, do_ipv6) < 0) {
 			perror("Cannot send dump request");
 			return -2;
 		}
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 749cf4fbb88e..fda5309ce44d 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -215,6 +215,22 @@ int rtnl_addrdump_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)
+{
+	struct {
+		struct nlmsghdr nlh;
+		struct rtmsg rtm;
+	} req = {
+		.nlh.nlmsg_len = sizeof(req),
+		.nlh.nlmsg_type = RTM_GETROUTE,
+		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
+		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
+		.rtm.rtm_family = family,
+	};
+
+	return send(rth->fd, &req, sizeof(req), 0);
+}
+
 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
 {
 	return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF);
-- 
2.11.0

  parent reply	other threads:[~2018-09-30  0:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-29 17:59 [PATCH iproute2-next 00/11] Fix dump requests to use proper header for type David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 01/11] libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req David Ahern
2018-09-30  9:35   ` Stephen Hemminger
2018-09-30 15:37     ` David Ahern
2018-09-29 17:59 ` David Ahern [this message]
2018-09-29 17:59 ` [PATCH iproute2-next 03/11] libnetlink: Convert GETADDRLABEL dumps to use rtnl_addrlbldump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 04/11] libnetlink: Convert GETMDB dumps to use rtnl_mdbdump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 05/11] libnetlink: Convert GETNETCONF dumps to use rtnl_netconfdump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 06/11] libnetlink: Convert GETRULE dumps to use rtnl_ruledump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 07/11] libnetlink: Convert GETNEIGH dumps to use rtnl_neighdump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 08/11] libnetlink: Convert GETNEIGHTBL dumps to use rtnl_neightbldump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 09/11] libnetlink: Convert GETNSID dumps to use rtnl_nsiddump_req David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 10/11] libnetlink: Rename rtnl_wilddump_* to rtnl_linkdump_* David Ahern
2018-09-29 17:59 ` [PATCH iproute2-next 11/11] libnetlink: Rename rtnl_wilddump_stats_req_filter to rtnl_statsdump_req_filter David Ahern
2018-09-30 18:45 ` [PATCH iproute2-next 00/11] Fix dump requests to use proper header for type Christian Brauner

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=20180929175931.18448-3-dsahern@kernel.org \
    --to=dsahern@kernel.org \
    --cc=christian@brauner.io \
    --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).