From nobody Mon Feb 9 07:05:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610331880; cv=none; d=zohomail.com; s=zohoarc; b=LuhLOAuopJpao5NFEv7ln55cZ8R1c4sSIXfJeHPQxDt/+fGcZFN25RF5SOSI0gF0VW60KOfeBOk+Ztq3MMiQ5YNjr6WxsRqnPo7UY/CZab/RWXv+xYHjNghS5W8RCDAuDLvrg7SCMlUyB1lEkOjDHDajGyJMbF7g+xtNxnYlO+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610331880; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eFaiqBVe31PoZbB2F6fBi7u9XCguRd2mIz6Gp3bFLR0=; b=IrvXzaWrzDpp8+D3e972/ofKnHdR5N3ef/PdEGQl5FtBRdDbL9GfZ3vW3WtruYubj2ftV2UeR0lNla3bsPuLVQosQTY5H4IqR7a9cS2FGLeWMmpQkxg1QwtG727BAG0e/9VsxZQoy1q1grJ4g7758OLVME3VZqMwMhSvVX0QXWY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1610331880733838.1391840765833; Sun, 10 Jan 2021 18:24:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-qtki3yXfOta-Q5NmGj8YAg-1; Sun, 10 Jan 2021 21:24:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E8CC180A093; Mon, 11 Jan 2021 02:24:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2B585D769; Mon, 11 Jan 2021 02:24:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5ED684BB7B; Mon, 11 Jan 2021 02:24:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10B2ON2f007226 for ; Sun, 10 Jan 2021 21:24:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1145D30BBA; Mon, 11 Jan 2021 02:24:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C20A2EF8E for ; Mon, 11 Jan 2021 02:24:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED9A7811E86 for ; Mon, 11 Jan 2021 02:24:22 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-193-95m_8NOUNi6rFtagtkwmvw-1; Sun, 10 Jan 2021 21:24:18 -0500 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp2 (Coremail) with SMTP id iOCowAAnkeDCtvtfIO+DCw--.10533S4; Mon, 11 Jan 2021 10:24:09 +0800 (CST) X-MC-Unique: qtki3yXfOta-Q5NmGj8YAg-1 X-MC-Unique: 95m_8NOUNi6rFtagtkwmvw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [PATCHv3 2/4] netlink: Minor changes for macros NETLINK_MSG_[NEST_START|NEST_END|PUT] Date: Mon, 11 Jan 2021 10:23:35 +0800 Message-Id: <20210111022337.27473-3-shi_lei@massclouds.com> In-Reply-To: <20210111022337.27473-1-shi_lei@massclouds.com> References: <20210111022337.27473-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowAAnkeDCtvtfIO+DCw--.10533S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF17XFWUJry7GFykZr4xWFg_yoWrWr1kpa 43KFy7Jr4UJw47Xrnaka4UWa43ZFZYgr15G34xKws2ya17JFyIqry2gas5ZryfC3yDJr4a y3ZI9r45Cw4fXaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0J1jG-5UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiQgcXT1bdHkBO+QAAs- X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, Shi Lei X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move macros NETLINK_MSG_[NEST_START|NEST_END|PUT] from .h into .c; within these macros, replace 'goto' with reporting error and returning; simplify virNetlinkDumpLink and virNetlinkDelLink by using NETLINK_MSG_PUT. Signed-off-by: Shi Lei --- src/util/virnetlink.c | 44 +++++++++++++++++++++++++++++++++---------- src/util/virnetlink.h | 23 ---------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 17e6eeb9..0b55b124 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -44,6 +44,35 @@ VIR_LOG_INIT("util.netlink"); =20 # include =20 +# define NETLINK_MSG_NEST_START(msg, container, attrtype) \ +do { \ + container =3D nla_nest_start(msg, attrtype); \ + if (!container) { \ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ + _("allocated netlink buffer is too small")); \ + return -1; \ + } \ +} while (0) + +# define NETLINK_MSG_NEST_END(msg, container) \ +do { nla_nest_end(msg, container); } while (0) + +/* + * we need to use an intermediary pointer to @data as compilers may someti= mes + * complain about @data not being a pointer type: + * error: the address of 'foo' will always evaluate as 'true' [-Werror=3Da= ddress] + */ +# define NETLINK_MSG_PUT(msg, attrtype, datalen, data) \ +do { \ + const void *dataptr =3D data; \ + if (dataptr && nla_put(msg, attrtype, datalen, dataptr) < 0) { \ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ + _("allocated netlink buffer is too small")); \ + return -1; \ + } \ +} while (0) + + /* State for a single netlink event handle */ struct virNetlinkEventHandle { int watch; @@ -406,10 +435,8 @@ virNetlinkDumpLink(const char *ifname, int ifindex, if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0) goto buffer_too_small; =20 - if (ifname) { - if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0) - goto buffer_too_small; - } + if (ifname) + NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname); =20 # ifdef RTEXT_FILTER_VF /* if this filter exists in the kernel's netlink implementation, @@ -419,10 +446,8 @@ virNetlinkDumpLink(const char *ifname, int ifindex, { uint32_t ifla_ext_mask =3D RTEXT_FILTER_VF; =20 - if (nla_put(nl_msg, IFLA_EXT_MASK, - sizeof(ifla_ext_mask), &ifla_ext_mask) < 0) { - goto buffer_too_small; - } + NETLINK_MSG_PUT(nl_msg, IFLA_EXT_MASK, + sizeof(ifla_ext_mask), &ifla_ext_mask); } # endif =20 @@ -636,8 +661,7 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0) goto buffer_too_small; =20 - if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0) - goto buffer_too_small; + NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname); =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) { diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 7c4ed202..966d6db3 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -38,29 +38,6 @@ struct nlmsghdr; =20 #endif /* WITH_LIBNL */ =20 -#define NETLINK_MSG_NEST_START(msg, container, attrtype) \ -do { \ - container =3D nla_nest_start(msg, attrtype); \ - if (!container) \ - goto buffer_too_small; \ -} while(0) - -#define NETLINK_MSG_NEST_END(msg, container) \ -do { nla_nest_end(msg, container); } while(0) - -/* - * we need to use an intermediary pointer to @data as compilers may someti= mes - * complain about @data not being a pointer type: - * error: the address of 'foo' will always evaluate as 'true' [-Werror=3Da= ddress] - */ -#define NETLINK_MSG_PUT(msg, attrtype, datalen, data) \ -do { \ - const void *dataptr =3D data; \ - if (dataptr && nla_put(msg, attrtype, datalen, dataptr) < 0) \ - goto buffer_too_small; \ -} while(0) - - int virNetlinkStartup(void); void virNetlinkShutdown(void); =20 --=20 2.25.1