]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
libnetlink: Add test for error code returned from netlink reply
authorCyrill Gorcunov <gorcunov@gmail.com>
Wed, 2 Nov 2016 13:14:55 +0000 (16:14 +0300)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 1 Dec 2016 18:55:56 +0000 (10:55 -0800)
In case if some diag module is not present in the system,
say the kernel is not modern enough, we simply skip the
error code reported. Instead we should check for data
length in NLMSG_DONE and process unsupported case.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
lib/libnetlink.c

index 21a76363207f2919d982303017cda1875a8d9d9f..a5db168e50ebbfff4405d8d959df77913c1c10af 100644 (file)
@@ -319,6 +319,22 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
                                        dump_intr = 1;
 
                                if (h->nlmsg_type == NLMSG_DONE) {
+                                       if (rth->proto == NETLINK_SOCK_DIAG) {
+                                               if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
+                                                       fprintf(stderr, "DONE truncated\n");
+                                                       return -1;
+                                               } else {
+                                                       int len = *(int *)NLMSG_DATA(h);
+                                                       if (len < 0) {
+                                                               errno = -len;
+                                                               if (errno == ENOENT ||
+                                                                   errno == EOPNOTSUPP)
+                                                                       return -1;
+                                                               perror("RTNETLINK answers");
+                                                               return len;
+                                                       }
+                                               }
+                                       }
                                        found_done = 1;
                                        break; /* process next filter */
                                }