netlink

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 20 Imported by: 6,082

README

Build Status GoDoc

The netlink package provides a simple netlink library for go. Netlink is the interface a user-space program in linux uses to communicate with the kernel. It can be used to add and remove interfaces, set ip addresses and routes, and configure ipsec. Netlink communication requires elevated privileges, so in most cases this code needs to be run as root. Since low-level netlink messages are inscrutable at best, the library attempts to provide an api that is loosely modeled on the CLI provided by iproute2. Actions like ip link add will be accomplished via a similarly named function like AddLink(). This library began its life as a fork of the netlink functionality in docker/libcontainer but was heavily rewritten to improve testability, performance, and to add new functionality like ipsec xfrm handling.

Local Build and Test

You can use go get command:

go get github.com/vishvananda/netlink

Testing dependencies:

go get github.com/vishvananda/netns

Testing (requires root):

sudo -E go test github.com/vishvananda/netlink

Examples

Add a new bridge and add eth1 into it:

package main

import (
    "fmt"
    "github.com/vishvananda/netlink"
)

func main() {
    la := netlink.NewLinkAttrs()
    la.Name = "foo"
    mybridge := &netlink.Bridge{LinkAttrs: la}
    err := netlink.LinkAdd(mybridge)
    if err != nil  {
        fmt.Printf("could not add %s: %v\n", la.Name, err)
    }
    eth1, _ := netlink.LinkByName("eth1")
    netlink.LinkSetMaster(eth1, mybridge)
}

Note NewLinkAttrs constructor, it sets default values in structure. For now it sets only TxQLen to -1, so kernel will set default by itself. If you're using simple initialization(LinkAttrs{Name: "foo"}) TxQLen will be set to 0 unless you specify it like LinkAttrs{Name: "foo", TxQLen: 1000}.

Add a new ip address to loopback:

package main

import (
    "github.com/vishvananda/netlink"
)

func main() {
    lo, _ := netlink.LinkByName("lo")
    addr, _ := netlink.ParseAddr("169.254.169.254/32")
    netlink.AddrAdd(lo, addr)
}

Future Work

Many pieces of netlink are not yet fully supported in the high-level interface. Aspects of virtually all of the high-level objects don't exist. Many of the underlying primitives are there, so its a matter of putting the right fields into the high-level objects and making sure that they are serialized and deserialized correctly in the Add and List methods.

There are also a few pieces of low level netlink functionality that still need to be implemented. Routing rules are not in place and some of the more advanced link types. Hopefully there is decent structure and testing in place to make these fairly straightforward to add.

Documentation

Overview

Package netlink provides a simple library for netlink. Netlink is the interface a user-space program in linux uses to communicate with the kernel. It can be used to add and remove interfaces, set up ip addresses and routes, and confiugre ipsec. Netlink communication requires elevated privileges, so in most cases this code needs to be run as root. The low level primitives for netlink are contained in the nl subpackage. This package attempts to provide a high-level interface that is loosly modeled on the iproute2 cli.

Index

Constants

View Source
const (
	TC_ACT_EXT_SHIFT    = 28
	TC_ACT_EXT_VAL_MASK = (1 << TC_ACT_EXT_SHIFT) - 1
)
View Source
const (
	INET_DIAG_NONE = iota
	INET_DIAG_MEMINFO
	INET_DIAG_INFO
	INET_DIAG_VEGASINFO
	INET_DIAG_CONG
	INET_DIAG_TOS
	INET_DIAG_TCLASS
	INET_DIAG_SKMEMINFO
	INET_DIAG_SHUTDOWN
	INET_DIAG_DCTCPINFO
	INET_DIAG_PROTOCOL
	INET_DIAG_SKV6ONLY
	INET_DIAG_LOCALS
	INET_DIAG_PEERS
	INET_DIAG_PAD
	INET_DIAG_MARK
	INET_DIAG_BBRINFO
	INET_DIAG_CLASS_ID
	INET_DIAG_MD5SIG
	INET_DIAG_ULP_INFO
	INET_DIAG_SK_BPF_STORAGES
	INET_DIAG_CGROUP_ID
	INET_DIAG_SOCKOPT
	INET_DIAG_MAX
)

INET_DIAG constatns

View Source
const (
	OperUnknown        = iota // Status can't be determined.
	OperNotPresent            // Some component is missing.
	OperDown                  // Down.
	OperLowerLayerDown        // Down due to state of lower layer.
	OperTesting               // In some test mode.
	OperDormant               // Not up but pending an external event.
	OperUp                    // Up, ready to send packets.
)
View Source
const (
	BOND_MODE_MASK uint64 = 1 << (1 + iota)
	BOND_ACTIVE_SLAVE_MASK
	BOND_MIIMON_MASK
	BOND_UPDELAY_MASK
	BOND_DOWNDELAY_MASK
	BOND_USE_CARRIER_MASK
	BOND_ARP_INTERVAL_MASK
	BOND_ARP_VALIDATE_MASK
	BOND_ARP_ALL_TARGETS_MASK
	BOND_PRIMARY_MASK
	BOND_PRIMARY_RESELECT_MASK
	BOND_FAIL_OVER_MAC_MASK
	BOND_XMIT_HASH_POLICY_MASK
	BOND_RESEND_IGMP_MASK
	BOND_NUM_PEER_NOTIF_MASK
	BOND_ALL_SLAVES_ACTIVE_MASK
	BOND_MIN_LINKS_MASK
	BOND_LP_INTERVAL_MASK
	BOND_PACKETS_PER_SLAVE_MASK
	BOND_LACP_RATE_MASK
	BOND_AD_SELECT_MASK
)

Flag mask for bond options. Bond.Flagmask must be set to on for option to work.

View Source
const (
	CSum    TunnelEncapFlag = 1 << 0
	CSum6                   = 1 << 1
	RemCSum                 = 1 << 2
)
View Source
const (
	IP6_TNL_F_IGN_ENCAP_LIMIT    IP6TunnelFlag = 1  // don't add encapsulation limit if one isn't present in inner packet
	IP6_TNL_F_USE_ORIG_TCLASS                  = 2  // copy the traffic class field from the inner packet
	IP6_TNL_F_USE_ORIG_FLOWLABEL               = 4  // copy the flowlabel from the inner packet
	IP6_TNL_F_MIP6_DEV                         = 8  // being used for Mobile IPv6
	IP6_TNL_F_RCV_DSCP_COPY                    = 10 // copy DSCP from the outer packet
	IP6_TNL_F_USE_ORIG_FWMARK                  = 20 // copy fwmark from inner packet
	IP6_TNL_F_ALLOW_LOCAL_REMOTE               = 40 // allow remote endpoint on the local node
)
View Source
const (
	IPOIB_MODE_DATAGRAM = iota
	IPOIB_MODE_CONNECTED
)
View Source
const (
	CAN_STATE_ERROR_ACTIVE = iota
	CAN_STATE_ERROR_WARNING
	CAN_STATE_ERROR_PASSIVE
	CAN_STATE_BUS_OFF
	CAN_STATE_STOPPED
	CAN_STATE_SLEEPING
)
View Source
const (
	HANDLE_NONE      = 0
	HANDLE_INGRESS   = 0xFFFFFFF1
	HANDLE_CLSACT    = HANDLE_INGRESS
	HANDLE_ROOT      = 0xFFFFFFFF
	PRIORITY_MAP_LEN = 16
)
View Source
const (
	HANDLE_MIN_INGRESS = 0xFFFFFFF2
	HANDLE_MIN_EGRESS  = 0xFFFFFFF3
)
View Source
const (
	HORIZON_DROP_POLICY_CAP     = 0
	HORIZON_DROP_POLICY_DROP    = 1
	HORIZON_DROP_POLICY_DEFAULT = 255
)
View Source
const (
	RT_FILTER_PROTOCOL uint64 = 1 << (1 + iota)
	RT_FILTER_SCOPE
	RT_FILTER_TYPE
	RT_FILTER_TOS
	RT_FILTER_IIF
	RT_FILTER_OIF
	RT_FILTER_DST
	RT_FILTER_SRC
	RT_FILTER_GW
	RT_FILTER_TABLE
	RT_FILTER_HOPLIMIT
	RT_FILTER_PRIORITY
	RT_FILTER_MARK
	RT_FILTER_MASK
	RT_FILTER_REALM
)
View Source
const (
	TCP_ESTABLISHED = iota + 0x01
	TCP_SYN_SENT
	TCP_SYN_RECV
	TCP_FIN_WAIT1
	TCP_FIN_WAIT2
	TCP_TIME_WAIT
	TCP_CLOSE
	TCP_CLOSE_WAIT
	TCP_LAST_ACK
	TCP_LISTEN
	TCP_CLOSING
	TCP_NEW_SYN_REC
	TCP_MAX_STATES
)

TCP States

View Source
const (
	UNIX_DIAG_NAME = iota
	UNIX_DIAG_VFS
	UNIX_DIAG_PEER
	UNIX_DIAG_ICONS
	UNIX_DIAG_RQLEN
	UNIX_DIAG_MEMINFO
	UNIX_DIAG_SHUTDOWN
	UNIX_DIAG_UID
	UNIX_DIAG_MAX
)

According to linux/include/uapi/linux/unix_diag.h

View Source
const (
	VIRTIO_NET_F_CSUM                = 0  // Host handles pkts w/ partial csum
	VIRTIO_NET_F_GUEST_CSUM          = 1  // Guest handles pkts w/ partial csum
	VIRTIO_NET_F_CTRL_GUEST_OFFLOADS = 2  // Dynamic offload configuration.
	VIRTIO_NET_F_MTU                 = 3  // Initial MTU advice
	VIRTIO_NET_F_MAC                 = 5  // Host has given MAC address.
	VIRTIO_NET_F_GUEST_TSO4          = 7  // Guest can handle TSOv4 in.
	VIRTIO_NET_F_GUEST_TSO6          = 8  // Guest can handle TSOv6 in.
	VIRTIO_NET_F_GUEST_ECN           = 9  // Guest can handle TSO[6] w/ ECN in.
	VIRTIO_NET_F_GUEST_UFO           = 10 // Guest can handle UFO in.
	VIRTIO_NET_F_HOST_TSO4           = 11 // Host can handle TSOv4 in.
	VIRTIO_NET_F_HOST_TSO6           = 12 // Host can handle TSOv6 in.
	VIRTIO_NET_F_HOST_ECN            = 13 // Host can handle TSO[6] w/ ECN in.
	VIRTIO_NET_F_HOST_UFO            = 14 // Host can handle UFO in.
	VIRTIO_NET_F_MRG_RXBUF           = 15 // Host can merge receive buffers.
	VIRTIO_NET_F_STATUS              = 16 // virtio_net_config.status available
	VIRTIO_NET_F_CTRL_VQ             = 17 // Control channel available
	VIRTIO_NET_F_CTRL_RX             = 18 // Control channel RX mode support
	VIRTIO_NET_F_CTRL_VLAN           = 19 // Control channel VLAN filtering
	VIRTIO_NET_F_CTRL_RX_EXTRA       = 20 // Extra RX mode control support
	VIRTIO_NET_F_GUEST_ANNOUNCE      = 21 // Guest can announce device on the* network
	VIRTIO_NET_F_MQ                  = 22 // Device supports Receive Flow Steering
	VIRTIO_NET_F_CTRL_MAC_ADDR       = 23 // Set MAC address
	VIRTIO_NET_F_VQ_NOTF_COAL        = 52 // Device supports virtqueue notification coalescing
	VIRTIO_NET_F_NOTF_COAL           = 53 // Device supports notifications coalescing
	VIRTIO_NET_F_GUEST_USO4          = 54 // Guest can handle USOv4 in.
	VIRTIO_NET_F_GUEST_USO6          = 55 // Guest can handle USOv6 in.
	VIRTIO_NET_F_HOST_USO            = 56 // Host can handle USO in.
	VIRTIO_NET_F_HASH_REPORT         = 57 // Supports hash report
	VIRTIO_NET_F_GUEST_HDRLEN        = 59 // Guest provides the exact hdr_len value.
	VIRTIO_NET_F_RSS                 = 60 // Supports RSS RX steering
	VIRTIO_NET_F_RSC_EXT             = 61 // extended coalescing info
	VIRTIO_NET_F_STANDBY             = 62 // Act as standby for another device with the same MAC.
	VIRTIO_NET_F_SPEED_DUPLEX        = 63 // Device set linkspeed and duplex
	VIRTIO_NET_F_GSO                 = 6  // Host handles pkts any GSO type
)

features for virtio net

View Source
const (
	VIRTIO_NET_S_LINK_UP  = 1 // Link is up
	VIRTIO_NET_S_ANNOUNCE = 2 // Announcement is needed
)

virtio net status

View Source
const (
	// Do we get callbacks when the ring is completely used, even if we've
	// suppressed them?
	VIRTIO_F_NOTIFY_ON_EMPTY = 24
	// Can the device handle any descriptor layout?
	VIRTIO_F_ANY_LAYOUT = 27
	// v1.0 compliant
	VIRTIO_F_VERSION_1 = 32
	// If clear - device has the platform DMA (e.g. IOMMU) bypass quirk feature.
	// If set - use platform DMA tools to access the memory.
	// Note the reverse polarity (compared to most other features),
	// this is for compatibility with legacy systems.
	VIRTIO_F_ACCESS_PLATFORM = 33
	// Legacy name for VIRTIO_F_ACCESS_PLATFORM (for compatibility with old userspace)
	VIRTIO_F_IOMMU_PLATFORM = VIRTIO_F_ACCESS_PLATFORM
	// This feature indicates support for the packed virtqueue layout.
	VIRTIO_F_RING_PACKED = 34
	// Inorder feature indicates that all buffers are used by the device
	// in the same order in which they have been made available.
	VIRTIO_F_IN_ORDER = 35
	// This feature indicates that memory accesses by the driver and the
	// device are ordered in a way described by the platform.
	VIRTIO_F_ORDER_PLATFORM = 36
	// Does the device support Single Root I/O Virtualization?
	VIRTIO_F_SR_IOV = 37
	// This feature indicates that the driver passes extra data (besides
	// identifying the virtqueue) in its device notifications.
	VIRTIO_F_NOTIFICATION_DATA = 38
	// This feature indicates that the driver uses the data provided by the device
	// as a virtqueue identifier in available buffer notifications.
	VIRTIO_F_NOTIF_CONFIG_DATA = 39
	// This feature indicates that the driver can reset a queue individually.
	VIRTIO_F_RING_RESET = 40
)

virtio config

View Source
const (
	VIRTIO_ID_NET            = 1  // virtio net
	VIRTIO_ID_BLOCK          = 2  // virtio block
	VIRTIO_ID_CONSOLE        = 3  // virtio console
	VIRTIO_ID_RNG            = 4  // virtio rng
	VIRTIO_ID_BALLOON        = 5  // virtio balloon
	VIRTIO_ID_IOMEM          = 6  // virtio ioMemory
	VIRTIO_ID_RPMSG          = 7  // virtio remote processor messaging
	VIRTIO_ID_SCSI           = 8  // virtio scsi
	VIRTIO_ID_9P             = 9  // 9p virtio console
	VIRTIO_ID_MAC80211_WLAN  = 10 // virtio WLAN MAC
	VIRTIO_ID_RPROC_SERIAL   = 11 // virtio remoteproc serial link
	VIRTIO_ID_CAIF           = 12 // Virtio caif
	VIRTIO_ID_MEMORY_BALLOON = 13 // virtio memory balloon
	VIRTIO_ID_GPU            = 16 // virtio GPU
	VIRTIO_ID_CLOCK          = 17 // virtio clock/timer
	VIRTIO_ID_INPUT          = 18 // virtio input
	VIRTIO_ID_VSOCK          = 19 // virtio vsock transport
	VIRTIO_ID_CRYPTO         = 20 // virtio crypto
	VIRTIO_ID_SIGNAL_DIST    = 21 // virtio signal distribution device
	VIRTIO_ID_PSTORE         = 22 // virtio pstore device
	VIRTIO_ID_IOMMU          = 23 // virtio IOMMU
	VIRTIO_ID_MEM            = 24 // virtio mem
	VIRTIO_ID_SOUND          = 25 // virtio sound
	VIRTIO_ID_FS             = 26 // virtio filesystem
	VIRTIO_ID_PMEM           = 27 // virtio pmem
	VIRTIO_ID_RPMB           = 28 // virtio rpmb
	VIRTIO_ID_MAC80211_HWSIM = 29 // virtio mac80211-hwsim
	VIRTIO_ID_VIDEO_ENCODER  = 30 // virtio video encoder
	VIRTIO_ID_VIDEO_DECODER  = 31 // virtio video decoder
	VIRTIO_ID_SCMI           = 32 // virtio SCMI
	VIRTIO_ID_NITRO_SEC_MOD  = 33 // virtio nitro secure module
	VIRTIO_ID_I2C_ADAPTER    = 34 // virtio i2c adapter
	VIRTIO_ID_WATCHDOG       = 35 // virtio watchdog
	VIRTIO_ID_CAN            = 36 // virtio can
	VIRTIO_ID_DMABUF         = 37 // virtio dmabuf
	VIRTIO_ID_PARAM_SERV     = 38 // virtio parameter server
	VIRTIO_ID_AUDIO_POLICY   = 39 // virtio audio policy
	VIRTIO_ID_BT             = 40 // virtio bluetooth
	VIRTIO_ID_GPIO           = 41 // virtio gpio
	// Virtio Transitional IDs
	VIRTIO_TRANS_ID_NET     = 0x1000 // transitional virtio net
	VIRTIO_TRANS_ID_BLOCK   = 0x1001 // transitional virtio block
	VIRTIO_TRANS_ID_BALLOON = 0x1002 // transitional virtio balloon
	VIRTIO_TRANS_ID_CONSOLE = 0x1003 // transitional virtio console
	VIRTIO_TRANS_ID_SCSI    = 0x1004 // transitional virtio SCSI
	VIRTIO_TRANS_ID_RNG     = 0x1005 // transitional virtio rng
	VIRTIO_TRANS_ID_9P      = 0x1009 // transitional virtio 9p console
)

virtio device ids

View Source
const (
	XDP_SHOW_INFO = 1 << iota
	XDP_SHOW_RING_CFG
	XDP_SHOW_UMEM
	XDP_SHOW_MEMINFO
	XDP_SHOW_STATS
)

XDP diagnosis show flag constants to request particular information elements.

View Source
const (
	XDP_DIAG_NONE                 = iota
	XDP_DIAG_INFO                 // when using XDP_SHOW_INFO
	XDP_DIAG_UID                  // when using XDP_SHOW_INFO
	XDP_DIAG_RX_RING              // when using XDP_SHOW_RING_CFG
	XDP_DIAG_TX_RING              // when using XDP_SHOW_RING_CFG
	XDP_DIAG_UMEM                 // when using XDP_SHOW_UMEM
	XDP_DIAG_UMEM_FILL_RING       // when using XDP_SHOW_UMEM
	XDP_DIAG_UMEM_COMPLETION_RING // when using XDP_SHOW_UMEM
	XDP_DIAG_MEMINFO              // when using XDP_SHOW_MEMINFO
	XDP_DIAG_STATS                // when using XDP_SHOW_STATS
)

XDP diag element constants

View Source
const SOCK_ANY_COOKIE = uint64(nl.TCPDIAG_NOCOOKIE)<<32 + uint64(nl.TCPDIAG_NOCOOKIE)
View Source
const (
	XDP_DU_F_ZEROCOPY = 1 << iota
)

Variables

View Source
var (
	// ErrAttrHeaderTruncated is returned when a netlink attribute's header is
	// truncated.
	ErrAttrHeaderTruncated = errors.New("attribute header truncated")
	// ErrAttrBodyTruncated is returned when a netlink attribute's body is
	// truncated.
	ErrAttrBodyTruncated = errors.New("attribute body truncated")
)
View Source
var (
	// ErrNotImplemented is returned when a requested feature is not implemented.
	ErrNotImplemented = errors.New("not implemented")
)
View Source
var StringToBondAdSelectMap = map[string]BondAdSelect{
	"stable":    BOND_AD_SELECT_STABLE,
	"bandwidth": BOND_AD_SELECT_BANDWIDTH,
	"count":     BOND_AD_SELECT_COUNT,
}
View Source
var StringToBondArpAllTargetsMap = map[string]BondArpAllTargets{
	"any": BOND_ARP_ALL_TARGETS_ANY,
	"all": BOND_ARP_ALL_TARGETS_ALL,
}
View Source
var StringToBondArpValidateMap = map[string]BondArpValidate{
	"none":   BOND_ARP_VALIDATE_NONE,
	"active": BOND_ARP_VALIDATE_ACTIVE,
	"backup": BOND_ARP_VALIDATE_BACKUP,
	"all":    BOND_ARP_VALIDATE_ALL,
}
View Source
var StringToBondFailOverMacMap = map[string]BondFailOverMac{
	"none":   BOND_FAIL_OVER_MAC_NONE,
	"active": BOND_FAIL_OVER_MAC_ACTIVE,
	"follow": BOND_FAIL_OVER_MAC_FOLLOW,
}
View Source
var StringToBondLacpRateMap = map[string]BondLacpRate{
	"slow": BOND_LACP_RATE_SLOW,
	"fast": BOND_LACP_RATE_FAST,
}
View Source
var StringToBondModeMap = map[string]BondMode{
	"balance-rr":    BOND_MODE_BALANCE_RR,
	"active-backup": BOND_MODE_ACTIVE_BACKUP,
	"balance-xor":   BOND_MODE_BALANCE_XOR,
	"broadcast":     BOND_MODE_BROADCAST,
	"802.3ad":       BOND_MODE_802_3AD,
	"balance-tlb":   BOND_MODE_BALANCE_TLB,
	"balance-alb":   BOND_MODE_BALANCE_ALB,
}
View Source
var StringToBondPrimaryReselectMap = map[string]BondPrimaryReselect{
	"always":  BOND_PRIMARY_RESELECT_ALWAYS,
	"better":  BOND_PRIMARY_RESELECT_BETTER,
	"failure": BOND_PRIMARY_RESELECT_FAILURE,
}
View Source
var StringToIPoIBMode = map[string]IPoIBMode{
	"datagram":  IPOIB_MODE_DATAGRAM,
	"connected": IPOIB_MODE_CONNECTED,
}
View Source
var StringToVlanProtocolMap = map[string]VlanProtocol{
	"802.1q":  VLAN_PROTOCOL_8021Q,
	"802.1ad": VLAN_PROTOCOL_8021AD,
}
View Source
var VlanProtocolToString = map[VlanProtocol]string{
	VLAN_PROTOCOL_8021Q:  "802.1q",
	VLAN_PROTOCOL_8021AD: "802.1ad",
}

Functions

func AddrAdd

func AddrAdd(link Link, addr *Addr) error

func AddrDel

func AddrDel(link Link, addr *Addr) error

func AddrReplace added in v1.1.0

func AddrReplace(link Link, addr *Addr) error

func ConntrackDeleteFilter deprecated

func ConntrackDeleteFilter(table ConntrackTableType, family InetFamily, filter *ConntrackFilter) (uint, error)

ConntrackDeleteFilter deletes entries on the specified table on the base of the filter conntrack -D [table] parameters Delete conntrack or expectation

Deprecated: use ConntrackDeleteFilter instead.

func ConntrackDeleteFilters added in v1.3.0

func ConntrackDeleteFilters(table ConntrackTableType, family InetFamily, filters ...CustomConntrackFilter) (uint, error)

ConntrackDeleteFilters deletes entries on the specified table matching any of the specified filters conntrack -D [table] parameters Delete conntrack or expectation

func ConntrackTableFlush

func ConntrackTableFlush(table ConntrackTableType) error

ConntrackTableFlush flushes all the flows of a specified table conntrack -F [table] Flush table The flush operation applies to all the family types

func FouAdd

func FouAdd(f Fou) error

func FouDel

func FouDel(f Fou) error

func GetNetNsIdByFd added in v1.1.0

func GetNetNsIdByFd(fd int) (int, error)

func GetNetNsIdByPid added in v1.1.0

func GetNetNsIdByPid(pid int) (int, error)

func HandleStr

func HandleStr(handle uint32) string

func LinkAdd

func LinkAdd(link Link) error

func LinkDel

func LinkDel(link Link) error

func LinkSetARPOff

func LinkSetARPOff(link Link) error

func LinkSetARPOn

func LinkSetARPOn(link Link) error

func LinkSetAlias

func LinkSetAlias(link Link, name string) error

func LinkSetDown

func LinkSetDown(link Link) error

func LinkSetFastLeave

func LinkSetFastLeave(link Link, mode bool) error

func LinkSetFlood

func LinkSetFlood(link Link, mode bool) error

func LinkSetGROIPv4MaxSize added in v1.2.1

func LinkSetGROIPv4MaxSize(link Link, maxSize int) error

func LinkSetGROMaxSize added in v1.2.1

func LinkSetGROMaxSize(link Link, maxSize int) error

func LinkSetGSOIPv4MaxSize added in v1.2.1

func LinkSetGSOIPv4MaxSize(link Link, maxSize int) error

func LinkSetGSOMaxSize added in v1.2.1

func LinkSetGSOMaxSize(link Link, maxSize int) error

func LinkSetGuard

func LinkSetGuard(link Link, mode bool) error

func LinkSetHairpin

func LinkSetHairpin(link Link, mode bool) error

func LinkSetHardwareAddr

func LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error

func LinkSetLearning

func LinkSetLearning(link Link, mode bool) error

func LinkSetMTU

func LinkSetMTU(link Link, mtu int) error

func LinkSetMaster

func LinkSetMaster(link Link, master Link) error

func LinkSetMasterByIndex

func LinkSetMasterByIndex(link Link, masterIndex int) error

func LinkSetName

func LinkSetName(link Link, name string) error

func LinkSetNoMaster

func LinkSetNoMaster(link Link) error

func LinkSetNsFd

func LinkSetNsFd(link Link, fd int) error

func LinkSetNsPid

func LinkSetNsPid(link Link, nspid int) error

func LinkSetRootBlock

func LinkSetRootBlock(link Link, mode bool) error

func LinkSetTxQLen

func LinkSetTxQLen(link Link, qlen int) error

func LinkSetUp

func LinkSetUp(link Link) error

func LinkSetVfHardwareAddr

func LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error

func LinkSetVfRate added in v1.1.0

func LinkSetVfRate(link Link, vf, minRate, maxRate int) error

func LinkSetVfTxRate

func LinkSetVfTxRate(link Link, vf, rate int) error

func LinkSetVfVlan

func LinkSetVfVlan(link Link, vf, vlan int) error

func LinkSetVfVlanQos added in v1.1.0

func LinkSetVfVlanQos(link Link, vf, vlan, qos int) error

func LinkSetVfVlanQosProto added in v1.2.1

func LinkSetVfVlanQosProto(link Link, vf, vlan, qos, proto int) error

func LinkSetXdpFd

func LinkSetXdpFd(link Link, fd int) error

func LinkSetXdpFdWithFlags added in v1.2.1

func LinkSetXdpFdWithFlags(link Link, fd, flags int) error

func MajorMinor

func MajorMinor(handle uint32) (uint16, uint16)

func MakeHandle

func MakeHandle(major, minor uint16) uint32

func NeighAdd

func NeighAdd(neigh *Neigh) error

func NeighAppend

func NeighAppend(neigh *Neigh) error

func NeighDel

func NeighDel(neigh *Neigh) error

func NeighSet

func NeighSet(neigh *Neigh) error

func NewIPNet

func NewIPNet(ip net.IP) *net.IPNet

NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128.

func ParseIPNet

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

ParseIPNet parses a string in ip/net format and returns a net.IPNet. This is valuable because addresses in netlink are often IPNets and ParseCIDR returns an IPNet with the IP part set to the base IP of the range.

func Percentage2u32

func Percentage2u32(percentage float32) uint32

func RouteAdd

func RouteAdd(route *Route) error

func RouteAppend added in v1.2.1

func RouteAppend(route *Route) error

func RouteChange added in v1.2.1

func RouteChange(route *Route) error

func RouteDel

func RouteDel(route *Route) error

func RouteReplace added in v1.2.1

func RouteReplace(route *Route) error

func SetFastLeave

func SetFastLeave(link Link, mode bool) error

func SetFlood

func SetFlood(link Link, mode bool) error

func SetGuard

func SetGuard(link Link, mode bool) error

func SetHairpin

func SetHairpin(link Link, mode bool) error

func SetLearning

func SetLearning(link Link, mode bool) error

func SetNetNsIdByFd added in v1.1.0

func SetNetNsIdByFd(fd, nsid int) error

func SetNetNsIdByPid added in v1.1.0

func SetNetNsIdByPid(pid, nsid int) error

func SetRootBlock

func SetRootBlock(link Link, mode bool) error

func TcActExtCmp added in v1.2.1

func TcActExtCmp(combined int32, opcode int32) bool

func XfrmPolicyAdd

func XfrmPolicyAdd(policy *XfrmPolicy) error

func XfrmPolicyDel

func XfrmPolicyDel(policy *XfrmPolicy) error

func XfrmStateAdd

func XfrmStateAdd(policy *XfrmState) error

func XfrmStateDel

func XfrmStateDel(policy *XfrmState) error

Types

type Action

type Action interface {
	Attrs() *ActionAttrs
	Type() string
}

Action represents an action in any supported filter.

type ActionAttrs

type ActionAttrs struct {
	Index      int
	Capab      int
	Action     TcAct
	Refcnt     int
	Bindcnt    int
	Statistics *ActionStatistic
	Timestamp  *ActionTimestamp
}

func (ActionAttrs) String

func (q ActionAttrs) String() string

type ActionStatistic added in v1.2.1

type ActionStatistic ClassStatistics

type ActionTimestamp added in v1.2.1

type ActionTimestamp struct {
	Installed uint64
	LastUsed  uint64
	Expires   uint64
	FirstUsed uint64
}

func (ActionTimestamp) String added in v1.2.1

func (t ActionTimestamp) String() string

type Addr

type Addr struct {
	*net.IPNet
	Label       string
	Flags       int
	Scope       int
	Peer        *net.IPNet
	Broadcast   net.IP
	PreferedLft int
	ValidLft    int
	LinkIndex   int
}

Addr represents an IP address from netlink. Netlink ip addresses include a mask, so it stores the address as a net.IPNet.

func AddrList

func AddrList(link Link, family int) ([]Addr, error)

func ParseAddr

func ParseAddr(s string) (*Addr, error)

ParseAddr parses the string representation of an address in the form $ip/$netmask $label. The label portion is optional

func (Addr) Equal

func (a Addr) Equal(x Addr) bool

Equal returns true if both Addrs have the same net.IPNet value.

func (Addr) PeerEqual

func (a Addr) PeerEqual(x Addr) bool

func (Addr) String

func (a Addr) String() string

String returns $ip/$netmask $label

type BareUDP added in v1.2.1

type BareUDP struct {
	LinkAttrs
	Port       uint16
	EtherType  uint16
	SrcPortMin uint16
	MultiProto bool
}

func (*BareUDP) Attrs added in v1.2.1

func (bareudp *BareUDP) Attrs() *LinkAttrs

func (*BareUDP) Type added in v1.2.1

func (bareudp *BareUDP) Type() string

type Bond

type Bond struct {
	LinkAttrs
	Mode            BondMode
	ActiveSlave     int
	Miimon          int
	UpDelay         int
	DownDelay       int
	UseCarrier      int
	ArpInterval     int
	ArpIpTargets    []net.IP
	ArpValidate     BondArpValidate
	ArpAllTargets   BondArpAllTargets
	Primary         int
	PrimaryReselect BondPrimaryReselect
	FailOverMac     BondFailOverMac
	XmitHashPolicy  BondXmitHashPolicy
	ResendIgmp      int
	NumPeerNotif    int
	AllSlavesActive int
	MinLinks        int
	LpInterval      int
	PacketsPerSlave int
	LacpRate        BondLacpRate
	AdSelect        BondAdSelect
	// looking at iproute tool AdInfo can only be retrived. It can't be set.
	AdInfo         *BondAdInfo
	AdActorSysPrio int
	AdUserPortKey  int
	AdActorSystem  net.HardwareAddr
	TlbDynamicLb   int
}

Bond representation

func NewLinkBond

func NewLinkBond(atr LinkAttrs) *Bond

func (*Bond) Attrs

func (bond *Bond) Attrs() *LinkAttrs

Attrs implementation.

func (*Bond) Type

func (bond *Bond) Type() string

Type implementation fro Vxlan.

type BondAdInfo

type BondAdInfo struct {
	AggregatorId int
	NumPorts     int
	ActorKey     int
	PartnerKey   int
	PartnerMac   net.HardwareAddr
}

BondAdInfo represents ad info for bond

type BondAdSelect

type BondAdSelect int

BondAdSelect type

const (
	BOND_AD_SELECT_STABLE BondAdSelect = iota
	BOND_AD_SELECT_BANDWIDTH
	BOND_AD_SELECT_COUNT
)

Possible BondAdSelect value

func (BondAdSelect) String added in v1.2.1

func (b BondAdSelect) String() string

type BondArpAllTargets

type BondArpAllTargets int

BondArpAllTargets type

const (
	BOND_ARP_ALL_TARGETS_ANY BondArpAllTargets = iota
	BOND_ARP_ALL_TARGETS_ALL
)

Possible BondArpAllTargets value

func (BondArpAllTargets) String added in v1.2.1

func (b BondArpAllTargets) String() string

type BondArpValidate

type BondArpValidate int

BondArpValidate type

const (
	BOND_ARP_VALIDATE_NONE BondArpValidate = iota
	BOND_ARP_VALIDATE_ACTIVE
	BOND_ARP_VALIDATE_BACKUP
	BOND_ARP_VALIDATE_ALL
)

Possible BondArpValidate value

func (BondArpValidate) String added in v1.2.1

func (b BondArpValidate) String() string

type BondFailOverMac

type BondFailOverMac int

BondFailOverMac type

const (
	BOND_FAIL_OVER_MAC_NONE BondFailOverMac = iota
	BOND_FAIL_OVER_MAC_ACTIVE
	BOND_FAIL_OVER_MAC_FOLLOW
)

Possible BondFailOverMac value

func (BondFailOverMac) String added in v1.2.1

func (b BondFailOverMac) String() string

type BondLacpRate

type BondLacpRate int

BondLacpRate type

const (
	BOND_LACP_RATE_SLOW BondLacpRate = iota
	BOND_LACP_RATE_FAST
	BOND_LACP_RATE_UNKNOWN
)

Possible BondLacpRate value

func StringToBondLacpRate

func StringToBondLacpRate(s string) BondLacpRate

StringToBondLacpRate returns bond lacp arte, or unknown is the s is invalid.

func (BondLacpRate) String

func (b BondLacpRate) String() string

type BondMode

type BondMode int

BondMode type

const (
	BOND_MODE_BALANCE_RR BondMode = iota
	BOND_MODE_ACTIVE_BACKUP
	BOND_MODE_BALANCE_XOR
	BOND_MODE_BROADCAST
	BOND_MODE_802_3AD
	BOND_MODE_BALANCE_TLB
	BOND_MODE_BALANCE_ALB
	BOND_MODE_UNKNOWN
)

Possible BondMode

func StringToBondMode

func StringToBondMode(s string) BondMode

StringToBondMode returns bond mode, or unknown is the s is invalid.

func (BondMode) String

func (b BondMode) String() string

type BondPrimaryReselect

type BondPrimaryReselect int

BondPrimaryReselect type

const (
	BOND_PRIMARY_RESELECT_ALWAYS BondPrimaryReselect = iota
	BOND_PRIMARY_RESELECT_BETTER
	BOND_PRIMARY_RESELECT_FAILURE
)

Possible BondPrimaryReselect value

func (BondPrimaryReselect) String added in v1.2.1

func (b BondPrimaryReselect) String() string

type BondSlave added in v1.1.0

type BondSlave struct {
	State                  BondSlaveState
	MiiStatus              BondSlaveMiiStatus
	LinkFailureCount       uint32
	PermHardwareAddr       net.HardwareAddr
	QueueId                uint16
	AggregatorId           uint16
	AdActorOperPortState   uint8
	AdPartnerOperPortState uint16
}

func (*BondSlave) SlaveType added in v1.1.0

func (b *BondSlave) SlaveType() string

type BondSlaveMiiStatus added in v1.1.0

type BondSlaveMiiStatus uint8

BondSlaveMiiStatus represents the values of the IFLA_BOND_SLAVE_MII_STATUS bond slave attribute, which contains the status of MII link monitoring

const (
	//BondLinkUp link is up and running.
	BondLinkUp BondSlaveMiiStatus = iota
	//BondLinkFail link has just gone down.
	BondLinkFail
	//BondLinkDown link has been down for too long time.
	BondLinkDown
	//BondLinkBack link is going back.
	BondLinkBack
)

func (BondSlaveMiiStatus) String added in v1.1.0

func (s BondSlaveMiiStatus) String() string

type BondSlaveState added in v1.1.0

type BondSlaveState uint8

BondSlaveState represents the values of the IFLA_BOND_SLAVE_STATE bond slave attribute, which contains the state of the bond slave.

const (
	//BondStateActive Link is active.
	BondStateActive BondSlaveState = iota
	//BondStateBackup Link is backup.
	BondStateBackup
)

func (BondSlaveState) String added in v1.1.0

func (s BondSlaveState) String() string

type BondXmitHashPolicy

type BondXmitHashPolicy int

BondXmitHashPolicy type

const (
	BOND_XMIT_HASH_POLICY_LAYER2 BondXmitHashPolicy = iota
	BOND_XMIT_HASH_POLICY_LAYER3_4
	BOND_XMIT_HASH_POLICY_LAYER2_3
	BOND_XMIT_HASH_POLICY_ENCAP2_3
	BOND_XMIT_HASH_POLICY_ENCAP3_4
	BOND_XMIT_HASH_POLICY_VLAN_SRCMAC
	BOND_XMIT_HASH_POLICY_UNKNOWN
)

Possible BondXmitHashPolicy value

func StringToBondXmitHashPolicy

func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy

StringToBondXmitHashPolicy returns bond lacp arte, or unknown is the s is invalid.

func (BondXmitHashPolicy) String

func (b BondXmitHashPolicy) String() string

type BpfAction

type BpfAction struct {
	ActionAttrs
	Fd   int
	Name string
}

func (*BpfAction) Attrs

func (action *BpfAction) Attrs() *ActionAttrs

func (*BpfAction) Type

func (action *BpfAction) Type() string

type BpfFilter

type BpfFilter struct {
	FilterAttrs
	ClassId      uint32
	Fd           int
	Name         string
	DirectAction bool
	Id           int
	Tag          string
}

func (*BpfFilter) Attrs

func (filter *BpfFilter) Attrs() *FilterAttrs

func (*BpfFilter) Type

func (filter *BpfFilter) Type() string

type Bridge

type Bridge struct {
	LinkAttrs
	MulticastSnooping *bool
	AgeingTime        *uint32
	HelloTime         *uint32
	VlanFiltering     *bool
	VlanDefaultPVID   *uint16
	GroupFwdMask      *uint16
}

Bridge links are simple linux bridges

func (*Bridge) Attrs

func (bridge *Bridge) Attrs() *LinkAttrs

func (*Bridge) Type

func (bridge *Bridge) Type() string

type Can added in v1.2.1

type Can struct {
	LinkAttrs

	BitRate            uint32
	SamplePoint        uint32
	TimeQuanta         uint32
	PropagationSegment uint32
	PhaseSegment1      uint32
	PhaseSegment2      uint32
	SyncJumpWidth      uint32
	BitRatePreScaler   uint32

	Name                string
	TimeSegment1Min     uint32
	TimeSegment1Max     uint32
	TimeSegment2Min     uint32
	TimeSegment2Max     uint32
	SyncJumpWidthMax    uint32
	BitRatePreScalerMin uint32
	BitRatePreScalerMax uint32
	BitRatePreScalerInc uint32

	ClockFrequency uint32

	State uint32

	Mask  uint32
	Flags uint32

	TxError uint16
	RxError uint16

	RestartMs uint32
}

func (*Can) Attrs added in v1.2.1

func (can *Can) Attrs() *LinkAttrs

func (*Can) Type added in v1.2.1

func (can *Can) Type() string

type Chain added in v1.2.1

type Chain struct {
	Parent uint32
	Chain  uint32
}

Chain contains the attributes of a Chain

func NewChain added in v1.2.1

func NewChain(parent uint32, chain uint32) Chain

func (Chain) String added in v1.2.1

func (c Chain) String() string

type Class

type Class interface {
	Attrs() *ClassAttrs
	Type() string
}

Class interfaces for all classes

type ClassAttrs

type ClassAttrs struct {
	LinkIndex  int
	Handle     uint32
	Parent     uint32
	Leaf       uint32
	Statistics *ClassStatistics
}

ClassAttrs represents a netlink class. A filter is associated with a link, has a handle and a parent. The root filter of a device should have a parent == HANDLE_ROOT.

func (ClassAttrs) String

func (q ClassAttrs) String() string

type ClassStatistics added in v1.1.0

type ClassStatistics struct {
	Basic   *GnetStatsBasic
	Queue   *GnetStatsQueue
	RateEst *GnetStatsRateEst
	BasicHw *GnetStatsBasic // Hardward statistics added in kernel 4.20
}

ClassStatistics representation based on generic networking statistics for netlink. See Documentation/networking/gen_stats.txt in Linux source code for more details.

func NewClassStatistics added in v1.1.0

func NewClassStatistics() *ClassStatistics

NewClassStatistics Construct a ClassStatistics struct which fields are all initialized by 0.

type Clsact added in v1.2.1

type Clsact struct {
	QdiscAttrs
}

Clsact is a qdisc for adding filters

func (*Clsact) Attrs added in v1.2.1

func (qdisc *Clsact) Attrs() *QdiscAttrs

func (*Clsact) Type added in v1.2.1

func (qdisc *Clsact) Type() string

type ConnmarkAction added in v1.1.0

type ConnmarkAction struct {
	ActionAttrs
	Zone uint16
}

func NewConnmarkAction added in v1.1.0

func NewConnmarkAction() *ConnmarkAction

func (*ConnmarkAction) Attrs added in v1.1.0

func (action *ConnmarkAction) Attrs() *ActionAttrs

func (*ConnmarkAction) Type added in v1.1.0

func (action *ConnmarkAction) Type() string

type ConntrackFilter

type ConntrackFilter struct{}

ConntrackFilter placeholder

type ConntrackFlow

type ConntrackFlow struct{}

ConntrackFlow placeholder

func ConntrackTableList

func ConntrackTableList(table ConntrackTableType, family InetFamily) ([]*ConntrackFlow, error)

ConntrackTableList returns the flow list of a table of a specific family conntrack -L [table] [options] List conntrack or expectation table

type ConntrackTableType

type ConntrackTableType uint8

ConntrackTableType Conntrack table for the netlink operation

type CsumAction added in v1.2.1

type CsumAction struct {
	ActionAttrs
	UpdateFlags CsumUpdateFlags
}

func NewCsumAction added in v1.2.1

func NewCsumAction() *CsumAction

func (*CsumAction) Attrs added in v1.2.1

func (action *CsumAction) Attrs() *ActionAttrs

func (*CsumAction) Type added in v1.2.1

func (action *CsumAction) Type() string

type CsumUpdateFlags added in v1.2.1

type CsumUpdateFlags uint32
const (
	TCA_CSUM_UPDATE_FLAG_IPV4HDR CsumUpdateFlags = 1
	TCA_CSUM_UPDATE_FLAG_ICMP    CsumUpdateFlags = 2
	TCA_CSUM_UPDATE_FLAG_IGMP    CsumUpdateFlags = 4
	TCA_CSUM_UPDATE_FLAG_TCP     CsumUpdateFlags = 8
	TCA_CSUM_UPDATE_FLAG_UDP     CsumUpdateFlags = 16
	TCA_CSUM_UPDATE_FLAG_UDPLITE CsumUpdateFlags = 32
	TCA_CSUM_UPDATE_FLAG_SCTP    CsumUpdateFlags = 64
)

type CustomConntrackFilter added in v1.3.0

type CustomConntrackFilter struct{}

CustomConntrackFilter placeholder

type Destination

type Destination interface {
	Family() int
	Decode([]byte) error
	Encode() ([]byte, error)
	String() string
	Equal(Destination) bool
}

type Device

type Device struct {
	LinkAttrs
}

Device links cannot be created via netlink. These links are links created by udev like 'lo' and 'etho0'

func (*Device) Attrs

func (device *Device) Attrs() *LinkAttrs

func (*Device) Type

func (device *Device) Type() string

type Dummy

type Dummy struct {
	LinkAttrs
}

Dummy links are dummy ethernet devices

func (*Dummy) Attrs

func (dummy *Dummy) Attrs() *LinkAttrs

func (*Dummy) Type

func (dummy *Dummy) Type() string

type Encap

type Encap interface {
	Type() int
	Decode([]byte) error
	Encode() ([]byte, error)
	String() string
	Equal(Encap) bool
}

type Filter

type Filter interface {
	Attrs() *FilterAttrs
	Type() string
}

type FilterAttrs

type FilterAttrs struct {
	LinkIndex int
	Handle    uint32
	Parent    uint32
	Priority  uint16 // lower is higher priority
	Protocol  uint16 // unix.ETH_P_*
	Chain     *uint32
}

FilterAttrs represents a netlink filter. A filter is associated with a link, has a handle and a parent. The root filter of a device should have a parent == HANDLE_ROOT.

func (FilterAttrs) String

func (q FilterAttrs) String() string

type Fou

type Fou struct {
	Family    int
	Port      int
	Protocol  int
	EncapType int
}

func FouList

func FouList(fam int) ([]Fou, error)

type Fq

type Fq struct {
	QdiscAttrs
	PacketLimit     uint32
	FlowPacketLimit uint32
	// In bytes
	Quantum        uint32
	InitialQuantum uint32
	// called RateEnable under the hood
	Pacing          uint32
	FlowDefaultRate uint32
	FlowMaxRate     uint32
	// called BucketsLog under the hood
	Buckets           uint32
	FlowRefillDelay   uint32
	LowRateThreshold  uint32
	Horizon           uint32
	HorizonDropPolicy uint8
}

Fq is a classless packet scheduler meant to be mostly used for locally generated traffic.

func NewFq

func NewFq(attrs QdiscAttrs) *Fq

func (*Fq) Attrs

func (qdisc *Fq) Attrs() *QdiscAttrs

func (*Fq) String added in v1.1.0

func (fq *Fq) String() string

func (*Fq) Type

func (qdisc *Fq) Type() string

type FqCodel

type FqCodel struct {
	QdiscAttrs
	Target        uint32
	Limit         uint32
	Interval      uint32
	ECN           uint32
	Flows         uint32
	Quantum       uint32
	CEThreshold   uint32
	DropBatchSize uint32
	MemoryLimit   uint32
}

FQ_Codel (Fair Queuing Controlled Delay) is queuing discipline that combines Fair Queuing with the CoDel AQM scheme.

func NewFqCodel

func NewFqCodel(attrs QdiscAttrs) *FqCodel

func (*FqCodel) Attrs

func (qdisc *FqCodel) Attrs() *QdiscAttrs

func (*FqCodel) String added in v1.1.0

func (fqcodel *FqCodel) String() string

func (*FqCodel) Type

func (qdisc *FqCodel) Type() string

type FwFilter added in v1.2.1

type FwFilter struct {
	FilterAttrs
	ClassId uint32
	InDev   string
	Mask    uint32
	Police  *PoliceAction
	Actions []Action
}

func (*FwFilter) Attrs added in v1.2.1

func (filter *FwFilter) Attrs() *FilterAttrs

func (*FwFilter) Type added in v1.2.1

func (filter *FwFilter) Type() string

type GTP

type GTP struct {
	LinkAttrs
	FD0         int
	FD1         int
	Role        int
	PDPHashsize int
}

func (*GTP) Attrs

func (gtp *GTP) Attrs() *LinkAttrs

func (*GTP) Type

func (gtp *GTP) Type() string

type GenericAction

type GenericAction struct {
	ActionAttrs
	Chain int32
}

func (*GenericAction) Attrs

func (action *GenericAction) Attrs() *ActionAttrs

func (*GenericAction) Type

func (action *GenericAction) Type() string

type GenericClass

type GenericClass struct {
	ClassAttrs
	ClassType string
}

GenericClass classes represent types that are not currently understood by this netlink library.

func (*GenericClass) Attrs

func (class *GenericClass) Attrs() *ClassAttrs

Attrs return the class attributes

func (*GenericClass) Type

func (class *GenericClass) Type() string

Type return the class type

type GenericFilter

type GenericFilter struct {
	FilterAttrs
	FilterType string
}

GenericFilter filters represent types that are not currently understood by this netlink library.

func (*GenericFilter) Attrs

func (filter *GenericFilter) Attrs() *FilterAttrs

func (*GenericFilter) Type

func (filter *GenericFilter) Type() string
type GenericLink struct {
	LinkAttrs
	LinkType string
}

GenericLink links represent types that are not currently understood by this netlink library.

func (*GenericLink) Attrs

func (generic *GenericLink) Attrs() *LinkAttrs

func (*GenericLink) Type

func (generic *GenericLink) Type() string

type GenericQdisc

type GenericQdisc struct {
	QdiscAttrs
	QdiscType string
}

GenericQdisc qdiscs represent types that are not currently understood by this netlink library.

func (*GenericQdisc) Attrs

func (qdisc *GenericQdisc) Attrs() *QdiscAttrs

func (*GenericQdisc) Type

func (qdisc *GenericQdisc) Type() string

type Geneve added in v1.2.1

type Geneve struct {
	LinkAttrs
	ID                uint32 // vni
	Remote            net.IP
	Ttl               uint8
	Tos               uint8
	Dport             uint16
	UdpCsum           uint8
	UdpZeroCsum6Tx    uint8
	UdpZeroCsum6Rx    uint8
	Link              uint32
	FlowBased         bool
	InnerProtoInherit bool
	Df                GeneveDf
}

Geneve devices must specify RemoteIP and ID (VNI) on create https://github.com/torvalds/linux/blob/47ec5303d73ea344e84f46660fff693c57641386/drivers/net/geneve.c#L1209-L1223

func (*Geneve) Attrs added in v1.2.1

func (geneve *Geneve) Attrs() *LinkAttrs

func (*Geneve) Type added in v1.2.1

func (geneve *Geneve) Type() string

type GeneveDf added in v1.2.1

type GeneveDf uint8
const (
	GENEVE_DF_UNSET GeneveDf = iota
	GENEVE_DF_SET
	GENEVE_DF_INHERIT
	GENEVE_DF_MAX
)

type GenlFamily

type GenlFamily struct{}

func GenlFamilyGet

func GenlFamilyGet(name string) (*GenlFamily, error)

func GenlFamilyList

func GenlFamilyList() ([]*GenlFamily, error)

type GenlMulticastGroup

type GenlMulticastGroup struct{}

type GenlOp

type GenlOp struct{}

type GnetStatsBasic added in v1.1.0

type GnetStatsBasic struct {
	Bytes   uint64 // number of seen bytes
	Packets uint32 // number of seen packets
}

GnetStatsBasic Ref: struct gnet_stats_basic { ... }

type GnetStatsQueue added in v1.1.0

type GnetStatsQueue struct {
	Qlen       uint32 // queue length
	Backlog    uint32 // backlog size of queue
	Drops      uint32 // number of dropped packets
	Requeues   uint32 // number of requues
	Overlimits uint32 // number of enqueues over the limit
}

GnetStatsQueue Ref: struct gnet_stats_queue { ... }

type GnetStatsRateEst added in v1.1.0

type GnetStatsRateEst struct {
	Bps uint32 // current byte rate
	Pps uint32 // current packet rate
}

GnetStatsRateEst Ref: struct gnet_stats_rate_est { ... }

type GnetStatsRateEst64 added in v1.1.0

type GnetStatsRateEst64 struct {
	Bps uint64 // current byte rate
	Pps uint64 // current packet rate
}

GnetStatsRateEst64 Ref: struct gnet_stats_rate_est64 { ... }

type Gretap

type Gretap struct {
	LinkAttrs
	IKey       uint32
	OKey       uint32
	EncapSport uint16
	EncapDport uint16
	Local      net.IP
	Remote     net.IP
	IFlags     uint16
	OFlags     uint16
	PMtuDisc   uint8
	Ttl        uint8
	Tos        uint8
	EncapType  uint16
	EncapFlags uint16
	Link       uint32
	FlowBased  bool
}

Gretap devices must specify LocalIP and RemoteIP on create

func (*Gretap) Attrs

func (gretap *Gretap) Attrs() *LinkAttrs

func (*Gretap) Type

func (gretap *Gretap) Type() string

type Gretun

type Gretun struct {
	LinkAttrs
	Link       uint32
	IFlags     uint16
	OFlags     uint16
	IKey       uint32
	OKey       uint32
	Local      net.IP
	Remote     net.IP
	Ttl        uint8
	Tos        uint8
	PMtuDisc   uint8
	EncapType  uint16
	EncapFlags uint16
	EncapSport uint16
	EncapDport uint16
	FlowBased  bool
}

func (*Gretun) Attrs

func (gretun *Gretun) Attrs() *LinkAttrs

func (*Gretun) Type

func (gretun *Gretun) Type() string

type Handle

type Handle struct{}

func NewHandle

func NewHandle(nlFamilies ...int) (*Handle, error)

func NewHandleAt

func NewHandleAt(ns netns.NsHandle, nlFamilies ...int) (*Handle, error)

func NewHandleAtFrom

func NewHandleAtFrom(newNs, curNs netns.NsHandle) (*Handle, error)

func (*Handle) AddrAdd

func (h *Handle) AddrAdd(link Link, addr *Addr) error

func (*Handle) AddrDel

func (h *Handle) AddrDel(link Link, addr *Addr) error

func (*Handle) AddrList

func (h *Handle) AddrList(link Link, family int) ([]Addr, error)

func (*Handle) ClassAdd

func (h *Handle) ClassAdd(class Class) error

func (*Handle) ClassChange

func (h *Handle) ClassChange(class Class) error

func (*Handle) ClassDel

func (h *Handle) ClassDel(class Class) error

func (*Handle) ClassList

func (h *Handle) ClassList(link Link, parent uint32) ([]Class, error)

func (*Handle) ClassReplace

func (h *Handle) ClassReplace(class Class) error

func (*Handle) Close added in v1.2.1

func (h *Handle) Close()

func (*Handle) ConntrackDeleteFilter deprecated

func (h *Handle) ConntrackDeleteFilter(table ConntrackTableType, family InetFamily, filter *ConntrackFilter) (uint, error)

ConntrackDeleteFilter deletes entries on the specified table on the base of the filter using the netlink handle passed conntrack -D [table] parameters Delete conntrack or expectation

Deprecated: use Handle.ConntrackDeleteFilters instead.

func (*Handle) ConntrackDeleteFilters added in v1.3.0

func (h *Handle) ConntrackDeleteFilters(table ConntrackTableType, family InetFamily, filters ...CustomConntrackFilter) (uint, error)

ConntrackDeleteFilters deletes entries on the specified table matching any of the specified filters using the netlink handle passed conntrack -D [table] parameters Delete conntrack or expectation

func (*Handle) ConntrackTableFlush

func (h *Handle) ConntrackTableFlush(table ConntrackTableType) error

ConntrackTableFlush flushes all the flows of a specified table using the netlink handle passed conntrack -F [table] Flush table The flush operation applies to all the family types

func (*Handle) ConntrackTableList

func (h *Handle) ConntrackTableList(table ConntrackTableType, family InetFamily) ([]*ConntrackFlow, error)

ConntrackTableList returns the flow list of a table of a specific family using the netlink handle passed conntrack -L [table] [options] List conntrack or expectation table

func (*Handle) Delete

func (h *Handle) Delete()

func (*Handle) FilterAdd

func (h *Handle) FilterAdd(filter Filter) error

func (*Handle) FilterDel

func (h *Handle) FilterDel(filter Filter) error

func (*Handle) FilterList

func (h *Handle) FilterList(link Link, parent uint32) ([]Filter, error)

func (*Handle) GenlFamilyGet

func (h *Handle) GenlFamilyGet(name string) (*GenlFamily, error)

func (*Handle) GenlFamilyList

func (h *Handle) GenlFamilyList() ([]*GenlFamily, error)

func (*Handle) LinkAdd

func (h *Handle) LinkAdd(link Link) error

func (*Handle) LinkByAlias

func (h *Handle) LinkByAlias(alias string) (Link, error)

func (*Handle) LinkByIndex

func (h *Handle) LinkByIndex(index int) (Link, error)

func (*Handle) LinkByName

func (h *Handle) LinkByName(name string) (Link, error)

func (*Handle) LinkDel

func (h *Handle) LinkDel(link Link) error
func (h *Handle) LinkList() ([]Link, error)

func (*Handle) LinkSetAlias

func (h *Handle) LinkSetAlias(link Link, name string) error

func (*Handle) LinkSetDown

func (h *Handle) LinkSetDown(link Link) error

func (*Handle) LinkSetFastLeave

func (h *Handle) LinkSetFastLeave(link Link, mode bool) error

func (*Handle) LinkSetFlood

func (h *Handle) LinkSetFlood(link Link, mode bool) error

func (*Handle) LinkSetGROIPv4MaxSize added in v1.2.1

func (h *Handle) LinkSetGROIPv4MaxSize(link Link, maxSize int) error

func (*Handle) LinkSetGROMaxSize added in v1.2.1

func (h *Handle) LinkSetGROMaxSize(link Link, maxSize int) error

func (*Handle) LinkSetGSOIPv4MaxSize added in v1.2.1

func (h *Handle) LinkSetGSOIPv4MaxSize(link Link, maxSize int) error

func (*Handle) LinkSetGSOMaxSize added in v1.2.1

func (h *Handle) LinkSetGSOMaxSize(link Link, maxSize int) error

func (*Handle) LinkSetGroup added in v1.1.0

func (h *Handle) LinkSetGroup(link Link, group int) error

func (*Handle) LinkSetGuard

func (h *Handle) LinkSetGuard(link Link, mode bool) error

func (*Handle) LinkSetHairpin

func (h *Handle) LinkSetHairpin(link Link, mode bool) error

func (*Handle) LinkSetHardwareAddr

func (h *Handle) LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error

func (*Handle) LinkSetLearning

func (h *Handle) LinkSetLearning(link Link, mode bool) error

func (*Handle) LinkSetMTU

func (h *Handle) LinkSetMTU(link Link, mtu int) error

func (*Handle) LinkSetMaster

func (h *Handle) LinkSetMaster(link Link, master Link) error

func (*Handle) LinkSetMasterByIndex

func (h *Handle) LinkSetMasterByIndex(link Link, masterIndex int) error

func (*Handle) LinkSetName

func (h *Handle) LinkSetName(link Link, name string) error

func (*Handle) LinkSetNoMaster

func (h *Handle) LinkSetNoMaster(link Link) error

func (*Handle) LinkSetNsFd

func (h *Handle) LinkSetNsFd(link Link, fd int) error

func (*Handle) LinkSetNsPid

func (h *Handle) LinkSetNsPid(link Link, nspid int) error

func (*Handle) LinkSetRootBlock

func (h *Handle) LinkSetRootBlock(link Link, mode bool) error

func (*Handle) LinkSetTxQLen

func (h *Handle) LinkSetTxQLen(link Link, qlen int) error

func (*Handle) LinkSetUp

func (h *Handle) LinkSetUp(link Link) error

func (*Handle) LinkSetVfHardwareAddr

func (h *Handle) LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error

func (*Handle) LinkSetVfRate added in v1.1.0

func (h *Handle) LinkSetVfRate(link Link, vf, minRate, maxRate int) error

func (*Handle) LinkSetVfTxRate

func (h *Handle) LinkSetVfTxRate(link Link, vf, rate int) error

func (*Handle) LinkSetVfVlan

func (h *Handle) LinkSetVfVlan(link Link, vf, vlan int) error

func (*Handle) LinkSetVfVlanQos added in v1.1.0

func (h *Handle) LinkSetVfVlanQos(link Link, vf, vlan, qos int) error

func (*Handle) LinkSetVfVlanQosProto added in v1.2.1

func (h *Handle) LinkSetVfVlanQosProto(link Link, vf, vlan, qos, proto int) error

func (*Handle) NeighAdd

func (h *Handle) NeighAdd(neigh *Neigh) error

func (*Handle) NeighAppend

func (h *Handle) NeighAppend(neigh *Neigh) error

func (*Handle) NeighDel

func (h *Handle) NeighDel(neigh *Neigh) error

func (*Handle) NeighList

func (h *Handle) NeighList(linkIndex, family int) ([]Neigh, error)

func (*Handle) NeighProxyList

func (h *Handle) NeighProxyList(linkIndex, family int) ([]Neigh, error)

func (*Handle) NeighSet

func (h *Handle) NeighSet(neigh *Neigh) error

func (*Handle) RouteAdd

func (h *Handle) RouteAdd(route *Route) error

func (*Handle) RouteAppend added in v1.2.1

func (h *Handle) RouteAppend(route *Route) error

func (*Handle) RouteChange added in v1.2.1

func (h *Handle) RouteChange(route *Route) error

func (*Handle) RouteDel

func (h *Handle) RouteDel(route *Route) error

func (*Handle) RouteGet

func (h *Handle) RouteGet(destination net.IP) ([]Route, error)

func (*Handle) RouteList

func (h *Handle) RouteList(link Link, family int) ([]Route, error)

func (*Handle) RouteListFiltered

func (h *Handle) RouteListFiltered(family int, filter *Route, filterMask uint64) ([]Route, error)

func (*Handle) RouteReplace

func (h *Handle) RouteReplace(route *Route) error

func (*Handle) RuleAdd

func (h *Handle) RuleAdd(rule *Rule) error

func (*Handle) RuleDel

func (h *Handle) RuleDel(rule *Rule) error

func (*Handle) RuleList

func (h *Handle) RuleList(family int) ([]Rule, error)

func (*Handle) SetPromiscOff

func (h *Handle) SetPromiscOff(link Link) error

func (*Handle) SetPromiscOn

func (h *Handle) SetPromiscOn(link Link) error

func (*Handle) SetSocketTimeout

func (h *Handle) SetSocketTimeout(to time.Duration) error

func (*Handle) SupportsNetlinkFamily

func (h *Handle) SupportsNetlinkFamily(nlFamily int) bool

type Hfsc added in v1.1.0

type Hfsc struct {
	QdiscAttrs
	Defcls uint16
}

func NewHfsc added in v1.1.0

func NewHfsc(attrs QdiscAttrs) *Hfsc

func (*Hfsc) Attrs added in v1.1.0

func (hfsc *Hfsc) Attrs() *QdiscAttrs

func (*Hfsc) String added in v1.1.0

func (hfsc *Hfsc) String() string

func (*Hfsc) Type added in v1.1.0

func (hfsc *Hfsc) Type() string

type HfscClass added in v1.1.0

type HfscClass struct {
	ClassAttrs
	Rsc ServiceCurve
	Fsc ServiceCurve
	Usc ServiceCurve
}

HfscClass is a representation of the HFSC class

func NewHfscClass added in v1.1.0

func NewHfscClass(attrs ClassAttrs) *HfscClass

NewHfscClass returns a new HFSC struct with the set parameters

func (*HfscClass) Attrs added in v1.1.0

func (hfsc *HfscClass) Attrs() *ClassAttrs

Attrs return the Hfsc parameters

func (*HfscClass) SetFsc added in v1.1.0

func (hfsc *HfscClass) SetFsc(m1 uint32, d uint32, m2 uint32)

SetFsc sets the Fsc curve. The bandwidth (m1 and m2) is specified in bits and the delay in seconds.

func (*HfscClass) SetLS added in v1.1.0

func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32)

SetLS implements the LS from the `tc` CLI. This function behaves the same as if one would set the USC through the `tc` command-line tool. This means bandwidth (m1 and m2) is specified in bits and the delay in ms.

func (*HfscClass) SetRsc added in v1.1.0

func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32)

SetRsc sets the Rsc curve. The bandwidth (m1 and m2) is specified in bits and the delay in seconds.

func (*HfscClass) SetSC added in v1.1.0

func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32)

SetSC implements the SC from the `tc` CLI. This function behaves the same as if one would set the USC through the `tc` command-line tool. This means bandwidth (m1 and m2) is specified in bits and the delay in ms.

func (*HfscClass) SetUL added in v1.1.0

func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32)

SetUL implements the UL from the `tc` CLI. This function behaves the same as if one would set the USC through the `tc` command-line tool. This means bandwidth (m1 and m2) is specified in bits and the delay in ms.

func (*HfscClass) SetUsc added in v1.1.0

func (hfsc *HfscClass) SetUsc(m1 uint32, d uint32, m2 uint32)

SetUsc sets the USC curve. The bandwidth (m1 and m2) is specified in bits and the delay in seconds.

func (*HfscClass) String added in v1.1.0

func (hfsc *HfscClass) String() string

String() returns a string that contains the information and attributes of the HFSC class

func (*HfscClass) Type added in v1.1.0

func (hfsc *HfscClass) Type() string

Type return the type of the class

type Htb

type Htb struct {
	QdiscAttrs
	Version      uint32
	Rate2Quantum uint32
	Defcls       uint32
	Debug        uint32
	DirectPkts   uint32
	DirectQlen   *uint32
}

Htb is a classful qdisc that rate limits based on tokens

func NewHtb

func NewHtb(attrs QdiscAttrs) *Htb

func (*Htb) Attrs

func (qdisc *Htb) Attrs() *QdiscAttrs

func (*Htb) Type

func (qdisc *Htb) Type() string

type HtbClass

type HtbClass struct {
	ClassAttrs
	Rate    uint64
	Ceil    uint64
	Buffer  uint32
	Cbuffer uint32
	Quantum uint32
	Level   uint32
	Prio    uint32
}

HtbClass represents an Htb class

func (*HtbClass) Attrs

func (q *HtbClass) Attrs() *ClassAttrs

Attrs returns the class attributes

func (HtbClass) String

func (q HtbClass) String() string

func (*HtbClass) Type

func (q *HtbClass) Type() string

Type return the class type

type HtbClassAttrs

type HtbClassAttrs struct {
	// TODO handle all attributes
	Rate    uint64
	Ceil    uint64
	Buffer  uint32
	Cbuffer uint32
	Quantum uint32
	Level   uint32
	Prio    uint32
}

HtbClassAttrs stores the attributes of HTB class

func (HtbClassAttrs) String

func (q HtbClassAttrs) String() string

type IPVlan

type IPVlan struct {
	LinkAttrs
	Mode IPVlanMode
	Flag IPVlanFlag
}

func (*IPVlan) Attrs

func (ipvlan *IPVlan) Attrs() *LinkAttrs

func (*IPVlan) Type

func (ipvlan *IPVlan) Type() string

type IPVlanFlag added in v1.1.0

type IPVlanFlag uint16
const (
	IPVLAN_FLAG_BRIDGE IPVlanFlag = iota
	IPVLAN_FLAG_PRIVATE
	IPVLAN_FLAG_VEPA
)

type IPVlanMode

type IPVlanMode uint16
const (
	IPVLAN_MODE_L2 IPVlanMode = iota
	IPVLAN_MODE_L3
	IPVLAN_MODE_L3S
	IPVLAN_MODE_MAX
)

type IPVtap added in v1.2.1

type IPVtap struct {
	IPVlan
}

IPVtap - IPVtap is a virtual interfaces based on ipvlan

func (*IPVtap) Attrs added in v1.2.1

func (ipvtap *IPVtap) Attrs() *LinkAttrs

func (IPVtap) Type added in v1.2.1

func (ipvtap IPVtap) Type() string

type IPoIB added in v1.1.0

type IPoIB struct {
	LinkAttrs
	Pkey   uint16
	Mode   IPoIBMode
	Umcast uint16
}

func (*IPoIB) Attrs added in v1.1.0

func (ipoib *IPoIB) Attrs() *LinkAttrs

func (*IPoIB) Type added in v1.1.0

func (ipoib *IPoIB) Type() string

type IPoIBMode added in v1.1.0

type IPoIBMode uint16

func (*IPoIBMode) String added in v1.1.0

func (m *IPoIBMode) String() string

type Ifb

type Ifb struct {
	LinkAttrs
}

Ifb links are advanced dummy devices for packet filtering

func (*Ifb) Attrs

func (ifb *Ifb) Attrs() *LinkAttrs

func (*Ifb) Type

func (ifb *Ifb) Type() string

type InetDiagTCPInfoResp added in v1.2.1

type InetDiagTCPInfoResp struct {
	InetDiagMsg *Socket
	TCPInfo     *TCPInfo
	TCPBBRInfo  *TCPBBRInfo
}

type InetDiagUDPInfoResp added in v1.2.1

type InetDiagUDPInfoResp struct {
	InetDiagMsg *Socket
	Memory      *MemInfo
}

type InetFamily

type InetFamily uint8

InetFamily Family type

type Ingress

type Ingress struct {
	QdiscAttrs
}

Ingress is a qdisc for adding ingress filters

func (*Ingress) Attrs

func (qdisc *Ingress) Attrs() *QdiscAttrs

func (*Ingress) Type

func (qdisc *Ingress) Type() string

type Ip6tnl added in v1.1.0

type Ip6tnl struct {
	LinkAttrs
	Link       uint32
	Local      net.IP
	Remote     net.IP
	Ttl        uint8
	Tos        uint8
	Flags      uint32
	Proto      uint8
	FlowInfo   uint32
	EncapLimit uint8
	EncapType  uint16
	EncapFlags uint16
	EncapSport uint16
	EncapDport uint16
	FlowBased  bool
}

func (*Ip6tnl) Attrs added in v1.1.0

func (ip6tnl *Ip6tnl) Attrs() *LinkAttrs

func (*Ip6tnl) Type added in v1.1.0

func (ip6tnl *Ip6tnl) Type() string

type Iptun

type Iptun struct {
	LinkAttrs
	Ttl        uint8
	Tos        uint8
	PMtuDisc   uint8
	Link       uint32
	Local      net.IP
	Remote     net.IP
	EncapSport uint16
	EncapDport uint16
	EncapType  uint16
	EncapFlags uint16
	FlowBased  bool
	Proto      uint8
}

func (*Iptun) Attrs

func (iptun *Iptun) Attrs() *LinkAttrs

func (*Iptun) Type

func (iptun *Iptun) Type() string
type Link interface {
	Attrs() *LinkAttrs
	Type() string
}

Link represents a link device from netlink. Shared link attributes like name may be retrieved using the Attrs() method. Unique data can be retrieved by casting the object to the proper type.

func LinkByAlias

func LinkByAlias(alias string) (Link, error)

func LinkByIndex

func LinkByIndex(index int) (Link, error)

func LinkByName

func LinkByName(name string) (Link, error)
func LinkList() ([]Link, error)

type LinkAttrs

type LinkAttrs struct {
	Index          int
	MTU            int
	TxQLen         int // Transmit Queue Length
	Name           string
	HardwareAddr   net.HardwareAddr
	Flags          net.Flags
	RawFlags       uint32
	ParentIndex    int         // index of the parent link device
	MasterIndex    int         // must be the index of a bridge
	Namespace      interface{} // nil | NsPid | NsFd
	Alias          string
	AltNames       []string
	Statistics     *LinkStatistics
	Promisc        int
	Allmulti       int
	Multi          int
	Xdp            *LinkXdp
	EncapType      string
	Protinfo       *Protinfo
	OperState      LinkOperState
	PhysSwitchID   int
	NetNsID        int
	NumTxQueues    int
	NumRxQueues    int
	TSOMaxSegs     uint32
	TSOMaxSize     uint32
	GSOMaxSegs     uint32
	GSOMaxSize     uint32
	GROMaxSize     uint32
	GSOIPv4MaxSize uint32
	GROIPv4MaxSize uint32
	Vfs            []VfInfo // virtual functions available on link
	Group          uint32
	PermHWAddr     net.HardwareAddr
	Slave          LinkSlave
}

LinkAttrs represents data shared by most link types

func NewLinkAttrs

func NewLinkAttrs() LinkAttrs

NewLinkAttrs returns LinkAttrs structure filled with default values

type LinkNotFoundError

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

LinkNotFoundError wraps the various not found errors when getting/reading links. This is intended for better error handling by dependent code so that "not found error" can be distinguished from other errors

type LinkOperState

type LinkOperState uint8

LinkOperState represents the values of the IFLA_OPERSTATE link attribute, which contains the RFC2863 state of the interface.

func (LinkOperState) String

func (s LinkOperState) String() string

type LinkSlave added in v1.1.0

type LinkSlave interface {
	SlaveType() string
}

LinkSlave represents a slave device.

type LinkStatistics

type LinkStatistics LinkStatistics64

type LinkStatistics32

type LinkStatistics32 struct {
	RxPackets         uint32
	TxPackets         uint32
	RxBytes           uint32
	TxBytes           uint32
	RxErrors          uint32
	TxErrors          uint32
	RxDropped         uint32
	TxDropped         uint32
	Multicast         uint32
	Collisions        uint32
	RxLengthErrors    uint32
	RxOverErrors      uint32
	RxCrcErrors       uint32
	RxFrameErrors     uint32
	RxFifoErrors      uint32
	RxMissedErrors    uint32
	TxAbortedErrors   uint32
	TxCarrierErrors   uint32
	TxFifoErrors      uint32
	TxHeartbeatErrors uint32
	TxWindowErrors    uint32
	RxCompressed      uint32
	TxCompressed      uint32
}

Ref: struct rtnl_link_stats {...}

type LinkStatistics64

type LinkStatistics64 struct {
	RxPackets         uint64
	TxPackets         uint64
	RxBytes           uint64
	TxBytes           uint64
	RxErrors          uint64
	TxErrors          uint64
	RxDropped         uint64
	TxDropped         uint64
	Multicast         uint64
	Collisions        uint64
	RxLengthErrors    uint64
	RxOverErrors      uint64
	RxCrcErrors       uint64
	RxFrameErrors     uint64
	RxFifoErrors      uint64
	RxMissedErrors    uint64
	TxAbortedErrors   uint64
	TxCarrierErrors   uint64
	TxFifoErrors      uint64
	TxHeartbeatErrors uint64
	TxWindowErrors    uint64
	RxCompressed      uint64
	TxCompressed      uint64
}

Ref: struct rtnl_link_stats64 {...}

type LinkXdp

type LinkXdp struct {
	Fd         int
	Attached   bool
	AttachMode uint32
	Flags      uint32
	ProgId     uint32
}

type Macvlan

type Macvlan struct {
	LinkAttrs
	Mode MacvlanMode

	// MACAddrs is only populated for Macvlan SOURCE links
	MACAddrs []net.HardwareAddr

	BCQueueLen     uint32
	UsedBCQueueLen uint32
}

Macvlan links have ParentIndex set in their Attrs()

func (*Macvlan) Attrs

func (macvlan *Macvlan) Attrs() *LinkAttrs

func (*Macvlan) Type

func (macvlan *Macvlan) Type() string

type MacvlanMode

type MacvlanMode uint16
const (
	MACVLAN_MODE_DEFAULT MacvlanMode = iota
	MACVLAN_MODE_PRIVATE
	MACVLAN_MODE_VEPA
	MACVLAN_MODE_BRIDGE
	MACVLAN_MODE_PASSTHRU
	MACVLAN_MODE_SOURCE
)

type Macvtap

type Macvtap struct {
	Macvlan
}

Macvtap - macvtap is a virtual interfaces based on macvlan

func (Macvtap) Type

func (macvtap Macvtap) Type() string

type MatchAll

type MatchAll struct {
	FilterAttrs
	ClassId uint32
	Actions []Action
}

MatchAll filters match all packets

func (*MatchAll) Attrs

func (filter *MatchAll) Attrs() *FilterAttrs

func (*MatchAll) Type

func (filter *MatchAll) Type() string

type MemInfo added in v1.2.1

type MemInfo struct {
	RMem uint32
	WMem uint32
	FMem uint32
	TMem uint32
}

According to https://man7.org/linux/man-pages/man7/sock_diag.7.html

type MirredAct

type MirredAct uint8
const (
	TCA_EGRESS_REDIR   MirredAct = 1 /* packet redirect to EGRESS*/
	TCA_EGRESS_MIRROR  MirredAct = 2 /* mirror packet to EGRESS */
	TCA_INGRESS_REDIR  MirredAct = 3 /* packet redirect to INGRESS*/
	TCA_INGRESS_MIRROR MirredAct = 4 /* mirror packet to INGRESS */
)

func (MirredAct) String

func (a MirredAct) String() string

type MirredAction

type MirredAction struct {
	ActionAttrs
	MirredAction MirredAct
	Ifindex      int
}

func NewMirredAction

func NewMirredAction(redirIndex int) *MirredAction

func (*MirredAction) Attrs

func (action *MirredAction) Attrs() *ActionAttrs

func (*MirredAction) Type

func (action *MirredAction) Type() string

type Neigh

type Neigh struct {
	LinkIndex    int
	Family       int
	State        int
	Type         int
	Flags        int
	FlagsExt     int
	IP           net.IP
	HardwareAddr net.HardwareAddr
	LLIPAddr     net.IP //Used in the case of NHRP
	Vlan         int
	VNI          int
	MasterIndex  int
}

Neigh represents a link layer neighbor from netlink.

func NeighDeserialize

func NeighDeserialize(m []byte) (*Neigh, error)

func NeighList

func NeighList(linkIndex, family int) ([]Neigh, error)

func (*Neigh) String

func (neigh *Neigh) String() string

String returns $ip/$hwaddr $label

type NeighUpdate added in v1.1.0

type NeighUpdate struct {
	Type uint16
	Neigh
}

NeighUpdate is sent when a neighbor changes - type is RTM_NEWNEIGH or RTM_DELNEIGH.

type Netem

type Netem struct {
	QdiscAttrs
	Latency       uint32
	DelayCorr     uint32
	Limit         uint32
	Loss          uint32
	LossCorr      uint32
	Gap           uint32
	Duplicate     uint32
	DuplicateCorr uint32
	Jitter        uint32
	ReorderProb   uint32
	ReorderCorr   uint32
	CorruptProb   uint32
	CorruptCorr   uint32
	Rate64        uint64
}

func (*Netem) Attrs

func (qdisc *Netem) Attrs() *QdiscAttrs

func (*Netem) String added in v1.1.0

func (netem *Netem) String() string

func (*Netem) Type

func (qdisc *Netem) Type() string

type NetemQdiscAttrs

type NetemQdiscAttrs struct {
	Latency       uint32  // in us
	DelayCorr     float32 // in %
	Limit         uint32
	Loss          float32 // in %
	LossCorr      float32 // in %
	Gap           uint32
	Duplicate     float32 // in %
	DuplicateCorr float32 // in %
	Jitter        uint32  // in us
	ReorderProb   float32 // in %
	ReorderCorr   float32 // in %
	CorruptProb   float32 // in %
	CorruptCorr   float32 // in %
	Rate64        uint64
}

func (NetemQdiscAttrs) String

func (q NetemQdiscAttrs) String() string

type Netkit added in v1.2.1

type Netkit struct {
	LinkAttrs
	Mode       NetkitMode
	Policy     NetkitPolicy
	PeerPolicy NetkitPolicy
	// contains filtered or unexported fields
}

func (*Netkit) Attrs added in v1.2.1

func (n *Netkit) Attrs() *LinkAttrs

func (*Netkit) IsPrimary added in v1.2.1

func (n *Netkit) IsPrimary() bool

func (*Netkit) SetPeerAttrs added in v1.2.1

func (n *Netkit) SetPeerAttrs(Attrs *LinkAttrs)

SetPeerAttrs will not take effect if trying to modify an existing netkit device

func (*Netkit) Type added in v1.2.1

func (n *Netkit) Type() string

type NetkitMode added in v1.2.1

type NetkitMode uint32
const (
	NETKIT_MODE_L2 NetkitMode = iota
	NETKIT_MODE_L3
)

type NetkitPolicy added in v1.2.1

type NetkitPolicy int
const (
	NETKIT_POLICY_FORWARD   NetkitPolicy = 0
	NETKIT_POLICY_BLACKHOLE NetkitPolicy = 2
)

type NextHopFlag

type NextHopFlag int

type NexthopInfo

type NexthopInfo struct {
	LinkIndex int
	Hops      int
	Gw        net.IP
	Flags     int
	NewDst    Destination
	Encap     Encap
	Via       Destination
}

func (NexthopInfo) Equal

func (n NexthopInfo) Equal(x NexthopInfo) bool

func (*NexthopInfo) ListFlags

func (n *NexthopInfo) ListFlags() []string

func (*NexthopInfo) String

func (n *NexthopInfo) String() string

type NsFd

type NsFd int

type NsPid

type NsPid int

type PeditAction added in v1.2.1

type PeditAction struct {
	ActionAttrs
	Proto      uint8
	SrcMacAddr net.HardwareAddr
	DstMacAddr net.HardwareAddr
	SrcIP      net.IP
	DstIP      net.IP
	SrcPort    uint16
	DstPort    uint16
}

func NewPeditAction added in v1.2.1

func NewPeditAction() *PeditAction

func (*PeditAction) Attrs added in v1.2.1

func (p *PeditAction) Attrs() *ActionAttrs

func (*PeditAction) Type added in v1.2.1

func (p *PeditAction) Type() string

type PfifoFast

type PfifoFast struct {
	QdiscAttrs
	Bands       uint8
	PriorityMap [PRIORITY_MAP_LEN]uint8
}

PfifoFast is the default qdisc created by the kernel if one has not been defined for the interface

func (*PfifoFast) Attrs

func (qdisc *PfifoFast) Attrs() *QdiscAttrs

func (*PfifoFast) Type

func (qdisc *PfifoFast) Type() string

type PoliceAction added in v1.2.1

type PoliceAction struct {
	ActionAttrs
	Rate            uint32 // in byte per second
	Burst           uint32 // in byte
	RCellLog        int
	Mtu             uint32
	Mpu             uint16 // in byte
	PeakRate        uint32 // in byte per second
	PCellLog        int
	AvRate          uint32 // in byte per second
	Overhead        uint16
	LinkLayer       int
	ExceedAction    TcPolAct
	NotExceedAction TcPolAct
}

func NewPoliceAction added in v1.2.1

func NewPoliceAction() *PoliceAction

func (*PoliceAction) Attrs added in v1.2.1

func (action *PoliceAction) Attrs() *ActionAttrs

func (*PoliceAction) Type added in v1.2.1

func (action *PoliceAction) Type() string

type Prio

type Prio struct {
	QdiscAttrs
	Bands       uint8
	PriorityMap [PRIORITY_MAP_LEN]uint8
}

Prio is a basic qdisc that works just like PfifoFast

func NewPrio

func NewPrio(attrs QdiscAttrs) *Prio

func (*Prio) Attrs

func (qdisc *Prio) Attrs() *QdiscAttrs

func (*Prio) Type

func (qdisc *Prio) Type() string

type Protinfo

type Protinfo struct {
	Hairpin       bool
	Guard         bool
	FastLeave     bool
	RootBlock     bool
	Learning      bool
	Flood         bool
	ProxyArp      bool
	ProxyArpWiFi  bool
	Isolated      bool
	NeighSuppress bool
}

Protinfo represents bridge flags from netlink.

func (*Protinfo) String

func (prot *Protinfo) String() string

String returns a list of enabled flags

type Qdisc

type Qdisc interface {
	Attrs() *QdiscAttrs
	Type() string
}

type QdiscAttrs

type QdiscAttrs struct {
	LinkIndex    int
	Handle       uint32
	Parent       uint32
	Refcnt       uint32 // read only
	IngressBlock *uint32
	Statistics   *QdiscStatistics
}

QdiscAttrs represents a netlink qdisc. A qdisc is associated with a link, has a handle, a parent and a refcnt. The root qdisc of a device should have parent == HANDLE_ROOT.

func (QdiscAttrs) String

func (q QdiscAttrs) String() string

type QdiscStatistics added in v1.2.1

type QdiscStatistics ClassStatistics

type QueueInfo added in v1.2.1

type QueueInfo struct {
	RQueue uint32
	WQueue uint32
}

type Route

type Route struct {
	LinkIndex        int
	ILinkIndex       int
	Scope            Scope
	Dst              *net.IPNet
	Src              net.IP
	Gw               net.IP
	MultiPath        []*NexthopInfo
	Protocol         RouteProtocol
	Priority         int
	Family           int
	Table            int
	Type             int
	Tos              int
	Flags            int
	MPLSDst          *int
	NewDst           Destination
	Encap            Encap
	Via              Destination
	Realm            int
	MTU              int
	Window           int
	Rtt              int
	RttVar           int
	Ssthresh         int
	Cwnd             int
	AdvMSS           int
	Reordering       int
	Hoplimit         int
	InitCwnd         int
	Features         int
	RtoMin           int
	InitRwnd         int
	QuickACK         int
	Congctl          string
	FastOpenNoCookie int
}

Route represents a netlink route.

func RouteGet added in v1.2.1

func RouteGet(destination net.IP) ([]Route, error)

func RouteList

func RouteList(link Link, family int) ([]Route, error)

func RouteListFiltered added in v1.2.1

func RouteListFiltered(family int, filter *Route, filterMask uint64) ([]Route, error)

func (*Route) ClearFlag

func (r *Route) ClearFlag(flag NextHopFlag)

func (Route) Equal

func (r Route) Equal(x Route) bool

func (*Route) ListFlags

func (r *Route) ListFlags() []string

func (*Route) SetFlag

func (r *Route) SetFlag(flag NextHopFlag)

func (Route) String

func (r Route) String() string

type RouteProtocol added in v1.2.1

type RouteProtocol int

Protocol describe what was the originator of the route

func (RouteProtocol) String added in v1.2.1

func (p RouteProtocol) String() string

type RouteUpdate

type RouteUpdate struct {
	Type    uint16
	NlFlags uint16
	Route
}

NlFlags is only non-zero for RTM_NEWROUTE, the following flags can be set:

  • unix.NLM_F_REPLACE - Replace existing matching config object with this request
  • unix.NLM_F_EXCL - Don't replace the config object if it already exists
  • unix.NLM_F_CREATE - Create config object if it doesn't already exist
  • unix.NLM_F_APPEND - Add to the end of the object list

type Rule

type Rule struct {
	Priority          int
	Family            int
	Table             int
	Mark              uint32
	Mask              *uint32
	Tos               uint
	TunID             uint
	Goto              int
	Src               *net.IPNet
	Dst               *net.IPNet
	Flow              int
	IifName           string
	OifName           string
	SuppressIfgroup   int
	SuppressPrefixlen int
	Invert            bool
	Dport             *RulePortRange
	Sport             *RulePortRange
	IPProto           int
	UIDRange          *RuleUIDRange
	Protocol          uint8
	Type              uint8
}

Rule represents a netlink rule.

func NewRule

func NewRule() *Rule

NewRule return empty rules.

func (Rule) String

func (r Rule) String() string

type RulePortRange added in v1.2.1

type RulePortRange struct {
	Start uint16
	End   uint16
}

RulePortRange represents rule sport/dport range.

func NewRulePortRange added in v1.2.1

func NewRulePortRange(start, end uint16) *RulePortRange

NewRulePortRange creates rule sport/dport range.

type RuleUIDRange added in v1.2.1

type RuleUIDRange struct {
	Start uint32
	End   uint32
}

RuleUIDRange represents rule uid range.

func NewRuleUIDRange added in v1.2.1

func NewRuleUIDRange(start, end uint32) *RuleUIDRange

NewRuleUIDRange creates rule uid range.

type Scope

type Scope uint8

Scope is an enum representing a route scope.

func (Scope) String added in v1.2.1

func (s Scope) String() string

type ServiceCurve added in v1.1.0

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

ServiceCurve is a nondecreasing function of some time unit, returning the amount of service (an allowed or allocated amount of bandwidth) at some specific point in time. The purpose of it should be subconsciously obvious: if a class was allowed to transfer not less than the amount specified by its service curve, then the service curve is not violated.

func (*ServiceCurve) Attrs added in v1.1.0

func (c *ServiceCurve) Attrs() (uint32, uint32, uint32)

Attrs return the parameters of the service curve

func (*ServiceCurve) Burst added in v1.2.1

func (c *ServiceCurve) Burst() uint32

Burst returns the burst rate (m1) of the curve

func (*ServiceCurve) Delay added in v1.2.1

func (c *ServiceCurve) Delay() uint32

Delay return the delay (d) of the curve

func (*ServiceCurve) Rate added in v1.2.1

func (c *ServiceCurve) Rate() uint32

Rate returns the rate (m2) of the curve

type Sfq added in v1.2.1

type Sfq struct {
	QdiscAttrs
	// TODO: Only the simplified options for SFQ are handled here. Support for the extended one can be added later.
	Quantum uint8
	Perturb uint8
	Limit   uint32
	Divisor uint8
}

func (*Sfq) Attrs added in v1.2.1

func (qdisc *Sfq) Attrs() *QdiscAttrs

func (*Sfq) String added in v1.2.1

func (sfq *Sfq) String() string

func (*Sfq) Type added in v1.2.1

func (qdisc *Sfq) Type() string

type Sittun

type Sittun struct {
	LinkAttrs
	Link       uint32
	Ttl        uint8
	Tos        uint8
	PMtuDisc   uint8
	Proto      uint8
	Local      net.IP
	Remote     net.IP
	EncapLimit uint8
	EncapType  uint16
	EncapFlags uint16
	EncapSport uint16
	EncapDport uint16
}

func (*Sittun) Attrs

func (sittun *Sittun) Attrs() *LinkAttrs

func (*Sittun) Type

func (sittun *Sittun) Type() string

type SkbEditAction added in v1.1.0

type SkbEditAction struct {
	ActionAttrs
	QueueMapping *uint16
	PType        *uint16
	Priority     *uint32
	Mark         *uint32
	Mask         *uint32
}

func NewSkbEditAction added in v1.1.0

func NewSkbEditAction() *SkbEditAction

func (*SkbEditAction) Attrs added in v1.1.0

func (action *SkbEditAction) Attrs() *ActionAttrs

func (*SkbEditAction) Type added in v1.1.0

func (action *SkbEditAction) Type() string

type Socket

type Socket struct {
	Family  uint8
	State   uint8
	Timer   uint8
	Retrans uint8
	ID      SocketID
	Expires uint32
	RQueue  uint32
	WQueue  uint32
	UID     uint32
	INode   uint32
}

Socket represents a netlink socket.

func SocketDestroy added in v1.2.1

func SocketDestroy(local, remote net.Addr) (*Socket, error)

func SocketGet

func SocketGet(local, remote net.Addr) (*Socket, error)

type SocketID

type SocketID struct {
	SourcePort      uint16
	DestinationPort uint16
	Source          net.IP
	Destination     net.IP
	Interface       uint32
	Cookie          [2]uint32
}

SocketID identifies a single socket.

type TCPBBRInfo added in v1.2.1

type TCPBBRInfo struct {
	BBRBW         uint64
	BBRMinRTT     uint32
	BBRPacingGain uint32
	BBRCwndGain   uint32
}

type TCPInfo added in v1.2.1

type TCPInfo struct {
	State                     uint8
	Ca_state                  uint8
	Retransmits               uint8
	Probes                    uint8
	Backoff                   uint8
	Options                   uint8
	Snd_wscale                uint8 // no uint4
	Rcv_wscale                uint8
	Delivery_rate_app_limited uint8
	Fastopen_client_fail      uint8
	Rto                       uint32
	Ato                       uint32
	Snd_mss                   uint32
	Rcv_mss                   uint32
	Unacked                   uint32
	Sacked                    uint32
	Lost                      uint32
	Retrans                   uint32
	Fackets                   uint32
	Last_data_sent            uint32
	Last_ack_sent             uint32
	Last_data_recv            uint32
	Last_ack_recv             uint32
	Pmtu                      uint32
	Rcv_ssthresh              uint32
	Rtt                       uint32
	Rttvar                    uint32
	Snd_ssthresh              uint32
	Snd_cwnd                  uint32
	Advmss                    uint32
	Reordering                uint32
	Rcv_rtt                   uint32
	Rcv_space                 uint32
	Total_retrans             uint32
	Pacing_rate               uint64
	Max_pacing_rate           uint64
	Bytes_acked               uint64 /* RFC4898 tcpEStatsAppHCThruOctetsAcked */
	Bytes_received            uint64 /* RFC4898 tcpEStatsAppHCThruOctetsReceived */
	Segs_out                  uint32 /* RFC4898 tcpEStatsPerfSegsOut */
	Segs_in                   uint32 /* RFC4898 tcpEStatsPerfSegsIn */
	Notsent_bytes             uint32
	Min_rtt                   uint32
	Data_segs_in              uint32 /* RFC4898 tcpEStatsDataSegsIn */
	Data_segs_out             uint32 /* RFC4898 tcpEStatsDataSegsOut */
	Delivery_rate             uint64
	Busy_time                 uint64 /* Time (usec) busy sending data */
	Rwnd_limited              uint64 /* Time (usec) limited by receive window */
	Sndbuf_limited            uint64 /* Time (usec) limited by send buffer */
	Delivered                 uint32
	Delivered_ce              uint32
	Bytes_sent                uint64 /* RFC4898 tcpEStatsPerfHCDataOctetsOut */
	Bytes_retrans             uint64 /* RFC4898 tcpEStatsPerfOctetsRetrans */
	Dsack_dups                uint32 /* RFC4898 tcpEStatsStackDSACKDups */
	Reord_seen                uint32 /* reordering events seen */
	Rcv_ooopack               uint32 /* Out-of-order packets received */
	Snd_wnd                   uint32 /* peer's advertised receive window after * scaling (bytes) */
}

type Tbf

type Tbf struct {
	QdiscAttrs
	Rate     uint64
	Limit    uint32
	Buffer   uint32
	Peakrate uint64
	Minburst uint32
}

Tbf is a classless qdisc that rate limits based on tokens

func (*Tbf) Attrs

func (qdisc *Tbf) Attrs() *QdiscAttrs

func (*Tbf) Type

func (qdisc *Tbf) Type() string

type TcAct

type TcAct int32
const (
	TC_ACT_UNSPEC     TcAct = -1
	TC_ACT_OK         TcAct = 0
	TC_ACT_RECLASSIFY TcAct = 1
	TC_ACT_SHOT       TcAct = 2
	TC_ACT_PIPE       TcAct = 3
	TC_ACT_STOLEN     TcAct = 4
	TC_ACT_QUEUED     TcAct = 5
	TC_ACT_REPEAT     TcAct = 6
	TC_ACT_REDIRECT   TcAct = 7
	TC_ACT_JUMP       TcAct = 0x10000000
)

func (TcAct) String

func (a TcAct) String() string

type TcPolAct

type TcPolAct int32
const (
	TC_POLICE_UNSPEC     TcPolAct = TcPolAct(TC_ACT_UNSPEC)
	TC_POLICE_OK         TcPolAct = TcPolAct(TC_ACT_OK)
	TC_POLICE_RECLASSIFY TcPolAct = TcPolAct(TC_ACT_RECLASSIFY)
	TC_POLICE_SHOT       TcPolAct = TcPolAct(TC_ACT_SHOT)
	TC_POLICE_PIPE       TcPolAct = TcPolAct(TC_ACT_PIPE)
)

func (TcPolAct) String

func (a TcPolAct) String() string

type TunnelKeyAct added in v1.1.0

type TunnelKeyAct int8
const (
	TCA_TUNNEL_KEY_SET   TunnelKeyAct = 1 // set tunnel key
	TCA_TUNNEL_KEY_UNSET TunnelKeyAct = 2 // unset tunnel key
)

type TunnelKeyAction added in v1.1.0

type TunnelKeyAction struct {
	ActionAttrs
	Action   TunnelKeyAct
	SrcAddr  net.IP
	DstAddr  net.IP
	KeyID    uint32
	DestPort uint16
}

func NewTunnelKeyAction added in v1.1.0

func NewTunnelKeyAction() *TunnelKeyAction

func (*TunnelKeyAction) Attrs added in v1.1.0

func (action *TunnelKeyAction) Attrs() *ActionAttrs

func (*TunnelKeyAction) Type added in v1.1.0

func (action *TunnelKeyAction) Type() string

type Tuntap

type Tuntap struct {
	LinkAttrs
	Mode       TuntapMode
	Flags      TuntapFlag
	NonPersist bool
	Queues     int
	Fds        []*os.File
	Owner      uint32
	Group      uint32
}

Tuntap links created via /dev/tun/tap, but can be destroyed via netlink

func (*Tuntap) Attrs

func (tuntap *Tuntap) Attrs() *LinkAttrs

func (*Tuntap) Type

func (tuntap *Tuntap) Type() string

type TuntapFlag

type TuntapFlag uint16

type TuntapMode

type TuntapMode uint16

type UnixDiagInfoResp added in v1.2.1

type UnixDiagInfoResp struct {
	DiagMsg  *UnixSocket
	Name     *string
	Peer     *uint32
	Queue    *QueueInfo
	Shutdown *uint8
}

type UnixSocket added in v1.2.1

type UnixSocket struct {
	Type   uint8
	Family uint8
	State  uint8

	INode  uint32
	Cookie [2]uint32
	// contains filtered or unexported fields
}

UnixSocket represents a netlink unix socket.

type Veth

type Veth struct {
	LinkAttrs
	PeerName         string // veth on create only
	PeerHardwareAddr net.HardwareAddr
	PeerNamespace    interface{}
}

Veth devices must specify PeerName on create

func (*Veth) Attrs

func (veth *Veth) Attrs() *LinkAttrs

func (*Veth) Type

func (veth *Veth) Type() string

type VfInfo added in v1.1.0

type VfInfo struct {
	ID        int
	Mac       net.HardwareAddr
	Vlan      int
	Qos       int
	VlanProto int
	TxRate    int // IFLA_VF_TX_RATE  Max TxRate
	Spoofchk  bool
	LinkState uint32
	MaxTxRate uint32 // IFLA_VF_RATE Max TxRate
	MinTxRate uint32 // IFLA_VF_RATE Min TxRate
	RxPackets uint64
	TxPackets uint64
	RxBytes   uint64
	TxBytes   uint64
	Multicast uint64
	Broadcast uint64
	RxDropped uint64
	TxDropped uint64

	RssQuery uint32
	Trust    uint32
}

VfInfo represents configuration of virtual function

type Vlan

type Vlan struct {
	LinkAttrs
	VlanId       int
	VlanProtocol VlanProtocol
}

Vlan links have ParentIndex set in their Attrs()

func (*Vlan) Attrs

func (vlan *Vlan) Attrs() *LinkAttrs

func (*Vlan) Type

func (vlan *Vlan) Type() string

type VlanProtocol added in v1.1.0

type VlanProtocol int

VlanProtocol type

const (
	VLAN_PROTOCOL_UNKNOWN VlanProtocol = 0
	VLAN_PROTOCOL_8021Q   VlanProtocol = 0x8100
	VLAN_PROTOCOL_8021AD  VlanProtocol = 0x88A8
)

VlanProtocol possible values

func StringToVlanProtocol added in v1.1.0

func StringToVlanProtocol(s string) VlanProtocol

StringToVlanProtocol returns vlan protocol, or unknown is the s is invalid.

func (VlanProtocol) String added in v1.1.0

func (p VlanProtocol) String() string

type Vrf

type Vrf struct {
	LinkAttrs
	Table uint32
}

func (*Vrf) Attrs

func (vrf *Vrf) Attrs() *LinkAttrs

func (*Vrf) Type

func (vrf *Vrf) Type() string

type VrfSlave added in v1.2.1

type VrfSlave struct {
	Table uint32
}

func (*VrfSlave) SlaveType added in v1.2.1

func (v *VrfSlave) SlaveType() string

type Vti

type Vti struct {
	LinkAttrs
	IKey   uint32
	OKey   uint32
	Link   uint32
	Local  net.IP
	Remote net.IP
}

func (*Vti) Attrs

func (vti *Vti) Attrs() *LinkAttrs

func (*Vti) Type

func (vti *Vti) Type() string

type Vxlan

type Vxlan struct {
	LinkAttrs
	VxlanId        int
	VtepDevIndex   int
	SrcAddr        net.IP
	Group          net.IP
	TTL            int
	TOS            int
	Learning       bool
	Proxy          bool
	RSC            bool
	L2miss         bool
	L3miss         bool
	UDPCSum        bool
	UDP6ZeroCSumTx bool
	UDP6ZeroCSumRx bool
	NoAge          bool
	GBP            bool
	FlowBased      bool
	Age            int
	Limit          int
	Port           int
	PortLow        int
	PortHigh       int
}

func (*Vxlan) Attrs

func (vxlan *Vxlan) Attrs() *LinkAttrs

func (*Vxlan) Type

func (vxlan *Vxlan) Type() string

type Wireguard added in v1.2.1

type Wireguard struct {
	LinkAttrs
}

Wireguard represent links of type "wireguard", see https://www.wireguard.com/

func (*Wireguard) Attrs added in v1.2.1

func (wg *Wireguard) Attrs() *LinkAttrs

func (*Wireguard) Type added in v1.2.1

func (wg *Wireguard) Type() string

type XDPDiagInfoResp added in v1.2.1

type XDPDiagInfoResp struct {
	XDPDiagMsg *XDPSocket
	XDPInfo    *XDPInfo
}

https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/xdp_diag.h#L21

type XDPDiagStats added in v1.2.1

type XDPDiagStats struct {
	RxDropped     uint64
	RxInvalid     uint64
	RxFull        uint64
	FillRingEmpty uint64
	TxInvalid     uint64
	TxRingEmpty   uint64
}

XDPDiagStats contains ring statistics for an XDP socket.

https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/xdp_diag.h#L74

type XDPDiagUmem added in v1.2.1

type XDPDiagUmem struct {
	Size      uint64
	ID        uint32
	NumPages  uint32
	ChunkSize uint32
	Headroom  uint32
	Ifindex   uint32
	QueueID   uint32
	Flags     uint32
	Refs      uint32
}

XDPDiagUmem describes the umem attached to an XDP socket.

https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/xdp_diag.h#L62

type XDPInfo added in v1.2.1

type XDPInfo struct {
	// XDP_DIAG_INFO/xdp_diag_info
	// https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/xdp_diag.h#L51
	Ifindex uint32
	QueueID uint32

	// XDP_DIAG_UID
	UID uint32

	// XDP_RX_RING
	// https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/xdp_diag.h#L56
	RxRingEntries             uint32
	TxRingEntries             uint32
	UmemFillRingEntries       uint32
	UmemCompletionRingEntries uint32

	// XDR_DIAG_UMEM
	Umem *XDPDiagUmem

	// XDR_DIAG_STATS
	Stats *XDPDiagStats
}

type XDPSocket added in v1.2.1

type XDPSocket struct {
	// xdp_diag_msg
	// https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/xdp_diag.h#L21
	Family uint8
	Type   uint8

	Ino    uint32
	Cookie [2]uint32
	// contains filtered or unexported fields
}

XDPSocket represents an XDP socket (and the common diagnosis part in particular). Please note that in contrast to UnixSocket the XDPSocket type does not feature “State” information.

type XfrmPolicy

type XfrmPolicy struct{}

func XfrmPolicyGet added in v1.2.1

func XfrmPolicyGet(policy *XfrmPolicy) (*XfrmPolicy, error)

func XfrmPolicyList

func XfrmPolicyList(family int) ([]XfrmPolicy, error)

type XfrmState

type XfrmState struct{}

func XfrmStateList

func XfrmStateList(family int) ([]XfrmState, error)

type Xfrmi added in v1.1.0

type Xfrmi struct {
	LinkAttrs
	Ifid uint32
}

Virtual XFRM Interfaces

Named "xfrmi" to prevent confusion with XFRM objects

func (*Xfrmi) Attrs added in v1.1.0

func (xfrm *Xfrmi) Attrs() *LinkAttrs

func (*Xfrmi) Type added in v1.1.0

func (xfrm *Xfrmi) Type() string

Directories

Path Synopsis
cmd
Package nl has low level primitives for making Netlink calls.
Package nl has low level primitives for making Netlink calls.

Jump to

Keyboard shortcuts

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