Documentation ¶
Overview ¶
common.go
Index ¶
- Constants
- func ValidateIPs(connIP IPAddr, pktIP net.IP) bool
- type BaseConnTrack
- type ConnKey
- type ICMPConnKey
- type ICMPConnTrack
- type ICMPTracker
- type IPAddr
- type PreallocatedIPs
- type TCPConnKey
- type TCPConnTrack
- type TCPState
- type TCPTracker
- type UDPConnTrack
- type UDPTracker
- func (t *UDPTracker) Close()
- func (t *UDPTracker) GetConnection(srcIP net.IP, srcPort uint16, dstIP net.IP, dstPort uint16) (*UDPConnTrack, bool)
- func (t *UDPTracker) IsValidInbound(srcIP net.IP, dstIP net.IP, srcPort uint16, dstPort uint16) bool
- func (t *UDPTracker) Timeout() time.Duration
- func (t *UDPTracker) TrackOutbound(srcIP net.IP, dstIP net.IP, srcPort uint16, dstPort uint16)
Constants ¶
const ( // DefaultICMPTimeout is the default timeout for ICMP connections DefaultICMPTimeout = 30 * time.Second // ICMPCleanupInterval is how often we check for stale ICMP connections ICMPCleanupInterval = 15 * time.Second )
const ( // MSL (Maximum Segment Lifetime) is typically 2 minutes MSL = 2 * time.Minute // TimeWaitTimeout (TIME-WAIT) should last 2*MSL TimeWaitTimeout = 2 * MSL )
const ( TCPSyn uint8 = 0x02 TCPAck uint8 = 0x10 TCPFin uint8 = 0x01 TCPRst uint8 = 0x04 TCPPush uint8 = 0x08 TCPUrg uint8 = 0x20 )
const ( // DefaultTCPTimeout is the default timeout for established TCP connections DefaultTCPTimeout = 3 * time.Hour // TCPHandshakeTimeout is timeout for TCP handshake completion TCPHandshakeTimeout = 60 * time.Second // TCPCleanupInterval is how often we check for stale connections TCPCleanupInterval = 5 * time.Minute )
const ( // DefaultUDPTimeout is the default timeout for UDP connections DefaultUDPTimeout = 30 * time.Second // UDPCleanupInterval is how often we check for stale connections UDPCleanupInterval = 15 * time.Second )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseConnTrack ¶
type BaseConnTrack struct { SourceIP net.IP DestIP net.IP SourcePort uint16 DestPort uint16 // contains filtered or unexported fields }
BaseConnTrack provides common fields and locking for all connection types
func (*BaseConnTrack) GetLastSeen ¶
func (b *BaseConnTrack) GetLastSeen() time.Time
GetLastSeen safely gets the last seen timestamp
func (*BaseConnTrack) IsEstablished ¶
func (b *BaseConnTrack) IsEstablished() bool
IsEstablished safely checks if connection is established
func (*BaseConnTrack) SetEstablished ¶
func (b *BaseConnTrack) SetEstablished(state bool)
SetEstablished safely sets the established state
func (*BaseConnTrack) UpdateLastSeen ¶
func (b *BaseConnTrack) UpdateLastSeen()
UpdateLastSeen safely updates the last seen timestamp
type ICMPConnKey ¶
type ICMPConnKey struct { // Supports both IPv4 and IPv6 SrcIP [16]byte DstIP [16]byte Sequence uint16 // ICMP sequence number ID uint16 // ICMP identifier }
ICMPConnKey uniquely identifies an ICMP connection
type ICMPConnTrack ¶
type ICMPConnTrack struct { BaseConnTrack Sequence uint16 ID uint16 }
ICMPConnTrack represents an ICMP connection state
type ICMPTracker ¶
type ICMPTracker struct {
// contains filtered or unexported fields
}
ICMPTracker manages ICMP connection states
func NewICMPTracker ¶
func NewICMPTracker(timeout time.Duration) *ICMPTracker
NewICMPTracker creates a new ICMP connection tracker
func (*ICMPTracker) Close ¶
func (t *ICMPTracker) Close()
Close stops the cleanup routine and releases resources
func (*ICMPTracker) IsValidInbound ¶
func (t *ICMPTracker) IsValidInbound(srcIP net.IP, dstIP net.IP, id uint16, seq uint16, icmpType uint8) bool
IsValidInbound checks if an inbound ICMP Echo Reply matches a tracked request
func (*ICMPTracker) TrackOutbound ¶
TrackOutbound records an outbound ICMP Echo Request
type PreallocatedIPs ¶
PreallocatedIPs is a pool of IP byte slices to reduce allocations
func NewPreallocatedIPs ¶
func NewPreallocatedIPs() *PreallocatedIPs
NewPreallocatedIPs creates a new IP pool
func (*PreallocatedIPs) Get ¶
func (p *PreallocatedIPs) Get() net.IP
Get retrieves an IP from the pool
func (*PreallocatedIPs) Put ¶
func (p *PreallocatedIPs) Put(ip net.IP)
Put returns an IP to the pool
type TCPConnKey ¶
TCPConnKey uniquely identifies a TCP connection
type TCPConnTrack ¶
type TCPConnTrack struct { BaseConnTrack State TCPState sync.RWMutex }
TCPConnTrack represents a TCP connection state
type TCPTracker ¶
type TCPTracker struct {
// contains filtered or unexported fields
}
TCPTracker manages TCP connection states
func NewTCPTracker ¶
func NewTCPTracker(timeout time.Duration) *TCPTracker
NewTCPTracker creates a new TCP connection tracker
func (*TCPTracker) Close ¶
func (t *TCPTracker) Close()
Close stops the cleanup routine and releases resources
func (*TCPTracker) IsValidInbound ¶
func (t *TCPTracker) IsValidInbound(srcIP net.IP, dstIP net.IP, srcPort uint16, dstPort uint16, flags uint8) bool
IsValidInbound checks if an inbound TCP packet matches a tracked connection
func (*TCPTracker) TrackOutbound ¶
func (t *TCPTracker) TrackOutbound(srcIP net.IP, dstIP net.IP, srcPort uint16, dstPort uint16, flags uint8)
TrackOutbound processes an outbound TCP packet and updates connection state
type UDPConnTrack ¶
type UDPConnTrack struct {
BaseConnTrack
}
UDPConnTrack represents a UDP connection state
type UDPTracker ¶
type UDPTracker struct {
// contains filtered or unexported fields
}
UDPTracker manages UDP connection states
func NewUDPTracker ¶
func NewUDPTracker(timeout time.Duration) *UDPTracker
NewUDPTracker creates a new UDP connection tracker
func (*UDPTracker) Close ¶
func (t *UDPTracker) Close()
Close stops the cleanup routine and releases resources
func (*UDPTracker) GetConnection ¶
func (t *UDPTracker) GetConnection(srcIP net.IP, srcPort uint16, dstIP net.IP, dstPort uint16) (*UDPConnTrack, bool)
GetConnection safely retrieves a connection state
func (*UDPTracker) IsValidInbound ¶
func (t *UDPTracker) IsValidInbound(srcIP net.IP, dstIP net.IP, srcPort uint16, dstPort uint16) bool
IsValidInbound checks if an inbound packet matches a tracked connection
func (*UDPTracker) Timeout ¶
func (t *UDPTracker) Timeout() time.Duration
Timeout returns the configured timeout duration for the tracker
func (*UDPTracker) TrackOutbound ¶
TrackOutbound records an outbound UDP connection