icmp

package
v0.0.0-...-290cafe Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package icmp provides the logic for parsing ICMP packets

Index

Constants

View Source
const (
	// IPProtoICMP is the IP protocol number for ICMP
	// we create our own constant here because there are
	// different imports for the constant in different
	// operating systems
	IPProtoICMP = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser interface {
	Match(header *ipv4.Header, packet []byte, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32) (net.IP, error)
	Parse(header *ipv4.Header, packet []byte) (*Response, error)
}

Parser defines the interface for parsing ICMP packets

func NewICMPTCPParser

func NewICMPTCPParser() Parser

NewICMPTCPParser creates a new ICMPParser that can parse ICMP packets with embedded TCP packets

func NewICMPUDPParser

func NewICMPUDPParser() Parser

NewICMPUDPParser creates a new ICMPParser that can parse ICMP packets with embedded UDP packets

type Response

type Response struct {
	SrcIP        net.IP
	DstIP        net.IP
	TypeCode     layers.ICMPv4TypeCode
	InnerSrcIP   net.IP
	InnerDstIP   net.IP
	InnerSrcPort uint16
	InnerDstPort uint16
	// InnerIdentifier will be populated with
	// an additional identifcation field for matching
	// received packets. For TCP packets, this is the
	// sequence number. For UDP packets, this is the
	// checksum, a uint16 cast to a uint32.
	InnerIdentifier uint32
}

Response encapsulates the data from an ICMP response packet needed for matching

func (*Response) Matches

func (i *Response) Matches(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32) bool

Matches checks if an ICMPResponse matches the expected response based on the local and remote IP, port, and identifier. In this context, identifier will either be the TCP sequence number OR the UDP checksum

type TCPParser

type TCPParser struct {
	// contains filtered or unexported fields
}

TCPParser encapsulates the data and logic for parsing ICMP packets with embedded TCP data

func (*TCPParser) Match

func (p *TCPParser) Match(header *ipv4.Header, packet []byte, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32) (net.IP, error)

Match encapsulates to logic to both parse and match an ICMP packet

func (*TCPParser) Parse

func (p *TCPParser) Parse(header *ipv4.Header, payload []byte) (*Response, error)

Parse parses an ICMP packet with embedded TCP data and returns a Response

type UDPParser

type UDPParser struct {
	// contains filtered or unexported fields
}

UDPParser encapsulates the data and logic for parsing ICMP packets with embedded UDP data

func (*UDPParser) Match

func (p *UDPParser) Match(header *ipv4.Header, packet []byte, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32) (net.IP, error)

Match encapsulates to logic to both parse and match an ICMP packet

func (*UDPParser) Parse

func (p *UDPParser) Parse(header *ipv4.Header, payload []byte) (*Response, error)

Parse parses an ICMP packet with embedded UDP data and returns a Response

Jump to

Keyboard shortcuts

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