packet

package
v0.0.0-...-31b9ebf Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTTL uint8 = 255
)

Variables

View Source
var (
	ErrFunnelNotFound = errors.New("funnel not found")
)

Functions

func FindIPVersion

func FindIPVersion(p []byte) (uint8, error)

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

func (Encoder) Encode

func (e Encoder) Encode(packet Packet) (RawPacket, error)

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) Get

func (ft *FunnelTracker) Get(id FunnelID) (Funnel, bool)

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

type ICMP struct {
	*IP
	*icmp.Message
}

ICMP represents is an IP packet + ICMP message

func NewICMPTTLExceedPacket

func NewICMPTTLExceedPacket(originalIP *IP, originalPacket RawPacket, routerIP netip.Addr) *ICMP

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

func (*ICMPDecoder) Decode

func (pd *ICMPDecoder) Decode(packet RawPacket) (*ICMP, error)

type IP

type IP struct {
	Src      netip.Addr
	Dst      netip.Addr
	Protocol layers.IPProtocol
	TTL      uint8
}

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)

func (*IP) IPLayer

func (ip *IP) IPLayer() *IP

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

func (*IPDecoder) Decode

func (pd *IPDecoder) Decode(packet RawPacket) (*IP, error)

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

type RawPacket

type RawPacket struct {
	Data []byte
}

RawPacket represents a raw packet or one encoded by Encoder

type Session

type Session struct {
	ID      uuid.UUID
	Payload []byte
}

Jump to

Keyboard shortcuts

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