Package route
Overview ▹
Index ▹
func FetchRIB ¶
func FetchRIB(af int, typ RIBType, arg int) ([]byte, error)
FetchRIB fetches a routing information base from the operating system.
The provided af must be an address family.
The provided arg must be a RIBType-specific argument. When RIBType is related to routes, arg might be a set of route flags. When RIBType is related to network interfaces, arg might be an interface index or a set of interface flags. In most cases, zero means a wildcard.
func ParseRIB ¶
func ParseRIB(typ RIBType, b []byte) ([]Message, error)
ParseRIB parses b as a routing information base and returns a list of routing messages.
type Addr ¶
An Addr represents an address associated with packet routing.
type Addr interface {
// Family returns an address family.
Family() int
}
type DefaultAddr ¶
A DefaultAddr represents an address of various operating system-specific features.
type DefaultAddr struct { Raw []byte // raw format of address // contains filtered or unexported fields }
func (*DefaultAddr) Family ¶
func (a *DefaultAddr) Family() int
Family implements the Family method of Addr interface.
type Inet4Addr ¶
An Inet4Addr represents an internet address for IPv4.
type Inet4Addr struct {
IP [4]byte // IP address
}
func (*Inet4Addr) Family ¶
func (a *Inet4Addr) Family() int
Family implements the Family method of Addr interface.
type Inet6Addr ¶
An Inet6Addr represents an internet address for IPv6.
type Inet6Addr struct { IP [16]byte // IP address ZoneID int // zone identifier }
func (*Inet6Addr) Family ¶
func (a *Inet6Addr) Family() int
Family implements the Family method of Addr interface.
type InterfaceAddrMessage ¶
An InterfaceAddrMessage represents an interface address message.
type InterfaceAddrMessage struct { Version int // message version Type int // message type Flags int // interface flags Index int // interface index Addrs []Addr // addresses // contains filtered or unexported fields }
func (*InterfaceAddrMessage) Sys ¶
func (m *InterfaceAddrMessage) Sys() []Sys
Sys implements the Sys method of Message interface.
type InterfaceAnnounceMessage ¶
An InterfaceAnnounceMessage represents an interface announcement message.
type InterfaceAnnounceMessage struct { Version int // message version Type int // message type Index int // interface index Name string // interface name What int // what type of announcement // contains filtered or unexported fields }
func (*InterfaceAnnounceMessage) Sys ¶
func (m *InterfaceAnnounceMessage) Sys() []Sys
Sys implements the Sys method of Message interface.
type InterfaceMessage ¶
An InterfaceMessage represents an interface message.
type InterfaceMessage struct { Version int // message version Type int // message type Flags int // interface flags Index int // interface index Name string // interface name Addrs []Addr // addresses // contains filtered or unexported fields }
func (*InterfaceMessage) Sys ¶
func (m *InterfaceMessage) Sys() []Sys
Sys implements the Sys method of Message interface.
type InterfaceMetrics ¶
A InterfaceMetrics represents interface metrics.
type InterfaceMetrics struct { Type int // interface type MTU int // maximum transmission unit }
func (*InterfaceMetrics) SysType ¶
func (imx *InterfaceMetrics) SysType() SysType
SysType implements the SysType method of Sys interface.
type InterfaceMulticastAddrMessage ¶
An InterfaceMulticastAddrMessage represents an interface multicast address message.
type InterfaceMulticastAddrMessage struct { Version int // message version Type int // messsage type Flags int // interface flags Index int // interface index Addrs []Addr // addresses // contains filtered or unexported fields }
func (*InterfaceMulticastAddrMessage) Sys ¶
func (m *InterfaceMulticastAddrMessage) Sys() []Sys
Sys implements the Sys method of Message interface.
type LinkAddr ¶
A LinkAddr represents a link-layer address.
type LinkAddr struct { Index int // interface index when attached Name string // interface name when attached Addr []byte // link-layer address when attached }
func (*LinkAddr) Family ¶
func (a *LinkAddr) Family() int
Family implements the Family method of Addr interface.
type Message ¶
A Message represents a routing message.
type Message interface {
// Sys returns operating system-specific information.
Sys() []Sys
}
type RIBType ¶
A RIBType reprensents a type of routing information base.
type RIBType int
const ( RIBTypeRoute RIBType = syscall.NET_RT_DUMP RIBTypeInterface RIBType = syscall.NET_RT_IFLIST )
type RouteMessage ¶
A RouteMessage represents a message conveying an address prefix, a nexthop address and an output interface.
Unlike other messages, this message can be used to query adjacency information for the given address prefix, to add a new route, and to delete or modify the existing route from the routing information base inside the kernel by writing and reading route messages on a routing socket.
For the manipulation of routing information, the route message must contain appropriate fields that include:
Version = <must be specified> Type = <must be specified> Flags = <must be specified> Index = <must be specified if necessary> ID = <must be specified> Seq = <must be specified> Addrs = <must be specified>
The Type field specifies a type of manipulation, the Flags field specifies a class of target information and the Addrs field specifies target information like the following:
route.RouteMessage{ Version: RTM_VERSION, Type: RTM_GET, Flags: RTF_UP | RTF_HOST, ID: uintptr(os.Getpid()), Seq: 1, Addrs: []route.Addrs{ RTAX_DST: &route.Inet4Addr{ ... }, RTAX_IFP: &route.LinkAddr{ ... }, RTAX_BRD: &route.Inet4Addr{ ... }, }, }
The values for the above fields depend on the implementation of each operating system.
The Err field on a response message contains an error value on the requested operation. If non-nil, the requested operation is failed.
type RouteMessage struct { Version int // message version Type int // message type Flags int // route flags Index int // interface index when atatched ID uintptr // sender's identifier; usually process ID Seq int // sequence number Err error // error on requested operation Addrs []Addr // addresses // contains filtered or unexported fields }
func (*RouteMessage) Marshal ¶
func (m *RouteMessage) Marshal() ([]byte, error)
Marshal returns the binary encoding of m.
func (*RouteMessage) Sys ¶
func (m *RouteMessage) Sys() []Sys
Sys implements the Sys method of Message interface.
type RouteMetrics ¶
A RouteMetrics represents route metrics.
type RouteMetrics struct {
PathMTU int // path maximum transmission unit
}
func (*RouteMetrics) SysType ¶
func (rmx *RouteMetrics) SysType() SysType
SysType implements the SysType method of Sys interface.
type Sys ¶
A Sys reprensents operating system-specific information.
type Sys interface { // SysType returns a type of operating system-specific // information. SysType() SysType }
type SysType ¶
A SysType represents a type of operating system-specific information.
type SysType int
const ( SysMetrics SysType = iota SysStats )