Commit Graph

774 Commits

Author SHA1 Message Date
Benjamin Leggett
1f4f72c917 Mimic ipset C code for determining correct default ipset revision
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
2025-05-09 11:39:54 -07:00
lwintermelon
2426b0576c qdisc: fix wrong type info of tc_sfq_qopt 2025-05-09 11:29:26 -07:00
Gwendolyn
a2e4b9a6ec veth: allow configuring peer attributes beyond namespace and address
Signed-off-by: Gwendolyn <me@gwendolyn.dev>
2025-05-09 11:11:58 -07:00
gongguan
9d88d8385b feat: add support for RtoMin lock 2025-04-25 12:38:46 -07:00
Daniel Borkmann
6b5dd30007 geneve: Support setting/getting source port range
Add support for geneve feature to specify source port range, see
kernel commits:

- e1f95b1992b8 ("geneve: Allow users to specify source port range")
- 5a41a00cd5d5 ("geneve, specs: Add port range to rt_link specification")

This is exactly equivalent on what is done in case of vxlan today.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2025-04-25 12:02:59 -07:00
zlava
d85a66b0d8 feat: add IFLA_INET6_ADDR_GEN_MODE support 2025-04-14 15:15:50 -07:00
Julian Wiedmann
5a4ec4bea5 addr_linux: don't require label to be prefixed with interface name
This requirement limits the usefulness of labels (given the total label
length can only be 15 characters).

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
2025-04-09 10:21:29 -07:00
kayos@tcp.direct
38b12299c1 tests: Improve address unit test infrastructure
Signed-off-by: kayos@tcp.direct <kayos@tcp.direct>
2025-04-03 08:32:13 +03:00
Andrey Smirnov
cb48698f25 fix: add missing CLOEXEC flag
Some calls were already using it, some were not, but fix the remaining
ones.

Without this flag, the file descriptor would to the child process after
fork/exec.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-03-27 22:15:54 -07:00
Junhuang Hong
5d6ad2bde7 add SRv6 support for END.DT4 2025-03-27 22:09:14 -07:00
Ivan Tsvetkov
14e2f0a5ba tuntap: add support for dynamically managing multi-queue FDs
Introduce AddQueues and RemoveQueues methods for attaching and detaching
queue file descriptors to an existing TUN/TAP interface in multi-queue mode.
This enables controlled testing of disabled queues and fine-grained queue
management without relying on interface recreation.

Signed-off-by: Ivan Tsvetkov <ivanfromearth@gmail.com>
2025-03-27 21:30:11 -07:00
Ivan Tsvetkov
298a362432 tuntap: parse additional netlink attributes for flags and queues
Signed-off-by: Ivan Tsvetkov <ivanfromearth@gmail.com>
2025-03-27 21:30:11 -07:00
James Lamanna
7740709424 Add support for ARP/ND Timestamps when retriving neighbors
On Linux, Netlink provides NDA_CACHEINFO which carries timestamps about
when ARP/ND was updated, used, and confirmed.

Expose these fields in the Neigh type
2025-03-26 11:54:52 -07:00
ChinmayaSharma-hue
8b05c6bd4c Added PCPU and SA fields to XfrmState 2025-03-26 11:31:48 -07:00
Mateusz Zalega
1f910b7a22 Support "sample" filter action
This change adds support for packet sampling using "psample" kernel
module.
2025-03-26 11:10:41 -07:00
Dylan Reimerink
dc4f225935 Add OifIndex option for RouteGetWithOptions
The `RouteGetWithOptions` function currently has a `Oif` option which
gets translated from link name to link index via a `LinkByName` call.
This adds unnecessary overhead when the link index is already known.

This commit adds a new `OifIndex` option to `RouteGetWithOptions` which
can be specified instead of `Oif` to skip the internal link index
translation.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
2025-03-26 11:00:25 -07:00
Sebastiaan van Stijn
6f000f5d02 go.mod: github.com/vishvananda/netns v0.0.5
- Adding file path for nerdctl and finch

full diff: https://github.com/vishvananda/netns/compare/v0.0.4...v0.0.5

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-26 10:54:39 -07:00
tc
31feb1b4c7 pedit: Fix EncodeActions to add TcGen for pedit action
TcGen was missing in pedit action and the kernel cannont correctly process pedit action.

Signed-off-by: Chen Tang <tangchen.1@bytedance.com>
2025-03-26 10:53:47 -07:00
Tim Rozet
9b61d26766 Add support for MTU Lock
When adding a route with "mtu lock <mtu>" path MTU discovery (PMTUD)
will not be tried and packets will be sent without DF bit set. Upon
receiving an ICMP needs frag due to PMTUD, the kernel will not install a
cached route and lower the MTU.

Signed-off-by: Tim Rozet <trozet@redhat.com>
2025-03-26 10:48:12 -07:00
Jordan Rife
0e7078ed04 netkit: Allow setting MAC address in L2 mode
Signed-off-by: Jordan Rife <jrife@google.com>
2025-03-03 14:47:20 -08:00
Daniel Borkmann
0af32151e7 vxlan: Fix parseVxlanData for source port range
binary.Read() != nil check means error case, so the vxlan.Port{Low,High}
are never populated. Fix the check.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2025-02-21 11:44:27 -08:00
Sven Rebhan
9f534ef909 fix: Use correct offset for unix socket diagnosis
Signed-off-by: Sven Rebhan <srebhan@influxdata.com>
2025-02-20 11:25:08 -08:00
Leon Hwang
655392bc77 Fix parsing 4-bytes attribute
What if the data length of attribute is 4? The attribute will be ignored,
because `i+4 < len(data)`.

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
2025-02-09 08:26:17 -08:00
Daman Arora
62fb240731 conntrack: prevent potential memory leak
Currently, the ConntrackDeleteFilters captures all flow entries
it fails to delete and reports them as errors. This behavior
can potentially lead to memory leaks in high-traffic systems,
where thousands of conntrack flow entries are cleared in a single
batch. With this commit, instead of returning all the un-deleted
flow entries, we now return a single error message for all of them.

Signed-off-by: Daman Arora <aroradaman@gmail.com>
2025-02-06 09:46:18 -08:00
Albin Kerouanton
7c2350bd14 Add IFLA_PARENT_DEV_NAME / IFLA_PARENT_DEV_BUS_NAME to links
These attributes are supported since kernel v5.14 (see [1]). Here's
what iproute2 shows:

```
$ ip -d link show eth0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 65535 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    ... parentbus virtio parentdev virtio0
```

[1]: 00e77ed8e6

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-01-27 16:21:08 -08:00
Adrian Moisey
3642538757 Preserve results when NLM_F_DUMP_INTR is set
Similar to https://github.com/vishvananda/netlink/pull/1018, but for
ConntrackDeleteFilters()

Relates to https://github.com/kubernetes/kubernetes/issues/129562
2025-01-20 22:11:48 -08:00
Dylan Reimerink
86d2f69adc link_linux: Add deserialization of IFF_RUNNING flag
Add deserialization of the `IFF_RUNNING` link flag which translates to
`net.FlagRunning`.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
2025-01-20 22:07:01 -08:00
wangling94
68cf136ebe 1. filter match support vlanId and srcMac, dstMac.
2. filter action support vlan pop/push.
2025-01-16 11:56:41 -08:00
Dylan Reimerink
56a588b0cd .github/workflows: Bump CI Go version to v1.22
Update the Go version we test against to Go v1.22 which is currently the
oldest version still receiving security updates.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
2025-01-16 10:04:49 -08:00
WeidiDeng
391c850512 disable broadcast if broadcast is set to net.IPv4zero
remove comments about broadcast when deleting address

remove another comment about broadcast auto calculation
2025-01-09 19:51:00 -08:00
wangling142
26ee0e2abe 1. fix rule test failed when rule add slow. 2024-12-27 11:12:53 -08:00
Jordan Rife
976bd8de7d Add support for IFLA_NETKIT_SCRUB and IFLA_NETKIT_PEER_SCRUB
Link: https://lore.kernel.org/bpf/20241004101335.117711-1-daniel@iogearbox.net/T/#u
2024-10-21 20:13:24 -07:00
Rob Murray
084abd93d3 Add ErrDumpInterrupted
Add a specific error to report that a netlink response had
NLM_F_DUMP_INTR set, indicating that the set of results may be
incomplete or inconsistent.

unix.EINTR was previously returned (with no results) when the
NLM_F_DUMP_INTR flag was set. Now, errors.Is(err, unix.EINTR) will
still work. But, this will be a breaking change for any code that's
checking for equality with unix.EINTR.

Return results with ErrDumpInterrupted. Results may be incomplete
or inconsistent, but give the caller the option of using them.

Look for NLM_F_DUMP_INTR in more places:
- linkSubscribeAt, neighSubscribeAt, routeSubscribeAt
  - can do an initial dump, which may report inconsistent results
  -> if there's an error callback, call it with ErrDumpInterrupted
- socketDiagXDPExecutor
  - makes an NLM_F_DUMP request, without using Execute()
  -> give it the same behaviour as functions that do use Execute()

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-09-22 00:00:40 -07:00
feng
a01829657b Fix FouList attribute body truncated error with kernel 5.2+
fou module added a bunch of new attributes in commit
1713cb37bf

which caused the old parsing logic failed, fix and add support for these attrributes.
2024-09-09 10:36:41 -07:00
Daman Arora
b1ce50cfa9 capture and return errors in ConntrackDeleteFilters
Signed-off-by: Daman Arora <aroradaman@gmail.com>
2024-09-05 11:07:32 -07:00
Rob Murray
e194da52b1 Fix SetSendTimeout/SetReceiveTimeout
They were implemented using SO_SNDTIMEO/SO_RCVTIMEO on the
socket descriptor - but that doesn't work now the socket is
non-blocking. Instead, set deadlines on the file read/write.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-09-04 15:52:52 -07:00
Matus Petrulak
0cd1f7961c Fix: Do not crash when enumerating tc filters with unknown actionType
for example actionType "vlan"

#987
2024-09-04 15:52:09 -07:00
Etienne Champetier
92645823f3 Fix deprecated comments
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
2024-08-26 11:35:36 -07:00
世界
6f57139475 Fix recvfrom goroutine leak v1.3.0 2024-08-23 12:41:44 -07:00
Sebastiaan van Stijn
298ff277ed Handle: add ConntrackDeleteFilter alias for backward compat
Commit c96b03b4be changed the signature
of this method to accept a list of filters and renamed it to
ConntrackDeleteFilters (plural).

This patch

- adds back ConntrackDeleteFilter as an alias
- marks it as deprecated in favor of the new version.
- adds missing stubs for other platforms

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-23 12:31:44 -07:00
Percy Wegmann
5b0b9d8260 rule: add Rule.Type to allow adding/listing unreachable (RTN_UNREACHABLE) rules
Updates #710

Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Signed-off-by: Percy Wegmann <percy@tailscale.com>
2024-08-23 12:10:14 -07:00
Etienne Champetier
65a253d375 link_linux: add support for IFLA_MACVLAN_BC_QUEUE_LEN(_USED)
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
v1.2.1
2024-08-15 09:19:21 -07:00
Daman Arora
3b7e16c5f8 Add ConntrackDeleteFilters
ConntrackDeleteFilters enables users to delete flow entries
that match any of the specified filters. This allows users
to delete multiple flow entries with a single dump table call.

Signed-off-by: Daman Arora <aroradaman@gmail.com>
2024-08-06 10:33:35 -07:00
Jason Joo
4317e32776 feat: add LinkSetBondSlaveActive()/LinkDelBondSlave()
Signed-off-by: Jason Joo <hblzxsj@gmail.com>
2024-08-06 10:15:19 -07:00
Hasan Mahmood
a57a7bd6b2 Add handle support for socket 2024-08-06 10:13:40 -07:00
Frank Dressler
aaf4f9866c Fix determination of the promiscuity counter for links
Function `LinkDeserialize` checked for presence of `IFF_PROMISC` in
the link's flags to determine whether it was in promiscuous mode.

This flag only tracks what is set with commands such as

	ip set <link> promisc on

but is not set when you run `tcpdump` or `wireshark` for example,
which also put the device in promiscuous mode.

There is a counter that tracks the number of times promiscuous mode
has been requested. It reacts to all the ways, `ip set`, and also
`tcpdump` and co.

With this change this counter is used instead of checking the flag.
This makes the library reflect what

	ip -d link show <link>

would show in its `promiscuity` field.

To test this change, start some processes of `tcpdump` or similar
and see the counter increase in `ip -d link show <link>` as well
as in the patched version of this netlink library. With the
unpatched version the counter remains 0. Then enable promiscuous
mode globally for the interface. This will increase the count in
all variants, `ip link`, the old unpatched and the patched version
of this netlink library.

Simple test program for reference:

	package main

	import "fmt"
	import "github.com/vishvananda/netlink"

	func main() {
		handle, _ := netlink.NewHandle()
		links, _ := handle.LinkList()
		for _, link := range links {
			attrs := link.Attrs()
			fmt.Printf("dev=%v promisc=%v\n",
				attrs.Name, attrs.Promisc)
		}
	}
2024-08-06 09:46:02 -07:00
Alex Godwin
7a4f10d3bc fix: updates SizeofVfVlanInfo to address #1003 2024-08-06 09:43:04 -07:00
qianxiao
8f96fd8b2f # rule: fix 32-bit platforms don't support adding rules with a mark value of 0x80000000/0xF0000000 ~ 0xF0000000/0xF0000000
The maximum value for an `int` type on a 32-bit platform is 0x7FFFFFFF. Since 0xF0000000 exceeds this limit, we need to use `uint` instead of `int` to handle these values.
2024-08-05 10:25:28 -07:00
TheDiveO
d13535d71e supports AF_XDP socket diagnosis; skip XSK diag test if kernel doesn't support XSK diag 2024-07-13 14:00:50 -07:00
Alex O'Regan
aed23dbf5e Adds ConntrackCreate & ConntrackUpdate
- Also refactored setUpNetlinkTestWithKModule function to reduce redundant NS's created and checks made.

 - Add conntrack protoinfo TCP support + groundwork for other protocols.

 - Tests to cover the above.
2024-07-04 08:47:44 -07:00