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