Commit Graph

1253 Commits

Author SHA1 Message Date
Jef Oliver ab17f9803d lib/route: Allow override of IFLA_AF_SPEC nesting
This patch adds the ability to override nesting into an AF specific
attribute. An example of this is the bridge module.

Regular Nesting:
[IFLA_AF_SPEC]
    [AF_INET]
        [AF_INET_ATTRS]

Bridge Nesting:
[IFLA_AF_SPEC]
    [AF_BRIDGE_ATTRS]

This patch adds ao_fill_af_no_nest to struct rtnl_link_af_ops.
When set to non-zero, this will override the nested AF attribute
and allow nesting of attributes directly into IFLA_AF_SPEC.

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 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
Jef Oliver 6e0c2e56cb lib/route: Fix appending IFLA_BRPORT_FASTLEAVE
This patch fixes IFLA_BRPORT_FASTLEAVE to append to the correct
netlink attribute. (Turned up in automated testing.)

Fixes: 55bc931a72

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-09-24 13:50:18 +02:00
Thomas Haller ff7ca59783 macsec: merge branch 'macsec-fix'
https://github.com/thom311/libnl/pull/108
2016-09-24 12:53:16 +02:00
Davide Caratti a355b9a53b remove multiple implementations of htonll(), ntohll()
use a single #define in include/netlink-private/utils.h

Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
2016-09-06 11:21:48 +02:00
Davide Caratti 6cfe71ef15 macsec: fix maximum ICV length
Update copy of kernel header 'if_macsec.h' to Linux 4.8-rc5, so that
upstream commit 2ccbe2cb79f2f74ab739252299b6f9ff27586f2c ("macsec: limit
ICV length to 16 octets") is included. Return -NLE_INVAL when trying to
configure an ICV length greater than 16 octets.

Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
2016-09-05 18:38:27 +02:00
Davide Caratti cd758fbfee macsec: fix endianness of 'sci' parameter
'sci' passed to kernel is meant to be in network byte order: use
ntohll() and htonll() accordingly.

Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
2016-09-05 18:37:06 +02:00
Thomas Haller 7bf2e64654 lib/route: merge branch 'bride-protinfo'
http://lists.infradead.org/pipermail/libnl/2016-August/002204.html

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-29 13:11:49 +02:00
Jef Oliver 55bc931a72 lib/route: modify link/bridge to set attributes
This patch modifies link/bridge to set link attributes in a
request message. It adds set support for currently implemented
functionality.

This patch adds bridge_fill_pi, a function to fill in the
IFLA_PROTINFO nested attribute.

This patch modifies the bridge_ops structure to support
modifications made to properly set RTM_SETLINK during modifcation
of a link, append the NLA_F_NESTED flag to IFLA_PROTINFO, and
to call the newly added bridge_fill_pi.

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-29 13:09:41 +02:00
Jef Oliver 998d107cd8 lib/route: set IFLA_PROTINFO attribute in request message
This patch adds the functionality to set IFLA_PROTINFO in a
request. This allows for appending protocol specific information
to a request message.

This patch adds ao_fill_pi to the rtnl_link_af_ops structure. This
registers a function to fill the IFLA_PROTINFO attribute. This
function follows the makeup of ao_fill_af.

This patch adds ao_fill_pi_flags to the rtnl_link_af_ops
structure. This registers an extra flag that can be bitmasked
onto the IFLA_PROTINFO definition. This is useful for address
families that require NLA_F_NESTED.

This patch adds a function named af_fill_pi, which is called by
build_link_msg. This function calls the registered function
pointers for an address family to fill IFLA_PROTINFO and to
bitmask any extra flags.

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-29 13:09:37 +02:00
Jef Oliver 5860c205d4 lib/route: allow override of message type during link change
When rtnl_link_build_change_request() builds a change request,
it sets the message type to RTM_NEWLINK by default. If the
request fails, it changes the type to RTM_SETLINK, and resubmits.

For some address families, this will result in a requested change
never being applied by the kernel. An exmaple of this is the Linux
bridge. When a netlink message of type RTM_NEWLINK is recieved,
rather than failing, it simply ignores the message and does not
return a failure.

To fix this, this patch implements an override for address
families that require it. The override can be set when an address
family registers itself in libnl.

This patch adds ao_override_rtm to the rtnl_link_af_ops structure.
This patch adds a static function named af_request_type.
This patch modifies rtnl_link_build_change_request to call
  af_request_type to properly set the request type if an address
  family wishes to override.

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-29 13:09:29 +02:00
Jeff Squyres 746bbba3e5 compat: add linux/socket.h for __kernel_sa_family_t
The __kernel_sa_family_t type is not present on older systems (e.g.,
RHEL 6), and libnl3 will not built without it.  Copy
/usr/include/linux/socket.h from a RHEL7 system to
include/linux-private/linux/socket.h so that it will be found by the
build system.

Fortunately, this socket.h is small and self-contained; it contains
very little (and does not #include any other files) beyond necessary
type.

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

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-29 12:49:45 +02:00
Thomas Haller e1ca7733ef all: merge branch 'strerror_l'
http://lists.infradead.org/pipermail/libnl/2016-August/002192.html

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-25 17:54:31 +02:00
André Draszik 6c2d111177 src: switch to using strerror_l() instead of strerror_r()
glibc provides two versions of strerror_r(), which
can be chosen between using feature test macros
_GNU_SOURCE and _POSIX_C_SOURCE. libnl is built using
the former, hence we get the glibc special version,
and all code so far has been written for this.

Other C libraries like musl on the other hand only try
to be posix compliant, and only ever provide the posix
version of strerror_r(), which has a different signature.

Uses in libnl hence generally cause printf() of an *int*
with a *string format* specifier for that reason.

Additionally, strerror_r() has been deprecated:
  http://austingroupbugs.net/view.php?id=655

Switch to using strerror_l().

Signed-off-by: André Draszik <adraszik@tycoint.com>
Reviewed-by: Stephane Ayotte <sayotte@tycoint.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-25 17:32:57 +02:00
André Draszik c1948ec29b lib: switch to using strerror_l() instead of strerror_r()
glibc provides two versions of strerror_r(), which
can be chosen between using feature test macros
_GNU_SOURCE and _POSIX_C_SOURCE. libnl is built using
the former, hence we get the glibc special version,
and all code so far has been written for this.

Other C libraries like musl on the other hand only try
to be posix compliant, and only ever provide the posix
version of strerror_r(), which has a different signature.

Uses in libnl hence generally cause printf() of an *int*
with a *string format* specifier for that reason.

Additionally, strerror_r() has been deprecated:
  http://austingroupbugs.net/view.php?id=655

Switch to using strerror_l() (via our wrapper just
introduced).

Signed-off-by: André Draszik <adraszik@tycoint.com>
Reviewed-by: Stephane Ayotte <sayotte@tycoint.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-25 17:32:57 +02:00
André Draszik 683f27fbb6 lib: add utility function nl_strerror_l()
libnl currently uses strerror_r() throughout, but this is
problematic because there is a non-standard GNU version
implemented in glibc, and the standard POSIX version, which
differ in signature. When using glibc, one can choose
between the two versions using feature test macros
_GNU_SOURCE and _POSIX_C_SOURCE.

Given libnl is built using the former, we always get the
glibc special version, and all code so far has been written
for that non-standard version.

Other C libraries like musl on the other hand only try
to be posix compliant, and only ever provide the posix
version of strerror_r(), which has a different signature.

The alternative is to use strerror_l() rather than
strerror_r() http://austingroupbugs.net/view.php?id=655
- this will avoid the non-confirming versions issue
- strerror_l() is now recommended by POSIX to replace
  strerror_r() usage

So rather than changing all uses of strerror_r() to be in
line with posix, we are going to switch to the recommended
interface strerror_l().

Since strerror_l() is slightly more difficuly to use, we
add a little (private) wrapper that we can use from all
current callsites of strerror_r().

Signed-off-by: André Draszik <adraszik@tycoint.com>
Reviewed-by: Stephane Ayotte <sayotte@tycoint.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-25 17:32:57 +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 5e17c54a75 route/addr: merge branch 'toanju-fix-addr_id_attrs_get' (#105)
https://github.com/thom311/libnl/pull/105

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 11:10:30 +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
Tobias Jungel dfaba51b5b route/addr: address attributes based on object
addr_id_attrs_get returned a fixed set of attributes for AF_INET. This
leads to an invalid cache in case the default cache manager is used.

The error was cause by nl_object_identical, which checkes the ce_mask
of an object against the req_attrs. For route/addr objects the ce_mask
may contain the ADDR_ATTR_PEER, but the addr_id_attrs_get always
includes this attribute. Thus nl_object_identical fails always in case
no peer exists, which is the default for local addresses.

Fixes: 83e851ca9c

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 11:00:30 +02:00
Thomas Haller 9867bc2053 all: merge branch 'various-fixes'
http://lists.infradead.org/pipermail/libnl/2016-August/002177.html

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 10:08:23 +02:00
Peter Wu ec7c9b4dcf doc: fix URLs and typo
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 09:57:25 +02:00
Peter Wu daaa2c5cb1 exp: fix a GCC 6 -Wmisleading-indentation warning
Replaced the spaces by tabs to fix it.

Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 09:57:25 +02:00
Peter Wu f1029d44be xfrm: fix memleak in another error path of build_xfrm_sa_message
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-14 09:57:25 +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
Peter Wu c520876011 trivial: whitespace-only fixes for src and lib
Fixes alignment, lines with just whitespace and mixed tab/space
indentation. Searched, reviewed and optionally fixed in vim using
regex ^\t* [\t ]*\([^*us ]\|$\)\|\t\+$

http://lists.infradead.org/pipermail/libnl/2016-August/002183.html

Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-08-12 23:06:27 +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 bd0e87b3d8 libnl-3.2.28-rc1 release
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-30 12:54:08 +02:00
Thomas Haller 9fa986bde7 build: fix adding macsec files to include/Makefile.am
Fixes: 885ff4ae1e
2016-06-30 12:54:08 +02:00
Thomas Haller 4095e5b4e9 route/addr: merge branch 'ip-addr-fixes'
http://lists.infradead.org/pipermail/libnl/2016-June/002156.html
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-29 10:27:29 +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 62f0fdb9c1 route/addr: fix handling peer addresses for IPv4 addresses
For IPv4, a "normal" route has IFA_LOCAL and IFA_ADDRESS set
to the same destination. An address with a explicit peer, has
them differing. A peer of 0.0.0.0 is also valid and must
be treated different from a normal address.

    unshare -n
    ip link add T type dummy
    ip link set T up
    ip addr add 192.168.5.10 peer 192.168.5.10/24 dev T
    ip addr add 192.168.5.10/24 dev T
    #RTNETLINK answers: File exists
    ip addr add 192.168.5.10 peer 192.168.6.10/24 dev T
    ip addr add 192.168.5.10 peer 0.0.0.0/24 dev T

Previously, that would give:

    nl-addr-list
    #192.168.5.10/24 inet dev T scope global <permanent>
    #192.168.5.10 peer 192.168.6.10/24 inet dev T scope global <permanent>
    #192.168.5.10/24 inet dev T scope global <permanent>

With this change, we properly get:

    nl-addr-list
    #192.168.5.10/24 inet dev T scope global <permanent>
    #192.168.5.10/24 peer 192.168.6.10 inet dev T scope global <permanent>
    #192.168.5.10/24 peer 0.0.0.0 inet dev T scope global <permanent>

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-29 10:26:18 +02:00
Thomas Haller 83e851ca9c route/addr: fix ID comparison for AF_INET and AF_INET6 addresses
For AF_INET/IPv4 addresses, the ID equality comparison must include
the net-part of the peer address:

    unshare -n
    ip link add T type dummy
    ip link set T up
    ip addr add 192.168.5.10/24 dev T
    ip addr add 192.168.5.10 peer 192.168.6.1/24 dev T
    ip addr add 192.168.5.10 peer 192.168.7.1/24 dev T
    ip addr add 192.168.5.10 peer 192.168.7.2/24 dev T
    # RTNETLINK answers: File exists

    ip addr change 192.168.5.10 peer 192.168.7.2/24 dev T
    ip addr show | grep 192.168.7.
    # inet 192.168.5.10 peer 192.168.7.1/24 scope global T

For AF_INET6/IPv6 addresses, the prefix length of the address
is not part of the ID:

    unshare -n
    ip link add T type dummy
    ip link set T up
    ip addr add 192.168.7.10/24 dev T
    ip addr add 192.168.7.10/23 dev T
    ip addr add 1:2:3:4:5::1/64 dev T
    ip addr add 1:2:3:4:5::1/63 dev T
    # RTNETLINK answers: File exists

    ip addr change 1:2:3:4:5::1/63 dev T
    ip addr show | grep 1:2:3:4:5::1
    # inet6 1:2:3:4:5::1/64 scope global

*sigh*

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-29 10:26:00 +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
Thomas Haller 9b7c28ebd2 macsec: merge branch 'qsn-macsec'
https://github.com/thom311/libnl/pull/100

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-27 21:42:08 +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
Sabrina Dubroca 6ecba6e440 import macsec uapi headers
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
2016-06-25 18:27:14 +02:00
Thomas Haller f087f3b50d link: merge branch 'qsn-io_compare' (#99)
https://github.com/thom311/libnl/pull/99

Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-25 17:53:03 +02:00
Sabrina Dubroca 89e7effa9a vxlan: properly handle LOOSE_COMPARISON in ->io_compare
This lets us match links only on the attributes that have actually been
set, instead of comparing all attributes.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-25 17:51:51 +02:00
Sabrina Dubroca 9702bb14ff pass flags through ->io_compare op
Currently rtnl_link_info_data_compare doesn't pass
flags (LOOSE_COMPARISON) to the ->io_compare op, so we cannot do a match
on only the attributes that are actually set in the filter object used
in a cache lookup via nl_cache_find().

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-25 17:51:45 +02:00
Thomas Haller a24319393c xfrm: merge branch 'xfrm/various-fixes'
http://lists.infradead.org/pipermail/libnl/2016-June/002138.html
2016-06-25 17:36:07 +02:00
Thomas Haller 49f612f188 xfrm: fix memleak in build_xfrm_sa_message() error-path
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-25 17:34:48 +02:00
Thomas Egerer 6db1547c0d xfrm: attach only one xfrm alg attribute to netlink message
The kernel only uses the xfrm alg auth attribute if the xfrm alg auth
truncated attribute is not present. Hence sending both attributes in one
message does not make sense.
This piece of code also removes the call to nla_reserve in favor of the
NLA_PUT macro.

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/002139.html
2016-06-25 17:31:38 +02:00
Thomas Egerer 01bd6ef7e0 xfrm: fix memory leak for encap original address
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/002141.html
2016-06-25 17:31:38 +02:00
Thomas Haller 0ee916bf6b xfrm: reuse encap data in xfrmnl_sa_set_encap_tmpl()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2016-06-25 17:31:24 +02:00
Thomas Egerer fa1076eaac xfrm: fix segfault when using encapsulation templates
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/002140.html
2016-06-25 17:21:58 +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
Thomas Haller c009b20919 xfrm: merge branch 'xfrm/buffer-overflows'
http://lists.infradead.org/pipermail/libnl/2016-May/002134.html
2016-06-25 13:55:59 +02:00