netlink

package
v1.15.22 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	RT_SCOPE_UNIVERSE = 0
	RT_SCOPE_SITE     = 200
	RT_SCOPE_LINK     = 253
	RT_SCOPE_HOST     = 254
	RT_SCOPE_NOWHERE  = 255
)
View Source
const (
	LINK_TYPE_BRIDGE = "bridge"
	LINK_TYPE_VETH   = "veth"
	LINK_TYPE_IPVLAN = "ipvlan"
	LINK_TYPE_DUMMY  = "dummy"
)

Link types.

View Source
const (
	ADD = iota
	REMOVE
)
View Source
const (
	NDA_UNSPEC = iota
	NDA_DST
	NDA_LLADDR
	NDA_CACHEINFO
	NDA_PROBES
	NDA_VLAN
	NDA_PORT
	NDA_VNI
	NDA_IFINDEX
	NDA_MAX = NDA_IFINDEX
)
View Source
const (
	NUD_NONE       = 0x00
	NUD_INCOMPLETE = 0x01
	NUD_REACHABLE  = 0x02
	NUD_STALE      = 0x04
	NUD_DELAY      = 0x08
	NUD_PROBE      = 0x10
	NUD_FAILED     = 0x20
	NUD_NOARP      = 0x40
	NUD_PERMANENT  = 0x80
)

Neighbor Cache Entry States.

View Source
const (
	NTF_USE    = 0x01
	NTF_SELF   = 0x02
	NTF_MASTER = 0x04
	NTF_PROXY  = 0x08
	NTF_ROUTER = 0x80
)

Neighbor Flags

View Source
const (
	IFLA_INFO_KIND   = 1
	IFLA_INFO_DATA   = 2
	IFLA_NET_NS_FD   = 28
	IFLA_IPVLAN_MODE = 1
	IFLA_BRPORT_MODE = 4
	VETH_INFO_PEER   = 1
	DEFAULT_CHANGE   = 0xFFFFFFFF
)

Netlink protocol constants that are not already defined in unix package.

View Source
const BadEth = "badeth"
View Source
const (
	RTPROT_KERNEL = 2
)

Variables

View Source
var ErrorMockNetlink = errors.New("Mock Netlink Error")

ErrorMockNetlink - netlink mock error

Functions

func Echo

func Echo(text string) error

Echo sends a netlink echo request message. TODO do we need this function?

func GetIPAddressFamily

func GetIPAddressFamily(ip net.IP) int

GetIPAddressFamily returns the address family of an IP address.

func ResetSocket

func ResetSocket()

ResetSocket deletes the default netlink socket.

Types

type BridgeLink struct {
	LinkInfo
}

BridgeLink represents an ethernet bridge.

type DummyLink struct {
	LinkInfo
}

DummyLink represents a dummy network interface.

type IPVlanLink struct {
	LinkInfo
	Mode IPVlanMode
}

IPVlanLink represents an IPVlan network interface.

type IPVlanMode

type IPVlanMode uint16

IPVLAN link attributes.

const (
	IPVLAN_MODE_L2 IPVlanMode = iota
	IPVLAN_MODE_L3
	IPVLAN_MODE_L3S
	IPVLAN_MODE_MAX
)
type Link interface {
	Info() *LinkInfo
}

Link represents a network interface.

type LinkInfo

type LinkInfo struct {
	Type        string
	Name        string
	Flags       net.Flags
	MTU         uint
	TxQLen      uint
	ParentIndex int
	MacAddress  net.HardwareAddr
	IPAddr      net.IP
}

LinkInfo respresents the common properties of all network interfaces.

func (*LinkInfo) Info

func (linkInfo *LinkInfo) Info() *LinkInfo
type MockNetlink struct {
	// contains filtered or unexported fields
}
func NewMockNetlink(returnError bool, errorString string) *MockNetlink

func (*MockNetlink) AddIPAddress

func (f *MockNetlink) AddIPAddress(string, net.IP, *net.IPNet) error

func (*MockNetlink) AddIPRoute

func (f *MockNetlink) AddIPRoute(r *Route) error
func (f *MockNetlink) AddLink(l Link) error

func (*MockNetlink) DeleteIPAddress

func (f *MockNetlink) DeleteIPAddress(string, net.IP, *net.IPNet) error

func (*MockNetlink) DeleteIPRoute

func (f *MockNetlink) DeleteIPRoute(r *Route) error
func (f *MockNetlink) DeleteLink(name string) error

func (*MockNetlink) GetIPRoute

func (f *MockNetlink) GetIPRoute(*Route) ([]*Route, error)

func (*MockNetlink) SetAddRouteValidationFn

func (f *MockNetlink) SetAddRouteValidationFn(fn routeValidateFn)

func (*MockNetlink) SetDeleteRouteValidationFn

func (f *MockNetlink) SetDeleteRouteValidationFn(fn routeValidateFn)

func (*MockNetlink) SetLinkAddress

func (f *MockNetlink) SetLinkAddress(string, net.HardwareAddr) error

func (*MockNetlink) SetLinkHairpin

func (f *MockNetlink) SetLinkHairpin(string, bool) error

func (*MockNetlink) SetLinkMTU

func (f *MockNetlink) SetLinkMTU(name string, mtu int) error

func (*MockNetlink) SetLinkMaster

func (f *MockNetlink) SetLinkMaster(string, string) error

func (*MockNetlink) SetLinkName

func (f *MockNetlink) SetLinkName(string, string) error

func (*MockNetlink) SetLinkNetNs

func (f *MockNetlink) SetLinkNetNs(string, uintptr) error

func (*MockNetlink) SetLinkPromisc

func (f *MockNetlink) SetLinkPromisc(string, bool) error

func (*MockNetlink) SetLinkState

func (f *MockNetlink) SetLinkState(name string, _ bool) error

func (*MockNetlink) SetOrRemoveLinkAddress

func (f *MockNetlink) SetOrRemoveLinkAddress(LinkInfo, int, int) error
type Netlink struct{}
func NewNetlink() *Netlink

func (Netlink) AddIPAddress

func (n Netlink) AddIPAddress(ifName string, ipAddress net.IP, ipNet *net.IPNet) error

AddIPAddress adds an IP address to a network interface.

func (Netlink) AddIPRoute

func (Netlink) AddIPRoute(route *Route) error

AddIPRoute adds an IP route to the route table.

func (Netlink) AddLink(link Link) error

AddLink adds a new network interface of a specified type.

func (Netlink) DeleteIPAddress

func (n Netlink) DeleteIPAddress(ifName string, ipAddress net.IP, ipNet *net.IPNet) error

DeleteIPAddress deletes an IP address from a network interface.

func (Netlink) DeleteIPRoute

func (Netlink) DeleteIPRoute(route *Route) error

DeleteIPRoute deletes an IP route from the route table.

func (Netlink) DeleteLink(name string) error

DeleteLink deletes a network interface.

func (Netlink) GetIPRoute

func (Netlink) GetIPRoute(filter *Route) ([]*Route, error)

GetIPRoute returns a list of IP routes matching the given filter.

func (Netlink) SetLinkAddress

func (Netlink) SetLinkAddress(ifName string, hwAddress net.HardwareAddr) error

SetLinkAddress sets the link layer hardware address of a network interface.

func (Netlink) SetLinkHairpin

func (Netlink) SetLinkHairpin(bridgeName string, on bool) error

SetLinkHairpin sets the hairpin (reflective relay) mode of a bridged interface.

func (Netlink) SetLinkMTU

func (Netlink) SetLinkMTU(name string, mtu int) error

func (Netlink) SetLinkMaster

func (Netlink) SetLinkMaster(name string, master string) error

SetLinkMaster sets the master (upper) device of a network interface.

func (Netlink) SetLinkName

func (Netlink) SetLinkName(name string, newName string) error

SetLinkName sets the name of a network interface.

func (Netlink) SetLinkNetNs

func (Netlink) SetLinkNetNs(name string, fd uintptr) error

SetLinkNetNs sets the network namespace of a network interface.

func (Netlink) SetLinkPromisc

func (Netlink) SetLinkPromisc(ifName string, on bool) error

SetLinkPromisc sets the promiscuous mode of a network interface. TODO do we need this function, not used anywhere currently

func (Netlink) SetLinkState

func (Netlink) SetLinkState(name string, up bool) error

SetLinkState sets the operational state of a network interface.

func (Netlink) SetOrRemoveLinkAddress

func (Netlink) SetOrRemoveLinkAddress(linkInfo LinkInfo, mode, linkState int) error

SetOrRemoveLinkAddress sets/removes static arp entry based on mode

type NetlinkInterface

type NetlinkInterface interface {
	AddLink(link Link) error
	DeleteLink(name string) error
	SetLinkName(name string, newName string) error
	SetLinkState(name string, up bool) error
	SetLinkMTU(name string, mtu int) error
	SetLinkMaster(name string, master string) error
	SetLinkNetNs(name string, fd uintptr) error
	SetLinkAddress(ifName string, hwAddress net.HardwareAddr) error
	SetLinkPromisc(ifName string, on bool) error
	SetLinkHairpin(bridgeName string, on bool) error
	SetOrRemoveLinkAddress(linkInfo LinkInfo, mode, linkState int) error
	AddIPAddress(ifName string, ipAddress net.IP, ipNet *net.IPNet) error
	DeleteIPAddress(ifName string, ipAddress net.IP, ipNet *net.IPNet) error
	GetIPRoute(filter *Route) ([]*Route, error)
	AddIPRoute(route *Route) error
	DeleteIPRoute(route *Route) error
}

type Route

type Route struct {
	Family     int
	Dst        *net.IPNet
	Src        net.IP
	Gw         net.IP
	Tos        int
	Table      int
	Protocol   int
	Scope      int
	Type       int
	Flags      int
	Priority   int
	LinkIndex  int
	ILinkIndex int
}

Route represents a netlink route.

type VEthLink struct {
	LinkInfo
	PeerName string
}

VEthLink represents a virtual ethernet network interface.

Jump to

Keyboard shortcuts

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