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]>
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 5a7a116 to 72cc1d4 Compare November 26, 2025 02:58
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