Documentation
¶
Index ¶
- func Splice(tunDev tun.Device, conn Connection, opts ...SpliceOption) error
- type Connection
- type Device
- type Direction
- type DstMuxedConn
- func (m *DstMuxedConn) Add(addr netip.Prefix, conn Connection) error
- func (m *DstMuxedConn) Close() error
- func (m *DstMuxedConn) Del(addr netip.Prefix) error
- func (m *DstMuxedConn) Prefixes() []netip.Prefix
- func (m *DstMuxedConn) ReadPacket(pkt []byte) (int, error)
- func (m *DstMuxedConn) Remove(addr netip.Prefix)
- func (m *DstMuxedConn) String() string
- func (m *DstMuxedConn) WritePacket(pkt []byte) ([]byte, error)
- type PacketInfo
- type PacketObserver
- type PacketQueue
- type Protocol
- type SpliceConfig
- type SpliceOption
- type SrcMuxedConn
- func (m *SrcMuxedConn) Add(addr netip.Prefix, conn Connection) error
- func (m *SrcMuxedConn) Close() error
- func (m *SrcMuxedConn) Del(addr netip.Prefix) error
- func (m *SrcMuxedConn) Prefixes() []netip.Prefix
- func (m *SrcMuxedConn) ReadPacket(pkt []byte) (int, error)
- func (m *SrcMuxedConn) Remove(addr netip.Prefix)
- func (m *SrcMuxedConn) String() string
- func (m *SrcMuxedConn) WritePacket(pkt []byte) ([]byte, error)
- type SuspendableObserver
- type TCPFlags
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 (*Device) NewPacketQueue ¶
func (d *Device) NewPacketQueue() (fasttun.PacketQueue, error)
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) ReadPacket ¶
ReadPacket reads a packet from multiple underlying Connection pipes.
func (*DstMuxedConn) Remove ¶
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
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) ReadPacket ¶
ReadPacket reads a packet from multiple underlying Connection pipes.
func (*SrcMuxedConn) Remove ¶
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.