netlink

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2015 License: Apache-2.0, Apache-2.0 Imports: 10 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_MACVLAN_MODE = 1
	IFLA_VLAN_ID      = 1
	IFLA_NET_NS_FD    = 28
	IFLA_ADDRESS      = 1
	IFLA_BRPORT_MODE  = 4
	SIOC_BRADDBR      = 0x89a0
	SIOC_BRDELBR      = 0x89a1
	SIOC_BRADDIF      = 0x89a2
)
View Source
const (
	MACVLAN_MODE_PRIVATE = 1 << iota
	MACVLAN_MODE_VEPA
	MACVLAN_MODE_BRIDGE
	MACVLAN_MODE_PASSTHRU
)

Variables

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

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 ChangeName

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

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

func DeleteBridge(name string) error

Delete the actual bridge device.

func NetworkChangeName

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

Rename a particular interface to a different name !!! Note that you can't rename an active interface. You need to bring it down before renaming it. This is identical to running: ip link set dev ${oldName} name ${newName}

func NetworkCreateVethPair

func NetworkCreateVethPair(name1, name2 string, txQueueLen int) error

Add a new VETH pair link on the host This is identical to running: ip link add name $name type veth peer name $peername

func NetworkLinkAdd

func NetworkLinkAdd(name string, linkType string) error

Add a new network link of a specified type. This is identical to running: ip link add $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 NetworkLinkAddMacVlan

func NetworkLinkAddMacVlan(masterDev, macVlanDev string, mode string) error

func NetworkLinkAddMacVtap

func NetworkLinkAddMacVtap(masterDev, macVlanDev string, mode string) error

func NetworkLinkAddVlan

func NetworkLinkAddVlan(masterDev, vlanDev string, vlanId uint16) error

Add a new VLAN interface with masterDev as its upper device This is identical to running: ip link add name $name link $masterdev type vlan id $id

func NetworkLinkDel

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

Bring down a particular network interface. This is identical to running: ip link set $name down

func NetworkLinkUp

func NetworkLinkUp(iface *net.Interface) error

Bring up a particular network interface. This is identical to running: ip link set dev $name up

func NetworkSetMTU

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

Set link Maximum Transmission Unit This is identical to running: ip link set dev $name mtu $MTU bridge is a bitch here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=292088 https://bugzilla.redhat.com/show_bug.cgi?id=697021 There is a discussion about how to deal with ifcs joining bridge with MTU > 1500 Regular network nterfaces do seem to work though!

func NetworkSetMacAddress

func NetworkSetMacAddress(iface *net.Interface, macaddr string) error

Set link layer address ie. MAC Address. This is identical to running: ip link set dev $name address $macaddress

func NetworkSetMaster

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

Add an interface to bridge. This is identical to running: ip link set $name master $master

func NetworkSetNoMaster

func NetworkSetNoMaster(iface *net.Interface) error

Remove an interface from the bridge This is is identical to to running: ip link $name set nomaster

func NetworkSetNsFd

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

Move a particular network interface to a particular mounted network namespace specified by file descriptor. This is idential to running: ip link set dev $name netns $fd

func NetworkSetNsPid

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

Move a particular network interface to a particular network namespace specified by PID. This is identical to running: ip link set dev $name netns $pid

func NetworkSetTxQueueLen

func NetworkSetTxQueueLen(iface *net.Interface, txQueueLen int) error

Set link queue length This is identical to running: ip link set dev $name txqueuelen $QLEN

func SetHairpinMode

func SetHairpinMode(iface *net.Interface, enabled bool) error

func SetMacAddress

func SetMacAddress(name, addr string) error

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 MacVlanLink struct {
	MasterDev string
	SlaveDev  string
	// contains filtered or unexported fields
}

MacVlan link has LowerDev, UpperDev and operates in Mode mode This simplifies the code when creating MacVlan or MacVtap interface

func (MacVlanLink) Mode

func (m MacVlanLink) Mode() uint32

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

func (s *NetlinkSocket) CheckMessage(m syscall.NetlinkMessage, seq, pid uint32) error

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