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.
Tobias Klauser [Tue, 17 Jan 2017 08:22:01 +0000 (09:22 +0100)]
ematch: Add missing function prototypes
Older versions of flex (namely the one used on Travis CI) don't properly
emit function prototypes for ematch_get_column() and
ematch_set_column(), leading to GCC -Wmissing-prototypes warnings. Fix
them by manually adding these prototypes.
Tobias Klauser [Tue, 17 Jan 2017 07:56:03 +0000 (08:56 +0100)]
pktloc: Add missing function prototypes
Older versions of flex (namely the one used on Travis CI) don't properly
emit function prototypes for pktloc_get_column() and
pktloc_set_column(), leading to GCC -Wmissing-prototypes warnings. Fix
them by manually adding these prototypes.
Tobias Klauser [Mon, 16 Jan 2017 14:43:08 +0000 (15:43 +0100)]
netfilter/exp: Add missing function prototypes
Add missing function prototypes for nfnl_exp_unset_flags(),
nfnl_exp_flags2str() and nfnl_exp_str2flags() to the public header.
This fixes the following GCC warnings when compiling with
-Wmissing-prototypes:
netfilter/exp_obj.c:458:6: warning: no previous prototype for ‘nfnl_exp_unset_flags’ [-Wmissing-prototypes]
netfilter/exp_obj.c:475:8: warning: no previous prototype for ‘nfnl_exp_flags2str’ [-Wmissing-prototypes]
netfilter/exp_obj.c:481:5: warning: no previous prototype for ‘nfnl_exp_str2flags’ [-Wmissing-prototypes]
Tobias Klauser [Mon, 16 Jan 2017 14:21:35 +0000 (15:21 +0100)]
link/ipgre: Add prototype for ABI-preserving wrapper rtnl_link_get_pmtudisc()
Avoid a GCC -Wmissing-prototypes warning by explicitely adding a
prototype for the ABI-preserving wrapper added in commit 8d04ebf55400
("lib/route: preserve old ABI for rtnl_link_get_pmtudisc()") and add an
explanatory comment.
Tobias Klauser [Mon, 16 Jan 2017 13:58:20 +0000 (14:58 +0100)]
link/ipvti: Fix and add function prototypes in public header
Add missing "_ipvti" part to function prototypes so they match the
exported name. Also add the missing prototype for rtnl_link_is_ipvti().
This fixes the following GCC warnings when compiling with
-Wmissing-prototypes:
route/link/ipvti.c:281:5: warning: no previous prototype for ‘rtnl_link_is_ipvti’ [-Wmissing-prototypes]
route/link/ipvti.c:369:10: warning: no previous prototype for ‘rtnl_link_ipvti_get_ikey’ [-Wmissing-prototypes]
route/link/ipvti.c:403:10: warning: no previous prototype for ‘rtnl_link_ipvti_get_okey’ [-Wmissing-prototypes]
route/link/ipvti.c:437:10: warning: no previous prototype for ‘rtnl_link_ipvti_get_local’ [-Wmissing-prototypes]
route/link/ipvti.c:471:10: warning: no previous prototype for ‘rtnl_link_ipvti_get_remote’ [-Wmissing-prototypes]
Also fix the corresponding names in documentation.
Tobias Klauser [Mon, 16 Jan 2017 13:42:57 +0000 (14:42 +0100)]
fib_lookup: Add missing prototypes to public header
Add the function prototypes for the struct flnl_result attribute access
functions to the public header fib_lookup/lookup.h
This fixes the following GCC warnings when compiling with
-Wmissing-prototypes:
fib_lookup/lookup.c:284:5: warning: no previous prototype for ‘flnl_result_get_table_id’ [-Wmissing-prototypes]
fib_lookup/lookup.c:289:5: warning: no previous prototype for ‘flnl_result_get_prefixlen’ [-Wmissing-prototypes]
fib_lookup/lookup.c:294:5: warning: no previous prototype for ‘flnl_result_get_nexthop_sel’ [-Wmissing-prototypes]
fib_lookup/lookup.c:299:5: warning: no previous prototype for ‘flnl_result_get_type’ [-Wmissing-prototypes]
fib_lookup/lookup.c:304:5: warning: no previous prototype for ‘flnl_result_get_scope’ [-Wmissing-prototypes]
fib_lookup/lookup.c:309:5: warning: no previous prototype for ‘flnl_result_get_error’ [-Wmissing-prototypes]
Tobias Klauser [Mon, 16 Jan 2017 13:35:36 +0000 (14:35 +0100)]
qdisc/red: Add missing prototypes for rtnl_red_set_limit() and rtnl_red_get_limit()
This fixes the following GCC warnings when compiling with
-Wmissing-prototypes:
route/qdisc/red.c:136:6: warning: no previous prototype for ‘rtnl_red_set_limit’ [-Wmissing-prototypes]
route/qdisc/red.c:152:5: warning: no previous prototype for ‘rtnl_red_get_limit’ [-Wmissing-prototypes]
Nick Kralevich [Tue, 17 Jan 2017 18:56:52 +0000 (10:56 -0800)]
fopen: add O_CLOEXEC
Add O_CLOEXEC to various fopen() calls. This avoids file descriptors
leaking across an exec() boundary in a multi-threaded program. Please
see "man 2 open" for additional information about O_CLOEXEC.
Signed-off-by: Nick Kralevich <nnk@google.com>
https://github.com/thom311/libnl/pull/128
Nick Kralevich [Sat, 14 Jan 2017 19:11:34 +0000 (11:11 -0800)]
lib/utils.c: lazy initialize user_hz and psched_hz
Rather than initializing user_hz and psched_hz when libnl is loaded,
defer initialization of these variables to the first time they are used.
This has several advantages:
1) Avoids an unnecessary permission denied error on /proc/net/psched,
which can occur on systems where /proc/net isn't readable due to
security policy.
2) Allows program code to initialize the environment variables
PROC_NET_PSCHED and/or PROC_ROOT prior to the first libnl call, giving a
program more flexibility about where libnl should look.
3) Trivially faster startup time (although unlikely to be significant).
4) Compiler may be able to prove that the get_psched_settings() function
is unreachable and optimize appropriately, because the callers never
(directly or indirectly) use this method. This could occur, for
instance, in doing dead code elimination for programs which statically
link libnl.
Signed-off-by: Nick Kralevich <nnk@google.com>
https://github.com/thom311/libnl/pull/123
Laine Stump [Tue, 17 Jan 2017 15:47:34 +0000 (10:47 -0500)]
sriov: fix crash in rtnl_link_sriov_parse_vflist
vf_vlan_info was incorrectly indexed with "len" (the length in bytes
of the entire vfinfo_list rather than list_len (the index of the
current end of the vf_vlan_info array)
Tobias Klauser [Fri, 13 Jan 2017 17:18:20 +0000 (18:18 +0100)]
route/tc: Remove unused function tca_set_kind()
The public prototype and the last internal user of the function were
removed in commit 8eb5b5532e ("Unified TC API") and it was unexported in
commit 4280dfb85d ("build: don't export internal symbols"), so it is
safe to remove it.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
https://github.com/thom311/libnl/pull/122
Tobias Klauser [Tue, 6 Dec 2016 14:22:11 +0000 (15:22 +0100)]
link: fix documentation for rtnl_link_get_carrier_changes
The doxygen comment of rtnl_link_get_carrier_changes still describes the
initially implemented behaviour and was not updated, when the signature
was changed as part of #119. Adjust it accordingly.
Fixes: 0c4b2ea6d17b ("link: add support for IFLA_CARRIER_CHANGES") Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
https://github.com/thom311/libnl/pull/120