Commit Graph

187 Commits

Author SHA1 Message Date
Tobias Klauser
f7fd7af437 Only set IFLA_XFRM_IF_ID if not 0
A value of 0 for IFLA_XFRM_IF_ID is not valid and will be rejected by
the kernel by returning EINVAL, see [1]. Thus, only set the
IFLA_XFRM_IF_ID attribute in case Xfrmi.Ifid != 0.

[1] 8efd0d9c31/net/xfrm/xfrm_interface.c (L645-L648)
2022-02-24 05:54:17 -08:00
Tao Li
f24382625b add proto field to Iptun 2022-02-17 12:20:32 -06:00
Tobias Urdin
650dca95af Export LinkModify function
When the LinkModify was merged in [1] a function
that exports it outside of pkgHandle was never
added like is available for LinkAdd, LinkDel etc.

Update testing to use exported LinkModify that
itself calls the pkgHandle.LinkModify function.

[1] https://github.com/vishvananda/netlink/pull/541
2021-11-18 08:18:26 -08:00
Joris Bonnefoy
fc5a223eaf Set NetNsId to -1 when attr is not specified 2021-11-01 11:26:46 -05:00
montag451
187053b978 Use SyscallConn() instead of Fd() to persist TUN/TAP interface
os.File.Fd() puts back the file descriptor in blocking mode which is
pretty annoying as SetDeadline will stop working
2021-09-24 15:29:09 -05:00
张祖建
b8aac10bba fix staticcheck issues 2021-09-21 09:10:48 -05:00
bersoare
7992ad9959 add support for bareudp link type 2021-09-17 10:14:18 -07:00
Dennis Afanasev
21f2c55a77 Add PHYS_SWITCH_ID attribute to LinkAttrs 2021-07-03 11:55:58 +02:00
eriknordmark
f9d8f911db more consistent error handling
Signed-off-by: eriknordmark <erik@zededa.com>
2021-05-30 12:55:19 +02:00
dennisafa
d1e684a60b Ability to set multicast attribute on a link 2021-05-30 12:51:51 +02:00
Tobias Klauser
4ef7bcbf15 Don't re-initialize or shadow package level var native to fix data race
The package level var native (holding the native endianness) is
initialized at package load time. Thus there is no need to re-initalize
it in functions using it, e.g. (*Handle).filterModify, parseU32Data,
parseFwData, parseBpfData and parseMatchAllData.

This fixes a data race between these functions and any read access of
var native, e.g. in LinkDeserialize as reported in issue #633.

Also don't re-declare local variables shadowing the global package-level
var.

Fixes #633

Signed-off-by: Tobias Klauser <tobias@cilium.io>
2021-05-10 07:24:37 -07:00
Riccardo Manfrin
af1e63ea7b Adds vrf slave link slave data parse 2021-05-10 07:22:18 -07:00
Dongdong Wang
dbf5d9e510 Fix another panic case of #509.
Signed-off-by: Dongdong Wang <wangdongdong.6@bytedance.com>
2021-05-08 09:21:41 -07:00
Bjorn Svensson
6063cc66d7 Add allmulti to link attributes
Provide the status of the allmulticast option via the highlevel
link attributes instead of requiring raw flag handling.

Avoid comparing all rawflags before and after in tests due to that
the IFF_RUNNING flag might change independenly.

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
2021-05-08 09:10:00 -07:00
Wei Yang
aa68aabe05 Add ipvtap link support
ipvtap is a similar link type as ipvlan with tap interface.

This patch enables it just like macvtap.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
2021-05-08 08:48:48 -07:00
Riccardo Manfrin
ec93726159 Adds strings translation methods
RTPROT_KEEPALIVED is commented to interop with earlier go versions (1.13, 1.14)
2021-03-04 14:52:04 -08:00
Moshe Litvin
88079d98e6 1. Fixed endianity probem with geneve VNI (ID)
2. Parse remote IP
3. Added unit test to test geneve paramters against "ip link"
2020-12-06 12:36:32 -08:00
Ahmet OZER
f2f0bfd10a Fix Geneve remote ipv4 attr 2020-12-05 19:47:00 -08:00
Stephen Hassard
d185ffdb62 Add Geneve link support
Heavily based on the existing Gretap support
2020-11-21 23:35:49 -08:00
lmbsog0
c7261bd9e0 add support for CAN 2020-11-20 12:42:29 -08:00
killianmuldoon
d40f9887b8 Add TxBytes to VFStats collection 2020-10-29 16:33:52 -04:00
root
e30b76407c VF stats struct and deserialization method added. VfStats now reported in the VfInfo struct
Co-authored-by: PatrickKutch <patrick.kutch@gmail.com>
2020-10-19 15:29:26 -04:00
Jaime Caamaño Ruiz
02121dbd7e Add LinkSetMacvlanMode 2020-09-24 21:35:02 -04:00
Konstantin Baranov
337442361b Allow placing veth peer into a namespace
Creating a veth pair across namespaces now is a multistep process.
Doing it in one shot with this change is clearer as current
namespace never sees peer IF. Also, moving peer into a namespace
may be rather slow, so better avoided.
2020-09-14 10:57:23 -04:00
Vishvananda Abrams
872fbf27a2 Fixes Issue #509 more generically
The first fix #512 apparently didn't solve all cases. This generically
skips values that are null to solve the problem. Also closes #548.
2020-09-14 10:54:56 -04:00
Miguel Duarte Barroso
7484f55b22 tuntap: use the owner / group parameters
Set the tuntap owner / group via syscall on the opened file
descriptor.

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
2020-09-14 10:54:17 -04:00
Dennis Marttinen
9690c54307 Add support for configuring bridge ageing time
Signed-off-by: Dennis Marttinen <dennis@weave.works>
2020-09-14 10:49:43 -04:00
Julian Kornberger
01e0a49c1f Add additional fields to link.Ip6tnl
and optimize aligment of Sittun fields
2020-09-14 10:42:05 -04:00
Sylvain Baubeau
fe26ba2db0 Set default values for link attributes
When deserializing a link related netlink message, if no network namespace id
attribute is specified, we need to set it to -1 otherwise it defaults to 0
which is a valid id. Using NewLinkAttrs sets the default values and allows
the user to distinguish an empty value from a missing value
2020-09-14 10:41:08 -04:00
Dmitrii Okunev
dc0e1b988c feature: Add wireguard link type
Added type "Wireguard" which implements link type "wireguard".

See also https://www.wireguard.com/

Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
2020-06-04 09:01:02 -07:00
Ralph Schmieder
5400e006d4 make tuntap pollable 2020-06-03 12:07:47 -07:00
Sylvain Baubeau
e6be014dfa Fix parsing of IFLA_IPTUN_COLLECT_METADATA
IFLA_IPTUN_COLLECT_METADATA are used as flags and
therefore have no content
2020-06-03 12:01:01 -07:00
Daniel Gollub
12f2829c35 Add LinkModify support
Signed-off-by: Daniel Gollub <dgollub@att.com>
2020-06-03 11:55:45 -07:00
Alex Forster
27f2b32dc6 Configure numrxqueues/numtxqueues on veth peer (fixes #536) 2020-06-03 11:23:51 -07:00
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
Vishvananda Abrams
261f000a62 Fix parseIpTun to handle empty flow based flag
Fixes #509
2020-01-27 15:52:54 -08:00
Konstantin Belyalov
b2372689b9 Save XDP attach mode into LinkXdp. 2020-01-27 15:47:19 -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
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
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
Juan-Luis de Sousa-Valadas Castaño
07130f38b9 Fix parsing of IFLA_GRE_COLLECT_METADATA 2019-09-12 09:05:07 -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
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