io

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrInvalidPacket

type ErrInvalidPacket struct {
	Err error
}

func (*ErrInvalidPacket) Error

func (e *ErrInvalidPacket) Error() string

type NFQueuePacketIOConfig

type NFQueuePacketIOConfig struct {
	QueueSize      uint32
	QueueNum       *uint16
	Table          string
	ConnMarkAccept uint32
	ConnMarkDrop   uint32

	ReadBuffer  int
	WriteBuffer int
	Local       bool
	RST         bool
}

type Packet

type Packet interface {
	// StreamID is the ID of the stream the packet belongs to.
	StreamID() uint32
	// Timestamp is the time the packet was received.
	Timestamp() time.Time
	// Data is the raw packet data, starting with the IP header.
	Data() []byte
}

Packet represents an IP packet.

type PacketCallback

type PacketCallback func(Packet, error) bool

PacketCallback is called for each packet received. Return false to "unregister" and stop receiving packets.

type PacketIO

type PacketIO interface {
	// Register registers a callback to be called for each packet received.
	// The callback should be called in one or more separate goroutines,
	// and stop when the context is cancelled.
	Register(context.Context, PacketCallback) error
	// SetVerdict sets the verdict for a packet.
	SetVerdict(Packet, Verdict, []byte) error
	// ProtectedDialContext is like net.DialContext, but the connection is "protected"
	// in the sense that the packets sent/received through the connection must bypass
	// the packet IO and not be processed by the callback.
	ProtectedDialContext(ctx context.Context, network, address string) (net.Conn, error)
	// Close closes the packet IO.
	Close() error
	// SetCancelFunc gives packet IO access to context cancel function, enabling it to
	// trigger a shutdown
	SetCancelFunc(cancelFunc context.CancelFunc) error
}

func NewNFQueuePacketIO

func NewNFQueuePacketIO(config NFQueuePacketIOConfig) (PacketIO, error)

func NewPcapPacketIO added in v0.4.0

func NewPcapPacketIO(config PcapPacketIOConfig) (PacketIO, error)

type PcapPacketIOConfig added in v0.4.0

type PcapPacketIOConfig struct {
	PcapFile string
	Realtime bool
}

type Verdict

type Verdict int
const (
	// VerdictAccept accepts the packet, but continues to process the stream.
	VerdictAccept Verdict = iota
	// VerdictAcceptModify is like VerdictAccept, but replaces the packet with a new one.
	VerdictAcceptModify
	// VerdictAcceptStream accepts the packet and stops processing the stream.
	VerdictAcceptStream
	// VerdictDrop drops the packet, but does not block the stream.
	VerdictDrop
	// VerdictDropStream drops the packet and blocks the stream.
	VerdictDropStream
)

Jump to

Keyboard shortcuts

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