Documentation
¶
Index ¶
- Constants
- Variables
- func FindIPVersion(p []byte) (uint8, error)
- func FindProtocol(p []byte) (layers.IPProtocol, error)
- type ActivityTracker
- type Encoder
- type Funnel
- type FunnelID
- type FunnelTracker
- func (ft *FunnelTracker) Get(id FunnelID) (Funnel, bool)
- func (ft *FunnelTracker) GetOrRegister(id FunnelID, shouldReplaceFunc func(Funnel) bool, ...) (funnel Funnel, new bool, err error)
- func (ft *FunnelTracker) ScheduleCleanup(ctx context.Context, idleTimeout time.Duration)
- func (ft *FunnelTracker) Unregister(id FunnelID, funnel Funnel) (deleted bool)
- type FunnelUniPipe
- type ICMP
- type ICMPDecoder
- type IP
- type IPDecoder
- type Packet
- type PseudoHeader
- type RawPacket
- type Session
Constants ¶
const (
DefaultTTL uint8 = 255
)
Variables ¶
var (
ErrFunnelNotFound = errors.New("funnel not found")
)
Functions ¶
func FindIPVersion ¶
func FindProtocol ¶
func FindProtocol(p []byte) (layers.IPProtocol, error)
Types ¶
type ActivityTracker ¶
type ActivityTracker struct {
// contains filtered or unexported fields
}
func NewActivityTracker ¶
func NewActivityTracker() *ActivityTracker
func (*ActivityTracker) LastActive ¶
func (at *ActivityTracker) LastActive() time.Time
func (*ActivityTracker) UpdateLastActive ¶
func (at *ActivityTracker) UpdateLastActive()
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func NewEncoder() *Encoder
type Funnel ¶
type Funnel interface {
// Updates the last time traffic went through this funnel
UpdateLastActive()
// LastActive returns the last time there is traffic through this funnel
LastActive() time.Time
// Close closes the funnel. Further call to SendToDst or ReturnToSrc should return an error
Close() error
// Equal compares if 2 funnels are equivalent
Equal(other Funnel) bool
}
Funnel is an abstraction to pipe from 1 src to 1 or more destinations
type FunnelID ¶
type FunnelID interface {
// Type returns the name of the type that implements the FunnelID
Type() string
fmt.Stringer
}
FunnelID represents a key type that can be used by FunnelTracker
type FunnelTracker ¶
type FunnelTracker struct {
// contains filtered or unexported fields
}
FunnelTracker tracks funnel from the perspective of eyeball to origin
func NewFunnelTracker ¶
func NewFunnelTracker() *FunnelTracker
func (*FunnelTracker) GetOrRegister ¶
func (ft *FunnelTracker) GetOrRegister( id FunnelID, shouldReplaceFunc func(Funnel) bool, newFunnelFunc func() (Funnel, error), ) (funnel Funnel, new bool, err error)
Registers a funnel. If the `id` is already registered and `shouldReplaceFunc` returns true, it closes and replaces the current funnel. If `newFunnelFunc` returns an error, the `id` will remain unregistered, even if it was registered when calling this function.
func (*FunnelTracker) ScheduleCleanup ¶
func (ft *FunnelTracker) ScheduleCleanup(ctx context.Context, idleTimeout time.Duration)
func (*FunnelTracker) Unregister ¶
func (ft *FunnelTracker) Unregister(id FunnelID, funnel Funnel) (deleted bool)
Unregisters and closes a funnel if the funnel equals to the current funnel
type FunnelUniPipe ¶
type FunnelUniPipe interface {
// SendPacket sends a packet to/from the funnel. It must not modify the packet,
// and after return it must not read the packet
SendPacket(dst netip.Addr, pk RawPacket) error
Close() error
}
FunnelUniPipe is a unidirectional pipe for sending raw packets
type ICMP ¶
ICMP represents is an IP packet + ICMP message
func NewICMPTTLExceedPacket ¶
func (*ICMP) EncodeLayers ¶
func (i *ICMP) EncodeLayers() ([]gopacket.SerializableLayer, error)
type ICMPDecoder ¶
type ICMPDecoder struct {
*IPDecoder
// contains filtered or unexported fields
}
ICMPDecoder decodes raw packets into IP and ICMP. It can process packets sequentially without allocating memory for the layers, so it cannot be called concurrently.
func NewICMPDecoder ¶
func NewICMPDecoder() *ICMPDecoder
type IP ¶
IP represents a generic IP packet. It can be embedded in more specific IP protocols
func (*IP) EncodeLayers ¶
func (ip *IP) EncodeLayers() ([]gopacket.SerializableLayer, error)
type IPDecoder ¶
type IPDecoder struct {
// contains filtered or unexported fields
}
IPDecoder decodes raw packets into IP. It can process packets sequentially without allocating memory for the layers, so it cannot be called concurrently.
func NewIPDecoder ¶
func NewIPDecoder() *IPDecoder
type Packet ¶
type Packet interface {
// IPLayer returns the IP of the packet
IPLayer() *IP
// EncodeLayers returns the layers that make up this packet. They can be passed to an Encoder to serialize into RawPacket
EncodeLayers() ([]gopacket.SerializableLayer, error)
}
Packet represents an IP packet or a packet that is encapsulated by IP
type PseudoHeader ¶
type PseudoHeader struct {
SrcIP [16]byte
DstIP [16]byte
UpperLayerPacketLength uint32
NextHeader uint8
// contains filtered or unexported fields
}
https://www.rfc-editor.org/rfc/rfc2460#section-8.1
func (*PseudoHeader) Marshal ¶
func (ph *PseudoHeader) Marshal() []byte