Thomas Haller [Fri, 9 Aug 2019 11:12:30 +0000 (13:12 +0200)]
lib/genl: avoid VLA in cmd_msg_parser()
We want to build with -Wvla, because VLAs interfere with static asserts
(if the condition of a static assert is not actually static, then VLAs
make it silently pass).
Also, VLAs should be avoided because we want to be in contol how much
we allocate on the stack.
Thomas Haller [Thu, 8 Aug 2019 16:26:23 +0000 (18:26 +0200)]
utils: add internal helper macros for cleanup
Yes, these use gcc-isms like typeof(), __attribute__((__unused__)),
__attribute__((__cleanup__(fcn))) and expression statements.
First of all, this is now only required when building libnl3 itself.
The public headers still should to be conservative and only use C89
features.
Also, clang supports these too, so you can at least build libnl3 with
gcc and clang. Since libnl3 uses internally linux headers, and the linux
kernel also can only be compiled with gcc (and maybe clang), it seems
clear that on the target platform a suitable compiler is available.
If there is a reasonable request of a real-world compiler that is not
able to compile this, we can revisit some choices. But not having
__attribute__((__cleanup__(fcn))) is like programming C from a decade
ago. Especially during parsing (which libnl3 does obviously a lot), this
allows to return-early while cleanup up memory. While this sounds simple
to get right manually, in practice the resulting code is either
unnecessary complex or simply buggy.
To make implementing libnl3 more convenient, these helpers are
introduced.
Thomas Haller [Wed, 7 Aug 2019 12:53:26 +0000 (14:53 +0200)]
attr: mark nested attributes as NLA_F_NESTED
Kernel 5.2 is adding stricter checking for netlink messages.
In particular, for certain API it checks now that NLA_F_NESTED flag is
set for nested attributes ([1]).
Do like libmnl, which always adds this flag ([2]). So we should do
that as well.
Thomas Haller [Thu, 7 Mar 2019 10:28:14 +0000 (11:28 +0100)]
route/link: avoid dangling pointer in rtnl_link_set_slave_type()
- don't leave a dangling pointer, in case we unset the
kind.
- try first to clone the string. If that fails, return early
without modifying the link. Only start modifying the link,
after we know it's going to succeed.
Wang Jian [Sat, 29 Sep 2018 11:09:17 +0000 (11:09 +0000)]
link: macvlan fixes
1. While parsing flags, it overrides mode.
2. Before, dump-line and dump-details are same leading that macvlan info will be shown twice while dumpping details.
So make dump-line show nothing.
3. Add some spaces to show dump-details more prettier.
Signed-off-by: Wang Jian <jianjian.wang1@gmail.com> Fixes: c76393e2037d78eb60c32f95b26f5b1e5b9422a6
http://lists.infradead.org/pipermail/libnl/2018-August/002405.html
http://lists.infradead.org/pipermail/libnl/2018-September/002406.html
http://lists.infradead.org/pipermail/libnl/2018-September/002411.html
Ilya Pronin [Thu, 23 Aug 2018 23:12:25 +0000 (16:12 -0700)]
route/cls: fix potential memory leak
rtnl_act_append() cannot add more than TCA_ACT_MAX_PRIO actions to the
same list. Because of that rtnl_basic_add_action() and
rtnl_u32_add_action() should not increment the reference counter of the
given action until it is successfully added to the filter's list.
Thomas Haller [Wed, 10 Oct 2018 09:33:16 +0000 (11:33 +0200)]
route/act: return error code from act-vlan getters
Our API is unfortunately not consistent about this.
However, in general, getters should aim to return an
error code whether the attribute could be retrieved.
Thomas Haller [Wed, 10 Oct 2018 09:02:36 +0000 (11:02 +0200)]
route/tc: return error code from rtnl_tc_get_chain()
Our API is unfortunately not consistent about this.
However, in general, getters should aim to return an
error code whether the attribute could be retrieved.
rtnl_link_vxlan_set_local() removes the bit for the other IP version in
ce_mask. A missing flag inversion in the v4 part made this removal
reset all bits to 0 except the v6 one, screwing all link configuration.
d0u9 [Fri, 23 Mar 2018 13:21:11 +0000 (21:21 +0800)]
Add support for cloning cgroup filter object.
In this commit, we implement ematch_tree_clone(), which is basis of
cgroup_clone() interface. The whole ematch tree is deep-copied except
the e_ops filed.
Also, a new unit test is added for testing the interface, which named as
check-ematch-tree-clone.c located in tests directory.
neigh: cache updates as well query AF_BRIDGE neigh
This commit adds the query for AF_BRIDGE neighbours. A cache refresh now
includes these objects as well. The result of `./src/nl-neigh-list
--family=bridge` includes now as well the same entries you would
retrieve from the kernel by calling `bridge fdb show`.
route/class: add new api rtnl_class_get_by_parent()
This function searches a class cache previously allocated with
rtnl_class_alloc_cache() and searches for a class matching the interface
index and parent qdisc.
route/link: fix sequence number handling in rtnl_link_change()
When rtnl_link_change() fails with -NLE_OPNOTSUPP, it retries
with RTM_SETLINK operation. However, it also needs to re-adjust
the sequence number. Otherwise, the second request might fail
with NLE_SEQ_MISMATCH, although it actually succeeded.
neigh: support bridge entries for vxlan interfaces
bridge entries used for switching into vxlan interfaces do not include a
vlan. A comparison of such entires currently always fails which leads
to an invalid cache. This patch selectively adds the NEIGH_ATTR_VLAN
flag based on the passed entry.
In case using a VXLAN interface at a bridge you will set L2 bridging
entries using a IP destination to tunnel the according L2 traffic. The
current behavior for the dst entries for a neighbor is to use the AF of
the neighbor itself thus in this case AF_BRIDGE is set. This is changed
in the PR to update the family of the dst using nl_addr_guess_family.
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.