netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, avagin@openvz.org,
	Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [PATCH net-next iproute2 1/2 v2] libnetlink: Add test for error code returned from netlink reply
Date: Wed,  2 Nov 2016 16:14:55 +0300	[thread overview]
Message-ID: <1478092496-7540-2-git-send-email-gorcunov@gmail.com> (raw)
In-Reply-To: <1478092496-7540-1-git-send-email-gorcunov@gmail.com>

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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 2279935..232daee 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -312,6 +312,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 */
 				}
-- 
2.7.4

  reply	other threads:[~2016-11-02 13:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02 13:14 [PATCH net-next iproute2 0/2 v2] Add support for operating raw sockest via diag interface Cyrill Gorcunov
2016-11-02 13:14 ` Cyrill Gorcunov [this message]
2016-11-02 13:14 ` [PATCH net-next iproute2 PATCH 2/2 v2] ss: Add inet raw sockets information gathering via netlink " Cyrill Gorcunov
2016-11-02 21:24   ` David Ahern
2016-12-01 18:57   ` Stephen Hemminger
2016-12-01 19:13     ` Cyrill Gorcunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478092496-7540-2-git-send-email-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=avagin@openvz.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).