slirp

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ICMPv6TypeEchoRequest           = 128
	ICMPv6TypeEchoReply             = 129
	ICMPv6TypeRouterSolicitation    = 133
	ICMPv6TypeRouterAdvertisement   = 134
	ICMPv6TypeNeighborSolicitation  = 135
	ICMPv6TypeNeighborAdvertisement = 136
)

ICMPv6 Type codes

Variables

This section is empty.

Functions

func IPChecksum

func IPChecksum(hdr []byte) uint16

Utilities shared by TCP/UDP IPChecksum computes the Internet checksum (RFC 1071) over the given header bytes.

func IPv6Checksum

func IPv6Checksum(src, dst [16]byte, protocol uint8, upperLayerPacketLength uint32, data []byte) uint16

IPv6Checksum calculates the pseudo-header checksum for IPv6 TCP/UDP.

func RandUint32

func RandUint32() uint32

RandUint32 returns a cryptographically random uint32.

func SeqAfter

func SeqAfter(a, b uint32) bool

SeqAfter reports whether TCP sequence number a is after b, handling 32-bit wraparound via signed comparison.

func TCPChecksum

func TCPChecksum(src, dst []byte, tcp []byte, payload []byte) uint16

TCPChecksum computes the TCP checksum including the IPv4 pseudo-header.

func UDPChecksum

func UDPChecksum(src, dst []byte, udp []byte, payload []byte) uint16

UDPChecksum computes the UDP checksum including the IPv4 pseudo-header.

Types

type Listener

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

Listener is a virtual network listener for TCP connections within the slirp stack.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener and aborts any queued but un-accepted connections.

type Listener6

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

Listener6 is a virtual network listener for IPv6 TCP connections within the slirp stack.

func (*Listener6) Accept

func (l *Listener6) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener6) Addr

func (l *Listener6) Addr() net.Addr

Addr returns the listener's network address.

func (*Listener6) Close

func (l *Listener6) Close() error

Close closes the listener and aborts any queued but un-accepted connections.

type Stack

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

Stack is a NAT/routing stack that implements pktkit.L3Device. Packets received via Send are routed to real network connections (NAT) or to virtual listeners. Responses are sent via the handler set with SetHandler.

For multi-tenant use, call Stack.ConnectL3 to create namespace-isolated inside L3Devices. Each namespace's connections are tracked independently, allowing overlapping inside IPs.

func New

func New() *Stack

func (*Stack) Addr

func (s *Stack) Addr() netip.Prefix

Addr returns the stack's configured IP prefix.

func (*Stack) Close

func (s *Stack) Close() error

Close shuts down the stack, stopping the maintenance goroutine and closing all active connections.

func (*Stack) ConnectL3

func (s *Stack) ConnectL3(dev pktkit.L3Device) (func() error, error)

ConnectL3 implements pktkit.L3Connector. It creates a namespace-isolated L3Device on this stack. Packets from the device are tracked with a unique namespace ID, so multiple devices can use overlapping IPs without conflict.

func (*Stack) Listen

func (s *Stack) Listen(network, address string) (net.Listener, error)

Listen announces on the virtual network address. The network must be "tcp", "tcp4", or "tcp6". The address is the virtual IP:port to listen on within the slirp stack.

func (*Stack) Send

func (s *Stack) Send(pkt pktkit.Packet) error

Send delivers an IP packet to the stack for processing. Implements pktkit.L3Device.

func (*Stack) SetAddr

func (s *Stack) SetAddr(p netip.Prefix) error

SetAddr configures the stack's IP prefix.

func (*Stack) SetHandler

func (s *Stack) SetHandler(h func(pktkit.Packet) error)

SetHandler sets the callback for packets produced by this stack.

Jump to

Keyboard shortcuts

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