Add VZVmnetNetworkDeviceAttachment (macOS 26+)#218
Open
lixin9311 wants to merge 1 commit into
Open
Conversation
c943cab to
afba220
Compare
Wraps the new VZVmnetNetworkDeviceAttachment class added in macOS 26
and exposes the underlying vmnet_network configuration surface as a
new `vmnet` subpackage so callers can drive vmnet_network_create
with mode, IPv4 subnet, and DHCP reservations.
package vmnet (new):
type Mode int
const (
HostMode Mode = 1000
SharedMode Mode = 1001
BridgedMode Mode = 1002
)
type NetworkConfiguration struct { *objc.Pointer }
func NewNetworkConfiguration(mode Mode) (*NetworkConfiguration, error)
func (*NetworkConfiguration) SetIPv4Subnet(netip.Prefix) error
func (*NetworkConfiguration) AddDhcpReservation(net.HardwareAddr, netip.Addr) error
type Network struct { *objc.Pointer }
func NewNetwork(config *NetworkConfiguration) (*Network, error)
func NewNetworkFromPointer(*objc.Pointer) *Network
package vz (additions in network.go):
type VmnetNetworkDeviceAttachment struct {
*pointer
*baseNetworkDeviceAttachment
}
func (*VmnetNetworkDeviceAttachment) String() string
func (*VmnetNetworkDeviceAttachment) Network() *vmnet.Network
func NewVmnetNetworkDeviceAttachment(*vmnet.Network) (*VmnetNetworkDeviceAttachment, error)
NetworkConfiguration.SetIPv4Subnet normalizes its netip.Prefix
argument to the gateway IP (first host of the network) before
calling vmnet_network_configuration_set_ipv4_subnet. Apple's docs
call that parameter "subnet_addr" but the actual semantic —
confirmed via vmnet_network_get_ipv4_subnet round-trip — is the
gateway IP, matching the older `vmnet_start_address_key` XPC key.
VZVmnetNetworkDeviceAttachment.network is a C-typed
`@property (readonly) vmnet_network_ref`. ObjC properties for
non-NSObject C types default to `assign` semantics, so the
attachment does not retain. Lifecycle:
- vmnet_network_create returns +1 retained — owned by the Go
*vmnet.Network wrapper, which CFReleases on GC finalize.
- The VZ attachment stores the same pointer without retaining;
callers must keep the *vmnet.Network alive while the attachment
is in use (it's stored on the VirtualMachineConfiguration, so
the typical orchestration code keeps it reachable).
- Network() reads VZ's stored pointer, CFRetain's it, and returns
a fresh *vmnet.Network wrapper that owns its own refcount.
SDK compile-time guard via the existing INCLUDE_TARGET_OSX_26 macro
in virtualization_helper.h; runtime guard via @available(macOS 26,
*) in the Obj-C wrappers; macOS-version + build-target guards on
the Go side via the existing osversion helpers.
Header dependency note: VZVmnetNetworkDeviceAttachment.h references
`vmnet_network_ref` via a @Property, so every compilation unit that
ends up pulling Virtualization.h needs <vmnet/vmnet.h> in scope
first. Added the include to virtualization_helper.h (imported by
every per-version header).
afba220 to
20274db
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Wraps the new
VZVmnetNetworkDeviceAttachmentclass added to Virtualization.framework in macOS 26.This is a simplified version of #205. This PR does not try to provide a full
vmnetpackage ambitiously.The goal is simple, we want to solve the weirdness of Apple's DHCP server and pin my VM with a stable static IP.
More features of vmnet should be added progressively.