stream

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 59 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// ViaModbusRTU is the explicit RTU-over-TCP endpoint allowlist, which
	// precedes every signature.
	ViaModbusRTU = "modbus-rtu"

	// ViaPort is the decoder registered for the server port.
	ViaPort = "port"

	// ViaFallback is the port-independent scan.
	ViaFallback = "fallback"

	// ViaUDPList is the UDPStreamDecoders pass, which exists for protocols
	// sharing a port with a TCP decoder. QUIC is reachable only here.
	ViaUDPList = "udp-list"
)

How a decoder came to be chosen.

Variables

View Source
var Debug bool

Debug controls debug log messages and behavior

DefaultAbstractDecoders contains decoders for custom abstractions that do not represent a specific network protocol.

View Source
var DefaultStreamDecoders = map[int32]core.StreamDecoderAPI{
	21:    ftp.Decoder,
	22:    ssh.Decoder,
	25:    smtp.Decoder,
	53:    dns.Decoder,
	80:    http.Decoder,
	102:   s7comm.Decoder,
	110:   pop3.Decoder,
	143:   imap.Decoder,
	179:   bgp.Decoder,
	443:   tls.Decoder,
	445:   smb.Decoder,
	502:   modbus.Decoder,
	514:   syslog.Decoder,
	1080:  socks.Decoder,
	1883:  mqttsn.Decoder,
	1884:  mqttsn.Decoder,
	2222:  cip.Decoder,
	3389:  rdp.Decoder,
	4840:  opcua.Decoder,
	5060:  sip.Decoder,
	6667:  irc.Decoder,
	8443:  tls.Decoder,
	20000: dnp3.Decoder,
	2404:  iec62351.Decoder,
	34964: profinet.Decoder,
	44818: cip.Decoder,
	47808: bacnetip.Decoder,

	49:    tacacs.Decoder,
	88:    kerberosaudit.Decoder,
	389:   ldap.Decoder,
	135:   dcerpc.Decoder,
	631:   ipp.Decoder,
	10050: zabbix.Decoder,
	10051: zabbix.Decoder,
	9090:  protobuf.Decoder,
	50051: protobuf.Decoder,

} // contains all available stream decoders

DefaultStreamDecoders contains stream decoders mapped to their protocols default port int32 is used to avoid casting when looking up values Note: Multiple decoders can share the same port if they use different transports (TCP vs UDP). The Transport() method is checked before CanDecode() to filter appropriately.

View Source
var SortedDecoderPorts []int32

SortedDecoderPorts provides a deterministic iteration order for DefaultStreamDecoders. Go maps have non-deterministic iteration order, which causes the fallback decoder scan (when no port-specific match is found) to select different decoders across runs. This sorted list ensures consistent decoder selection.

UDPStreamDecoders contains additional stream decoders specifically for UDP protocols. They compete with the mapped decoders in the fallback scan. This is particularly useful for protocols that share port numbers with TCP protocols (e.g., QUIC uses UDP port 443 while TLS uses TCP port 443).

Functions

func ApplyActionToAbstractDecoders

func ApplyActionToAbstractDecoders(action func(api core.DecoderAPI))

ApplyActionToAbstractDecoders can be used to run custom code for all stream decoders.

func ApplyActionToAbstractDecodersAsync

func ApplyActionToAbstractDecodersAsync(action func(api core.DecoderAPI))

ApplyActionToAbstractDecodersAsync can be used to run custom code for all gopacket decoders asynchronously.

func ApplyActionToStreamDecoders

func ApplyActionToStreamDecoders(action func(api core.StreamDecoderAPI))

ApplyActionToStreamDecoders can be used to run custom code for all stream decoders.

func ApplyActionToStreamDecodersAsync

func ApplyActionToStreamDecodersAsync(action func(api core.StreamDecoderAPI))

ApplyActionToStreamDecodersAsync can be used to run custom code for all gopacket decoders asynchronously.

func InitAbstractDecoders

func InitAbstractDecoders(c *config.Config) (decoders []core.DecoderAPI, err error)

InitAbstractDecoders initializes all stream decoders.

func InitDecoders

func InitDecoders(c *config.Config) (decoders []core.StreamDecoderAPI, err error)

InitDecoders initializes all stream decoders.

func ObserveFTPData

func ObserveFTPData(c *core.ConversationInfo)

ObserveFTPData retains bounded candidates until control/data readers drain.

func ObserveTLSUpgrade

func ObserveTLSUpgrade(c *core.ConversationInfo, primary string)

Types

type Datagram

type Datagram struct {
	Data   []byte
	Client bool
}

type Selection

type Selection struct {
	API     core.StreamDecoderAPI
	Decoder core.StreamDecoderInterface
	Name    string
	Port    int32
	Via     string
}

Selection is the outcome of SelectDecoder.

func SelectDecoder

func SelectDecoder(in *SelectionInput) (Selection, bool)

SelectDecoder chooses the decoder for a conversation.

This is the single implementation for both transports. It previously existed twice, in tcp_connection.go and udp_stream.go, and the copies had drifted: only one carried the Modbus RTU pre-pass, only one concatenated a direction before the fallback scan, and only one consulted UDPStreamDecoders. Reading either copy gave a wrong account of how a protocol gets claimed.

Ordering is unchanged from those copies: explicit endpoint, then the registered port, then an ascending-port scan, then the UDP-only list. The scan picks the most specific match. A strong registered-port match stays on the fast path; weak port matches are compared against the full conversation.

type SelectionInput

type SelectionInput struct {
	// Transport filters the registry. A decoder is considered when its own
	// transport matches, or when it declares core.All.
	Transport core.TransportProtocol

	// ServerPort is the port the server listens on: for TCP that is the
	// client's destination, not the server's.
	ServerPort int32

	// PortClient and PortServer are the bytes offered to the port pass.
	PortClient, PortServer []byte

	// ScanClient and ScanServer are the bytes offered to the fallback scan.
	ScanClient, ScanServer []byte
	// ScanBytes is evaluated only if the registered-port fast path misses.
	ScanBytes func() ([]byte, []byte)
	// UDP datagrams are independent messages. If the first is incomplete or
	// unrecognized, a later complete one may still identify the conversation;
	// their bytes must never be concatenated as though this were TCP.
	Datagrams []Datagram

	// Conversation is handed to the winning decoder's factory.
	Conversation *core.ConversationInfo
}

SelectionInput describes one conversation to choose a decoder for.

The port pass and the fallback pass take different bytes, and deliberately so: TCP concatenates a whole direction before the fallback scan, because a length-prefixed protocol cannot be recognized from its first fragment alone, while the port pass sees only that fragment. UDP passes the first datagram to both. Carrying them as separate fields makes that difference visible instead of leaving it implicit in two copies of this logic.

Directories

Path Synopsis
Package network handles network-layer protocol conversations (ICMP, IGMP, GRE, etc.) that don't have a transport layer.
Package network handles network-layer protocol conversations (ICMP, IGMP, GRE, etc.) that don't have a transport layer.
Package quic implements QUIC protocol analysis for both gQUIC and IETF QUIC.
Package quic implements QUIC protocol analysis for both gQUIC and IETF QUIC.

Jump to

Keyboard shortcuts

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