From 59781412faa538b23263739b6b142b1116ce3945 Mon Sep 17 00:00:00 2001
From: Jacco Ligthart <jacco@redsleeve.org>
Date: Sun, 13 Dec 2015 16:02:06 +0100
Subject: [PATCH] redsleeve

---
 SOURCES/0001.ifa_flags-workaround.patch | 52 +++++++++++++++++++++++++++++++++
 SPECS/libnl3.spec                       |  9 +++++-
 2 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 SOURCES/0001.ifa_flags-workaround.patch

diff --git a/SOURCES/0001.ifa_flags-workaround.patch b/SOURCES/0001.ifa_flags-workaround.patch
new file mode 100644
index 0000000..b420a47
--- /dev/null
+++ b/SOURCES/0001.ifa_flags-workaround.patch
@@ -0,0 +1,52 @@
+From dce5f1ce978118ed4a8384c151f5ce720ab1f5df Mon Sep 17 00:00:00 2001
+From: Thomas Haller <thaller@redhat.com>
+Date: Thu, 3 Apr 2014 18:09:51 +0200
+Subject: [PATCH 1/1] route/addr: only sent IFA_FLAGS when needed to workaround
+ picky older kernels
+
+Older kernels don't accept receiving unknown netlink attributes.
+See net/core/rtnetlink.c, rtnetlink_rcv_msg(). This was fixed by kernel
+commit 661d2967b3f1b34eeaa7e212e7b9bbe8ee072b59.
+
+As a workaround, only set the additional attributes, when the user
+provided flags that makes this necessary and useful.
+
+https://github.com/thom311/libnl/issues/56
+https://bugzilla.redhat.com/show_bug.cgi?id=1063885
+
+Based-on-patch-by: Pavel Kankovsky <peak@argo.troja.mff.cuni.cz>
+Acked-by: Thomas Graf <tgraf@suug.ch>
+Signed-off-by: Thomas Haller <thaller@redhat.com>
+(cherry picked from commit 5206c050504f8676a24854519b9c351470fb7cc6)
+---
+ lib/route/addr.c | 14 +++++++++++++-
+ 1 file changed, 13 insertions(+), 1 deletion(-)
+
+diff --git a/lib/route/addr.c b/lib/route/addr.c
+index 97905f0..e6e91d2 100644
+--- a/lib/route/addr.c
++++ b/lib/route/addr.c
+@@ -598,7 +598,19 @@ static int build_addr_msg(struct rtnl_addr *tmpl, int cmd, int flags,
+ 		NLA_PUT(msg, IFA_CACHEINFO, sizeof(ca), &ca);
+ 	}
+ 
+-	NLA_PUT_U32(msg, IFA_FLAGS, tmpl->a_flags);
++	if (tmpl->a_flags & ~0xFF) {
++		/* only set the IFA_FLAGS attribute, if they actually contain additional
++		 * flags that are not already set to am.ifa_flags.
++		 *
++		 * Older kernels refuse RTM_NEWADDR and RTM_NEWROUTE messages with EINVAL
++		 * if they contain unknown netlink attributes. See net/core/rtnetlink.c, which
++		 * was fixed by kernel commit 661d2967b3f1b34eeaa7e212e7b9bbe8ee072b59.
++		 *
++		 * With this workaround, libnl will function correctly with older kernels,
++		 * unless there is a new libnl user that wants to set these flags. In this
++		 * case it's up to the user to workaround this issue. */
++		NLA_PUT_U32(msg, IFA_FLAGS, tmpl->a_flags);
++	}
+ 
+ 	*result = msg;
+ 	return 0;
+-- 
+1.9.0
+
diff --git a/SPECS/libnl3.spec b/SPECS/libnl3.spec
index a0a5b27..862815e 100644
--- a/SPECS/libnl3.spec
+++ b/SPECS/libnl3.spec
@@ -3,7 +3,7 @@ Group: Development/Libraries
 License: LGPLv2
 Name: libnl3
 Version: 3.2.21
-Release: 10%{?dist}
+Release: 10%{?dist}.redsleeve
 URL: http://www.infradead.org/~tgr/libnl/
 Source: http://www.infradead.org/~tgr/libnl/files/libnl-%{version}.tar.gz
 Source1: http://www.infradead.org/~tgr/libnl/files/libnl-doc-%{version}.tar.gz
@@ -27,6 +27,8 @@ Patch10: 0010-rh1249158-local-port-EADDRINUSE.patch
 Patch11: 0011-support-IFLA_LINK_NETNSID-rh1255050.patch
 Patch12: 0012-rh1261028-rtnl-neigh-get.patch
 
+Patch10001: 0001.ifa_flags-workaround.patch
+
 %description
 This package contains a convenience library to simplify
 using the Linux kernel's netlink sockets interface for
@@ -75,6 +77,8 @@ This package contains libnl3 API documentation
 %patch11 -p1
 %patch12 -p1
 
+%patch10001 -p1 -b .0001.ifa_flags-workaround.orig
+
 tar -xzf %SOURCE1
 
 %build
@@ -127,6 +131,9 @@ find $RPM_BUILD_ROOT -name \*.la -delete
 %doc libnl-doc-%{version}/api/*
 
 %changelog
+* Sun Dec 13 2015 Jacco Ligthart <jacco@redsleeve.org> - 3.2.21-10.redsleeve
+- fix breaking on older kernels due to IFA_FLAGS attribute (rh #1063885)
+
 * Wed Sep 30 2015 Thomas Haller <thaller@redhat.com> - 3.2.21-10
 - rtnl: fix lookup in rtnl_neigh_get() to ignore address family (rh #1261028)
 
-- 
1.8.3.1

