vendor: Update vishvanana/netlink dependency.
This updates the netlink dependency to include recent updates, including a fix when setting prosmic mode on a bridge and additions for creating qdisc/classes/filters. This is necessary for some upcoming additions to CNI
This commit is contained in:
29
vendor/github.com/vishvananda/netlink/nl/addr_linux.go
generated
vendored
29
vendor/github.com/vishvananda/netlink/nl/addr_linux.go
generated
vendored
@ -45,3 +45,32 @@ func (msg *IfAddrmsg) Serialize() []byte {
|
||||
func (msg *IfAddrmsg) Len() int {
|
||||
return syscall.SizeofIfAddrmsg
|
||||
}
|
||||
|
||||
// struct ifa_cacheinfo {
|
||||
// __u32 ifa_prefered;
|
||||
// __u32 ifa_valid;
|
||||
// __u32 cstamp; /* created timestamp, hundredths of seconds */
|
||||
// __u32 tstamp; /* updated timestamp, hundredths of seconds */
|
||||
// };
|
||||
|
||||
const IFA_CACHEINFO = 6
|
||||
const SizeofIfaCacheInfo = 0x10
|
||||
|
||||
type IfaCacheInfo struct {
|
||||
IfaPrefered uint32
|
||||
IfaValid uint32
|
||||
Cstamp uint32
|
||||
Tstamp uint32
|
||||
}
|
||||
|
||||
func (msg *IfaCacheInfo) Len() int {
|
||||
return SizeofIfaCacheInfo
|
||||
}
|
||||
|
||||
func DeserializeIfaCacheInfo(b []byte) *IfaCacheInfo {
|
||||
return (*IfaCacheInfo)(unsafe.Pointer(&b[0:SizeofIfaCacheInfo][0]))
|
||||
}
|
||||
|
||||
func (msg *IfaCacheInfo) Serialize() []byte {
|
||||
return (*(*[SizeofIfaCacheInfo]byte)(unsafe.Pointer(msg)))[:]
|
||||
}
|
||||
|
74
vendor/github.com/vishvananda/netlink/nl/bridge_linux.go
generated
vendored
Normal file
74
vendor/github.com/vishvananda/netlink/nl/bridge_linux.go
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
package nl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
SizeofBridgeVlanInfo = 0x04
|
||||
)
|
||||
|
||||
/* Bridge Flags */
|
||||
const (
|
||||
BRIDGE_FLAGS_MASTER = iota /* Bridge command to/from master */
|
||||
BRIDGE_FLAGS_SELF /* Bridge command to/from lowerdev */
|
||||
)
|
||||
|
||||
/* Bridge management nested attributes
|
||||
* [IFLA_AF_SPEC] = {
|
||||
* [IFLA_BRIDGE_FLAGS]
|
||||
* [IFLA_BRIDGE_MODE]
|
||||
* [IFLA_BRIDGE_VLAN_INFO]
|
||||
* }
|
||||
*/
|
||||
const (
|
||||
IFLA_BRIDGE_FLAGS = iota
|
||||
IFLA_BRIDGE_MODE
|
||||
IFLA_BRIDGE_VLAN_INFO
|
||||
)
|
||||
|
||||
const (
|
||||
BRIDGE_VLAN_INFO_MASTER = 1 << iota
|
||||
BRIDGE_VLAN_INFO_PVID
|
||||
BRIDGE_VLAN_INFO_UNTAGGED
|
||||
BRIDGE_VLAN_INFO_RANGE_BEGIN
|
||||
BRIDGE_VLAN_INFO_RANGE_END
|
||||
)
|
||||
|
||||
// struct bridge_vlan_info {
|
||||
// __u16 flags;
|
||||
// __u16 vid;
|
||||
// };
|
||||
|
||||
type BridgeVlanInfo struct {
|
||||
Flags uint16
|
||||
Vid uint16
|
||||
}
|
||||
|
||||
func (b *BridgeVlanInfo) Serialize() []byte {
|
||||
return (*(*[SizeofBridgeVlanInfo]byte)(unsafe.Pointer(b)))[:]
|
||||
}
|
||||
|
||||
func DeserializeBridgeVlanInfo(b []byte) *BridgeVlanInfo {
|
||||
return (*BridgeVlanInfo)(unsafe.Pointer(&b[0:SizeofBridgeVlanInfo][0]))
|
||||
}
|
||||
|
||||
func (b *BridgeVlanInfo) PortVID() bool {
|
||||
return b.Flags&BRIDGE_VLAN_INFO_PVID > 0
|
||||
}
|
||||
|
||||
func (b *BridgeVlanInfo) EngressUntag() bool {
|
||||
return b.Flags&BRIDGE_VLAN_INFO_UNTAGGED > 0
|
||||
}
|
||||
|
||||
func (b *BridgeVlanInfo) String() string {
|
||||
return fmt.Sprintf("%+v", *b)
|
||||
}
|
||||
|
||||
/* New extended info filters for IFLA_EXT_MASK */
|
||||
const (
|
||||
RTEXT_FILTER_VF = 1 << iota
|
||||
RTEXT_FILTER_BRVLAN
|
||||
RTEXT_FILTER_BRVLAN_COMPRESSED
|
||||
)
|
189
vendor/github.com/vishvananda/netlink/nl/conntrack_linux.go
generated
vendored
Normal file
189
vendor/github.com/vishvananda/netlink/nl/conntrack_linux.go
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
package nl
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// Track the message sizes for the correct serialization/deserialization
|
||||
const (
|
||||
SizeofNfgenmsg = 4
|
||||
SizeofNfattr = 4
|
||||
SizeofNfConntrack = 376
|
||||
SizeofNfctTupleHead = 52
|
||||
)
|
||||
|
||||
var L4ProtoMap = map[uint8]string{
|
||||
6: "tcp",
|
||||
17: "udp",
|
||||
}
|
||||
|
||||
// All the following constants are coming from:
|
||||
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/netfilter/nfnetlink_conntrack.h
|
||||
|
||||
// enum cntl_msg_types {
|
||||
// IPCTNL_MSG_CT_NEW,
|
||||
// IPCTNL_MSG_CT_GET,
|
||||
// IPCTNL_MSG_CT_DELETE,
|
||||
// IPCTNL_MSG_CT_GET_CTRZERO,
|
||||
// IPCTNL_MSG_CT_GET_STATS_CPU,
|
||||
// IPCTNL_MSG_CT_GET_STATS,
|
||||
// IPCTNL_MSG_CT_GET_DYING,
|
||||
// IPCTNL_MSG_CT_GET_UNCONFIRMED,
|
||||
//
|
||||
// IPCTNL_MSG_MAX
|
||||
// };
|
||||
const (
|
||||
IPCTNL_MSG_CT_GET = 1
|
||||
IPCTNL_MSG_CT_DELETE = 2
|
||||
)
|
||||
|
||||
// #define NFNETLINK_V0 0
|
||||
const (
|
||||
NFNETLINK_V0 = 0
|
||||
)
|
||||
|
||||
// #define NLA_F_NESTED (1 << 15)
|
||||
const (
|
||||
NLA_F_NESTED = (1 << 15)
|
||||
)
|
||||
|
||||
// enum ctattr_type {
|
||||
// CTA_UNSPEC,
|
||||
// CTA_TUPLE_ORIG,
|
||||
// CTA_TUPLE_REPLY,
|
||||
// CTA_STATUS,
|
||||
// CTA_PROTOINFO,
|
||||
// CTA_HELP,
|
||||
// CTA_NAT_SRC,
|
||||
// #define CTA_NAT CTA_NAT_SRC /* backwards compatibility */
|
||||
// CTA_TIMEOUT,
|
||||
// CTA_MARK,
|
||||
// CTA_COUNTERS_ORIG,
|
||||
// CTA_COUNTERS_REPLY,
|
||||
// CTA_USE,
|
||||
// CTA_ID,
|
||||
// CTA_NAT_DST,
|
||||
// CTA_TUPLE_MASTER,
|
||||
// CTA_SEQ_ADJ_ORIG,
|
||||
// CTA_NAT_SEQ_ADJ_ORIG = CTA_SEQ_ADJ_ORIG,
|
||||
// CTA_SEQ_ADJ_REPLY,
|
||||
// CTA_NAT_SEQ_ADJ_REPLY = CTA_SEQ_ADJ_REPLY,
|
||||
// CTA_SECMARK, /* obsolete */
|
||||
// CTA_ZONE,
|
||||
// CTA_SECCTX,
|
||||
// CTA_TIMESTAMP,
|
||||
// CTA_MARK_MASK,
|
||||
// CTA_LABELS,
|
||||
// CTA_LABELS_MASK,
|
||||
// __CTA_MAX
|
||||
// };
|
||||
const (
|
||||
CTA_TUPLE_ORIG = 1
|
||||
CTA_TUPLE_REPLY = 2
|
||||
CTA_STATUS = 3
|
||||
CTA_TIMEOUT = 8
|
||||
CTA_MARK = 9
|
||||
CTA_PROTOINFO = 4
|
||||
)
|
||||
|
||||
// enum ctattr_tuple {
|
||||
// CTA_TUPLE_UNSPEC,
|
||||
// CTA_TUPLE_IP,
|
||||
// CTA_TUPLE_PROTO,
|
||||
// CTA_TUPLE_ZONE,
|
||||
// __CTA_TUPLE_MAX
|
||||
// };
|
||||
// #define CTA_TUPLE_MAX (__CTA_TUPLE_MAX - 1)
|
||||
const (
|
||||
CTA_TUPLE_IP = 1
|
||||
CTA_TUPLE_PROTO = 2
|
||||
)
|
||||
|
||||
// enum ctattr_ip {
|
||||
// CTA_IP_UNSPEC,
|
||||
// CTA_IP_V4_SRC,
|
||||
// CTA_IP_V4_DST,
|
||||
// CTA_IP_V6_SRC,
|
||||
// CTA_IP_V6_DST,
|
||||
// __CTA_IP_MAX
|
||||
// };
|
||||
// #define CTA_IP_MAX (__CTA_IP_MAX - 1)
|
||||
const (
|
||||
CTA_IP_V4_SRC = 1
|
||||
CTA_IP_V4_DST = 2
|
||||
CTA_IP_V6_SRC = 3
|
||||
CTA_IP_V6_DST = 4
|
||||
)
|
||||
|
||||
// enum ctattr_l4proto {
|
||||
// CTA_PROTO_UNSPEC,
|
||||
// CTA_PROTO_NUM,
|
||||
// CTA_PROTO_SRC_PORT,
|
||||
// CTA_PROTO_DST_PORT,
|
||||
// CTA_PROTO_ICMP_ID,
|
||||
// CTA_PROTO_ICMP_TYPE,
|
||||
// CTA_PROTO_ICMP_CODE,
|
||||
// CTA_PROTO_ICMPV6_ID,
|
||||
// CTA_PROTO_ICMPV6_TYPE,
|
||||
// CTA_PROTO_ICMPV6_CODE,
|
||||
// __CTA_PROTO_MAX
|
||||
// };
|
||||
// #define CTA_PROTO_MAX (__CTA_PROTO_MAX - 1)
|
||||
const (
|
||||
CTA_PROTO_NUM = 1
|
||||
CTA_PROTO_SRC_PORT = 2
|
||||
CTA_PROTO_DST_PORT = 3
|
||||
)
|
||||
|
||||
// enum ctattr_protoinfo {
|
||||
// CTA_PROTOINFO_UNSPEC,
|
||||
// CTA_PROTOINFO_TCP,
|
||||
// CTA_PROTOINFO_DCCP,
|
||||
// CTA_PROTOINFO_SCTP,
|
||||
// __CTA_PROTOINFO_MAX
|
||||
// };
|
||||
// #define CTA_PROTOINFO_MAX (__CTA_PROTOINFO_MAX - 1)
|
||||
const (
|
||||
CTA_PROTOINFO_TCP = 1
|
||||
)
|
||||
|
||||
// enum ctattr_protoinfo_tcp {
|
||||
// CTA_PROTOINFO_TCP_UNSPEC,
|
||||
// CTA_PROTOINFO_TCP_STATE,
|
||||
// CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
|
||||
// CTA_PROTOINFO_TCP_WSCALE_REPLY,
|
||||
// CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
|
||||
// CTA_PROTOINFO_TCP_FLAGS_REPLY,
|
||||
// __CTA_PROTOINFO_TCP_MAX
|
||||
// };
|
||||
// #define CTA_PROTOINFO_TCP_MAX (__CTA_PROTOINFO_TCP_MAX - 1)
|
||||
const (
|
||||
CTA_PROTOINFO_TCP_STATE = 1
|
||||
CTA_PROTOINFO_TCP_WSCALE_ORIGINAL = 2
|
||||
CTA_PROTOINFO_TCP_WSCALE_REPLY = 3
|
||||
CTA_PROTOINFO_TCP_FLAGS_ORIGINAL = 4
|
||||
CTA_PROTOINFO_TCP_FLAGS_REPLY = 5
|
||||
)
|
||||
|
||||
// /* General form of address family dependent message.
|
||||
// */
|
||||
// struct nfgenmsg {
|
||||
// __u8 nfgen_family; /* AF_xxx */
|
||||
// __u8 version; /* nfnetlink version */
|
||||
// __be16 res_id; /* resource id */
|
||||
// };
|
||||
type Nfgenmsg struct {
|
||||
NfgenFamily uint8
|
||||
Version uint8
|
||||
ResId uint16 // big endian
|
||||
}
|
||||
|
||||
func (msg *Nfgenmsg) Len() int {
|
||||
return SizeofNfgenmsg
|
||||
}
|
||||
|
||||
func DeserializeNfgenmsg(b []byte) *Nfgenmsg {
|
||||
return (*Nfgenmsg)(unsafe.Pointer(&b[0:SizeofNfgenmsg][0]))
|
||||
}
|
||||
|
||||
func (msg *Nfgenmsg) Serialize() []byte {
|
||||
return (*(*[SizeofNfgenmsg]byte)(unsafe.Pointer(msg)))[:]
|
||||
}
|
89
vendor/github.com/vishvananda/netlink/nl/genetlink_linux.go
generated
vendored
Normal file
89
vendor/github.com/vishvananda/netlink/nl/genetlink_linux.go
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
package nl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const SizeofGenlmsg = 4
|
||||
|
||||
const (
|
||||
GENL_ID_CTRL = 0x10
|
||||
GENL_CTRL_VERSION = 2
|
||||
GENL_CTRL_NAME = "nlctrl"
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_CTRL_CMD_GETFAMILY = 3
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_CTRL_ATTR_UNSPEC = iota
|
||||
GENL_CTRL_ATTR_FAMILY_ID
|
||||
GENL_CTRL_ATTR_FAMILY_NAME
|
||||
GENL_CTRL_ATTR_VERSION
|
||||
GENL_CTRL_ATTR_HDRSIZE
|
||||
GENL_CTRL_ATTR_MAXATTR
|
||||
GENL_CTRL_ATTR_OPS
|
||||
GENL_CTRL_ATTR_MCAST_GROUPS
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_CTRL_ATTR_OP_UNSPEC = iota
|
||||
GENL_CTRL_ATTR_OP_ID
|
||||
GENL_CTRL_ATTR_OP_FLAGS
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_ADMIN_PERM = 1 << iota
|
||||
GENL_CMD_CAP_DO
|
||||
GENL_CMD_CAP_DUMP
|
||||
GENL_CMD_CAP_HASPOL
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_CTRL_ATTR_MCAST_GRP_UNSPEC = iota
|
||||
GENL_CTRL_ATTR_MCAST_GRP_NAME
|
||||
GENL_CTRL_ATTR_MCAST_GRP_ID
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_GTP_VERSION = 0
|
||||
GENL_GTP_NAME = "gtp"
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_GTP_CMD_NEWPDP = iota
|
||||
GENL_GTP_CMD_DELPDP
|
||||
GENL_GTP_CMD_GETPDP
|
||||
)
|
||||
|
||||
const (
|
||||
GENL_GTP_ATTR_UNSPEC = iota
|
||||
GENL_GTP_ATTR_LINK
|
||||
GENL_GTP_ATTR_VERSION
|
||||
GENL_GTP_ATTR_TID
|
||||
GENL_GTP_ATTR_PEER_ADDRESS
|
||||
GENL_GTP_ATTR_MS_ADDRESS
|
||||
GENL_GTP_ATTR_FLOW
|
||||
GENL_GTP_ATTR_NET_NS_FD
|
||||
GENL_GTP_ATTR_I_TEI
|
||||
GENL_GTP_ATTR_O_TEI
|
||||
GENL_GTP_ATTR_PAD
|
||||
)
|
||||
|
||||
type Genlmsg struct {
|
||||
Command uint8
|
||||
Version uint8
|
||||
}
|
||||
|
||||
func (msg *Genlmsg) Len() int {
|
||||
return SizeofGenlmsg
|
||||
}
|
||||
|
||||
func DeserializeGenlmsg(b []byte) *Genlmsg {
|
||||
return (*Genlmsg)(unsafe.Pointer(&b[0:SizeofGenlmsg][0]))
|
||||
}
|
||||
|
||||
func (msg *Genlmsg) Serialize() []byte {
|
||||
return (*(*[SizeofGenlmsg]byte)(unsafe.Pointer(msg)))[:]
|
||||
}
|
74
vendor/github.com/vishvananda/netlink/nl/link_linux.go
generated
vendored
74
vendor/github.com/vishvananda/netlink/nl/link_linux.go
generated
vendored
@ -102,7 +102,10 @@ const (
|
||||
IFLA_BRPORT_FAST_LEAVE
|
||||
IFLA_BRPORT_LEARNING
|
||||
IFLA_BRPORT_UNICAST_FLOOD
|
||||
IFLA_BRPORT_MAX = IFLA_BRPORT_UNICAST_FLOOD
|
||||
IFLA_BRPORT_PROXYARP
|
||||
IFLA_BRPORT_LEARNING_SYNC
|
||||
IFLA_BRPORT_PROXYARP_WIFI
|
||||
IFLA_BRPORT_MAX = IFLA_BRPORT_PROXYARP_WIFI
|
||||
)
|
||||
|
||||
const (
|
||||
@ -151,6 +154,10 @@ const (
|
||||
IFLA_BOND_AD_LACP_RATE
|
||||
IFLA_BOND_AD_SELECT
|
||||
IFLA_BOND_AD_INFO
|
||||
IFLA_BOND_AD_ACTOR_SYS_PRIO
|
||||
IFLA_BOND_AD_USER_PORT_KEY
|
||||
IFLA_BOND_AD_ACTOR_SYSTEM
|
||||
IFLA_BOND_TLB_DYNAMIC_LB
|
||||
)
|
||||
|
||||
const (
|
||||
@ -416,7 +423,8 @@ const (
|
||||
IFLA_XDP_UNSPEC = iota
|
||||
IFLA_XDP_FD /* fd of xdp program to attach, or -1 to remove */
|
||||
IFLA_XDP_ATTACHED /* read-only bool indicating if prog is attached */
|
||||
IFLA_XDP_MAX = IFLA_XDP_ATTACHED
|
||||
IFLA_XDP_FLAGS /* xdp prog related flags */
|
||||
IFLA_XDP_MAX = IFLA_XDP_FLAGS
|
||||
)
|
||||
|
||||
const (
|
||||
@ -452,3 +460,65 @@ const (
|
||||
IFLA_VRF_UNSPEC = iota
|
||||
IFLA_VRF_TABLE
|
||||
)
|
||||
|
||||
const (
|
||||
IFLA_BR_UNSPEC = iota
|
||||
IFLA_BR_FORWARD_DELAY
|
||||
IFLA_BR_HELLO_TIME
|
||||
IFLA_BR_MAX_AGE
|
||||
IFLA_BR_AGEING_TIME
|
||||
IFLA_BR_STP_STATE
|
||||
IFLA_BR_PRIORITY
|
||||
IFLA_BR_VLAN_FILTERING
|
||||
IFLA_BR_VLAN_PROTOCOL
|
||||
IFLA_BR_GROUP_FWD_MASK
|
||||
IFLA_BR_ROOT_ID
|
||||
IFLA_BR_BRIDGE_ID
|
||||
IFLA_BR_ROOT_PORT
|
||||
IFLA_BR_ROOT_PATH_COST
|
||||
IFLA_BR_TOPOLOGY_CHANGE
|
||||
IFLA_BR_TOPOLOGY_CHANGE_DETECTED
|
||||
IFLA_BR_HELLO_TIMER
|
||||
IFLA_BR_TCN_TIMER
|
||||
IFLA_BR_TOPOLOGY_CHANGE_TIMER
|
||||
IFLA_BR_GC_TIMER
|
||||
IFLA_BR_GROUP_ADDR
|
||||
IFLA_BR_FDB_FLUSH
|
||||
IFLA_BR_MCAST_ROUTER
|
||||
IFLA_BR_MCAST_SNOOPING
|
||||
IFLA_BR_MCAST_QUERY_USE_IFADDR
|
||||
IFLA_BR_MCAST_QUERIER
|
||||
IFLA_BR_MCAST_HASH_ELASTICITY
|
||||
IFLA_BR_MCAST_HASH_MAX
|
||||
IFLA_BR_MCAST_LAST_MEMBER_CNT
|
||||
IFLA_BR_MCAST_STARTUP_QUERY_CNT
|
||||
IFLA_BR_MCAST_LAST_MEMBER_INTVL
|
||||
IFLA_BR_MCAST_MEMBERSHIP_INTVL
|
||||
IFLA_BR_MCAST_QUERIER_INTVL
|
||||
IFLA_BR_MCAST_QUERY_INTVL
|
||||
IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
|
||||
IFLA_BR_MCAST_STARTUP_QUERY_INTVL
|
||||
IFLA_BR_NF_CALL_IPTABLES
|
||||
IFLA_BR_NF_CALL_IP6TABLES
|
||||
IFLA_BR_NF_CALL_ARPTABLES
|
||||
IFLA_BR_VLAN_DEFAULT_PVID
|
||||
IFLA_BR_PAD
|
||||
IFLA_BR_VLAN_STATS_ENABLED
|
||||
IFLA_BR_MCAST_STATS_ENABLED
|
||||
IFLA_BR_MCAST_IGMP_VERSION
|
||||
IFLA_BR_MCAST_MLD_VERSION
|
||||
IFLA_BR_MAX = IFLA_BR_MCAST_MLD_VERSION
|
||||
)
|
||||
|
||||
const (
|
||||
IFLA_GTP_UNSPEC = iota
|
||||
IFLA_GTP_FD0
|
||||
IFLA_GTP_FD1
|
||||
IFLA_GTP_PDP_HASHSIZE
|
||||
IFLA_GTP_ROLE
|
||||
)
|
||||
|
||||
const (
|
||||
GTP_ROLE_GGSN = iota
|
||||
GTP_ROLE_SGSN
|
||||
)
|
||||
|
43
vendor/github.com/vishvananda/netlink/nl/nl_linux.go
generated
vendored
43
vendor/github.com/vishvananda/netlink/nl/nl_linux.go
generated
vendored
@ -24,7 +24,7 @@ const (
|
||||
)
|
||||
|
||||
// SupportedNlFamilies contains the list of netlink families this netlink package supports
|
||||
var SupportedNlFamilies = []int{syscall.NETLINK_ROUTE, syscall.NETLINK_XFRM}
|
||||
var SupportedNlFamilies = []int{syscall.NETLINK_ROUTE, syscall.NETLINK_XFRM, syscall.NETLINK_NETFILTER}
|
||||
|
||||
var nextSeqNr uint32
|
||||
|
||||
@ -321,6 +321,7 @@ func (a *RtAttr) Serialize() []byte {
|
||||
type NetlinkRequest struct {
|
||||
syscall.NlMsghdr
|
||||
Data []NetlinkRequestData
|
||||
RawData []byte
|
||||
Sockets map[int]*SocketHandle
|
||||
}
|
||||
|
||||
@ -332,6 +333,8 @@ func (req *NetlinkRequest) Serialize() []byte {
|
||||
dataBytes[i] = data.Serialize()
|
||||
length = length + len(dataBytes[i])
|
||||
}
|
||||
length += len(req.RawData)
|
||||
|
||||
req.Len = uint32(length)
|
||||
b := make([]byte, length)
|
||||
hdr := (*(*[syscall.SizeofNlMsghdr]byte)(unsafe.Pointer(req)))[:]
|
||||
@ -343,6 +346,10 @@ func (req *NetlinkRequest) Serialize() []byte {
|
||||
next = next + 1
|
||||
}
|
||||
}
|
||||
// Add the raw data if any
|
||||
if len(req.RawData) > 0 {
|
||||
copy(b[next:length], req.RawData)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
@ -352,6 +359,13 @@ func (req *NetlinkRequest) AddData(data NetlinkRequestData) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization
|
||||
func (req *NetlinkRequest) AddRawData(data []byte) {
|
||||
if data != nil {
|
||||
req.RawData = append(req.RawData, data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the request against a the given sockType.
|
||||
// Returns a list of netlink messages in serialized format, optionally filtered
|
||||
// by resType.
|
||||
@ -445,18 +459,18 @@ func NewNetlinkRequest(proto, flags int) *NetlinkRequest {
|
||||
}
|
||||
|
||||
type NetlinkSocket struct {
|
||||
fd int
|
||||
fd int32
|
||||
lsa syscall.SockaddrNetlink
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func getNetlinkSocket(protocol int) (*NetlinkSocket, error) {
|
||||
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, protocol)
|
||||
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW|syscall.SOCK_CLOEXEC, protocol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &NetlinkSocket{
|
||||
fd: fd,
|
||||
fd: int32(fd),
|
||||
}
|
||||
s.lsa.Family = syscall.AF_NETLINK
|
||||
if err := syscall.Bind(fd, &s.lsa); err != nil {
|
||||
@ -542,7 +556,7 @@ func Subscribe(protocol int, groups ...uint) (*NetlinkSocket, error) {
|
||||
return nil, err
|
||||
}
|
||||
s := &NetlinkSocket{
|
||||
fd: fd,
|
||||
fd: int32(fd),
|
||||
}
|
||||
s.lsa.Family = syscall.AF_NETLINK
|
||||
|
||||
@ -571,30 +585,32 @@ func SubscribeAt(newNs, curNs netns.NsHandle, protocol int, groups ...uint) (*Ne
|
||||
}
|
||||
|
||||
func (s *NetlinkSocket) Close() {
|
||||
syscall.Close(s.fd)
|
||||
s.fd = -1
|
||||
fd := int(atomic.SwapInt32(&s.fd, -1))
|
||||
syscall.Close(fd)
|
||||
}
|
||||
|
||||
func (s *NetlinkSocket) GetFd() int {
|
||||
return s.fd
|
||||
return int(atomic.LoadInt32(&s.fd))
|
||||
}
|
||||
|
||||
func (s *NetlinkSocket) Send(request *NetlinkRequest) error {
|
||||
if s.fd < 0 {
|
||||
fd := int(atomic.LoadInt32(&s.fd))
|
||||
if fd < 0 {
|
||||
return fmt.Errorf("Send called on a closed socket")
|
||||
}
|
||||
if err := syscall.Sendto(s.fd, request.Serialize(), 0, &s.lsa); err != nil {
|
||||
if err := syscall.Sendto(fd, request.Serialize(), 0, &s.lsa); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NetlinkSocket) Receive() ([]syscall.NetlinkMessage, error) {
|
||||
if s.fd < 0 {
|
||||
fd := int(atomic.LoadInt32(&s.fd))
|
||||
if fd < 0 {
|
||||
return nil, fmt.Errorf("Receive called on a closed socket")
|
||||
}
|
||||
rb := make([]byte, syscall.Getpagesize())
|
||||
nr, _, err := syscall.Recvfrom(s.fd, rb, 0)
|
||||
nr, _, err := syscall.Recvfrom(fd, rb, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -606,7 +622,8 @@ func (s *NetlinkSocket) Receive() ([]syscall.NetlinkMessage, error) {
|
||||
}
|
||||
|
||||
func (s *NetlinkSocket) GetPid() (uint32, error) {
|
||||
lsa, err := syscall.Getsockname(s.fd)
|
||||
fd := int(atomic.LoadInt32(&s.fd))
|
||||
lsa, err := syscall.Getsockname(fd)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user