20 Commits

Author SHA1 Message Date
Anthony Harivel
b3f5422a3b
link: add support for IFLA_VFINFO_LIST and IFLA_VF_STATS (#295)
Add support for decoding Virtual Function (VF) information from netlink
messages. This enables users to retrieve SR-IOV VF details when querying
network interfaces.

The implementation adds:
- VFStats struct containing per-VF traffic statistics (packets, bytes,
  broadcast, multicast, dropped counters for both RX and TX)
- VFInfo struct containing VF configuration (MAC address, VLAN, QoS,
  TX rate limits, spoof check, link state, RSS query, trust settings)
- VFLinkState type with Auto/Enable/Disable constants
- NumVF and VFInfoList fields to LinkAttributes
- Decoding logic for IFLA_NUM_VF and IFLA_VFINFO_LIST nested attributes

The VF information follows the kernel's nested attribute structure.

This is useful for monitoring and managing SR-IOV enabled network
interfaces where the Physical Function (PF) exposes multiple Virtual
Functions to guest VMs or containers.

Signed-off-by: Anthony Harivel <aharivel@redhat.com>
2026-02-08 12:50:40 +01:00
Jeroen Simonetti
5c41262525
Implement additional drivers (#280)
Add drivers for bridge, macvlan, vlan, vxlan and add helpers to
LinkService to use them (SetMaster, RemoveMaster)

Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
2025-10-30 22:55:44 +01:00
Andrey Smirnov
cff2178760
feat: add support for address priority (#256)
This allows to set route priority/metric for prefix routes created
automatically when an address is assigned.

E.g. `10.0.0.0/8` with metric `32` would generate a route:

```
10.0.0.0/8 via <if> metric 32
```

The default metric is zero. A custom metric allows to prefer
one interface over another when the prefixes overlap.

See https://github.com/siderolabs/talos/issues/10696

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-04-15 10:06:46 +02:00
Andrey Smirnov
ec4117e892
feat: implement support for altnames (#241)
This properly list is used e.g. by `systemd-udevd` to provide other
alternative names for predictable interface names.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2024-12-16 17:28:22 +01:00
Timo Beckers
3fefb86a94
Refactor netns handling, fix flakes, namespace some tests (#227)
* netns: remove iproute2 dependency

This commit introduces a breaking change to rtnetlink.NetNS.

The existing netns implementation had a few problems. It assumed that network
namespaces have names, that they would always be pinned to /var/run/netns, and
that numeric/integer references are pid references. This made the NetNS type
unusable for referring to existing netns by fd, such as ones created by other
libraries, or by opening procfs entries directly as demonstrated in the new
testutils.NetNS() function.

The forced dependency on the `ip` CLI tool also wasn't reasonable for a pure-Go
library. Using the old implementation in a scratch/distroless container would
quickly run into roadblocks.

This commit also removes the functionality of creating and pinning new netns.
There are plenty of options out in the Go ecosystem for that, and providing
your own is only a few lines of code.

Signed-off-by: Timo Beckers <timo@incline.eu>

* test: remove calls to unix.Setrlimit() in favor of rlimit.RemoveMemlock()

ebpf-go provides this out of the box and skips setting the rlimit on kernels
that support bpf memory cgroup accounting.

Signed-off-by: Timo Beckers <timo@incline.eu>

* neigh: fix flaky tests, add State field to Neigh entry

The flaky tests that were documented in the code are expected. Use the State
field to discard entries that can't reasonably be considered in tests.

Signed-off-by: Timo Beckers <timo@incline.eu>

* neigh: fix race in Conn.Neighbours

When running tests locally, I would frequently hit "too many/little matches,
expected 1, actual 0" due to other tests creating and deleting interfaces in
the common host netns used by all tests.

Neigh entries that fail the interface lookup can't have their Interface fields
populated and should be dropped from the result since the interface is no longer
there to begin with.

Signed-off-by: Timo Beckers <timo@incline.eu>

* xdp: refactor test suite to use test helpers and netns-driven tests

While running the test suite for testing netns-related changes, I noticed
some of the xdp tests started failing because they wanted to create a dummy
interface in the host network namespace.

Avoid the complexity of managing dummy interfaces altogether by running all
tests within their own netns and use the existing lo device that's present by
default.

Signed-off-by: Timo Beckers <timo@incline.eu>

* xdp,netkit: remove duplicate kernelMinReq in favor of testutils.SkipOnOldKernel

There were two implementations of this, so move them to common testutils.

Signed-off-by: Timo Beckers <timo@incline.eu>

---------

Signed-off-by: Timo Beckers <timo@incline.eu>
2024-05-15 13:44:37 +02:00
Birol Bilgin
bd79d59a97
Add LinkDriver interface and Driver package (#221)
* Add attr validation

This commit removes unix.IFLA_UNSPEC and introduces checks for the interface name,
the link type and the queue disc fields.
Interface name validation is necessary to prevent an 'invalid argument' error
when creating a link with an empty name. Other checks were added to be consistent with the ip tools.

Signed-off-by: Birol Bilgin <birolbilgin@gmail.com>

* Add network namespace type

This commit introduces the NetNS struct and integrates network namespace capabilities into link attributes.
This enhancement facilitates the creation of links, such as veth pairs, across different network namespaces
without the need to execute directly within those namespaces.

Signed-off-by: Birol Bilgin <birolbilgin@gmail.com>

* Add LinkDriver interface

This commit introduces a Driver interface and changes Data and SlaveData fields within the LinkInfo struct
as LinkDriver to accommodate driver-specific data encoding, addressing the limitation
where LinkInfo.Data and SlaveData fields were merely byte slices without support for specific data encoding.

Drivers are registered globally with the RegisterDriver function.
For un-registered drivers, the default LinkData driver is used.

Signed-off-by: Birol Bilgin <birolbilgin@gmail.com>

* Add Driver Package

This commit introduces the 'driver' package, which contains specific implementations of the LinkDriver interface.
It also includes the implementation of the Linux bond driver as LinkDriver and the bond slave driver as LinkSlaveDriver.

Signed-off-by: Birol Bilgin <birolbilgin@gmail.com>

* Add Netkit and Veth drivers

This commit adds Netkit and Veth drivers.

Signed-off-by: Birol Bilgin <birolbilgin@gmail.com>

---------

Signed-off-by: Birol Bilgin <birolbilgin@gmail.com>
2024-05-10 08:51:09 +02:00
SUN Haoyu
f070a40baa
Add new attributes to LinkAttributes with decoder. (#153)
Signed-off-by: Haoyu Sun <hasun@redhat.com>
2022-10-09 01:59:02 +02:00
Florian Lehner
a833fb5b68
add netlink/rule (#139)
* add netlink/rule

Signed-off-by: Florian Lehner <dev@der-flo.net>

* Add some fuzzing corpus

Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>

Co-authored-by: Jeroen Simonetti <jeroen@simonetti.nl>
2022-04-12 09:00:30 +02:00
Matt Layher
3f746d924b
rtnetlink: support for RTA_PREF (#137)
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2022-03-13 18:00:51 +01:00
Matt Layher
93da338047
rtnetlink: Go 1.17 build tags, fix example build tags (#128)
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2021-10-22 21:23:32 +02:00
Francis Begyn
97e6deb670
Patch LinkXDP data types and encoding behavior (#113)
LinkXDP was using uint32 datatypes for the file desriptor fields, but this
makes it so you're unable to clear or send correct netlink message. It was also
always encoding all fields, while the rtnetlink API was not expecting this.

don't encode XDP_ATTACHED and XDP_PROG_ID fields: https://elixir.bootlin.com/linux/v5.10.15/source/net/core/rtnetlink.c#L2894
use int32 for FD and EXPECTED_FD fields: https://elixir.bootlin.com/linux/v5.10.15/source/net/core/rtnetlink.c#L1924

The PR patches the fields and encoding behavior to resolve this conflict.

Signed-off-by: Francis Begyn <francis@begyn.be>
2021-03-07 21:38:07 +01:00
Matt Layher
8d122574c7
rtnetlink: add RouteMetrics.InitRwnd field (#104)
Signed-off-by: Matt Layher <mlayher@fastly.com>
2021-01-22 17:32:28 +01:00
Matt Layher
beb2a7965b
internal/unix: fix Mac build
Signed-off-by: Matt Layher <mlayher@fastly.com>
2020-11-18 15:30:48 -05:00
Matt Layher
057ddd1f37
rtnetlink: implement MPLSNextHop encoding and decoding
Signed-off-by: Matt Layher <mlayher@fastly.com>
2020-11-18 15:26:31 -05:00
Florian Lehner
b76ef30e43
Add XDP encode/decoder (#91)
Signed-off-by: Lehner Florian <dev@der-flo.net>
2020-11-04 01:56:49 +01:00
Dave Josephsen
bae80799d8 rtnetlink: complete route multipath encoding and decoding logic
Signed-off-by: Dave Josephsen <djosephsen@fastly.com>
Signed-off-by: Matt Layher <mlayher@fastly.com>
2020-10-26 12:43:11 -04:00
Matt Layher
4e9cdead09
rtnetlink: add RouteMetrics nested attributes within RouteAttributes (#81)
Signed-off-by: Matt Layher <mlayher@fastly.com>
2020-10-02 16:52:24 +02:00
jeremiejig
d699427278
route: Implement support for RTA_MARK (#79)
* module: `go mod tidy`

Signed-off-by: Jeremiejig <me@jeremiejig.fr>

* route: Implement support for RTA_MARK

The RTA_MARK attribute allow to send get request with mark information;
it is useful when having multiple table selected by rule policy
matching on fwmark.

Signed-off-by: Jeremiejig <me@jeremiejig.fr>
2020-07-26 18:59:00 +02:00
Jeroen Simonetti
3b195764a9
Fix rtnl for macos (#71)
Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
2020-01-17 13:13:10 +01:00
Florian Lehner
d21b2cb70d resolve GOOS dependency (#63)
* resolve GOOS dependency

Signed-off-by: Lehner Florian <dev@der-flo.net>

* exclude internal constants from linter

Signed-off-by: Lehner Florian <dev@der-flo.net>
2019-10-19 19:25:34 +02:00