vmnet

package module
v0.0.0-...-1579d1a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DHCPLease

type DHCPLease struct {
	net.HardwareAddr
	netip.Addr
}

DHCPLease is a lease info of DHCP.

type DNSConfig

type DNSConfig struct {
	// Nameservers are the IP addresses of the nameservers to use.
	// If empty, use values from resolv.conf.
	Nameservers []netip.Addr

	// SearchDomains are the domain suffixes to use when expanding
	// single-label name queries.
	// If empty, use values from resolv.conf.
	SearchDomains []string

	// StaticRecords are the DNS records will be served by the DNS
	// server embedded in the gateway if this value is not empty.
	//
	// If this is not empty, the gateway IP is automatically appended
	// to Nameservers.
	StaticRecords map[string]netip.Addr
}

DNSConfig is a configuration to resolve DNS in the guest OS.

type Gateway

type Gateway struct {
	// contains filtered or unexported fields
}

Gateway is a network gateway.

func (*Gateway) IPv4

func (gw *Gateway) IPv4() net.IP

IPv4 returns IPv4 address.

func (*Gateway) Leases

func (gw *Gateway) Leases() []DHCPLease

Leases returns DHCP leases. If there is a HardwareAddr, it is leased.

func (*Gateway) MACAddress

func (gw *Gateway) MACAddress() net.HardwareAddr

MACAddress returns MAC address.

type LinkDevice

type LinkDevice struct {
	// contains filtered or unexported fields
}

LinkDevice is a link device with vmnet network.

func (*LinkDevice) Close

func (l *LinkDevice) Close() error

Close closes this device and LinkDevice connection.

func (*LinkDevice) File

func (l *LinkDevice) File() *os.File

File returns *os.File for this device.

func (*LinkDevice) IPv4

func (l *LinkDevice) IPv4() net.IP

IPv4 returns ipv4 address that you can use in the guest OS.

func (*LinkDevice) MACAddress

func (l *LinkDevice) MACAddress() net.HardwareAddr

MACAddress returns MAC address.

type LinkDeviceOpts

type LinkDeviceOpts func(*linkDeviceOpts)

LinkDeviceOpts is a optional type for NewLinkDevice.

func WithSendBufferSize

func WithSendBufferSize(bufSize int) LinkDeviceOpts

WithSendBufferSize is an option sets SO_SNDBUF size between ethernet device and guest system. And sets SO_RCVBUF size four times of SO_SNDBUF. the default SO_SNDBUF is 131072.

func WithTCPIncomingForward

func WithTCPIncomingForward(hostPort, guestPort int) LinkDeviceOpts

WithTCPIncomingForward is an option to set TCP forward from host machine to guest machine. For example, if you want to connect from the host machine to the guest machine via ssh, configure as follows:

`WithTCPIncomingForward(8888, 22)` then you can ssh to the guest OS via 127.0.0.1:8888

This option can be applied multiple times.

type Network

type Network struct {
	// contains filtered or unexported fields
}

Network is network for any virtual machines.

func New

func New(cidr string, opts ...NetworkOpts) (*Network, error)

New initializes new network stack with a network gateway. The first IP in the specified cidr range is treated as the gateway IP address.

For example, assume the value specified for cidr is "192.168.127.0/24". The first IP address in this range is "192.168.127.0" and last is "192.168.127.255. These IP addresses are not used for assignment. Because In general the first address is the network identification and the last one is the broadcast. Thus, the first IP address used for assignment here is "192.168.127.1". This is for the Gateway. Subsequent IP addresses will be assigned to the Link Device.

func (*Network) Gateway

func (nt *Network) Gateway() *Gateway

Gateway returns default gateway in this network stack.

func (*Network) NewLinkDevice

func (nt *Network) NewLinkDevice(hwAddr net.HardwareAddr, opts ...LinkDeviceOpts) (*LinkDevice, error)

NewLinkDevice creates a new link device which is connected with vmnet network.

func (*Network) Shutdown

func (nt *Network) Shutdown()

type NetworkOpts

type NetworkOpts func(*networkOpts)

NetworkOpts is functional options.

func WithDNSConfig

func WithDNSConfig(dnsConfig *DNSConfig) NetworkOpts

WithDNSConfig is an option to configure DNS.

Default value will be created from your /etc/resolv.conf file.

func WithGatewayMACAddress

func WithGatewayMACAddress(hwAddr net.HardwareAddr) NetworkOpts

WithGatewayMACAddress is an option to specify the gateway MAC address.

Default is "7a:5b:10:21:90:e3"

func WithLogger

func WithLogger(logger *slog.Logger) NetworkOpts

WithLogger is an option for debug logging which is using the given logger.

Default is nil.

func WithMTU

func WithMTU(mtu uint32) NetworkOpts

WithMTU is an option to set MTU (maximum transmission unit) between the gateway and some link devices.

Default is 1500.

func WithPcapFile

func WithPcapFile(pcapFile *os.File) NetworkOpts

WithPcapFile is an option to create a pcap file based on the given file for writing packet data.

Default is nil.

func WithTCPMaxInFlight

func WithTCPMaxInFlight(maxInFlight int) NetworkOpts

WithTCPMaxInFlight is an option initializes a new TCP forwarder with the given maximum number of in-flight connection attempts. Once the maximum is reached new incoming connection requests will be ignored.

Default is 512.

func WithTCPReceiveBufferSize

func WithTCPReceiveBufferSize(rcvWnd int) NetworkOpts

WithTCPReceiveBufferSize is an option when use initialize a new TCP forwarder with the given buffer size of TCP Recieve window.

Default is 1048576.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL