linma / rpms / iproute

Forked from rpms/iproute 4 years ago
Clone

Blame SOURCES/0050-libnetlink-Convert-GETADDR-dumps-to-use-rtnl_addrdum.patch

8def76
From ae7cf70848d837d2ed85a21f6d7cbdf4c6ee6e4e Mon Sep 17 00:00:00 2001
8def76
From: Andrea Claudi <aclaudi@redhat.com>
8def76
Date: Mon, 10 Jun 2019 14:25:21 +0200
8def76
Subject: [PATCH] libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req
8def76
8def76
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1716772
8def76
Upstream Status: iproute2.git commit 46917d0895fb0
8def76
8def76
commit 46917d0895fb0fb1df9b3c1575ccd467b4a1f860
8def76
Author: David Ahern <dsahern@gmail.com>
8def76
Date:   Sat Sep 29 08:41:46 2018 -0700
8def76
8def76
    libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req
8def76
8def76
    Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg
8def76
    as the header. Convert existing RTM_GETADDR dumps to use it.
8def76
8def76
    Signed-off-by: David Ahern <dsahern@gmail.com>
8def76
---
8def76
 include/libnetlink.h |  4 ++++
8def76
 ip/ipaddress.c       |  6 +++---
8def76
 lib/libnetlink.c     | 16 ++++++++++++++++
8def76
 3 files changed, 23 insertions(+), 3 deletions(-)
8def76
8def76
diff --git a/include/libnetlink.h b/include/libnetlink.h
8def76
index 9d9249e634dc3..2d9f6190230c1 100644
8def76
--- a/include/libnetlink.h
8def76
+++ b/include/libnetlink.h
8def76
@@ -46,6 +46,10 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
8def76
 	__attribute__((warn_unused_result));
8def76
 
8def76
 void rtnl_close(struct rtnl_handle *rth);
8def76
+
8def76
+int rtnl_addrdump_req(struct rtnl_handle *rth, int family)
8def76
+	__attribute__((warn_unused_result));
8def76
+
8def76
 int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type)
8def76
 	__attribute__((warn_unused_result));
8def76
 int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type,
8def76
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
8def76
index f315a815e945d..4714bce60db1b 100644
8def76
--- a/ip/ipaddress.c
8def76
+++ b/ip/ipaddress.c
8def76
@@ -1672,7 +1672,7 @@ static int ipaddr_flush(void)
8def76
 	filter.flushe = sizeof(flushb);
8def76
 
8def76
 	while ((max_flush_loops == 0) || (round < max_flush_loops)) {
8def76
-		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
8def76
+		if (rtnl_addrdump_req(&rth, filter.family) < 0) {
8def76
 			perror("Cannot send dump request");
8def76
 			exit(1);
8def76
 		}
8def76
@@ -1764,7 +1764,7 @@ int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
8def76
 	}
8def76
 
8def76
 	if (ainfo) {
8def76
-		if (rtnl_wilddump_request(&rth, family, RTM_GETADDR) < 0) {
8def76
+		if (rtnl_addrdump_req(&rth, family) < 0) {
8def76
 			perror("Cannot send dump request");
8def76
 			return 1;
8def76
 		}
8def76
@@ -1889,7 +1889,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
8def76
 		if (ipadd_save_prep())
8def76
 			exit(1);
8def76
 
8def76
-		if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETADDR) < 0) {
8def76
+		if (rtnl_addrdump_req(&rth, preferred_family) < 0) {
8def76
 			perror("Cannot send dump request");
8def76
 			exit(1);
8def76
 		}
8def76
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
8def76
index a9932d423126e..db625b9bd18ca 100644
8def76
--- a/lib/libnetlink.c
8def76
+++ b/lib/libnetlink.c
8def76
@@ -199,6 +199,22 @@ int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)
8def76
 	return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE);
8def76
 }
8def76
 
8def76
+int rtnl_addrdump_req(struct rtnl_handle *rth, int family)
8def76
+{
8def76
+	struct {
8def76
+		struct nlmsghdr nlh;
8def76
+		struct ifaddrmsg ifm;
8def76
+	} req = {
8def76
+		.nlh.nlmsg_len = sizeof(req),
8def76
+		.nlh.nlmsg_type = RTM_GETADDR,
8def76
+		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
8def76
+		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
8def76
+		.ifm.ifa_family = family,
8def76
+	};
8def76
+
8def76
+	return send(rth->fd, &req, sizeof(req), 0);
8def76
+}
8def76
+
8def76
 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
8def76
 {
8def76
 	return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF);
8def76
-- 
8def76
2.20.1
8def76