packet

package
v0.0.0-...-90ffb0e Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package packet contains *Packet and the related definitions.

Index

Constants

View Source
const (
	// IPProtocolTCP is the TCP protocol number.
	IPProtocolTCP = 6

	// IPProtocolUDP is the UDP protocol number.
	IPProtocolUDP = 17
)
View Source
const (
	// TCPFlagFIN is the FIN flag.
	TCPFlagFIN = 1

	// TCPFlagSYN is the SYN flag.
	TCPFlagSYN = 2

	// TCPFlagRST is the RST flag.
	TCPFlagRST = 4

	// TCPFlagPSH is the PSH flag.
	TCPFlagPSH = 8

	// TCPFlagACK is the ACK flag.
	TCPFlagACK = 16
)
View Source
const DefaultBufferChannel = 128

DefaultBufferChannel is the required buffering for NetworkDevice channels.

Variables

This section is empty.

Functions

func NewNetworkDeviceIOChannels

func NewNetworkDeviceIOChannels() (chan *Packet, chan *Packet)

NewNetworkDeviceIOChannels constructs two channels with size == DefaultBufferChannel.

Types

type Filter

type Filter interface {
	Filter(pkt *Packet) (Target, []*Packet)
}

Filter processes *Packet and determines its fate.

The Filter method returns the Target and optionally a list of new packets to inject.

type FilterFunc

type FilterFunc func(pkt *Packet) (Target, []*Packet)

FilterFunc allows using a function as a Filter.

func (FilterFunc) Filter

func (fx FilterFunc) Filter(p *Packet) (Target, []*Packet)

Filter implements the Filter interface.

type IPProtocol

type IPProtocol uint8

IPProtocol is the protocol number of an IP packet.

func (IPProtocol) String

func (p IPProtocol) String() string

String returns the string representation of the IP protocol.

type NetworkDevice

type NetworkDevice interface {
	// Addresses returns the device addresses.
	Addresses() []netip.Addr

	// EOF returns a channel that is closed when the device is closed.
	EOF() <-chan struct{}

	// Input returns a channel to send [*Packet] to the device.
	//
	// The channel must have size >= [DefaultBufferChannel].
	Input() chan<- *Packet

	// Output returns a channel to receive [*Packet] from the device.
	//
	// The channel must have size >= [DefaultBufferChannel].
	Output() <-chan *Packet
}

NetworkDevice is a network device to read/write *Packet.

type Packet

type Packet struct {
	// TTL is the packet time to live.
	TTL uint8

	// SrcAddr is the source address.
	SrcAddr netip.Addr

	// DstAddr is the destination address.
	DstAddr netip.Addr

	// IPProtocol is the protocol number.
	IPProtocol IPProtocol

	// SrcPort is the source port.
	SrcPort uint16

	// DstPort is the destination port.
	DstPort uint16

	// TCPFlags is the TCP flags.
	Flags TCPFlags

	// Payload is the packet payload.
	Payload []byte
}

Packet is a network packet.

func (*Packet) String

func (p *Packet) String() string

String returns the string representation of the packet.

type TCPFlags

type TCPFlags uint8

TCPFlags is a set of TCP flags.

func (TCPFlags) String

func (flags TCPFlags) String() string

String returns the string representation of the TCP flags.

type Target

type Target int

Target represents what to do with a *Packet similarly to `iptables` target.

const (
	// CONTINUE lets the [*Packet] continue through the chain.
	CONTINUE Target = iota

	// DROP silently discards the [*Packet].
	DROP
)

Jump to

Keyboard shortcuts

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