Thomas Haller [Mon, 9 Oct 2017 11:46:44 +0000 (13:46 +0200)]
nl: add "const" specifier for nla_policy argument of parse functions
Adding const to a function argument is generally not an API break
(at least, if the argument is a struct, like in this case).
Usually we declare the policy as static variables. The user should
be able to mark them as "const", so that the linker makes the policy
array read-only. Adjust the API to allow for that.
Some of the cli tools use select(2) and its man page states:
/* According to POSIX.1-2001, POSIX.1-2008 */
#include <sys/select.h>
Do so and explicitly #include <sys/select.h> in <netlink/cli/utils.h>
instead of relying of getting select(2) via implicit includes. This is
also needed to make libnl compile for Android.
David Ahern [Thu, 17 Aug 2017 22:59:36 +0000 (15:59 -0700)]
route: Add support for lwtunnel encapsulations
Add framework to support lwtunnel encapsulations per nexthop.
Encapsulations types are expected to fill in the nh_encap_ops for
building and parsing messages, compare encapsulations in routes,
dumping the encapsulations and freeing memory.
David Ahern [Thu, 17 Aug 2017 22:59:34 +0000 (15:59 -0700)]
Add support for label stack in nl-route commands
Add support for MPLS labels in nexthop specification. Specifically, the
'as' keyword specifies the MPLS label stack and if the route address
family is MPLS then the nexthop via is added as a route via instead of
a gateway (subtle differences introduced for MPLS).
David Ahern [Thu, 17 Aug 2017 22:59:32 +0000 (15:59 -0700)]
route: Add support for MPLS address family
Add support for route in MPLS family. New attributes:
- RTA_NEWDST - label stack for a nexthop
- RTA_VIA - nexthop address (e.g., IPv4 or IPv6)
Other changes required:
- scope has to be universe for MPLS routes so fixup rtnl_route_guess_scope
- priority attribute can not be set for MPLS. Change rtnl_route_parse to
not set the attribute by default for AF_MPLS.
- table attribute should not be set unless something other than the default
table. For MPLS this attribute can not be set.
'/' is the separator in label stacks for consistency with iproute2.
I'm not 100% sure this is the correct fix; maybe this really is supposed
to return family->gf_maxattr, but this is an odd way of writing
that. Anyway, comparing to the other genl_family_[gs]et functions, I
suppose this is what was really meant.
This is clearly not what was intended. While at it, drop the pointless
cast of the allocator's return value, and use plain malloc since we're
explicitly populating all len bytes immediately afterwards.
Thomas Haller [Thu, 15 Jun 2017 15:44:05 +0000 (17:44 +0200)]
lib/route/qdisc/netem.c/trivial: fix whitespace and indentation in netem_msg_fill_raw()
The indentation around
if (netem->qnm_dist.dist_data && netem->qnm_dist.dist_size) {
looked very wrong. Don't change the behavior, only the indentation.
See also commit 861901c55bd9e2f84e7c8de0da5ea6179867907d which
introduced the ill indentation.
lib/route/qdisc/netem.c: avoid memory leak if realloc fails
PS: There's some serious whitespace damage in this vicinity (starting
around line 269), making one wonder if the ifs and elses are matched as
they should be.
lib/route/cls/u32.c: avoid overflowing an unsigned char
If rtnl_u32_add_key is called too many times, sel->nkeys will wrap from
255 to 0, effectively killing all the previous rtnl_u32_add_key
calls (while having an inaccessible chunk of memory sitting beyond the
accessible part of the ->keys array). Not sure NOMEM is the best error
code, but that's at least something users would already have to be
prepared to handle.
Increasing the size of the u->cu_selector item by the size of a struct
tc_u32_key (i.e., making the flexible array member sel->keys one element
bigger) is pointless when one doesn't update sel->nkeys or otherwise
records the increased size, so these are effectively memory leaks.
The only way we can enter the block containing this goto is if i is
equal to (the old value of) mngr->cm_nassocs, and that slot is now
guaranteed to exist and be vacant after the succesful realloc call,
while no earlier slots can have become available [there's no locking
involved, so I assume that avoiding concurrent operations on a struct
nl_cache_mngr is up to the caller].
foo = realloc(foo, ...) is almost always a bug - the only exceptions
being if (a) one just exits the process in case of failure or (b) if one
has made a copy of the foo pointer before the realloc call, and takes
care to either reinstate it afterwards or free() it and make sure that
the data structure is updated to handle foo now being NULL (in this case
for example setting ->cm_nassocs to 0). (a) is not an option in
libraries, and (b) is more cumbersome than just doing it the canonical
way: use local variables for the new pointer and size, and only install
them when realloc succeeds.
Tobias Klauser [Tue, 23 May 2017 07:20:43 +0000 (09:20 +0200)]
genl: drop usage of GENL_ID_GENERATE
After kernel commit a07ea4d9941a ("genetlink: no longer support using
static family IDs"), GENL_ID_GENERATE is no longer exposed to userspace
(and actually should never have been). Update the private header copy of
linux/genetlink.h accordingly. And replace the two occurences of
GENL_ID_GENERATE.
Thomas Haller [Fri, 12 May 2017 10:47:19 +0000 (12:47 +0200)]
build: allow building cli without dynamic librarires support
Commit 3cb28534d34392ceec4adead0cfa97039796ccb7 enables building
of cli always as part of `make check`. As cli previously always
included <dlfcn.h>, this broke tests for building with toolchains
that don't support dynamic library loading.
Add a configure check and disable dlopen() based on whether
<dlfcn.h> is available.
Signed-off-by: Thomas Haller <thaller@redhat.com>
https://github.com/thom311/libnl/pull/141
Thomas Haller [Fri, 12 May 2017 10:40:45 +0000 (12:40 +0200)]
build: don't build cli libraries by default
When configuring with --enable-cli=no, we should not build
the libraries related the cli.
This fixes commit 3cb2853 (build: enable building cli during tests)
which enables building of cli during `make check`. However, during
regular build, these libraries should not get build.
Thomas Haller [Fri, 12 May 2017 08:37:53 +0000 (10:37 +0200)]
rule: change API for setting/getting l3mdev rule property
- for rtnl_rule_set_l3mdev(), also allow unsetting the l3mdev field.
In practice, kernel only allows for two options: either omit
tb[FRA_L3MDEV] or set it to 1. As such, rtnl_rule_set_l3mdev()
allows for both of these. In principle the setter could get
extended to set other values. Such values are reserved.
- for rtnl_rule_get_l3mdev() also return an error code. I think it
is appropriate to mix value and negative error code, as long as
the range of values cannot overlap with error codes.
Arguably, the outcome is a bit awkward, as the function now is
expected to return -NLE_MISSING_ATTR or 1. So, the best check
is probably
if (rtnl_rule_get_l3mdev(r) > 0) { ... }
The reason for this change is that libnl should expose the netlink
API without coercing uint8 to boolean. That way, future changes
in kernel don't require update to libnl3.
David Ahern [Wed, 3 May 2017 23:21:10 +0000 (16:21 -0700)]
rule: Add support for l3mdev in FIB rules
Add support for the l3mdev option in FIB rules. If l3mdev is set
then the lookup is directed to the table associated with the l3mdev
(e.g., VRF) device.
If the l3mev attribute is set the table id is not, so update the table
id attribute to make sure r_table is non-0.
iproute2 shows the rule as:
1000: from all lookup [l3mdev-table]
where [l3mdev-table] infers the dynamic nature of the table id. Keep
that notation for libnl.
Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
Markus Trapp [Tue, 14 Feb 2017 15:33:04 +0000 (16:33 +0100)]
route/link: add accessor API for IPv6 flags
Add functions to access the IPv6 specific flags of a link object.
Also the functions for IPv6 link flags translation are now exported, similar
to the non IPv6 specific translation functions.
Alexey Brodkin [Fri, 10 Mar 2017 14:44:22 +0000 (17:44 +0300)]
lib: escape usage of strerror_l() if it doesn't exist in libc
uClibc doesn't implement strerror_l() and thus libnl starting from
3.2.29 couldn't be compiled with it any longer.
To work-around that problem we'll just do a check on strerror_l()
availability during configuration and if it's not there just fall back
to locale-less strerror().
Thomas Haller [Mon, 6 Mar 2017 20:28:49 +0000 (21:28 +0100)]
libnl-3.3.0-rc1 release
First release candidate for upcoming libnl 3.3.0 release.
Note that from now on, future libnl3 release will bump the
second version number, instead of the third. So the next
version will be 3.3.0 instead of 3.2.30.
This does not imply a break of API/ABI, it is only a change
of the versioning scheme.
Thomas Haller [Wed, 1 Mar 2017 23:30:17 +0000 (00:30 +0100)]
include: restore linux header includes in public headers
The previous commits reorganized the public headers to drop includes
of linux kernel headers.
Restore the previous situation because otherwise the change might
break compilation for users who rely on certain headers getting dragged
in by libnl3.
Thomas Haller [Wed, 1 Mar 2017 21:00:14 +0000 (22:00 +0100)]
include: don't include kernel headers in public libnl3 headers
It would be desirable not to include kernel headers in our public
libnl3 headers. As a test, remove all those includes, and fix
compilation by explicitly including the kernel headers where needed.
In some cases, that requires forward declaration for kernel
structures, as we use them as part of our own headers.
Realistically, we cannot drop those includes as it probalby breaks
compilation for users that expect to get a certain kernel header
when including a libnl3 header. So, this will not be done and the
includes will be restored in the next commit.
Do this step to show how it would be and to verify that we could
build with such a change. The reason not to do this is backward
compatibility (at compile-time).
Thomas Haller [Mon, 27 Feb 2017 17:02:06 +0000 (18:02 +0100)]
build: ensure build directory for generated sources exist
For out-of-tree builds, we must ensure that the build directory
for the generated sources exists. We do that by adding a dependency
to the .dirstamp file.
Thomas Haller [Mon, 27 Feb 2017 16:32:15 +0000 (17:32 +0100)]
xfrm: allow quering optional arguments from xfrmnl_sp_get_sec_ctx()
The previous API of xfrmnl_sp_get_sec_ctx() is totally broken,
as it requires all out-arguments to be set. The user can thus
not know how large the ctx_str buffer must be.
Fix the API by allowing all arguments to be optional. Thus,
a user can first query the size only, and then in a second
step query the ctx_str. Previous version are broken.
security policy can be identified with direction, selector and security context
too. Therefore the code to append approptiate data to delete message is added.
Identification of policy are possible with:
1. direction and index
2. direction and selector
Theoretically second one needs a security context, but non existing context is
valid too.
Fixed xfrmnl_sp->sec_ctx length parameters in xfrmnl_sp_set_sec_ctx,
because former use of only one value wasn't right.
Therefore parameter len is unsued and could be removed.
Thomas Haller [Mon, 27 Feb 2017 11:02:43 +0000 (12:02 +0100)]
build: enable building cli during tests
The cli programs don't have any additional external dependencies.
So, during a `make check`, we should always build them, even if
they were disabled during configure and won't be installed.
Thomas Haller [Mon, 6 Feb 2017 21:23:52 +0000 (22:23 +0100)]
lib: check for integer-overflow in nlmsg_reserve()
In general, libnl functions are not robust against calling with
invalid arguments. Thus, never call libnl functions with invalid
arguments. In case of nlmsg_reserve() this means never provide
a @len argument that causes overflow.
Still, add an additional safeguard to avoid exploiting such bugs.
Assume that @pad is a trusted, small integer.
Assume that n->nm_size is a valid number of allocated bytes (and thus
much smaller then SIZE_T_MAX).
Assume, that @len may be set to an untrusted value. Then the patch
avoids an integer overflow resulting in reserving too few bytes.