28 Commits

Author SHA1 Message Date
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
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
Ben Kochie
8026e5db33
Fix Go mod path (#226)
In order to update to v2.0.0, we need to update the module path per the
Go module documentation.
* https://go.dev/doc/modules/major-version

Fixes: https://github.com/jsimonetti/rtnetlink/issues/225

This can be released as v2.0.1

Signed-off-by: SuperQ <superq@gmail.com>
2024-05-10 16:40:56 +02:00
Ben Kochie
889c07bf6d
Enable golangci-lint (#202)
Add a GitHub actions workflow to run golanci-lint.
* Only uses latest Go version to avoid `gofmt` differences.
* Fixup linting issues.
* Ignore misspell `Prefered` as it is used as a public struct variable.
* Disable `unused-parameter` as it produces unecessary warning noise.

Signed-off-by: SuperQ <superq@gmail.com>
2023-11-27 13:42:29 +01:00
Paweł Zmarzły
03775388c0
Fix invalid LinkMessage family (#144)
Signed-off-by: Pawel Zmarzly <pzmarzly@fb.com>
2022-07-20 20:25:37 +02: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
Matt Layher
af39de65d6
rtnetlink: make AddressMessage.Attributes optional via pointer (#124)
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2021-07-14 15:52:44 +02:00
Julian Kornberger
bde56ed163
Cleanup (#94)
* Clean up code and remove code duplication
* Apply gofmt

Signed-off-by: Julian Kornberger <jk+github@digineo.de>
2020-12-16 14:43:43 +01:00
Seán C. McCord
8a8c0ddd67
feat: support multiple matching routes (#100)
* feat: support multiple matching routes

Adds support for returning multiple matching routes for rtnl.

Fixes #99

Signed-off-by: Seán C McCord <ulexus@gmail.com>

* Fixing style errors.

Co-authored-by: stickler-ci <support@stickler-ci.com>
2020-12-06 12:37:23 +01:00
Pablo Mazzini
014bdad0d6 Merge branch 'master' into route
Signed-off-by: Pablo Mazzini <pmazzini@gmail.com>
2020-11-04 16:51:25 +00:00
Pablo Mazzini
6693401ca1 [rtnl] add RouteGet method
Signed-off-by: Pablo Mazzini <pmazzini@gmail.com>
2020-11-04 08:10:46 +00:00
Spencer Smith
7cf95b6356
[rtnl] support functional args for routes (#86)
This PR will add the ability to use functional args for route
add/replace with rtnl. Currently, two functions are supported,
`WithRouteSrc` and `WithRouteAttrs`. This allows the consolidation of
the route methods, as well as adding the ability to BYO-Attributes for a
given route. This layout can of course be extended to add other
route-specific args, as well as a starting point for options and args for other parts of the
rtnl package as time goes on.

Note that this removes the `RouteAddSrc` and `RouteReplaceSrc`
functions.

Signed-off-by: Spencer Smith <robertspencersmith@gmail.com>
2020-10-22 10:05:59 +02:00
Davydov Denis
154ecd4176 - added methods for replace route
Signed-off-by: Davydov Denis <dadmoscow@gmail.com>
2020-04-13 15:44:53 +03:00
Jeroen Simonetti
f846d4f6c1
Use github actions (#70)
Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
2020-01-17 13:37:17 +01: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
Brad Beam
1b9462860a fix: Adjust route scope decision (#67)
Change route scope decision to be based on gateway. This should
make more sense because a link without a gateway should reside
on the same subnet.

Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
2019-12-23 09:40:07 +01:00
Timo Beckers
228b24473a rtnl - set 'host' scope when adding loopback addresses (#66)
Signed-off-by: Timo Beckers <timo@incline.eu>
2019-12-03 19:33:23 +01:00
Timo Beckers
5d027701a5 rtnl.(Must)ParseAddr and documentation fixes (#65)
* rtnl: add ParseAddr and MustParseAddr helpers, add usage examples

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

* addr_*_test - test ParseAddr and MustParseAddr

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

* Examples: use first ParseCIDR return value as IP address

Signed-off-by: Timo Beckers <timo@incline.eu>
2019-12-03 01:13:55 +01:00
Brad Beam
3784a6c7c5 feat(rtnl): Add better handling for route scope decisions (#58)
Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
2019-08-30 11:01:07 +01:00
Yaroslav Kolomiiets
6e7d6532fc rtnl: extend integration tests to include Neighbours()
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-06-06 15:25:42 +01:00
Yaroslav Kolomiiets
f03390fac9 rtnl: only skip TestLiveAddrAddDel if EPERM, fail otherwise
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-05-02 12:26:50 +01:00
Yaroslav Kolomiiets
f505b733d0 rtnl: AddrAdd: ensure v4 address format is used for AF_INET
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-05-01 13:07:41 +01:00
Yaroslav Kolomiiets
cc931d0061 rtnl: fix bad IPMask returned in Addrs()
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-05-01 13:07:31 +01:00
Yaroslav Kolomiiets
317cffa967 rtnl: add Addr* integration tests
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-04-29 17:22:13 +01:00
insomniac
b8fe779e51
[rtnl] Remove unnecessary parameters from RouteDel (#50)
As discussed on https://github.com/jsimonetti/rtnetlink/pull/47

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-04-27 15:41:53 +01:00
Andrea Barberio
c1c593ef5f [rtnl] Add RouteDel and RouteAddSrc
Added `RouteDel` to support route deletion.
Also added `RouteAddSrc` to support adding routes with a source parameter.

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-04-26 19:52:23 +01:00
Yaroslav Kolomiiets
690b790d9c rtnl: do not drop error on Close() but leave to caller
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-04-26 17:43:25 +01:00
Yaroslav Kolomiiets
ac4930ec47 add rtnl, the new high-level wrapper package
Signed-off-by: Yaroslav Kolomiiets <yarikos@gmail.com>
2019-04-26 15:44:14 +01:00