summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* tests: add a very basic test for route cacheThomas Haller2024-05-173-1/+91
| | | | Hopefully more to come, and more to improve.
* tests: add NLTstSelectRoute test helperThomas Haller2024-05-173-0/+401
| | | | | Add functions for matching a route. Currently only a few trivial options are supported, like the destination address and the ifindex.
* tests: set NLTST_IN_CI for not skipping tests accidentallyThomas Haller2024-05-173-0/+16
| | | | | In CI, we know which tests should be skipped. Let github actions set NLTST_IN_CI=1, and disable certain skip checks.
* route: add missing priority to route_keygen() debug printJonas Gorski2024-05-171-4/+5
| | | | | | | | | | | | | | | | | | | | | | | Route priority is part of the hash key calculation, but the debug print omitted it. This could cause seemingly identical values have different hash values. Fix this by also printing the route priority, and reformat according to clang-format. Before: DBG<5>lib/route/route_obj.c:378 route_keygen: route 0x55fd326f7d50 key (fam 10 tos 0 table 254 addr fe80::/64) keysz 26 hash 0x18c DBG<5>lib/route/route_obj.c:378 route_keygen: route 0x55fd326f7fa0 key (fam 10 tos 0 table 254 addr fe80::/64) keysz 26 hash 0x278 After: DBG<5>lib/route/route_obj.c:378 route_keygen: route 0x558cfde91d50 key (fam 10 tos 0 table 254 prio 256 addr fe80::/64) keysz 26 hash 0x18c DBG<5>lib/route/route_obj.c:378 route_keygen: route 0x558cfde91fa0 key (fam 10 tos 0 table 254 prio 1024 addr fe80::/64) keysz 26 hash 0x278 Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de> https://github.com/thom311/libnl/pull/388
* tests: add helper to detect availablility of iproute2Thomas Haller2024-05-172-0/+25
|
* tests: add helper functions for testsThomas Haller2024-05-171-0/+44
|
* route: move "struct rtnl_nexthop" to "nl-priv-dynamic-route"Thomas Haller2024-05-172-15/+15
| | | | | | | | rtnl_route_get_nexthops() returns the list of nexthops, but that is not usable without access to the rtnh_list field. We want to use that from tests. Move to another header (but still not public API).
* build: fix "check-progs" target in "Makefile.am"Thomas Haller2024-05-171-2/+2
| | | | Fixes: 71e59e145ebe ('build: separate build tests from unit tests')
* github: print test-suite.log in case of test failureThomas Haller2024-05-171-10/+10
|
* route: expose nexthop id attributeJonas Gorski2024-05-173-1/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Routes may reference a nexthop (group) via the new nexthop API by its ID, so add accessors for setting and getting it. Referencing a nexthop is mutually exclusive to specifiying nexthops in the route, so make sure we do not do that when creating netlink messages (which may exist both, since netlink messages from the kernel contain both unless 'nexthop_compat_mode' is disabled). $ ip -6 r 2001:db8:3::/64 nhid 20 metric 1024 pref medium nexthop via 2001:db8:1::2 dev v0 weight 1 nexthop via 2001:db8:2::2 dev v1 weight 1 Before: $ nl-route-list inet6 2001:db8:3::/64 table main type unicast via 2001:db8:1::2 dev v0 via 2001:db8:2::2 dev v1 After: $ nl-route-list inet6 2001:db8:3::/64 table main type unicast nhid 20 via 2001:db8:1::2 dev v0 via 2001:db8:2::2 dev v1 Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de> https://github.com/thom311/libnl/pull/386
* tests: fix _nltst_object_to_string() to print one line onlyThomas Haller2024-05-172-3/+25
|
* route: drop unused fields from "struct rtnl_route"Thomas Haller2024-05-171-2/+0
|
* build: separate build tests from unit testsThomas Haller2024-05-172-11/+18
| | | | | The build tests spam the terminal output of the CI run. Make them a separate build target (check-build), so we can run them first.
* format: reformat "tests/nl-test-util.h" fileThomas Haller2024-05-162-113/+112
|
* route: merge branch 'bisdn:jogo_route_nh_cmp'Thomas Haller2024-05-144-12/+25
|\ | | | | | | https://github.com/thom311/libnl/pull/384
| * route: use the new helper function for comparing nexthopsJonas Gorski2024-05-141-12/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a route is created while the interface has no link, we get a notification with the route and the nexthop having the flag LINKDOWN. If the interface later gets a link, we do not get a route notification about it, so the route and nexthop stay at LINKDOWN in the libnl cache. If the route then gets removed again, the to be removed route will not have the LINKDOWN flag anymore, which then can break comparison of the nexthop(s). So use the new nexthop identical helper to avoid this scenario. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
| * nexthop: add a identical helper functionJonas Gorski2024-05-143-0/+21
|/ | | | | | | | | | | | | | | Not all attributes of a nexthop are id attributes, e.g. the flags will contain state (LINKDOWN, DEAD) of the attached link about which the kernel will not send route updates. Likewise, the weight may not exist when processing an ECMP IPv6 route update which only contains a single nexthop. Since rtnl_nexthop isn't a first class cache object, we cannot use nl_object_identical(), so add a separate identical helper function which compares only fixed attributes. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
* utils: reserve the nl_has_capabiliy numbers for releases 3.10 - 3.12Thomas Haller2024-05-072-3/+21
| | | | | Fix the capability numbers for the next few releases already. While not yet in use, the number is reserved and stable.
* github,clang-format: update fedora version for clang-formatThomas Haller2024-05-071-1/+1
| | | | | | | | | | We use clang-format, but the result depends on the version of the tool. The version to be used, is the one from the github action. You can use "tools/clang-format-container.sh" to run that version in a container. Now that Fedora 40 is released, bump the Fedora version (and the used clang-format version) from Fedora 39 (17.0.6-2.fc39) to Fedora 40 (18.1.1-1.fc40). Luckily, our source code formats the same for both.
* route: fix IPv6 ecmp route deleted nexthop matchingJonas Gorski2024-05-071-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the kernel sends a ECMP route update with just the deleted nexthop, the nexthop will have no associated weight, and its flags may indicate that it is dead: route_update: RTM_DELROUTE new route: inet6 default table main type unicast <DEAD,> scope global priority 0x400 protocol 0x9 nexthop via fe80::b226:28ff:fe62:8841 dev port4 <dead,> old route: inet6 default table main type unicast scope global priority 0x400 protocol 0x9 nexthop via fe80::b226:28ff:fe62:8841 dev port4 weight 0 <> nexthop via fe80::fa8e:a1ff:fee0:8344 dev port49 weight 0 <> nexthop via fe80::b226:28ff:fe62:d400 dev port3 weight 0 <> nexthop via fe80::fa8e:a1ff:fee0:8349 dev port54 weight 0 <> Since we are comparing the nexthops strictly with all attributes, we can never match the deleted nexthop. This causes libnl to fail to remove the deleted nexthop from the route, and consequently send out a nop-update and a desync of the route in the cache and in the kernel. Fix this by ignoring NH_ATTR_FLAGS (0x1) and NH_ATTR_WEIGHT (0x2) when comparing nexthops to properly match the deleted one. Fixes: 29b71371e764 ("route cache: Fix handling of ipv6 multipath routes") Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de> https://github.com/thom311/libnl/pull/382
* cache: merge branch 'ievenbach:aurora/cache-mgr-cb'Thomas Haller2024-05-064-28/+59
|\ | | | | | | https://github.com/thom311/libnl/pull/378
| * cache: use cleanup attribute in nl_cache_mngr_alloc_ex()Thomas Haller2024-05-062-21/+17
| | | | | | | | No "goto errout".
| * cache: cleanup nl_cache_mngr_alloc_ex()Thomas Haller2024-05-062-31/+31
| | | | | | | | | | | | | | | | | | | | | | | | - mngr->cm_flags must be set together when assigning the socket. Otherwise, a `goto errout` in the middle will cause a leak. - normalize the flags variable to not contain unexpected values. - NL_ALLOCATED_SYNC_SOCK is private API. No need to expose that to public headers. Fixes: 1dbdc30a6b9f ('cache: allow to allocate cache manager with custom refill socket')
| * cache: allow to allocate cache manager with custom refill socketIlya A. Evenbach2024-05-063-15/+50
|/ | | | | | | | | | | Cache managers use two sockets: one for cache refill operation, and another one for notifications. In order to simulate NETLINK events by reading data from files, we need to be able to overwrite callbacks for both sockets. This new function allows us to set up refill socket any way we want. It does have requirement that the refill socket be blocking.
* tests: test compiling all public headers with C++ compilerThomas Haller2024-05-062-0/+35
| | | | | | | | | | While libnl3 is a C library (and itself can only be built using a C compiler), the public headers are supposed to also work with C++. Add a test for that. Unfortunately, this test does not cover whether all symbols are correctly marked as "extern "C"" for linkage.
* tests: don't use $COMPILE for building header testsThomas Haller2024-05-061-1/+1
|
* include: add _NL_NO_WARN_DEPRECATED_HEADER for suppressing warning about ↵Thomas Haller2024-05-065-1/+9
| | | | | | | | | | | | | | | | deprecated headers Header files are part of a stable API. Warning about using deprecated API is cumbersome, albeit often useful to force the user to migrate away from the API. But it also requires that the unit test disables "-Wcpp". That is problematic on its own, because we don't want to disable any warnings. As we only have 4 such header files, instead guard the warnings with a #ifndef _NL_NO_WARN_DEPRECATED_HEADER
* tests: avoid "-Wunused-parameter" warning in build headers testThomas Haller2024-05-061-1/+1
| | | | | | | | | | | | | | | printf "#include <$(echo "include/netlink/addr.h" | sed 's|.*\<include/netlink/|netlink/|')>\nint main(int argc, char **argv) { return 0; }" > include/netlink/addr.h.build-headers-test.c gcc -DHAVE_CONFIG_H -I. -I./include -O2 -Wall -Wextra -Werror -Wall -Werror -Wno-error=cpp -I./include -I./include -c -o include/netlink/addr.h.build-headers-test.o include/netlink/addr.h.build-headers-test.c include/netlink/addr.h.build-headers-test.c: In function ‘main’: include/netlink/addr.h.build-headers-test.c:2:14: error: unused parameter ‘argc’ [-Werror=unused-parameter] 2 | int main(int argc, char **argv) { return 0; } | ~~~~^~~~ include/netlink/addr.h.build-headers-test.c:2:27: error: unused parameter ‘argv’ [-Werror=unused-parameter] 2 | int main(int argc, char **argv) { return 0; } | ~~~~~~~^~~~ cc1: all warnings being treated as errors Fixes: d9a1e0ce9c95 ('build: add "check-local-build-headers" test target to build public headers')
* route: avoid compiler warning about calloc() arguments in ↵Thomas Haller2024-05-061-1/+1
| | | | | | | | | | | rtnl_netem_set_delay_distribution() CC lib/route/qdisc/libnl_route_3_la-netem.lo lib/route/qdisc/netem.c: In function 'rtnl_netem_set_delay_distribution': lib/route/qdisc/netem.c:975:39: error: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args] 975 | line = (char *) calloc(sizeof(char), len + 1); | ^~~~ lib/route/qdisc/netem.c:975:39: note: earlier argument should specify number of elements, later size of each element
* cache: fix new object in callback v2 on updated objectsJonas Gorski2024-04-261-1/+1
| | | | | | | | | | | | | | | | | When calling the callback v2 for objects that were updated, we pass the update ("obj") instead of the updated object ("old") as new. Presumably this wasn't intended, so pass the updated object as new. This avoids weird updates where the new object is significantly smaller than the old one. E.g. for IPv6 multipath route updates, old would be the full route with all nexthops, while new would be a partial route with only the added/removed nexthop. Fixes: 66d032ad443a ("cache_mngr: add include callback v2") Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de> https://github.com/thom311/libnl/pull/381
* socket: fix ubsan complaint about incorrect left-shift in generate_local_port()Ilya A. Evenbach2024-04-261-1/+1
| | | | | | n needs to be uint32_t to fit left shift by 22 bits https://github.com/thom311/libnl/pull/379
* all: merge branch 'th/nl-debug'Thomas Haller2024-04-227-27/+17
|\
| * github: test with --enable-debug=no configure optionThomas Haller2024-04-221-1/+3
| | | | | | | | | | In this case, only test it with clang. It seems not worth building everything twice toggling only this option.
| * utils: always define nl_debug_dpThomas Haller2024-04-222-9/+5
| | | | | | | | | | | | | | | | | | | | | | Otherwise, whether libnl-3.so exports nl_debug_dp depends on NL_DEBUG. That is ugly. It also breaks the linker checking the symbol versioning file with the "--no-undefined-version" flag. Instead, always define it. It's small anyway. Reported-by: lch361 <lch361@skiff.com> See-also: https://github.com/thom311/libnl/pull/375
| * core: always define statements for NL_DBG()Thomas Haller2024-04-223-14/+3
| | | | | | | | | | | | | | | | | | | | Conditionally defining to nothing, means that the compiler doesn't see the print statement without NL_DEBUG. In turn, we lack checking of the statement by the compiler. Instead, add an "if (NL_DEBUG)" around it. Since NL_DEBUG is a constant, the compiler will optimize out all the code of the statement, while still checking it.
| * build: always define NL_DEBUGThomas Haller2024-04-226-10/+13
|/ | | | | | | | | | Checking conditional defines with #ifdef is error prone because we don't get a compiler warning when the define wrongly is missing. Instead, always define it to either 0 or 1. The benefit is also that now we can use NL_DEBUG in C (not only in the preprocessor).
* all: use defines for attributesThomas Haller2024-04-225-9/+9
| | | | We have those defines. Use them throughout.
* route/bison: include "nl-default.h" in lex/yacc filesThomas Haller2024-04-223-1/+6
| | | | | | | | | | | For building all of our source files, we should include first "config.h". This ensures that we have for example NL_DEBUG available. Actually, "config.h" is included by "nl-default.h". In turn this means, all our source files should first include "nl-default.h", which drags in a set of default headers. Fix the lex/yacc files for that.
* route: add support for layer 3 filtering on bridgesCordell O'Leary2024-04-033-0/+105
| | | | https://github.com/thom311/libnl/pull/373
* route: merge branch 'Cordell-O:main'Thomas Haller2024-02-297-8/+602
|\ | | | | | | https://github.com/thom311/libnl/pull/372
| * tests: add test for bridge vlan attributes.Cordell O'Leary2024-02-293-4/+135
| |
| * route: add support for vlan filtering on bridge ports.Cordell O'Leary2024-02-295-8/+402
| |
| * route: Add support to set ageing time for dynamic bridge table entriesCordell O'Leary2024-02-293-0/+69
|/
* tests: add unit test for `nl_addr_parse("default", AF_INET6, &addr6)`Thomas Haller2024-02-021-0/+8
|
* lib/xfrm: add missing #include <time.h>Aleksander Mazur2024-01-082-0/+2
| | | | | | https://github.com/thom311/libnl/issues/370 https://github.com/thom311/libnl/pull/371
* libnl-3.9.0 releaselibnl3_9_0Thomas Haller2023-12-044-3/+9
|
* include/linux-private: import 'seg6 local' headers from kernel treeKonstantin Kogdenko2023-12-045-0/+261
| | | | Add headers from 6995e2de6891c724bfeb2db33d7b87775f913ad1 (tag: v6.4).
* lib: remove unused assignment in nl_addr_parse()Thomas Haller2023-12-041-2/+0
| | | | | | | | | | | | Coverity warns about this. Avoid it. Error: CLANG_WARNING: [#def3] libnl-3.8.0/lib/addr.c:324:3: warning[deadcode.DeadStores]: Value stored to 'len' is never read # 322| !strcasecmp(str, "any")) { # 323| # 324|-> len = 0; # 325| # 326| switch (hint) {
* route/tc: avoid integer overflow in rtnl_tc_calc_cell_log()Thomas Haller2023-12-041-2/+2
| | | | | | | | | | | | Coverity doesn't like this. Workaround. Error: CPPCHECK_WARNING (CWE-190): [#def97] libnl-3.8.0/lib/route/tc.c:681: error[integerOverflow]: Signed integer overflow for expression '1<<i'. # 679| # 680| for (i = 0; i < 32; i++) # 681|-> if ((1 << i) == cell_size) # 682| return i; # 683|
* xfrm: return -NLE_MISSING_ATTR from xfrmnl_sa_get_auth_params()Thomas Haller2023-12-041-13/+10
| | | | | | Don't return -1, that is not an error code. Also, return early from function.