From patchwork Fri Nov 12 09:14:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yaroshchuk X-Patchwork-Id: 1554214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ZvAdddsc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrCd800vNz9sPf for ; Fri, 12 Nov 2021 20:16:27 +1100 (AEDT) Received: from localhost ([::1]:59798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlSfZ-00020L-Bg for incoming@patchwork.ozlabs.org; Fri, 12 Nov 2021 04:16:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlSe0-0001xW-Vv for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:49 -0500 Received: from [2a00:1450:4864:20::231] (port=40479 helo=mail-lj1-x231.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlSdz-0000pT-2A for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:48 -0500 Received: by mail-lj1-x231.google.com with SMTP id u22so10518356lju.7 for ; Fri, 12 Nov 2021 01:14:46 -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=cc8p07X3/E/2bL9Y63qcgGX2vC1m/sTNn/AoaaI3kXE=; b=ZvAdddscbl+68r+EHU4E51X8pvDvhR7F2zYRDA5qhJGPet8X9RcAEwFUhGQKWNcypA RzJ/e2h/QFId6iyVHUMuJhwBFUxvjYR0udAx0fYfTd2fHHd8Z5qRQiIp+5IlM85IK2PN jAT/A8PcXVGm0LsbD+xsObdOOSodkzG0Dr6h/B8my+Fc+qd855mvydE21Eu27UX2gaQX WuKxqEYLypZpV04b21dPOInwpRIZcQlAZcFvzrmfV42xCsDwNpRNFIXiutwQLqdwJn3R PyAC/qgYCurWSzV1gpbsbYvjHtc2sVN8L5afnxxkcArRjcfeC7YnInEj0TaaevZ6MrvC YXpQ== 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=cc8p07X3/E/2bL9Y63qcgGX2vC1m/sTNn/AoaaI3kXE=; b=iMqfLv0yjbbIxJrdtFwlHitRLHtnerco1cIJNJUUwGo4PBaNPpulc5BdhmX/kfmO/U k47RnpJo8zObDty/JHc1AosmLCZvc1GqKw3SwwmijGYtZmF/OwqWn1LoNk0E65PKolM0 t2huxHYlqwAJiYo2tIYp3P3TF+Mup/WP+AuSlxFfROo0iimeJi3m4AB9L8/stwcEGh5c MjwB6EhHgZGyotKpC2B7V+6Fc6qW6MQZgouOcjsaBOaS5Mep3Bpyjwfdq6VQOFI7QPs6 A+EDc32pR2KIYNGAxQo6WbTzOhbml7BpSNUuUIsMuAvUDq+FJ0SMATVLJrDt0/KtZdFw AZcA== X-Gm-Message-State: AOAM533aeJMbsn6t0nEF2ZNjPrOglKm6tvSB1nIsGKFKEmQEq2fFqn/L bP8QsYa875ehYEyGeaeS482ZFivugftOrA== X-Google-Smtp-Source: ABdhPJwlub6z8nOu50pwhRWwejuU6Q4sdnFrnxp079y2Uh5QyZ4ca5ikUzlGHlq+qZYgnuv5gFL7xg== X-Received: by 2002:a2e:85c1:: with SMTP id h1mr13857225ljj.398.1636708485061; Fri, 12 Nov 2021 01:14:45 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2d:d7c7:95ac:c963:ac2e:68f]) by smtp.gmail.com with ESMTPSA id j11sm570134ljc.9.2021.11.12.01.14.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 01:14:44 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v5 1/6] net/vmnet: add vmnet dependency and customizable option Date: Fri, 12 Nov 2021 12:14:09 +0300 Message-Id: <20211112091414.34223-2-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211112091414.34223-1-yaroshchuk2000@gmail.com> References: <20211112091414.34223-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::231 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::231; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lj1-x231.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, PDS_HP_HELO_NORDNS=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Vladislav Yaroshchuk --- meson.build | 4 ++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 3 files changed, 9 insertions(+) diff --git a/meson.build b/meson.build index 2ece4fe088..202e04af31 100644 --- a/meson.build +++ b/meson.build @@ -477,6 +477,8 @@ if cocoa.found() and get_option('gtk').enabled() error('Cocoa and GTK+ cannot be enabled at the same time') endif +vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet')) + seccomp = not_found if not get_option('seccomp').auto() or have_system or have_tools seccomp = dependency('libseccomp', version: '>=2.3.0', @@ -1455,6 +1457,7 @@ config_host_data.set('CONFIG_SECCOMP', seccomp.found()) config_host_data.set('CONFIG_SNAPPY', snappy.found()) config_host_data.set('CONFIG_USB_LIBUSB', libusb.found()) config_host_data.set('CONFIG_VDE', vde.found()) +config_host_data.set('CONFIG_VMNET', vmnet.found()) config_host_data.set('CONFIG_VHOST_USER_BLK_SERVER', have_vhost_user_blk_server) config_host_data.set('CONFIG_VNC', vnc.found()) config_host_data.set('CONFIG_VNC_JPEG', jpeg.found()) @@ -3383,6 +3386,7 @@ endif summary_info += {'JACK support': jack} summary_info += {'brlapi support': brlapi} summary_info += {'vde support': vde} +summary_info += {'vmnet.framework support': vmnet} summary_info += {'netmap support': have_netmap} summary_info += {'l2tpv3 support': have_l2tpv3} summary_info += {'Linux AIO support': libaio} diff --git a/meson_options.txt b/meson_options.txt index 411952bc91..bdcd9674ea 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -147,6 +147,8 @@ option('netmap', type : 'feature', value : 'auto', description: 'netmap network backend support') option('vde', type : 'feature', value : 'auto', description: 'vde network backend support') +option('vmnet', type : 'feature', value : 'auto', + description: 'vmnet.framework network backend support') option('virglrenderer', type : 'feature', value : 'auto', description: 'virgl rendering support') option('vnc', type : 'feature', value : 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 45e1f2e20d..f75375c795 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -81,6 +81,7 @@ meson_options_help() { printf "%s\n" ' u2f U2F emulation support' printf "%s\n" ' usb-redir libusbredir support' printf "%s\n" ' vde vde network backend support' + printf "%s\n" ' vmnet vmnet.framework network backend support' printf "%s\n" ' vhost-user-blk-server' printf "%s\n" ' build vhost-user-blk server' printf "%s\n" ' virglrenderer virgl rendering support' @@ -239,6 +240,8 @@ _meson_option_parse() { --disable-usb-redir) printf "%s" -Dusb_redir=disabled ;; --enable-vde) printf "%s" -Dvde=enabled ;; --disable-vde) printf "%s" -Dvde=disabled ;; + --enable-vmnet) printf "%s" -Dvmnet=enabled ;; + --disable-vmnet) printf "%s" -Dvmnet=disabled ;; --enable-vhost-user-blk-server) printf "%s" -Dvhost_user_blk_server=enabled ;; --disable-vhost-user-blk-server) printf "%s" -Dvhost_user_blk_server=disabled ;; --enable-virglrenderer) printf "%s" -Dvirglrenderer=enabled ;; From patchwork Fri Nov 12 09:14:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yaroshchuk X-Patchwork-Id: 1554215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QPWhs9uC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrCd85GlPz9sRK for ; Fri, 12 Nov 2021 20:16:28 +1100 (AEDT) Received: from localhost ([::1]:59830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlSfa-00021y-Ej for incoming@patchwork.ozlabs.org; Fri, 12 Nov 2021 04:16:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlSe2-0001z1-0T for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:50 -0500 Received: from [2a00:1450:4864:20::129] (port=39451 helo=mail-lf1-x129.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlSdz-0000pX-MK for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:49 -0500 Received: by mail-lf1-x129.google.com with SMTP id f18so20781056lfv.6 for ; Fri, 12 Nov 2021 01:14:47 -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=yXldErOT0CqmaZDauAKyCejL9ob32Awf5qissE87w+s=; b=QPWhs9uCk0vGWvz/pTbBS2aNneld+2HcUain6ArsSImG/kuvAwdsBETILa/QwuAml/ dgJiL/kvltACQlSnlyy/5gq/fYaefUjvvIaH0J4DwP5jF/6oy5TSytnxN1Yda3R8WiDo 83Au6lrMEVV9b8tnoGuxs7W48dubmOCfsgXG1J6J0A9iC//kDBwO4LXueAmjcNA5i2Wq lJev+sjs9q+QtiNrPDIZDx3DATsRncr1daOdjErMFuakyyChUKVnvHxlZ27hgynNNG3r fZlOqn8UHj1/fiqsc+sV0+1bBZc7wHwUP6J418pmHOM7jbpkLVYZ9VZ4COnAJhlD7AYb yY0Q== 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=yXldErOT0CqmaZDauAKyCejL9ob32Awf5qissE87w+s=; b=0Z5tliP9+Zs7AKIxtymNd/rciR+mv0T0nWB71ntTk7w8CU/xjlhI9lqUMfMjawGjor XGMceE17dTTZDtvJPr3xyMtIbXQWO4pQTGXB62fa0cZ5ekgwxvvWZPhwae2kwx9+YQBs KXA8zuH9CJ1mBUuk/nnYQUXFNwgXExsDqOzvCmsGCxwDXOeyNiCz3lxz2Hod6Qo03SXz 42tTYgjI9imePGgMklQGpOo/WRmeXikdZa6uoGpB9hErLsrtqDN9ntYoTe7yKN1j/PID kkds7jJbtqw65rqvT0brNdkCtbxr11DbBDz3orscQABlziYgpKy7oEC+mAq3XvMsFX9f ctjg== X-Gm-Message-State: AOAM532GV8hj++qN9nvhxg4OtMWstqInUUW4WoVJWX+ezOvHJVEF+RnN h6t5hgNOez7M4wsI5gVw9x5zZrJSthldRA== X-Google-Smtp-Source: ABdhPJwObeg+nvdShp9FdJNEXcFCI3w81T5cHi8WRTrsN6djF5j0W9b5aMOgZ0hTZ7LSfFQQ8HNCgA== X-Received: by 2002:a05:6512:32c8:: with SMTP id f8mr12516803lfg.669.1636708485886; Fri, 12 Nov 2021 01:14:45 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2d:d7c7:95ac:c963:ac2e:68f]) by smtp.gmail.com with ESMTPSA id j11sm570134ljc.9.2021.11.12.01.14.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 01:14:45 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v5 2/6] net/vmnet: add vmnet backends to qapi/net Date: Fri, 12 Nov 2021 12:14:10 +0300 Message-Id: <20211112091414.34223-3-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211112091414.34223-1-yaroshchuk2000@gmail.com> References: <20211112091414.34223-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::129 (failed) 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: -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, PDS_HP_HELO_NORDNS=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Create separate netdevs for each vmnet operating mode: - vmnet-host - vmnet-shared - vmnet-bridged Signed-off-by: Vladislav Yaroshchuk --- net/clients.h | 11 ++++ net/meson.build | 7 +++ net/net.c | 10 ++++ net/vmnet-bridged.m | 25 +++++++++ net/vmnet-common.m | 20 +++++++ net/vmnet-host.c | 24 +++++++++ net/vmnet-shared.c | 25 +++++++++ net/vmnet_int.h | 25 +++++++++ qapi/net.json | 127 +++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 net/vmnet-bridged.m create mode 100644 net/vmnet-common.m create mode 100644 net/vmnet-host.c create mode 100644 net/vmnet-shared.c create mode 100644 net/vmnet_int.h 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, 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 847bc2ac85..00a88c4951 100644 --- a/net/meson.build +++ b/net/meson.build @@ -42,4 +42,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')) +vmnet_files = files( + 'vmnet-common.m', + 'vmnet-bridged.m', + 'vmnet-host.c', + 'vmnet-shared.c' +) +softmmu_ss.add(when: vmnet, if_true: vmnet_files) subdir('can') diff --git a/net/net.c b/net/net.c index f0d14dbfc1..1dbb64b935 100644 --- a/net/net.c +++ b/net/net.c @@ -1021,6 +1021,11 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3] = net_init_l2tpv3, #endif +#ifdef CONFIG_VMNET + [NET_CLIENT_DRIVER_VMNET_HOST] = net_init_vmnet_host, + [NET_CLIENT_DRIVER_VMNET_SHARED] = net_init_vmnet_shared, + [NET_CLIENT_DRIVER_VMNET_BRIDGED] = net_init_vmnet_bridged, +#endif /* CONFIG_VMNET */ }; @@ -1106,6 +1111,11 @@ void show_netdevs(void) #endif #ifdef CONFIG_VHOST_VDPA "vhost-vdpa", +#endif +#ifdef CONFIG_VMNET + "vmnet-host", + "vmnet-shared", + "vmnet-bridged", #endif }; diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m new file mode 100644 index 0000000000..4e42a90391 --- /dev/null +++ b/net/vmnet-bridged.m @@ -0,0 +1,25 @@ +/* + * vmnet-bridged.m + * + * Copyright(c) 2021 Vladislav Yaroshchuk + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#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 + +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.m b/net/vmnet-common.m new file mode 100644 index 0000000000..532d152840 --- /dev/null +++ b/net/vmnet-common.m @@ -0,0 +1,20 @@ +/* + * vmnet-common.m - 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 later. + * See the COPYING file in the top-level directory. + * + */ + +#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 + diff --git a/net/vmnet-host.c b/net/vmnet-host.c new file mode 100644 index 0000000000..4a5ef99dc7 --- /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 later. + * See the COPYING file in the top-level directory. + * + */ + +#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 + +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..f8c4a4f3b8 --- /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 later. + * See the COPYING file in the top-level directory. + * + */ + +#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 + +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_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 later. + * 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 */ diff --git a/qapi/net.json b/qapi/net.json index 7fab2e7cd8..665ef82a0d 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -452,6 +452,117 @@ '*vhostdev': 'str', '*queues': 'int' } } +## +# @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 host. +# +# @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 @subnet-mask. +# 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 @subnet-mask. +# +# @subnet-mask: The IPv4 subnet mask to use on the interface. Must +# be specified along with @dhcpstart and @subnet-mask. +# +# @isolated: Enable isolation for this interface. Interface isolation +# ensures that network communication between multiple +# vmnet interfaces instances is not possible. +# +# @net-uuid: The identifier (UUID) to uniquely identify the network. +# If provided, no DHCP service is provided on this network +# and the interface is added to an isolated network with +# the specified identifier. +# +# Since: 7.0 +## +{ 'struct': 'NetdevVmnetHostOptions', + 'data': { + '*dhcpstart': 'str', + '*dhcpend': 'str', + '*subnet-mask': 'str', + '*isolated': 'bool', + '*net-uuid': '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 communicate with the native host and with +# other shared mode interfaces on the same subnet. If no DHCP +# settings, subnet mask and IPv6 prefix specified, the interface can +# communicate with any of other interfaces in shared mode. +# +# @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 @subnet-mask. +# 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 @subnet-mask. +# +# @subnet-mask: The IPv4 subnet mask to use on the interface. Must +# be specified along with @dhcpstart and @subnet-mask. +# +# @isolated: Enable isolation for this interface. Interface isolation +# ensures that network communication between multiple +# vmnet interfaces instances is not possible. +# +# @nat66-prefix: The IPv6 prefix to use into guest network. Must be a +# unique local address i.e. start with fd00::/8 and have +# length of 64. +# +# Since: 7.0 +## +{ 'struct': 'NetdevVmnetSharedOptions', + 'data': { + '*dhcpstart': 'str', + '*dhcpend': 'str', + '*subnet-mask': 'str', + '*isolated': 'bool', + '*nat66-prefix': '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. +# +# @isolated: Enable isolation for this interface. Interface isolation +# ensures that network communication between multiple +# vmnet interfaces instances is not possible. +# +# Since: 7.0 +## +{ 'struct': 'NetdevVmnetBridgedOptions', + 'data': { + 'ifname': 'str', + '*isolated': 'str' + }, + 'if': 'CONFIG_VMNET' } + ## # @NetClientDriver: # @@ -460,10 +571,16 @@ # Since: 2.7 # # @vhost-vdpa since 5.1 +# @vmnet-host since 7.0 +# @vmnet-shared since 7.0 +# @vmnet-bridged since 7.0 ## { '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' }] } ## # @Netdev: @@ -477,6 +594,9 @@ # Since: 1.2 # # 'l2tpv3' - since 2.1 +# 'vmnet-host' - since 7.0 +# 'vmnet-shared' - since 7.0 +# 'vmnet-bridged' - since 7.0 ## { 'union': 'Netdev', 'base': { 'id': 'str', 'type': 'NetClientDriver' }, @@ -492,7 +612,10 @@ 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', 'vhost-user': 'NetdevVhostUserOptions', - 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } + 'vhost-vdpa': 'NetdevVhostVDPAOptions', + 'vmnet-host': 'NetdevVmnetHostOptions', + 'vmnet-shared': 'NetdevVmnetSharedOptions', + 'vmnet-bridged': 'NetdevVmnetBridgedOptions' } } ## # @RxState: From patchwork Fri Nov 12 09:14:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yaroshchuk X-Patchwork-Id: 1554217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UCF2zzZZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrCgZ0BB0z9sPf for ; Fri, 12 Nov 2021 20:18:34 +1100 (AEDT) Received: from localhost ([::1]:39860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlShb-00007G-Oz for incoming@patchwork.ozlabs.org; Fri, 12 Nov 2021 04:18:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlSe2-00020s-T5 for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:50 -0500 Received: from [2a00:1450:4864:20::230] (port=39815 helo=mail-lj1-x230.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlSe0-0000pb-EZ for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:50 -0500 Received: by mail-lj1-x230.google.com with SMTP id t11so17344335ljh.6 for ; Fri, 12 Nov 2021 01:14:48 -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=3Zhk16j4465JK+6nsn2hzafJQwkvamYf/L2WE8Bxhkk=; b=UCF2zzZZ5i50gdzBDGX+R+V58BN9AsswBco1EA4bdK5hWHOIj+0pfjvTqU9lskR1Gm oFOqh4bLCGq92H17Hcvj9RRgxct1FRuAT+O8gGr9prYX5GUFq5bQntqrVH6kYlmzMCFn 3Cm3i0L4EKjWXdG63qaZZ5piPzOroFI5Q4igrjSplc7bo8CLkSBIFF3bk10hu55SkRiv BGBN/YWInVq/1VyxZXpgRQvl5GJBOxoZUIF8S5MplxnojG6VEKdi2OAyXcOQjjQGGmMO DJgCJ/gX1HRgVbVh4+I1goOyx95YqxKGMed6yqGtV/ZazKm2OptDW2zUCT6ZSsvGrbFI YSYA== 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=3Zhk16j4465JK+6nsn2hzafJQwkvamYf/L2WE8Bxhkk=; b=CzUjld+lo1SHwp2SuGR/aG08fNFRnz5XjHxA026RZ8ytHbkM1V1UV/HMlO/dvp91LH 1fk+r9v/RgURok9rJUzvgzy85qcRvjgEYGS/vWhQNwN0CKHYAaIfFI/aXXmQzMFCN3fk h1jrKD9wmVW8WcKxZcGPCzh7f2EsAd+DSxdWKJI3TOTiVRuvtrdaRGN2AZTFru9iyb6j w+CGv4lO48xMT6U0kURIEINSNfwWNb5LAqU30bLnWJFoyoqtsjgCNkBrrYlGFKD7iNw0 qIkP3DPY1TDIwgwK8uKCkGV9wZbX6xd2vj+cHUgFpZkrTHgf1nK5VfBUwEISGuHdkVlc ceBg== X-Gm-Message-State: AOAM530CRQvVAhxCsh7C31IDOaOHLWOiwvIETawMpZaMtNArSAjpcoFN JXacGT7FMugUxSSRXe3CVpKycgqHP7aN7Q== X-Google-Smtp-Source: ABdhPJzvkmmcy5HNuZ/CuEq5rddojJ5wQNohaIApADhAOywTyopU/fRdJzEj3r03iB53ulf+3wd/vA== X-Received: by 2002:a2e:9206:: with SMTP id k6mr14054092ljg.415.1636708486608; Fri, 12 Nov 2021 01:14:46 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2d:d7c7:95ac:c963:ac2e:68f]) by smtp.gmail.com with ESMTPSA id j11sm570134ljc.9.2021.11.12.01.14.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 01:14:46 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v5 3/6] net/vmnet: implement shared mode (vmnet-shared) Date: Fri, 12 Nov 2021 12:14:11 +0300 Message-Id: <20211112091414.34223-4-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211112091414.34223-1-yaroshchuk2000@gmail.com> References: <20211112091414.34223-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::230 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::230; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lj1-x230.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, PDS_HP_HELO_NORDNS=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Phillip Tennen Signed-off-by: Vladislav Yaroshchuk --- net/vmnet-common.m | 305 +++++++++++++++++++++++++++++++++++++++++++++ net/vmnet-shared.c | 75 ++++++++++- net/vmnet_int.h | 23 ++++ 3 files changed, 399 insertions(+), 4 deletions(-) diff --git a/net/vmnet-common.m b/net/vmnet-common.m index 532d152840..b058e1b846 100644 --- a/net/vmnet-common.m +++ b/net/vmnet-common.m @@ -10,6 +10,8 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "qemu/log.h" #include "qapi/qapi-types-net.h" #include "vmnet_int.h" #include "clients.h" @@ -17,4 +19,307 @@ #include "qapi/error.h" #include +#include +#ifdef DEBUG +#define D(x) x +#define D_LOG(...) qemu_log(__VA_ARGS__) +#else +#define D(x) do { } while (0) +#define D_LOG(...) do { } while (0) +#endif + +typedef struct vmpktdesc vmpktdesc_t; +typedef struct iovec iovec_t; + +static void vmnet_set_send_enabled(VmnetCommonState *s, bool enable) +{ + s->send_enabled = enable; +} + + +static void vmnet_send_completed(NetClientState *nc, ssize_t len) +{ + VmnetCommonState *s = 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 == 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 = DO_UPCAST(VmnetCommonState, nc, nc); + + packets_available = xpc_dictionary_get_uint64( + event, + vmnet_estimated_packets_available_key + ); + + pkt_cnt = (packets_available < VMNET_PACKETS_LIMIT) ? + packets_available : + VMNET_PACKETS_LIMIT; + + + iov = s->iov_buf; + packets = s->packets_buf; + + for (i = 0; i < pkt_cnt; ++i) { + packets[i].vm_pkt_size = s->max_packet_size; + packets[i].vm_pkt_iovcnt = 1; + packets[i].vm_flags = 0; + } + + if_status = vmnet_read(s->vmnet_if, packets, &pkt_cnt); + if (if_status != VMNET_SUCCESS) { + error_printf("vmnet: read failed: %s\n", + vmnet_status_map_str(if_status)); + } + qemu_mutex_lock_iothread(); + for (i = 0; i < pkt_cnt; ++i) { + size = qemu_send_packet_async(nc, + iov[i].iov_base, + packets[i].vm_pkt_size, + vmnet_send_completed); + if (size == 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 = 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 = s->packets_buf; + iov = s->iov_buf; + + for (i = 0; i < VMNET_PACKETS_LIMIT; ++i) { + iov[i].iov_len = s->max_packet_size; + iov[i].iov_base = g_malloc0(iov[i].iov_len); + packets[i].vm_pkt_iov = 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"; + case VMNET_SHARING_SERVICE_BUSY: + return "conflict, sharing service is in use"; + 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_param)) +{ + VmnetCommonState *s; + + dispatch_queue_t if_create_q; + dispatch_semaphore_t if_created_sem; + + __block vmnet_return_t if_status; + + if_create_q = dispatch_queue_create("org.qemu.vmnet.create", + DISPATCH_QUEUE_SERIAL); + if_created_sem = dispatch_semaphore_create(0); + + xpc_dictionary_set_bool( + if_desc, + vmnet_allocate_mac_address_key, + false + ); + + D(D_LOG("vmnet.start.interface_desc:\n"); + xpc_dictionary_apply(if_desc, + ^bool(const char *k, xpc_object_t v) { + char *desc = xpc_copy_description(v); + D_LOG(" %s=%s\n", k, desc); + free(desc); + return true; + })); + + s = DO_UPCAST(VmnetCommonState, nc, nc); + s->vmnet_if = vmnet_start_interface( + if_desc, + if_create_q, + ^(vmnet_return_t status, xpc_object_t interface_param) { + if_status = status; + if (status != VMNET_SUCCESS || !interface_param) { + dispatch_semaphore_signal(if_created_sem); + return; + } + + s->mtu = xpc_dictionary_get_uint64( + interface_param, + vmnet_mtu_key); + s->max_packet_size = xpc_dictionary_get_uint64( + interface_param, + vmnet_max_packet_size_key); + D(D_LOG("vmnet.start.interface_param:\n"); + xpc_dictionary_apply(interface_param, + ^bool(const char *k, xpc_object_t v) { + char *desc = xpc_copy_description(v); + D_LOG(" %s=%s\n", k, desc); + free(desc); + return true; + })); + dispatch_semaphore_signal(if_created_sem); + }); + + if (s->vmnet_if == 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 != VMNET_SUCCESS) { + error_setg(errp, + "cannot create vmnet interface: %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 = 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 = (char *) buf; + iov.iov_len = size; + + packet.vm_pkt_iovcnt = 1; + packet.vm_flags = 0; + packet.vm_pkt_size = size; + packet.vm_pkt_iov = &iov; + + pkt_cnt = 1; + if_status = vmnet_write(s->vmnet_if, &packet, &pkt_cnt); + + if (if_status != VMNET_SUCCESS) { + error_report("vmnet: write error: %s\n", + vmnet_status_map_str(if_status)); + } + + if (if_status == VMNET_SUCCESS && pkt_cnt) { + return size; + } + return 0; +} + + +void vmnet_cleanup_common(NetClientState *nc) +{ + VmnetCommonState *s; + dispatch_queue_t if_destroy_q; + + s = DO_UPCAST(VmnetCommonState, nc, nc); + + qemu_purge_queued_packets(nc); + vmnet_set_send_enabled(s, false); + + if (s->vmnet_if == NULL) { + return; + } + + if_destroy_q = 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 = 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 f8c4a4f3b8..b27ada3219 100644 --- a/net/vmnet-shared.c +++ b/net/vmnet-shared.c @@ -10,16 +10,83 @@ #include "qemu/osdep.h" #include "qapi/qapi-types-net.h" +#include "qapi/error.h" #include "vmnet_int.h" #include "clients.h" -#include "qemu/error-report.h" -#include "qapi/error.h" #include +typedef struct VmnetSharedState { + VmnetCommonState cs; +} VmnetSharedState; + + +static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp) +{ + const NetdevVmnetSharedOptions *options = &(netdev->u.vmnet_shared); + xpc_object_t if_desc = 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_enable_isolation_key, + options->isolated + ); + + if (options->has_nat66_prefix) { + xpc_dictionary_set_string(if_desc, + vmnet_nat66_prefix_key, + options->nat66_prefix); + } + + if (options->has_dhcpstart || + options->has_dhcpend || + options->has_subnet_mask) { + + if (options->has_dhcpstart && + options->has_dhcpend && + options->has_subnet_mask) { + + 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->subnet_mask); + } else { + error_setg( + errp, + "'dhcpstart', 'dhcpend', 'subnet_mask' " + "should be provided together" + ); + } + } + + return if_desc; +} + +static NetClientInfo net_vmnet_shared_info = { + .type = NET_CLIENT_DRIVER_VMNET_SHARED, + .size = sizeof(VmnetSharedState), + .receive = vmnet_receive_common, + .cleanup = 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 = qemu_new_net_client(&net_vmnet_shared_info, + peer, "vmnet-shared", name); + xpc_object_t if_desc = create_if_desc(netdev, errp); + + return vmnet_if_create(nc, if_desc, errp, NULL); } + 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 @@ #include +#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]; } VmnetCommonState; +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_param)); + +ssize_t vmnet_receive_common(NetClientState *nc, + const uint8_t *buf, + size_t size); + +void vmnet_cleanup_common(NetClientState *nc); #endif /* VMNET_INT_H */ From patchwork Fri Nov 12 09:14:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yaroshchuk X-Patchwork-Id: 1554216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QQCAuscr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrCd94XBpz9sPf for ; Fri, 12 Nov 2021 20:16:29 +1100 (AEDT) Received: from localhost ([::1]:59944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlSfb-00026l-CM for incoming@patchwork.ozlabs.org; Fri, 12 Nov 2021 04:16:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlSe3-00021K-3r for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:51 -0500 Received: from [2a00:1450:4864:20::22e] (port=40477 helo=mail-lj1-x22e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlSe0-0000pg-U2 for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:50 -0500 Received: by mail-lj1-x22e.google.com with SMTP id u22so10518514lju.7 for ; Fri, 12 Nov 2021 01:14:48 -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=fDigqMREZ6cxzC0W1knHKDGniod1WoHeEKIA7AsPTsI=; b=QQCAuscrIHZ4P9i75Mic+9yZajjfwbj+UtrBUBe33yJciEqL/YfaKdszLa9KEmerP9 WoxJRMTyu9SGuZZNRwCE5qSlthc18tgACR0WpJlsg3Fb2GiDiiMtBKCdxiVHmSZSADv0 SB/YmPujTpnNgeIl4MYNFrZfioMKFM//gZ5G1JeCUSfcvaH4N1Ke1wIWTpzuU7KDlX3F vRhBHcX117ZDl2kUIzaAUAvux9PyfmEyGgb5gtIx1MM0lgSB+Znz8nXno5TxHqTt9kca SH5Iy6h8Dg6NSVBjcw2A7inePBzGLqC8Gbu3yRm8EG8LXDvTUDjo6/wZXhxYs9WPXJyY G3+w== 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=fDigqMREZ6cxzC0W1knHKDGniod1WoHeEKIA7AsPTsI=; b=FSt/CYVbGjkHdWgp8yVS1OYM+vaiWLS70lEjWpzyRCfGkX0NvpL79Yse/SBQVIOTQm G0T9NtYXVBza3RIpcOuFgUtg1JB/tkscjMWQ1fnfgXbZ76aeap0B6DHMXGZ1Fnw97dPE TcebYV118eaxSOFKmXrfhq6+9QHP82IPxa0YTdHg4Fkpkv9czJUX9AxefqZ6NYwbay6K B+7Pk60Kx1be8hTdmY1xa7HKK9bsbH0wurnlMJpgmxadPZmDlnLRVubQUnOzBH9RsgcQ 4HrY6x5nWiM1Y2yBAsp8K3iEyfgk2CJuqcxXvKG1Yql7Lf15cM7q5fA6175P4ZkLRLou vRDA== X-Gm-Message-State: AOAM531o+ba/1mu410tMdpQjtQcUYpQ8v7MAnp1WbnLgmhOdF4Ma69/P JJDrApO8Lr7F0BHg6QmV2yGG2BswBpFF8w== X-Google-Smtp-Source: ABdhPJzp1u5bSArxhhopv/FAZTwMZVs7x+nC9JR7ysEtXs5qyGpjLzdxxy1yWYSYquJEylQp6bVNDw== X-Received: by 2002:a2e:a54e:: with SMTP id e14mr14111605ljn.136.1636708487238; Fri, 12 Nov 2021 01:14:47 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2d:d7c7:95ac:c963:ac2e:68f]) by smtp.gmail.com with ESMTPSA id j11sm570134ljc.9.2021.11.12.01.14.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 01:14:46 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v5 4/6] net/vmnet: implement host mode (vmnet-host) Date: Fri, 12 Nov 2021 12:14:12 +0300 Message-Id: <20211112091414.34223-5-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211112091414.34223-1-yaroshchuk2000@gmail.com> References: <20211112091414.34223-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::22e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lj1-x22e.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, PDS_HP_HELO_NORDNS=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Vladislav Yaroshchuk --- net/vmnet-host.c | 99 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/net/vmnet-host.c b/net/vmnet-host.c index 4a5ef99dc7..f7dbd3f9bf 100644 --- a/net/vmnet-host.c +++ b/net/vmnet-host.c @@ -9,16 +9,103 @@ */ #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" #include +typedef struct VmnetHostState { + VmnetCommonState cs; + QemuUUID network_uuid; +} VmnetHostState; + +static xpc_object_t create_if_desc(const Netdev *netdev, + NetClientState *nc, + Error **errp) +{ + const NetdevVmnetHostOptions *options = &(netdev->u.vmnet_host); + VmnetCommonState *cs = DO_UPCAST(VmnetCommonState, nc, nc); + VmnetHostState *hs = DO_UPCAST(VmnetHostState, cs, cs); + + xpc_object_t if_desc = 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_enable_isolation_key, + options->isolated + ); + + if (options->has_net_uuid) { + if (qemu_uuid_parse(options->net_uuid, &hs->network_uuid) < 0) { + error_setg(errp, "Invalid UUID provided in 'net-uuid'"); + } + + xpc_dictionary_set_uuid( + if_desc, + vmnet_network_identifier_key, + hs->network_uuid.data + ); + } + + if (options->has_dhcpstart || + options->has_dhcpend || + options->has_subnet_mask) { + + if (options->has_dhcpstart && + options->has_dhcpend && + options->has_subnet_mask) { + + if (options->has_net_uuid) { + error_setg(errp, + "DHCP disabled for this interface " + "because 'net-uuid' is provided"); + } + + 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->subnet_mask); + } else { + error_setg( + errp, + "'dhcpstart', 'dhcpend', 'subnet_mask' " + "should be provided together" + ); + } + } + + return if_desc; +} + +static NetClientInfo net_vmnet_host_info = { + .type = NET_CLIENT_DRIVER_VMNET_HOST, + .size = sizeof(VmnetHostState), + .receive = vmnet_receive_common, + .cleanup = 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 = qemu_new_net_client(&net_vmnet_host_info, + peer, "vmnet-host", name); + if_desc = create_if_desc(netdev, nc, errp); + return vmnet_if_create(nc, if_desc, errp, NULL); } From patchwork Fri Nov 12 09:14:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yaroshchuk X-Patchwork-Id: 1554218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=gBmewjAa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrCgd2Qkyz9sPf for ; Fri, 12 Nov 2021 20:18:37 +1100 (AEDT) Received: from localhost ([::1]:40208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlShf-0000Mm-5H for incoming@patchwork.ozlabs.org; Fri, 12 Nov 2021 04:18:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlSe3-00021T-6S for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:51 -0500 Received: from [2a00:1450:4864:20::12d] (port=34429 helo=mail-lf1-x12d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlSe1-0000pt-MJ for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:50 -0500 Received: by mail-lf1-x12d.google.com with SMTP id n12so11145155lfe.1 for ; Fri, 12 Nov 2021 01:14:49 -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=vlN7d0rtidqdQWLCIgN5N1fcLK+0qLzuCPNMY3+d1oo=; b=gBmewjAa8t5HjREEN8jgvvPrYP7for0X1EttCruV0vVOOnOXg2jmyKw5/i4l2QrRCA uXTXgj/jRvNTGGe6fisiIXPNR054zODB+irAYMzSnnMSlZLucfAs+6t2fFez9g7ZsOHm w4OQG5FvtExuJP7Yzva15rfDug1C/3N0TXYuAGvFMKKujupa6I8ga3bNM0DIlFeF6BEN ZUU734inTTevks0P/aV9WzWZ65lMCOBx489nGhmp0jIuj0bdeefE6ybskxcKQXk5V7/v eZ4zVHl0R8Vq6MuoUpAiDdGwR8u9/KnZdn+5EVQqIdNRyAP7rE8Zqt8pqB39ZDNWN1Gv T6VQ== 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=vlN7d0rtidqdQWLCIgN5N1fcLK+0qLzuCPNMY3+d1oo=; b=1nFz0MRJ6S4SEqzPtWDBYmavLRrEzTryb0KXZeH0b722mnyC8YrOt8HjS/CcMNxzqD U9R/LfJU0VmMrN7sahmEOFaH4wWbqulPEOkS7jExeH7wqbYY2DbrQTYZr16Ybuqeq7OZ CV3f60Vhg9dIIQ6JRlUnoC2VtWUT5fNCz1ychStZDRRX8ta4roHoriMvDgdMd7DCyit3 ZriXPA6Vgj3dia7Q4ZKrJ5aAuunUZCcLTalB6ABVJMcYmvrI2S0ve9bX3FD/ot79cnjk 3QP9xR5Jfh6tmA0dPx5TnQrLSmojpzC2L5rhcm5KAcxt6VYSMHHKmpJRqVMvcyuTSAmy e1xA== X-Gm-Message-State: AOAM531AeLi5JfAYdOOISTxJLCjU1DK8w+N8y8C6dHO/Qit3OQ6udxf/ WZValONgbt+dSzTZ+FrdXjYJMho337ZHPw== X-Google-Smtp-Source: ABdhPJwBHekBp29geNsempEt6ung5uNo1NnrV+BW/qGt7yhvYNQ1eej4H2kjpTPzH0ILrgRW0HZyRg== X-Received: by 2002:a05:6512:3b27:: with SMTP id f39mr12231569lfv.67.1636708487879; Fri, 12 Nov 2021 01:14:47 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2d:d7c7:95ac:c963:ac2e:68f]) by smtp.gmail.com with ESMTPSA id j11sm570134ljc.9.2021.11.12.01.14.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 01:14:47 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v5 5/6] net/vmnet: implement bridged mode (vmnet-bridged) Date: Fri, 12 Nov 2021 12:14:13 +0300 Message-Id: <20211112091414.34223-6-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211112091414.34223-1-yaroshchuk2000@gmail.com> References: <20211112091414.34223-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::12d (failed) 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: -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, PDS_HP_HELO_NORDNS=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Vladislav Yaroshchuk --- net/vmnet-bridged.m | 98 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-) diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m index 4e42a90391..3c9da9dc8b 100644 --- a/net/vmnet-bridged.m +++ b/net/vmnet-bridged.m @@ -10,16 +10,102 @@ #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" #include +typedef struct VmnetBridgedState { + VmnetCommonState cs; +} VmnetBridgedState; + +static bool validate_ifname(const char *ifname) +{ + xpc_object_t shared_if_list = vmnet_copy_shared_interface_list(); + __block bool match = false; + + xpc_array_apply( + shared_if_list, + ^bool(size_t index, xpc_object_t value) { + if (strcmp(xpc_string_get_string_ptr(value), ifname) == 0) { + match = true; + return false; + } + return true; + }); + + return match; +} + +static const char *get_valid_ifnames(void) +{ + xpc_object_t shared_if_list = vmnet_copy_shared_interface_list(); + __block char *if_list = NULL; + + xpc_array_apply( + shared_if_list, + ^bool(size_t index, xpc_object_t value) { + if_list = 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 = &(netdev->u.vmnet_bridged); + xpc_object_t if_desc = 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_enable_isolation_key, + options->isolated + ); + + 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 = { + .type = NET_CLIENT_DRIVER_VMNET_BRIDGED, + .size = sizeof(VmnetBridgedState), + .receive = vmnet_receive_common, + .cleanup = 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 = qemu_new_net_client(&net_vmnet_bridged_info, + peer, "vmnet-bridged", name); + xpc_object_t if_desc = 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); +} \ No newline at end of file From patchwork Fri Nov 12 09:14:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yaroshchuk X-Patchwork-Id: 1554219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=g4kewQfH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrCj20w03z9sPf for ; Fri, 12 Nov 2021 20:19:50 +1100 (AEDT) Received: from localhost ([::1]:44162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlSip-0003AX-Tu for incoming@patchwork.ozlabs.org; Fri, 12 Nov 2021 04:19:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlSe3-00023b-TE for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:51 -0500 Received: from [2a00:1450:4864:20::134] (port=35728 helo=mail-lf1-x134.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlSe2-0000q2-4U for qemu-devel@nongnu.org; Fri, 12 Nov 2021 04:14:51 -0500 Received: by mail-lf1-x134.google.com with SMTP id p16so20789769lfa.2 for ; Fri, 12 Nov 2021 01:14:49 -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=QJBpzO6R9GmHNAE7Ii3PsVXpsYLZ7zboHCfFVaSYQkU=; b=g4kewQfHFOmzzOhQ2c1J/NrSIdjjqiIwMxFSZutryFZQZ4hWa2Zn0tvKK8igTIVBpI RMZ7J/uzSjjUVBulStVzxTFAybUWJL80XThu/y/AtCoeFptjQ9KkKb7QUVgdcEIrFHHE Qo+WsAyuvslWNMyxHzsSL63ZF1QuLuiIjNh2ICbkpc2xoH2Pracwt6ohYwVj7rklnny3 xa/2sOEOSzvq5MH3dEprrWApZYFDzME6qsooTJ67Lx/IBiQDrzVPNiwGNDuzD/jAQLOt N12F8uMjg7YxGM3GHBvhr2Hoiyf9mbJCt0lhC2UAbCUPd8x5C3emE+1OkLKTf+WRa01x yjRg== 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=QJBpzO6R9GmHNAE7Ii3PsVXpsYLZ7zboHCfFVaSYQkU=; b=AQVQtq/P14yd5HQJbNl1CFNBQSSI9XI/R/CiZgSbD3nGrqg+FLaIIhf+zCXQoFc+0T Bi8RywM80YNhQ+vG+ZOPVgNTpr1bOUopXZOL+AFkl00bRAcijAJ5j7GKsvfaVi+9njSM QdTRQqMfr3O+mziTzDgIRcu3B9jAcUpAkIn4shTngfCnC1InbqFZmZsSCIUnjVm4y+pu gm5EkHMRaVIKtMIMJsf+jO+eBl0FY70r3RRYmqxIK1C5QWYKBJWVuwl/j0D4U/l3Inin CYPRIm5LICU6lfHc8w0m52MtPJTI+ZL45vI/25BzN8P7h4wz5yCXE3S6f7Bj85FHjuD5 yMfw== X-Gm-Message-State: AOAM532G6N/bQczRGnPIrA6T0a4Eq1CxgXMSSHG0ifRqBLfJD4mFgzvn k14y+99+9vZl2HE5aR+2fUeWiu42+lqICA== X-Google-Smtp-Source: ABdhPJxHebIzzBpDtC9ILjNcl3L/Wf/879OlkvzQysaQjXj3f/Dr2Rv9h65QLbGabxNgbL0qb8YK7A== X-Received: by 2002:ac2:5f0d:: with SMTP id 13mr12901747lfq.334.1636708488460; Fri, 12 Nov 2021 01:14:48 -0800 (PST) Received: from UNIT-808.lan ([2a02:2698:6c2d:d7c7:95ac:c963:ac2e:68f]) by smtp.gmail.com with ESMTPSA id j11sm570134ljc.9.2021.11.12.01.14.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 01:14:48 -0800 (PST) From: Vladislav Yaroshchuk To: qemu-devel@nongnu.org Subject: [PATCH v5 6/6] net/vmnet: update qemu-options.hx Date: Fri, 12 Nov 2021 12:14:14 +0300 Message-Id: <20211112091414.34223-7-yaroshchuk2000@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211112091414.34223-1-yaroshchuk2000@gmail.com> References: <20211112091414.34223-1-yaroshchuk2000@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::134 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=yaroshchuk2000@gmail.com; helo=mail-lf1-x134.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, PDS_HP_HELO_NORDNS=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Vladislav Yaroshchuk --- qemu-options.hx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 7749f59300..350d43bbc0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2677,6 +2677,25 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, #ifdef __linux__ "-netdev vhost-vdpa,id=str,vhostdev=/path/to/dev\n" " configure a vhost-vdpa network,Establish a vhost-vdpa netdev\n" +#endif +#ifdef CONFIG_VMNET + "-netdev vmnet-host,id=str[,isolated=on|off][,net-uuid=uuid]\n" + " [,dhcpstart=addr,dhcpend=addr,subnet-mask=mask]\n" + " configure a vmnet network backend in host mode with ID 'str',\n" + " isolate this interface from others with 'isolated',\n" + " configure its DHCP server and choose a subnet mask\n" + " or specify network UUID 'uuid' to disable DHCP and interact with\n" + " vmnet-host interfaces within this isolated network\n" + "-netdev vmnet-shared,id=str[,isolated=on|off][,nat66-prefix=addr]\n" + " [,dhcpstart=addr,dhcpend=addr,subnet-mask=mask]\n" + " configure a vmnet network backend in shared mode with ID 'str',\n" + " configure its DHCP server and choose a subnet mask,\n" + " set IPv6 ULA prefix (of length 64) to use for internal network,\n" + " isolate this interface from others with 'isolated'\n" + "-netdev vmnet-bridged,id=str,ifname=name[,isolated=on|off]\n" + " configure a vmnet network backend in bridged mode with ID 'str',\n" + " use 'ifname=name' to select a physical network interface to be bridged,\n" + " isolate this interface from others with 'isolated'\n" #endif "-netdev hubport,id=str,hubid=n[,netdev=nd]\n" " configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL) @@ -2696,6 +2715,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=macaddr]\n" " initialize an on-board / default host NIC (using MAC address\n" @@ -2718,6 +2740,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"