rtnl

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rtnl provides a convenient API on top of the rtnetlink library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustParseAddr

func MustParseAddr(s string) *net.IPNet

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"))

func ParseAddr

func ParseAddr(s string) (*net.IPNet, error)

ParseAddr parses a CIDR string into a host address and network mask. This is a convenience wrapper around net.ParseCIDR(), which surprisingly returns the network address and mask instead of the host address and mask.

Types

type Conn

type Conn struct {
	Conn *rtnetlink.Conn // a route netlink connection
}

Conn represents the underlying netlink connection

func Dial

func Dial(cfg *netlink.Config) (*Conn, error)

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

func (c *Conn) AddrAdd(ifc *net.Interface, addr *net.IPNet) error

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

func (c *Conn) AddrDel(ifc *net.Interface, addr *net.IPNet) error

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

func (c *Conn) Addrs(ifc *net.Interface, family int) (out []*net.IPNet, err error)

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) Close

func (c *Conn) Close() error

Close the connection.

func (*Conn) LinkByIndex

func (c *Conn) LinkByIndex(ifindex int) (*net.Interface, error)

LinkByIndex returns an interface by its index. Similar to net.InterfaceByIndex.

func (*Conn) LinkDown

func (c *Conn) LinkDown(ifc *net.Interface) error

LinkDown takes an inteface down, disabling the link.

func (*Conn) LinkSetHardwareAddr

func (c *Conn) LinkSetHardwareAddr(ifc *net.Interface, hw net.HardwareAddr) error

LinkSetHardwareAddr overrides the L2 address (MAC-address) for the interface.

func (*Conn) LinkUp

func (c *Conn) LinkUp(ifc *net.Interface) error

LinkUp drives an inteface up, enabling the link.

func (c *Conn) Links() (r []*net.Interface, err error)

Links return the list of interfaces available on the system.

func (*Conn) Neighbours

func (c *Conn) Neighbours(ifc *net.Interface, family int) (r []*Neigh, err error)

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) (err error)

RouteAdd adds infomation about a network route.

func (*Conn) RouteAddSrc

func (c *Conn) RouteAddSrc(ifc *net.Interface, dst net.IPNet, src *net.IPNet, gw net.IP) (err error)

RouteAddSrc adds infomation about a network route with the given destination and source. If source is `nil` it's ignored.

func (*Conn) RouteDel

func (c *Conn) RouteDel(ifc *net.Interface, dst net.IPNet) error

RouteDel deletes the route to the given destination.

func (*Conn) RouteReplace

func (c *Conn) RouteReplace(ifc *net.Interface, dst net.IPNet, gw net.IP) (err error)

RouteReplace adds or replace information about a network route.

func (*Conn) RouteReplaceSrc

func (c *Conn) RouteReplaceSrc(ifc *net.Interface, dst net.IPNet, src *net.IPNet, gw net.IP) (err error)

RouteReplaceSrc adds or replace infomation about a network route with the given destination and source. If source is `nil` it's ignored.

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)

Jump to

Keyboard shortcuts

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