connection

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Splice

func Splice(tunDev tun.Device, conn Connection, opts ...SpliceOption) error

Splice starts the TUN <-> Connection splice operation.

Types

type Connection

type Connection interface {
	io.Closer

	String() string

	ReadPacket([]byte) (int, error)
	WritePacket([]byte) ([]byte, error)
}

Connection is a simple interface implemented by connect-ip-go and custom connection types.

type Device

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

func NewDevice

func NewDevice(conn *connectip.Conn) *Device

func (*Device) Close

func (d *Device) Close() error

func (*Device) MTU

func (d *Device) MTU() (int, error)

func (*Device) Name

func (d *Device) Name() string

func (*Device) NewPacketQueue

func (d *Device) NewPacketQueue() (fasttun.PacketQueue, error)

type Direction

type Direction uint8

Direction indicates whether a packet is inbound or outbound.

const (
	DirectionOutbound Direction = iota // TUN → Remote
	DirectionInbound                   // Remote → TUN
)

func (Direction) String

func (d Direction) String() string

type DstMuxedConn

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

DstMuxedConn implements Connection that multiplexes multiple Connections based on the destination IP of the IPv4/v6 packet.

func NewDstMuxedConn

func NewDstMuxedConn() *DstMuxedConn

NewDstMuxedConn creates a new DstMuxedConn instance.

func (*DstMuxedConn) Add

func (m *DstMuxedConn) Add(addr netip.Prefix, conn Connection) error

Add adds a new connection to the multiplexer.

The connection is wrapped in an asyncSendConn so that a slow or backpressured underlying connection cannot stall writes destined for its siblings via the shared splice goroutine (see async_send.go). Reads flow through the embedded Connection unchanged.

func (*DstMuxedConn) Close

func (m *DstMuxedConn) Close() error

func (*DstMuxedConn) Del

func (m *DstMuxedConn) Del(addr netip.Prefix) error

Del removes a connection from the multiplexer.

func (*DstMuxedConn) Prefixes

func (m *DstMuxedConn) Prefixes() []netip.Prefix

func (*DstMuxedConn) ReadPacket

func (m *DstMuxedConn) ReadPacket(pkt []byte) (int, error)

ReadPacket reads a packet from multiple underlying Connection pipes.

func (*DstMuxedConn) Remove

func (m *DstMuxedConn) Remove(addr netip.Prefix)

Remove is an internal helper that removes a connection without external validation

func (*DstMuxedConn) String

func (m *DstMuxedConn) String() string

func (*DstMuxedConn) WritePacket

func (m *DstMuxedConn) WritePacket(pkt []byte) ([]byte, error)

WritePacket writes a pkt to one of the underlying Connection objects based on the destination IP of the pkt.

type PacketInfo

type PacketInfo struct {
	Timestamp time.Time
	Direction Direction
	Protocol  Protocol
	SrcIP     netip.Addr
	SrcPort   uint16
	DstIP     netip.Addr
	DstPort   uint16
	Size      int
	TCPFlags  TCPFlags
}

PacketInfo contains metadata extracted from a packet.

func ExtractPacketInfo

func ExtractPacketInfo(packet []byte, dir Direction) PacketInfo

ExtractPacketInfo parses an IP packet to extract metadata.

type PacketObserver

type PacketObserver interface {
	OnPacket(info PacketInfo)
}

PacketObserver is an interface for observing packets flowing through the tunnel.

type PacketQueue

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

func (*PacketQueue) BatchSize

func (q *PacketQueue) BatchSize() int

func (*PacketQueue) Close

func (q *PacketQueue) Close() error

func (*PacketQueue) Read

func (q *PacketQueue) Read(pkts [][]byte, sizes []int) (int, error)

func (*PacketQueue) Write

func (q *PacketQueue) Write(pkts [][]byte) (int, error)

type Protocol

type Protocol uint8

Protocol represents the transport layer protocol.

const (
	ProtocolUnknown Protocol = iota
	ProtocolTCP
	ProtocolUDP
	ProtocolICMP
)

func (Protocol) String

func (p Protocol) String() string

type SpliceConfig

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

SpliceConfig holds configuration options for splice operations.

type SpliceOption

type SpliceOption func(*SpliceConfig)

SpliceOption is a function that configures splice behavior.

func WithChecksumErrorLogging

func WithChecksumErrorLogging() SpliceOption

WithChecksumErrorLogging enables detailed logging of checksum errors.

func WithChecksumRecalculation

func WithChecksumRecalculation() SpliceOption

WithChecksumRecalculation enables TCP checksum recalculation.

func WithChecksumVerification

func WithChecksumVerification() SpliceOption

WithChecksumVerification enables TCP checksum verification (for debugging).

func WithPacketObserver

func WithPacketObserver(obs PacketObserver) SpliceOption

WithPacketObserver sets a packet observer for traffic monitoring.

type SrcMuxedConn

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

SrcMuxedConn implements Connection that multiplexes multiple Connections based on the source IP of the IPv4/v6 packet.

func NewSrcMuxedConn

func NewSrcMuxedConn() *SrcMuxedConn

NewSrcMuxedConn creates a new SrcMuxedConn instance.

func (*SrcMuxedConn) Add

func (m *SrcMuxedConn) Add(addr netip.Prefix, conn Connection) error

Add adds a new connection to the multiplexer.

The connection is wrapped in an asyncSendConn so that a slow or backpressured underlying connection cannot stall writes destined for its siblings via the shared splice goroutine (see async_send.go). Reads flow through the embedded Connection unchanged.

func (*SrcMuxedConn) Close

func (m *SrcMuxedConn) Close() error

func (*SrcMuxedConn) Del

func (m *SrcMuxedConn) Del(addr netip.Prefix) error

Del removes a connection from the multiplexer.

func (*SrcMuxedConn) Prefixes

func (m *SrcMuxedConn) Prefixes() []netip.Prefix

func (*SrcMuxedConn) ReadPacket

func (m *SrcMuxedConn) ReadPacket(pkt []byte) (int, error)

ReadPacket reads a packet from multiple underlying Connection pipes.

func (*SrcMuxedConn) Remove

func (m *SrcMuxedConn) Remove(addr netip.Prefix)

Remove is an internal helper that removes a connection without external validation

func (*SrcMuxedConn) String

func (m *SrcMuxedConn) String() string

func (*SrcMuxedConn) WritePacket

func (m *SrcMuxedConn) WritePacket(pkt []byte) ([]byte, error)

WritePacket writes a pkt to one of the underlying Connection objects based on the source IP of the pkt.

type SuspendableObserver

type SuspendableObserver interface {
	IsSuspended() bool
	CountPacket() // lightweight increment when suspended, for rate tracking
}

SuspendableObserver is an optional interface that PacketObservers can implement to allow the hot path to skip packet parsing when observation is suspended.

type TCPFlags

type TCPFlags uint8

TCPFlags represents TCP control flags.

const (
	TCPFlagFIN TCPFlags = 0x01
	TCPFlagSYN TCPFlags = 0x02
	TCPFlagRST TCPFlags = 0x04
	TCPFlagPSH TCPFlags = 0x08
	TCPFlagACK TCPFlags = 0x10
	TCPFlagURG TCPFlags = 0x20
)

func (TCPFlags) String

func (f TCPFlags) String() string

Jump to

Keyboard shortcuts

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