diff mbox series

[iproute2-next,06/11] libnetlink: Convert GETRULE dumps to use rtnl_ruledump_req

Message ID 20180929175931.18448-7-dsahern@kernel.org
State Accepted, archived
Delegated to: David Ahern
Headers show
Series Fix dump requests to use proper header for type | expand

Commit Message

David Ahern Sept. 29, 2018, 5:59 p.m. UTC
From: David Ahern <dsahern@gmail.com>

Add rtnl_ruledump_req for fib fule dumps using the proper fib_rule_hdr
as the header. Convert existing RTM_GETRULE dumps to use it.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 include/libnetlink.h |  2 ++
 ip/iprule.c          |  2 +-
 lib/libnetlink.c     | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/libnetlink.h b/include/libnetlink.h
index 7e9ef640c704..5f6bbe55fe4a 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -53,6 +53,8 @@  int rtnl_addrlbldump_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_ruledump_req(struct rtnl_handle *rth, int family)
+	__attribute__((warn_unused_result));
 int rtnl_mdbdump_req(struct rtnl_handle *rth, int family)
 	__attribute__((warn_unused_result));
 int rtnl_netconfdump_req(struct rtnl_handle *rth, int family)
diff --git a/ip/iprule.c b/ip/iprule.c
index 744d6d88e343..60fd4c7e9f93 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -615,7 +615,7 @@  static int iprule_list_flush_or_save(int argc, char **argv, int action)
 		argc--; argv++;
 	}
 
-	if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
+	if (rtnl_ruledump_req(&rth, af) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index e5cb275faf09..89e4d6a2a662 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -22,6 +22,7 @@ 
 #include <errno.h>
 #include <time.h>
 #include <sys/uio.h>
+#include <linux/fib_rules.h>
 #include <linux/if_addrlabel.h>
 #include <linux/if_bridge.h>
 
@@ -249,6 +250,22 @@  int rtnl_routedump_req(struct rtnl_handle *rth, int family)
 	return send(rth->fd, &req, sizeof(req), 0);
 }
 
+int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
+{
+	struct {
+		struct nlmsghdr nlh;
+		struct fib_rule_hdr frh;
+	} req = {
+		.nlh.nlmsg_len = sizeof(req),
+		.nlh.nlmsg_type = RTM_GETRULE,
+		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
+		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
+		.frh.family = family
+	};
+
+	return send(rth->fd, &req, sizeof(req), 0);
+}
+
 int rtnl_mdbdump_req(struct rtnl_handle *rth, int family)
 {
 	struct {