summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
7 daysutils: reserve the nl_has_capabiliy numbers for releases 3.10 - 3.12upstream-mainThomas Haller
Fix the capability numbers for the next few releases already. While not yet in use, the number is reserved and stable.
7 daysgithub,clang-format: update fedora version for clang-formatThomas Haller
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.
7 daysroute: fix IPv6 ecmp route deleted nexthop matchingJonas Gorski
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
8 dayscache: merge branch 'ievenbach:aurora/cache-mgr-cb'Thomas Haller
https://github.com/thom311/libnl/pull/378
8 dayscache: use cleanup attribute in nl_cache_mngr_alloc_ex()Thomas Haller
No "goto errout".
8 dayscache: cleanup nl_cache_mngr_alloc_ex()Thomas Haller
- 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')
8 dayscache: allow to allocate cache manager with custom refill socketIlya A. Evenbach
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.
8 daystests: test compiling all public headers with C++ compilerThomas Haller
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.
8 daystests: don't use $COMPILE for building header testsThomas Haller
8 daysinclude: add _NL_NO_WARN_DEPRECATED_HEADER for suppressing warning about ↵Thomas Haller
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
8 daystests: avoid "-Wunused-parameter" warning in build headers testThomas Haller
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')
8 daysroute: avoid compiler warning about calloc() arguments in ↵Thomas Haller
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
2024-04-26cache: fix new object in callback v2 on updated objectsJonas Gorski
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
2024-04-26socket: fix ubsan complaint about incorrect left-shift in generate_local_port()Ilya A. Evenbach
n needs to be uint32_t to fit left shift by 22 bits https://github.com/thom311/libnl/pull/379
2024-04-22all: merge branch 'th/nl-debug'Thomas Haller
2024-04-22github: test with --enable-debug=no configure optionThomas Haller
In this case, only test it with clang. It seems not worth building everything twice toggling only this option.
2024-04-22utils: always define nl_debug_dpThomas Haller
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
2024-04-22core: always define statements for NL_DBG()Thomas Haller
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.
2024-04-22build: always define NL_DEBUGThomas Haller
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).
2024-04-22all: use defines for attributesThomas Haller
We have those defines. Use them throughout.
2024-04-22route/bison: include "nl-default.h" in lex/yacc filesThomas Haller
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.
2024-04-03route: add support for layer 3 filtering on bridgesCordell O'Leary
https://github.com/thom311/libnl/pull/373
2024-02-29route: merge branch 'Cordell-O:main'Thomas Haller
https://github.com/thom311/libnl/pull/372
2024-02-29tests: add test for bridge vlan attributes.Cordell O'Leary
2024-02-29route: add support for vlan filtering on bridge ports.Cordell O'Leary
2024-02-29route: Add support to set ageing time for dynamic bridge table entriesCordell O'Leary
2024-02-02tests: add unit test for `nl_addr_parse("default", AF_INET6, &addr6)`Thomas Haller
2024-01-08lib/xfrm: add missing #include <time.h>Aleksander Mazur
https://github.com/thom311/libnl/issues/370 https://github.com/thom311/libnl/pull/371
2023-12-04libnl-3.9.0 releaseThomas Haller
2023-12-04include/linux-private: import 'seg6 local' headers from kernel treeKonstantin Kogdenko
Add headers from 6995e2de6891c724bfeb2db33d7b87775f913ad1 (tag: v6.4).
2023-12-04lib: remove unused assignment in nl_addr_parse()Thomas Haller
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) {
2023-12-04route/tc: avoid integer overflow in rtnl_tc_calc_cell_log()Thomas Haller
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|
2023-12-04xfrm: return -NLE_MISSING_ATTR from xfrmnl_sa_get_auth_params()Thomas Haller
Don't return -1, that is not an error code. Also, return early from function.
2023-12-04xfrm: fix leaking usertemplate in xfrmnl_sp_parse()Thomas Haller
Fixes: 49c20efaa783 ('xfrm: fix crashes in case of ENOMEM')
2023-12-04socket: workaround coverity warning about time_t handlingThomas Haller
Coverity really wants to warn if a time_t is cast to 32 bits. We use time() here to get (some very bad) randomness. The loss of the upper bits is the least of the problems. Work around the coverity warning by also the higher bits. Error: Y2K38_SAFETY (CWE-197): [#def12] libnl-3.8.0/lib/socket.c:76: store_truncates_time_t: A "time_t" value is stored in an integer with too few bits to accommodate it. The expression "time(NULL)" is cast to "uint32_t". # 74| # 75| if (idx_state == 0) { # 76|-> uint32_t t = (uint32_t) time(NULL); # 77| # 78| /* from time to time (on average each 2^15 calls), the idx_state will Error: Y2K38_SAFETY (CWE-197): [#def13] libnl-3.8.0/lib/socket.c:193: store_truncates_time_t: A "time_t" value is stored in an integer with too few bits to accommodate it. The expression "time(NULL)" is cast to "unsigned int". # 191| sk->s_local.nl_family = AF_NETLINK; # 192| sk->s_peer.nl_family = AF_NETLINK; # 193|-> sk->s_seq_next = (unsigned int) time(NULL); # 194| sk->s_seq_expect = sk->s_seq_next; # 195|
2023-12-04github: update Fedora image and version for clang-formatThomas Haller
Update the Fedora container for github. In particular, this updates the used version of clang-format for formatting the C sources.
2023-12-02clang-format: rework container scriptThomas Haller
Build a container image for the code formatting, and run that.
2023-12-01lib: fix signed overflow warning in nl_object_diff()Thomas Haller
Coverity warns "Signed integer overflow for expression '1<<31'".
2023-12-01socket: explicitly cast time() to uint32_tThomas Haller
Coverity warns about this. Try to avoid the warning by casting. We only use time() to get some (very little) entropy. The cast is fine.
2023-12-01src: fix leak in "nl-cls-add"Thomas Haller
Not important, but coverity flags this. Avoid it.
2023-12-01route/cls: add get/take wrappers for rtnl_act_append()Thomas Haller
rtnl_act_append() either takes ownership of the argument, or does nothing (on error). This pattern is hard to get right. In the past, there were various bugs at this place. Add two wrappers _rtnl_act_append_get() and _rtnl_act_append_take() which consistently don't take ownership of the pointer or take it. Also, in functions like rtnl_flower_append_action() only set the mask after successfully modifying the data.
2023-12-01route/cls: fix leak in error handling of rtnl_flower_append_action()Thomas Haller
Using rtnl_act_append() correctly is hard. Fixes: ef46de143206 ('route/cls: add flower classifier')
2023-12-01route: fix just introduced use-after-free in rtnl_act_parse()Thomas Haller
Fixes: 105a6be10a5f ('route: use cleanup macro in rtnl_act_parse()')
2023-12-01route: use cleanup macro in rtnl_act_parse()Thomas Haller
2023-12-01nl-aux-route: add cleanup macro for rtnl_act_put_all()Thomas Haller
2023-12-01base: add _NL_AUTO_DEFINE_FCN_INDIRECT0() macroThomas Haller
This is useful for a very special case. For a cleanup macro that calls rtnl_act_put_all(). In that case, we have a auto variable `struct rtnl_act *head`, but the cleanup function expects as argument `&head`.
2023-12-01route: fix memleak in rtnl_act_parse()Thomas Haller
Coverity warns: Error: RESOURCE_LEAK (CWE-772): [#def2] libnl-3.8.0/lib/route/act.c:421: alloc_fn: Storage is returned from allocation function "rtnl_act_alloc". libnl-3.8.0/lib/route/act.c:421: var_assign: Assigning: "act" = storage returned from "rtnl_act_alloc()". libnl-3.8.0/lib/route/act.c:426: var_assign: Assigning: "tc" = "act". libnl-3.8.0/lib/route/act.c:438: noescape: Resource "tc" is not freed or pointed-to in "rtnl_tc_set_kind". libnl-3.8.0/lib/route/act.c:455: leaked_storage: Variable "tc" going out of scope leaks the storage it points to. libnl-3.8.0/lib/route/act.c:455: leaked_storage: Variable "act" going out of scope leaks the storage it points to. # 453| tc_act_stats_policy); # 454| if (err < 0) # 455|-> return err; # 456| # 457| if (tb3[TCA_STATS_BASIC]) { Fixes: 05bd6366387c ('add support for TC action statistics')
2023-12-01base: don't use static array indices for buffer argument of _nl_inet_ntop()Thomas Haller
Seems the static array indices can confuse coverity. I think coverity is wrong here, regardless, change it. libnl-3.8.0/include/base/nl-base-utils.h:683: overrun-buffer-arg: Overrunning buffer pointed to by "buf" of 16 bytes by passing it to a function which accesses it at byte offset 45 using argument "(addr_family == 2) ? 16 : 46" (which evaluates to 46). # 681| * and a suitably large buffer, it cannot. Assert for that. */ # 682| # 683|-> r = (char *)inet_ntop(addr_family, addr, buf, # 684| (addr_family == AF_INET) ? INET_ADDRSTRLEN : # 685| INET6_ADDRSTRLEN);
2023-12-01route/can: implement can_device_statsJob Feikens
Adds the rtnl_link_can_get_device_stats function to get xstats of a CAN-bus link as a can_device_stats struct. https://github.com/thom311/libnl/pull/368
2023-11-29github: build with "-fexceptions" CFLAGSThomas Haller
This seems good for our test builds. This can result in additional uninitialized variable warnings about autovariables with cleanup attribute. This flag is also enabled by default on Fedora package build ([1]). [1] https://src.fedoraproject.org/rpms/redhat-rpm-config//blob/rawhide/f/buildflags.md