]> granicus.if.org Git - libnl/log
libnl
11 years agonetfilter/ct: support optional CTA_ZONE attribute
Holger Eitzenberger [Fri, 30 Aug 2013 08:50:23 +0000 (10:50 +0200)]
netfilter/ct: support optional CTA_ZONE attribute

Newer kernels support conntrack zones, which help to partition the
conntrack table into virtual conntrack tables.

This patch is for adding support for the optional attribute, adds
setters and getters, and adds support for the zone ID in the conntrack
dumper.

An example entry in NL_DUMP_LINE format looks like:

  tcp SYN_SENT 10.128.128.99:43354 <-> 10.128.129.20:22 zone 1

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonetfilter/ct: support optional CTA_TIMESTAMP attribute
Holger Eitzenberger [Fri, 30 Aug 2013 08:50:22 +0000 (10:50 +0200)]
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:

  udp 10.128.128.28:56836 <-> 10.128.129.255:8612 delta-time 30

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoCall to_msg_fill_raw when defined to_msg_fill is NULL
chantra [Mon, 19 Aug 2013 07:16:45 +0000 (00:16 -0700)]
Call to_msg_fill_raw when defined to_msg_fill is NULL

netem qdisc uses to_msg_fill_raw to build netlink packet. So far, this
was not called from anywhere.

Example creating a netem qdisc before and after the change:

[root@testbox libnl]# NLCB=debug ./netem
-- Debug: Sent Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 48
    .type = 36 <route/qdisc::new>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376894544
    .port = 17877
  [PAYLOAD] 20 octets
    00 00 00 00 02 00 00 00 00 00 01 80 01 00 01 00 ................
    00 00 00 00                                     ....
  [ATTR 01] 6 octets
    6e 65 74 65 6d 00                               netem.
  [PADDING] 2 octets
    00 00                                           ..
---------------------------  END NETLINK MESSAGE ---------------------------
-- Debug: Received Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 68
    .type = 2 <ERROR>
    .flags = 0 <>
    .seq = 1376894544
    .port = 17877
  [ERRORMSG] 20 octets
    .error = -22 "Invalid argument"
  [ORIGINAL MESSAGE] 16 octets
    .nlmsg_len = 16
    .type = 36 <0x24>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376894544
    .port = 17877
---------------------------  END NETLINK MESSAGE ---------------------------
-- Error received: Invalid argument
-- Original message: type=0x24 length=48 flags=<REQUEST,ACK,ATOMIC>
sequence-nr=1376894544 pid=17877
RC -7
[root@testbox libnl]# NLCB=debug ./netem
-- Debug: Sent Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 76
    .type = 36 <route/qdisc::new>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376895147
    .port = 26541
  [PAYLOAD] 20 octets
    00 00 00 00 02 00 00 00 00 00 01 80 01 00 01 00 ................
    00 00 00 00                                     ....
  [ATTR 01] 6 octets
    6e 65 74 65 6d 00                               netem.
  [PADDING] 2 octets
    00 00                                           ..
  [ATTR 02] 24 octets
    00 00 00 00 a0 86 01 00 00 00 00 80 00 00 00 00 ................
    00 00 00 00 00 00 00 00                         ........
---------------------------  END NETLINK MESSAGE ---------------------------
-- Debug: Received Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 36
    .type = 2 <ERROR>
    .flags = 0 <>
    .seq = 1376895147
    .port = 26541
  [ERRORMSG] 20 octets
    .error = 0 "Success"
  [ORIGINAL MESSAGE] 16 octets
    .nlmsg_len = 16
    .type = 36 <0x24>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376895147
    .port = 26541
---------------------------  END NETLINK MESSAGE  ---------------------------
RC 0
[root@testbox libnl]# tc qdisc show
qdisc htb 1: dev eth0 root refcnt 2 r2q 10 default 0 direct_packets_stat 21115
qdisc netem 8001: dev eth0 parent 1:1 limit 100000 loss 50%
qdisc htb 1: dev eth1 root refcnt 2 r2q 10 default 0 direct_packets_stat 0

Signed-off-by: chantra <chantra@fb.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoPriority of the '<' operator is higher than that of the '=' operator
maksqwe [Fri, 23 Aug 2013 10:39:03 +0000 (13:39 +0300)]
Priority of the '<' operator is higher than that of the '=' operator

Signed-off-by: maksqwe <maksqwe1@ukr.net>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agofix double free caused by freeing link af_data in rtnl_link_set_family()
Jiri Pirko [Wed, 21 Aug 2013 12:40:34 +0000 (14:40 +0200)]
fix double free caused by freeing link af_data in rtnl_link_set_family()

Introduced by commit 8026fe2e3a9089eff3f5a06ee6e3cc78d96334ed ("link:
Free and realloc af specific data upon rtnl_link_set_family()")

link->l_af_data[link->l_af_ops->ao_family] is freed here but not set to
zero. That leads to double free made by link_free_data->do_foreach_af.

Fix this by setting link->l_af_data[link->l_af_ops->ao_family] to zero
rigth after free.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoEnable linker versioning
Thomas Graf [Wed, 7 Aug 2013 12:51:03 +0000 (14:51 +0200)]
Enable linker versioning

Reported-by: Ian Stakenvicius
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoMerge pull request #44 from sassanosystems/idiag
Thomas Graf [Mon, 5 Aug 2013 06:10:42 +0000 (23:10 -0700)]
Merge pull request #44 from sassanosystems/idiag

Idiag

11 years agolink: add support for IFLA_PHYS_PORT_ID
Jiri Pirko [Thu, 1 Aug 2013 11:57:08 +0000 (13:57 +0200)]
link: add support for IFLA_PHYS_PORT_ID

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoMerge pull request #45 from chibacchie/vxlan
Thomas Graf [Mon, 5 Aug 2013 06:06:19 +0000 (23:06 -0700)]
Merge pull request #45 from chibacchie/vxlan

Add VXLAN support

11 years agoAdd VXLAN support.
Yasunobu Chiba [Sun, 4 Aug 2013 06:43:54 +0000 (15:43 +0900)]
Add VXLAN support.

11 years agoMore safely parse vegas info and mem info.
Joe Damato [Fri, 26 Jul 2013 00:07:12 +0000 (17:07 -0700)]
More safely parse vegas info and mem info.

11 years agoAdd idiag-socket-details
Joe Damato [Thu, 25 Jul 2013 23:36:16 +0000 (16:36 -0700)]
Add idiag-socket-details

This small program lists all sockets on the system seen by netlink and serves
as a simple example showing how to alloc an idiag msg cache and dump the
objects in it.

11 years agoHandle the case where nl_msec2str is passed 0 msecs
Joe Damato [Fri, 19 Jul 2013 05:35:45 +0000 (22:35 -0700)]
Handle the case where nl_msec2str is passed 0 msecs

11 years agoAdd support for inet diag Netlink protocol.
Joe Damato [Thu, 4 Jul 2013 01:40:58 +0000 (18:40 -0700)]
Add support for inet diag Netlink protocol.

- Inet diag allows users to gather low-level socket information.
- This library provides a higher-level API for creating inetdiag requests (via
  idiagnl_connect and idiagnl_send_simple) and parsing the replies (via
  idiagnl_msg_parse). A cache is also provided (via idiagnl_msg_alloc_cache).
- Request and message objects provide APIs for accessing and setting the
  various properties of each.
- This library also allows the user to parse the inetdiag response attributes
  which contain information about traffic class, TOS, congestion, socket
  memory info, and more depending on the kernel version used.
- Includes doxygen documentation.

11 years agoadd generic netlink functions to swig
Arend van Spriel [Mon, 15 Jul 2013 10:09:13 +0000 (12:09 +0200)]
add generic netlink functions to swig

Provide wrapper function for generic netlink library functions. The
genlmsg_parse() function is handled similar to nla_parse_nested() so
it returns tuple with error code and dictionary of parsed attributes.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoadd python module for generic netlink library
Arend van Spriel [Mon, 15 Jul 2013 10:09:12 +0000 (12:09 +0200)]
add python module for generic netlink library

This commit adds creation of the netlink.genl package. The actual
capi.i will be filled in upcoming commits so the module is rather
dumb for now.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoadd support functions for attributes and callback handlers
Arend van Spriel [Mon, 15 Jul 2013 10:09:11 +0000 (12:09 +0200)]
add support functions for attributes and callback handlers

added support functions to access the netlink attributes and use
custom callback handlers. Most is wrapped as is, but there are
a couple of special cases handled.

1) void *nla_data(struct nlattr *);
The return value is changed to a Python byte array so it includes
the lenght of the data stream.

2) int nla_parse_nested(...);
This returns a tuple (err, dict). 'err' is the error code and 'dict'
is a dictionary with attribute identifier as key and value represents
a struct nlattr object.

3) macro nla_for_each_nested()
Provide nla_get_nested() which returns a Python list of struct nlattr
objects that is iterable.

4) allocate struct nla_policy array
Provide nla_policy_array() function that allocates consecutive space
in memory for struct nla_policy array entries. Each entry is put in
a Python list so the entry fields can be modified in Python. This
array object can be passed to the nla_parse_nested() function.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agohandle the case where 0 is passed to nl_size2str
Joe Damato [Sun, 7 Jul 2013 19:12:27 +0000 (12:12 -0700)]
handle the case where 0 is passed to nl_size2str

(cherry picked from commit 968ccbe97d476e3a8485b04dbaf469e8d01b8811)
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agocache: Return -NLE_PROTO_MISMATCH if socket provided mismatches cache protocol
Thomas Graf [Sat, 29 Jun 2013 20:29:43 +0000 (22:29 +0200)]
cache: Return -NLE_PROTO_MISMATCH if socket provided mismatches cache protocol

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agosocket: Warn via debug message if local port namespace is exhausted
Thomas Graf [Fri, 28 Jun 2013 16:53:16 +0000 (18:53 +0200)]
socket: Warn via debug message if local port namespace is exhausted

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agotests: use AM_CFLAGS instead of CFLAGS directly
Thomas Graf [Fri, 28 Jun 2013 16:49:51 +0000 (18:49 +0200)]
tests: use AM_CFLAGS instead of CFLAGS directly

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agomsg: Avoid returning a negative value for nlmsg_attrlen()
Thomas Graf [Thu, 27 Jun 2013 16:29:17 +0000 (18:29 +0200)]
msg: Avoid returning a negative value for nlmsg_attrlen()

If a hdrlen was provided that was greather than the actual
message length, a negative attributes length would result.

This was typically happening for RTM_GETLINK requests where
we can get a away with a 4 bytes header on the request side
but the response would use a 16 bytes header.

This resulted in strange -8 bytes leftover debug messages.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonetfilter/queue: introduce nfnl_queue_msg_send_verdict_batch()
Holger Eitzenberger [Wed, 19 Jun 2013 13:23:15 +0000 (15:23 +0200)]
netfilter/queue: introduce nfnl_queue_msg_send_verdict_batch()

The batched verdict implicitely ACKs all queue packet IDs up to the
one send back, which reduces the number of verdict messages send
to the kernel.

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonetfilter/queue: generalize nfnl_queue_msg_build_verdict()
Holger Eitzenberger [Wed, 19 Jun 2013 13:23:14 +0000 (15:23 +0200)]
netfilter/queue: generalize nfnl_queue_msg_build_verdict()

Generalize netfilter/queue to allow sending batched verdicts
later.

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoHandle -NLE_AGAIN in nl_cache_mngr_data_ready
Andrew Collins [Mon, 17 Jun 2013 21:58:43 +0000 (15:58 -0600)]
Handle -NLE_AGAIN in nl_cache_mngr_data_ready

Since commit "nl: Return -NLE_AGAIN if non-blocking socket would block",
nl_cache_mngr_data_ready returns -NLE_AGAIN to callers on non-blocking sockets.
Change it to consider -NLE_AGAIN as a non-error case as it is expected behavior
with the nl_recv changes.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoDefault to comparing all attributes if no oo_id_attrs defined
Andrew Collins [Mon, 17 Jun 2013 21:24:05 +0000 (15:24 -0600)]
Default to comparing all attributes if no oo_id_attrs defined

Since commit: "cache pickup: Avoid duplicates during cache pickup",
nfnl_ct_alloc_cache no longer properly fills the cache, as it doesn't
define oo_id_attrs so all items are considered duplicates.

Instead of adding a ~0 oo_id_attrs to ct_obj, this changes
nl_object_identical to default to comparing all attributes if
neither oo_id_attrs_get or oo_id_attrs are provided.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoMerge branch 'master' of https://github.com/michael-dev/libnl
Thomas Graf [Fri, 24 May 2013 12:37:02 +0000 (14:37 +0200)]
Merge branch 'master' of https://github.com/michael-dev/libnl

11 years agoAdd macvlan support
Michael Braun [Thu, 16 May 2013 14:54:13 +0000 (16:54 +0200)]
Add macvlan support

This patch add support for kernel macvlan interfaces.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
11 years ago3.2.22 release libnl3_2_22
Thomas Graf [Tue, 14 May 2013 12:09:07 +0000 (14:09 +0200)]
3.2.22 release

11 years agonl: Increase receive buffer size to 4 pages
Thomas Graf [Wed, 8 May 2013 11:52:27 +0000 (13:52 +0200)]
nl: Increase receive buffer size to 4 pages

Assuming that the kernel does not send more than a page is no longer valid,
and enabling MSG_PEEK'ing by default to figure out the exact message buffer
requirements can have a negative influence on the performance of existing
applications. Bumping the default receive buffer space to 4 pages seems
a sane default.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agortnl_link_af_unregister: fix locking
Nathan Lynch [Mon, 29 Apr 2013 21:29:46 +0000 (16:29 -0500)]
rtnl_link_af_unregister: fix locking

rtnl_link_af_unregister() attempts to write-lock info_lock twice
instead of releasing it before returning.  It also will return with
info_lock write-locked if passed a NULL ops.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoPrepare for 3.2.22-rc1 release libnl3_2_22rc1
Thomas Graf [Sun, 28 Apr 2013 10:52:26 +0000 (12:52 +0200)]
Prepare for 3.2.22-rc1 release

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agotests: Include util.h in dist
Thomas Graf [Sun, 28 Apr 2013 10:51:58 +0000 (12:51 +0200)]
tests: Include util.h in dist

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agotests: Add basic attribute unit tests
Thomas Graf [Sun, 28 Apr 2013 10:31:52 +0000 (12:31 +0200)]
tests: Add basic attribute unit tests

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoconfigure: Convert ENABLE_UNIT_TESTS to a mere AM conditional
Thomas Graf [Sun, 28 Apr 2013 09:41:15 +0000 (11:41 +0200)]
configure: Convert ENABLE_UNIT_TESTS to a mere AM conditional

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoWrong calcultation in nla_reserve
Emmanuel Thierry [Wed, 24 Apr 2013 16:39:19 +0000 (18:39 +0200)]
Wrong calcultation in nla_reserve

There seams to be an error in the calculation of needed space for the message in nla_reserve. The current size of the message is counted twice: Once in NLMSG_ALIGN, once in the condition below.
This causes nla_put_* calls to be rejected if the allocation size of the message has been strictly calculated by the caller.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoattr: Fix typo in nla_is_nested()
Thomas Graf [Sun, 28 Apr 2013 08:33:52 +0000 (10:33 +0200)]
attr: Fix typo in nla_is_nested()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoMerge branch 'fixes' of https://github.com/socketpair/libnl
Thomas Graf [Sun, 28 Apr 2013 08:25:47 +0000 (10:25 +0200)]
Merge branch 'fixes' of https://github.com/socketpair/libnl

11 years agoattr: nla_is_nested() must access nla_type directly
Thomas Graf [Sun, 28 Apr 2013 08:23:28 +0000 (10:23 +0200)]
attr: nla_is_nested() must access nla_type directly

Can't used nla_type() as it applies NLA_TYPE_MASK first

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoFix leak of cb if nl_socket_alloc_cb() failed to allocate socket
Коренберг Марк (дома) [Sat, 27 Apr 2013 18:35:37 +0000 (00:35 +0600)]
Fix leak of cb if nl_socket_alloc_cb() failed to allocate socket

- each *_get() should have corresponding *_put(). That rule was broken in nl_socket_alloc()
- Also, check if cb is NULL in nl_socket_set_cb (calls BUG())

11 years agotests: Make unit test building optional
Thomas Graf [Sat, 27 Apr 2013 12:27:10 +0000 (14:27 +0200)]
tests: Make unit test building optional

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agodump_attrs: "NLA_F_NESTED" => nla_is_nested(nla)
Коренберг Марк (дома) [Fri, 26 Apr 2013 17:50:54 +0000 (23:50 +0600)]
dump_attrs: "NLA_F_NESTED"  => nla_is_nested(nla)

11 years agoautoconf: Use PKG_CHECK_MODULES() instead of AM_PATH_CHECK()
Thomas Graf [Fri, 5 Apr 2013 08:44:06 +0000 (10:44 +0200)]
autoconf: Use PKG_CHECK_MODULES() instead of AM_PATH_CHECK()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoaddr: only translate more recent address family names and ARP types if defined
Thomas Graf [Fri, 5 Apr 2013 08:37:55 +0000 (10:37 +0200)]
addr: only translate more recent address family names and ARP types if defined

Helps making libnl compilable with older kernel headers

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoPerform no operation on nl_object_free(NULL).
Emmanuel Roullit [Wed, 3 Apr 2013 19:07:32 +0000 (21:07 +0200)]
Perform no operation on nl_object_free(NULL).

Passing a NULL pointer would cause a NULL pointer dereference within
nl_object_free().
Returning early on NULL pointer is the behavior free(3) and other
nl*_free() functions.

Signed-off-by: Emmanuel Roullit <emmanuel.roullit@gmail.com>
11 years agomsg: Pretty print generic netlink header in nl_msg_dump()
Thomas Graf [Tue, 2 Apr 2013 21:13:15 +0000 (23:13 +0200)]
msg: Pretty print generic netlink header in nl_msg_dump()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonl: Return -NLE_AGAIN if non-blocking socket would block
Thomas Graf [Tue, 2 Apr 2013 09:58:18 +0000 (11:58 +0200)]
nl: Return -NLE_AGAIN if non-blocking socket would block

Previously 0 was returned which gave the caller no chance of detecting
when a non-blocking socket would block. If a caller intends to never
see an error message it should utilize poll()/select() to only read
when the socket has pending data or information.

Reported-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agogenl: Fix cb reference leak in genl_ctrl_probe_by_name()
Thomas Graf [Tue, 2 Apr 2013 09:51:53 +0000 (11:51 +0200)]
genl: Fix cb reference leak in genl_ctrl_probe_by_name()

nl_socket_get_cb() bumps the cb reference counter

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoct: add ICMPv6 type,code and ID
Holger Eitzenberger [Sun, 31 Mar 2013 19:16:21 +0000 (21:16 +0200)]
ct: add ICMPv6 type,code and ID

Add ICMPv6 type, code and ID (if set) by using the already available
conntrack atttributes.

Currently the ICMPv6 conntrack objects in libnl are without type, code
and ID.  This e. g. is the output of nl_object_dump() without the patch:

  ipv6-icmp ::1 <-> ::1
  id 0xdd0871f0 family inet6 timeout 30s <NOREPLY,SNAT_INIT,DNAT_INIT>

The attached patch tries to solve that.  It then looks like

  ipv6-icmp ::1 <-> ::1 icmp type 128 code 0 id 28253
  id 0xdf3a11f0 family inet6 timeout 30s <SNAT_INIT,DNAT_INIT>

It is the 'small' approach, because it reuses the existing ICMP
attributes of the conntrack object (currently only used for IPv4).
This way I can avoid to add new _icmp6_get_, _icmp6_set_ and
_icmp6_test_ functions.

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonl: Print file:line:func in debugging messages and provide --disable-debug to disable...
Thomas Graf [Tue, 2 Apr 2013 09:39:30 +0000 (11:39 +0200)]
nl: Print file:line:func in debugging messages and provide --disable-debug to disable debugging

Compiling libnl with --disable-debug will result in the ignorance
of the 'NLDBG' environment variable.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agocache: Improve debugging messages of cache operations
Thomas Graf [Mon, 1 Apr 2013 09:46:30 +0000 (11:46 +0200)]
cache: Improve debugging messages of cache operations

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agogenl: Update mt_id of cache ops when resolving genl id
Thomas Graf [Mon, 1 Apr 2013 09:16:34 +0000 (11:16 +0200)]
genl: Update mt_id of cache ops when resolving genl id

The cache layer uses the message type array stored in the cache
ops to lookup which cache a message belongs to. Update to the
the message array with the resolved generic netlink id to make
it compatible with the caching API.

Allows to use nl_cache_refill() and others for generic netlink
based caches with dynamic generic netlink ids.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agogenl: Provide internal function to resolve name to id
Thomas Graf [Mon, 1 Apr 2013 09:14:49 +0000 (11:14 +0200)]
genl: Provide internal function to resolve name to id

Like genl_ops_resolve() but uses its own socket.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonl-route-add: Add NLM_F_EXCL flag to route add
roopa [Sun, 24 Mar 2013 00:42:59 +0000 (17:42 -0700)]
nl-route-add: Add NLM_F_EXCL flag to route add

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoRemove rtnl_link_free() declaration from the header file.
Tony Cheneau [Sat, 16 Mar 2013 04:23:18 +0000 (00:23 -0400)]
Remove rtnl_link_free() declaration from the header file.

Reason: there is no rtnl_link_free() definition anywhere in the code.

Signed-off-by: Tony Cheneau <tony.cheneau@amnesiak.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoRemove superfluous declaration of rtnl_route_put()
Tony Cheneau [Sat, 16 Mar 2013 04:23:19 +0000 (00:23 -0400)]
Remove superfluous declaration of rtnl_route_put()

rtnl_route_put() is declared twice in the same header file

Signed-off-by: Tony Cheneau <tony.cheneau@amnesiak.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agortnl-addr: Fix invalid call to nl_addr_set_prefixlen() if neither local or peer addre...
Thomas Graf [Thu, 14 Mar 2013 17:57:15 +0000 (18:57 +0100)]
rtnl-addr: Fix invalid call to nl_addr_set_prefixlen() if neither local or peer address are present

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agortnl-addr: Inherit prefix length to nl_addr objs in rtnl_addr_set_prefixlen()
Thomas Graf [Thu, 14 Mar 2013 17:52:17 +0000 (18:52 +0100)]
rtnl-addr: Inherit prefix length to nl_addr objs in rtnl_addr_set_prefixlen()

Previously if using rtnl_addr_set_prefixlen() the new prefix length
was not forwarded to the corresponding 'struct nl_addr' objects
associated with address already and thus the comparison function
would fail.

This patch also clears the internal ADDR_ATTR_PREFIXLEN flag if
the prefix length has been reset.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agotests: Add check based unit test system
Thomas Graf [Thu, 14 Mar 2013 15:25:17 +0000 (16:25 +0100)]
tests: Add check based unit test system

Introduces new unit tests based on `check`. Each subsystem/module can
have its own unit tests in tests/check-<name>.c that will be linked
together in tests/check-all.c.

Running 'make check' will compile and run the unit tests automatically.

A reference unit test implementation has been done for the abstract
address module.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoaddr: Update to latest address familiy definition for translation
Thomas Graf [Thu, 14 Mar 2013 15:09:19 +0000 (16:09 +0100)]
addr: Update to latest address familiy definition for translation

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoaddr: improve API reference documentation for nl_addr_*()
Thomas Graf [Thu, 14 Mar 2013 14:37:46 +0000 (15:37 +0100)]
addr: improve API reference documentation for nl_addr_*()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoaddr: Reset unused portion of binary address in nl_addr_set_binary_addr()
Thomas Graf [Thu, 14 Mar 2013 13:41:12 +0000 (14:41 +0100)]
addr: Reset unused portion of binary address in nl_addr_set_binary_addr()

memset() the binary address before overwriting it with new data
to avoid leaving around old portions of the address.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agomsg: Pretty print error message header even if incomplete
Thomas Graf [Wed, 13 Mar 2013 16:44:47 +0000 (17:44 +0100)]
msg: Pretty print error message header even if incomplete

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agomsg: Pretty print padding attributes in nl_msg_dump()
Thomas Graf [Wed, 13 Mar 2013 16:28:07 +0000 (17:28 +0100)]
msg: Pretty print padding attributes in nl_msg_dump()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoattr: Warn application if nla_parse() observes same attribute multiple times
Thomas Graf [Wed, 13 Mar 2013 16:12:03 +0000 (17:12 +0100)]
attr: Warn application if nla_parse() observes same attribute multiple times

Use a debugging message to warn applications if an attribute is
found multiple times in the same message. It is perfectly valid
to rely on this behaviour but it is likely to indicate a bug.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoattr: No longer warn about attribute of type 0
Thomas Graf [Wed, 13 Mar 2013 16:07:01 +0000 (17:07 +0100)]
attr: No longer warn about attribute of type 0

The kernel will start using type 0 attributes for padding purposes.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoattr: Do not enforce maximum length for NLA_FLAG attributes
Thomas Graf [Wed, 13 Mar 2013 16:01:54 +0000 (17:01 +0100)]
attr: Do not enforce maximum length for NLA_FLAG attributes

Although wasteful, NLA_FLAG with non zero payload cause no harm
and should thus not be rejected.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoattr: Add nla_nest_cancel() to remove partially added nested attributes
Thomas Graf [Wed, 13 Mar 2013 15:53:07 +0000 (16:53 +0100)]
attr: Add nla_nest_cancel() to remove partially added nested attributes

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoUse thread-safe strerror_r() instead of strerror()
Thomas Graf [Thu, 28 Feb 2013 12:07:04 +0000 (13:07 +0100)]
Use thread-safe strerror_r() instead of strerror()

We have only ever fed well known error codes into strerror()
so it should never have been a problem though.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: Fix rtnl_link_af_data_compare return value
roopa [Fri, 15 Feb 2013 18:26:30 +0000 (10:26 -0800)]
link: Fix rtnl_link_af_data_compare return value

This patch fixes a bug where because of the af_ops check
being first in the function, we were returning ~0 if af_ops
was null even if both objects really did not have af_data
and we should be returning 0.

Its better to have the af_data present check before anything else.

So, Rearranged some of the code in rtnl_link_af_data_compare.
Changes include:
- Do the attribute present check before anything else
- If ao_compare op not present, return ~0

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com>
Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: move af_data_compare to the end
roopa [Fri, 15 Feb 2013 18:26:29 +0000 (10:26 -0800)]
link: move af_data_compare to the end

In the current code if rtnl_link_af_data_compare returns value > 0
we mark PROTINFO attribute in the diff mask and return without
comparing flags.

This patch makes af_data to be the last thing we compare.

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com>
Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agobond: Provide rtnl_link_bond_alloc()
Thomas Graf [Thu, 14 Feb 2013 11:48:00 +0000 (12:48 +0100)]
bond: Provide rtnl_link_bond_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agovlan: Provide rtnl_link_vlan_alloc()
Thomas Graf [Thu, 14 Feb 2013 11:42:07 +0000 (12:42 +0100)]
vlan: Provide rtnl_link_vlan_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonetlink: Forward declare frequent libnl types to ease inclusion deps
Thomas Graf [Thu, 14 Feb 2013 11:37:10 +0000 (12:37 +0100)]
netlink: Forward declare frequent libnl types to ease inclusion deps

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agobridge: Provide rtnl_link_bridge_alloc()
Thomas Graf [Thu, 14 Feb 2013 11:34:57 +0000 (12:34 +0100)]
bridge: Provide rtnl_link_bridge_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agobridge: Support the new bridging attributes
Thomas Graf [Tue, 5 Feb 2013 21:41:26 +0000 (22:41 +0100)]
bridge: Support the new bridging attributes

This provides support for the new bridging attributes provided
in IFLA_PROTINFO while maintaining backwards compatibility
with older kernels.

A set of new API functions are exported to access the bridging
information. rtnl_link_bridge_has_ext_info() can be used to
check whether a bridge object has been constructed based on
the newly available attributes or the old message format.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoattr: Provide nla_is_nested() function
Thomas Graf [Tue, 5 Feb 2013 21:31:31 +0000 (22:31 +0100)]
attr: Provide nla_is_nested() function

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: Free and realloc af specific data upon rtnl_link_set_family()
Thomas Graf [Tue, 5 Feb 2013 12:52:22 +0000 (13:52 +0100)]
link: Free and realloc af specific data upon rtnl_link_set_family()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: Hold af_ops reference for each AF_SPEC block during lifetime of link object
Thomas Graf [Tue, 5 Feb 2013 12:46:42 +0000 (13:46 +0100)]
link: Hold af_ops reference for each AF_SPEC block during lifetime of link object

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: Modify link policy on the stack
Thomas Graf [Tue, 5 Feb 2013 12:21:10 +0000 (13:21 +0100)]
link: Modify link policy on the stack

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: Keep reference to af_ops during lifetime of link object
Thomas Graf [Tue, 5 Feb 2013 12:18:25 +0000 (13:18 +0100)]
link: Keep reference to af_ops during lifetime of link object

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agolink: Fix af_ops leak on ENOMEM
Thomas Graf [Tue, 5 Feb 2013 12:03:02 +0000 (13:03 +0100)]
link: Fix af_ops leak on ENOMEM

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agocan: Fix nested message creation in can_put_attrs()
Holger Dengler [Fri, 1 Feb 2013 10:56:47 +0000 (11:56 +0100)]
can: Fix nested message creation in can_put_attrs()

Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
Signed-off-by: Holger Dengler <dengler@linutronix.de>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agocan: Include "linux/can/netlink.h" in the distribution
Thomas Graf [Fri, 1 Feb 2013 09:51:33 +0000 (10:51 +0100)]
can: Include "linux/can/netlink.h" in the distribution

Needed to compile if local kernel headers are outdated.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoneigh: Remove check for AF_UNSPEC in rtnl_neigh_get()
Thomas Graf [Fri, 1 Feb 2013 09:41:45 +0000 (10:41 +0100)]
neigh: Remove check for AF_UNSPEC in rtnl_neigh_get()

This check was introduces to not accidently return AF_BRIDGE objects
to unaware API users as they do differ in structure. However, such
objects are only available if explicitely requests using the
NL_CACHE_AF_ITER flag or by using arg1 == AF_BRIDGE for the cache.

Therefore remove this check and allow rtnl_neigh_get() to be used to
fetch any neighbor object of a cache.

Reported-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agocache: Make NL_ACT_* and nl_cache_ops_(get|put)() available
Thomas Graf [Fri, 1 Feb 2013 09:21:58 +0000 (10:21 +0100)]
cache: Make NL_ACT_* and nl_cache_ops_(get|put)() available

Move NL_ACT_* definition and the functions nl_cache_ops_get()
and nl_cache_ops_put() into the public facing API. They can
be considered stable.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoFix mask calculation in nl_addr_cmp_prefix()
Thomas Graf [Thu, 31 Jan 2013 09:59:10 +0000 (10:59 +0100)]
Fix mask calculation in nl_addr_cmp_prefix()

Signed-off-by: Malte Langermann <mlangermann@radiodata.biz>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoMerge branch 'nattuple' of https://github.com/rmfought/libnl
Thomas Graf [Thu, 31 Jan 2013 09:47:58 +0000 (10:47 +0100)]
Merge branch 'nattuple' of https://github.com/rmfought/libnl

11 years agolink cache: remove AF_UNSPEC check in rtnl_get_link and rtnl_get_link_by_name
roopa [Mon, 28 Jan 2013 15:46:16 +0000 (07:46 -0800)]
link cache: remove AF_UNSPEC check in rtnl_get_link and rtnl_get_link_by_name

This patch reverts back the AF_UNSPEC check introduced by AF_BRIDGE
changes at http://lists.infradead.org/pipermail/libnl/2012-November/000796.html

After the addition of AF_BRIDGE support, link cache can now contain objects of
type AF_BRIDGE. To make sure existing api's did not return AF_BRIDGE objects
and surprise existing callers, I introduced the check for AF_UNSPEC.

But from what Andy Wang reported, rtnl_link_get_by_name returns the first
link object with matching ifindex and that could have not only been AF_UNSPEC
but also of family AF_INET6. And his app always got an AF_INET6 object prior
to the patch that introduced the AF_UNSPEC check.

I could just add AF_INET6 family check along with AF_UNSPEC in the apis and that
should work well.

But thinking about it some more, removing the AF_UNSPEC change seems to be safer at
this point. That way this api will retain its semantics and return the first object
with matching ifindex. It could be of any supported family. The user will know if the
cache contains bridge objects, because they are available only with the cache flag
NL_CACHE_AF_ITER. Besides, if new users want to search for a specific object,
nl_cache_find is a better option.

Reported-by: Andy Wang <Andy.Wang@watchguard.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agonetfilter: correct error in construction of NAT tuple
Rich Fought [Tue, 29 Jan 2013 23:10:01 +0000 (15:10 -0800)]
netfilter: correct error in construction of NAT tuple

11 years agocan: add helper function to get CAN bus state
Benedikt Spranger [Fri, 25 Jan 2013 15:50:32 +0000 (16:50 +0100)]
can: add helper function to get CAN bus state

Add a helper function to get the CAN bus state.

Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
11 years agoMerge pull request #29 from rmfought/natdir32
Thomas Graf [Thu, 24 Jan 2013 16:32:35 +0000 (08:32 -0800)]
Merge pull request #29 from rmfought/natdir32

netfilter: expectation NAT direction is 32 bit attribute

11 years agonetfilter: keep 8-bit API for 32-bit NAT dir attribute
Rich Fought [Thu, 24 Jan 2013 16:18:35 +0000 (08:18 -0800)]
netfilter: keep 8-bit API for 32-bit NAT dir attribute

11 years ago3.2.21 release libnl3_2_21
Thomas Graf [Thu, 24 Jan 2013 14:00:26 +0000 (15:00 +0100)]
3.2.21 release

11 years agoProvide better help text when bumping CURRENT,AGE,REVISION
Thomas Graf [Thu, 24 Jan 2013 13:34:22 +0000 (14:34 +0100)]
Provide better help text when bumping CURRENT,AGE,REVISION

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoRemove obsolete warning from <netlink/object-api.h> as it breaks NM build
Thomas Graf [Thu, 24 Jan 2013 13:29:18 +0000 (14:29 +0100)]
Remove obsolete warning from <netlink/object-api.h> as it breaks NM build

NM uses -Werror=cpp thus the build breaks if we emit #warning upon
inclusion of <netlink/object-api.h>

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoFix build warnings of nl-(qdisc|class|cls)-add
Thomas Graf [Thu, 24 Jan 2013 13:10:33 +0000 (14:10 +0100)]
Fix build warnings of nl-(qdisc|class|cls)-add

Reported-by: Jeroen Roovers <jer@gentoo.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoFix test-cache-mngr test
Thomas Graf [Thu, 24 Jan 2013 13:05:48 +0000 (14:05 +0100)]
Fix test-cache-mngr test

Needs to include <netlink-private/cache-api.h>

Reported-by: Jeroen Roovers <jer@gentoo.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoProvide compat headers for removed private API
Thomas Graf [Thu, 24 Jan 2013 13:03:52 +0000 (14:03 +0100)]
Provide compat headers for removed private API

Some projects seem to have mistakenly included the private
API headers without actually needing them.

Provide dummy headers referring to the real headers to
provide backwards compatibility.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
11 years agoMove private header files to <netlink-private/*>
Thomas Graf [Thu, 24 Jan 2013 12:51:24 +0000 (13:51 +0100)]
Move private header files to <netlink-private/*>

This clarifies the seperation between public and private
header files.

Signed-off-by: Thomas Graf <tgraf@suug.ch>