rtroute

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package rtroute implements interacting with the systems network routing through the Netlink rtnetlink subsystem.

References:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheInfo

type CacheInfo struct {
	Clntref uint32
	LastUse uint32
	Expires uint32
	Error   uint32
	Used    uint32

	// only set when peer info is available.
	Id    uint32
	Ts    uint32
	Tsage uint32
}

CacheInfo contains cache information for a Route.

References:

func (*CacheInfo) UnmarshalBinary

func (c *CacheInfo) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals the rta_cacheinfo struct from bytes.

type EncapType

type EncapType uint16

EncapType is the encapsulation type configured for a Route.

References:

  • linux/includes/uapi/linux/lw_tunnel.h
const (
	MPLS EncapType = 1 + iota
	IP
	ILA
	IP6
	SEG6
	BPF
	SEG6_LOCAL
	RPL
	IOAM6
	XFRM
)

Constants for EncapType.

func (EncapType) String

func (e EncapType) String() string

type Family

type Family uint8

Family configures the family of addresses applicable for a Route.

const (
	ALL   Family = unix.AF_UNSPEC
	INET  Family = unix.AF_INET
	INET6 Family = unix.AF_INET6
)

Constants for Family.

func (Family) String

func (f Family) String() string

type Features

type Features uint32

Features are contained within Metrics.

References:

  • linux/include/uapi/linux/rtnetlink.h
const (
	ECH Features = 1 << iota
	SACK
	TIMESTAMP
	ALLFRAG
	TCP_USEC_TS
)

Constants for Features.

func (Features) String

func (f Features) String() string

type Flags

type Flags uint32

Flags configure the handling of a Route.

References:

  • linux/include/uapi/linux/rtnetlink.h

Constants for Flags.

func (Flags) String

func (f Flags) String() string

type Metrics

type Metrics struct {
	Lock             uint32
	MTU              uint32
	Window           uint32
	Rtt              uint32
	Rttvar           uint32
	Ssthresh         uint32
	Cwnd             uint32
	Advmss           uint32
	Reordering       uint32
	HopLimit         uint32
	InitCwnd         uint32
	Features         Features
	RtoMin           uint32
	InitRwnd         uint32
	QuickAck         uint32
	CcAlgo           string
	FastOpenNoCookie uint32
}

Metrics contains statistics for a Route.

References:

func (*Metrics) UnmarshalAttributes

func (m *Metrics) UnmarshalAttributes(attrs *netlink.AttributeDecoder) error

UnmarshalAttributes unmarshals the metrics contained within a Route.

type MfcStats

type MfcStats struct {
	Packets uint64
	Bytes   uint64
	WrongIf uint64
}

MfcStats not sure what this is yet.

References:

  • linux/include/uapi/linux/rtnetlink.h

func (*MfcStats) UnmarshalBinary

func (m *MfcStats) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals the rta_mfc_stats struct from bytes.

type NextHop

type NextHop struct {
	Len     uint16
	Flags   uint8
	Hops    uint8
	Index   int
	Gateway netip.Addr
}

NextHop contains parameters for the next multipath hop.

References:

  • linux/include/uapi/linux/rtnetlink.h

type Proto

type Proto uint8

Proto is the origin of a Route.

References:

  • rtnetlink(7)
const (
	REDIRECT Proto = 1 + iota
	KERNEL
	BOOT
	STATIC

	// these are user defined values for common routing daemons, not
	// interpreted by the kernel itself.
	GATED      Proto = 8
	RA         Proto = 9
	MRT        Proto = 10
	ZEBRA      Proto = 11
	BIRD       Proto = 12
	DNROUTED   Proto = 13
	XORP       Proto = 14
	NTK        Proto = 15
	DHCP       Proto = 16
	MROUTED    Proto = 17
	KEEPALIVED Proto = 18
	BABEL      Proto = 42
	OVN        Proto = 84
	OPENR      Proto = 99
	BGP        Proto = 186
	ISIS       Proto = 187
	OSPF       Proto = 188
	RIP        Proto = 189
	EIGRP      Proto = 192
)

Constants for Proto.

func (Proto) String

func (p Proto) String() string

type Route

type Route struct {
	Family       Family
	DstLen       uint8
	SrcLen       uint8
	Table        Table
	Proto        Proto
	Scope        Scope
	Type         Type
	Flags        Flags
	Dst          netip.Addr
	Src          netip.Addr
	Iif          int
	Oif          int
	Gateway      netip.Addr
	Priority     uint32
	PrefSrc      netip.Addr
	Metrics      Metrics
	Multipath    []*NextHop
	Flow         uint32
	CacheInfo    *CacheInfo
	Mark         uint32
	MfcStats     *MfcStats
	Via          *Via
	NewDst       netip.Addr
	Pref         uint8
	EncapType    EncapType
	Uid          uint32
	TtlPropagate uint8
	IPProto      uint8
	Sport        uint16
	Dport        uint16
}

Route contains a network route within one of the systems routing tables.

References:

func (*Route) UnmarshalAttributes

func (r *Route) UnmarshalAttributes(attrs *netlink.AttributeDecoder) error

UnmarshalAttributes unmarshals a Route attributes from a Netlink message.

It assumes the RtMsg header has already been read and values set on the Route.

func (r *Route) UnmarshalNetlink(msg netlink.MessageDecoder) error

UnmarshalNetlink unmarshals a single Route from a Netlink message.

type Routes

type Routes []*Route

Routes contains a list of Route read from a series of Netlink messages.

func (rs *Routes) UnmarshalNetlink(msg netlink.MessageDecoder) error

UnmarshalNetlink unmarshals one-or-more Netlink messages containing a Route and appends it to itself.

type RtMsg

type RtMsg struct {
	Family Family
	DstLen uint8
	SrcLen uint8
	TOS    uint8
	Table  uint8
	Proto  Proto
	Scope  Scope
	Type   Type
	Flags  Flags
}

RtMsg is the fixed-length header before Route messages.

References:

  • rtnetlink(7)

func (RtMsg) AppendBinary

func (r RtMsg) AppendBinary(b []byte) ([]byte, error)

AppendBinary appends an RtMsg to bytes using the host byteorder.

func (RtMsg) Len

func (RtMsg) Len() int

Len returns the fixed-length of the RtMsg header.

func (RtMsg) MarshalBinary

func (r RtMsg) MarshalBinary() ([]byte, error)

MarshalBinary marshals an RtMsg to bytes using the host byteorder.

func (RtMsg) String

func (r RtMsg) String() string

String returns a string representation of the attribute header for debugging.

func (*RtMsg) UnmarshalBinary

func (r *RtMsg) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals an RtMsg from bytes using the host byteorder.

It will ignore any additional bytes it is given.

type Scope

type Scope uint8

Scope configures the network scope for an [addr.Addr] or Route.

Constants for Scope.

func (Scope) String

func (s Scope) String() string

type Table

type Table uint32

Table configures which routing table a Route is part of.

References:

  • linux/include/uapi/linux/rtnetlink.h
const (
	COMPAT    Table = 252
	DEFAULT   Table = 253
	MAIN      Table = 254
	LOCALHOST Table = 255
)

Constants for Table.

func (Table) String

func (t Table) String() string

type Type

type Type uint8

Type is the type of Route.

References:

  • rtnetlink(7)
  • linux/include/uapi/linux/rtnetlink.h
const (
	UNICAST Type = 1 + iota
	LOCAL
	BROADCAST
	ANYCAST
	MULTICAST
	BLACKHOLE
	UNREACHABLE
	PROHIBIT
	THROW
	NAT
	XRESOLVE
)

Constants for Type.

func (Type) String

func (t Type) String() string

type Via

type Via struct {
	Family uint16
	Addr   netip.Addr
}

Via configures a gateway in a different route family.

References:

  • rtnetlink(7)
  • linux/include/uapi/linux/rtnetlink.h

func (*Via) UnmarshalBinary

func (v *Via) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals the rtvia struct from bytes.

Jump to

Keyboard shortcuts

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