Documentation
¶
Index ¶
- Constants
- Variables
- func ReleaseOnCleanup[O interface{ ... }](o O) O
- func Retain[O interface{ ... }](o O) O
- type Interface
- type Mode
- type Network
- type NetworkConfiguration
- func (c *NetworkConfiguration) AddDhcpReservation(client net.HardwareAddr, reservation netip.Addr) error
- func (c *NetworkConfiguration) AddPortForwardingRule(protocol uint8, addressFamily uint8, internalPort uint16, externalPort uint16, ...) error
- func (c *NetworkConfiguration) DisableDhcp()
- func (c *NetworkConfiguration) DisableDnsProxy()
- func (c *NetworkConfiguration) DisableNat44()
- func (c *NetworkConfiguration) DisableNat66()
- func (c *NetworkConfiguration) DisableRouterAdvertisement()
- func (c *NetworkConfiguration) SetExternalInterface(ifname string) error
- func (c *NetworkConfiguration) SetIPv4Subnet(subnet netip.Prefix) error
- func (c *NetworkConfiguration) SetIPv6Prefix(prefix netip.Prefix) error
- func (c *NetworkConfiguration) SetMtu(mtu uint32) error
- type PacketsAvailableEventCallback
- type PktDescsManager
- func (v *PktDescsManager) At(index int) *VMPktDesc
- func (v *PktDescsManager) MaxPacketCount() int
- func (v *PktDescsManager) ReadPacketsFromConn(conn net.Conn) (int, error)
- func (v *PktDescsManager) ReadPacketsFromPacketConn(conn net.PacketConn) (int, error)
- func (v *PktDescsManager) Reset()
- func (v *PktDescsManager) WritePacketsToConn(conn net.Conn, packetCount, receiveBufferSize int) error
- func (v *PktDescsManager) WritePacketsToPacketConn(conn net.PacketConn, packetCount int) error
- type Return
- type VMPktDesc
Constants ¶
const VirtioNetHdrSize = 12 // Size of virtio_net_hdr_v1
Variables ¶
var ( // AllocateMacAddressKey represents [vmnet_allocate_mac_address_key]. // - Allocate a MAC address for the VM to use (bool). Default value is true. // - If set to false, no MAC address will be generated. // - Can be used in the interface describing dictionary passed to [StartInterfaceWithNetwork] to request automatic MAC address allocation. // - See <vmnet/vmnet.h> for details. // // [vmnet_allocate_mac_address_key]: https://developer.apple.com/documentation/vmnet/vmnet_allocate_mac_address_key?language=objc AllocateMacAddressKey = C.GoString(C.vmnet_allocate_mac_address_key) // EnableChecksumOffloadKey represents [vmnet_enable_checksum_offload_key]. // - Can be used in the interface describing dictionary passed to [StartInterfaceWithNetwork] to enable checksum offloading. // - See <vmnet/vmnet.h> for details. // // [vmnet_enable_checksum_offload_key]: https://developer.apple.com/documentation/vmnet/vmnet_enable_checksum_offload_key?language=objc EnableChecksumOffloadKey = C.GoString(C.vmnet_enable_checksum_offload_key) // EnableIsolationKey represents [vmnet_enable_isolation_key]. // - Can be used in the interface describing dictionary passed to [StartInterfaceWithNetwork] to enable isolation. // - See <vmnet/vmnet.h> for details. // // [vmnet_enable_isolation_key]: https://developer.apple.com/documentation/vmnet/vmnet_enable_isolation_key?language=objc EnableIsolationKey = C.GoString(C.vmnet_enable_isolation_key) // EnableTSOKey represents [vmnet_enable_tso_key]. // - Can be used in the interface describing dictionary passed to [StartInterfaceWithNetwork] to enable TCP Segmentation Offloading (TSO). // - See <vmnet/vmnet.h> for details. // // [vmnet_enable_tso_key]: https://developer.apple.com/documentation/vmnet/vmnet_enable_tso_key?language=objc EnableTSOKey = C.GoString(C.vmnet_enable_tso_key) // EnableVirtioHeaderKey represents [vmnet_enable_virtio_header_key]. // - Can be used in the interface describing dictionary passed to [StartInterfaceWithNetwork] to enable Virtio header support. // - See <vmnet/vmnet.h> for details. // - Requires macOS 15.4 or newer SDK. On older SDKs, [StartInterfaceWithNetwork] will return an error if this key is used. // // [vmnet_enable_virtio_header_key]: https://developer.apple.com/documentation/vmnet/vmnet_enable_virtio_header_key-swift.var?language=objc EnableVirtioHeaderKey = func() string { if cs := C.wrap_vmnet_enable_virtio_header_key(); cs != nil { return C.GoString(cs) } return EnableVirtioHeaderKeyUnavailableError }() )
Keys for interface describing parameters dictionary.
Functions ¶
func ReleaseOnCleanup ¶
func ReleaseOnCleanup[O interface{ releaseOnCleanup() }](o O) O
ReleaseOnCleanup calls releaseOnCleanup method on the given object and returns it.
Types ¶
type Interface ¶
type Interface struct {
Param *xpc.Dictionary
MaxPacketSize uint64
MaxReadPacketCount int
MaxWritePacketCount int
// Interface Describing Parameters on starting the interface.
AllocateMacAddress bool
EnableChecksumOffload bool
EnableIsolation bool
EnableTSO bool
EnableVirtioHeader bool
// contains filtered or unexported fields
}
Interface represents a interface_ref in vmnet.
func StartInterfaceWithNetwork ¶
func StartInterfaceWithNetwork(network *Network, interfaceDesc *xpc.Dictionary) (*Interface, error)
StartInterfaceWithNetwork starts an Interface with the given Network and interface describing parameter.
- If Network is created in another process and passed via serialization, the process's executable must be the same as the one which created the Network. If not, the API call causes SIGTRAP with API Misuse.
- The condition that the executable is the same is checked by: (<macOS 26.2) the CDHash of the executable is the same? (macOS 26.2) the path of the executable is the same?
- https://developer.apple.com/documentation/vmnet/vmnet_interface_start_with_network(_:_:_:_:)?language=objc
- interfaceDesc is a dictionary of interface describing parameters. Allowed keys are: AllocateMacAddressKey, EnableChecksumOffloadKey, EnableIsolationKey, EnableTSOKey, EnableVirtioHeaderKey//
func (*Interface) ReadPackets ¶
ReadPackets reads packets from the Interface into VMPktDesc array. It returns the number of packets read.
func (*Interface) SetPacketsAvailableEventCallback ¶
func (i *Interface) SetPacketsAvailableEventCallback(callback PacketsAvailableEventCallback) error
SetPacketsAvailableEventCallback sets the packets available event callback for the Interface.
- https://developer.apple.com/documentation/vmnet/vmnet_interface_set_event_callback(_:_:_:_:)?language=objc
- https://developer.apple.com/documentation/vmnet/vmnet_interface_event_callback_t?language=objc
- https://developer.apple.com/documentation/vmnet/interface_event_t/vmnet_interface_packets_available?language=objc
- https://developer.apple.com/documentation/vmnet/vmnet_estimated_packets_available_key?language=objc
func (*Interface) WritePackets ¶
WritePackets writes packets to the Interface from VMPktDesc array.
- Partial write won't happen, either all packets are written or an error is returned.
- https://developer.apple.com/documentation/vmnet/vmnet_write(_:_:_:)?language=objc
type Mode ¶
type Mode uint32
Mode defines the mode of a Network. (See operating_modes_t)
- HostMode and SharedMode are supported by NewNetworkConfiguration.
- VMNET_BRIDGED_MODE is not supported by underlying API vmnet_network_configuration_create.
const ( // https://developer.apple.com/documentation/vmnet/operating_modes_t/vmnet_host_mode?language=objc HostMode Mode = C.VMNET_HOST_MODE SharedMode Mode = C.VMNET_SHARED_MODE )
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network represents a vmnet_network_ref.
func NewNetwork ¶
func NewNetwork(config *NetworkConfiguration) (*Network, error)
NewNetwork creates a new Network with NetworkConfiguration. This is only supported on macOS 26 and newer, error will be returned on older versions.
func NewNetworkFromPointer ¶
NewNetworkFromPointer creates a new Network from an existing objc.Pointer.
func NewNetworkWithSerialization ¶
NewNetworkWithSerialization creates a new Network from a serialized representation. This is only supported on macOS 26 and newer, error will be returned on older versions.
func (*Network) CopySerialization ¶
CopySerialization returns a serialized copy of Network in xpc_object_t as xpc.Object.
func (*Network) IPv4Subnet ¶
IPv4Subnet returns the IPv4 subnet of the Network.
func (*Network) IPv6Prefix ¶
IPv6Prefix returns the IPv6 prefix of the Network.
type NetworkConfiguration ¶
type NetworkConfiguration struct {
// contains filtered or unexported fields
}
NetworkConfiguration represents a vmnet_network_configuration_ref.
func NewNetworkConfiguration ¶
func NewNetworkConfiguration(mode Mode) (*NetworkConfiguration, error)
NewNetworkConfiguration creates a new NetworkConfiguration with Mode. This is only supported on macOS 26 and newer, error will be returned on older versions. [BridgedMode] is not supported by this function.
func (*NetworkConfiguration) AddDhcpReservation ¶
func (c *NetworkConfiguration) AddDhcpReservation(client net.HardwareAddr, reservation netip.Addr) error
AddDhcpReservation configures a new DHCP reservation for the Network. client is the MAC address for which the DHCP address is reserved. reservation is the DHCP IPv4 address to be reserved.
func (*NetworkConfiguration) AddPortForwardingRule ¶
func (c *NetworkConfiguration) AddPortForwardingRule(protocol uint8, addressFamily uint8, internalPort uint16, externalPort uint16, internalAddress netip.Addr) error
AddPortForwardingRule configures a port forwarding rule for the Network. These rules will not be able to be removed or queried until network has been started. To do that, use `vmnet_interface_remove_ip_forwarding_rule` or `vmnet_interface_get_ip_port_forwarding_rules` C API directly. (`vmnet_interface` related functionality not implemented in this package yet)
protocol must be either IPPROTO_TCP or IPPROTO_UDP addressFamily must be either AF_INET or AF_INET6 internalPort is the TCP or UDP port that forwarded traffic should be redirected to. externalPort is the TCP or UDP port on the outside network that should be redirected from. internalAddress is the IPv4 or IPv6 address of the machine on the internal network that should receive the forwarded traffic.
func (*NetworkConfiguration) DisableDhcp ¶
func (c *NetworkConfiguration) DisableDhcp()
DisableDhcp disables DHCP server on the Network.
func (*NetworkConfiguration) DisableDnsProxy ¶
func (c *NetworkConfiguration) DisableDnsProxy()
DisableDnsProxy disables DNS proxy on the Network.
func (*NetworkConfiguration) DisableNat44 ¶
func (c *NetworkConfiguration) DisableNat44()
DisableNat44 disables NAT44 on the Network.
func (*NetworkConfiguration) DisableNat66 ¶
func (c *NetworkConfiguration) DisableNat66()
DisableNat66 disables NAT66 on the Network.
func (*NetworkConfiguration) DisableRouterAdvertisement ¶
func (c *NetworkConfiguration) DisableRouterAdvertisement()
DisableRouterAdvertisement disables router advertisement on the Network.
func (*NetworkConfiguration) SetExternalInterface ¶
func (c *NetworkConfiguration) SetExternalInterface(ifname string) error
SetExternalInterface sets the external interface of the Network. This is only available to networks of SharedMode.
func (*NetworkConfiguration) SetIPv4Subnet ¶
func (c *NetworkConfiguration) SetIPv4Subnet(subnet netip.Prefix) error
SetIPv4Subnet configures the IPv4 address for the Network. Note that the first, second, and last addresses of the range are reserved. The second address is reserved for the host, the first and last are not assignable to any node.
func (*NetworkConfiguration) SetIPv6Prefix ¶
func (c *NetworkConfiguration) SetIPv6Prefix(prefix netip.Prefix) error
SetIPv6Prefix configures the IPv6 prefix for the Network.
type PacketsAvailableEventCallback ¶
type PacketsAvailableEventCallback func(estimatedCount int)
PacketsAvailableEventCallback is a callback function type for packets available event.
type PktDescsManager ¶
type PktDescsManager struct {
PktDescs *VMPktDesc
// contains filtered or unexported fields
}
PktDescsManager manages pktDescs and their backing buffers.
func NewPktDescsManager ¶
func NewPktDescsManager(count int, maxPacketSize uint64) *PktDescsManager
NewPktDescsManager allocates pktDesc array and backing buffers. pktDesc's iov_base points to the buffer after 4-byte header. The 4-byte header is reserved for packet size to the connection.
func (*PktDescsManager) At ¶
func (v *PktDescsManager) At(index int) *VMPktDesc
at returns the pointer to the pktDesc at the given index.
func (*PktDescsManager) MaxPacketCount ¶
func (v *PktDescsManager) MaxPacketCount() int
maxPacketCount returns the maximum number of pktDescs managed.
func (*PktDescsManager) ReadPacketsFromConn ¶
func (v *PktDescsManager) ReadPacketsFromConn(conn net.Conn) (int, error)
ReadPacketsFromConn reads packets from the net.Conn into [VMPktDesc]s.
- It returns the number of packets read.
- The packets are expected to come one by one with 4-byte big-endian header indicating the packet size.
- It reads all available packets until no more packets are available, packetCount reaches maxPacketCount, or an error occurs.
- It waits for the connection to be ready for initial read of 4-byte header.
func (*PktDescsManager) ReadPacketsFromPacketConn ¶
func (v *PktDescsManager) ReadPacketsFromPacketConn(conn net.PacketConn) (int, error)
ReadPacketsFromPacketConn reads packets from the net.PacketConn into [VMPktDesc]s.
- It returns the number of packets read.
- The packets are expected to come one by one.
- It receives all available packets until no more packets are available, packetCount reaches maxPacketCount, or an error occurs.
- It waits for the connection to be ready for initial packet.
func (*PktDescsManager) Reset ¶
func (v *PktDescsManager) Reset()
Reset resets pktDescs to initial state.
func (*PktDescsManager) WritePacketsToConn ¶
func (v *PktDescsManager) WritePacketsToConn(conn net.Conn, packetCount, receiveBufferSize int) error
WritePacketsToConn writes packets from [VMPktDesc]s to the net.Conn.
- It returns the number of bytes written.
func (*PktDescsManager) WritePacketsToPacketConn ¶
func (v *PktDescsManager) WritePacketsToPacketConn(conn net.PacketConn, packetCount int) error
WritePacketsToPacketConn writes packets from [VMPktDesc]s to the net.PacketConn.
- It returns an error if any occurs during sending packets.
type Return ¶
The status code returning the result of vmnet operations.
const ( ErrSuccess Return = C.VMNET_SUCCESS // VMNET_SUCCESS Successfully completed. ErrFailure Return = C.VMNET_FAILURE // VMNET_FAILURE General failure. ErrMemFailure Return = C.VMNET_MEM_FAILURE // VMNET_MEM_FAILURE Memory allocation failure. ErrInvalidArgument Return = C.VMNET_INVALID_ARGUMENT // VMNET_INVALID_ARGUMENT Invalid argument specified. ErrSetupIncomplete Return = C.VMNET_SETUP_INCOMPLETE // VMNET_SETUP_INCOMPLETE Interface setup is not complete. ErrInvalidAccess Return = C.VMNET_INVALID_ACCESS // VMNET_INVALID_ACCESS Permission denied. ErrPacketTooBig Return = C.VMNET_PACKET_TOO_BIG // VMNET_PACKET_TOO_BIG Packet size larger than MTU. ErrBufferExhausted Return = C.VMNET_BUFFER_EXHAUSTED // VMNET_BUFFER_EXHAUSTED Buffers exhausted in kernel. ErrTooManyPackets Return = C.VMNET_TOO_MANY_PACKETS // VMNET_TOO_MANY_PACKETS Packet count exceeds limit. ErrSharingServiceBusy Return = C.VMNET_SHARING_SERVICE_BUSY // VMNET_SHARING_SERVICE_BUSY Vmnet Interface cannot be started as conflicting sharing service is in use. ErrNotAuthorized Return = C.VMNET_NOT_AUTHORIZED // VMNET_NOT_AUTHORIZED The operation could not be completed due to missing authorization. )
type VMPktDesc ¶
type VMPktDesc C.struct_vmpktdesc
VMPktDesc is a Go representation of C.struct_vmpktdesc.
func (*VMPktDesc) GetPacketSize ¶
GetPacketSize gets the packet size from VMPktDesc.
func (*VMPktDesc) GetVmPktIov ¶
GetVmPktIov returns the vm_pkt_iov pointer in VMPktDesc.
func (*VMPktDesc) SetPacketSize ¶
SetPacketSize sets the packet size in VMPktDesc.