netstackvm

package
v0.0.0-...-9a26220 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const TUN_MTU = 1420

TUN_MTU is the default MTU for TUN device. 1420 is wg default MTU, use it for compatibility.

View Source
const UTUNINDEXSTART = 410

Variables

This section is empty.

Functions

func NewPCAPAdaptor

func NewPCAPAdaptor(ifaceName string, promisc bool) (*pcapAdaptor, error)

NewPCAPAdaptor creates a new pcap adaptor for the given interface. It reuses existing adaptors if one already exists for the interface.

Types

type Config

type Config struct {

	// stack options
	IPv4Disabled                bool
	IPv6Disabled                bool
	DHCPDisabled                bool
	ARPDisabled                 bool
	ICMPDisabled                bool
	HandleLocal                 bool
	TCPDisabled                 bool
	UDPDisabled                 bool
	DisallowPacketEndpointWrite bool
	EnableLinkLayer             bool
	OnTCPConnectionRequested    func(*tcpip.FullAddress, *tcpip.FullAddress)
	DisableForwarding           bool

	//dhcp config
	DHCPAcquireTimeout       time.Duration
	DHCPAcquireInterval      time.Duration
	DHCPAcquireRetryInterval time.Duration
	DHCPAcquireCallback      func(ctx context.Context, lost, acquired tcpip.AddressWithPrefix, cfg gvisorDHCP.Config)

	//arp config
	ARPAnnouncementFastInterval time.Duration
	ARPAnnouncementFastTimes    int
	ARPAnnouncementSlowInterval time.Duration

	// nic options
	MainNICIPv4Address        string
	MainNICIPv4AddressNetmask string

	MainNICIPv6Address        string
	MainNICIPv6AddressNetmask string
	MainNICLinkAddress        net.HardwareAddr

	// tcp options
	// DefaultTTL specifies the default TTL used by stack
	DefaultTTL uint8
	// ICMPBurst is the number of ICMP messages that can be sent in a single burst
	ICMPBurst int
	// ICMPLimit is the maximum number of ICMP messages permitted by rate limiter
	ICMPLimit rate.Limit
	// TCPSendBufferSizeMin is the smallest size of a send buffer
	TCPSendBufferSizeMin int
	// TCPSendBufferSizeMax is the maximum permitted size of a send buffer
	TCPSendBufferSizeMax int
	// TCPSendBufferSizeDefault is the default size of the send buffer
	TCPSendBufferSizeDefault int
	// TCPReceiveBufferSizeMin is the smallest size of a receive buffer
	TCPReceiveBufferSizeMin int
	// TCPReceiveBufferSizeMax is the maximum permitted size of a receive buffer
	TCPReceiveBufferSizeMax int
	// TCPReceiveBufferSizeDefault is the default size of the receive buffer
	TCPReceiveBufferSizeDefault int
	// TCPCongestionControl is the congestion control algorithm used by TCP (reno or cubic)
	TCPCongestionControl string
	// TCPDelayEnabled enables/disables Nagle's algorithm for TCP
	TCPDelayEnabled bool
	// TCPModerateReceiveBuffer enables/disables TCP receive buffer auto-tuning
	TCPModerateReceiveBuffer bool
	// TCPSACKEnabled enables/disables TCP selective acknowledgment
	TCPSACKEnabled bool
	// TCPRACKLossDetection specifies the TCP loss detection algorithm
	TCPRACKLossDetection tcpip.TCPRecovery
	// contains filtered or unexported fields
}

func NewDefaultConfig

func NewDefaultConfig() *Config

type NIC

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

type NetStackVirtualMachine

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

func NewNetStackVirtualMachine

func NewNetStackVirtualMachine(opts ...Option) (*NetStackVirtualMachine, error)

func (*NetStackVirtualMachine) AllowTCP

func (vm *NetStackVirtualMachine) AllowTCP(destinationAddr string)

func (*NetStackVirtualMachine) AllowTCPWithSrc

func (vm *NetStackVirtualMachine) AllowTCPWithSrc(destinationAddr string, srcAddr string)

func (*NetStackVirtualMachine) DialTCP

func (vm *NetStackVirtualMachine) DialTCP(timeout time.Duration, hostport string) (net.Conn, error)

func (*NetStackVirtualMachine) DisallowTCP

func (vm *NetStackVirtualMachine) DisallowTCP(destinationAddr string)

func (*NetStackVirtualMachine) DisallowTCPWithSrc

func (vm *NetStackVirtualMachine) DisallowTCPWithSrc(destinationAddr string, srcAddr string)

func (*NetStackVirtualMachine) GetMTU

func (vm *NetStackVirtualMachine) GetMTU() int

func (*NetStackVirtualMachine) GetMainNICIPv4Address

func (vm *NetStackVirtualMachine) GetMainNICIPv4Address() net.IP

func (*NetStackVirtualMachine) GetMainNICIPv4Gateway

func (vm *NetStackVirtualMachine) GetMainNICIPv4Gateway() net.IP

func (*NetStackVirtualMachine) GetMainNICIPv4Netmask

func (vm *NetStackVirtualMachine) GetMainNICIPv4Netmask() *net.IPNet

func (*NetStackVirtualMachine) GetMainNICLinkAddress

func (vm *NetStackVirtualMachine) GetMainNICLinkAddress() net.HardwareAddr

func (*NetStackVirtualMachine) GetOSNetStackIPv4

func (vm *NetStackVirtualMachine) GetOSNetStackIPv4() (net.IP, net.IP, net.IPMask)

func (*NetStackVirtualMachine) GetOSNetStackIPv6

func (vm *NetStackVirtualMachine) GetOSNetStackIPv6() (net.IP, net.IP, net.IPMask)

func (*NetStackVirtualMachine) GetStack

func (vm *NetStackVirtualMachine) GetStack() *stack.Stack

func (*NetStackVirtualMachine) GetSystemInterface

func (vm *NetStackVirtualMachine) GetSystemInterface() *net.Interface

func (*NetStackVirtualMachine) InheritPcapInterfaceIP

func (vm *NetStackVirtualMachine) InheritPcapInterfaceIP() error

func (*NetStackVirtualMachine) MainNICID

func (vm *NetStackVirtualMachine) MainNICID() tcpip.NICID

func (*NetStackVirtualMachine) SetDefaultRoute

func (vm *NetStackVirtualMachine) SetDefaultRoute(gateway net.IP) error

func (*NetStackVirtualMachine) SetFilterForSynScan

func (vm *NetStackVirtualMachine) SetFilterForSynScan()

func (*NetStackVirtualMachine) SetMainNICv4

func (vm *NetStackVirtualMachine) SetMainNICv4(ipAddr net.IP, netmask *net.IPNet, getaway net.IP) error

func (*NetStackVirtualMachine) StartAnnounceARP

func (m *NetStackVirtualMachine) StartAnnounceARP() error

func (*NetStackVirtualMachine) StartDHCP

func (vm *NetStackVirtualMachine) StartDHCP() error

func (*NetStackVirtualMachine) Wait

func (vm *NetStackVirtualMachine) Wait()

func (*NetStackVirtualMachine) WaitDHCPFinished

func (t *NetStackVirtualMachine) WaitDHCPFinished(ctx context.Context) error

type Option

type Option func(*Config) error

func WithARPDisabled

func WithARPDisabled(disabled bool) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithDHCPDisabled

func WithDHCPDisabled(disabled bool) Option

func WithDisableForwarding

func WithDisableForwarding(v bool) Option

func WithDisallowPacketEndpointWrite

func WithDisallowPacketEndpointWrite(disallow bool) Option

func WithEnableLinkLayer

func WithEnableLinkLayer(enable bool) Option

func WithHandleLocal

func WithHandleLocal(handleLocal bool) Option

func WithICMPDisabled

func WithICMPDisabled(disabled bool) Option

func WithIPv4Disabled

func WithIPv4Disabled(disabled bool) Option

func WithIPv6Disabled

func WithIPv6Disabled(disabled bool) Option

func WithMainNICIPAddress

func WithMainNICIPAddress(ipAddress string) Option

func WithMainNICLinkAddress

func WithMainNICLinkAddress(linkAddress string) Option

func WithOnTCPConnectionRequested

func WithOnTCPConnectionRequested(fn func(*tcpip.FullAddress, *tcpip.FullAddress)) Option

func WithPCAPInboundFilter

func WithPCAPInboundFilter(filter func(packet gopacket.Packet) bool) Option

func WithPCAPOutboundFilter

func WithPCAPOutboundFilter(filter func(packet gopacket.Packet) bool) Option

func WithPcapDevice

func WithPcapDevice(device string) Option

func WithPcapPromisc

func WithPcapPromisc(promisc bool) Option

func WithRandomMainNICLinkAddress

func WithRandomMainNICLinkAddress() Option

func WithTCPDisabled

func WithTCPDisabled(disabled bool) Option

func WithUDPDisabled

func WithUDPDisabled(disabled bool) Option

type PCAPEndpoint

type PCAPEndpoint struct {
	*channel.Endpoint
	// contains filtered or unexported fields
}

func NewPCAPEndpoint

func NewPCAPEndpoint(ctx context.Context, stackIns *stack.Stack, device string, macAddr net.HardwareAddr, promisc bool) (*PCAPEndpoint, error)

func (*PCAPEndpoint) AllowTCP

func (p *PCAPEndpoint) AllowTCP(addr string)

func (*PCAPEndpoint) AllowTCPWithSrc

func (p *PCAPEndpoint) AllowTCPWithSrc(addr string, src string)

func (*PCAPEndpoint) Attach

func (p *PCAPEndpoint) Attach(dispatcher stack.NetworkDispatcher)

func (*PCAPEndpoint) Capabilities

func (p *PCAPEndpoint) Capabilities() stack.LinkEndpointCapabilities

func (*PCAPEndpoint) Close

func (p *PCAPEndpoint) Close()

func (*PCAPEndpoint) DisallowTCP

func (p *PCAPEndpoint) DisallowTCP(addr string)

func (*PCAPEndpoint) DisallowTCPWithSrc

func (p *PCAPEndpoint) DisallowTCPWithSrc(addr string, src string)

func (*PCAPEndpoint) SetGatewayHardwareAddr

func (p *PCAPEndpoint) SetGatewayHardwareAddr(hwAddr net.HardwareAddr)

func (*PCAPEndpoint) SetGatewayIP

func (p *PCAPEndpoint) SetGatewayIP(g net.IP)

func (*PCAPEndpoint) SetPCAPInboundFilter

func (p *PCAPEndpoint) SetPCAPInboundFilter(filter func(packet gopacket.Packet) bool)

func (*PCAPEndpoint) SetPCAPOutboundFilter

func (p *PCAPEndpoint) SetPCAPOutboundFilter(filter func(packet gopacket.Packet) bool)

func (*PCAPEndpoint) Wait

func (p *PCAPEndpoint) Wait()

type TunVirtualMachine

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

func NewTunVirtualMachine

func NewTunVirtualMachine(ctx context.Context) (*TunVirtualMachine, error)

func (*TunVirtualMachine) Close

func (t *TunVirtualMachine) Close() error

func (*TunVirtualMachine) GetTunnelName

func (t *TunVirtualMachine) GetTunnelName() string

func (*TunVirtualMachine) HijackDomain

func (vm *TunVirtualMachine) HijackDomain(domain string) error

func (*TunVirtualMachine) HijackIP

func (vm *TunVirtualMachine) HijackIP(ip string) error

func (*TunVirtualMachine) HijackIPNet

func (vm *TunVirtualMachine) HijackIPNet(ipNet *net.IPNet) error

func (*TunVirtualMachine) SetHijackTCPHandler

func (t *TunVirtualMachine) SetHijackTCPHandler(handle func(conn netstack.TCPConn)) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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