conntrack

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package conntrack tracks per-connection state across the TCP handshake so the bypass engine knows when to inject the fake ClientHello and whether the real server acknowledged it.

This is the Go port of the upstream MonitorConnection + FakeInjectiveConnection classes, split along state vs. I/O concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Mu sync.Mutex

	Tuple Tuple

	// Sequence numbers learned from observed packets. Zero means "unknown";
	// callers should gate on Stage rather than checking these directly.
	SynSeq    uint32
	SynAckSeq uint32

	Stage HandshakeStage

	// FakePayload is the fake ClientHello bytes to inject after the handshake.
	FakePayload []byte

	// Done is closed exactly once when the handshake reaches a terminal state
	// (FakeAcked or Failed). Consumers wait on it to learn the outcome.
	Done   chan struct{}
	Result Result

	// Monitor indicates whether the packet filter should still intercept this
	// flow. Flipped to false by the owner once the bypass completes or fails,
	// after which packets pass through unchanged.
	Monitor bool
}

Connection is the mutable per-flow state observed by the packet injector. All field access must hold Mu.

func New

func New(t Tuple, fakePayload []byte) *Connection

New returns a fresh Connection in StageInit with Monitor enabled.

func (*Connection) Finish

func (c *Connection) Finish(ok bool, reason string)

Finish records the outcome and closes Done. Idempotent under Mu. Callers MUST hold c.Mu.

type HandshakeStage

type HandshakeStage uint8

HandshakeStage tracks how far through the TCP 3-way handshake we are, and whether the fake ClientHello has been emitted yet. Transitions are linear:

Init → SynSent → SynAckSeen → AckSent → FakeScheduled → FakeSent → FakeAcked
(or → Failed at any point)
const (
	StageInit HandshakeStage = iota
	StageSynSent
	StageSynAckSeen
	StageAckSent
	StageFakeScheduled
	StageFakeSent
	StageFakeAcked
	StageFailed
)

type Result

type Result struct {
	OK     bool
	Reason string
}

Result carries the terminal outcome reported to the connection owner.

type Table

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

Table is a thread-safe map of in-flight connections keyed by 4-tuple.

func NewTable

func NewTable() *Table

NewTable returns an empty Table.

func (*Table) Add

func (t *Table) Add(c *Connection) bool

Add registers c. Returns false if an entry for the same tuple already exists.

func (*Table) Get

func (t *Table) Get(k Tuple) (*Connection, bool)

Get returns the connection for the given tuple, if any.

func (*Table) Len

func (t *Table) Len() int

Len returns the current connection count (for metrics/telemetry).

func (*Table) Remove

func (t *Table) Remove(k Tuple)

Remove deletes the entry for k. Safe to call repeatedly.

type Tuple

type Tuple struct {
	SrcIP   netip.Addr
	SrcPort uint16
	DstIP   netip.Addr
	DstPort uint16
}

Tuple is the 4-tuple identifying a TCP connection.

Jump to

Keyboard shortcuts

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