Blame SOURCES/iproute2-ipaddress-fix-ipaddr_flush-for-Linux-3.1.patch

02706e
From 1a47c83cc1e59314c318f29b7cec49a58c6d1af8 Mon Sep 17 00:00:00 2001
02706e
From: Phil Sutter <psutter@redhat.com>
02706e
Date: Wed, 17 Feb 2016 14:03:59 +0100
02706e
Subject: [PATCH] ipaddress: fix ipaddr_flush for Linux >= 3.1
02706e
02706e
This is a combination of 3 commits:
02706e
02706e
commit 8e72880f6bfa39f439b9c4a88eb84b635b991687
02706e
Author: Phil Sutter <phil@nwl.cc>
02706e
Date:   Tue Nov 24 15:31:01 2015 +0100
02706e
02706e
    libnetlink: introduce nc_flags
02706e
02706e
    Allow for a filter to ignore certain nlmsg_flags.
02706e
02706e
    Signed-off-by: Phil Sutter <phil@nwl.cc>
02706e
02706e
commit c6995c48025233902a5b0c5fe88654e17ea934f6
02706e
Author: Phil Sutter <phil@nwl.cc>
02706e
Date:   Tue Nov 24 15:31:00 2015 +0100
02706e
02706e
    ipaddress: simplify ipaddr_flush()
02706e
02706e
    Since it's no longer relevant whether an IP address is primary or
02706e
    secondary when flushing, ipaddr_flush() can be simplified a bit.
02706e
02706e
    Signed-off-by: Phil Sutter <phil@nwl.cc>
02706e
02706e
commit d25ec03e1dce4cf22093a9f7106e9401ab5bf066
02706e
Author: Phil Sutter <phil@nwl.cc>
02706e
Date:   Tue Nov 24 15:31:02 2015 +0100
02706e
02706e
    ipaddress: fix ipaddr_flush for Linux >= 3.1
02706e
02706e
    Linux version 3.1 introduced a consistency check for netlink dumps in
02706e
    commit 670dc28 ("netlink: advertise incomplete dumps"). This bites
02706e
    iproute2 when flushing more addresses than can fit into a single
02706e
    RTM_GETADDR response. To silence the spurious error message "Dump was
02706e
    interrupted and may be inconsistent.", advise rtnl_dump_filter_l() to
02706e
    not care about NLM_F_DUMP_INTR.
02706e
02706e
    Signed-off-by: Phil Sutter <phil@nwl.cc>
02706e
---
02706e
 include/libnetlink.h |  8 ++++++--
02706e
 ip/ipaddress.c       | 39 ++-------------------------------------
02706e
 lib/libnetlink.c     | 10 ++++++----
02706e
 3 files changed, 14 insertions(+), 43 deletions(-)
02706e
02706e
diff --git a/include/libnetlink.h b/include/libnetlink.h
02706e
index 95f41d979828f..b008b93f4e65e 100644
02706e
--- a/include/libnetlink.h
02706e
+++ b/include/libnetlink.h
02706e
@@ -48,12 +48,16 @@ struct rtnl_dump_filter_arg
02706e
 {
02706e
 	rtnl_filter_t filter;
02706e
 	void *arg1;
02706e
+	__u16 nc_flags;
02706e
 };
02706e
 
02706e
 extern int rtnl_dump_filter_l(struct rtnl_handle *rth,
02706e
 			      const struct rtnl_dump_filter_arg *arg);
02706e
-extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
02706e
-			    void *arg);
02706e
+int rtnl_dump_filter_nc(struct rtnl_handle *rth,
02706e
+			rtnl_filter_t filter,
02706e
+			void *arg, __u16 nc_flags);
02706e
+#define rtnl_dump_filter(rth, filter, arg) \
02706e
+	rtnl_dump_filter_nc(rth, filter, arg, 0)
02706e
 extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
02706e
 		     struct nlmsghdr *answer, size_t len);
02706e
 extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int);
02706e
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
02706e
index 94ff53898a915..533c72c5b1c0f 100644
02706e
--- a/ip/ipaddress.c
02706e
+++ b/ip/ipaddress.c
02706e
@@ -875,28 +875,6 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
02706e
 	return 0;
02706e
 }
02706e
 
02706e
-static int print_addrinfo_primary(const struct sockaddr_nl *who,
02706e
-				  struct nlmsghdr *n, void *arg)
02706e
-{
02706e
-	struct ifaddrmsg *ifa = NLMSG_DATA(n);
02706e
-
02706e
-	if (ifa->ifa_flags & IFA_F_SECONDARY)
02706e
-		return 0;
02706e
-
02706e
-	return print_addrinfo(who, n, arg);
02706e
-}
02706e
-
02706e
-static int print_addrinfo_secondary(const struct sockaddr_nl *who,
02706e
-				    struct nlmsghdr *n, void *arg)
02706e
-{
02706e
-	struct ifaddrmsg *ifa = NLMSG_DATA(n);
02706e
-
02706e
-	if (!(ifa->ifa_flags & IFA_F_SECONDARY))
02706e
-		return 0;
02706e
-
02706e
-	return print_addrinfo(who, n, arg);
02706e
-}
02706e
-
02706e
 struct nlmsg_list
02706e
 {
02706e
 	struct nlmsg_list *next;
02706e
@@ -1139,26 +1117,13 @@ static int ipaddr_flush(void)
02706e
 	filter.flushe = sizeof(flushb);
02706e
 
02706e
 	while ((max_flush_loops == 0) || (round < max_flush_loops)) {
02706e
-		const struct rtnl_dump_filter_arg a[3] = {
02706e
-			{
02706e
-				.filter = print_addrinfo_secondary,
02706e
-				.arg1 = stdout,
02706e
-			},
02706e
-			{
02706e
-				.filter = print_addrinfo_primary,
02706e
-				.arg1 = stdout,
02706e
-			},
02706e
-			{
02706e
-				.filter = NULL,
02706e
-				.arg1 = NULL,
02706e
-			},
02706e
-		};
02706e
 		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
02706e
 			perror("Cannot send dump request");
02706e
 			exit(1);
02706e
 		}
02706e
 		filter.flushed = 0;
02706e
-		if (rtnl_dump_filter_l(&rth, a) < 0) {
02706e
+		if (rtnl_dump_filter_nc(&rth, print_addrinfo,
02706e
+					stdout, NLM_F_DUMP_INTR) < 0) {
02706e
 			fprintf(stderr, "Flush terminated\n");
02706e
 			exit(1);
02706e
 		}
02706e
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
02706e
index c455a41eccfdd..ebe3c120aa96b 100644
02706e
--- a/lib/libnetlink.c
02706e
+++ b/lib/libnetlink.c
02706e
@@ -234,6 +234,8 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
02706e
 			while (NLMSG_OK(h, msglen)) {
02706e
 				int err;
02706e
 
02706e
+				h->nlmsg_flags &= ~a->nc_flags;
02706e
+
02706e
 				if (nladdr.nl_pid != 0 ||
02706e
 				    h->nlmsg_pid != rth->local.nl_pid ||
02706e
 				    h->nlmsg_seq != rth->dump)
02706e
@@ -284,13 +286,13 @@ skip_it:
02706e
 	}
02706e
 }
02706e
 
02706e
-int rtnl_dump_filter(struct rtnl_handle *rth,
02706e
+int rtnl_dump_filter_nc(struct rtnl_handle *rth,
02706e
 		     rtnl_filter_t filter,
02706e
-		     void *arg1)
02706e
+		     void *arg1, __u16 nc_flags)
02706e
 {
02706e
 	const struct rtnl_dump_filter_arg a[2] = {
02706e
-		{ .filter = filter, .arg1 = arg1, },
02706e
-		{ .filter = NULL,   .arg1 = NULL, },
02706e
+		{ .filter = filter, .arg1 = arg1, .nc_flags = nc_flags, },
02706e
+		{ .filter = NULL,   .arg1 = NULL, .nc_flags = 0, },
02706e
 	};
02706e
 
02706e
 	return rtnl_dump_filter_l(rth, a);
02706e
-- 
02706e
2.8.2
02706e