Commit Graph

354 Commits

Author SHA1 Message Date
Jef Oliver 9be1849eab lib/route: Extend Bridge Flags
This patch adds support for the following bridge port flags:

IFLA_BRPORT_UNICAST_FLOOD
IFLA_BRPORT_LEARNING
IFLA_BRPORT_LEARNING_SYNC

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-09-24 13:51:29 +02:00
Jef Oliver e17a15a057 lib/route: Add port state translation functions
This patch adds translation functions for translating the port
state between integers and strings.

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-09-24 13:51:29 +02:00
Thomas Haller b3dfa79010 nl-addr: avoid read-out-of-bound in nl_addr_fill_sockaddr()
https://github.com/thom311/libnl/issues/103

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 11:46:19 +02:00
Thomas Haller 99b1d8acf8 lib: capability NL_CAPABILITY_RTNL_ADDR_PEER_ID_FIX for ID comparison of v4 addresses
The ID attributes for IPv4 addresses were broken which causes wrong
nl_object_identical() and cache lookup.

This capability shall indicate that the bug was fixed.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 11:07:01 +02:00
Peter Wu f6b7a7f974 cli: add noreturn attributes
Teach static code analyzers (such as Clang static analyzer) that code
following nl_cli_fatal can never be executed. Avoids false positives
such as detecting use of NULL pointers when that cannot happen.

Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 09:57:25 +02:00
Craig Gallek 625c8f13cf build: fixup headers for C++ inclusion
- Fix typos in extern "C" wrappers.
- 'class' is a reserved word, change to cls.
- int -> enum casts are not automatic.
- Static strings must be of type const char*
- Add a few implicit header dependencies explicitly.

http://lists.infradead.org/pipermail/libnl/2016-July/002165.html

Signed-off-by: Craig Gallek <kraig@google.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-12 23:00:18 +02:00
Thomas Haller 656f381ccf libnl-3.2.28 release
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-07-08 11:41:42 +02:00
Thomas Haller 3711d44e32 route/addr: add capability NL_CAPABILITY_RTNL_ADDR_PEER_FIX to indicate address fixes
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-29 10:26:24 +02:00
Thomas Haller ca5d662e9d xfrm: allow avoiding buffer overflow for key in xfrmnl_sa_get_*_params()
The previous API of xfrmnl_sa_get_*_params() would always require
a @key buffer, but it was not possible to avoid buffer overflow
because the required size was unknown.

That is not really fixable, because the old API is broken.

Now, allow omitting the @key argument to only request the @key_size.
That allows the caller to ask beforehand how large the @key buffer
must be: ((@key_size + 7) / 8).

Unfortunately, omitting the key against previous versions of libnl
leads to a crash. And passing a key against older versions makes it
impossible to avoid buffer-overflow.

Another option would be to add functions like
xfrmnl_sa_get_crypto_params_keylen() so the user can query the required
buffer size by calling that instead of xfrmnl_sa_get_crypto_params().
However, then the user also requires a backport of the new API
and this will not be possible against older libnl3 versions either.
Thus, if the user already requires the fix, he can just as well
require a backport of this patch and then safely call xfrmnl_sa_get_crypto_params()
without @key argument. This way has the advantage/disadvantage, that
it can detect the presence of the patch at runtime.

The cumbersome way to get it right would be:

    unsiged key_len;
    char *key;
    int r;

    if (!nl_has_capability(17 /*NL_CAPABILITY_XFRM_SA_KEY_SIZE*/)) {
        /* no way to use this API safely. Abort. */
        return -NLE_OPNOTSUPP;
    }

    r = xfrmnl_sa_get_crypto_params(sa, NULL, &key_len, NULL);
    if (r < 0)
         return r;
    key = malloc((key_len + 7) / 8);
    if (!key)
         return -NLE_NOMEM;
    r = xfrmnl_sa_get_crypto_params(sa, NULL, &key_len, &key);
    if (r < 0) {
        free(key);
        return r;
    }
    ...

http://lists.infradead.org/pipermail/libnl/2016-June/002155.html

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-29 10:16:04 +02:00
Sabrina Dubroca 885ff4ae1e lib/route: add macsec support
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
2016-06-25 18:27:14 +02:00
Thomas Egerer 6a9b59ca73 xfrm: make character pointers in setters const
All of these pointers are either strcpy'd or memcpy'd and usually const
in a calling application. Changing them to const in the header does not
break the compatibility and allows for users with const pointers to use
the library without compiler warnings.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>

http://lists.infradead.org/pipermail/libnl/2016-June/002137.html
2016-06-25 14:03:50 +02:00
Przemyslaw Szczerbik 424b3b6d0d lib: return error on Netlink attribute length overflow
Netlink attribute length is defined as u16. It's possible to exceed nla_len when
creating nested attributes. Storing incorrect length due to overflow will cause
a reader to read only a part of nested attribute or skip it entirely.

As a solution cancel the addition of a nested attribute when nla_len size is
exceeded.

Signed-off-by: Przemyslaw Szczerbik <przemek.szczerbik@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>

http://lists.infradead.org/pipermail/libnl/2016-May/002131.html
2016-06-24 19:32:25 +02:00
Jonas Johansson 3bf503d30c neigh: add function to look up neighbour (fdb) by ifindex, mac and vlan
The rtnl_neigh_get() function can not be used to look up a fdb entry in the
neigh cache. This is due to that the function searches among destination
addresses (NDA_DST) and not among link layer addresses (NDA_LLADDR), which is
used by fdb entries. A fdb entry can also exist in several vlans, so a vlan id
parameter is also needed to find a unique entry.
This commit adds a function, rtnl_neigh_get_by_vlan() which searches the neigh
cache for a specific neighbour (fdb) entry by interface index, link layer
address and vlan id.

Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
Signed-off-by: Thomas Haller <thaller@redhat.com>

http://lists.infradead.org/pipermail/libnl/2016-May/002124.html
https://github.com/thom311/libnl/pull/98
2016-05-29 15:19:22 +02:00
Thomas Haller 207dc03527 sit: add public API for sit 6RD support
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-04-15 16:24:15 +02:00
Thomas Haller 962afc32df sit: fix invalid declaration of rtnl_link_sit_get_proto() in sit.h
Fixes: d715b8a5f6

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-04-15 16:24:15 +02:00
Haishuang Yan eec318f026 ipgre: add support for gretap tunnel
Since kernel support both gre/gretap tunnel, so add support
for gretap appropriately.

Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>

[thaller@redhat.com: modified original patch to move symbols
 in libnl-route-3.sym to proper section]

http://lists.infradead.org/pipermail/libnl/2016-April/002102.html
2016-04-15 16:18:41 +02:00
Przemyslaw Szczerbik cdf2d4baf3 lib: add type casting for nla_for_each_nested macro
g++ is unable to compile code with nla_for_each_nested macro due to
implicit type conversion from void* to nlattr*. This patch adds type
casting for nla_for_each_nested macro to address this issue.

Signed-off-by: Przemyslaw Szczerbik <przemek.szczerbik@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>

http://lists.infradead.org/pipermail/libnl/2016-February/002095.html
2016-02-25 19:42:56 +01:00
Thomas Haller 926e7777e3 lib/utils: add NL_CAPABILITY_NL_OBJECT_DIFF64 capability
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-02-12 18:20:42 +01:00
David Ahern a09b855814 lib: update ce-mask to uint64_t
lib/route/link.c already defines 32 attributes which fills the current
uint32_t used for ce_mask. To accommodate more attributes the mask needs
to be expanded. This patch updates the definition to uint64_t.

The nl_object_diff API is maintained for ABI with existing users. A new
nl_object_diff64 API is added for the expanded attribute list. The MSB
of the 32-bit API is used to indicate if higher order attributes had a
mismatch. (Suggested by Thomas).

Note that LINK_ATTR_LINK_NETNSID changes. But since the attribute flags
are not public API it shouldn't be a problem.

http://lists.infradead.org/pipermail/libnl/2015-December/002078.html
http://lists.infradead.org/pipermail/libnl/2015-December/002083.html

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-02-12 18:09:04 +01:00
Nick Lewycky 58396ae2ae remove null dereference from netlink/link.h
Replace a null pointer dereference with a use of the 'offsetof' macro in stddef.h.

http://lists.infradead.org/pipermail/libnl/2016-January/002085.html

Signed-off-by: Nick Lewycky <nlewycky@google.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-02-12 13:21:40 +01:00
Tobias Jungel 6e54fd2bed route/link/bridge: fixed return type
Fixes: 6555b0d

https://github.com/thom311/libnl/pull/94
2015-12-16 14:52:54 +01:00
David Ahern 05631628a5 bridge: add support for VLANs
Add operation for requesting VLAN data for AF_BRIDGE and parsing of
IFLA_AF_SPEC for AF_BRIDGE. VLANs are saved in a bitmap.

Also add dumping of vlan info to link list and neigh list.
For example:

$ nl-link-list --details --family=bridge
br1 ether 8e:6e:0e:86:e5:86 master br1 <broadcast,multicast,up,running,lowerup>
    mtu 1500 txqlen 0 weight 0 index 18
    mode default carrier down
    bridge: pvid 1   all vlans: 1 301-400 601-610   untagged vlans: 1
bond1 ether 46:ef:e1:c9:46:fe <broadcast,multicast,master>
    mtu 1500 txqlen 0 weight 0 index 20
    state down mode default carrier down
    bridge:

Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
[thaller@redhat.com: modified original patch to use ao_parse_af_full().
  Also renaming new API and drop some #defines]
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-12-07 12:20:22 +01:00
David Ahern 4b205cab17 route/link/vxlan: add support for link_info compare
Signed-off-by: Balki Raman <ramanb@cumulusnetworks.com>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
[thaller@redhat.com: whitespace, add capability, consider local6/group6]
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-11-20 11:25:34 +01:00
Beniamino Galvani 3f231213c7 route/link: add macvtap support
This adds support for MAC-VLAN based tap interfaces (macvtap).

http://lists.infradead.org/pipermail/libnl/2015-October/001976.html

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-11-19 17:20:28 +01:00
David Ahern 18d60cb9d7 link/neigh: add flags option to link and neighbor caches
Both link and neighbor cache support specify multiple groups (nl_af_group),
but the alloc_cache functions for both do not set the NL_CACHE_AF_ITER
flag before populating the cache so only the first group is used by
default. This patch adds an API to pass in flags to make that happen
and updates the nl-neigh-list command to make use of it.

http://lists.infradead.org/pipermail/libnl/2015-October/001996.html

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-11-19 16:48:21 +01:00
Thomas Haller 7ea15f60a7 route/vlan: allow clearing vlan ingress map
An entry of the ingress map can be cleared by setting
the "to" part to zero.

Previously, vlan_put_attrs() would skip over zero "to"
and thus the user cannot unset an ingress map entry.

Add a modified-mask to record the state of each ingress
map entry and also sent explicit zeros to kernel.

when we receive a IFLA_VLAN_INGRESS_QOS message from kernel,
vlan_parse() similarly sets the received entries as modified.
This preserves previous behavior when using a received object
to modify a vlan.

Add a capability NL_CAPABILITY_RTNL_LINK_VLAN_INGRESS_MAP_CLEAR
to indicate the behavioral change.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-11-19 16:20:39 +01:00
Beniamino Galvani a0b2710ed9 route/link: fix parsing of 'remote' attribute for GRE links
Fixes: 57bdc4ff48

http://lists.infradead.org/pipermail/libnl/2015-November/002004.html

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
[thaller@redhat.com: add capability to indicate bug-fix]
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-11-19 16:14:06 +01:00
David Ahern 493bbd13e6 route/vrf: add VRF support
http://lists.infradead.org/pipermail/libnl/2015-October/001991.html

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
[thaller@redhat.com: slightly modified original patch]
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-11-01 17:54:03 +01:00
Thomas Haller cef00e4f7b rtnl/link: indicate capability NL_CAPABILITY_RTNL_LINK_VLAN_PROTOCOL_SERIALZE
Related: 0aca70083e
2015-10-21 19:04:48 +02:00
Thomas Haller 7b9671c6d8 libnl-3.2.27 release
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-10-16 14:08:36 +02:00
Thomas Haller 6263a11bfc lib/attr: add nla utility functions for signed integers
Commit 7bb956501c added nla functions for
s32. We preferibly add all signed integer operations at the same time.
Thus, also add s8, s16, and s64.

Also, previously the NLA_TYPE_MAX enum was not extended to have
NLA_S32. Fix that too.

Reported-By: Jiri Pirko <jiri@resnulli.us>
Fixes: 7bb956501c
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-10-05 16:52:41 +02:00
Thomas Haller 2a8a7c31e6 route: add capability indicating the behavior of rtnl_neigh_get()
A wrong behavior for rtnl_neigh_get() was introduced between 3.2.14 and 3.2.15
(commit 64fcb47a36).

It was later fixed between 3.2.21 and 3.2.22
(commit 8571f58f23).

Add a capability NL_CAPABILITY_RTNL_NEIGH_GET_FILTER_AF_UNSPEC_FIX
to indicate that this buggy behavior was fixed.

https://bugzilla.redhat.com/show_bug.cgi?id=1261028
http://lists.infradead.org/pipermail/libnl/2015-August/001951.html
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-09-29 18:35:34 +02:00
Thomas Haller 2fc97e66e7 route/link: make link_netnsid argument (signed) int32_t
Fixes: 66aab65595

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-08-17 23:02:00 +02:00
Thomas Haller 7bb956501c lib/attr: add nla utility functions for s32
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-08-17 23:01:57 +02:00
Thomas Haller 66aab65595 route/link: add support for IFLA_LINK_NETNSID
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-08-17 17:13:54 +02:00
matben2 34ccb7210f link: set ifi_change in link message
The ifi_change field can be set with the mask of the flags that need
to be changed as part of the link message to the kernel. This means only
the specific flags that have been changed will be modified in the kernel,
rather than the entire flags entry.

[thaller@redhat.com: add capability to indicate the change in behavior]

https://github.com/thom311/libnl/pull/86
2015-07-09 22:33:32 +02:00
Thomas Haller b4afcadc30 ipvlan: fix signature of rtnl_link_ipvlan_get_mode() to signal error
http://lists.infradead.org/pipermail/libnl/2015-June/001902.html

Fixes: 7de5be85bf

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-06-26 18:04:34 +02:00
Cong Wang 7de5be85bf ipvlan: add ipvlan support
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-06-19 18:03:55 +02:00
Thomas Haller a9c789ccd4 lib: fix spelling of NL_CAPABILITY_NL_RECV_FAIL_TRUNC_NO_PEEK
Instead of NL_CAPABILITY_NL_RECV_FAIL_TRUNK_NO_PEEK.

Fixes: bbdcaea9a7

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-06-05 11:28:59 +02:00
Thomas Egerer bbdcaea9a7 lib: return error if an incomplete message was read
If recvmsg indicates that the message read was truncated libnl retries
to read the complete message after increasing the message buffer. This
only works if the message flags MSG_PEEK | MSG_TRUNC are set. If
NL_MSG_PEEK is not enabled on the nl_sock structure, flags are left
empty and the rest of the truncated message is discarded, hence a
subsequent recvmsg returns the next message (in case of a multipart
message, the NLMSG_DONE) is read and returned.
This patch aborts message processing if the message was truncated and
the NL_MSG_PEEK flags was not activated for the nl_sock structure.

http://lists.infradead.org/pipermail/libnl/2015-June/001888.html

[thaller@redhat.com: add NL_CAPABILITY_NL_RECV_FAIL_TRUNK_NO_PEEK]

Signed-off-by: Thomas Egerer <hakke_007@gmx.de>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-06-05 08:40:02 +02:00
Thomas Haller 8f5c65beee libnl-3.2.26 release
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-03-30 13:17:17 +02:00
Jonas Johansson 31d7d19393 neigh: add support for NDA_VLAN nl attribute
[thaller@redhat.com: modified patch to parse NDA_VLAN and diff vlan]

http://lists.infradead.org/pipermail/libnl/2015-March/001861.html

Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-03-23 09:27:23 +01:00
Thomas Haller 860ea27a46 utils: add code comment about capability number assignment
Also reserve a range of capabilities (0x7000 to 0x7FFF) that we won't
use upstream. Add a macro NL_CAPABILITY_IS_USER_RESERVED() to check
if the capability is in that range.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-03-19 12:26:53 +01:00
David Chappelle 50a76998ac route: remove unnecessary include of private linux/if.h
Including linux/if.h in netlink/route/link.h causes issues
in cases where libnl is used in conjuntion with other third
party libraries that include net/if.h. Seems to be a long
checkered history of symbol collisions between these two
files. As it turns out, including linux/if.h from within
netlink/route/link.h is actually unecessary. I resurrected
a forgotten path from this thread:

    http://lists.infradead.org/pipermail/libnl/2012-April/000525.html

By removing the include as the patch suggests we can get
around the nuissance of the symbol collisions.

https://github.com/thom311/libnl/pull/73

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-03-17 10:07:49 +01:00
Thomas Haller 2d61e89037 lib/socket: add nl_socket_set_fd() function
This is based on the patch by sagil@infinidat.com, but heavily modified.

Add a function nl_socket_set_fd(), I renamed it from nl_connect_fd().

Now nl_connect() and nl_socket_set_fd() are implemented independently as
they share little code. But they have similar functionality:
to initialize a libnl socket and set it's file descriptor.

A user who wants libnl to setup the socket can continue to use nl_connect().
A user with special requirements should setup the socket entirely. That includes
calling socket() (with or without SOCK_CLOEXEC), bind(), setting buffer size.

For the same reason I dropped nl_create_fd(). It didn't do much more then
calling socket() -- which the user can do directly.

https://github.com/thom311/libnl/pull/68

Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-03-05 12:10:28 +01:00
Sagi Lowenhardt f91e6959ea add socket nl_connect_fd() & nl_create_fd()
-    Added option to create socket (fd) without bind.
     It is now possible to forward the socket fd to another child process...
     ...later use nl_connect_fd() to connect to socket from the child process.

-    Added option to disable CLOEXEC even if defined (in socket.h)
     'nl_socket_enable_cloexec' & 'nl_socket_disable_cloexec'
     No change to current default behavior.

 Signed-off-by: Sagi Lowenhardt <sagil@infinidat.com>
2015-03-05 11:27:27 +01:00
Cong Wang d8f080d94f cls: add rtnl_u32_get_classid() API
[thaller@redhat.com: modified patch to use rtnl_tc_data_peek()]

http://lists.infradead.org/pipermail/libnl/2015-March/001841.html

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-03-04 20:31:37 +01:00
Rohan Joyce 6f891f6c0c lib: add const-ness to appropriate parameters in addr, attr, data
This patch changes the signatures of some functions to allow const pointers in
places where a const qualified pointer is enough access for what the function
does (e.g. nla_get_u8). It also changes some functions that take a pointer
parameter and return a pointer derived from it to use the strchr idiom.

This is not exhaustive in terms of places where const can be added, but it's
a decent chunk that should not make the external api any more restrictive.

http://lists.infradead.org/pipermail/libnl/2015-February/001826.html

Signed-off-by: Rohan Joyce <rojoyce.github@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-02-16 11:20:18 +01:00
Cong Wang e75a1c373a route/tc: add rtnl_tc_stat2str() and rtnl_tc_str2stat()
[thaller@redhat.com: add symbols to libnl-route-3.sym]

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-02-02 18:22:47 +01:00
Cong Wang 6d5b9ab8ae route/act: add skbedit action
[thaller@redhat.com: changed whitespace and libnl-route.sym]

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-02-02 18:16:11 +01:00