common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package common contains common functionality for both TCP and UDP traceroute implementations

Index

Constants

View Source
const (
	DefaultNetworkPathTimeout    = 3000
	DefaultPort                  = 33434
	DefaultTracerouteQueries     = 3
	DefaultNumE2eProbes          = 50
	DefaultMinTTL                = 1
	DefaultMaxTTL                = 30
	DefaultDelay                 = 50 //msec
	DefaultProtocol              = "udp"
	DefaultTcpMethod             = "syn"
	DefaultWantV6                = false
	DefaultReverseDns            = false
	DefaultCollectSourcePublicIP = false
	DefaultUseWindowsDriver      = false
	DefaultSkipPrivateHops       = false
)

Variables

View Source
var ErrPacketDidNotMatchTraceroute = &ReceiveProbeNoPktError{Err: fmt.Errorf("packet did not match the traceroute")}

ErrPacketDidNotMatchTraceroute is returned when a packet does not match the traceroute, either because it is unrelated traffic or from a different traceroute instance.

Functions

func CheckProbeRetryable

func CheckProbeRetryable(funcName string, err error) bool

CheckProbeRetryable returns whether ReceiveProbe failed due to a real error or just an irrelevant packet

func ConvertDurationToMs added in v0.1.6

func ConvertDurationToMs(duration time.Duration) float64

func IPFamily

func IPFamily(addr netip.Addr) gopacket.LayerType

IPFamily returns the IP family of an address (v4 or v6) as a gopacket layer

func LocalAddrForHost

func LocalAddrForHost(destIP net.IP, destPort uint16) (*net.UDPAddr, net.Conn, error)

LocalAddrForHost takes in a destination IP and port and returns the local address that should be used to connect to the destination. The returned connection should be closed by the caller when the local UDP port is no longer needed

func ToHops

func ToHops(p TracerouteParams, probes []*ProbeResponse) ([]*result.TracerouteHop, error)

ToHops converts a list of ProbeResponses to a Results TODO remove this, and use a single type to represent results

func UnmappedAddrFromSlice

func UnmappedAddrFromSlice(slice []byte) (netip.Addr, bool)

UnmappedAddrFromSlice is the same as netip.AddrFromSlice but it also gets rid of mapped ipv6 addresses.

Types

type BadPacketError

type BadPacketError struct {
	Err error
}

BadPacketError is a non-fatal error that occurs when a packet is malformed.

func (*BadPacketError) Error

func (e *BadPacketError) Error() string

func (*BadPacketError) Unwrap

func (e *BadPacketError) Unwrap() error

type CanceledError

type CanceledError string

CanceledError is sent when a listener is canceled

func (CanceledError) Error

func (c CanceledError) Error() string

Error implements the error interface for CanceledError

type MatcherFunc

type MatcherFunc func(*ipv4.Header, []byte, net.IP, uint16, net.IP, uint16, uint32, uint16) (net.IP, error)

MatcherFunc defines functions for matching a packet from the wire to a traceroute based on the source/destination addresses and an identifier

type MismatchError

type MismatchError string

MismatchError is an error type that indicates a MatcherFunc failed due to one or more fields from the packet not matching the expected information

func (MismatchError) Error

func (m MismatchError) Error() string

Error implements the error interface for MismatchError

type ProbeResponse

type ProbeResponse struct {
	// TTL is the Time To Live of the probe that was originally sent
	TTL uint8
	// IP is the IP address of the responding host
	IP netip.Addr
	// RTT is the round-trip time of the probe
	RTT time.Duration
	// IsDest is true if the responding host is the destination
	IsDest bool
}

ProbeResponse is the response of a single probe in a traceroute

func TracerouteParallel

func TracerouteParallel(ctx context.Context, t TracerouteDriver, p TracerouteParallelParams) ([]*ProbeResponse, error)

TracerouteParallel runs a traceroute in parallel

func TracerouteSerial

TracerouteSerial runs a traceroute in serial. Sometimes this is necessary over TracerouteParallel because the driver doesn't support parallel.

type ReceiveProbeNoPktError

type ReceiveProbeNoPktError struct {
	Err error
}

ReceiveProbeNoPktError is returned when ReceiveProbe() didn't find anything new. This is normal if the RTT is long

func (*ReceiveProbeNoPktError) Error

func (e *ReceiveProbeNoPktError) Error() string

func (*ReceiveProbeNoPktError) Unwrap

func (e *ReceiveProbeNoPktError) Unwrap() error

type TracerouteDriver

type TracerouteDriver interface {
	// GetDriverInfo returns metadata about this driver
	GetDriverInfo() TracerouteDriverInfo
	// SendProbe sends a traceroute packet with a specific TTL
	SendProbe(ttl uint8) error
	// ReceiveProbe polls to get a traceroute response with a timeout.
	ReceiveProbe(timeout time.Duration) (*ProbeResponse, error)
}

TracerouteDriver is an implementation of traceroute send+receive of packets

type TracerouteDriverInfo

type TracerouteDriverInfo struct {
	SupportsParallel bool
}

TracerouteDriverInfo is metadata about a TracerouteDriver

type TracerouteParallelParams

type TracerouteParallelParams struct {
	TracerouteParams
}

TracerouteParallelParams are the parameters for TracerouteParallel

func (TracerouteParallelParams) MaxTimeout

func (p TracerouteParallelParams) MaxTimeout() time.Duration

MaxTimeout combines the timeout+probe delays into a total timeout for the traceroute

type TracerouteParams

type TracerouteParams struct {
	// MinTTL is the TTL to start the traceroute at
	MinTTL uint8
	// MaxTTL is the TTL to end the traceroute at
	MaxTTL uint8
	// TracerouteTimeout is the maximum time to wait for a response
	TracerouteTimeout time.Duration
	// PollFrequency is how often to poll for a response
	PollFrequency time.Duration
	// SendDelay is the delay between sending probes (typically small)
	SendDelay time.Duration
}

TracerouteParams are the parameters for a traceroute shared between serial and parallel

func (TracerouteParams) ProbeCount

func (p TracerouteParams) ProbeCount() int

ProbeCount returns the number of probes that will be sent

type TracerouteSerialParams

type TracerouteSerialParams struct {
	TracerouteParams
}

TracerouteSerialParams are the parameters for TracerouteSerial

Jump to

Keyboard shortcuts

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