96 Commits

Author SHA1 Message Date
Vladimir Ermakov
ba05b48cab Fixed IP6tnl encapsulation and ID handling issues:
- Added IP6tnlEncap processing
- Added proper IP6tnlEncap.ID assignment
- Enabled handling of IP6tnlEncap.TC and IP6tnlEncap.FLAGS for serialization support
2025-08-29 16:10:43 -07:00
Albert Jin
b032ea08ec Add support for the expires option of ip route 2025-08-29 15:51:23 -07:00
gongguan
9d88d8385b feat: add support for RtoMin lock 2025-04-25 12:38:46 -07:00
Junhuang Hong
5d6ad2bde7 add SRv6 support for END.DT4 2025-03-27 22:09:14 -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
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
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
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
Shaun Crampton
b54f85093f Add RouteListFilteredIter API.
Allows for listing large numbers of routes without
buffering the whole list in memory at once.

Add benchmarks for RouteListFiltered variants.
2024-07-03 13:08:00 -07:00
shu1r0
e6a5c0e113 Support SEG6_LOCAL_ACTION_END_BPF
fix unit test

fix end.bpf

fix bug
2024-07-03 12:55:03 -07:00
youngifif
4d4ba1473f fix logic bug caused by operator precedence 2024-05-24 09:54:44 -07:00
Quan Tian
1e68b2710d Revert "Change behavior of Subscribe to non-blocking. Fix test."
This reverts commit 916f9685fa.
2024-05-23 09:21:30 -07:00
foyerunix
19057e85f5 Fix RouteListFiltered when using FAMILY_ALL 2024-04-03 06:56:43 -07:00
foyerunix
aafe841692 Filter RouteListFiltered response by requested IP family in 2024-03-27 08:56:09 -07:00
Kuroame
916f9685fa Change behavior of Subscribe to non-blocking. Fix test.
When listening for IPv6 address changes, I found that subscribe is not returning when there is message in the socket. After some researching, I found that libnl suggest setting socket to non-blocking when subscribing to groups. (Ref)[https://www.infradead.org/~tgr/libnl/doc/core.html#:~:text=best%20to%20put%20the%20socket%20in%20non-blocking%20mode]

Also fixed test related to BareUDP, which requires "bareudp" kmod. (Ref)[https://www.kernelconfig.io/config_bareudp]
2024-03-01 13:38:14 -08:00
Maxime Soulé
7f562ed576 RouteUpdate gains NlFlags field
It allows to distinguish between a new created route or a replaced one.

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
2024-03-01 13:06:15 -08:00
Maxime Soulé
124bb8e721 Add RouteChange API
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
2024-02-26 09:50:43 -08:00
Hasan Mahmood
6ab7f5a376 Use local handle, not package handle for link lookups 2024-02-23 09:54:32 -08:00
Hasan Mahmood
42d9a053ea Add IifIndex option to RouteGetOptions 2024-02-23 09:54:32 -08:00
Tao Li
8d48f50f55 Added ip6tnlEncap to insert ip6tnl encap route
This commit added support to allow the operation of ip6tnl encapsulation.
It is equivalent to the iproute2 command, e.g., ip route add 192.168.99.0/24 encap ip6 dst 2001:db8:: dev ip6-tunnel
The limitation include that the options field defined in encap nl route attribute is not implenmented yet.
Testcase is included.
2024-01-23 10:47:39 -08:00
Dave Setzke
229a10237c Add ReceiveBufferSize and force option to *Subscribe
When there are a large number of existing results for the link, neighbor, and
address subscribe functions with ListExisting are likely to fail with ENOBUFS.
This takes the AddrSubscribeOptions ReceiveBufferSize, already applied
to LinkSubscribeOptions, and applies it to NeighSubscribeOptions and
RouteSubscribeOptions. The ReceiveTimeout option was also added to each.

Added a SetReceiveBufferSize to the nl_linux socket API.

The existing addr_linux subscribe function was modified so instead of setting
the ReceiveBufferSize on the netlink pkghandle, it is set on the socket
associated with the subscription. The new implementations also only change the
receive buffer size on the socket.

Lastly, a new ReceiveBufferForceSize option was applied to all four of the
modified Subscribe functions.
2023-09-21 19:50:55 -07:00
Yutaro Hayakawa
bd5868794c Support fibmatch flag for RouteGetWithOptions
Support `ip route get fibmatch` equivalent with RouteGetWithOptions by
adding FIBMatch flag to RouteGetOptions.

Signed-off-by: Yutaro Hayakawa <yutaro.hayakawa@isovalent.com>
2023-07-05 17:39:32 +02:00
Li Chun
acdc658b86 Add "default" dst while no DST attr responsed from nl
Signed-off-by: Li Chun <chun2.li@intel.com>
2023-06-03 21:11:57 -07:00
Steffen Vogel
d3b7a6fadd Add firewall mark option to RouteGetOptions
This option allows performing FIB lookups for a particular
firewall mark. It is equivalent to iproute2's 'ip route get mark'
option.
2022-11-07 10:26:17 -08:00
chengzhycn
337a587de1 fix RouteList can't list routes properly when unspecifying link
Signed-off-by: chengzhycn <chengzhycn@gmail.com>
2022-10-26 10:42:34 -07:00
Manjiri Gadagkar
6e2993d135 RouteGetWithOptions: Add UID option 2022-08-02 12:21:20 +02:00
conjones
7b913bc23e routes: Uses empty RtMsg and routeHandle in RouteListFiltered
RouteListFiltered constructs an RtMsg with default options and lists
routes. Only routes matching these default options are returned from the
kernel when STRICT_CHECK enabled. The kernel will return all routes only
when an option is set to the zero value. This patch sets the zero value
by default, overwriting when specified by the consumer.
2022-07-12 21:14:29 +02:00
open-cmi
6bb6f8abbc fix: build failed on macos when use RT_FILTER_TABLE 2022-03-29 11:19:33 -05:00
conjones
657c30750a Use Addrmsg when listing addrs, and RtMsg when listing routes 2022-03-29 11:15:07 -05:00
yuwenchao
f055e5464f Add linux route get oif option.
This option is equivalent to "ip route get ... dev ...", which is useful when the route is multipath.

Signed-off-by: yuwenchao <yuwenchao@qiyi.com>
2021-09-21 09:12:08 -05:00
张祖建
b8aac10bba fix staticcheck issues 2021-09-21 09:10:48 -05:00
Tobias Urdin
65349edba8 Add support for RTA_FLOW
This adds support for the RTA_FLOW routing msg
attribute and adds the Realm field to the Route
object.
2021-09-20 10:45:34 -07:00
Oliver Geiselhardt-Herms
d1fad16de5 Expose AFI on routes 2021-07-03 11:44:51 +02:00
bersoare
079db23e21 lwtunnel: add support for encap type bpf
add bpf program types

add unit tests

don't use strings to determine type

fix camel case
2021-07-03 11:44:22 +02:00
eriknordmark
f9d8f911db more consistent error handling
Signed-off-by: eriknordmark <erik@zededa.com>
2021-05-30 12:55:19 +02:00
Tobias Klauser
d17758a128 Don't re-initialize package level var native in (*Handle).RouteGetWithOptions
This was missed in #637 due to it being introduced by #623, which was
merged just recently.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
2021-05-10 09:43:52 -07: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
Hasan Mahmood
66ddd91f7d Add route get iif option 2021-05-08 08:48:35 -07:00
Vishvananda Abrams
e838b0f0e0 Update travis and fix formatting errors 2021-04-21 13:45:44 -05:00
Michael Cambria
f5de75959a Remove "=======" characters left over from merge
Signed-off-by: Michael Cambria <mcambria@redhat.com>
2021-03-30 08:40:13 -07:00
Michael Cambria
0a32cffaf5 New RouteAddEcmp() call to allow a prefix to be added when one
already exists via a different interface.

Fixes https://github.com/vishvananda/netlink/issues/620

Signed-off-by: Michael Cambria <mcambria@redhat.com>
2021-03-27 13:26:27 -07:00
Joe Stringer
c21bda41e9 Fix non-linux build
Commit ec93726159 ("Adds strings translation methods") broke non-Linux
builds by relying on unix constants that are only declared on the linux
platform in the upstream x/sys/unix package.

Other platforms report undefined variables, such as the following:

  $ GOOS=darwin go build .
  # github.com/vishvananda/netlink
  ./route.go:17:7: undefined: SCOPE_UNIVERSE
  ./route.go:19:7: undefined: SCOPE_SITE
  ./route.go:21:7: undefined: SCOPE_LINK
  ./route.go:23:7: undefined: SCOPE_HOST
  ./route.go:25:7: undefined: SCOPE_NOWHERE
  ./route.go:55:7: undefined: unix.RTPROT_BABEL
  ./route.go:57:7: undefined: unix.RTPROT_BGP
  ./route.go:59:7: undefined: unix.RTPROT_BIRD
  ./route.go:61:7: undefined: unix.RTPROT_BOOT
  ./route.go:63:7: undefined: unix.RTPROT_DHCP
  ./route.go:63:7: too many errors

Move the platform-specific implementations to platform-specific files
and add stubs to satisfy other platforms.

Fixes: ec93726159 ("Adds strings translation methods")
Signed-off-by: Joe Stringer <joe@cilium.io>
2021-03-16 07:45:50 -07:00
yaocw2020
c30d9bc9e7 Add ip route append
Signed-off-by: yaocw2020 <yaocanwu@gmail.com>
2021-03-15 00:21:01 -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
Steve Shaw
fbe60771a0 Adding support for RTA_VIA
Signed-off-by: Steve Shaw <shaw38@gmail.com>
2020-12-03 10:12:37 -08:00
Oliver Herms
ffba2c833f RouteGetWithOptions: Add source address option 2020-11-21 22:56:51 -08:00
bianze
fb953eb4ce Add whole route metrics for netlink
There are lots of route metrics to be added, such as rto_min,
quick_ack and so on, and these metrics are useful for users to
tune network performance, so we add all these metrics.

Signed-off-by: bianze <bianze1993@gmail.com>
2020-10-19 15:37:56 -04:00
Amit Nishry
5a869a71f0 Introduce RouteGetWithOptions that allows to modify the RouteGet
Add support for VrfName as the RouteGetOptions

Signed-off-by: Amit Nishry <amit.nishry@gmail.com>
2020-06-03 12:09:39 -07:00
Chris Tarazi
564132f787 Implement RuleListFiltered
This commit adds the ability to list rules in a filtered manner, similar
to RouteListFiltered.

Signed-off-by: Chris Tarazi <tarazichris@gmail.com>
2020-06-03 11:26:35 -07:00
takt
d71301a47b Attach RTA_ENCAP_TYPE to children, not rtAttrs, when using Multipath 2019-11-13 10:34:27 -08:00