Commit Graph

1002 Commits

Author SHA1 Message Date
Thomas Haller
77ae25aad1 xfrm: fix memory corruption (dangling pointer) when when setting xfrmnl_sa
The follow leaves a dangling pointer when the name argument is too long:

xfrmnl_sa_set_aead_params:

    if (sa->aead)
        free (sa->aead);
    if (   strlen (alg_name) >= sizeof (sa->aead->alg_name)
        || (sa->aead = calloc (1, newlen)) == NULL)
        return -1;

Fix that, but do more:

- ensure that we don't modify the object when the setter is going to
  fail. That means, first check whether we can succeed with all the
  steps that are requested, and (in case we cannot) fail without
  modifing the target object.

- bonus points for making the setter self-assignment safe by reordering
  the setting and freeing of the memory.
2019-08-09 16:48:55 +02:00
Thomas Haller
7d3991b87b 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.
2019-08-09 16:48:55 +02:00
Thomas Haller
f1a085994a link/sriov: fix memleak in rtnl_link_sriov_clone()
Found by Coverity.
2019-08-08 17:01:21 +02:00
Thomas Haller
f6f163d68e route: fix strncpy() warning from coverity about unterminated string
Coverity says:

  Error: BUFFER_SIZE_WARNING (CWE-120): [#def1]
  libnl-3.4.0/lib/route/cls/ematch/text.c:94: buffer_size_warning: Calling strncpy with a maximum size argument of 16 bytes on destination array "t->cfg.algo" of size 16 bytes might leave the destination string unterminated.
  #   92|   	struct text_data *t = rtnl_ematch_data(e);
  #   93|
  #   94|-> 	strncpy(t->cfg.algo, algo, sizeof(t->cfg.algo));
  #   95|   }
  #   96|

  Error: BUFFER_SIZE_WARNING (CWE-120): [#def11]
  libnl-3.4.0/lib/xfrm/sa.c:1192: buffer_size_warning: Calling strncpy with a maximum size argument of 64 bytes on destination array "auth->alg_name" of size 64 bytes might leave the destination string unterminated.
  # 1190|   			}
  # 1191|
  # 1192|-> 			strncpy(auth->alg_name, tmpl->auth->alg_name, sizeof(auth->alg_name));
  # 1193|   			auth->alg_key_len = tmpl->auth->alg_key_len;
  # 1194|   			memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8);
2019-08-08 17:01:21 +02:00
Thomas Haller
7de65a051f 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.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b424e432e770d6dd572765459d5b6a96a19c5286
[2] https://git.netfilter.org/libmnl/tree/src/attr.c?id=5937dfcb0185f5cb9cf275992ea701ec4e619d9c#n535
2019-08-07 15:32:19 +02:00
Thomas Haller
e5961ffaf1 doc: fix typos in example in documentation
https://github.com/thom311/libnl/issues/210
2019-08-07 14:51:30 +02:00
Thomas Haller
cf6804add6 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.
2019-03-07 11:50:52 +01:00
Tobias Jungel
c503f924a0 route/link: expose IFLA_INFO_SLAVE_KIND
add rtnl_link_{get,set}_slave_type functions to expose the
IFLA_INFO_SLAVE_KIND attribute.
2018-10-22 15:20:19 +02:00
Thomas Haller
08160f0555 route/macvlan: style fixes in "lib/route/link/macvlan.c" 2018-10-10 12:16:16 +02:00
Wang Jian
470b983546 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: c76393e203

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
2018-10-10 12:11:55 +02:00
Patrick Havelange
123dc07bcc nla_ok: fix overrun in attribute iteration.
A detailed explanation is provided in the original Linux kernel commit that
fixes the bug: 1045b03e07d85f3545118510a587035536030c1c

Valgrind spotted the issue when the remaining was negative.
This bug was triggering application crashes.

Signed-off-by: Patrick Havelange <patrick.havelange@tessares.net>

https://github.com/thom311/libnl/pull/199
2018-10-10 11:54:08 +02:00
Ilya Pronin
1ac40683a8 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.

Signed-off-by: Ilya Pronin <ipronin@twitter.com>

Fixes: e5d9b828f6

https://github.com/thom311/libnl/pull/201
2018-10-10 11:48:55 +02:00
Thomas Haller
46440e7fe7 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.
2018-10-10 11:37:41 +02:00
Thomas Haller
a358cf2cd1 route/act: style fixes in "lib/route/act/vlan.c" 2018-10-10 11:30:06 +02:00
Volodymyr Bendiuga
b004e40063 route:act: add vlan action
For more information please see:
http://man7.org/linux/man-pages/man8/tc-vlan.8.html

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-10-10 11:12:08 +02:00
Thomas Haller
a90256de2f 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.
2018-10-10 11:02:46 +02:00
Volodymyr Bendiuga
c9b28170e7 route:tc: allow to set chain index for tc objects
This is useful when one wants to chain filters.

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-10-10 11:00:21 +02:00
Thomas Haller
1bffe3cc67 lib/tc: fix uninitalized err variable in rtnl_tc_msg_build()
Fixes: 52cd3c14ce
2018-10-10 10:59:48 +02:00
Thomas Haller
b7419a1bce lib/qdisc: avoid BUG() in "lib/route/qdisc/mqprio.c"
BUG() raises an assertion. It seems overly harsh.

For example, rtnl_tc_data() can fail if we fail to allocate
memory. Asserting against that, makes libnl3 not out-of-memory
safe.

Just return a regular error.
2018-10-09 15:31:39 +02:00
Thomas Haller
8a6c8e548d lib/qdisc: style fixes in "lib/route/qdisc/mqprio.c" 2018-10-09 10:57:58 +02:00
Thomas Haller
52cd3c14ce lib/tc: ensure correct error code in rtnl_tc_msg_build() 2018-10-08 13:41:25 +02:00
Volodymyr Bendiuga
25cf1d39ed route:qdisc: add MQPRIO Qdisc
More about Qdisc mqprio can be found at:
http://man7.org/linux/man-pages/man8/tc-mqprio.8.html

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-07-26 11:17:37 +02:00
Thomas Winter
daa2edebe7 ipvti: Fix wrong array size initialization
IPv4 VTI tunnels use the VTI defines.

Signed-off-by: Thomas Winter <Thomas.Winter@alliedtelesis.co.nz>

Fixes: 8f6301426a
2018-06-25 15:10:00 +02:00
Thomas Winter
a31948b905 ipgre: Fix wrong array size initialization
IPv4 GRE tunnels use the GRE defines.

Signed-off-by: Thomas Winter <Thomas.Winter@alliedtelesis.co.nz>

Fixes: 57bdc4ff48
2018-06-25 15:07:46 +02:00
Tobias Jungel
a153517c5c neigh: update neighbour.h and add missing flags
NTF_EXT_LEARNED, NTF_OFFLOADED and NTF_MASTER are added to neigh_flags.

https://github.com/thom311/libnl/pull/186
2018-06-25 14:50:03 +02:00
Tuetuopay
cd5f6f8429 route/link/vxlan: Fix IPv4 set_local resetting ce_mask
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.

Fixes: 2e68fb5b02

https://github.com/thom311/libnl/pull/192
2018-06-25 14:44:56 +02:00
d0u9
ddfc36f46e 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.

https://github.com/thom311/libnl/pull/176
2018-06-25 14:39:41 +02:00
Tobias Jungel
3ebb0ea66b neigh_dump_line: dump master as well
In case NEIGH_ATTR_MASTER is set this dumps as well the master
interface.

https://github.com/thom311/libnl/pull/190
2018-06-25 14:30:02 +02:00
Tobias Jungel
2e87f72bf4 neigh: add get/set functions for NEIGH_ATTR_MASTER
Beeing able to set NEIGH_ATTR_MASTER hash based lookups are possible for
AF_BRIDGE neighbours.

https://github.com/thom311/libnl/pull/189
2018-06-25 14:27:50 +02:00
Tobias Jungel
857961ac02 whitespace cleanup 2018-06-25 13:57:34 +02:00
Tobias Jungel
ee16d50a68 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`.
2018-06-25 13:57:34 +02:00
Matthieu Baerts
40fd4113f2 nl: fix function name in debug msg
Just a typo.

Fixes: f545295 (lib: log errors from platform)

Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>

https://github.com/thom311/libnl/pull/191
2018-06-25 13:55:22 +02:00
d0u9
17f0459c8d 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.

https://github.com/thom311/libnl/pull/185
2018-04-11 13:05:09 +02:00
Thomas Haller
bb446bc116 nl-msg: explicitly initialize nlmsg_seq and nlmsg_pid field in nlmsg_alloc_simple()
This is no change in behavior, because the NL_AUTO_* macros are both
zero.
2018-04-11 12:48:44 +02:00
Thomas Haller
dc61768ec6 route/link: assert in rtnl_link_change() that the sequence number is set as expected 2018-04-11 12:48:41 +02:00
Tuetuopay
4e2f5dfa64 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.

[thaller@redhat.com: changed commit message]

https://github.com/thom311/libnl/issues/179
https://github.com/thom311/libnl/pull/184
2018-04-11 12:35:41 +02:00
Thomas Haller
1c703b84be route/mall: fix deep cloning mall
rtnl_act_append() does not clone the object, it takes it over
and thus the source object is destroyed.
2018-04-11 12:22:16 +02:00
Volodymyr Bendiuga
5893c3f18e route:cls: add matchall classifier
This simple classifier allows any traffic pass through.
Useful as an example for port mirroring.

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-04-11 12:22:16 +02:00
Tuetuopay
6ddd60127e cache: make "result" output argument for nl_cache_mngr_add() optional
[thaller@redhat.com: rewritten commit message]

https://github.com/thom311/libnl/issues/178
https://github.com/thom311/libnl/pull/183
2018-04-11 12:19:01 +02:00
Tobias Jungel
3c96f6513c 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.

https://github.com/thom311/libnl/pull/182
2018-04-06 19:51:22 +02:00
Tobias Jungel
d1bd68d100 neigh: set correct AF for NDA_DST
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.

https://github.com/thom311/libnl/pull/180
2018-04-06 19:47:03 +02:00
David Ahern
961c4f6750 rule: Add support for protocol and port ranges
Add support for recent fib rule features - specifying a protocol
that installed a rule and an IP protocol plus port range for rules.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2018-04-06 14:54:12 +02:00
Jonas Johansson
c3db1c4782 route/vrf: initalize clone destination with NULL in vrf_clone()
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2018-03-12 13:53:22 +01:00
Roopa Prabhu
988b0cc0ca lib: route: rule: add rule_groups to cache ops
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
2018-02-15 10:21:33 +01:00
Thomas Haller
cb8e34859b lib/rtnl: rename public define RTNL_GENEVE_ID_MAX
Public defines must have a libnl3 related prefix. Rename
GENEVE_ID_MAX to RTNL_GENEVE_ID_MAX.
2018-02-12 15:23:02 +01:00
Wang Jian
6b4fc607ba link: add Geneve support.
Signed-off-by: Wang Jian <jianjian.wang1@gmail.com>
2018-02-12 14:36:15 +01:00
Thomas Haller
daa4a68177 lib: merge implementations of nl_attr_end() and nl_attr_keep_empty()
Both functions are almost identical. Merge them into a common helper
function with an @keep_empty argument, so it is clear at which point
they differ.

Also, fix symbols versioning for nl_attr_keep_empty(). For symbol
versioning, once released a version cannot be modifified/extended.
2018-02-12 14:17:11 +01:00
d0u9
5205783203 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.
2018-01-24 00:02:55 +08:00
Thomas Haller
7eeb29bc53 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.
2018-01-18 07:54:27 +01:00
d0u9
ca02edd101 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.
2018-01-18 07:51:23 +01:00