Documentation
¶
Overview ¶
Package rtnl provides a convenient API on top of the rtnetlink library.
Index ¶
- func MustParseAddr(s string) *net.IPNet
- func ParseAddr(s string) (*net.IPNet, error)
- type Conn
- func (c *Conn) AddrAdd(ifc *net.Interface, addr *net.IPNet) error
- func (c *Conn) AddrDel(ifc *net.Interface, addr *net.IPNet) error
- func (c *Conn) Addrs(ifc *net.Interface, family int) (out []*net.IPNet, err error)
- func (c *Conn) Close() error
- func (c *Conn) LinkByIndex(ifindex int) (*net.Interface, error)
- func (c *Conn) LinkDown(ifc *net.Interface) error
- func (c *Conn) LinkSetHardwareAddr(ifc *net.Interface, hw net.HardwareAddr) error
- func (c *Conn) LinkUp(ifc *net.Interface) error
- func (c *Conn) Links() (r []*net.Interface, err error)
- func (c *Conn) Neighbours(ifc *net.Interface, family int) (r []*Neigh, err error)
- func (c *Conn) RouteAdd(ifc *net.Interface, dst net.IPNet, gw net.IP, options ...RouteOption) (err error)
- func (c *Conn) RouteDel(ifc *net.Interface, dst net.IPNet) error
- func (c *Conn) RouteGet(dst net.IP) (*Route, error)
- func (c *Conn) RouteGetAll(dst net.IP) (ret []*Route, err error)
- func (c *Conn) RouteReplace(ifc *net.Interface, dst net.IPNet, gw net.IP, options ...RouteOption) (err error)
- type Neigh
- type Route
- type RouteOption
- type RouteOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustParseAddr ¶
MustParseAddr wraps ParseAddr, but panics on error. Use to conveniently parse a known-valid or hardcoded address into a function argument.
iface, _ := net.InterfaceByName("enp2s0") conn.AddrDel(iface, rtnl.MustParseAddr("10.1.1.1/24"))
Types ¶
type Conn ¶
Conn represents the underlying netlink connection
func Dial ¶
Dial the netlink socket. Establishes a new connection. The typical initialisation is:
conn, err := rtnl.Dial(nil) if err != nil { log.Fatal("can't establish netlink connection: ", err) } defer conn.Close() // use conn for your calls
func (*Conn) AddrAdd ¶
AddrAdd associates an IP-address with an interface.
iface, _ := net.InterfaceByName("lo") conn.AddrAdd(iface, rtnl.MustParseAddr("127.0.0.1/8"))
func (*Conn) AddrDel ¶
AddrDel revokes an IP-address from an interface.
iface, _ := net.InterfaceByName("lo") conn.AddrDel(iface, rtnl.MustParseAddr("127.0.0.1/8"))
func (*Conn) Addrs ¶
Addrs returns IP addresses matching the interface and address family. To retrieve all addresses configured for the system, run:
conn.Addrs(nil, 0)
func (*Conn) LinkByIndex ¶
LinkByIndex returns an interface by its index. Similar to net.InterfaceByIndex.
func (*Conn) LinkSetHardwareAddr ¶
LinkSetHardwareAddr overrides the L2 address (MAC-address) for the interface.
func (*Conn) Neighbours ¶
Neighbours lists entries from the neighbor table (e.g. the ARP table).
func (*Conn) RouteAdd ¶
func (c *Conn) RouteAdd(ifc *net.Interface, dst net.IPNet, gw net.IP, options ...RouteOption) (err error)
RouteAdd adds information about a network route.
func (*Conn) RouteGetAll ¶
RouteGetAll returns all routes to the given destination IP in the main routing table.
type Neigh ¶
type Neigh struct { HwAddr net.HardwareAddr // Link-layer address IP net.IP // Network-layer address Interface *net.Interface // Network interface }
Neigh represents a neighbour table entry (e.g. an entry in the ARP table)
type RouteOption ¶
type RouteOption func(*RouteOptions)
RouteOption is the functional options func
func WithRouteAttrs ¶
func WithRouteAttrs(attrs rtnetlink.RouteAttributes) RouteOption
WithRouteAttrs sets the attributes.
func WithRouteSrc ¶
func WithRouteSrc(src *net.IPNet) RouteOption
WithRouteSrc sets the src address.
type RouteOptions ¶
type RouteOptions struct { Src *net.IPNet Attrs rtnetlink.RouteAttributes }
RouteOptions is the functional options struct
func DefaultRouteOptions ¶
DefaultRouteOptions defines the default route options.