Re: [PATCH v2] net/macos: implement vmnet-based network device

2021-03-15 Thread Markus Armbruster
Phillip Tennen  writes:

> Markus, thanks for the review. I apologize for my lateness in getting back
> to you.
>
> I've integrated most of your suggestions, and will submit a v5 that
> incorporates them. I've left a couple comments and questions for you below.
>
> Aside: I haven't responded inline to emails like this before, I'm hoping it
> shows
> up correctly for you! I appreciate how understanding everyone's been
> towards my
> newness to this development & review format. I cut out the irrelevant bits
> for brevity and am unsure if that breaks anything.

We *try* not to be jerks ;)

Your reply looks fine to me.

> Phillip
>
> On Tue, Mar 2, 2021 at 11:49 AM Markus Armbruster  wrote:
>
>> Phillip, this doesn't apply anymore.  I'm reviewing the QAPI schema part
>> anyway.
>>
>> Peter, there is a question for you below.  Search for "Sphinx".
>>
>> phillip.en...@gmail.com writes:
>>
>> > From: Phillip Tennen 
>> >
>> > This patch implements a new netdev device, reachable via -netdev
>> > vmnet-macos, that’s backed by macOS’s vmnet framework.
>> >
>>
> [...]
>
>> > diff --git a/qapi/net.json b/qapi/net.json
>> > index c31748c87f..e4d4143243 100644
>> > --- a/qapi/net.json
>> > +++ b/qapi/net.json
>> > @@ -450,6 +450,115 @@
>> >  '*vhostdev': 'str',
>> >  '*queues':   'int' } }
>> >
>> > +##
>> > +# @VmnetOperatingMode:
>> > +#
>> > +# The operating modes in which a vmnet netdev can run
>> > +# Only available on macOS
>>
>> Please end these sentences with a period.
>>
>> I'm not sure we need "Only available on macOS".  Rendered documentation
>> shows the 'if' like
>>
>> [...]
>
>> > +#  (only valid with mode=host|shared)
>>
>> Isn't that trivial?  The type's only use is as union branch for modes
>> host and shared.
>>
> True. I added comments like this for clarity, but I accept that the schema
> should make it clear alone.

Clarity is in the eye of the beholder.  We try to find the sweet spot
between bafflingly terse and tiresomely verbose.


>> > +#  (must be specified with dhcp-end-address and
>> > +#   dhcp-subnet-mask)
>>
>> Does that mean you have to specify all three parameters or none?
>>
> That's correct. You may provide either none or all three.

In bridged mode, none.

In host or shared mode, either all three or none.

Correct?

> [...]
>
>> > +#  (allocated automatically if unset)
>>
>> How?
>>
> vmnet automatically allocates specifics like the MAC address, DHCP pool,
> etc,
> if not explicitly supplied. I'll add some wording to this effect.
> [...]
>
>>
>> > +#
>> > +# Since: 6.0
>> > +##
>> > +{ 'struct': 'NetdevVmnetOptions',
>> > +  'data': {'options': 'NetdevVmnetModeOptions' },
>> > +  'if': 'defined(CONFIG_DARWIN)' }
>> > +
>>
>> Awkward.
>>
>> You can't use make NetdevVmnetModeOptions a branch of union Netdev,
>> because NetdevVmnetModeOptions is a union, and a branch must be a
>> struct.  To work around, you wrap struct NetdevVmnetOptions around union
>> NetdevVmnetModeOptions.
>>
>> NetdevVmnetModeOptions has no common members other than the union
>> discriminator.  Why not add them as three branches to Netdev?
>
> Just to be sure I understand, you're proposing adding 3 new fields to
> Netdev,
> like so:
> 'vmnet-macos-bridged': { 'type': 'NetdevVmnetModeOptionsBridged',
>  'if': 'defined(CONFIG_DARWIN)' },
> 'vmnet-macos-host': { 'type': 'NetdevVmnetModeOptionsHostOrShared',
>  'if': 'defined(CONFIG_DARWIN)' },
> 'vmnet-macos-shared': { 'type': 'NetdevVmnetModeOptionsHostOrShared',
>  'if': 'defined(CONFIG_DARWIN)' },
> ... where each of those "ModeOptions" structs contains a new "mode" field
> extracted from the union. Did I get your intent right? I'm assuming there
> wouldn't be issues with "vmnet-macos" referenced elsewhere.

Yes, except you don't need a @mode member, you can derive the mode from
Netdev member @type.

Clear now?




Re: [PATCH v2] net/macos: implement vmnet-based network device

2021-03-12 Thread Phillip Tennen
Markus, thanks for the review. I apologize for my lateness in getting back
to you.

I've integrated most of your suggestions, and will submit a v5 that
incorporates them. I've left a couple comments and questions for you below.

Aside: I haven't responded inline to emails like this before, I'm hoping it
shows
up correctly for you! I appreciate how understanding everyone's been
towards my
newness to this development & review format. I cut out the irrelevant bits
for brevity and am unsure if that breaks anything.

Phillip

On Tue, Mar 2, 2021 at 11:49 AM Markus Armbruster  wrote:

> Phillip, this doesn't apply anymore.  I'm reviewing the QAPI schema part
> anyway.
>
> Peter, there is a question for you below.  Search for "Sphinx".
>
> phillip.en...@gmail.com writes:
>
> > From: Phillip Tennen 
> >
> > This patch implements a new netdev device, reachable via -netdev
> > vmnet-macos, that’s backed by macOS’s vmnet framework.
> >
>
[...]

> > diff --git a/qapi/net.json b/qapi/net.json
> > index c31748c87f..e4d4143243 100644
> > --- a/qapi/net.json
> > +++ b/qapi/net.json
> > @@ -450,6 +450,115 @@
> >  '*vhostdev': 'str',
> >  '*queues':   'int' } }
> >
> > +##
> > +# @VmnetOperatingMode:
> > +#
> > +# The operating modes in which a vmnet netdev can run
> > +# Only available on macOS
>
> Please end these sentences with a period.
>
> I'm not sure we need "Only available on macOS".  Rendered documentation
> shows the 'if' like
>
> [...]

> > +#  (only valid with mode=host|shared)
>
> Isn't that trivial?  The type's only use is as union branch for modes
> host and shared.
>
True. I added comments like this for clarity, but I accept that the schema
should make it clear alone.

>
> > +#  (must be specified with dhcp-end-address and
> > +#   dhcp-subnet-mask)
>
> Does that mean you have to specify all three parameters or none?
>
That's correct. You may provide either none or all three.

[...]

> > +#  (allocated automatically if unset)
>
> How?
>
vmnet automatically allocates specifics like the MAC address, DHCP pool,
etc,
if not explicitly supplied. I'll add some wording to this effect.
[...]

>
> > +#
> > +# Since: 6.0
> > +##
> > +{ 'struct': 'NetdevVmnetOptions',
> > +  'data': {'options': 'NetdevVmnetModeOptions' },
> > +  'if': 'defined(CONFIG_DARWIN)' }
> > +
>
> Awkward.
>
> You can't use make NetdevVmnetModeOptions a branch of union Netdev,
> because NetdevVmnetModeOptions is a union, and a branch must be a
> struct.  To work around, you wrap struct NetdevVmnetOptions around union
> NetdevVmnetModeOptions.
>
> NetdevVmnetModeOptions has no common members other than the union
> discriminator.  Why not add them as three branches to Netdev?
>
> Just to be sure I understand, you're proposing adding 3 new fields to
Netdev,
like so:
'vmnet-macos-bridged': { 'type': 'NetdevVmnetModeOptionsBridged',
 'if': 'defined(CONFIG_DARWIN)' },
'vmnet-macos-host': { 'type': 'NetdevVmnetModeOptionsHostOrShared',
 'if': 'defined(CONFIG_DARWIN)' },
'vmnet-macos-shared': { 'type': 'NetdevVmnetModeOptionsHostOrShared',
 'if': 'defined(CONFIG_DARWIN)' },
... where each of those "ModeOptions" structs contains a new "mode" field
extracted from the union. Did I get your intent right? I'm assuming there
wouldn't be issues with "vmnet-macos" referenced elsewhere.

Thank you!
Phillip


Re: [PATCH v2] net/macos: implement vmnet-based network device

2021-03-02 Thread Markus Armbruster
Phillip, this doesn't apply anymore.  I'm reviewing the QAPI schema part
anyway.

Peter, there is a question for you below.  Search for "Sphinx".

phillip.en...@gmail.com writes:

> From: Phillip Tennen 
>
> This patch implements a new netdev device, reachable via -netdev
> vmnet-macos, that’s backed by macOS’s vmnet framework.
>
> The vmnet framework provides native bridging support, and its usage in
> this patch is intended as a replacement for attempts to use a tap device
> via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
> never would have worked in the first place, as QEMU interacts with the
> tap device via poll(), and macOS does not support polling device files.
>
> vmnet requires either a special entitlement, granted via a provisioning
> profile, or root access. Otherwise attempts to create the virtual
> interface will fail with a “generic error” status code. QEMU may not
> currently be signed with an entitlement granted in a provisioning
> profile, as this would necessitate pre-signed binary build distribution,
> rather than source-code distribution. As such, using this netdev
> currently requires that qemu be run with root access. I’ve opened a
> feedback report with Apple to allow the use of the relevant entitlement
> with this use case:
> https://openradar.appspot.com/radar?id=5007417364447232
>
> vmnet offers three operating modes, all of which are supported by this
> patch via the “mode=host|shared|bridge” option:
>
> * "Host" mode: Allows the vmnet interface to communicate with other
> * vmnet
> interfaces that are in host mode and also with the native host.
> * "Shared" mode: Allows traffic originating from the vmnet interface to
> reach the Internet through a NAT. The vmnet interface can also
> communicate with the native host.
> * "Bridged" mode: Bridges the vmnet interface with a physical network
> interface.
>
> Each of these modes also provide some extra configuration that’s
> supported by this patch:
>
> * "Bridged" mode: The user may specify the physical interface to bridge
> with. Defaults to en0.
> * "Host" mode / "Shared" mode: The user may specify the DHCP range and
> subnet. Allocated by vmnet if not provided.
>
> vmnet also offers some extra configuration options that are not
> supported by this patch:
>
> * Enable isolation from other VMs using vmnet
> * Port forwarding rules
> * Enabling TCP segmentation offload
> * Only applicable in "shared" mode: specifying the NAT IPv6 prefix
> * Only available in "host" mode: specifying the IP address for the VM
> within an isolated network
>
> Note that this patch requires macOS 10.15 as a minimum, as this is when
> bridging support was implemented in vmnet.framework.
>
> Signed-off-by: Phillip Tennen 
> ---
[...]
> diff --git a/qapi/net.json b/qapi/net.json
> index c31748c87f..e4d4143243 100644
> --- a/qapi/net.json
> +++ b/qapi/net.json
> @@ -450,6 +450,115 @@
>  '*vhostdev': 'str',
>  '*queues':   'int' } }
>  
> +##
> +# @VmnetOperatingMode:
> +#
> +# The operating modes in which a vmnet netdev can run
> +# Only available on macOS

Please end these sentences with a period.

I'm not sure we need "Only available on macOS".  Rendered documentation
shows the 'if' like

If
defined(CONFIG_DARWIN)

More of the same below.

> +#
> +# @host: the guest may communicate with the host 
> +#and other guest network interfaces
> +#
> +# @shared: the guest may reach the Internet through a NAT, 
> +#  and may communicate with the host and other guest 
> +#  network interfaces
> +#
> +# @bridged: the guest's traffic is bridged with a 
> +#   physical network interface of the host
> +#
> +# Since: 6.0
> +##
> +{ 'enum': 'VmnetOperatingMode',
> +  'data': [ 'host', 'shared', 'bridged' ],
> +  'if': 'defined(CONFIG_DARWIN)' }
> +
> +##
> +# @NetdevVmnetModeOptionsBridged:
> +#
> +# Options for the vmnet-macos netdev
> +# that are only available in 'bridged' mode
> +# Only available on macOS

Likewise.

> +#
> +# @ifname: the physical network interface to bridge with 
> +#  (defaults to en0 if not specified)
> +#
> +# Since: 6.0
> +##
> +{ 'struct': 'NetdevVmnetModeOptionsBridged',
> +  'data': { '*ifname':  'str' },
> +  'if': 'defined(CONFIG_DARWIN)' }
> +
> +##
> +# @NetdevVmnetModeOptionsHostOrShared:
> +#
> +# Options for the vmnet-macos netdev
> +# that are only available in 'host' or 'shared' mode
> +# Only available on macOS
> +#
> +# @dhcp-start-address: the gateway address to use for the interface. 
> +#  The range to dhcp_end_address is placed in the DHCP 
> pool.

Recommend to wrap lines around column 75.

> +#  (only valid with mode=host|shared)

Isn't that trivial?  The type's only use is as union branch for modes
host and shared.

> +#  (must be specified with dhcp-end-address and 
> +#   dhcp-subnet-mask)

Does that mean you have to specify all three parameters or none?


Re: [PATCH v2] net/macos: implement vmnet-based network device

2021-02-11 Thread Phillip Tennen
Hi Howard,

Thanks very much for taking a look and testing it out!

This is a good catch - VMNET_SHARING_SERVICE_BUSY
was added in macOS Big Sur, and is not available in prior versions.

I'll submit a v3 of this patch that adds a compile-guard around this
constant (assuming the #available macro is... available), and will
validate the other vmnet symbols I reference as well.

Phillip

On Thu, Feb 11, 2021 at 7:51 AM Howard Spoelstra  wrote:

> On Fri, Feb 5, 2021 at 5:54 PM  wrote:
> >
> > From: Phillip Tennen 
> >
> > This patch implements a new netdev device, reachable via -netdev
> > vmnet-macos, that’s backed by macOS’s vmnet framework.
> >
> > The vmnet framework provides native bridging support, and its usage in
> > this patch is intended as a replacement for attempts to use a tap device
> > via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
> > never would have worked in the first place, as QEMU interacts with the
> > tap device via poll(), and macOS does not support polling device files.
> >
> > vmnet requires either a special entitlement, granted via a provisioning
> > profile, or root access. Otherwise attempts to create the virtual
> > interface will fail with a “generic error” status code. QEMU may not
> > currently be signed with an entitlement granted in a provisioning
> > profile, as this would necessitate pre-signed binary build distribution,
> > rather than source-code distribution. As such, using this netdev
> > currently requires that qemu be run with root access. I’ve opened a
> > feedback report with Apple to allow the use of the relevant entitlement
> > with this use case:
> > https://openradar.appspot.com/radar?id=5007417364447232
> >
> > vmnet offers three operating modes, all of which are supported by this
> > patch via the “mode=host|shared|bridge” option:
> >
> > * "Host" mode: Allows the vmnet interface to communicate with other
> > * vmnet
> > interfaces that are in host mode and also with the native host.
> > * "Shared" mode: Allows traffic originating from the vmnet interface to
> > reach the Internet through a NAT. The vmnet interface can also
> > communicate with the native host.
> > * "Bridged" mode: Bridges the vmnet interface with a physical network
> > interface.
> >
> > Each of these modes also provide some extra configuration that’s
> > supported by this patch:
> >
> > * "Bridged" mode: The user may specify the physical interface to bridge
> > with. Defaults to en0.
> > * "Host" mode / "Shared" mode: The user may specify the DHCP range and
> > subnet. Allocated by vmnet if not provided.
> >
> > vmnet also offers some extra configuration options that are not
> > supported by this patch:
> >
> > * Enable isolation from other VMs using vmnet
> > * Port forwarding rules
> > * Enabling TCP segmentation offload
> > * Only applicable in "shared" mode: specifying the NAT IPv6 prefix
> > * Only available in "host" mode: specifying the IP address for the VM
> > within an isolated network
> >
> > Note that this patch requires macOS 10.15 as a minimum, as this is when
> > bridging support was implemented in vmnet.framework.
> >
> > Signed-off-by: Phillip Tennen 
> >
> Hi Phillip,
>
> Thank you very much for this patch. As you wrote it should apply from
> 10.15 upwards. I have no problem building on Big Sur, but Catalina
> stumbles. See below. Latest Xcode installed, other requirements
> installed through brew.
>
> Thanks for looking into this,
>
> Best,
> Howard
>
> [1181/2135] Compiling C object libcommon.fa.p/net_vmnet-macos.c.o
> FAILED: libcommon.fa.p/net_vmnet-macos.c.o
> cc -Ilibcommon.fa.p -I. -I.. -I../capstone/include/capstone
> -I../dtc/libfdt -I../slirp -I../slirp/src -Iqapi -Itrace -Iui
> -Iui/shader -I/usr/local/Cellar/libffi/3.3_2/include
> -I/usr/local/Cellar/glib/2.66.6/include
> -I/usr/local/Cellar/glib/2.66.6/include/glib-2.0
> -I/usr/local/Cellar/glib/2.66.6/lib/glib-2.0/include
> -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.44/include
> -I/usr/local/Cellar/glib/2.66.6/include/gio-unix-2.0
> -I/usr/local/Cellar/libusb/1.0.24/include/libusb-1.0
> -I/usr/local/Cellar/pixman/0.40.0/include/pixman-1 -Xclang
> -fcolor-diagnostics -pipe -Wall -Winvalid-pch -std=gnu99 -O2 -g
> -iquote . -iquote /Users/hsp/src/qemu-master -iquote
> /Users/hsp/src/qemu-master/include -iquote
> /Users/hsp/src/qemu-master/disas/libvixl -iquote
> /Users/hsp/src/qemu-master/tcg/i386 -iquote
> /Users/hsp/src/qemu-master/accel/tcg -m64 -mcx16
> -DOS_OBJECT_USE_OBJC=0 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
> -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef
> -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common
> -fwrapv -Wold-style-definition -Wtype-limits -Wformat-security
> -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body
> -Wnested-externs -Wendif-labels -Wexpansion-to-defined
> -Wno-initializer-overrides -Wno-missing-include-dirs
> -Wno-shift-negative-value -Wno-string-plus-int
> -Wno-typedef-redefinition 

Re: [PATCH v2] net/macos: implement vmnet-based network device

2021-02-10 Thread Howard Spoelstra
On Fri, Feb 5, 2021 at 5:54 PM  wrote:
>
> From: Phillip Tennen 
>
> This patch implements a new netdev device, reachable via -netdev
> vmnet-macos, that’s backed by macOS’s vmnet framework.
>
> The vmnet framework provides native bridging support, and its usage in
> this patch is intended as a replacement for attempts to use a tap device
> via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
> never would have worked in the first place, as QEMU interacts with the
> tap device via poll(), and macOS does not support polling device files.
>
> vmnet requires either a special entitlement, granted via a provisioning
> profile, or root access. Otherwise attempts to create the virtual
> interface will fail with a “generic error” status code. QEMU may not
> currently be signed with an entitlement granted in a provisioning
> profile, as this would necessitate pre-signed binary build distribution,
> rather than source-code distribution. As such, using this netdev
> currently requires that qemu be run with root access. I’ve opened a
> feedback report with Apple to allow the use of the relevant entitlement
> with this use case:
> https://openradar.appspot.com/radar?id=5007417364447232
>
> vmnet offers three operating modes, all of which are supported by this
> patch via the “mode=host|shared|bridge” option:
>
> * "Host" mode: Allows the vmnet interface to communicate with other
> * vmnet
> interfaces that are in host mode and also with the native host.
> * "Shared" mode: Allows traffic originating from the vmnet interface to
> reach the Internet through a NAT. The vmnet interface can also
> communicate with the native host.
> * "Bridged" mode: Bridges the vmnet interface with a physical network
> interface.
>
> Each of these modes also provide some extra configuration that’s
> supported by this patch:
>
> * "Bridged" mode: The user may specify the physical interface to bridge
> with. Defaults to en0.
> * "Host" mode / "Shared" mode: The user may specify the DHCP range and
> subnet. Allocated by vmnet if not provided.
>
> vmnet also offers some extra configuration options that are not
> supported by this patch:
>
> * Enable isolation from other VMs using vmnet
> * Port forwarding rules
> * Enabling TCP segmentation offload
> * Only applicable in "shared" mode: specifying the NAT IPv6 prefix
> * Only available in "host" mode: specifying the IP address for the VM
> within an isolated network
>
> Note that this patch requires macOS 10.15 as a minimum, as this is when
> bridging support was implemented in vmnet.framework.
>
> Signed-off-by: Phillip Tennen 
>
Hi Phillip,

Thank you very much for this patch. As you wrote it should apply from
10.15 upwards. I have no problem building on Big Sur, but Catalina
stumbles. See below. Latest Xcode installed, other requirements
installed through brew.

Thanks for looking into this,

Best,
Howard

[1181/2135] Compiling C object libcommon.fa.p/net_vmnet-macos.c.o
FAILED: libcommon.fa.p/net_vmnet-macos.c.o
cc -Ilibcommon.fa.p -I. -I.. -I../capstone/include/capstone
-I../dtc/libfdt -I../slirp -I../slirp/src -Iqapi -Itrace -Iui
-Iui/shader -I/usr/local/Cellar/libffi/3.3_2/include
-I/usr/local/Cellar/glib/2.66.6/include
-I/usr/local/Cellar/glib/2.66.6/include/glib-2.0
-I/usr/local/Cellar/glib/2.66.6/lib/glib-2.0/include
-I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.44/include
-I/usr/local/Cellar/glib/2.66.6/include/gio-unix-2.0
-I/usr/local/Cellar/libusb/1.0.24/include/libusb-1.0
-I/usr/local/Cellar/pixman/0.40.0/include/pixman-1 -Xclang
-fcolor-diagnostics -pipe -Wall -Winvalid-pch -std=gnu99 -O2 -g
-iquote . -iquote /Users/hsp/src/qemu-master -iquote
/Users/hsp/src/qemu-master/include -iquote
/Users/hsp/src/qemu-master/disas/libvixl -iquote
/Users/hsp/src/qemu-master/tcg/i386 -iquote
/Users/hsp/src/qemu-master/accel/tcg -m64 -mcx16
-DOS_OBJECT_USE_OBJC=0 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
-D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef
-Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common
-fwrapv -Wold-style-definition -Wtype-limits -Wformat-security
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body
-Wnested-externs -Wendif-labels -Wexpansion-to-defined
-Wno-initializer-overrides -Wno-missing-include-dirs
-Wno-shift-negative-value -Wno-string-plus-int
-Wno-typedef-redefinition -Wno-tautological-type-limit-compare
-fstack-protector-strong -DSTRUCT_IOVEC_DEFINED -MD -MQ
libcommon.fa.p/net_vmnet-macos.c.o -MF
libcommon.fa.p/net_vmnet-macos.c.o.d -o
libcommon.fa.p/net_vmnet-macos.c.o -c ../net/vmnet-macos.c
../net/vmnet-macos.c:54:10: error: use of undeclared identifier
'VMNET_SHARING_SERVICE_BUSY'
case VMNET_SHARING_SERVICE_BUSY:
 ^



[PATCH v2] net/macos: implement vmnet-based network device

2021-02-05 Thread phillip . ennen
From: Phillip Tennen 

This patch implements a new netdev device, reachable via -netdev
vmnet-macos, that’s backed by macOS’s vmnet framework.

The vmnet framework provides native bridging support, and its usage in
this patch is intended as a replacement for attempts to use a tap device
via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
never would have worked in the first place, as QEMU interacts with the
tap device via poll(), and macOS does not support polling device files.

vmnet requires either a special entitlement, granted via a provisioning
profile, or root access. Otherwise attempts to create the virtual
interface will fail with a “generic error” status code. QEMU may not
currently be signed with an entitlement granted in a provisioning
profile, as this would necessitate pre-signed binary build distribution,
rather than source-code distribution. As such, using this netdev
currently requires that qemu be run with root access. I’ve opened a
feedback report with Apple to allow the use of the relevant entitlement
with this use case:
https://openradar.appspot.com/radar?id=5007417364447232

vmnet offers three operating modes, all of which are supported by this
patch via the “mode=host|shared|bridge” option:

* "Host" mode: Allows the vmnet interface to communicate with other
* vmnet
interfaces that are in host mode and also with the native host.
* "Shared" mode: Allows traffic originating from the vmnet interface to
reach the Internet through a NAT. The vmnet interface can also
communicate with the native host.
* "Bridged" mode: Bridges the vmnet interface with a physical network
interface.

Each of these modes also provide some extra configuration that’s
supported by this patch:

* "Bridged" mode: The user may specify the physical interface to bridge
with. Defaults to en0.
* "Host" mode / "Shared" mode: The user may specify the DHCP range and
subnet. Allocated by vmnet if not provided.

vmnet also offers some extra configuration options that are not
supported by this patch:

* Enable isolation from other VMs using vmnet
* Port forwarding rules
* Enabling TCP segmentation offload
* Only applicable in "shared" mode: specifying the NAT IPv6 prefix
* Only available in "host" mode: specifying the IP address for the VM
within an isolated network

Note that this patch requires macOS 10.15 as a minimum, as this is when
bridging support was implemented in vmnet.framework.

Signed-off-by: Phillip Tennen 
---
 configure |   2 +-
 net/clients.h |   6 +
 net/meson.build   |   1 +
 net/net.c |   3 +
 net/vmnet-macos.c | 437 ++
 qapi/net.json | 120 -
 qemu-options.hx   |   9 +
 7 files changed, 575 insertions(+), 3 deletions(-)
 create mode 100644 net/vmnet-macos.c

diff --git a/configure b/configure
index 4afd22bdf5..f449198db1 100755
--- a/configure
+++ b/configure
@@ -778,7 +778,7 @@ Darwin)
   fi
   audio_drv_list="coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
-  QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
+  QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit -framework vmnet 
$QEMU_LDFLAGS"
   # Disable attempts to use ObjectiveC features in os/object.h since they
   # won't work when we're compiling with gcc as a C compiler.
   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
diff --git a/net/clients.h b/net/clients.h
index 92f9b59aed..463a9b2f67 100644
--- a/net/clients.h
+++ b/net/clients.h
@@ -63,4 +63,10 @@ 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_DARWIN
+int net_init_vmnet_macos(const Netdev *netdev, const char *name,
+NetClientState *peer, Error **errp);
+#endif
+
 #endif /* QEMU_NET_CLIENTS_H */
diff --git a/net/meson.build b/net/meson.build
index 1076b0a7ab..8c7c32f775 100644
--- a/net/meson.build
+++ b/net/meson.build
@@ -37,5 +37,6 @@ endif
 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'))
+softmmu_ss.add(when: 'CONFIG_DARWIN', if_true: files('vmnet-macos.c'))
 
 subdir('can')
diff --git a/net/net.c b/net/net.c
index c1cd9c75f6..e68a410a89 100644
--- a/net/net.c
+++ b/net/net.c
@@ -977,6 +977,9 @@ static int (* const 
net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
 #ifdef CONFIG_L2TPV3
 [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3,
 #endif
+#ifdef CONFIG_DARWIN
+[NET_CLIENT_DRIVER_VMNET_MACOS] = net_init_vmnet_macos,
+#endif
 };
 
 
diff --git a/net/vmnet-macos.c b/net/vmnet-macos.c
new file mode 100644
index 00..1b713de05c
--- /dev/null
+++ b/net/vmnet-macos.c
@@ -0,0 +1,437 @@
+/*
+ * vmnet.framework backed netdev for macOS 10.15+ hosts
+ *
+ * Copyright (c) 2021 Phillip