From nobody Sat Nov 23 15:18:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1724781685261941.2080815130482; Tue, 27 Aug 2024 11:01:25 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 36EA011F4; Tue, 27 Aug 2024 14:01:24 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0832911D8; Tue, 27 Aug 2024 14:00:59 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 43465A2B; Tue, 27 Aug 2024 14:00:55 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C722B11C1 for ; Tue, 27 Aug 2024 14:00:54 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-3Zuy9n_9Olav18ixFbhWZw-1; Tue, 27 Aug 2024 14:00:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93C911955BF2; Tue, 27 Aug 2024 18:00:51 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.225.168]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A2E551956048; Tue, 27 Aug 2024 18:00:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724781654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ajv6E6EUeMedoOYhw3u1xKvBX8bj74Rusobi6qx//CU=; b=TugWGjQTb4aGK8xMGB3goE38m4dfBUpfYJk8DwBciqXw2oqugzSiP/Nw9+DT6IZ8Q9BFx8 zs2gnGTYAqyhtw36VX4ox0FpZ6szeSLYSqy4TLYJM4CP8R3NhBulOTSYvH6wTvNOJyBCvC 3GtNENpZ7glhBC/PoH9YpzLhc67+iHs= X-MC-Unique: 3Zuy9n_9Olav18ixFbhWZw-1 From: Pavel Hrdina To: devel@lists.libvirt.org Subject: [libvirt PATCH] ch: interface: correctly update nicindexes Date: Tue, 27 Aug 2024 20:00:49 +0200 Message-ID: <92f3547c8f300a1116f911f05bcc51639b6aede3.1724781519.git.phrdina@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: T4NTKG3X72SLDGW2X3SKNC3L4AESKXKY X-Message-ID-Hash: T4NTKG3X72SLDGW2X3SKNC3L4AESKXKY X-MailFrom: phrdina@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: praveenkpaladugu@gmail.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724781686105116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Originally nicindexes were updated only for VIR_DOMAIN_NET_TYPE_BRIDGE and VIR_DOMAIN_NET_TYPE_DIRECT. The mentioned commit adds support for NAT network mode and changes the code to update nicindexes for VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK as well. It doesn't work as intended and after the change nicindexes are updated only for VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK. Fixes: aa642090738eb276f7bd70dea97d3a4fd03d59e3 Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/ch/ch_interface.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/ch/ch_interface.c b/src/ch/ch_interface.c index 47b02bc322..87a95cde53 100644 --- a/src/ch/ch_interface.c +++ b/src/ch/ch_interface.c @@ -34,6 +34,26 @@ =20 VIR_LOG_INIT("ch.ch_interface"); =20 + +static int +virCHInterfaceUpdateNicindexes(virDomainNetDef *net, + int **nicindexes, + size_t *nnicindexes) +{ + int nicindex =3D 0; + + if (!nicindexes || !nnicindexes || !net->ifname) + return 0; + + if (virNetDevGetIndex(net->ifname, &nicindex) < 0) + return -1; + + VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex); + + return 0; +} + + /** * virCHConnetNetworkInterfaces: * @driver: pointer to ch driver object @@ -78,6 +98,8 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, net->driver.virtio.queues) <= 0) return -1; =20 + if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) <= 0) + return -1; break; case VIR_DOMAIN_NET_TYPE_NETWORK: if (virDomainInterfaceBridgeConnect(vm, net, @@ -88,9 +110,15 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, false, NULL) < 0) return -1; + + if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) <= 0) + return -1; break; case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_DIRECT: + if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) <= 0) + return -1; + break; case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: @@ -109,19 +137,5 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, return -1; } =20 - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_ETHERNET || - actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK || - actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || - actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { - if (nicindexes && nnicindexes && net->ifname) { - int nicindex =3D 0; - - if (virNetDevGetIndex(net->ifname, &nicindex) < 0) - return -1; - - VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex); - } - } - return 0; } --=20 2.46.0