Commit Graph

496 Commits

Author SHA1 Message Date
stffabi
5f2fc868c2 Add BridgeSetVlanFiltering to change VlanFiltering on an existing bridge
Signed-off-by: stffabi <stffabi@pm.me>
2020-02-18 12:46:31 -05:00
Tobias Klauser
bfba8e4149 Correct value of SizeofXfrmUsersaFlush
struct xfrm_usersa_flush contains a single u8, thus sizeof(struct
xfrm_usersa_flush) == 1 as can be verified by running the following
code through go tool cgo -godefs:

    package xfrm_test

    // #include <linux/xfrm.h>
    import "C"

    const SizeofXfrmUsersaFlush = C.sizeof_struct_xfrm_usersa_flush

which results in

    // Code generated by cmd/cgo -godefs; DO NOT EDIT.
    // cgo -godefs foo.go

    package xfrm_test

    const SizeofXfrmUsersaFlush = 0x1

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-02-10 14:25:39 -08:00
chendotjs
a2e8781202 rule: add support for dport/sport 2020-02-10 06:52:06 -08:00
Jianlin Lv
5e92c072cd check payload of the NLMSG_DONE nlmsg
check the payload of the NLMSG_DONE type netlink
message for possible error

Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
2020-02-09 10:25:19 -08:00
Amit Nishry
7ed9c95980 rule, add TOS
Signed-off-by: Amit Nishry <amit.nishry@gmail.com>
2020-02-09 10:15:44 -08:00
Vishvananda Abrams
261f000a62 Fix parseIpTun to handle empty flow based flag
Fixes #509
2020-01-27 15:52:54 -08:00
Tobias Klauser
8f32382eaa Use IfaCacheinfo and IFA_* consts from golang.org/x/sys/unix
Use the IfaCacheinfo type and the IFA_* consts from
golang.org/x/sys/unix instead of locally duplicating them.
2020-01-27 15:51:47 -08:00
Tobias Klauser
7e7e2d40cd Update golang.org/x/sys to current master
This will allow to use type IfaCacheinfo.
2020-01-27 15:51:47 -08:00
Francis Begyn
01d9156030 Service curves fix
There was something off with the math for the ServiceCurves. The set value was 8
times too large and the returned one was 8 times too small.

This is now fixed in `class.go` and `class_linux.go` so the user can just set the rate in bit and
it will match the tc show output.
2020-01-27 15:49:46 -08:00
Konstantin Belyalov
b2372689b9 Save XDP attach mode into LinkXdp. 2020-01-27 15:47:19 -08:00
Konstantin Belyalov
0f858a2aeb [non linux: netlink/xdp] Add dummy function for LinkSetXdpFdWithFlags 2020-01-27 15:46:36 -08:00
Mamduh Alassi
f049be6f39 Fix LinkSetVfGUID to not reverse the GUID 2020-01-17 10:40:31 -08:00
Benjamin Peterson
ec20eb4fc3 fix link statistics pointer alignment
gc's `-d checkptr` option reported the following problem:
```
--- FAIL: TestAddrAdd (0.00s)
panic: runtime error: unsafe pointer conversion [recovered]
	panic: runtime error: unsafe pointer conversion

goroutine 19 [running]:
testing.tRunner.func1(0xc00011a240)
	go/src/testing/testing.go:916 +0xaeb
panic(0x7f5c80, 0xc00013a100)
	go/src/runtime/panic.go:973 +0x396
github.com/vishvananda/netlink.LinkDeserialize(0x0, 0xc000174010, 0x514, 0x514, 0x1, 0x1, 0x0, 0x0)
	netlink/link_linux.go:1674 +0x33c5
github.com/vishvananda/netlink.execGetLink(0xc0001540a0, 0xc00013a0a0, 0x2, 0x2, 0x3)
	netlink/link_linux.go:1495 +0x205
github.com/vishvananda/netlink.(*Handle).LinkByName(0xa95e70, 0x81c4c9, 0x2, 0x4, 0x4, 0xc, 0x1)
	netlink/link_linux.go:1415 +0x578
github.com/vishvananda/netlink.LinkByName(...)
	netlink/link_linux.go:1395
github.com/vishvananda/netlink.DoTestAddr(0xc00011a240, 0x82d878)
	netlink/addr_test.go:62 +0xfbc
github.com/vishvananda/netlink.TestAddrAdd(0xc00011a240)
	netlink/addr_test.go:15 +0x45
testing.tRunner(0xc00011a240, 0x82d898)
	go/src/testing/testing.go:954 +0x1ec
created by testing.(*T).Run
	go/src/testing/testing.go:1005 +0x661
FAIL	github.com/vishvananda/netlink	0.006s
FAIL
```

Make sure the link structures are properly aligned.
2020-01-08 09:05:10 -08:00
Zhiyuan Hou
ed8931371a filter, action: Add support for skbedit
Signed-off-by: Zhiyuan Hou <zhiyuan2048@linux.alibaba.com>
2019-12-17 09:15:28 -08:00
Zhiyuan Hou
e25c252266 filter, action: Add support for tunnel_key
Signed-off-by: Zhiyuan Hou <zhiyuan2048@linux.alibaba.com>
2019-12-03 14:07:18 -08:00
takt
d71301a47b Attach RTA_ENCAP_TYPE to children, not rtAttrs, when using Multipath 2019-11-13 10:34:27 -08:00
Daniel Borkmann
cbc6cb49af link, veth: fix stack corruption from retrieving peer index
For 4.20 and newer kernels VethPeerIndex() causes a stack corruption as
the kernel is copying more data to golang user space than originally
expected. This is due to a recent kernel commit where it extends veth
driver's ethtool stats for XDP:

  https://git.kernel.org/torvalds/c/d397b9682c1c808344dd93b43de8750fa4d9f581

The VethPeerIndex()'s logic is utterly wrong to assume ethtool stats are
never extended in the driver. Unfortunately there is no other way around
in golang than to add serialize/deserialize helpers to have a dynamically
sized ethtoolStats with a uint64 data array that has the size of the previous
result from the ETHTOOL_GSSET_INFO query. This ensures we don't run into
a buffer overflow triggered by kernel's copy_to_user() in ETHTOOL_GSTATS
query (ethtool_get_stats() in kernel). Now, for the deserialize operation
we really only care about the peer's ifindex which is always stored in
the first uint64.

Fixes: 54ad9e3a4c ("Two new functions: LinkSetBondSlave and VethPeerIndex")
Reported-by: Jean Raby <jean@raby.sh>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: phob0s <git@phob0s.pl>
2019-11-13 10:31:03 -08:00
Daniel Borkmann
b9fd9670a1 link, veth: remove useless call to retrieve ethtool strings
It's not needed for retrieving the veth peer ifindex, and we already
get the set count via earlier ETHTOOL_GSSET_INFO call. Both are copying
veth_get_sset_count() up to user space in veth case (which is the only
user of this anyway).

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-11-13 10:31:03 -08:00
J. Brandt Buckley
aad0baef28 Don't auto-set broadcast unless subnet larger than /31
Since [vishvananda/netlink#248](https://github.com/vishvananda/netlink/pull/248), adding an address automatically sets the broadcast if the broadcast address was not specified. This is undesirable when adding an IP with a prefixlen of /31 or /32. (Additional details in the issues linked below.)

This changes the behavior so that the broadcast is only automatically set if the prefixlen is /30 or larger.

Issue reported in:

- https://github.com/vishvananda/netlink/issues/329
- https://github.com/vishvananda/netlink/issues/471

See also:

- [RFC 3021](http://tools.ietf.org/html/rfc3021)

Alternatives to this PR:

A. https://github.com/vishvananda/netlink/issues/472 - Adds `AddrAddWithoutCalculatedBroadcast`.
B. 9a85a619d2 - Breaking change to make auto-setting the broadcast address an opt-in feature.
C. already works - Suppress setting the broadcast when addr's broadcast address is set to `0.0.0.0`. (This works today, but I'm not sure the behavior can be relied upon as a public API.)
2019-11-13 10:28:39 -08:00
Tobias Klauser
e934999cd7 Add support for Go modules
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2019-11-07 09:00:16 -08:00
Takushi Fujiwara
2ec5bdc52b Change LinkSetMaster's master argument type. (*Bridge -> Link)
LinkSetMaster also works with Bond device.
So this PR changes the type of master argument to Link.
2019-09-30 07:54:47 -07:00
Yakushi Fujiwara
ac5f4df047 Add support for parsing IFLA_BOND_ARP_IP_TARGET 2019-09-24 13:57:46 -07:00
Oleg Senin
6b3a223c53 Add ip6tnl support 2019-09-24 13:56:29 -07:00
Ihar Hrachyshka
07ace697be Introduce constants for known VF link states 2019-09-24 13:55:40 -07:00
Sam Gwydir
205d80393d Support setting link state for SR-IOV VFs 2019-09-24 13:55:40 -07:00
Takushi Fujiwara
205a160d2e Add bond slave information
This PR refers to PR@lebauce and add some changes.
- Added some tests to retrieve bond slave information.
- Link.BondSlave is changed to LinkSlave interface.
- BondSlaveState.String() returns UPPER case. (same as iproute2)
- BondSlaveMiiStatus.String() returns UPPER case. (same as iproute2)
2019-09-16 08:52:39 -07:00
Laurent Bernaille
e906d22624 Add support for output-mark 2019-09-16 08:26:04 -07:00
Tobias Klauser
36d367fd76 Remove unused *_PROTO constants
These are unused since commit 941b4de9e1

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2019-09-13 09:58:27 -07:00
Juan-Luis de Sousa-Valadas Castaño
07130f38b9 Fix parsing of IFLA_GRE_COLLECT_METADATA 2019-09-12 09:05:07 -07:00
Nicolas Belouin
a1c9a648f7 neighSubscribeAt: AF_BRIDGE entries not listed when listExisting is true
When subscribing to neigh updates, the updates for all neigh
protocol families are received. However when listExisting is set,
the request is made with AF_UNSPEC family, this request does not
include AF_BRIDGE entries.

This patch add a second request for AF_BRIDGE entries.

Add test for existing AF_BRIDGE entry and make expectNeighUpdate
take a slice of expected updates

Creates a VXLAN interface for this test as its AF_BRIDGE entries
looks a lot like usual ones

Also add support for latest (2014+) neighbour attributes

NDA_MASTER was added back in 2014, it indicates whether a neigh
entry is linked to a master interface and index of this interface.

The other entries, namely NDA_LINK_NETNSID and NDA_SRC_VNI were
added later and will need extra handling.

Signed-off-by: Nicolas Belouin <nicolas.belouin@gandi.net>
2019-08-23 11:29:04 -07:00
GopiKrishna Kodali
941b4de9e1 Read connection marking information from CT flow TLV 2019-08-23 11:20:03 -07:00
Yakushi Fujiwara
254c8a89c5 Replace values defined in unix package.
- replace following values to unix.*
  AF_MPLS, RTA_NEWDST, RTA_ENCAP_TYPE, RTA_ENCAP
2019-08-23 11:17:48 -07:00
Naiming Shen
e825b754c0 Add Timestamp, Timeout to conntrack
Signed-off-by: Naiming Shen <naiming@zededa.com>
2019-08-12 12:01:13 -07:00
Adrian Chiris
46ae81cf70 Add support for IPoIB interfaces
- Add a new Link type, IPoIB, that exposes the following IPoIB attributes:
    * IFLA_IPOIB_PKEY
    * IFLA_IPOIB_MODE
    * IFLA_IPOIB_UMCAST
- Suppport Deserialize for IPoIB link attributes in LinkDeserialize()
- Support IPoIB attributes in LinkAdd()
2019-08-12 04:46:40 -07:00
Thomas Bucher
b4e9f47a11 Update netlink_unspecified.go
AddrReplace was missing, could not compile on OSX
2019-07-26 00:49:17 +02:00
Adrian Chiris
28720742a4 Add support for IFLA_VF_RATE
Today netlink package supports Get/Set of a VF's max TX rate
via IFLA_VF_TX_RATE netlink attribute.

This patch add support to Get/Set of a VFs min and max TX rate
via IFLA_VF_RATE netlink attribute.

- Add support to set min/max tx rate for VF via IFLA_VF_RATE
- Added IFLA_VF_RATE min/max tx rate attributes to netlink.VfInfo
  including parsing support in netlink.parseVfInfo()

NOTE: According to [1] IFLA_VF_RATE takes precedence over
      IFLA_VF_TX_RATE. Dealing with the co-existance of these
      netlink attributes is left for the user to handle.

[1]https://lists.openwall.net/netdev/2014/05/22/42
2019-07-25 03:38:53 +02:00
bingshen.wbs
14bd2e6fd2 support ipvlan flag
Signed-off-by: bingshen.wbs <bingshen.wbs@alibaba-inc.com>
2019-07-25 03:37:08 +02:00
Daniel Borkmann
b1e9859792 netlink: enforce similar pid checks as in iproute2
iproute2's own netlink library asserts that the sockaddr sender pid
has to be the one of the kernel [0]. It also doesn't bail out on pid
mismatch but only skips the message instead. We've seen cases where
the latter had a pid 0; in such case we should skip to the next nl
message instead of hard bail out.

  [0] https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/lib/libnetlink.c
      rtnl_dump_filter_l(), __rtnl_talk_iov()

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-18 17:26:53 -07:00
Przemyslaw Lal
43af4161ea Add support for setting VLAN QoS for VF links
This change adds support for setting VLAN QoS (priority) field for the
SR-IOV Virtual Function links.
2019-07-15 07:57:55 -07:00
Anton Aksola
df01369528 add support for link groups (IFLA_GROUP) 2019-07-13 20:34:27 -07:00
Farid Zakaria
2e4a68ee6c Add support for additional TC BPF filter attributes
In order to support BPF_SYSCALL `PROG_GET_FD_BY_ID` -- the ID of the
eBPF must be available.

Add the additional enumerations and handle them when parsing the BPF
filter.
2019-07-01 11:37:39 -07:00
Lorenz Bauer
a8241965b5 Allow replacing filters
Add a function FilterReplace, which mirrors the behaviour of
QdiscReplace, etc. This makes it possible to swap out filters
with a single netlink message.
2019-06-24 06:52:36 -07:00
Martynas Pumputis
99a56c251a veth: Set peer hardware addr when creating
This commit extends LinkAdd function for Veth by allowing to specify
peer hardware addr.

Signed-off-by: Martynas Pumputis <m@lambda.lt>
2019-06-18 07:33:17 -07:00
Parav Pandit
123a384710 Add an API to change net namespace of RDMA device
Add an API to change net namespace of RDMA device similar to

$ rdma dev set [DEV] netns NSNAME

Signed-off-by: Parav Pandit <parav@mellanox.com>
2019-06-13 22:19:36 -07:00
Sargun Dhillon
d50d15ce3f Set Link TX / RX Queues on Deserialization
This deserializes the tx queue, and rx queue count on link
deserialization. We already supported it on serialization.

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
2019-06-12 19:02:44 -07:00
eriknordmark
3a1f6536f6 Make AddrSubscribe more robust against kernel reporting errors 2019-06-10 08:41:22 -07:00
Parav Pandit
0f040b9e2c Add an API to set RDMA subsystem network namespace mode
Add an API to change the RDMA subsystem network namespace mode as either
shared or exclusive similar to

$ rdma system set netns { shared | exclusive }

Signed-off-by: Parav Pandit <parav@mellanox.com>
2019-06-07 21:21:07 -07:00
Parav Pandit
4666477197 Add an API to query RDMA subsystem net namespace mode
RDMA subsystem can be running in shared or exclusive mode with regards
to sharing RDMA device sharing among multiple network namespaces.

Add and API to query such mode of kernel similar to iproute2 command
$ rdma system show netns

Signed-off-by: Parav Pandit <parav@mellanox.com>
2019-06-07 21:21:07 -07:00
yandong.yan
c8c507c80e fix: fix ip rule goto bug 2019-06-03 19:20:42 -07:00
Archana Shinde
db99c040b9 tuntap: Return TunTapLink instead of GenericLink
For tuntap interfaces, return a TunTap Interface instead of
a Generic link when retrieving the interface.
Use netlink extended attributes to populate the Link attributes
for the tuntap link.
In case of older tun driver which does not provide these
attributes, use sysfs to retrieve these attributes.

This commit also adds Owner and Group attributes for the TunTap
Link.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
2019-06-03 12:01:21 -07:00