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) (err error)
- func (c *Conn) RouteAddSrc(ifc *net.Interface, dst net.IPNet, src *net.IPNet, gw net.IP) (err error)
- func (c *Conn) RouteDel(ifc *net.Interface, dst net.IPNet) error
- func (c *Conn) RouteReplace(ifc *net.Interface, dst net.IPNet, gw net.IP) (err error)
- func (c *Conn) RouteReplaceSrc(ifc *net.Interface, dst net.IPNet, src *net.IPNet, gw net.IP) (err error)
- type Neigh
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) 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) RouteReplace ¶
RouteReplace adds or replace information about a network route.