Documentation
¶
Overview ¶
Package common contains common functionality for both TCP and UDP traceroute implementations
Index ¶
- Variables
- func CheckProbeRetryable(funcName string, err error) bool
- func IPFamily(addr netip.Addr) gopacket.LayerType
- func LocalAddrForHost(destIP net.IP, destPort uint16) (*net.UDPAddr, net.Conn, error)
- func UnmappedAddrFromSlice(slice []byte) (netip.Addr, bool)
- type BadPacketError
- type CanceledError
- type Hop
- type MatcherFunc
- type MismatchError
- type ProbeResponse
- type ReceiveProbeNoPktError
- type Results
- type TracerouteDriver
- type TracerouteDriverInfo
- type TracerouteParallelParams
- type TracerouteParams
- type TracerouteSerialParams
Constants ¶
This section is empty.
Variables ¶
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 ¶
CheckProbeRetryable returns whether ReceiveProbe failed due to a real error or just an irrelevant packet
func LocalAddrForHost ¶
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
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 Hop ¶
type Hop struct {
IP net.IP
Port uint16
ICMPType uint8
ICMPCode uint8
RTT time.Duration
IsDest bool
}
Hop encapsulates information about a single hop in a traceroute
func ToHops ¶
func ToHops(p TracerouteParams, probes []*ProbeResponse) ([]*Hop, error)
ToHops converts a list of ProbeResponses to a Results TODO remove this, and use a single type to represent results
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 ¶
func TracerouteSerial(ctx context.Context, t TracerouteDriver, p TracerouteSerialParams) ([]*ProbeResponse, error)
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 Results ¶
type Results struct {
Source net.IP
SourcePort uint16
Target net.IP
DstPort uint16
Hops []*Hop
Tags []string
}
Results encapsulates a response from the traceroute
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