naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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