All of lore.kernel.org
 help / color / mirror / Atom feed
From: Edwin Peer <edwin.peer@broadcom.com>
To: netdev@vger.kernel.org
Cc: Edwin Peer <edwin.peer@broadcom.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Andrew Gospodarek <andrew.gospodarek@broadcom.com>,
	Michael Chan <michael.chan@broadcom.com>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Michal Kubecek <mkubecek@suse.cz>,
	David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data
Date: Fri, 22 Jan 2021 20:53:49 -0800	[thread overview]
Message-ID: <20210123045351.2797433-2-edwin.peer@broadcom.com> (raw)
In-Reply-To: <20210123045351.2797433-1-edwin.peer@broadcom.com>

[-- Attachment #1: Type: text/plain, Size: 3227 bytes --]

The kernel might truncate VF info in IFLA_VFINFO_LIST. Sufficiently new
kernels will provide NLM_F_NEST_TRUNCATED in these cases, but this flag
has limited resolution, as it pertains to the entire netlink message. A
better approach is to compare the expected number of VFs in IFLA_NUM_VF
to how many were found in the list and warn accordingly.

Signed-off-by: Edwin Peer <edwin.peer@broadcom.com>
---
 ip/ipaddress.c   |  9 ++++++++-
 lib/libnetlink.c | 12 ++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 571346b15cc3..0bbcee2b3bb2 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -922,6 +922,7 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 	const char *name;
 	unsigned int m_flag = 0;
 	SPRINT_BUF(b1);
+	bool truncated_vfs = false;
 
 	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
 		return 0;
@@ -1199,15 +1200,18 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 
 	if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) {
 		struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST];
-		int rem = RTA_PAYLOAD(vflist);
+		int rem = RTA_PAYLOAD(vflist), count = 0;
 
 		open_json_array(PRINT_JSON, "vfinfo_list");
 		for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 			open_json_object(NULL);
 			print_vfinfo(fp, ifi, i);
 			close_json_object();
+			count++;
 		}
 		close_json_array(PRINT_JSON, NULL);
+		if (count != rta_getattr_u32(tb[IFLA_NUM_VF]))
+			truncated_vfs = true;
 	}
 
 	if (tb[IFLA_PROP_LIST]) {
@@ -1228,6 +1232,9 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 
 	print_string(PRINT_FP, NULL, "%s", "\n");
 	fflush(fp);
+	/* prettier here if stderr and stdout go to the same place */
+	if (truncated_vfs)
+		fprintf(stderr, "Truncated VF list: %s\n", name);
 	return 1;
 }
 
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index c958aa57d0cd..b1f07d4570cf 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -833,6 +833,9 @@ static int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
 					dump_intr = 1;
 
+				if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+					fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					err = rtnl_dump_done(h);
 					if (err < 0) {
@@ -978,6 +981,9 @@ next:
 				continue;
 			}
 
+			if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+				fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 			if (h->nlmsg_type == NLMSG_ERROR) {
 				struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
 				int error = err->error;
@@ -1156,6 +1162,9 @@ int rtnl_listen(struct rtnl_handle *rtnl,
 				exit(1);
 			}
 
+			if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+				fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 			err = handler(&ctrl, h, jarg);
 			if (err < 0)
 				return err;
@@ -1206,6 +1215,9 @@ int rtnl_from_file(FILE *rtnl, rtnl_listen_filter_t handler,
 			return -1;
 		}
 
+		if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+			fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 		status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl);
 
 		if (status != NLMSG_ALIGN(l)) {
-- 
2.30.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4160 bytes --]

  reply	other threads:[~2021-01-23  4:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23  4:53 [PATCH iproute2-next 1/4] uapi: update kernel headers from upstream Edwin Peer
2021-01-23  4:53 ` Edwin Peer [this message]
2021-01-23  4:53 ` [PATCH iproute2-next 3/4] iplink: filter stats using RTEXT_FILTER_SKIP_STATS Edwin Peer
2021-01-23  4:53 ` [PATCH iproute2-next 4/4] iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST Edwin Peer

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=20210123045351.2797433-2-edwin.peer@broadcom.com \
    --to=edwin.peer@broadcom.com \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=dsahern@gmail.com \
    --cc=kuba@kernel.org \
    --cc=michael.chan@broadcom.com \
    --cc=mkubecek@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.