Commit graph

778 commits

Author SHA1 Message Date
Joe Damato
81d2b1d509 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.
2013-07-19 02:06:21 -07:00
Arend van Spriel
89b00119f2 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>
2013-07-18 23:22:18 +02:00
Arend van Spriel
7dc033f5cc 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>
2013-07-18 23:22:18 +02:00
Arend van Spriel
e77ea939c4 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>
2013-07-18 23:22:18 +02:00
Joe Damato
c08aacc2e8 handle the case where 0 is passed to nl_size2str
(cherry picked from commit 968ccbe97d476e3a8485b04dbaf469e8d01b8811)
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-18 23:10:19 +02:00
Thomas Graf
408a1b8f07 cache: Return -NLE_PROTO_MISMATCH if socket provided mismatches cache protocol
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-01 12:41:42 +02:00
Thomas Graf
2d0810eb93 socket: Warn via debug message if local port namespace is exhausted
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-06-28 18:53:16 +02:00
Thomas Graf
cd1c1e1041 tests: use AM_CFLAGS instead of CFLAGS directly
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-06-28 18:49:51 +02:00
Thomas Graf
01cfa9c1db 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>
2013-06-27 18:29:17 +02:00
Holger Eitzenberger
d612180cda 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>
2013-06-27 01:16:15 +02:00
Holger Eitzenberger
34a96ba5c2 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>
2013-06-27 01:15:34 +02:00
Andrew Collins
53ac502a2b 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>
2013-06-27 01:12:36 +02:00
Andrew Collins
87bbfb6b12 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>
2013-06-27 01:12:28 +02:00
Thomas Graf
c1de0f3129 Merge branch 'master' of https://github.com/michael-dev/libnl 2013-05-24 14:37:02 +02:00
Michael Braun
c76393e203 Add macvlan support
This patch add support for kernel macvlan interfaces.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
2013-05-16 17:04:08 +02:00
Thomas Graf
c4d846f239 3.2.22 release 2013-05-14 14:09:07 +02:00
Thomas Graf
807fddc4cd 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>
2013-05-08 13:52:27 +02:00
Nathan Lynch
8983fa9914 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>
2013-05-08 13:48:24 +02:00
Thomas Graf
183052d047 Prepare for 3.2.22-rc1 release
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-28 12:52:26 +02:00
Thomas Graf
ed1f4cba2c tests: Include util.h in dist
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-28 12:51:58 +02:00
Thomas Graf
4e9aa6a9a6 tests: Add basic attribute unit tests
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-28 12:31:52 +02:00
Thomas Graf
ffc0ee3540 configure: Convert ENABLE_UNIT_TESTS to a mere AM conditional
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-28 11:41:15 +02:00
Emmanuel Thierry
979ea335b0 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>
2013-04-28 10:34:50 +02:00
Thomas Graf
3a6d256da5 attr: Fix typo in nla_is_nested()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-28 10:33:52 +02:00
Thomas Graf
37f788f391 Merge branch 'fixes' of https://github.com/socketpair/libnl 2013-04-28 10:25:47 +02:00
Thomas Graf
c07a6a30c2 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>
2013-04-28 10:23:28 +02:00
Коренберг Марк (дома)
33396faca5 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())
2013-04-28 02:08:50 +06:00
Thomas Graf
ead4cdeb99 tests: Make unit test building optional
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-27 14:27:10 +02:00
Коренберг Марк (дома)
59db7fb35b dump_attrs: "NLA_F_NESTED" => nla_is_nested(nla) 2013-04-26 23:50:54 +06:00
Thomas Graf
d505165f2b autoconf: Use PKG_CHECK_MODULES() instead of AM_PATH_CHECK()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-05 10:44:06 +02:00
Thomas Graf
d3cf89ea94 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>
2013-04-05 10:37:55 +02:00
Emmanuel Roullit
ea436445ad 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>
2013-04-03 21:17:33 +02:00
Thomas Graf
56eb22fa74 msg: Pretty print generic netlink header in nl_msg_dump()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-02 23:13:15 +02:00
Thomas Graf
375a6294a4 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>
2013-04-02 11:58:18 +02:00
Thomas Graf
df66b0f267 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>
2013-04-02 11:51:53 +02:00
Holger Eitzenberger
18152ca916 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>
2013-04-02 11:42:59 +02:00
Thomas Graf
ff567100d6 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>
2013-04-02 11:39:30 +02:00
Thomas Graf
f9241d57fe cache: Improve debugging messages of cache operations
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-01 11:46:30 +02:00
Thomas Graf
ad545f2854 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>
2013-04-01 11:21:22 +02:00
Thomas Graf
aad041c46f 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>
2013-04-01 11:14:49 +02:00
roopa
6c9be5a316 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>
2013-03-24 10:58:18 +01:00
Tony Cheneau
23e26e9e05 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>
2013-03-17 17:31:53 +01:00
Tony Cheneau
4db11517fd 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>
2013-03-17 17:31:45 +01:00
Thomas Graf
b39c9f7a53 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>
2013-03-14 18:57:15 +01:00
Thomas Graf
549d26dc87 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>
2013-03-14 18:52:17 +01:00
Thomas Graf
e09e7f1035 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>
2013-03-14 16:25:17 +01:00
Thomas Graf
780a0423dc addr: Update to latest address familiy definition for translation
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-03-14 16:09:19 +01:00
Thomas Graf
88527534ba addr: improve API reference documentation for nl_addr_*()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-03-14 15:37:46 +01:00
Thomas Graf
f0f33c394b 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>
2013-03-14 14:41:12 +01:00
Thomas Graf
f72bfc7220 msg: Pretty print error message header even if incomplete
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-03-14 12:46:14 +01:00