From nobody Sun May 5 19:31:12 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1630438232; cv=none; d=zohomail.com; s=zohoarc; b=ReSGo61z2PoWaszcL2Z7xqkUiDI0auyEICnr/dXybb/Xf6FPCz+USTkqiUtlOKZC7PMMjCkg0PQn0dyPuTmWpJoNXwlPXHIkQ5KAadbqwjnUE1+VOe4Ri7rMuFZJdBMg+vEWZKXzYDowB8nuIlxUnaqNZx/TI+1B5bPQ4DaoEXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630438232; 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=qhNnfObZtyZZs9EpNx4FogV0B3f+YivYcf4b6vuqy/w=; b=EOnXOt8GPcSo7JlFEuL84DpqRtIziaybO2sWzDqDgE3XmakkxSuQA0P9zrqLSK3l8cRR+Fv2CTAtiS9PanRvxjCLI/6G6lBQ0Fm46RqkwttNH/5LbNG0DP0TbDrvxIsbrhTXYSXx8huTcd24p69HcfSi6fx7vpgy8BMtSehRhFE= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630438232439573.5338085792685; Tue, 31 Aug 2021 12:30:32 -0700 (PDT) Received: from localhost ([::1]:38012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL9Sp-0001Js-AL for importer@patchew.org; Tue, 31 Aug 2021 15:30:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL9QS-000881-Qx for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:04 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:33292) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL9QQ-0001ie-PY for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:04 -0400 Received: by mail-lf1-x136.google.com with SMTP id p38so1279704lfa.0 for ; Tue, 31 Aug 2021 12:28:02 -0700 (PDT) Received: from UNIT-808.lan ([217.12.73.131]) by smtp.gmail.com with ESMTPSA id u13sm1254791lfq.254.2021.08.31.12.27.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Aug 2021 12:27:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qhNnfObZtyZZs9EpNx4FogV0B3f+YivYcf4b6vuqy/w=; b=nuPTdMB9Ht+KFo1/LsRv34RcLcVffM/pxLLtsU2DLgPbMshhTWQ3FqXz0slBVy3+Mh KD2Fomo2OB+Ck3U5CIAQhMxSO9DJiT6MVPZ0T7riD2vLMbogY8ifYwv7oqY6bydAOrsp UGBZyRxJCSr4kiuNLL6l6as24CJOFDg2SKmHHwGj7NcrokPEhXfZMlcrSt4VpADSodHM aMERG8R2KE4ub+D4BQh/eEZQLQTiteY2DYlSO72z/F+AWxsCIXg8DDvy27MfwV07YNqT FBie9Xu5kiajVVGHEDLHEKHyvEIVJdcmO25wPLPtOiUYidsykMzr1AApYWMgiAG+b3LD naFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qhNnfObZtyZZs9EpNx4FogV0B3f+YivYcf4b6vuqy/w=; b=A4HkCADLdIW1usV0PTpB7oJNN/AipShU/RxQRHRjybQT3BiSWG3DDF9C5YgmRK2PY8 zJpq7jWseRLhTiXSp3r9DQJ5TF/Jwdmj/U7x3IarM3eXQJt7ipXSFAv8mR0FqXD514mI 3nXl5h9tEfOsPwxYGKC0iZRZsYhua7/xWpV51zndhAFN9vMv64W1yEhZ4oTSI9kvFjZj IanlXe639CXlU/ByWLNzYiNG7Pwz9HTnU7CeXpIvI2AN4GNClnFuw6sWwngy/Z0FeVnI TvtIEVqCr1uYlqdn0bT6WwpH/WdVxsjBlbZkeW7FzTGs2V/QIVSWB6QlTCdiap4bq6KF zWCg== X-Gm-Message-State: AOAM532sBTT4o7txs+VWB204MJCbTTkAuAXzDQQ05mHmCiXbDdY9F+pC fdiDFn48rU1vWvHdn8NGEXy4UKQZmqYk0w== X-Google-Smtp-Source: ABdhPJyFRjk7iGMLftuUveJcsvQVrnikYeni3Vwy+gD8j4pNLlx3kcxJFXksd5JZWLpZwG2pjzzIMw== X-Received: by 2002:a05:6512:3b90:: with SMTP id g16mr3345665lfv.409.1630438080334; Tue, 31 Aug 2021 12:28:00 -0700 (PDT) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] net/vmnet: dependencies setup, initial preparations Date: Tue, 31 Aug 2021 22:27:15 +0300 Message-Id: <20210831192720.33406-2-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210831192720.33406-1-yaroshchuk2000@gmail.com> References: <20210831192720.33406-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, r.bolshakov@yadro.com, Vladislav Yaroshchuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1630438233320100001 Content-Type: text/plain; charset="utf-8" Add 'vmnet' customizable option and 'vmnet.framework' probe into configure; Create separate netdev per each vmnet operating mode because they use quite different settings. Especially since macOS 11.0 (vmnet.framework API gets lots of updates) Create source files for network client driver, update meson.build; Three new netdevs are added: - vmnet-host - vmnet-shared - vmnet-bridged Signed-off-by: Vladislav Yaroshchuk --- configure | 31 ++++++++++++++++ meson.build | 5 +++ net/clients.h | 11 ++++++ net/meson.build | 1 + net/net.c | 10 +++++ net/vmnet.c | 34 +++++++++++++++++ qapi/net.json | 99 ++++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 net/vmnet.c diff --git a/configure b/configure index 9a79a004d7..9884f0aff2 100755 --- a/configure +++ b/configure @@ -308,6 +308,7 @@ mpath=3D"auto" vnc=3D"auto" sparse=3D"auto" vde=3D"$default_feature" +vmnet=3D"auto" vnc_sasl=3D"auto" vnc_jpeg=3D"auto" vnc_png=3D"auto" @@ -1074,6 +1075,10 @@ for opt do ;; --enable-vde) vde=3D"yes" ;; + --disable-vmnet) vmnet=3D"no" + ;; + --enable-vmnet) vmnet=3D"yes" + ;; --disable-netmap) netmap=3D"no" ;; --enable-netmap) netmap=3D"yes" @@ -1899,6 +1904,7 @@ disabled with --disable-FEATURE, default is enabled i= f available rdma Enable RDMA-based migration pvrdma Enable PVRDMA support vde support for vde network + vmnet vmnet.framework support (macOS) netmap support for netmap network linux-aio Linux AIO support linux-io-uring Linux io_uring support @@ -2964,6 +2970,28 @@ EOF fi fi =20 +########################################## +# vmnet.framework probe +if test "$vmnet" !=3D "no" ; then + vmnet_flags=3D"-framework vmnet" + cat > $TMPC << EOF +#include +int main(void) +{ + (void) vmnet_allocate_mac_address_key; + return 0; +} +EOF + if compile_prog "" "$vmnet_flags" ; then + vmnet=3Dyes + else + if test "$vmnet" =3D "yes" ; then + feature_not_found "vmnet" "'vmnet.framework' in unsupported in this = build" + fi + vmnet=3Dno + fi +fi + ########################################## # netmap support probe # Apart from looking for netmap headers, we make sure that the host API ve= rsion @@ -4538,6 +4566,9 @@ if test "$vde" =3D "yes" ; then echo "CONFIG_VDE=3Dy" >> $config_host_mak echo "VDE_LIBS=3D$vde_libs" >> $config_host_mak fi +if test "$vmnet" =3D "yes" ; then + echo "CONFIG_VMNET=3Dy" >> $config_host_mak +fi if test "$netmap" =3D "yes" ; then echo "CONFIG_NETMAP=3Dy" >> $config_host_mak fi diff --git a/meson.build b/meson.build index bf63784812..936fab8f04 100644 --- a/meson.build +++ b/meson.build @@ -180,6 +180,7 @@ iokit =3D [] emulator_link_args =3D [] nvmm =3Dnot_found hvf =3D not_found +vmnet =3D not_found if targetos =3D=3D 'windows' socket =3D cc.find_library('ws2_32') winmm =3D cc.find_library('winmm') @@ -191,6 +192,9 @@ if targetos =3D=3D 'windows' elif targetos =3D=3D 'darwin' coref =3D dependency('appleframeworks', modules: 'CoreFoundation') iokit =3D dependency('appleframeworks', modules: 'IOKit', required: fals= e) + if config_host.has_key('CONFIG_VMNET') + vmnet =3D dependency('appleframeworks', modules: 'vmnet') + endif elif targetos =3D=3D 'sunos' socket =3D [cc.find_library('socket'), cc.find_library('nsl'), @@ -2886,6 +2890,7 @@ summary_info +=3D {'vhost-user support': config_host.= has_key('CONFIG_VHOST_USER')} summary_info +=3D {'vhost-user-blk server support': have_vhost_user_blk_se= rver} summary_info +=3D {'vhost-user-fs support': config_host.has_key('CONFIG_VH= OST_USER_FS')} summary_info +=3D {'vhost-vdpa support': config_host.has_key('CONFIG_VHOST= _VDPA')} +summary_info +=3D {'vmnet support': vmnet.found()} summary_info +=3D {'build guest agent': config_host.has_key('CONFIG_GUEST_= AGENT')} summary(summary_info, bool_yn: true, section: 'Configurable features') =20 diff --git a/net/clients.h b/net/clients.h index 92f9b59aed..c9157789f2 100644 --- a/net/clients.h +++ b/net/clients.h @@ -63,4 +63,15 @@ int net_init_vhost_user(const Netdev *netdev, const char= *name, =20 int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); +#ifdef CONFIG_VMNET +int net_init_vmnet_host(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp); + +int net_init_vmnet_shared(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp); + +int net_init_vmnet_bridged(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp); +#endif /* CONFIG_VMNET */ + #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/meson.build b/net/meson.build index 1076b0a7ab..196cf321a2 100644 --- a/net/meson.build +++ b/net/meson.build @@ -38,4 +38,5 @@ softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files(tap_p= osix)) softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('tap-win32.c')) softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: files('vhost-vdpa.c= ')) =20 +softmmu_ss.add(when: ['CONFIG_VMNET', vmnet], if_true: files('vmnet.c')) subdir('can') diff --git a/net/net.c b/net/net.c index 52c99196c6..11bc6d289c 100644 --- a/net/net.c +++ b/net/net.c @@ -1003,6 +1003,11 @@ static int (* const net_client_init_fun[NET_CLIENT_D= RIVER__MAX])( #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3] =3D net_init_l2tpv3, #endif +#ifdef CONFIG_VMNET + [NET_CLIENT_DRIVER_VMNET_HOST] =3D net_init_vmnet_host, + [NET_CLIENT_DRIVER_VMNET_SHARED] =3D net_init_vmnet_shared, + [NET_CLIENT_DRIVER_VMNET_BRIDGED] =3D net_init_vmnet_bridged, +#endif /* CONFIG_VMNET */ }; =20 =20 @@ -1088,6 +1093,11 @@ void show_netdevs(void) #endif #ifdef CONFIG_VHOST_VDPA "vhost-vdpa", +#endif +#ifdef CONFIG_VMNET + "vmnet-host", + "vmnet-shared", + "vmnet-bridged", #endif }; =20 diff --git a/net/vmnet.c b/net/vmnet.c new file mode 100644 index 0000000000..3f25afd7e8 --- /dev/null +++ b/net/vmnet.c @@ -0,0 +1,34 @@ +/* + * vmnet.c - network client wrapper for Apple vmnet.framework + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include + +int net_init_vmnet_host(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) { + error_setg(errp, "vmnet is not implemented yet"); + return -1; +} + +int net_init_vmnet_shared(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) { + error_setg(errp, "vmnet is not implemented yet"); + return -1; +} + +int net_init_vmnet_bridged(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) { + error_setg(errp, "vmnet is not implemented yet"); + return -1; +} diff --git a/qapi/net.json b/qapi/net.json index 7fab2e7cd8..f4519d194f 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -452,6 +452,89 @@ '*vhostdev': 'str', '*queues': 'int' } } =20 +## +# @NetdevVmnetHostOptions: +# +# vmnet (host mode) network backend. +# +# Allows the vmnet interface to communicate with +# other vmnet interfaces that are in host mode and also with the native ho= st. +# +# @dhcpstart: The starting IPv4 address to use for the interface. Must be = in the +# private IP range (RFC 1918). Must be specified along +# with @dhcpend and @subnetmask. +# This address is used as the gateway address. The subsequent = address +# up to and including dhcpend are placed in the DHCP pool. +# +# @dhcpend: The DHCP IPv4 range end address to use for the interface. Must= be in +# the private IP range (RFC 1918). Must be specified along +# with @dhcpstart and @subnetmask. +# +# @subnetmask: The IPv4 subnet mask to use on the interface. Must be speci= fied +# along with @dhcpstart and @subnetmask. +# +# +# Since: 6.2, +## +{ 'struct': 'NetdevVmnetHostOptions', + 'data': { + '*dhcpstart': 'str', + '*dhcpend': 'str', + '*subnetmask': 'str' + }, + 'if': 'CONFIG_VMNET' } + +## +# @NetdevVmnetSharedOptions: +# +# vmnet (shared mode) network backend. +# +# Allows traffic originating from the vmnet interface to reach the +# Internet through a network address translator (NAT). The vmnet interface +# can also communicate with the native host. By default, the vmnet interfa= ce +# is able to communicate with other shared mode interfaces. If a subnet ra= nge +# is specified, the vmnet interface can communicate with other shared mode +# interfaces on the same subnet. +# +# @dhcpstart: The starting IPv4 address to use for the interface. Must be = in the +# private IP range (RFC 1918). Must be specified along +# with @dhcpend and @subnetmask. +# This address is used as the gateway address. The subsequent = address +# up to and including dhcpend are placed in the DHCP pool. +# +# @dhcpend: The DHCP IPv4 range end address to use for the interface. Must= be in +# the private IP range (RFC 1918). Must be specified along +# with @dhcpstart and @subnetmask. +# +# @subnetmask: The IPv4 subnet mask to use on the interface. Must be speci= fied +# along with @dhcpstart and @subnetmask. +# +# +# Since: 6.2, +## +{ 'struct': 'NetdevVmnetSharedOptions', + 'data': { + '*dhcpstart': 'str', + '*dhcpend': 'str', + '*subnetmask': 'str' + }, + 'if': 'CONFIG_VMNET' } + +## +# @NetdevVmnetBridgedOptions: +# +# vmnet (bridged mode) network backend. +# +# Bridges the vmnet interface with a physical network interface. +# +# @ifname: The name of the physical interface to be bridged. +# +# Since: 6.2 +## +{ 'struct': 'NetdevVmnetBridgedOptions', + 'data': { 'ifname': 'str' }, + 'if': 'CONFIG_VMNET' } + ## # @NetClientDriver: # @@ -460,10 +543,16 @@ # Since: 2.7 # # @vhost-vdpa since 5.1 +# @vmnet-host since 6.2 +# @vmnet-shared since 6.2 +# @vmnet-bridged since 6.2 ## { 'enum': 'NetClientDriver', 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', - 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] } + 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa', + { 'name': 'vmnet-host', 'if': 'CONFIG_VMNET' }, + { 'name': 'vmnet-shared', 'if': 'CONFIG_VMNET' }, + { 'name': 'vmnet-bridged', 'if': 'CONFIG_VMNET' }] } =20 ## # @Netdev: @@ -477,6 +566,9 @@ # Since: 1.2 # # 'l2tpv3' - since 2.1 +# 'vmnet-host' - since 6.2 +# 'vmnet-shared' - since 6.2 +# 'vmnet-bridged' - since 6.2 ## { 'union': 'Netdev', 'base': { 'id': 'str', 'type': 'NetClientDriver' }, @@ -492,7 +584,10 @@ 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', 'vhost-user': 'NetdevVhostUserOptions', - 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } + 'vhost-vdpa': 'NetdevVhostVDPAOptions', + 'vmnet-host': 'NetdevVmnetHostOptions', + 'vmnet-shared': 'NetdevVmnetSharedOptions', + 'vmnet-bridged': 'NetdevVmnetBridgedOptions' } } =20 ## # @RxState: --=20 2.23.0 From nobody Sun May 5 19:31:12 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1630438354; cv=none; d=zohomail.com; s=zohoarc; b=gbcLQCJrWPkL7n7aU3QJufYid63XdMqa7VSpUrvn2akQp2OQEN0wBMCKCBpLqkxAJmZtYrentaebnTY5DgwFCkqBytVtmoUa5zbq8XTyXDw8IO8Pt9Wd3SGb0hwTj6zGqVPH+2tBuEeLGcdDh+fn3sAgl0tBisrE5j0GGbHWV5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630438354; 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=gtLaycDdICWu7/AUl/hrECYbXp2281mwsRjGskQkFgo=; b=OIXOKnTlfOKoqJ3hk3uroaUjb9TiIso75Ar5OzIPNcgaKId60XE4pV7r12CHgvzQxxvsyd2LkhTRcF6TAchT9QO012pJfFPQ+396YNUGKtSRXyXWFUZIHPFG8urR5mt0IdFd1mp0kx/4nKP6EuYKxu2razYBas2kuH/Si/MX0Rk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630438354563215.37361517361728; Tue, 31 Aug 2021 12:32:34 -0700 (PDT) Received: from localhost ([::1]:43454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL9Un-00054f-Jc for importer@patchew.org; Tue, 31 Aug 2021 15:32:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL9QT-00088G-7E for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:05 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:45647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL9QQ-0001kM-Se for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:04 -0400 Received: by mail-lf1-x129.google.com with SMTP id g13so1061677lfj.12 for ; Tue, 31 Aug 2021 12:28:02 -0700 (PDT) Received: from UNIT-808.lan ([217.12.73.131]) by smtp.gmail.com with ESMTPSA id u13sm1254791lfq.254.2021.08.31.12.28.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Aug 2021 12:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gtLaycDdICWu7/AUl/hrECYbXp2281mwsRjGskQkFgo=; b=iiES62mPHkI/ukIN8FpG55LZ07UU4B+nuus6k0/HNXt5OOAcibWnrzAXys3ObcKUiz O9cW5UETq/9qAyxtued6JFTh+qP46vuOzD5WRwg4Y1TLY3tMMBhbWAP0PXtY//2stBlo GJXFr018h4wpmpxpxMrI5JCbwGCiUHeKLYUqQlwt4m+joXS/bF2kaG3YSRtM8YSrXkvU lpURVM8/bjSLMBCzxhTPD97xoxB6OVjWx0I30ihBEX+NNp36l49ZVggRxf7gMaTpOXtW Vpk9Qq09U4VSgkoL4StRqMGoNzaUKtvLl2V8x1taeCYM3bLAmXLq/Pm+4XV91pcCT1q3 xTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gtLaycDdICWu7/AUl/hrECYbXp2281mwsRjGskQkFgo=; b=OfGKX3OPuWeOZRt4j6R6pp3d+1dMXL5oJFaSj7EmNwhlGoY7YjPRuIumrRMMPayfcJ rzZgpfs00fNhgCy4zghq+nMiXFbEi/l21fj+xXe7yl7zYbEo1DcBkT4c3s3WUDuNcbSG Q/YIF3CLWifrebdOd4YUlIlYJiI4GvZ6Y87dSmZyLQbZSUb/yi4X6ciGMEElyN/2wti8 SvJoSq8P3hmJiRsW1AVOvdjttqvoiIInzGURG5ONcDFoCp1SAqYZ0tKncXG+FhhvoF1g Upq3j3naoGwagABMRgDE9b/SNkBX+9Ni1tB6ViGJbbn1cghssgDWULSCoc4VuTGK5Imh v5+Q== X-Gm-Message-State: AOAM533JfU2oc6+lq/WFsaasR3FVHYiBMrzl7MJxhQm6HMulUOL9UI4H lH8DH0/knzqcbNVsyaPikz991am2ZJmGAg== X-Google-Smtp-Source: ABdhPJy6iYK8zWUFr2JY8USJXp4Ac3koNey2fnAUoXshv0qc5R9hIvmG5NkRWLpbtM5RiVMJMlKgfw== X-Received: by 2002:a05:6512:114a:: with SMTP id m10mr4472487lfg.268.1630438081054; Tue, 31 Aug 2021 12:28:01 -0700 (PDT) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] net/vmnet: create common netdev state structure Date: Tue, 31 Aug 2021 22:27:16 +0300 Message-Id: <20210831192720.33406-3-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210831192720.33406-1-yaroshchuk2000@gmail.com> References: <20210831192720.33406-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::129; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lf1-x129.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, r.bolshakov@yadro.com, Vladislav Yaroshchuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1630438355225100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladislav Yaroshchuk --- net/meson.build | 8 +++++++- net/vmnet-bridged.c | 25 +++++++++++++++++++++++++ net/vmnet-common.c | 20 ++++++++++++++++++++ net/vmnet-host.c | 24 ++++++++++++++++++++++++ net/vmnet-shared.c | 25 +++++++++++++++++++++++++ net/vmnet.c | 34 ---------------------------------- net/vmnet_int.h | 25 +++++++++++++++++++++++++ 7 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 net/vmnet-bridged.c create mode 100644 net/vmnet-common.c create mode 100644 net/vmnet-host.c create mode 100644 net/vmnet-shared.c delete mode 100644 net/vmnet.c create mode 100644 net/vmnet_int.h diff --git a/net/meson.build b/net/meson.build index 196cf321a2..82eed63c8f 100644 --- a/net/meson.build +++ b/net/meson.build @@ -38,5 +38,11 @@ softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files(tap_= posix)) softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('tap-win32.c')) softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: files('vhost-vdpa.c= ')) =20 -softmmu_ss.add(when: ['CONFIG_VMNET', vmnet], if_true: files('vmnet.c')) +vmnet_files =3D files( + 'vmnet-common.c', + 'vmnet-bridged.c', + 'vmnet-host.c', + 'vmnet-shared.c' +) +softmmu_ss.add(when: ['CONFIG_VMNET', vmnet], if_true: vmnet_files) subdir('can') diff --git a/net/vmnet-bridged.c b/net/vmnet-bridged.c new file mode 100644 index 0000000000..9226c42353 --- /dev/null +++ b/net/vmnet-bridged.c @@ -0,0 +1,25 @@ +/* + * vmnet-bridged.c + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi-types-net.h" +#include "vmnet_int.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include + +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; +} diff --git a/net/vmnet-common.c b/net/vmnet-common.c new file mode 100644 index 0000000000..8ba31dc7b2 --- /dev/null +++ b/net/vmnet-common.c @@ -0,0 +1,20 @@ +/* + * vmnet.c - network client wrapper for Apple vmnet.framework + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * Copyright(c) 2021 Phillip Tennen + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi-types-net.h" +#include "vmnet_int.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include + diff --git a/net/vmnet-host.c b/net/vmnet-host.c new file mode 100644 index 0000000000..1d3484b51e --- /dev/null +++ b/net/vmnet-host.c @@ -0,0 +1,24 @@ +/* + * vmnet-host.c + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi-types-net.h" +#include "vmnet_int.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include + +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; +} diff --git a/net/vmnet-shared.c b/net/vmnet-shared.c new file mode 100644 index 0000000000..177b5a48ec --- /dev/null +++ b/net/vmnet-shared.c @@ -0,0 +1,25 @@ +/* + * vmnet-shared.c + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi-types-net.h" +#include "vmnet_int.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include + +int net_init_vmnet_shared(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) +{ + error_setg(errp, "vmnet-shared is not implemented yet"); + return -1; +} diff --git a/net/vmnet.c b/net/vmnet.c deleted file mode 100644 index 3f25afd7e8..0000000000 --- a/net/vmnet.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * vmnet.c - network client wrapper for Apple vmnet.framework - * - * Copyright(c) 2021 Vladislav Yaroshchuk - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - * - */ - -#include "qemu/osdep.h" -#include "clients.h" -#include "qemu/error-report.h" -#include "qapi/error.h" - -#include - -int net_init_vmnet_host(const Netdev *netdev, const char *name, - NetClientState *peer, Error **errp) { - error_setg(errp, "vmnet is not implemented yet"); - return -1; -} - -int net_init_vmnet_shared(const Netdev *netdev, const char *name, - NetClientState *peer, Error **errp) { - error_setg(errp, "vmnet is not implemented yet"); - return -1; -} - -int net_init_vmnet_bridged(const Netdev *netdev, const char *name, - NetClientState *peer, Error **errp) { - error_setg(errp, "vmnet is not implemented yet"); - return -1; -} diff --git a/net/vmnet_int.h b/net/vmnet_int.h new file mode 100644 index 0000000000..c5982259a4 --- /dev/null +++ b/net/vmnet_int.h @@ -0,0 +1,25 @@ +/* + * vmnet_int.h + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ +#ifndef VMNET_INT_H +#define VMNET_INT_H + +#include "qemu/osdep.h" +#include "vmnet_int.h" +#include "clients.h" + +#include + +typedef struct VmnetCommonState { + NetClientState nc; + +} VmnetCommonState; + + +#endif /* VMNET_INT_H */ --=20 2.23.0 From nobody Sun May 5 19:31:12 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1630438606; cv=none; d=zohomail.com; s=zohoarc; b=AclBevDmBNFCO6Bf3LRr1C/wJt9nQdIMs5weest/PtRzr1ccVuo95gA/OKYriMK2SZjULHZElNZyZnx3cHl8VZBz+N+1kW3Mgsxo6XrI2tHps2JlMSQCPj9JLKrH98Ja/zvizFqi+2iZjR6btVYAG7tea0XWZEQCHtagPPB0Jgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630438606; 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=AsirMuvXQZR2XXuh1voANfL7ODQci6QThA/Q5ruNU1o=; b=PbhjddhWADEZutcJj3PXUElJJQN3ZGEGg3a/HhiyiyTZx1afyIngV8AnQM4/8mfozdt7IqGyS2J7CX3H2eZHMJAk+NNkHaXmTRTWoES8lkmMZw9RKwigqTEG3UzpwrtAuxwDZvBBlYcMy/SVcGAXnVuagyDsYlc+LHXRa/2Fg8Y= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630438606675416.58641472472266; Tue, 31 Aug 2021 12:36:46 -0700 (PDT) Received: from localhost ([::1]:49986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL9Yr-0001CW-G1 for importer@patchew.org; Tue, 31 Aug 2021 15:36:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL9QU-00089a-4Q for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:06 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:40833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL9QR-0001kX-Pt for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:05 -0400 Received: by mail-lf1-x136.google.com with SMTP id bq28so1126211lfb.7 for ; Tue, 31 Aug 2021 12:28:03 -0700 (PDT) Received: from UNIT-808.lan ([217.12.73.131]) by smtp.gmail.com with ESMTPSA id u13sm1254791lfq.254.2021.08.31.12.28.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Aug 2021 12:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AsirMuvXQZR2XXuh1voANfL7ODQci6QThA/Q5ruNU1o=; b=Zhp0l0wmgrcOTMbaAfk98Nxq6XeCcBqvZI+DxB2kQN+nV4xiQNMYGtXzoCKEoF5sTU ma3My6/FsLaHTpQpVB9kbOQI8GIQJdn4SSkfGoekHWWK+40SHHlUDSDJA78JLmJule0R Tn6TyPz6Ua5eBGLeHBlhsuhK28XH5K4myZSGRw+JaX78+fBqOxOBGR3DFm4lAjec0X80 LVovqvwj3x5lh8/LpqPd8Xkrg7UNZ0uCnSJSJ0vLF3KHBiNeljCx29lA/hdnNyqu0R6G eV8BTF2gh443TYWMHwvQl7ADLcAHR/tPjG4tpp2ZJwY2y54rae1AH2frxUjhvfCfty86 DxXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AsirMuvXQZR2XXuh1voANfL7ODQci6QThA/Q5ruNU1o=; b=pQhcIJaKFxSxEjPudU5sLFNUb2ehBafHifazXQmwtJQSAVEaiymUVvu55i6QKbaeLs RATTDvfEmPyjN1x+FKz3Id7XjBX1fJsULFzC4QuR0CNgXNXB7XkxRaqmfcitntXXdJdM SoJPFQrtzDlCUmRIqCf5t3bC96k+CYC1XRa7eaSr1K2REw65wjERY41zJGU8BMBgoCbF rfr3K/lmVUj/p3RiitnRh8L+fNtOhhqmTDS422yBLwV7elRu2OIiasi9H+eIFBA1Ev+E U/vhq5ZqCXZYjr0nnwIyE2PwdK7bWXqtnpHbtgF5lLaLA7Io+RK/UqYfN17hp8dJkXcy hvHw== X-Gm-Message-State: AOAM530NdsfwffxrPpuQsrZMd9AhYc4j5TH2gLg7MD5miTCIXaZGQJxz Ty31QRiphnHJnPrwLlh0xVbLqmXq1rnwBA== X-Google-Smtp-Source: ABdhPJy3yFnGsJB6oyQPhMMfkSNLk3Eqvamsw0R2mePvn/fp/eKIgld+V+FFMMotY/VQ6YRm8N/nrQ== X-Received: by 2002:a19:f616:: with SMTP id x22mr8197008lfe.239.1630438082041; Tue, 31 Aug 2021 12:28:02 -0700 (PDT) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] net/vmnet: implement shared mode (vmnet-shared) Date: Tue, 31 Aug 2021 22:27:17 +0300 Message-Id: <20210831192720.33406-4-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210831192720.33406-1-yaroshchuk2000@gmail.com> References: <20210831192720.33406-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, r.bolshakov@yadro.com, Vladislav Yaroshchuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1630438608146100003 Content-Type: text/plain; charset="utf-8" Still not implemented: - port forwarding - ipv6 prefix setting Signed-off-by: Vladislav Yaroshchuk --- net/meson.build | 2 +- net/vmnet-common.c | 20 --- net/vmnet-common.m | 294 +++++++++++++++++++++++++++++++++++++++++++++ net/vmnet-shared.c | 73 ++++++++++- net/vmnet_int.h | 23 ++++ 5 files changed, 389 insertions(+), 23 deletions(-) delete mode 100644 net/vmnet-common.c create mode 100644 net/vmnet-common.m diff --git a/net/meson.build b/net/meson.build index 82eed63c8f..1df498ad99 100644 --- a/net/meson.build +++ b/net/meson.build @@ -39,7 +39,7 @@ softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('tap-= win32.c')) softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: files('vhost-vdpa.c= ')) =20 vmnet_files =3D files( - 'vmnet-common.c', + 'vmnet-common.m', 'vmnet-bridged.c', 'vmnet-host.c', 'vmnet-shared.c' diff --git a/net/vmnet-common.c b/net/vmnet-common.c deleted file mode 100644 index 8ba31dc7b2..0000000000 --- a/net/vmnet-common.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * vmnet.c - network client wrapper for Apple vmnet.framework - * - * Copyright(c) 2021 Vladislav Yaroshchuk - * Copyright(c) 2021 Phillip Tennen - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - * - */ - -#include "qemu/osdep.h" -#include "qapi-types-net.h" -#include "vmnet_int.h" -#include "clients.h" -#include "qemu/error-report.h" -#include "qapi/error.h" - -#include - diff --git a/net/vmnet-common.m b/net/vmnet-common.m new file mode 100644 index 0000000000..c6e7df99e0 --- /dev/null +++ b/net/vmnet-common.m @@ -0,0 +1,294 @@ +/* + * vmnet.c - network backend based on vmnet.framework + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "qapi-types-net.h" +#include "vmnet_int.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include +#include + +typedef struct vmpktdesc vmpktdesc_t; +typedef struct iovec iovec_t; + +static void vmnet_set_send_enabled(VmnetCommonState *s, bool enable) +{ + s->send_enabled =3D enable; +} + + +static void vmnet_send_completed(NetClientState *nc, ssize_t len) +{ + VmnetCommonState *s =3D DO_UPCAST(VmnetCommonState, nc, nc); + vmnet_set_send_enabled(s, true); +} + + +static void vmnet_send(NetClientState *nc, + interface_event_t event_id, + xpc_object_t event) +{ + assert(event_id =3D=3D VMNET_INTERFACE_PACKETS_AVAILABLE); + + VmnetCommonState *s; + uint64_t packets_available; + + struct iovec *iov; + struct vmpktdesc *packets; + int pkt_cnt; + int i; + + vmnet_return_t if_status; + ssize_t size; + + s =3D DO_UPCAST(VmnetCommonState, nc, nc); + + packets_available =3D xpc_dictionary_get_uint64( + event, + vmnet_estimated_packets_available_key + ); + + pkt_cnt =3D (packets_available < VMNET_PACKETS_LIMIT) ? + packets_available : + VMNET_PACKETS_LIMIT; + + + iov =3D s->iov_buf; + packets =3D s->packets_buf; + + for (i =3D 0; i < pkt_cnt; ++i) { + packets[i].vm_pkt_size =3D s->max_packet_size; + packets[i].vm_pkt_iovcnt =3D 1; + packets[i].vm_flags =3D 0; + } + + if_status =3D vmnet_read(s->vmnet_if, packets, &pkt_cnt); + if (if_status !=3D VMNET_SUCCESS) { + error_printf("vmnet: read failed: %s\n", + vmnet_status_map_str(if_status)); + } + qemu_mutex_lock_iothread(); + for (i =3D 0; i < pkt_cnt; ++i) { + size =3D qemu_send_packet_async(nc, + iov[i].iov_base, + packets[i].vm_pkt_size, + vmnet_send_completed); + if (size =3D=3D 0) { + vmnet_set_send_enabled(s, false); + } else if (size < 0) { + break; + } + } + qemu_mutex_unlock_iothread(); + +} + + +static void vmnet_register_event_callback(VmnetCommonState *s) +{ + dispatch_queue_t avail_pkt_q =3D dispatch_queue_create( + "org.qemu.vmnet.if_queue", + DISPATCH_QUEUE_SERIAL + ); + + vmnet_interface_set_event_callback( + s->vmnet_if, + VMNET_INTERFACE_PACKETS_AVAILABLE, + avail_pkt_q, + ^(interface_event_t event_id, xpc_object_t event) { + if (s->send_enabled) { + vmnet_send(&s->nc, event_id, event); + } + }); +} + + +static void vmnet_bufs_init(VmnetCommonState *s) +{ + int i; + struct vmpktdesc *packets; + struct iovec *iov; + + packets =3D s->packets_buf; + iov =3D s->iov_buf; + + for (i =3D 0; i < VMNET_PACKETS_LIMIT; ++i) { + iov[i].iov_len =3D s->max_packet_size; + iov[i].iov_base =3D g_malloc0(iov[i].iov_len); + packets[i].vm_pkt_iov =3D iov + i; + } +} + + +const char *vmnet_status_map_str(vmnet_return_t status) +{ + switch (status) { + case VMNET_SUCCESS: + return "success"; + case VMNET_FAILURE: + return "general failure"; + case VMNET_MEM_FAILURE: + return "memory allocation failure"; + case VMNET_INVALID_ARGUMENT: + return "invalid argument specified"; + case VMNET_SETUP_INCOMPLETE: + return "interface setup is not complete"; + case VMNET_INVALID_ACCESS: + return "invalid access, permission denied"; + case VMNET_PACKET_TOO_BIG: + return "packet size is larger than MTU"; + case VMNET_BUFFER_EXHAUSTED: + return "buffers exhausted in kernel"; + case VMNET_TOO_MANY_PACKETS: + return "packet count exceeds limit"; + default: + return "unknown vmnet error"; + } +} + + +int vmnet_if_create(NetClientState *nc, + xpc_object_t if_desc, + Error **errp, + void (*completion_callback)(xpc_object_t interface_par= am)) +{ + VmnetCommonState *s; + + dispatch_queue_t if_create_q; + dispatch_semaphore_t if_created_sem; + + __block vmnet_return_t if_status; + + if_create_q =3D dispatch_queue_create("org.qemu.vmnet.create", + DISPATCH_QUEUE_SERIAL); + if_created_sem =3D dispatch_semaphore_create(0); + + s =3D DO_UPCAST(VmnetCommonState, nc, nc); + s->vmnet_if =3D vmnet_start_interface( + if_desc, + if_create_q, + ^(vmnet_return_t status, xpc_object_t interface_param) { + if_status =3D status; + if (status !=3D VMNET_SUCCESS || !interface_param) { + dispatch_semaphore_signal(if_created_sem); + return; + } + + s->mtu =3D xpc_dictionary_get_uint64( + interface_param, + vmnet_mtu_key); + s->max_packet_size =3D xpc_dictionary_get_uint64( + interface_param, + vmnet_max_packet_size_key); + + if (completion_callback) { + completion_callback(interface_param); + } + dispatch_semaphore_signal(if_created_sem); + }); + + if (s->vmnet_if =3D=3D NULL) { + error_setg(errp, "unable to create interface with requested params= "); + return -1; + } + + dispatch_semaphore_wait(if_created_sem, DISPATCH_TIME_FOREVER); + dispatch_release(if_create_q); + + if (if_status !=3D VMNET_SUCCESS) { + error_setg(errp, + "interface creation error: %s", + vmnet_status_map_str(if_status)); + return -1; + } + + vmnet_register_event_callback(s); + vmnet_bufs_init(s); + vmnet_set_send_enabled(s, true); + + return 0; +} + + +ssize_t vmnet_receive_common(NetClientState *nc, + const uint8_t *buf, + size_t size) +{ + VmnetCommonState *s; + vmpktdesc_t packet; + iovec_t iov; + int pkt_cnt; + vmnet_return_t if_status; + + s =3D DO_UPCAST(VmnetCommonState, nc, nc); + + if (size > s->max_packet_size) { + warn_report("vmnet: packet is too big, %zu > %llu\n", + packet.vm_pkt_size, + s->max_packet_size); + return -1; + } + + iov.iov_base =3D (char *) buf; + iov.iov_len =3D size; + + packet.vm_pkt_iovcnt =3D 1; + packet.vm_flags =3D 0; + packet.vm_pkt_size =3D size; + packet.vm_pkt_iov =3D &iov; + + pkt_cnt =3D 1; + if_status =3D vmnet_write(s->vmnet_if, &packet, &pkt_cnt); + + if (if_status !=3D VMNET_SUCCESS) { + error_report("vmnet: write error: %s\n", + vmnet_status_map_str(if_status)); + } + + if (if_status =3D=3D VMNET_SUCCESS && pkt_cnt) { + return size; + } + return 0; +} + + +void vmnet_cleanup_common(NetClientState *nc) +{ + VmnetCommonState *s; + dispatch_queue_t if_destroy_q; + + s =3D DO_UPCAST(VmnetCommonState, nc, nc); + + qemu_purge_queued_packets(nc); + vmnet_set_send_enabled(s, false); + + if (s->vmnet_if =3D=3D NULL) { + return; + } + + if_destroy_q =3D dispatch_queue_create( + "org.qemu.vmnet.destroy", + DISPATCH_QUEUE_SERIAL + ); + + vmnet_stop_interface( + s->vmnet_if, + if_destroy_q, + ^(vmnet_return_t status) { + }); + + for (int i =3D 0; i < VMNET_PACKETS_LIMIT; ++i) { + g_free(s->iov_buf[i].iov_base); + } +} diff --git a/net/vmnet-shared.c b/net/vmnet-shared.c index 177b5a48ec..a9db0ad52b 100644 --- a/net/vmnet-shared.c +++ b/net/vmnet-shared.c @@ -17,9 +17,78 @@ =20 #include =20 +typedef struct VmnetSharedState { + VmnetCommonState common; + +} VmnetSharedState; + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp); + +static NetClientInfo net_vmnet_shared_info =3D { + .type =3D NET_CLIENT_DRIVER_VMNET_SHARED, + .size =3D sizeof(VmnetSharedState), + .receive =3D vmnet_receive_common, + .cleanup =3D vmnet_cleanup_common, +}; + int net_init_vmnet_shared(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { - error_setg(errp, "vmnet-shared is not implemented yet"); - return -1; + NetClientState *nc; + xpc_object_t if_desc; + + nc =3D qemu_new_net_client(&net_vmnet_shared_info, + peer, "vmnet-shared", name); + if_desc =3D create_if_desc(netdev, errp); + return vmnet_if_create(nc, if_desc, errp, NULL); +} + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp) +{ + const NetdevVmnetSharedOptions *options; + xpc_object_t if_desc; + + if_desc =3D xpc_dictionary_create(NULL, NULL, 0); + xpc_dictionary_set_uint64( + if_desc, + vmnet_operation_mode_key, + VMNET_SHARED_MODE + ); + + xpc_dictionary_set_bool( + if_desc, + vmnet_allocate_mac_address_key, + false + ); + + options =3D &(netdev->u.vmnet_shared); + + if (options->has_dhcpstart || + options->has_dhcpend || + options->has_subnetmask) { + + if (options->has_dhcpstart && + options->has_dhcpend && + options->has_subnetmask) { + + xpc_dictionary_set_string(if_desc, + vmnet_start_address_key, + options->dhcpstart); + xpc_dictionary_set_string(if_desc, + vmnet_end_address_key, + options->dhcpend); + xpc_dictionary_set_string(if_desc, + vmnet_subnet_mask_key, + options->subnetmask); + } else { + error_setg( + errp, + "'dhcpstart', 'dhcpend', 'subnetmask' " + "must be provided together" + ); + } + } + + return if_desc; } + diff --git a/net/vmnet_int.h b/net/vmnet_int.h index c5982259a4..3979fe4678 100644 --- a/net/vmnet_int.h +++ b/net/vmnet_int.h @@ -16,10 +16,33 @@ =20 #include =20 +#define VMNET_PACKETS_LIMIT 50 + typedef struct VmnetCommonState { NetClientState nc; + interface_ref vmnet_if; + + bool send_enabled; + + uint64_t mtu; + uint64_t max_packet_size; + + struct vmpktdesc packets_buf[VMNET_PACKETS_LIMIT]; + struct iovec iov_buf[VMNET_PACKETS_LIMIT]; =20 } VmnetCommonState; =20 +const char *vmnet_status_map_str(vmnet_return_t status); + +int vmnet_if_create(NetClientState *nc, + xpc_object_t if_desc, + Error **errp, + void (*completion_callback)(xpc_object_t interface_par= am)); + +ssize_t vmnet_receive_common(NetClientState *nc, + const uint8_t *buf, + size_t size); + +void vmnet_cleanup_common(NetClientState *nc); =20 #endif /* VMNET_INT_H */ --=20 2.23.0 From nobody Sun May 5 19:31:12 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1630438468; cv=none; d=zohomail.com; s=zohoarc; b=eadQrNVXLy2OJupIzdD52RGsP7NOoNS3pFbcA6lYCUH0bJdrcMZv9ilpJTt/Hh3Uc0UM1MA20np5dS81dwPuLt6KJnWmvMXenDcFm0RF+2Mv9hsOfFPeEXBJ1kMYhcizK6TZuCydRwXpEEM4uYtMp0Db+pkkPejswGAv0IFhbnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630438468; 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=oE/CTQccPGQwH7DHVloQHpvY33VY/8DHBhYmKwKIpCU=; b=OdD/WuRxadNaQclCPiJb1zg3LBJ6JMPfPh4rZhB6FfBZlKb6Y501MJUFyAEHdI+7msbBKWsoYZa8Tsyh3HHLpuMEkfQJ+qSx9f/Einv6XI9zK1tG0yrtx6uQ2Lu8fLewaBuF3dls7gbqaX5OkolZkKOiLmUw3lMHxeEepPAZAoA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630438467776434.8046680149214; Tue, 31 Aug 2021 12:34:27 -0700 (PDT) Received: from localhost ([::1]:47052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL9Wc-0007Vz-Rp for importer@patchew.org; Tue, 31 Aug 2021 15:34:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL9QV-0008ET-VL for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:07 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]:34813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL9QS-0001ka-GI for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:07 -0400 Received: by mail-lf1-x130.google.com with SMTP id z2so1204059lft.1 for ; Tue, 31 Aug 2021 12:28:04 -0700 (PDT) Received: from UNIT-808.lan ([217.12.73.131]) by smtp.gmail.com with ESMTPSA id u13sm1254791lfq.254.2021.08.31.12.28.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Aug 2021 12:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oE/CTQccPGQwH7DHVloQHpvY33VY/8DHBhYmKwKIpCU=; b=rJfmRWEYkbcNiMAVij76Cmv5qXclovHajEqZldw0+Td5nX20EhVYijBiNDOuEMEPzz kwXXqEZA7Mw2oG1jEK3sEKcJE9UvT+QdRNxmBSFg1QuuHzRGppohKcw4wXZCON1NAFN6 3toOR/47byQlkdwd3yiPrNPFb+MbpkyZqjgtQCBCeWHMxfBm9VwnazuFqXGYRbeepUB6 kOCVjeBc7xe/oTKhN6FiLYxljMNOHUlFrd4RtXI+K7UzQpTe/4NyaR6JHv3qR55YVnWv sxR5IiAq8kX5bs71gnqoQzdGv8iPwkU+O2Tt2BwpYmSa1R/uBZqjRfj3sddtqRWV2gpc XE9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oE/CTQccPGQwH7DHVloQHpvY33VY/8DHBhYmKwKIpCU=; b=sinGekUrSsZ49Npnj4AwX8OFvzhL2HxPe1aFyhzxYARnrU3ah9ZzIk1VfqGvQxxbXD hhWzGmaTSJ8ZOar6mPejhbymwfYtC0omekkJRQmpVwuEQSW9qEzvM5eSThvUDicTf/Lc JWEwy5cD5sX97jZogoal4WN+PZi/r4xTd2M1L8CiC6wDgihmG4XYqfEtKXB59lgPyBXm 760vgr5WRsELYw7gf/SmvRoTodFdsetPVarCCZgdgVGROGwnQIYkCBfMLALlA827xQ8W CW1JHRqlU935feRh5hCH3jXsko3I38KlALpNEl8rPGuP8wgDOPtHy3ub9cPLydQ5RQE5 U9Rw== X-Gm-Message-State: AOAM531zZzCGYklF/zi3BQkOJkaZWFfz5wGUQsoH65iK916pM5VXL6WJ 3uxd7k7MKmsXE7XH6suS9Z4Vqgbxih0org== X-Google-Smtp-Source: ABdhPJzUjk5vKY25kKvxNK6EXHMpea/0dsLNMhsNSA56/vJ5qLdCnhq9wJS/NR+G9N7bNJuP8IGGlw== X-Received: by 2002:a05:6512:2291:: with SMTP id f17mr19407271lfu.489.1630438082717; Tue, 31 Aug 2021 12:28:02 -0700 (PDT) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] net/vmnet: implement host mode (vmnet-host) Date: Tue, 31 Aug 2021 22:27:18 +0300 Message-Id: <20210831192720.33406-5-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210831192720.33406-1-yaroshchuk2000@gmail.com> References: <20210831192720.33406-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::130; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lf1-x130.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, r.bolshakov@yadro.com, Vladislav Yaroshchuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1630438469025100001 Content-Type: text/plain; charset="utf-8" Still not implemented: - port forwarding Signed-off-by: Vladislav Yaroshchuk --- net/vmnet-host.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/net/vmnet-host.c b/net/vmnet-host.c index 1d3484b51e..77a2c20b48 100644 --- a/net/vmnet-host.c +++ b/net/vmnet-host.c @@ -17,8 +17,77 @@ =20 #include =20 +typedef struct VmnetHostState { + VmnetCommonState common; + +} VmnetHostState; + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp); + +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; + xpc_object_t if_desc; + + nc =3D qemu_new_net_client(&net_vmnet_host_info, + peer, "vmnet-host", name); + if_desc =3D create_if_desc(netdev, errp); + return vmnet_if_create(nc, if_desc, errp, NULL); +} + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp) +{ + const NetdevVmnetHostOptions *options; + xpc_object_t if_desc; + + if_desc =3D xpc_dictionary_create(NULL, NULL, 0); + xpc_dictionary_set_uint64( + if_desc, + vmnet_operation_mode_key, + VMNET_HOST_MODE + ); + + xpc_dictionary_set_bool( + if_desc, + vmnet_allocate_mac_address_key, + false + ); + + options =3D &(netdev->u.vmnet_host); + + if (options->has_dhcpstart || + options->has_dhcpend || + options->has_subnetmask) { + + if (options->has_dhcpstart && + options->has_dhcpend && + options->has_subnetmask) { + + xpc_dictionary_set_string(if_desc, + vmnet_start_address_key, + options->dhcpstart); + xpc_dictionary_set_string(if_desc, + vmnet_end_address_key, + options->dhcpend); + xpc_dictionary_set_string(if_desc, + vmnet_subnet_mask_key, + options->subnetmask); + } else { + error_setg( + errp, + "'dhcpstart', 'dhcpend', 'subnetmask' " + "must be provided together" + ); + } + } + + return if_desc; } --=20 2.23.0 From nobody Sun May 5 19:31:12 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1630438347; cv=none; d=zohomail.com; s=zohoarc; b=lQKlV/rGz+jKYGfRWw9x/VTkXorJyTibAJ2sBQC9m/YTHliJdvm3CqSwrxstn21tWbO3dzIRSAs7YYbI1mwHgPS6drj/wE6t+2vHwb3CstNVJrLsxFUf+EB/4+JX5nT19l/OWhvFO6nLcqs0+ZAaIiXRmi0T1/IrM/HZpa1xf8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630438347; 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=mQO9Jtuj60CqwGL2PeMxqW7qhxlXNo242GuzLYoT+MU=; b=VX2yzreLKusvz08Vb8ZwCURoumRw8V1iGCqLuSASqkdp3ziJ3PajkcbmD+5lg+mkdXchtLvsBeSGoejtPrmHZriD72INTG0QS7HxYnM60yKbcVpOksDXdRiBt4z19l3w6C0IM7WSr4CpkyzRONS62zmSraFZQn9noz03v3ZqCDI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630438347646467.55425284493083; Tue, 31 Aug 2021 12:32:27 -0700 (PDT) Received: from localhost ([::1]:43238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL9Uf-0004vO-9t for importer@patchew.org; Tue, 31 Aug 2021 15:32:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL9QU-0008Bk-Vs for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:07 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]:43867) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL9QT-0001l7-9g for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:06 -0400 Received: by mail-lf1-x12e.google.com with SMTP id m18so1081974lfl.10 for ; Tue, 31 Aug 2021 12:28:04 -0700 (PDT) Received: from UNIT-808.lan ([217.12.73.131]) by smtp.gmail.com with ESMTPSA id u13sm1254791lfq.254.2021.08.31.12.28.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Aug 2021 12:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mQO9Jtuj60CqwGL2PeMxqW7qhxlXNo242GuzLYoT+MU=; b=YUoCePRR3MmTZowomuJNKzS7Bhq6VBDogAk1hkQmXlywiuvmcRUyFPrY2gD5R6GG8x mEPQUdyKpx3cCumMfVNuHVi1Ou/0GTEl0LDTKVT3eK5Lomms2NmFJVsM7dvG/h2OBXVN Gql9MrHOVtIDMLjWEzeONPqAHg2ma6fG/eSjoS7AfFxyRBYA1mkHAlNoYSWHcfh+4i0C KNP8yv2/g2jU0HG1s9ZQJlhvg12hriwDwZ7nL/evX75wZxbUGJ5t1bLMnPkC0kUwNjgK OAfswQ+ZtoZdeI1yPBDVISJ4qTyjOW0XPg8iPL5EOtdxa3d0PjzIUF6nhFA4lh4vEP/E SEqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mQO9Jtuj60CqwGL2PeMxqW7qhxlXNo242GuzLYoT+MU=; b=L1m84hcFTxgDzhfCXDScWGkc2yJ9amTpxT46RuorpBB2amESgGEZD0/HZ2FYz7Kpsl EAlBjx9+VJSYYqAB7R/eZkoo9bsuOGLtLIiMSo80GSTKF5p51y1A8IG1R5FPC9H1S6s2 7zIRRxntoYnRkxRKeh/1s0eBPOTD+Us1wjTd1IudQIlTQGpC8sjx6eKq3ocoqZzj/4E2 RYwyyy15TT8eis73qXzJJEcik13E8Dyy8muR2ywBYmDjPkUR7DCghdWRLHI470ynLdye WM00M4NjWHz93yMC4RVioxFxsK5PgS/Gm3gorZdlJkRZPItqhK+J8HWrfP34/5afxLjg 8tLA== X-Gm-Message-State: AOAM5309HnxgcewT9TFVhT9toLdaetlpadgukOwQBnxzZ/gndta43qbW Pavd7IFjZBRtd7lfT14Ydbb9J9919ZZ6sw== X-Google-Smtp-Source: ABdhPJwjWd9ABkf9eSC3LGKXHboTAj4snRM2bkuZKqTF0ycl2+HtNVh2ncptOnnR4da8st1gOK0iSg== X-Received: by 2002:a05:6512:1385:: with SMTP id p5mr22868240lfa.447.1630438083538; Tue, 31 Aug 2021 12:28:03 -0700 (PDT) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] net/vmnet: implement bridged mode (vmnet-bridged) Date: Tue, 31 Aug 2021 22:27:19 +0300 Message-Id: <20210831192720.33406-6-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210831192720.33406-1-yaroshchuk2000@gmail.com> References: <20210831192720.33406-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::12e; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lf1-x12e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, r.bolshakov@yadro.com, Vladislav Yaroshchuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1630438348707100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladislav Yaroshchuk --- net/meson.build | 2 +- net/vmnet-bridged.c | 25 --------- net/vmnet-bridged.m | 123 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 26 deletions(-) delete mode 100644 net/vmnet-bridged.c create mode 100644 net/vmnet-bridged.m diff --git a/net/meson.build b/net/meson.build index 1df498ad99..495419e964 100644 --- a/net/meson.build +++ b/net/meson.build @@ -40,7 +40,7 @@ softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: fi= les('vhost-vdpa.c')) =20 vmnet_files =3D files( 'vmnet-common.m', - 'vmnet-bridged.c', + 'vmnet-bridged.m', 'vmnet-host.c', 'vmnet-shared.c' ) diff --git a/net/vmnet-bridged.c b/net/vmnet-bridged.c deleted file mode 100644 index 9226c42353..0000000000 --- a/net/vmnet-bridged.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * vmnet-bridged.c - * - * Copyright(c) 2021 Vladislav Yaroshchuk - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - * - */ - -#include "qemu/osdep.h" -#include "qapi-types-net.h" -#include "vmnet_int.h" -#include "clients.h" -#include "qemu/error-report.h" -#include "qapi/error.h" - -#include - -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; -} diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m new file mode 100644 index 0000000000..61a96ce11a --- /dev/null +++ b/net/vmnet-bridged.m @@ -0,0 +1,123 @@ +/* + * vmnet-bridged.c + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi-types-net.h" +#include "vmnet_int.h" +#include "clients.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +#include + +typedef struct VmnetBridgedState { + VmnetCommonState common; + +} VmnetBridgedState; + +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, +}; + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp); + +static bool validate_ifname(const char *ifname); + +static const char *get_valid_ifnames(void); + +int net_init_vmnet_bridged(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) +{ + NetClientState *nc; + xpc_object_t if_desc; + + nc =3D qemu_new_net_client(&net_vmnet_bridged_info, + peer, "vmnet-bridged", name); + 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); +} + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp) +{ + const NetdevVmnetBridgedOptions *options; + xpc_object_t if_desc; + + if_desc =3D xpc_dictionary_create(NULL, NULL, 0); + xpc_dictionary_set_uint64( + if_desc, + vmnet_operation_mode_key, + VMNET_BRIDGED_MODE + ); + + xpc_dictionary_set_bool( + if_desc, + vmnet_allocate_mac_address_key, + false + ); + + options =3D &(netdev->u.vmnet_bridged); + 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 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]"; +} --=20 2.23.0 From nobody Sun May 5 19:31:12 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1630438665; cv=none; d=zohomail.com; s=zohoarc; b=EH917H/Pt4f5VxcGE5uoJBEdNjeAx3magpJflYiiCvPug5oido/Z4UuKsCBevId3w8/vsNSm33t7GbSfi+q0QMg/8eT4RNjVJVzO7IBu4t+sX95ZtDgfYbUt+K+0DQ6im/+toJkJHrCc8NaqcvP8ZadfBIGNfm84Zc9SSwP/ZjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630438665; 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=aCPeNlXlWGkhJOT2ZZoxAKVM/qk0CiVaGY6Okr5opEE=; b=BvcHs5I+gB5yiRwMbk/THXPh8jTg5KEyNAPyNNYG79tIaSys1QcdeEL+wUExMItkrhIdvm8ymgfK6ArD21lrm1egWek3VOYnO9k08GO4jFzWWm8H78dMGwuQrJSXDHYZxOZAQ40XmUj6tYzig5c0weQ0y9toknEW6jjq5lh/KUo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630438665779848.5006805315353; Tue, 31 Aug 2021 12:37:45 -0700 (PDT) Received: from localhost ([::1]:52586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL9Zo-0002z8-LX for importer@patchew.org; Tue, 31 Aug 2021 15:37:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL9QV-0008DD-Fk for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:07 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]:40825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL9QU-0001md-1v for qemu-devel@nongnu.org; Tue, 31 Aug 2021 15:28:07 -0400 Received: by mail-lf1-x12d.google.com with SMTP id bq28so1126422lfb.7 for ; Tue, 31 Aug 2021 12:28:05 -0700 (PDT) Received: from UNIT-808.lan ([217.12.73.131]) by smtp.gmail.com with ESMTPSA id u13sm1254791lfq.254.2021.08.31.12.28.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Aug 2021 12:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aCPeNlXlWGkhJOT2ZZoxAKVM/qk0CiVaGY6Okr5opEE=; b=DWvPyfu2fk22njgR+TiEnXjE9OJUPfI/qyVqO+NUgPTC9YPJareYUevx8AXtJlYe16 huli8t7dMTrQ4N8gDGozcPvLGcjwap31YCdjiQMrmi33Ufgdi88cbIePFGq7zsnD2u+R gBBEZn4ZxzRdmQhG9xxrvbzCdz9hlvZidbNsAE7YrG6BDX43EEF8fyz4IDB+vt16u7ZC eSyISJykj0ImsIORqKU65bNfUlFwHubf4sQEOIAEmg0JM8JSwsBClFy9talgr91d4TtP usE8Q2GLAZUwGy1lAul1Kr9y5xqtnWjY7nRhUUAenL76scG8yPaFFXFoCPEQlndJYuqt CHjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aCPeNlXlWGkhJOT2ZZoxAKVM/qk0CiVaGY6Okr5opEE=; b=Q1otA3o+7bELun8Ezb3FQD84umn825HEbcyUwy+YVztXevf0lHQ3zuqIAQa8FReIOf pC25ObBog7dxgAdaTKhmd3QL1tcbY+gRufBkb903gnf4NW5DtcGnp2QOplixfB1SgAq6 vbflkeDmUQsieg+GFKQhP6P2KR/ZHkRQeXooA6fGh3GFvNJ2Ml0hLlhRNLodF6g9iMBK 54LGxvu65yWEOR/W4kpeeb8v6cM5zXeRDHbIJP6B8CuH9Yqk+rQlHkN9xkUAiC2TpKuz 2UGOCdL0cPHW83LcApBFEwRzEZRK4Ip27Wuh7ZQ0hYii/WjNfEA/b2vz7kd0R1mXBY2E Q5dA== X-Gm-Message-State: AOAM533ifxa0A/3Sb6tmvuJ71HLjjLjfzd83ovSJsmCTfUakhxXOrqk6 e4M7jAsyzBi+Kw0uUrBzhOHt9fwFeHy9VQ== X-Google-Smtp-Source: ABdhPJyXaSK3ITFzFvrjgJC8vmQFjUvI+yG7qQYhrZ1YNlTdVNV5VDGY3Q1Ir/1unLt3InBqR+mdfA== X-Received: by 2002:a05:6512:c5:: with SMTP id c5mr12067515lfp.627.1630438084223; Tue, 31 Aug 2021 12:28:04 -0700 (PDT) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v2 6/6] net/vmnet: update qemu-options.hx Date: Tue, 31 Aug 2021 22:27:20 +0300 Message-Id: <20210831192720.33406-7-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210831192720.33406-1-yaroshchuk2000@gmail.com> References: <20210831192720.33406-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::12d; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lf1-x12d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, r.bolshakov@yadro.com, Vladislav Yaroshchuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1630438667468100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladislav Yaroshchuk --- qemu-options.hx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 83aa59a920..b5d1cbd49a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2655,6 +2655,17 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, #ifdef __linux__ "-netdev vhost-vdpa,id=3Dstr,vhostdev=3D/path/to/dev\n" " configure a vhost-vdpa network,Establish a vhost-vdpa= netdev\n" +#endif +#ifdef CONFIG_VMNET + "-netdev vmnet-host,id=3Dstr,[dhcpstart=3Daddr,dhcpend=3Daddr,subnetma= sk=3Dmask]\n" + " configure a vmnet network backend in host mode with I= D 'str',\n" + " configure its DHCP server and choose a subnet\n" + "-netdev vmnet-shared,id=3Dstr,[dhcpstart=3Daddr,dhcpend=3Daddr,subnet= mask=3Dmask]\n" + " configure a vmnet network backend in shared mode with= ID 'str',\n" + " configure its DHCP server and choose a subnet\n" + "-netdev vmnet-bridged,id=3Dstr,ifname=3Dname\n" + " configure a vmnet network backend in bridged mode wit= h ID 'str'\n" + " use 'ifname=3Dname' to select a physical network inte= rface to be bridged\n" #endif "-netdev hubport,id=3Dstr,hubid=3Dn[,netdev=3Dnd]\n" " configure a hub port on the hub with ID 'n'\n", QEMU_= ARCH_ALL) @@ -2674,6 +2685,9 @@ DEF("nic", HAS_ARG, QEMU_OPTION_nic, #endif #ifdef CONFIG_POSIX "vhost-user|" +#endif +#ifdef CONFIG_VMNET + "vmnet-host|vmnet-shared|vmnet-bridged|" #endif "socket][,option][,...][mac=3Dmacaddr]\n" " initialize an on-board / default host NIC (using MAC = address\n" @@ -2696,6 +2710,9 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, #endif #ifdef CONFIG_NETMAP "netmap|" +#endif +#ifdef CONFIG_VMNET + "vmnet-host|vmnet-shared|vmnet-bridged|" #endif "socket][,option][,option][,...]\n" " old way to initialize a host network interface\n" --=20 2.23.0