From nobody Tue Feb 10 08:03:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=jetbrains.com ARC-Seal: i=1; a=rsa-sha256; t=1645809823; cv=none; d=zohomail.com; s=zohoarc; b=YLn5I26++Ew5W+Rjib90lYzCqG1+YIthXFHqEwzKukCEfg44TJ/VVwN450bnFwKNaGdbkAfaMqELzX5cJ4ek/y01kKYCedRszme3FR/InfarlPgZOW26YxCK0S1i/04Q6oVJJFXj/1lM9vlZHfiZ0zlxk7fFCQX1QhNPjA3CUZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645809823; h=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=v7no45Cg1W0LRKhNzoQg5XczUdm3gvdwwe9l+1jYHe4=; b=T9LZXVxQ4+C4ksjwj7/BIL1EsqtBV56JNbaQ4x1JJoKGUeSBLpU0j2qhAtma0dJTzRd3/luD8fDC91T6ov7UhU2c2ZaZ38SbabGS7i9SWrGLwD9bSTaFFHJ7sWzln0+EoNaWkbIzbGBHRa4s434jVY3ibC4UYIT2mAnfjDqQ8IY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164580982378751.170727570373856; Fri, 25 Feb 2022 09:23:43 -0800 (PST) Received: from localhost ([::1]:60430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNeJi-0007S4-T5 for importer@patchew.org; Fri, 25 Feb 2022 12:23:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNdqZ-0002ap-GH for qemu-devel@nongnu.org; Fri, 25 Feb 2022 11:53:35 -0500 Received: from [2a00:1450:4864:20::12c] (port=37633 helo=mail-lf1-x12c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNdqV-00048L-Ct for qemu-devel@nongnu.org; Fri, 25 Feb 2022 11:53:35 -0500 Received: by mail-lf1-x12c.google.com with SMTP id m14so10440622lfu.4 for ; Fri, 25 Feb 2022 08:53:31 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2a:768f:813e:378d:5c94:9b97]) by smtp.gmail.com with ESMTPSA id l11-20020a2e834b000000b00246308690e2sm309683ljh.85.2022.02.25.08.53.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Feb 2022 08:53:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetbrains.com; s=googleapps; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v7no45Cg1W0LRKhNzoQg5XczUdm3gvdwwe9l+1jYHe4=; b=YGO7uIGR+uFxYQG+4SEiDLdpA0GN8+ldrSLEW2LegS0gTik25H15xvmK7fdBKWqQju FyDQpVbZ218h+CB6SIQB/rgvz+AIUEDik3YZJIRC9sCd0BfP2LGRa7N4LEMz+7GYLXm4 Eq9h3vbioZl5IwtpTG6EUmMW/CUf5yv3dcwu0= 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=v7no45Cg1W0LRKhNzoQg5XczUdm3gvdwwe9l+1jYHe4=; b=CcsW5qWuNosn97aVnHIid9tSbG+g6EQPrz5F9LyJC7T1wq6phpgJn9TeQR0qJ/Xwe0 5kWAiaKTLlgkT0bG1WBPh7YvYj5lyoznqWOle7OTrbO+Ovri3fnuNywVxqgSZVsn4tqA NwnF8Sh2mAIYqqrx3r09m72GVwseGQ9wQrvFDv8+clFMTjhReHJBKpbDecss98Y9Jsbp EwhlI6SDpjC3XGj1Qch/aZB1BMjljwjtslplPSc7d7kX0yX6zLurPGvz5xLb5FNH5eBy wj9GcDlpHPPsVcWbHCUV6Bd7gSV/3Ialg2AKdfnwCw3BxU//NQjnIgnAmuBp1Y81wVbW 3W9g== X-Gm-Message-State: AOAM5336kdLGn7gs+QOMeaynfFBMUCajJIlYMIZzzwd2xWh0+UrvsqeT FEgAp6BTHw7AT6//AdJt/kHJVAQbNSJ8og== X-Google-Smtp-Source: ABdhPJxh5RZYyq2BulIgb8qv54HUzdMZ8R00JZx4Tcme6/6w8TWktkfDFpsw6tbvaDGwB7nTQehD1g== X-Received: by 2002:a05:6512:38c4:b0:443:7b86:e129 with SMTP id p4-20020a05651238c400b004437b86e129mr5600725lft.48.1645808009545; Fri, 25 Feb 2022 08:53:29 -0800 (PST) From: Vladislav Yaroshchuk X-Google-Original-From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Cc: jasowang@redhat.com, r.bolshakov@yadro.com, eblake@redhat.com, phillip.ennen@gmail.com, phillip@axleos.com, akihiko.odaki@gmail.com, armbru@redhat.com, hsp.cat7@gmail.com, hello@adns.io, roman@roolebo.dev, peter.maydell@linaro.org, dirty@apple.com, f4bug@amsat.org, agraf@csgraf.de, kraxel@redhat.com, alex.bennee@linaro.org, qemu_oss@crudebyte.com, Vladislav Yaroshchuk Subject: [PATCH v14 4/8] net/vmnet: implement host mode (vmnet-host) Date: Fri, 25 Feb 2022 19:52:34 +0300 Message-Id: <20220225165238.63646-5-Vladislav.Yaroshchuk@jetbrains.com> X-Mailer: git-send-email 2.34.1.vfs.0.0 In-Reply-To: <20220225165238.63646-1-Vladislav.Yaroshchuk@jetbrains.com> References: <20220225165238.63646-1-Vladislav.Yaroshchuk@jetbrains.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::12c (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::12c; envelope-from=vladislav.yaroshchuk@jetbrains.com; helo=mail-lf1-x12c.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 25 Feb 2022 12:16:18 -0500 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @jetbrains.com) X-ZM-MESSAGEID: 1645809825907100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladislav Yaroshchuk --- net/vmnet-host.c | 115 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 6 deletions(-) diff --git a/net/vmnet-host.c b/net/vmnet-host.c index 32dc437037..2a711400e7 100644 --- a/net/vmnet-host.c +++ b/net/vmnet-host.c @@ -9,16 +9,119 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/uuid.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 VmnetHostState { + VmnetCommonState cs; + QemuUUID network_uuid; +} VmnetHostState; + +static bool validate_options(const Netdev *netdev, Error **errp) +{ + const NetdevVmnetHostOptions *options =3D &(netdev->u.vmnet_host); + QemuUUID uuid; + +#if defined(MAC_OS_VERSION_11_0) && \ + MAC_OS_X_VERSION_MIN_REQUIRED >=3D MAC_OS_VERSION_11_0 + + if (options->has_net_uuid && + qemu_uuid_parse(options->net_uuid, &uuid) < 0) { + error_setg(errp, "Invalid UUID provided in 'net-uuid'"); + return false; + } +#else + if (options->has_isolated) { + error_setg(errp, + "vmnet-host.isolated feature is " + "unavailable: outdated vmnet.framework API"); + return false; + } + + if (options->has_net_uuid) { + error_setg(errp, + "vmnet-host.net-uuid feature is " + "unavailable: outdated vmnet.framework API"); + return false; + } +#endif + + if ((options->has_start_address || + options->has_end_address || + options->has_subnet_mask) && + !(options->has_start_address && + options->has_end_address && + options->has_subnet_mask)) { + error_setg(errp, + "'start-address', 'end-address', 'subnet-mask' " + "should be provided together"); + return false; + } + + return true; +} + +static xpc_object_t build_if_desc(const Netdev *netdev, + NetClientState *nc) +{ + const NetdevVmnetHostOptions *options =3D &(netdev->u.vmnet_host); + VmnetCommonState *cs =3D DO_UPCAST(VmnetCommonState, nc, nc); + VmnetHostState *hs =3D DO_UPCAST(VmnetHostState, cs, cs); + xpc_object_t if_desc =3D xpc_dictionary_create(NULL, NULL, 0); + + xpc_dictionary_set_uint64(if_desc, + vmnet_operation_mode_key, + VMNET_HOST_MODE); + +#if defined(MAC_OS_VERSION_11_0) && \ + MAC_OS_X_VERSION_MIN_REQUIRED >=3D MAC_OS_VERSION_11_0 + + xpc_dictionary_set_bool(if_desc, + vmnet_enable_isolation_key, + options->isolated); + + if (options->has_net_uuid) { + qemu_uuid_parse(options->net_uuid, &hs->network_uuid); + xpc_dictionary_set_uuid(if_desc, + vmnet_network_identifier_key, + hs->network_uuid.data); + } +#endif + + if (options->has_start_address) { + xpc_dictionary_set_string(if_desc, + vmnet_start_address_key, + options->start_address); + xpc_dictionary_set_string(if_desc, + vmnet_end_address_key, + options->end_address); + xpc_dictionary_set_string(if_desc, + vmnet_subnet_mask_key, + options->subnet_mask); + } + + return if_desc; +} + +static NetClientInfo net_vmnet_host_info =3D { + .type =3D NET_CLIENT_DRIVER_VMNET_HOST, + .size =3D sizeof(VmnetHostState), + .receive =3D vmnet_receive_common, + .cleanup =3D vmnet_cleanup_common, +}; + int net_init_vmnet_host(const Netdev *netdev, const char *name, - NetClientState *peer, Error **errp) { - error_setg(errp, "vmnet-host is not implemented yet"); - return -1; + NetClientState *peer, Error **errp) +{ + NetClientState *nc =3D qemu_new_net_client(&net_vmnet_host_info, + peer, "vmnet-host", name); + if (!validate_options(netdev, errp)) { + g_assert_not_reached(); + } + return vmnet_if_create(nc, build_if_desc(netdev, nc), errp); } --=20 2.34.1.vfs.0.0