The header file added new values for IPSTATS_MIB_* and ICMP6_MIB_*, but
more importantly, the kernel broke user space API by reordering enum values in
IPSTATS_MIB_*. Add a workaround when parsing IFLA_PROTINFO trying to
be compatible with both older and newer kernels.
Note that this workaround might fail for some specific kernel versions by
assuming the old enum value mapping, although the kernel version already
contains the API change. In this case rtnl_link_get_stat() mixes up
values.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Thu, 20 Mar 2014 18:18:43 +0000 (19:18 +0100)]
route: detect missing cfgid in rtnl_link_inet_get_conf()
If the netlink message for IFLA_INET_CONF contains less then
IPV4_DEVCONF_MAX entires, the last entries in i_conf are unset.
Modify rtnl_link_inet_get_conf() to return -EINVAL when accessing
an unset cfgid.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Thu, 20 Mar 2014 18:18:42 +0000 (19:18 +0100)]
route: don't enforce minlen in inet6_parse_protinfo() (IFLA_PROTINFO) and inet_parse_af() (IFLA_AF_SPEC)
Older kernel version might have fewer values defined, so they would send
netlink messages that got rejected. Only check that at least one value
got sent.
This is especially grave as libnl uses an internal copy of the
kernel header files. Thus not only it is bound to the installed kernel
headers but to the libnl internal header copies that might easily be out
of sync with the kernel.
Cong Wang [Thu, 20 Mar 2014 17:24:12 +0000 (10:24 -0700)]
u32: add const to rtnl_u32_add_key_in*_addr()
Cc: Thomas Haller <thaller@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Cong Wang [Thu, 20 Mar 2014 17:45:45 +0000 (10:45 -0700)]
link: document sk == NULL case for rtnl_link_alloc_cache()
When sk == NULL, rtnl_link_alloc_cache() returns 0 but the cache
is still empty. We should document this behavior, otherwise it is confusing.
Cc: Thomas Haller <thaller@redhat.com> Cc: Thomas Graf <tgraf@suug.ch> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
This capability indicates that libnl does no longer overwrites
the route scope in rtnl_route_build_msg(), as fixed by commit 85ec9c7ad80c60f4f619472f2bb9d9595da93b26.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Cong Wang [Wed, 12 Mar 2014 23:42:39 +0000 (16:42 -0700)]
fill prio and protocol attr bits when parsing cls message
Otherwise, the filter we get from a cls cache can't be used
for removal.
Cc: Thomas Haller <thaller@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Thu, 13 Feb 2014 20:31:37 +0000 (21:31 +0100)]
route: rtnl_route_build_msg() should not overwrite the route scope
rtnl_route_build_msg() should allow the user to set the route scope
explicitly to RT_SCOPE_NOWHERE.
This is useful for IPv4 routes, because when deleting a route,
the kernel requires the scope to match, unless the scope is set to
RT_SCOPE_NOWHERE. Thus by setting the scope to RT_SCOPE_NOWHERE,
the user can delete a route, even without knowing its scope.
rtnl_route_build_msg() should only try to guess the scope, if it was
not explicitly specified.
Signed-off-by: Thomas Haller <thaller@redhat.com> Acked-by: Thomas Graf <tgraf@suug.ch>
Cong Wang [Wed, 15 Jan 2014 01:37:42 +0000 (17:37 -0800)]
act: remove rtnl_act_alloc_cache()
It is complicated to cache tc actions, they are different
from tc qdisc's and filters by design. So, it is simple
if we just don't cache them.
This patch only removes the tc action cache allocation API.
We still need to bypass the libnl cache layer from scratch,
but that would not break ABI any more, therefore we can do
it later.
Cc: Thomas Graf <tgraf@suug.ch> Cc: Thomas Haller <thaller@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Mon, 16 Dec 2013 20:19:14 +0000 (21:19 +0100)]
build: fix build failure when using different build dir (make distcheck)
`make distcheck` builds outside the source directory using
`../configure --srcdir=..`. This was broken because libnl.sym was
expected in the $(top_srcdir) instead of $(top_builddir).
Samuel Gauthier [Fri, 29 Nov 2013 08:28:44 +0000 (09:28 +0100)]
The commit 6a8d90f5fec4 "attr: Allow attribute type 0" intended to
allow the parsing of {netlink,packet,unix}_diag, even if they are
using type 0 for valid attributes.
It lacked this part in nla_parse.
Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
Thomas Graf [Thu, 28 Nov 2013 22:14:38 +0000 (23:14 +0100)]
attr: Allow attribute type 0
{netlink,packet,unix}_diag use attribute type 0 for valid
attributes. The value was reserved and usage was prohibited
by the protocol but we can't undo the breakge.
Make libnl accept attribute type 0 to allow parsing these
attributes.
Reported-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
Cong Wang [Fri, 8 Nov 2013 19:32:13 +0000 (11:32 -0800)]
do not compile some address families when not available
This fixes the following error while compiling libnl3 on CentOS5:
addr.c:1027: error: 'AF_RDS' undeclared here (not in a function)
addr.c:1033: error: 'AF_CAN' undeclared here (not in a function)
addr.c:1034: error: 'AF_TIPC' undeclared here (not in a function)
addr.c:1036: error: 'AF_IUCV' undeclared here (not in a function)
addr.c:1037: error: 'AF_RXRPC' undeclared here (not in a function)
addr.c:1038: error: 'AF_ISDN' undeclared here (not in a function)
addr.c:1039: error: 'AF_PHONET' undeclared here (not in a function)
make[2]: *** [addr.lo] Error 1
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
Nicolas PLANEL [Thu, 10 Oct 2013 20:51:38 +0000 (20:51 +0000)]
route/link: fixup link->l_af_ops must be set for some kind of links
Lookup on IFLA_INFO_KIND information to setup the right link->l_af_ops callbacks
For example, if you setup a bridge this is avoid to trig IS_BRIDGE_LINK_ASSERT() on rtnl_link_bridge_get_flags() call.
line=<optimized out>, function=<optimized out>) at assert.c:94
0x7ffff5dc39a0 "rtnl_link_bridge_get_flags") at assert.c:103
Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
Julien BERNARD [Tue, 8 Oct 2013 11:04:30 +0000 (13:04 +0200)]
nl-link-set: Add --state option
I modified the nl-link-set.c file to be able to set the interface up or
down. I joined the patch.
With the new nl-link-set binary I can set the tap interface down.
I am working with Ubuntu 12.04 LTS 64bits and the libnl and libnl-route
packages built from libnl3-3.2.3 from ubuntu reprositories.
Teto [Wed, 2 Oct 2013 20:18:31 +0000 (22:18 +0200)]
Fixed ObjIterator for python3, fixed output of _color and added missing parameter to nl_cache_resync
Here are a few things I fixed and that provoked a python error.
I canno't answer to this thread but one solution I found while using
the python binding is to iterate over all and filter via python
http://list-archives.org/2013/09/09/libnl-lists-infradead-org/missing-feature-for-retrieving-cached-
address-objects/f/5031600704
python: remove use of PyArg_ParseTuple() for callback result
The message receive callback handler in the netlink api processes
the result object from the python callback. It used PyArg_ParseTuple()
to get the value, but this does not work as intended (see ref [1]).
Instead check the type and convert it accordingly.
The property name used in __str__ should be local_port
instead of localPort to get rid of the AttributeError.
>>> str(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../netlink/core.py", line 172, in __str__
return 'nlsock<{0}>'.format(self.localPort)
AttributeError: 'Socket' object has no attribute 'localPort'
Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
python: allow callback function to be a class method
The callback functionality only worked for regular Python
functions. With this patch it also allows the callback
to be a class method (bounded or unbounded) as show in
example below.
class test_class(object):
def my_callback(self, msg, arg):
print('handling %s' % str(msg))
The initial commit adding netlink callback handling also introduced
memory leak issue. The python callback info was stored in an allocated
structure, but that was never freed.
Only exposing nl_cb_alloc() as is. nl_cb_get() is removed as it is
not very useful to use reference counting mechanism. Python uses
that itself internally. To deal properly with Python callback info
the function nl_cb_put() and nl_cb_clone() have a custom wrapper
taking care of Python reference counting.
This commit also adds a Callback python class using the netlink
callback functions.
Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
The application could use the same handler for multiple
nl_cb_type events. This patch stores the nl_cb_type in
the nl_cb struct during the callback. This allows the
application to obtain that information using the new
nl_cb_active_type() function. This way the callback
signature remains as is so existing applications are
not affected.
Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
netfilter/ct: support optional CTA_TIMESTAMP attribute
Recent kernels support conntrack time stamping, which is a helpful
feature to determine the duration of a flow without building a flow
cache in your user space application, just to keep the 'start' time of
your flow.
Timestamps are recorded with nanosecond resolution once this feature
is enabled.
This patch adds optional support for the CTA_TIMESTAMP, then
modifies the dump routine to write that info in a format similar
to /proc/net/nf_conntrack. This is an example output when using
NL_DUMP_LINE: