Skip to content

Conversation

@norio-nomura
Copy link
Contributor

@norio-nomura norio-nomura commented Nov 22, 2025

feat: add VZVmnetNetworkDeviceAttachment support (macOS 26.0)

VmnetNetworkDeviceAttachment does not require the com.apple.vm.networking entitlement nor root privileges.
HostMode and SharedMode are supported.
In order for multiple VMs to communicate with each other in SharedMode, they must be started in the same process and the same VmnetNetwork must be passed to NewVmnetNetworkDeviceAttachment() to create an attachment.

Add:

  • VmnetReturn:
    • ErrVmnetSuccess
    • ...
  • VmnetMode:
    • HostMode
    • SharedMode
    • BridgedMode(definition only since not supported. marked as deprecated)
  • VmnetNetworkConfiguration: NewVmnetNetworkConfiguration(),  
    The use of the instance method group is still unknown. Setting subnet seems to trigger disabling DHCP, etc.
  • VmnetNetwork: NewVmnetNetwork(), some APIs which using xpc_object_t are not implemented.
  • VmnetNetworkDeviceAttachment: NewVmnetNetworkDeviceAttachment()

see: https://developer.apple.com/documentation/virtualization/vzvmnetnetworkdeviceattachment?language=objc

Which issue(s) this PR fixes:

Mentioned in #198 (comment)

@norio-nomura norio-nomura changed the title feat: add VmnetNetworkDeviceAttachment support (macOS 26.0) feat: add VZVmnetNetworkDeviceAttachment support (macOS 26.0) Nov 22, 2025
@norio-nomura norio-nomura force-pushed the feat-add-vmnet-network-device-attachment branch 2 times, most recently from 6617c8f to 6a1f741 Compare November 22, 2025 12:34
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Nov 22, 2025
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE`
```yaml
networks:
- vzShared: true
- vzHost: true
```
But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process.

It depends on Code-Hex/vz#205

Signed-off-by: Norio Nomura <[email protected]>
const (
HostMode VmnetMode = C.VMNET_HOST_MODE
SharedMode VmnetMode = C.VMNET_SHARED_MODE
// Deprecated: BridgedMode is not supported by NewVmnetNetworkConfiguration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why not supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. It's documented on:
https://developer.apple.com/documentation/vmnet/vmnet_network_configuration_create(_:_:)?language=objc

Parameters
mode
Shared mode or host-only mode.

@nirs
Copy link

nirs commented Nov 24, 2025

This can be used by multiple processes like this:

  1. Start a network process create the vmnet_network_ref, starting a xpc listener
  2. Start vm process, obtaining the vmnet_network_ref from the xpc server
  3. Start more vms using same vmnet_network_ref...
  4. Wait until vms exit
  5. Terminate network process

`VZVmnetNetworkDeviceAttachment` does not require the `com.apple.vm.networking` entitlement nor root privileges.
`HostMode` and `SharedMode` are supported.
In order for multiple VMs to communicate with each other in SharedMode, they must be started in the same process and the same `VmnetNetwork` must be passed to `NewVmnetNetworkDeviceAttachment()` to create an attachment.

Add:
- `VmnetReturn`:
  - `ErrVmnetSuccess`
  - ...
- `VmnetMode`:
  - `HostMode`
  - `SharedMode`
  - `BridgedMode`(definition only since not supported. marked as deprecated)
- `VmnetNetworkConfiguration`: `NewVmnetNetworkConfiguration()`,  
  The use of the instance method group is still unknown. Setting subnet seems to trigger disabling DHCP, etc.
- `VmnetNetwork`: `NewVmnetNetwork()`, some APIs which using `xpc_object_t` are not implemented.
- `VmnetNetworkDeviceAttachment`: `NewVmnetNetworkDeviceAttachment()`

see: https://developer.apple.com/documentation/virtualization/vzvmnetnetworkdeviceattachment?language=objc

change `MACAddress.EthernetAddress()` to `MACAddress.ethernetAddress()`

to avoid export C type from Go

Signed-off-by: Norio Nomura <[email protected]>
Add:
- `TestVmnetSharedModeAllowsCommunicationBetweenMultipleVMs()`
- `Container.DetectIPv4()`

Move `Container.exec()` from `shared_directory_arm64_test.go` to `virtualization_test.go`

Signed-off-by: Norio Nomura <[email protected]>
Signed-off-by: Norio Nomura <[email protected]>
@norio-nomura norio-nomura force-pushed the feat-add-vmnet-network-device-attachment branch from 5a7a116 to 72cc1d4 Compare November 26, 2025 02:58
@norio-nomura
Copy link
Contributor Author

This can be used by multiple processes like this:

In this procedure, I confirmed that VMs launched from multiple processes can share networks with each other. 👍🏻
It seems that it can be reproduced in the unit test, so I will try to make a unit test.

Signed-off-by: Norio Nomura <[email protected]>

Stop using CFTypeRef

Signed-off-by: Norio Nomura <[email protected]>
change `VmnetNetworkConfiguration.SetIPv4Subnet()`

Signed-off-by: Norio Nomura <[email protected]>
@norio-nomura norio-nomura force-pushed the feat-add-vmnet-network-device-attachment branch from 72cc1d4 to 9506cbd Compare December 2, 2025 03:56
@norio-nomura
Copy link
Contributor Author

It seems that it can be reproduced in the unit test, so I will try to make a unit test.

Added unit test and pkg/xpc.

@norio-nomura norio-nomura marked this pull request as draft December 2, 2025 04:01
@norio-nomura
Copy link
Contributor Author

norio-nomura commented Dec 2, 2025

Added unit test and pkg/xpc.

I'll try this added xpc package with lima to make it work. Until then, it's a draft.

@norio-nomura norio-nomura force-pushed the feat-add-vmnet-network-device-attachment branch 5 times, most recently from 7bf24c1 to 007c2a5 Compare December 3, 2025 07:26
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Dec 3, 2025
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE`
```yaml
networks:
- vzShared: true
- vzHost: true
```
But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process.

It depends on Code-Hex/vz#205

Signed-off-by: Norio Nomura <[email protected]>
@norio-nomura norio-nomura force-pushed the feat-add-vmnet-network-device-attachment branch from 007c2a5 to aba95bd Compare December 4, 2025 00:13
- Add `TestVmnetNetworkShareModeSharingOverXpc` to `vmnet_test.go`
`TestVmnetNetworkShareModeSharingOverXpc` tests sharing `VmnetNetwork` in `SharedMode` over XPC communication.
This test registers test executable as an Mach service and launches it using `launchctl`.
The launched Mach service provides `VmnetNetwork` serialization to clients upon request, after booting
a VM using the provided `VmnetNetwork` to ensure the network is functional on the server side.
The client boots VM using the provided `VmnetNetwork` serialization.

This test uses `pkg/xpc` package to implement XPC communication.

- Add `pkg/xpc` package that providing `<xpc/xpc.h>` APIs to support implementing Mach service server and client

Signed-off-by: Norio Nomura <[email protected]>
@norio-nomura norio-nomura force-pushed the feat-add-vmnet-network-device-attachment branch from aba95bd to ba619f5 Compare December 4, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants