Commit Graph

86 Commits

Author SHA1 Message Date
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
Yakushi Fujiwara
254c8a89c5 Replace values defined in unix package.
- replace following values to unix.*
  AF_MPLS, RTA_NEWDST, RTA_ENCAP_TYPE, RTA_ENCAP
2019-08-23 11:17:48 -07:00
Daniel Borkmann
b1e9859792 netlink: enforce similar pid checks as in iproute2
iproute2's own netlink library asserts that the sockaddr sender pid
has to be the one of the kernel [0]. It also doesn't bail out on pid
mismatch but only skips the message instead. We've seen cases where
the latter had a pid 0; in such case we should skip to the next nl
message instead of hard bail out.

  [0] https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/lib/libnetlink.c
      rtnl_dump_filter_l(), __rtnl_talk_iov()

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-18 17:26:53 -07:00
Andrei Vagin
e281812e70 Fix typos
Signed-off-by: Andrei Vagin <avagin@google.com>
2019-03-19 08:22:03 -07:00
Magesh GV
1404979ff6 Add support for hoplimit metric in routes 2018-10-16 12:33:37 -07:00
Kentaro Ebisawa
16769db002 Support LWTUNNEL_ENCAP_SEG6_LOCAL (including tests) 2018-05-08 09:50:31 -07:00
eriknordmark
5f5d5cddcf Add a 'ListExisting' option to get the existing entries in the
route/addr/link tables as part of RouteSubscribeWithOptions,
AddrSubscribeWithOptions, and LinkSubscribeWithOptions.
2018-01-23 14:25:48 -08:00
Vishvananda Ishaya Abrams
63ca7e48f5 Support setting and retrieving route MTU/AdvMSS 2017-11-09 14:04:31 -08:00
Kentaro Ebisawa
eb7ed874fe Support LWTUNNEL_ENCAP_SEG6 2017-11-08 03:33:01 -08:00
Ian Bishop
0e3b74dbe2 replace syscall with golang.org/x/sys/unix 2017-10-26 09:45:08 -07:00
Vincent Bernat
c684918a4f Add more variant with options to subscribe functions
For link, address, route, add a `WithOptions` variant to the
`*Subscribe()` function to specify a namespace and an error
callback. Those options can be extended in the future without adding
more functions. For example, it could be possible to subscribe only
for a given family by adding a `Family` member to the appropriate
struct.

As a minor change, the private function is always suffixed by `At`,
since it was the case for route and raw netlink functions (but not for
address and link).
2017-09-24 11:01:49 -07:00