Blame SOURCES/0017-netlink-Change-rtnl_dump_done-to-always-show-error.patch

be97f7
From 61ccf0f453306e727e254e6de1641bb934a3b7ec Mon Sep 17 00:00:00 2001
be97f7
From: Hangbin Liu <haliu@redhat.com>
be97f7
Date: Wed, 8 Nov 2017 14:39:07 +0800
be97f7
Subject: [PATCH] netlink: Change rtnl_dump_done to always show error
be97f7
be97f7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1380803
be97f7
Upstream Status: iproute2.git commit 05a14fc12188
be97f7
be97f7
commit 05a14fc1218885ba6236b409fbf6b89976b8636e
be97f7
Author: David Ahern <dsahern@gmail.com>
be97f7
Date:   Tue May 16 14:22:46 2017 -0700
be97f7
be97f7
    netlink: Change rtnl_dump_done to always show error
be97f7
be97f7
    The original code which became rtnl_dump_done only shows netlink errors
be97f7
    if the protocol is NETLINK_SOCK_DIAG, but netlink dumps always appends
be97f7
    the length which contains any error encountered during the dump. Update
be97f7
    rtnl_dump_done to always show the error if there is one.
be97f7
be97f7
    As an *example* without this patch, dumping a route object that exceeds
be97f7
    the internal buffer size terminates with no message to the user -- the
be97f7
    dump just ends because the NLMSG_DONE attribute was received. With this
be97f7
    patch the user at least gets a message that the dump was aborted.
be97f7
be97f7
    $ ip ro ls
be97f7
    default via 10.0.2.2 dev eth0
be97f7
    10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
be97f7
    10.10.0.0/16 dev veth1 proto kernel scope link src 10.10.0.1
be97f7
    172.16.1.0/24 dev br0.11 proto kernel scope link src 172.16.1.1
be97f7
    Error: Buffer too small for object
be97f7
    Dump terminated
be97f7
be97f7
    The point of this patch is to notify the user of a failure versus
be97f7
    silently exiting on a partial dump. Because the NLMSG_DONE attribute
be97f7
    was received, the entire dump needs to be restarted to use a larger
be97f7
    buffer for EMSGSIZE errors. That could be done automatically but it
be97f7
    has other user impacts (e.g., duplicate output if the dump is
be97f7
    restarted) and should be the subject of a different patch.
be97f7
be97f7
    Signed-off-by: David Ahern <dsahern@gmail.com>
be97f7
be97f7
Signed-off-by: Hangbin Liu <haliu@redhat.com>
be97f7
---
be97f7
 lib/libnetlink.c | 28 +++++++++++++++++-----------
be97f7
 1 file changed, 17 insertions(+), 11 deletions(-)
be97f7
be97f7
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
be97f7
index 9303b66..e91bd5a 100644
be97f7
--- a/lib/libnetlink.c
be97f7
+++ b/lib/libnetlink.c
be97f7
@@ -266,21 +266,27 @@ static int rtnl_dump_done(const struct rtnl_handle *rth,
be97f7
 {
be97f7
 	int len = *(int *)NLMSG_DATA(h);
be97f7
 
be97f7
-	if (rth->proto == NETLINK_SOCK_DIAG) {
be97f7
-		if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
be97f7
-			fprintf(stderr, "DONE truncated\n");
be97f7
-			return -1;
be97f7
-		}
be97f7
-
be97f7
+	if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
be97f7
+		fprintf(stderr, "DONE truncated\n");
be97f7
+		return -1;
be97f7
+	}
be97f7
 
be97f7
-		if (len < 0) {
be97f7
-			errno = -len;
be97f7
-			if (errno == ENOENT || errno == EOPNOTSUPP)
be97f7
-				return -1;
be97f7
+	if (len < 0) {
be97f7
+		errno = -len;
be97f7
+		switch (errno) {
be97f7
+		case ENOENT:
be97f7
+		case EOPNOTSUPP:
be97f7
+			return -1;
be97f7
+		case EMSGSIZE:
be97f7
+			fprintf(stderr,
be97f7
+				"Error: Buffer too small for object.\n");
be97f7
+			break;
be97f7
+		default:
be97f7
 			perror("RTNETLINK answers");
be97f7
-			return len;
be97f7
 		}
be97f7
+		return len;
be97f7
 	}
be97f7
+
be97f7
 	return 0;
be97f7
 }
be97f7
 
be97f7
-- 
be97f7
1.8.3.1
be97f7