Documentation ¶
Overview ¶
Package nl has low level primitives for making Netlink calls.
Index ¶
- Constants
- func BytesToString(b []byte) string
- func GetIPFamily(ip net.IP) int
- func NativeEndian() binary.ByteOrder
- func NonZeroTerminated(s string) []byte
- func ParseRouteAttr(b []byte) ([]syscall.NetlinkRouteAttr, error)
- func Swap16(i uint16) uint16
- func Swap32(i uint32) uint32
- func Uint16Attr(v uint16) []byte
- func Uint32Attr(v uint32) []byte
- func Uint8Attr(v uint8) []byte
- func ZeroTerminated(s string) []byte
- type IfAddrmsg
- type IfInfomsg
- type NetlinkRequest
- type NetlinkRequestData
- type NetlinkSocket
- type RtAttr
- type RtMsg
- type XfrmAddress
- type XfrmAlgo
- type XfrmAlgoAuth
- type XfrmEncapTmpl
- type XfrmId
- type XfrmLifetimeCfg
- type XfrmLifetimeCur
- type XfrmSelector
- type XfrmStats
- type XfrmUserTmpl
- type XfrmUserpolicyId
- type XfrmUserpolicyInfo
- type XfrmUsersaId
- type XfrmUsersaInfo
Constants ¶
const ( IFLA_INFO_UNSPEC = iota IFLA_INFO_KIND IFLA_INFO_DATA IFLA_INFO_XSTATS IFLA_INFO_MAX = IFLA_INFO_XSTATS )
const ( IFLA_VLAN_UNSPEC = iota IFLA_VLAN_ID IFLA_VLAN_FLAGS IFLA_VLAN_EGRESS_QOS IFLA_VLAN_INGRESS_QOS IFLA_VLAN_PROTOCOL IFLA_VLAN_MAX = IFLA_VLAN_PROTOCOL )
const ( VETH_INFO_UNSPEC = iota VETH_INFO_PEER VETH_INFO_MAX = VETH_INFO_PEER )
const ( IFLA_VXLAN_UNSPEC = iota IFLA_VXLAN_ID IFLA_VXLAN_GROUP IFLA_VXLAN_LINK IFLA_VXLAN_LOCAL IFLA_VXLAN_TTL IFLA_VXLAN_TOS IFLA_VXLAN_LEARNING IFLA_VXLAN_AGEING IFLA_VXLAN_LIMIT IFLA_VXLAN_PORT_RANGE IFLA_VXLAN_PROXY IFLA_VXLAN_RSC IFLA_VXLAN_L2MISS IFLA_VXLAN_L3MISS IFLA_VXLAN_PORT IFLA_VXLAN_GROUP6 IFLA_VXLAN_LOCAL6 IFLA_VXLAN_MAX = IFLA_VXLAN_LOCAL6 )
const ( BRIDGE_MODE_UNSPEC = iota BRIDGE_MODE_HAIRPIN )
const ( IFLA_BRPORT_UNSPEC = iota IFLA_BRPORT_STATE IFLA_BRPORT_PRIORITY IFLA_BRPORT_COST IFLA_BRPORT_MODE IFLA_BRPORT_GUARD IFLA_BRPORT_PROTECT IFLA_BRPORT_FAST_LEAVE IFLA_BRPORT_LEARNING IFLA_BRPORT_UNICAST_FLOOD IFLA_BRPORT_MAX = IFLA_BRPORT_UNICAST_FLOOD )
const ( IFLA_IPVLAN_UNSPEC = iota IFLA_IPVLAN_MODE IFLA_IPVLAN_MAX = IFLA_IPVLAN_MODE )
const ( IFLA_MACVLAN_UNSPEC = iota IFLA_MACVLAN_MODE IFLA_MACVLAN_FLAGS IFLA_MACVLAN_MAX = IFLA_MACVLAN_FLAGS )
const ( MACVLAN_MODE_PRIVATE = 1 MACVLAN_MODE_VEPA = 2 MACVLAN_MODE_BRIDGE = 4 MACVLAN_MODE_PASSTHRU = 8 MACVLAN_MODE_SOURCE = 16 )
const ( // Family type definitions FAMILY_ALL = syscall.AF_UNSPEC FAMILY_V4 = syscall.AF_INET FAMILY_V6 = syscall.AF_INET6 )
const ( XFRM_MSG_BASE = 0x10 XFRM_MSG_NEWSA = 0x10 XFRM_MSG_DELSA = 0x11 XFRM_MSG_GETSA = 0x12 XFRM_MSG_NEWPOLICY = 0x13 XFRM_MSG_DELPOLICY = 0x14 XFRM_MSG_GETPOLICY = 0x15 XFRM_MSG_ALLOCSPI = 0x16 XFRM_MSG_ACQUIRE = 0x17 XFRM_MSG_EXPIRE = 0x18 XFRM_MSG_UPDPOLICY = 0x19 XFRM_MSG_UPDSA = 0x1a XFRM_MSG_POLEXPIRE = 0x1b XFRM_MSG_FLUSHSA = 0x1c XFRM_MSG_FLUSHPOLICY = 0x1d XFRM_MSG_NEWAE = 0x1e XFRM_MSG_GETAE = 0x1f XFRM_MSG_REPORT = 0x20 XFRM_MSG_MIGRATE = 0x21 XFRM_MSG_NEWSADINFO = 0x22 XFRM_MSG_GETSADINFO = 0x23 XFRM_MSG_NEWSPDINFO = 0x24 XFRM_MSG_GETSPDINFO = 0x25 XFRM_MSG_MAPPING = 0x26 XFRM_MSG_MAX = 0x26 XFRM_NR_MSGTYPES = 0x17 )
Message Types
const ( /* Netlink message attributes. */ XFRMA_UNSPEC = 0x00 XFRMA_ALG_AUTH = 0x01 /* struct xfrm_algo */ XFRMA_ALG_CRYPT = 0x02 /* struct xfrm_algo */ XFRMA_ALG_COMP = 0x03 /* struct xfrm_algo */ XFRMA_ENCAP = 0x04 /* struct xfrm_algo + struct xfrm_encap_tmpl */ XFRMA_TMPL = 0x05 /* 1 or more struct xfrm_user_tmpl */ XFRMA_SA = 0x06 /* struct xfrm_usersa_info */ XFRMA_POLICY = 0x07 /* struct xfrm_userpolicy_info */ XFRMA_SEC_CTX = 0x08 /* struct xfrm_sec_ctx */ XFRMA_LTIME_VAL = 0x09 XFRMA_REPLAY_VAL = 0x0a XFRMA_REPLAY_THRESH = 0x0b XFRMA_ETIMER_THRESH = 0x0c XFRMA_SRCADDR = 0x0d /* xfrm_address_t */ XFRMA_COADDR = 0x0e /* xfrm_address_t */ XFRMA_LASTUSED = 0x0f /* unsigned long */ XFRMA_POLICY_TYPE = 0x10 /* struct xfrm_userpolicy_type */ XFRMA_MIGRATE = 0x11 XFRMA_ALG_AEAD = 0x12 /* struct xfrm_algo_aead */ XFRMA_KMADDRESS = 0x13 /* struct xfrm_user_kmaddress */ XFRMA_ALG_AUTH_TRUNC = 0x14 /* struct xfrm_algo_auth */ XFRMA_MARK = 0x15 /* struct xfrm_mark */ XFRMA_TFCPAD = 0x16 /* __u32 */ XFRMA_REPLAY_ESN_VAL = 0x17 /* struct xfrm_replay_esn */ XFRMA_SA_EXTRA_FLAGS = 0x18 /* __u32 */ XFRMA_MAX = 0x18 )
Attribute types
const ( SizeofXfrmAddress = 0x10 SizeofXfrmSelector = 0x38 SizeofXfrmLifetimeCfg = 0x40 SizeofXfrmLifetimeCur = 0x20 SizeofXfrmId = 0x18 )
const ( SizeofXfrmUserpolicyId = 0x40 SizeofXfrmUserpolicyInfo = 0xa8 SizeofXfrmUserTmpl = 0x40 )
const ( SizeofXfrmUsersaId = 0x18 SizeofXfrmStats = 0x0c SizeofXfrmUsersaInfo = 0xe0 SizeofXfrmAlgo = 0x44 SizeofXfrmAlgoAuth = 0x48 SizeofXfrmEncapTmpl = 0x18 )
const (
DEFAULT_CHANGE = 0xFFFFFFFF
)
const (
// not defined in syscall
IFLA_NET_NS_FD = 28
)
const (
XFRM_INF = ^uint64(0)
)
Infinity for packet and byte counts
Variables ¶
This section is empty.
Functions ¶
func BytesToString ¶
func NonZeroTerminated ¶
func ParseRouteAttr ¶
func ParseRouteAttr(b []byte) ([]syscall.NetlinkRouteAttr, error)
func Uint16Attr ¶
func Uint32Attr ¶
func ZeroTerminated ¶
Types ¶
type IfInfomsg ¶
IfInfomsg is related to links, but it is used for list requests as well
func DeserializeIfInfomsg ¶
func NewIfInfomsg ¶
Create an IfInfomsg with family specified
func NewIfInfomsgChild ¶
type NetlinkRequest ¶
type NetlinkRequest struct { syscall.NlMsghdr Data []NetlinkRequestData }
func NewNetlinkRequest ¶
func NewNetlinkRequest(proto, flags int) *NetlinkRequest
Create a new netlink request from proto and flags Note the Len value will be inaccurate once data is added until the message is serialized
func (*NetlinkRequest) AddData ¶
func (msg *NetlinkRequest) AddData(data NetlinkRequestData)
func (*NetlinkRequest) Execute ¶
func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error)
Execute the request against a the given sockType. Returns a list of netlink messages in seriaized format, optionally filtered by resType.
func (*NetlinkRequest) Serialize ¶
func (msg *NetlinkRequest) Serialize() []byte
Serialize the Netlink Request into a byte array
type NetlinkRequestData ¶
type NetlinkSocket ¶
type NetlinkSocket struct {
// contains filtered or unexported fields
}
func Subscribe ¶
func Subscribe(protocol int, groups ...uint) (*NetlinkSocket, error)
Create a netlink socket with a given protocol (e.g. NETLINK_ROUTE) and subscribe it to multicast groups passed in variable argument list. Returns the netlink socket on whic hReceive() method can be called to retrieve the messages from the kernel.
func (*NetlinkSocket) Close ¶
func (s *NetlinkSocket) Close()
func (*NetlinkSocket) GetPid ¶
func (s *NetlinkSocket) GetPid() (uint32, error)
func (*NetlinkSocket) Recieve ¶
func (s *NetlinkSocket) Recieve() ([]syscall.NetlinkMessage, error)
func (*NetlinkSocket) Send ¶
func (s *NetlinkSocket) Send(request *NetlinkRequest) error
type RtAttr ¶
Extend RtAttr to handle data and children
func NewRtAttrChild ¶
Create a new RtAttr obj anc add it as a child of an existing object
type RtMsg ¶
func DeserializeRtMsg ¶
type XfrmAddress ¶
type XfrmAddress [SizeofXfrmAddress]byte
func DeserializeXfrmAddress ¶
func DeserializeXfrmAddress(b []byte) *XfrmAddress
func (*XfrmAddress) FromIP ¶
func (x *XfrmAddress) FromIP(ip net.IP)
func (*XfrmAddress) Serialize ¶
func (msg *XfrmAddress) Serialize() []byte
func (*XfrmAddress) ToIP ¶
func (x *XfrmAddress) ToIP() net.IP
type XfrmAlgo ¶
func DeserializeXfrmAlgo ¶
type XfrmAlgoAuth ¶
func DeserializeXfrmAlgoAuth ¶
func DeserializeXfrmAlgoAuth(b []byte) *XfrmAlgoAuth
func (*XfrmAlgoAuth) Len ¶
func (msg *XfrmAlgoAuth) Len() int
func (*XfrmAlgoAuth) Serialize ¶
func (msg *XfrmAlgoAuth) Serialize() []byte
type XfrmEncapTmpl ¶
type XfrmEncapTmpl struct { EncapType uint16 EncapSport uint16 // big endian EncapDport uint16 // big endian Pad [2]byte EncapOa XfrmAddress }
func DeserializeXfrmEncapTmpl ¶
func DeserializeXfrmEncapTmpl(b []byte) *XfrmEncapTmpl
func (*XfrmEncapTmpl) Len ¶
func (msg *XfrmEncapTmpl) Len() int
func (*XfrmEncapTmpl) Serialize ¶
func (msg *XfrmEncapTmpl) Serialize() []byte
type XfrmId ¶
type XfrmId struct { Daddr XfrmAddress Spi uint32 // big endian Proto uint8 Pad [3]byte }
func DeserializeXfrmId ¶
type XfrmLifetimeCfg ¶
type XfrmLifetimeCfg struct { SoftByteLimit uint64 HardByteLimit uint64 SoftPacketLimit uint64 HardPacketLimit uint64 SoftAddExpiresSeconds uint64 HardAddExpiresSeconds uint64 SoftUseExpiresSeconds uint64 HardUseExpiresSeconds uint64 }
func DeserializeXfrmLifetimeCfg ¶
func DeserializeXfrmLifetimeCfg(b []byte) *XfrmLifetimeCfg
func (*XfrmLifetimeCfg) Len ¶
func (msg *XfrmLifetimeCfg) Len() int
func (*XfrmLifetimeCfg) Serialize ¶
func (msg *XfrmLifetimeCfg) Serialize() []byte
type XfrmLifetimeCur ¶
func DeserializeXfrmLifetimeCur ¶
func DeserializeXfrmLifetimeCur(b []byte) *XfrmLifetimeCur
func (*XfrmLifetimeCur) Len ¶
func (msg *XfrmLifetimeCur) Len() int
func (*XfrmLifetimeCur) Serialize ¶
func (msg *XfrmLifetimeCur) Serialize() []byte
type XfrmSelector ¶
type XfrmSelector struct { Daddr XfrmAddress Saddr XfrmAddress Dport uint16 // big endian DportMask uint16 // big endian Sport uint16 // big endian SportMask uint16 // big endian Family uint16 PrefixlenD uint8 PrefixlenS uint8 Proto uint8 Pad [3]byte Ifindex int32 User uint32 }
func DeserializeXfrmSelector ¶
func DeserializeXfrmSelector(b []byte) *XfrmSelector
func (*XfrmSelector) Len ¶
func (msg *XfrmSelector) Len() int
func (*XfrmSelector) Serialize ¶
func (msg *XfrmSelector) Serialize() []byte
type XfrmStats ¶
func DeserializeXfrmStats ¶
type XfrmUserTmpl ¶
type XfrmUserTmpl struct { XfrmId XfrmId Family uint16 Pad1 [2]byte Saddr XfrmAddress Reqid uint32 Mode uint8 Optional uint8 Pad2 byte Aalgos uint32 Ealgos uint32 Calgos uint32 }
func DeserializeXfrmUserTmpl ¶
func DeserializeXfrmUserTmpl(b []byte) *XfrmUserTmpl
func (*XfrmUserTmpl) Len ¶
func (msg *XfrmUserTmpl) Len() int
func (*XfrmUserTmpl) Serialize ¶
func (msg *XfrmUserTmpl) Serialize() []byte
type XfrmUserpolicyId ¶
type XfrmUserpolicyId struct { Sel XfrmSelector Index uint32 Dir uint8 Pad [3]byte }
func DeserializeXfrmUserpolicyId ¶
func DeserializeXfrmUserpolicyId(b []byte) *XfrmUserpolicyId
func (*XfrmUserpolicyId) Len ¶
func (msg *XfrmUserpolicyId) Len() int
func (*XfrmUserpolicyId) Serialize ¶
func (msg *XfrmUserpolicyId) Serialize() []byte
type XfrmUserpolicyInfo ¶
type XfrmUserpolicyInfo struct { Sel XfrmSelector Lft XfrmLifetimeCfg Curlft XfrmLifetimeCur Priority uint32 Index uint32 Dir uint8 Action uint8 Flags uint8 Pad [4]byte }
func DeserializeXfrmUserpolicyInfo ¶
func DeserializeXfrmUserpolicyInfo(b []byte) *XfrmUserpolicyInfo
func (*XfrmUserpolicyInfo) Len ¶
func (msg *XfrmUserpolicyInfo) Len() int
func (*XfrmUserpolicyInfo) Serialize ¶
func (msg *XfrmUserpolicyInfo) Serialize() []byte
type XfrmUsersaId ¶
type XfrmUsersaId struct { Daddr XfrmAddress Spi uint32 // big endian Family uint16 Proto uint8 Pad byte }
func DeserializeXfrmUsersaId ¶
func DeserializeXfrmUsersaId(b []byte) *XfrmUsersaId
func (*XfrmUsersaId) Len ¶
func (msg *XfrmUsersaId) Len() int
func (*XfrmUsersaId) Serialize ¶
func (msg *XfrmUsersaId) Serialize() []byte
type XfrmUsersaInfo ¶
type XfrmUsersaInfo struct { Sel XfrmSelector Id XfrmId Saddr XfrmAddress Lft XfrmLifetimeCfg Curlft XfrmLifetimeCur Stats XfrmStats Seq uint32 Reqid uint32 Family uint16 Mode uint8 ReplayWindow uint8 Flags uint8 Pad [7]byte }
func DeserializeXfrmUsersaInfo ¶
func DeserializeXfrmUsersaInfo(b []byte) *XfrmUsersaInfo
func (*XfrmUsersaInfo) Len ¶
func (msg *XfrmUsersaInfo) Len() int
func (*XfrmUsersaInfo) Serialize ¶
func (msg *XfrmUsersaInfo) Serialize() []byte