netlink

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Packet netlink provide access to low level Netlink sockets and messages.

Actual implementations are in: netlink_linux.go netlink_darwin.go

Index

Constants

View Source
const (
	IFNAMSIZ       = 16
	DEFAULT_CHANGE = 0xFFFFFFFF
	IFLA_INFO_KIND = 1
	IFLA_INFO_DATA = 2
	VETH_INFO_PEER = 1
	IFLA_NET_NS_FD = 28
	SIOC_BRADDBR   = 0x89a0
	SIOC_BRDELBR   = 0x89a1
	SIOC_BRADDIF   = 0x89a2
)

Variables

View Source
var (
	ErrWrongSockType = errors.New("Wrong socket type")
	ErrShortResponse = errors.New("Got short response from netlink")
)

Functions

func AddDefaultGw

func AddDefaultGw(ip, device string) error

Add a new default gateway. Identical to: ip route add default via $ip

func AddRoute

func AddRoute(destination, source, gateway, device string) error

Add a new route table entry.

func AddToBridge

func AddToBridge(iface, master *net.Interface) error

Add a slave to abridge device. This is more backward-compatible than netlink.NetworkSetMaster and works on RHEL 6.

func CreateBridge

func CreateBridge(name string, setMacAddr bool) error

Create the actual bridge device. This is more backward-compatible than netlink.NetworkLinkAdd and works on RHEL 6.

func DeleteBridge added in v0.0.3

func DeleteBridge(name string) error

Delete the actual bridge device.

func DeleteRoute added in v0.0.3

func DeleteRoute(destination, source, gateway, device string) error

Delete route table entry.

func NetworkChangeName

func NetworkChangeName(iface *net.Interface, newName string) error

func NetworkCreateVethPair

func NetworkCreateVethPair(name1, name2 string) error

func NetworkLinkAdd

func NetworkLinkAdd(name string, linkType string) error

Add a new network link of a specified type. This is identical to running: ip add link $name type $linkType

func NetworkLinkAddIp

func NetworkLinkAddIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error

Add an Ip address to an interface. This is identical to: ip addr add $ip/$ipNet dev $iface

func NetworkLinkDel added in v0.0.3

func NetworkLinkDel(name string) error

Delete a network link. This is identical to running: ip link del $name

func NetworkLinkDelIp

func NetworkLinkDelIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error

Delete an IP address from an interface. This is identical to: ip addr del $ip/$ipNet dev $iface

func NetworkLinkDown

func NetworkLinkDown(iface *net.Interface) error

func NetworkLinkUp

func NetworkLinkUp(iface *net.Interface) error

Bring up a particular network interface

func NetworkSetMTU

func NetworkSetMTU(iface *net.Interface, mtu int) error

func NetworkSetMaster

func NetworkSetMaster(iface, master *net.Interface) error

same as ip link set $name master $master

func NetworkSetNsFd

func NetworkSetNsFd(iface *net.Interface, fd int) error

func NetworkSetNsPid

func NetworkSetNsPid(iface *net.Interface, nspid int) error

func ReplaceDefaultGw added in v0.0.3

func ReplaceDefaultGw(ip, device string) error

Replace default gateway. Identical to: ip route replace default via $ip

func ReplaceRoute added in v0.0.3

func ReplaceRoute(destination, source, gateway, device string) error

Replace route table entry.

Types

type IfAddr

type IfAddr struct {
	Iface *net.Interface
	IP    net.IP
	IPNet *net.IPNet
}

An IfAddr defines IP network settings for a given network interface

type IfAddrmsg

type IfAddrmsg struct {
	syscall.IfAddrmsg
}

func (*IfAddrmsg) Len

func (msg *IfAddrmsg) Len() int

func (*IfAddrmsg) ToWireFormat

func (msg *IfAddrmsg) ToWireFormat() []byte

type IfInfomsg

type IfInfomsg struct {
	syscall.IfInfomsg
}

func (*IfInfomsg) Len

func (msg *IfInfomsg) Len() int

func (*IfInfomsg) ToWireFormat

func (msg *IfInfomsg) ToWireFormat() []byte

type NetlinkRequest

type NetlinkRequest struct {
	syscall.NlMsghdr
	Data []NetlinkRequestData
}

func (*NetlinkRequest) AddData

func (rr *NetlinkRequest) AddData(data NetlinkRequestData)

func (*NetlinkRequest) ToWireFormat

func (rr *NetlinkRequest) ToWireFormat() []byte

type NetlinkRequestData

type NetlinkRequestData interface {
	Len() int
	ToWireFormat() []byte
}

type NetlinkSocket

type NetlinkSocket struct {
	// contains filtered or unexported fields
}

func (*NetlinkSocket) Close

func (s *NetlinkSocket) Close()

func (*NetlinkSocket) GetPid

func (s *NetlinkSocket) GetPid() (uint32, error)

func (*NetlinkSocket) HandleAck

func (s *NetlinkSocket) HandleAck(seq uint32) error

func (*NetlinkSocket) Receive

func (s *NetlinkSocket) Receive() ([]syscall.NetlinkMessage, error)

func (*NetlinkSocket) Send

func (s *NetlinkSocket) Send(request *NetlinkRequest) error

type Route

type Route struct {
	*net.IPNet
	Iface   *net.Interface
	Default bool
}

A Route is a subnet associated with the interface to reach it.

func NetworkGetRoutes

func NetworkGetRoutes() ([]Route, error)

Returns an array of IPNet for all the currently routed subnets on ipv4 This is similar to the first column of "ip route" output

type RtAttr

type RtAttr struct {
	syscall.RtAttr
	Data []byte
	// contains filtered or unexported fields
}

func (*RtAttr) Len

func (a *RtAttr) Len() int

func (*RtAttr) ToWireFormat

func (a *RtAttr) ToWireFormat() []byte

type RtMsg

type RtMsg struct {
	syscall.RtMsg
}

func (*RtMsg) Len

func (msg *RtMsg) Len() int

func (*RtMsg) ToWireFormat

func (msg *RtMsg) ToWireFormat() []byte

Jump to

Keyboard shortcuts

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