Categorygithub.com/jsimonetti/rtnetlink/v2
modulepackage
2.0.2
Repository: https://github.com/jsimonetti/rtnetlink.git
Documentation: pkg.go.dev

# README

rtnetlink Linux Integration GoDoc Go Report Card

Package rtnetlink allows the kernel's routing tables to be read and altered. Network routes, IP addresses, Link parameters, Neighbor setups, Queueing disciplines, Traffic classes and Packet classifiers may all be controlled. It is based on netlink messages.

A convenient, high-level API wrapper is available using package rtnl.

The base rtnetlink library explicitly only exposes a limited low-level API to rtnetlink. It is not the intention (nor wish) to create an iproute2 replacement.

Debugging and netlink errors

Unfortunately the errors generated by the kernels netlink interface are not very great.

When in doubt about your message structure it can always be useful to look at the message send by iproute2 using strace -f -esendmsg /bin/ip or similar.

Another (and possibly even more flexible) way would be using nlmon and wireshark. nlmod is a special kernel module which allows you to capture all netlink (not just rtnetlink) traffic inside the kernel. Be aware that this might be overwhelming on a system with a lot of netlink traffic.

# modprobe nlmon
# ip link add type nlmon
# ip link set nlmon0 up

At this point use wireshark or tcpdump on the nlmon0 interface to view all netlink traffic.

Have a look at the examples for common uses of rtnetlink.

If you have any questions or you'd like some guidance, please join us on Gophers Slack in the #networking channel!

# Packages

No description provided by the author
Package rtnl provides a convenient API on top of the rtnetlink library.

# Functions

Dial dials a route netlink connection.
NetNSForFD returns a handle to an existing network namespace created by another library.
NetNSForPID returns a handle to the network namespace of an existing process given its pid.
RegisterDriver registers a driver with the link service This allows the driver to be used to encode/decode the link data This function is not threadsafe.

# Constants

down, waiting for some external event.
down, either administratively or due to a fault.
down, due to lower-layer interfaces.
down, due to some missing component (typically hardware).
operationally down, in some test mode.
status could not be determined.
interface is in a state to send and receive packets.

# Structs

AddressAttributes contains all attributes for an interface.
A AddressMessage is a route netlink address message.
AddressService is used to retrieve rtnetlink family information.
CacheInfo contains address information.
A Conn is a route netlink connection.
LinkAttributes contains all attributes for an interface.
LinkData implements the default LinkDriver interface for not registered drivers.
LinkInfo contains data for specific network types.
A LinkMessage is a route netlink link message.
LinkService is used to retrieve rtnetlink family information.
LinkStats contains packet statistics.
LinkStats64 contains packet statistics.
LinkXDP holds Express Data Path specific information.
An MPLSNextHop is a route next hop using MPLS encapsulation.
NeighAttributes contains all attributes for a neighbor.
NeighCacheInfo contains neigh information.
A NeighMessage is a route netlink neighbor message.
NeighService is used to retrieve rtnetlink family information.
NetNS represents a Linux network namespace handle to specify in [LinkAttributes].
NextHop wraps struct rtnexthop to provide access to nested attributes.
No description provided by the author
No description provided by the author
RouteMetrics holds some advanced metrics for a route.
No description provided by the author
RTNextHop represents the netlink rtnexthop struct (not an attribute).
RuleAttributes contains all attributes for a rule.
A RuleMessage is a route netlink link message.
RulePortRange defines start and end ports for a rule.
RuleService is used to retrieve rtnetlink family information.
RuleUIDRange defines the start and end for UID matches.

# Interfaces

LinkDriver is the interface that wraps link-specific Encode, Decode, and Kind methods.
LinkDriverVerifier defines a LinkDriver with Verify method.
LinkSlaveDriver defines a LinkDriver with Slave method.
Message is the interface used for passing around different kinds of rtnetlink messages.

# Type aliases

OperationalState represents an interface's operational state.