From patchwork Sat Jan 23 04:53:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edwin Peer X-Patchwork-Id: 12041107 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35A61C433E0 for ; Sat, 23 Jan 2021 04:55:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0D4B23AA1 for ; Sat, 23 Jan 2021 04:55:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726822AbhAWEzB (ORCPT ); Fri, 22 Jan 2021 23:55:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbhAWEyw (ORCPT ); Fri, 22 Jan 2021 23:54:52 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7101C061794 for ; Fri, 22 Jan 2021 20:53:59 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id 11so5180263pfu.4 for ; Fri, 22 Jan 2021 20:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=LI6HKM/0jE7QF0K+h0o5q3QojmaF5bUVzmQHTFlOYdk=; b=GkL0M0V/Jfs/BUU9I9u7abs/+DHik3sM/GkLr+7gxHX38Nrr9OgL6Oij/m9UZlAdFM CmUeqRWO/U7KkEOJQ9fs7NA1Ly91/RO4IYMUQlGK4sR4Z5Xk2jyF33+DDh4F5as27Zyx cLA7UiezGIKCvIRPszJsH9cLMS93wUk+uf9/E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=LI6HKM/0jE7QF0K+h0o5q3QojmaF5bUVzmQHTFlOYdk=; b=jqIiPHfX0bPdcQO1UuNwtNzhdBoYoRKfbEf778eoqJQoF4r1i+SHiPOK5Eev1uMmxd 9PKVqG0QEcRhQU4EXfm+bLiJMThHVwTCXmXNVv1wSOu5oAzonNUBlpY4/etrOwmmxJA2 GviIzFOPYicZIbZxcWtJAuRHe1UfRaVADBmoFp0IskCpVbw7TJ1teMgYq5Exz5/89dcU 0k+D//PiyTzTrUL5r+7SYnBSvvVja9gI7YDexsgCGE4/gnc/XEDVihVavD4XYj2NvqGW UfvVaeo1lAkg4eaczscrg9fv1rlGcj2OPEPsW6fXJUguWdOQxx29CAJ+i4YlTksE5dnw UVWg== X-Gm-Message-State: AOAM53266wvQclhNiPI/1SUgOH/y31EyQ7RkoiF3vwrHxOBNcmotGDZf aZ7JilUVF243KSwYstwGbEg2k0gyh31tBszaUgBu2M3uoxvLW1bbIQSSJsO9U2O0MvVZQX/VkAm UpivoawFWf+h5zArxpw6Hm4ne75nRKgVpHSlaefHOtgZqGglEqodsn1+uwZC7N2U9NZr97PiI X-Google-Smtp-Source: ABdhPJxpZWybz67XNnA04/l/wnN39xhCGxsaecNgaEx4vqTN1ucp4QMmlEdlh2u7wGs8DGlPcxeFRw== X-Received: by 2002:a62:31c7:0:b029:1b8:4194:8982 with SMTP id x190-20020a6231c70000b02901b841948982mr8354488pfx.33.1611377638639; Fri, 22 Jan 2021 20:53:58 -0800 (PST) Received: from hex.swdvt.lab.broadcom.net ([2600:8802:d04:de02::77c]) by smtp.gmail.com with ESMTPSA id k3sm9675743pgm.94.2021.01.22.20.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 20:53:57 -0800 (PST) From: Edwin Peer To: netdev@vger.kernel.org Cc: Edwin Peer , Jakub Kicinski , Andrew Gospodarek , Michael Chan , Stephen Hemminger , Michal Kubecek , David Ahern Subject: [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data Date: Fri, 22 Jan 2021 20:53:49 -0800 Message-Id: <20210123045351.2797433-2-edwin.peer@broadcom.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210123045351.2797433-1-edwin.peer@broadcom.com> References: <20210123045351.2797433-1-edwin.peer@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com 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 --- 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)) {