Thomas Haller [Mon, 24 Nov 2014 16:14:48 +0000 (17:14 +0100)]
idiag: deprecate IDIAG_ATTR_* enumeration
IDIAG_ATTR_* were a copy of the INET_DIAG_* extension kernel
flags. Redefining them is wrong, user space should continue
to use the values provided via the kernel headers.
Also they were misused as change flags (ce_mask), which they are not.
Deprecate the IDIAG_ATTR_* flags and redefine them to what the
originally are: INET_DIAG_*.
Also deprecated idiagnl_attrs2str() because there is already
idiagnl_exts2str(). idiagnl_attrs2str() in the sense of libnl change
flags (ce_mask) makes no sense.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Cong Wang [Mon, 27 Oct 2014 16:50:17 +0000 (09:50 -0700)]
idiag: add a copy of linux/sock_diag.h
When we test idiag on 3.4 kernel, we always get ERANGE.
This is because libnl has its own copy for SK_MEMINFO_*,
which is actually newer than 3.4, where SK_MEMINFO_VARS
is larger than kernel's.
We add a copy from latest kernel, so on older kernel
libnl should still compile. Note, for kernel < 3.6
we don't have SK_MEMINFO_BACKLOG, we have to relax
the minlen.
Cong Wang [Thu, 20 Nov 2014 20:26:01 +0000 (12:26 -0800)]
idiag: provide a hash function for idiag objects
Without ->oo_keygen, libnl will use linear search
for cache objects. This is extremely slow for idiag
when we have a lot of TCP connections. Provide a
hash function for idiag so that libnl will be able
to lookup a hashtable.
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>
The cache pickup does a check for duplicates for some time now.
However, the pickup in nl_cache_refill() explicitely clears the
cache, so the pickup doesn't need to actually do the dupe check,
as uniqueness is already guaranteed be Netlink subsystem.
And avoiding the dup check is beneficitial for performance
reasons, as the current algorithm is O(n^2).
Thomas Haller [Mon, 18 Aug 2014 13:24:30 +0000 (15:24 +0200)]
link: fix memory leaks due to repeated calls to .io_alloc()
All the io_alloc() implementation unconditionally allocated
new memory, thus leaking memory if called more then once.
Fix io_alloc() implementations not to allocate new memory
if not needed.
This happens for example in link_msg_parser() which first
calls rtnl_link_set_type():
#0 macvlan_alloc (link=0x609d50) at route/link/macvlan.c:56
#1 0x00007ffff7b99a78 in rtnl_link_set_type (link=link@entry=0x609d50, type=type@entry=0x609a94 "macvlan") at route/link.c:2233
#2 0x00007ffff7b99c28 in link_msg_parser (ops=<optimized out>, who=<optimized out>, n=<optimized out>, pp=0x7fffffffd870) at route/link.c:547
#3 0x00007ffff7dea109 in nl_cache_parse (ops=0x7ffff7dd8600 <rtnl_link_ops>, who=0x603338, nlh=0x6098a0, params=0x7fffffffd870) at cache.c:914
#4 0x00007ffff7dea15b in update_msg_parser (msg=<optimized out>, arg=<optimized out>) at cache.c:668
#5 0x00007ffff7def7bf in nl_cb_call (msg=<optimized out>, type=<optimized out>, cb=<optimized out>) at ../include/netlink-private/netlink.h:142
#6 recvmsgs (cb=0x6057a0, sk=0x6034c0) at nl.c:952
#7 nl_recvmsgs_report (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1003
#8 0x00007ffff7defb79 in nl_recvmsgs (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1027
#9 0x00007ffff7de9668 in __cache_pickup (sk=0x6034c0, cache=0x603510, param=param@entry=0x7fffffffd870) at cache.c:701
#10 0x00007ffff7dea08d in nl_cache_pickup (sk=<optimized out>, cache=<optimized out>) at cache.c:753
#11 0x0000000000400d56 in main ()
and later ops->io_parse():
#0 macvlan_alloc (link=0x609d50) at route/link/macvlan.c:56
#1 0x00007ffff7baae9d in macvlan_parse (link=0x609d50, data=<optimized out>, xstats=<optimized out>) at route/link/macvlan.c:79
#2 0x00007ffff7b99c80 in link_msg_parser (ops=<optimized out>, who=<optimized out>, n=<optimized out>, pp=0x7fffffffd870) at route/link.c:567
#3 0x00007ffff7dea109 in nl_cache_parse (ops=0x7ffff7dd8600 <rtnl_link_ops>, who=0x603338, nlh=0x6098a0, params=0x7fffffffd870) at cache.c:914
#4 0x00007ffff7dea15b in update_msg_parser (msg=<optimized out>, arg=<optimized out>) at cache.c:668
#5 0x00007ffff7def7bf in nl_cb_call (msg=<optimized out>, type=<optimized out>, cb=<optimized out>) at ../include/netlink-private/netlink.h:142
#6 recvmsgs (cb=0x6057a0, sk=0x6034c0) at nl.c:952
#7 nl_recvmsgs_report (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1003
#8 0x00007ffff7defb79 in nl_recvmsgs (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1027
#9 0x00007ffff7de9668 in __cache_pickup (sk=0x6034c0, cache=0x603510, param=param@entry=0x7fffffffd870) at cache.c:701
#10 0x00007ffff7dea08d in nl_cache_pickup (sk=<optimized out>, cache=<optimized out>) at cache.c:753
#11 0x0000000000400d56 in main ()
Thomas Haller [Wed, 24 Sep 2014 05:49:34 +0000 (07:49 +0200)]
build: move copy of linux headers to private directory
libnl3 contains a private copy of some kernel header files.
Normally, users are expected to install libnl and specify
-I$PREFIX/include/libnl3 as include path. As the private kernel
header files are not installed, this works fine.
However, it can be convenient to build against the libnl source
directory, without installing libnl. In this case, the private kernel
header files shaddow the system provided ones. This is undesired.
Move these files to a different directory to avoid this clash.
Nicolas PLANEL [Tue, 26 Aug 2014 15:43:49 +0000 (11:43 -0400)]
cls: check data before memcpy() it
[thaller@redhat.com: I modified the condition "if (data && len)"
in the original patch to just check "len > 0".
Note that all call sites of meta_alloc() make sure to pass a
valid data pointer with a non-zero length (anything else would
be a bug). But indeed, calling memcpy with invalid src pointer
is undefined behavior, even if len is zero.]
Thomas Graf [Mon, 25 Aug 2014 23:09:08 +0000 (01:09 +0200)]
nf: nfnl_*_str2copy_mode() should return int
... to be able to return a negative error code for unknown modes.
[thaller@redhat.com: This is potentially an ABI break, but since
the size of the enum is implementation defined, it seems
anyway unstable to have them as function arguments/return values.]
Thomas Graf [Tue, 26 Aug 2014 00:08:21 +0000 (02:08 +0200)]
build: Add continuous integration support via travis-ci
This allows any libnl github repo to link to travis-ci which
will result in new commits and pull requests to be automatically
built with both gcc and clang. Any build failures including the
addition of warnings are reported to the author and committer.
Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Cong Wang [Mon, 28 Jul 2014 22:21:01 +0000 (15:21 -0700)]
qdisc: add hfsc qdisc support
Cc: Thomas Graf <tgraf@suug.ch> 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 [Mon, 28 Jul 2014 22:21:00 +0000 (15:21 -0700)]
tc: save error code for rtnl_tc_data_check()
Cc: Thomas Graf <tgraf@suug.ch> 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 [Sat, 26 Jul 2014 13:07:00 +0000 (15:07 +0200)]
style: add .indent.pro file for GNU indent
This is somewhat an approximation of the coding style
in libnl3. In the end, it does not work overly well,
but I think it will be useful to cherry-pick some automatic
style fixes.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Cong Wang [Mon, 21 Jul 2014 19:27:32 +0000 (12:27 -0700)]
link: add ifb device support
Cc: Thomas Graf <tgraf@suug.ch> 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 [Mon, 21 Jul 2014 17:44:45 +0000 (10:44 -0700)]
xfrm: use the right specifier for uint64_t
This fixes compile warnings like this:
xfrm/sp.c: In function 'xfrm_sp_dump_line':
xfrm/sp.c:346:3: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'uint64_t' [-Wformat=]
sprintf (dir, "%llu", sp->lft->soft_byte_limit);
Cc: Thomas Haller <thaller@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
Cong Wang [Sat, 12 Jul 2014 00:19:03 +0000 (17:19 -0700)]
tc: add co_groups for tc qdisc and filter
Otherwise these tc caches would not be able to be updated
asynchronously.
Cc: Thomas Haller <thaller@redhat.com> Cc: Thomas Graf <tgraf@suug.ch> 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 [Wed, 25 Jun 2014 08:11:56 +0000 (10:11 +0200)]
attr: nla_get_u64() should return 0 if the attribute does not fully contain 64 bit
Manually "inline" nla_memcpy() to nla_get_u64() and change the behavior
to return always zero (0) if the attribute does not contain at least
sizeof(uint64_t) bytes. Considering endianness, reading a truncated integer
does not seem to be useful and should result in a defined behavior
instead.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Peter Wu [Tue, 24 Jun 2014 21:13:38 +0000 (23:13 +0200)]
attr: fix compile warning in headers
strlen() returns a size_t type, but nla_put accepts an int only. This
breaks a -Werror build of applications using libnl, so avoid this
warning by explicitly casting the length to an int.
Signed-off-by: Peter Wu <peter@lekensteyn.nl> Signed-off-by: Thomas Haller <thaller@redhat.com>
Tobias Klauser [Tue, 17 Jun 2014 12:58:10 +0000 (14:58 +0200)]
cache_mngr: Fix assignment of error code in nl_cache_mngr_alloc()
In the current form, the parentheses in these two if (...) statements
lead to err being assigned the result of nl_connect(...) < 0 and
nl_socket_set_nonblocking(...) < 0 instead of the return value of these
functions. Adjust the parentheses to assign the returned error code to
err.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Tobias Klauser [Tue, 17 Jun 2014 12:58:09 +0000 (14:58 +0200)]
cache_mngr: Return proper error code if nl_socket_alloc() fails
If nl_socket_alloc() failes in nl_cache_mngr_alloc() we would currently
return 0 due to the previous assignment of the err variable, even though
the failed allocation is an error condition. Fix this by setting err to
-NLE_NOMEM if nl_socket_alloc() fails.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Tue, 10 Jun 2014 15:50:09 +0000 (17:50 +0200)]
route/link: fix dangling pointer after rtnl_link_get_ifalias(link, NULL)
Fixed bug that left a dangling pointer after clearing the ifalias
property. This happened when calling 'rtnl_link_get_ifalias(link, NULL)'
on a link that has already an ifalias set.
This can cause a crash and/or a double-free.
Error found by coverity.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Tue, 10 Jun 2014 15:53:37 +0000 (17:53 +0200)]
lib: reorder free() after printf("%p") statements
Previously coverity was complaining about a use-after-free.
This was not a real problem, because the printf statement
does not dereferenciate the pointer. Change it to avoid
the warning.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Thomas Haller [Tue, 10 Jun 2014 16:20:25 +0000 (18:20 +0200)]
route/link: pass proper type to sizeof() for calloc() in vlan_parse()
This fixes the following coverity warning:
lib/route/link/vlan.c:148:23:warning – Result of 'calloc' is converted to a pointer of type 'struct vlan_map', which is incompatible with sizeof operand type 'struct ifla_vlan_qos_mapping'
This was not a real problem, because the types are effectively
the same.
Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>