From nobody Sun Nov 24 11:02:43 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=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 172255121249782.92383446628958; Thu, 1 Aug 2024 15:26:52 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 427A61424; Thu, 1 Aug 2024 18:26:51 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 508C1143D; Thu, 1 Aug 2024 18:25:25 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0E79A13BA; Thu, 1 Aug 2024 18:25:19 -0400 (EDT) Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 6010413BC for ; Thu, 1 Aug 2024 18:25:18 -0400 (EDT) Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7093efbade6so5110487a34.2 for ; Thu, 01 Aug 2024 15:25:18 -0700 (PDT) Received: from home.. ([2603:8081:c640:1::1002]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70a3a768e12sm178646a34.65.2024.08.01.15.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 15:25:16 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722551117; x=1723155917; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+lnhYyYNI+85UqvH5eMCFZKGrdy13XgUqFvZ9tQ920s=; b=RbtpNkHoNyYbZysfBt4TsZmuYXugYTVvIsrkplQnpenHJEC6ZaamZc+9jPjU26bqvi Nm+KTp+rE9JVQ0VrXxFCS7WsM4DEQv+gF5ZuTJx+VXeiQhQH+Mitk5FevhqaL/OjwBLT PNX46saH5VZtxjm3ssYb2fuJh+5+KOALqgHTWdXR9m2zoUKBKSdZ+graC5hZbenXeijt rVUQReYQvqmm10BJGKRw3XFAA0olmWc1+hBdrFLGSD6t5RjdDeoUHQof5siEhJDWE2fs yWSellKy7jLw0wc8ve1vLQfQOnJ+ZR/JB4Wrm5eshw/LOSX+uG6ru6TUswRQYA9M1NTA p21Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722551117; x=1723155917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+lnhYyYNI+85UqvH5eMCFZKGrdy13XgUqFvZ9tQ920s=; b=Bb+ZBQmork2kCVH7QjW4FIt/J3G+UkSCauzPsNmw+gcxqeZamtPVkeA8CQ10fuWhah g+oxj0WvrfYhIJSzgx840B56hIHtBd6SfSyB5mhkTgmiTydpsQNVlXqyBvHxi7eVHlDf F6hjdTMRS8KqgMlgS0zt5VSAPXZn+xlsPe2Apeq4yrgUaPmLE1Yuv02pRwjpChgZ/Umi XfXbreC5fzAilDNNXnBea0ZoiWFBR+msvIesarlW2Ewg3HKMQwbaYh6FZ5NVo1npBevM SNisCr/clz9FqPADIujQXHgWWOODDeal9Fbhbf31W0dEX46ZRzVaxHBxyAOUD6opOH5r C8Wg== X-Gm-Message-State: AOJu0YySyI37cE6punfvE+pyZAbggYjBTq3rImXTwfpWadwudsfzh0DI BuDhfJ0NSNnpHwcFlDHjE8Ba9IHnxQhbUcNfKMfcpR18stFOYmKxKXuSEZb5 X-Google-Smtp-Source: AGHT+IG5Sp3MpAIHiNM+Wj+7wF8E4oZipUYbSigxmsxc285LtVhS13cJv4nqSpD+mXaXBeveEmIbKQ== X-Received: by 2002:a05:6830:660c:b0:704:4563:b66a with SMTP id 46e09a7af769-709b31fc96amr2331126a34.4.1722551117171; Thu, 01 Aug 2024 15:25:17 -0700 (PDT) From: Praveen K Paladugu X-Google-Original-From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH 2/2] ch: Enable NAT Network mode support Date: Thu, 1 Aug 2024 17:25:14 -0500 Message-ID: <20240801222514.16742-3-prapal@linux.microsoft.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240801222514.16742-1-prapal@linux.microsoft.com> References: <20240801222514.16742-1-prapal@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VDTGTEMUXZHZWMP2NOGDNKC6SPSQPXRS X-Message-ID-Hash: VDTGTEMUXZHZWMP2NOGDNKC6SPSQPXRS X-MailFrom: praveenkpaladugu@gmail.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: liuwe@microsoft.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: 1722551214449116600 Content-Type: text/plain; charset="utf-8" From: Praveen K Paladugu From: Praveen K Paladugu enable VIR_DOMAIN_NET_TYPE_NETWORK network support for ch guests. Tested with following config: Signed-off-by: Praveen K Paladugu Signed-off-by: Praveen K Paladugu --- src/ch/ch_interface.c | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/ch/ch_interface.c b/src/ch/ch_interface.c index c7af6a35fa..07bdd71560 100644 --- a/src/ch/ch_interface.c +++ b/src/ch/ch_interface.c @@ -28,7 +28,7 @@ #include "ch_interface.h" #include "virjson.h" #include "virlog.h" - +#include "datatypes.h" =20 #define VIR_FROM_THIS VIR_FROM_CH =20 @@ -39,8 +39,9 @@ VIR_LOG_INIT("ch.ch_interface"); * @driver: pointer to ch driver object * @vm: pointer to domain definition * @net: pointer to a guest net - * @nicindexes: returned array of FDs of guest interfaces - * @nnicindexes: returned number of guest interfaces + * @tapfds: returned array of tap FDs + * @nicindexes: returned array list of network interface indexes + * @nnicindexes: returned number of network interfaces * * * Returns 0 on success, -1 on error. @@ -49,10 +50,24 @@ int virCHConnetNetworkInterfaces(virCHDriver *driver, virDomainDef *vm, virDomainNetDef *net, - int *tapfds, int **nicindexes, size_t *nnicin= dexes) + int *tapfds, + int **nicindexes, size_t *nnicindexes) { virDomainNetType actualType =3D virDomainNetGetActualType(net); + g_autoptr(virCHDriverConfig) cfg =3D virCHDriverGetConfig(driver); + g_autoptr(virConnect) conn =3D NULL; + =20 + /* If appropriate, grab a physical device from the configured + * network's pool of devices, or resolve bridge device name + * to the one defined in the network definition. + */ + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!(conn =3D virGetConnectNetwork())) + return -1; + if (virDomainNetAllocateActualDevice(conn, vm, net) < 0) + return -1; + } =20 switch (actualType) { case VIR_DOMAIN_NET_TYPE_ETHERNET: @@ -63,20 +78,19 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, net->driver.virtio.queues) <= 0) return -1; =20 - G_GNUC_FALLTHROUGH; + break; case VIR_DOMAIN_NET_TYPE_NETWORK: + if (virDomainInterfaceBridgeConnect(vm, net, + tapfds, + net->driver.virtio.queues, + driver->privileged, + driver->ebtables, + false, + NULL) < 0) + return -1; + break; case VIR_DOMAIN_NET_TYPE_BRIDGE: case 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); - } - - break; case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: @@ -94,6 +108,19 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, _("Unsupported Network type %1$d"), actualType); return -1; } + 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); + } + } =20 return 0; } --=20 2.44.0