d0u9 [Tue, 23 Jan 2018 06:13:43 +0000 (14:13 +0800)]
Fix for cgroup filter addition problem.
Currently, due to the incomplete netlink datagram sent by libnl, cgroup
filter addition is not fully functional. The datagram generated by `tc`
command includes an empty attribute section, which is stripped off
in the libnl counterpart.
In this commit, a new `interface nla_nest_end_keep_empty()` is added.
This function closes attribute without stripping off empty attribute.
Thomas Haller [Thu, 18 Jan 2018 06:54:27 +0000 (07:54 +0100)]
route: rename rtnl_cls_cache_set_tcm_params() and fix symbol versioning
After rethinking, "tcm_params" doesn't seem like a good name. Change it to
"tc_params".
Also, an already released section in the linker file must never be
modified. It defeats the purpose of symbol versioning. Move the symbol
to the right section.
d0u9 [Mon, 15 Jan 2018 08:35:50 +0000 (16:35 +0800)]
Add new function for setting ifindex and parent of a classifier cache.
It is not good to give classifier cache users only one chance to
set interface index and parent handle when allocte new cache.
Sometimes we want to reuse classifier cache to reduce the overhead
of allocating new memory everytime a new cache is created.
Based in the function documentation, peer name could be set regardless
of the link name being informed of not. These parameters should be
checked independently.
Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
https://github.com/thom311/libnl/pull/162
tests: Add test to {de}activate loopback interface
This tests is much more like an example of how to do it, and also works
as a test to check if rtnl_link_change is working as expected when it
comes to loopback interface.
Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
https://github.com/thom311/libnl/pull/161
Steffen Vogel [Wed, 20 Dec 2017 10:09:08 +0000 (11:09 +0100)]
route: add separate function to set netem qdisc delay distribution
A new function rtnl_netem_set_delay_distribution_data() has been added
to allow the user to pass the delay distribution directly without loading
it from a file.
In conjunction with the maketable code (see iproute2 / NISTnet) this can
be used to generate and load custom delay distributions on the fly.
Chris Grahn [Fri, 1 Dec 2017 19:41:45 +0000 (13:41 -0600)]
tests: fix bug in test-create-bridge.c
The call to rtnl_link_get_master() at the end of the example can
misleadingly fail because the nl_cache isn't refilled after adding the
test interface to the test bridge.
This commit changes the example to refill the cache before calling
rtnl_link_get_master().
Jef Oliver [Tue, 28 Nov 2017 21:10:54 +0000 (13:10 -0800)]
Change rtnl_link_af_ops.ao_override_rtm behavior
rtnl_link_af_ops.ao_override_rtm allows for a link module to
override the change request type being sent to the kernel. More
specifically, the default change request type is RTM_NEWLINK.
Some link change requests require the reqeust type to be set to
RTM_SETLINK. This is the case for IFLA_PROTINFO specific
attributes for a link that is slave to a bridge.
Currently, ao_override_rtm is static to the address family type.
So, all changes submitted to AF_BRIDGE override the link change
request type. The override only needs to happen if IFLA_PROTINFO
attributes are appended to the link change request.
This patch changes ao_override_rtm from a const integer to a
function pointer that allows for a link module to determine if
the override needs to actually happen.
Currently, only the bridge module uses this functionality. If
bridge flags are applied to a link (bdpu blocking, learning,
fast leave, etc...), these flags are nested in IFLA_PROTINFO. If
the flags are present, the link change request type will be
overridden as RTM_SETLINK.
This fixes the ability to set a bridge link up or down by using
the correct RTM_NEWLINK link change request type.
Sebastian Bixl [Sun, 15 Oct 2017 20:34:01 +0000 (22:34 +0200)]
route/vlan: fix memory corruption in rtnl_link_vlan_set_egress_map
If you set more than four entries for the vlan egress map a memory
corruption occurs because the reallocation does not reserve memory
for more than four.
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.