netutils

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: GPL-2.0 Imports: 14 Imported by: 0

README

IPREF netutils

This repository contains the CLI utilities ipref-traceroute and ipref-ping.

The CLI interface is designed to be compatible with GNU inetutils. Not all options are supported, and these utilities add some IRPEF-specific options.

When not behind an IPREF gateway, these utilities behave largely the same as their GNU inetutils counterparts. When behind an IPREF gateway, these utilities show additional information from IPREF ICMP UDP tunnel packets.

Supports Linux and FreeBSD.

Building

Run make, then you'll find the binaries in bin/.

Documentation

Index

Constants

View Source
const (
	// ICMPv4 types
	ICMPv4_ECHO_REPLY    = 0
	ICMPv4_DEST_UNREACH  = 3
	ICMPv4_SOURCE_QUENCH = 4
	ICMPv4_REDIRECT      = 5
	ICMPv4_ECHO_REQUEST  = 8
	ICMPv4_TIME_EXCEEDED = 11

	// ICMPv4 codes for ICMPv4_DEST_UNREACH
	ICMPv4_NET_UNREACH  = 0
	ICMPv4_HOST_UNREACH = 1
	ICMPv4_PROT_UNREACH = 2 // protocol unreachable
	ICMPv4_PORT_UNREACH = 3
	ICMPv4_FRAG_NEEDED  = 4
	ICMPv4_NET_UNKNOWN  = 6
	ICMPv4_HOST_UNKNOWN = 7
	ICMPv4_ADMIN_PROHIB = 13 // communication administratively prohibited

	// ICMPv4 codes for ICMPv4_TIME_EXCEEDED
	ICMPv4_EXC_TTL  = 0
	ICMPv4_EXC_FRAG = 1 // fragment reassembly time exceeded

	// ICMPv6 types
	ICMPv6_DEST_UNREACH   = 1
	ICMPv6_PACKET_TOO_BIG = 2
	ICMPv6_TIME_EXCEEDED  = 3
	ICMPv6_ECHO_REQUEST   = 128 // code = 0
	ICMPv6_ECHO_REPLY     = 129 // code = 0

	// ICMPv6 codes for ICMPv6_DEST_UNREACH
	ICMPv6_NET_UNREACH  = 0
	ICMPv6_ADMIN_PROHIB = 1
	ICMPv6_HOST_UNREACH = 3
	ICMPv6_PORT_UNREACH = 4

	// ICMPv6 codes for ICMPv6_TIME_EXCEEDED
	ICMPv6_EXC_TTL  = 0 // hop limit exceeded
	ICMPv6_EXC_FRAG = 1

	// IPREF_ICMP types
	IPREF_ICMP_ECHO_REPLY    = 0
	IPREF_ICMP_DEST_UNREACH  = 3
	IPREF_ICMP_ECHO_REQUEST  = 8
	IPREF_ICMP_TIME_EXCEEDED = 11

	// IPREF_ICMP codes for IPREF_ICMP_DEST_UNREACH
	IPREF_ICMP_NET_UNREACH  = 0
	IPREF_ICMP_HOST_UNREACH = 1
	IPREF_ICMP_PORT_UNREACH = 2
	IPREF_ICMP_FRAG_NEEDED  = 4
	IPREF_ICMP_ADMIN_PROHIB = 13

	// IPREF_ICMP codes for IPREF_ICMP_TIME_EXCEEDED
	IPREF_ICMP_EXC_TTL  = 0
	IPREF_ICMP_EXC_FRAG = 1
)
View Source
const (
	ICMP              = 1 // Same protocol number used by IPv4 and IPREF
	TCP               = 6
	UDP               = 17
	ECHO              = 7
	DISCARD           = 9
	IPv6_HOP_OPT      = 0  // IPv6 hop-by-hop options extension header
	IPv6_FRAG_EXT     = 44 // IPv6 fragment extension header
	ICMPv6            = 58
	IPv6_NO_NEXT      = 59
	IPREF_PORT        = 1045
	IPREF_LOCAL_PORT  = 1046
	IPREF_HDR_MIN_LEN = 4 + 4 + 4 + 4 + 4
	IPREF_HDR_MAX_LEN = 4 + 8 + 16 + 16 + 16 + 16
	// IPv4 header offests
	IP_VER           = 0
	IPv4_DSCP        = 1
	IPv4_LEN         = 2
	IPv4_ID          = 4
	IPv4_FRAG        = 6
	IPv4_TTL         = 8
	IPv4_PROTO       = 9
	IPv4_CSUM        = 10
	IPv4_SRC         = 12
	IPv4_DST         = 16
	IPv4_HDR_MIN_LEN = 20
	// IPv6 header offsets
	IPv6_PLD_LEN     = 4
	IPv6_NEXT        = 6
	IPv6_TTL         = 7
	IPv6_SRC         = 8
	IPv6_DST         = 24
	IPv6_HDR_MIN_LEN = 40
	// IPv6 fragment extension header offsets
	IPv6_FRAG_NEXT    = 0
	IPv6_FRAG_RES1    = 1
	IPv6_FRAG_OFF     = 2
	IPv6_FRAG_IDENT   = 4
	IPv6_FRAG_HDR_LEN = 8
	// UDP offsets
	UDP_SPORT   = 0
	UDP_DPORT   = 2
	UDP_LEN     = 4
	UDP_CSUM    = 6
	UDP_HDR_LEN = 8
	// TCP offsets
	TCP_SPORT = 0
	TCP_DPORT = 2
	TCP_CSUM  = 16
	// ICMP offsets
	ICMP_TYPE = 0
	ICMP_CODE = 1
	ICMP_CSUM = 2
	ICMP_BODY = 4
	ICMP_MTU  = 6
	ICMP_DATA = 8
)
View Source
const (
	PKT_IPREF = iota + 1
	PKT_IPv4
	PKT_IPv6
)

Variables

This section is empty.

Functions

func CompareProbeResponse

func CompareProbeResponse(a, b ProbeResponse) int

func ICMPAnnot

func ICMPAnnot(pkt_typ int, typ, code byte) string

Short code shown in traceroute

func ICMPDesc

func ICMPDesc(pkt_typ int, typ, code byte) string

func ResolveName

func ResolveName(name string) ([]ipref.IP, error)

func ReverseResolve

func ReverseResolve(ip ipref.IP, no_names bool) (name string)

Types

type PktBuf

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

type ProbePacket

type ProbePacket struct {
	Sent       time.Time
	Ident, Seq uint16
}

type ProbeResponse

type ProbeResponse interface {
	Clone() ProbeResponse
	GetProbeResponseCommon() *ProbeResponseCommon
}

func MergeProbeResponses

func MergeProbeResponses(responses []ProbeResponse,
	clear_orig_packet bool, diff_protos bool) (merged []ProbeResponse)

type ProbeResponseCommon

type ProbeResponseCommon struct {
	ProbePacket
	Since []time.Duration
	SrcIP ipref.IP
	ProbeResponseStatus
}

type ProbeResponseICMP

type ProbeResponseICMP struct {
	ProbeResponseCommon
}

func (*ProbeResponseICMP) Clone

func (res *ProbeResponseICMP) Clone() ProbeResponse

func (*ProbeResponseICMP) GetProbeResponseCommon

func (res *ProbeResponseICMP) GetProbeResponseCommon() *ProbeResponseCommon

type ProbeResponseIPREF

type ProbeResponseIPREF struct {
	ProbeResponseCommon
	SrcIpRef ipref.IpRef
	DstIpRef ipref.IpRef
}

func (*ProbeResponseIPREF) Clone

func (res *ProbeResponseIPREF) Clone() ProbeResponse

func (*ProbeResponseIPREF) GetProbeResponseCommon

func (res *ProbeResponseIPREF) GetProbeResponseCommon() *ProbeResponseCommon

type ProbeResponseStatus

type ProbeResponseStatus struct {
	Proto      int  // PKT_IPv4, PKT_IPv6, or PKT_IPREF
	Type, Code byte // ICMP type and code
	Expected   bool
}

type Prober

type Prober struct {
	Local, Target ipref.IP // read-only
	// contains filtered or unexported fields
}

func (*Prober) Destroy

func (p *Prober) Destroy()

func (*Prober) Init

func (p *Prober) Init(local, target ipref.IP) error

func (*Prober) Listen

func (p *Prober) Listen(first_timeout, second_timeout, overdue_timeout time.Duration,
	all, single bool) ([]ProbeResponse, error)

Not re-entrant. Timeout is time elapsed since last packet sent.

Packets received beyond 'overdue_timeout' are ignored.

If 'all', then return once a response is received for all probe packets.

If 'single', then return once a single response is received.

func (*Prober) SendProbePackets

func (p *Prober) SendProbePackets(ttl byte, seq int, n int) error

Can be called during p.Listen(). Not re-entrant.

func (*Prober) StartProbe

func (p *Prober) StartProbe()

Don't call during p.Listen().

Directories

Path Synopsis
cmd
ping command
traceroute command

Jump to

Keyboard shortcuts

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