From nobody Fri Apr 26 00:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642086566300966.7303276651173; Thu, 13 Jan 2022 07:09:26 -0800 (PST) Received: from localhost ([::1]:48860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n81jB-0003jc-6L for importer@patchew.org; Thu, 13 Jan 2022 10:09:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n81bg-0002Kx-A5 for qemu-devel@nongnu.org; Thu, 13 Jan 2022 10:01:40 -0500 Received: from [2a00:1450:4864:20::136] (port=42693 helo=mail-lf1-x136.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n81bd-0003df-Ie for qemu-devel@nongnu.org; Thu, 13 Jan 2022 10:01:40 -0500 Received: by mail-lf1-x136.google.com with SMTP id e3so17693734lfc.9 for ; Thu, 13 Jan 2022 07:01:37 -0800 (PST) Received: from UNIT-808.labs.intellij.net ([91.132.204.20]) by smtp.gmail.com with ESMTPSA id w25sm314278lfl.155.2022.01.13.07.01.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jan 2022 07:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S1SywTA5bEA3SeEdMMJI7GgMwkgxeo13AxqEEF5FKwE=; b=NrPqSvLlmVaojvajXJHkpyF+pnGO6FidM0T8ux00lSq5yIuw+oVpAZaFvKQ10EF/2C xUy+a4CZP3WJ8DkzFz2coW7ooAHW8dtPTTNdqzoxcaXscDDDjaUog7gGJv3hJJ//9rLW yONcTdiL3ai0TfTLKnOOPYtKwG6QmVqL6LdwNzdLMaRzYCpa6GnQ2rkHhtwhaP+fYMSr lyhpGrWsawEkKBuW1cd693hG7aoeTH5T9LytLZksCjSP4KKYBqJ6Q8mp4ZdR3AYCFnql 0a0eNezk1oefGnYgTw2uiRq8EB/PSXsAg8sxPXDDKPVyUDIPAWSp5q7jCOwmPkBTiki1 4xTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S1SywTA5bEA3SeEdMMJI7GgMwkgxeo13AxqEEF5FKwE=; b=uhDew/RodCF+fa2xe/JsCRf5MZbmtDrLSgXRQG9NJoZ95za4ijPRRu79QJuGsMz1WP Ui8Yu+gQSqWee9+Iq3lSQWch29MYu8gctbJ1TvZfvJAY1nM9FYdcb7mMMv9ut6oTCRb8 rFQ4IXdcVyn+/97ZeWIouCC0NIveEm6IF6iaO30cRVJT9y9tGk3ZbvLV3AHlKHZo01NU oDiVt6vdOKsz3QmSNeS7fv//xaAfmWL5M6f123aAMRceK45QrYlQD2sUpH2YKl5sDqN5 86t4L/M74mA4Wl074eQktO3uL8eXWM2xaVs8cFA/HLUcVbGUjOy1lVhjlNBtj/wrAvaQ T7HA== X-Gm-Message-State: AOAM531CH6KOTsUOiad1Np1ubh7dMycxz/nTlKEl4eRG2unYCrComktj MGoNHRHONpMewTdhEyfPomA+0jR+iJb0h9+1 X-Google-Smtp-Source: ABdhPJy7SNx16S1dKBvkpOr98C7HcpcdmhYV0X0NZmobwoWXDfRlxipXtB6LEBy7GDSjZRHjxg8B4Q== X-Received: by 2002:a05:6512:b06:: with SMTP id w6mr3465992lfu.433.1642086094725; Thu, 13 Jan 2022 07:01:34 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v12 5/7] net/vmnet: implement bridged mode (vmnet-bridged) Date: Thu, 13 Jan 2022 18:01:11 +0300 Message-Id: <20220113150113.58437-6-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220113150113.58437-1-yaroshchuk2000@gmail.com> References: <20220113150113.58437-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::136 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lf1-x136.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladislav Yaroshchuk , jasowang@redhat.com, phillip.ennen@gmail.com, armbru@redhat.com, r.bolshakov@yadro.com, phillip@axleos.com, akihiko.odaki@gmail.com, hsp.cat7@gmail.com, hello@adns.io, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642086568619100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladislav Yaroshchuk --- net/vmnet-bridged.m | 105 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 5 deletions(-) diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m index 4e42a90391..f528af036c 100644 --- a/net/vmnet-bridged.m +++ b/net/vmnet-bridged.m @@ -10,16 +10,111 @@ =20 #include "qemu/osdep.h" #include "qapi/qapi-types-net.h" -#include "vmnet_int.h" -#include "clients.h" -#include "qemu/error-report.h" #include "qapi/error.h" +#include "clients.h" +#include "vmnet_int.h" =20 #include =20 +typedef struct VmnetBridgedState { + VmnetCommonState cs; +} VmnetBridgedState; + +static bool validate_ifname(const char *ifname) +{ + xpc_object_t shared_if_list =3D vmnet_copy_shared_interface_list(); + __block bool match =3D false; + + xpc_array_apply( + shared_if_list, + ^bool(size_t index, xpc_object_t value) { + if (strcmp(xpc_string_get_string_ptr(value), ifname) =3D=3D 0) { + match =3D true; + return false; + } + return true; + }); + + return match; +} + +static const char *get_valid_ifnames(void) +{ + xpc_object_t shared_if_list =3D vmnet_copy_shared_interface_list(); + __block char *if_list =3D NULL; + + xpc_array_apply( + shared_if_list, + ^bool(size_t index, xpc_object_t value) { + if_list =3D g_strconcat(xpc_string_get_string_ptr(value), + " ", + if_list, + NULL); + return true; + }); + + if (if_list) { + return if_list; + } + return "[no interfaces]"; +} + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp) +{ + const NetdevVmnetBridgedOptions *options =3D &(netdev->u.vmnet_bridged= ); + xpc_object_t if_desc =3D xpc_dictionary_create(NULL, NULL, 0); + + xpc_dictionary_set_uint64( + if_desc, + vmnet_operation_mode_key, + VMNET_BRIDGED_MODE + ); + +#if defined(MAC_OS_VERSION_11_0) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_VERSION_11_0 + xpc_dictionary_set_bool( + if_desc, + vmnet_enable_isolation_key, + options->isolated + ); +#else + if (options->has_isolated) { + error_setg(errp, + "vmnet-bridged.isolated feature is " + "unavailable: outdated vmnet.framework API"); + } +#endif + + if (validate_ifname(options->ifname)) { + xpc_dictionary_set_string(if_desc, + vmnet_shared_interface_name_key, + options->ifname); + } else { + return NULL; + } + return if_desc; +} + +static NetClientInfo net_vmnet_bridged_info =3D { + .type =3D NET_CLIENT_DRIVER_VMNET_BRIDGED, + .size =3D sizeof(VmnetBridgedState), + .receive =3D vmnet_receive_common, + .cleanup =3D vmnet_cleanup_common, +}; + int net_init_vmnet_bridged(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { - error_setg(errp, "vmnet-bridged is not implemented yet"); - return -1; + NetClientState *nc =3D qemu_new_net_client(&net_vmnet_bridged_info, + peer, "vmnet-bridged", name); + xpc_object_t if_desc =3D create_if_desc(netdev, errp);; + + if (!if_desc) { + error_setg(errp, + "unsupported ifname, should be one of: %s", + get_valid_ifnames()); + return -1; + } + + return vmnet_if_create(nc, if_desc, errp, NULL); } --=20 2.23.0