Fork me on GitHub

Netlink Protocol Library Suite (libnl)

Summary

The libnl suite is a collection of libraries providing APIs to netlink protocol based Linux kernel interfaces.

Netlink is a IPC mechanism primarly between the kernel and user space processes. It was designed to be a more flexible successor to ioctl to provide mainly networking related kernel configuration and monitoring interfaces.

Libraries

The interfaces are split into several small libraries to not force applications to link against a single, bloated library.

libnl
Core library implementing the fundamentals required to use the netlink protocol such as socket handling, message construction and parsing, and sending and receiving of data. This library is kept small and minimalistic. Other libraries of the suite depend on this library.
libnl-route
API to the configuration interfaces of the NETLINK_ROUTE family including network interfaces, routes, addresses, neighbours, and traffic control.
libnl-genl
API to the generic netlink protocol, an extended version of the netlink protocol.
libnl-nf
API to netlink based netfilter configuration and monitoring interfaces (conntrack, log, queue)

Installation

The easiest method of installing the libnl library suite is to use the existing packages of your linux distribution. See the table below for a list of available packages per distribution. Please note that the list may be out of date at times. Refer to the manual of your distribution for more information on how to install packages.

Distribution libnl-3.x libnl-2.x libnl-1.x
Source Package libnl-3.2.22.tar.gz No stable releases anymore libnl-1.1.4.tar.gz
CentOS Never packaged Never packaged 1.1
Package names: libnl, libnl-devel
Debian 3.2.7
Package names: libnl-3, libnl-3-dev, libnl-route-3-200, ...
1.99 (git snapshot)
Package names: libnl2, libnl2-dev, libnl2-doc, libnl2-dbg
1.1
Package names: libnl1, libnl1-dev, libnl1-doc
Fedora 3.2.13
Package names: libnl3
Never packaged 1.1
Package names: libnl, libnl-devel
OpenSUSE 3.2.12
Package names: libnl3, libnl3-devel, libnl-config, libnl-tools
2.0
Package names: libnl2_0
1.1
Package names: libnl-1, libnl-1_1-devel
Slackware Never packaged Never packaged 1.1
Package names: libnl-1.1
Ubuntu 3.2.3
Package names: libnl-3-200, libnl-3-200-dbg
1.99 (git snapshot)
Package names: libnl2, libnl2-dev, libnl2-doc, libnl2-dbg
1.1
Package names: libnl1, libnl-dev, libnl-doc

See the archives for specific older releases.

Known Bugs

Releases 3.2.18 and 3.2.19 have been shipped with an incorrect SONAME.

Release Notes

Version 3.2.22 has been released on May 14, 2013.

Important: 3.2.10 reverted an an uneeded SONAME bump that was done due to an ABI/API breakage in an unused API. After severe discussion, it was decided to undo the SONAME bump to make life easier for distribution maintainers by removing the unused APIs from the public header files and by providing compat header files that mistakenly included them.

If you linked against 3.2.18 or 3.2.19 your binary will not be compatible with >= 3.2.20. You will have to relink your binary. We are sorry for any inconvenience this may cause.

Changelog for 3.2.21 -> 3.2.22

Benedikt Spranger (1):
      can: add helper function to get CAN bus state

Emmanuel Roullit (1):
      Perform no operation on nl_object_free(NULL).

Emmanuel Thierry (1):
      Wrong calcultation in nla_reserve

Holger Dengler (1):
      can: Fix nested message creation in can_put_attrs()

Holger Eitzenberger (1):
      ct: add ICMPv6 type,code and ID

Nathan Lynch (1):
      rtnl_link_af_unregister: fix locking

Rich Fought (3):
      netfilter: expectation NAT direction is 32 bit attribute
      netfilter: keep 8-bit API for 32-bit NAT dir attribute
      netfilter: correct error in construction of NAT tuple

Thomas Graf (49):
      Merge pull request #29 from rmfought/natdir32
      Merge branch 'nattuple' of https://github.com/rmfought/libnl
      Fix mask calculation in nl_addr_cmp_prefix()
      cache: Make NL_ACT_* and nl_cache_ops_(get|put)() available
      neigh: Remove check for AF_UNSPEC in rtnl_neigh_get()
      can: Include "linux/can/netlink.h" in the distribution
      link: Fix af_ops leak on ENOMEM
      link: Keep reference to af_ops during lifetime of link object
      link: Modify link policy on the stack
      link: Hold af_ops reference for each AF_SPEC block during lifetime of link object
      link: Free and realloc af specific data upon rtnl_link_set_family()
      attr: Provide nla_is_nested() function
      bridge: Support the new bridging attributes
      bridge: Provide rtnl_link_bridge_alloc()
      netlink: Forward declare frequent libnl types to ease inclusion deps
      vlan: Provide rtnl_link_vlan_alloc()
      bond: Provide rtnl_link_bond_alloc()
      Use thread-safe strerror_r() instead of strerror()
      attr: Add nla_nest_cancel() to remove partially added nested attributes
      attr: Do not enforce maximum length for NLA_FLAG attributes
      attr: No longer warn about attribute of type 0
      attr: Warn application if nla_parse() observes same attribute multiple times
      msg: Pretty print padding attributes in nl_msg_dump()
      msg: Pretty print error message header even if incomplete
      addr: Reset unused portion of binary address in nl_addr_set_binary_addr()
      addr: improve API reference documentation for nl_addr_*()
      addr: Update to latest address familiy definition for translation
      tests: Add check based unit test system
      rtnl-addr: Inherit prefix length to nl_addr objs in rtnl_addr_set_prefixlen()
      rtnl-addr: Fix invalid call to nl_addr_set_prefixlen() if neither local or peer address are present
      genl: Provide internal function to resolve name to id
      genl: Update mt_id of cache ops when resolving genl id
      cache: Improve debugging messages of cache operations
      nl: Print file:line:func in debugging messages and provide --disable-debug to disable debugging
      genl: Fix cb reference leak in genl_ctrl_probe_by_name()
      nl: Return -NLE_AGAIN if non-blocking socket would block
      msg: Pretty print generic netlink header in nl_msg_dump()
      addr: only translate more recent address family names and ARP types if defined
      autoconf: Use PKG_CHECK_MODULES() instead of AM_PATH_CHECK()
      tests: Make unit test building optional
      attr: nla_is_nested() must access nla_type directly
      Merge branch 'fixes' of https://github.com/socketpair/libnl
      attr: Fix typo in nla_is_nested()
      configure: Convert ENABLE_UNIT_TESTS to a mere AM conditional
      tests: Add basic attribute unit tests
      tests: Include util.h in dist
      Prepare for 3.2.22-rc1 release
      nl: Increase receive buffer size to 4 pages
      3.2.22 release

Tony Cheneau (2):
      Remove superfluous declaration of rtnl_route_put()
      Remove rtnl_link_free() declaration from the header file.

roopa (4):
      link cache: remove AF_UNSPEC check in rtnl_get_link and rtnl_get_link_by_name
      link: move af_data_compare to the end
      link: Fix rtnl_link_af_data_compare return value
      nl-route-add: Add NLM_F_EXCL flag to route add

Коренберг Марк (дома) (2):
      dump_attrs: "NLA_F_NESTED"  => nla_is_nested(nla)
      Fix leak of cb if nl_socket_alloc_cb() failed to allocate socket

Changelog for 1.1.3 -> 1.1.4

Emmanuel Roullit (1):
      Perform no operation on nl_object_free(NULL).

Emmanuel Thierry (1):
      Wrong calcultation in nla_reserve

Jiri Pirko (1):
      use MSG_TRUNC flag to get recv message size at once

Thomas Graf (2):
      1.1.4 release
      nl: Increase receive buffer size to 4 pages

Коренберг Марк (дома) (1):
      Fix leak of cb if nl_socket_alloc_cb() failed to allocate socket

Documentation

Documentation tarball: libnl-doc-3.2.22.tar.gz

Library Developer's Guide API Reference Tutorials
Core Library (libnl) Core Library Developer's Guide API Reference
Routing Family (libnl-route) Routing Library Developer's Guide API Reference
Generic Netlink Family (libnl-genl) API Reference
Netfilter Family (libnl-nf) API Reference

Mailing List

Please post questions and patches to the libnl mailinglist libnl@lists.infradead.org.

Visit the info page for more information and to subscribe to the list or checkout the archives.

Git Trees

3.x releases

git://
git://git.infradead.org/users/tgr/libnl.git
git://github.com/tgraf/libnl.git
http://
http://git.infradead.org/users/tgr/libnl.git
https://github.com/tgraf/libnl.git

1.1.x releases

Support for 1.1.x releases is limited, backports are only done upon request. Do not develop new applications based on libnl1 and consider porting your applications to libnl3

git://
git://github.com/tgraf/libnl-1.1-stable.git
http://
https://github.com/tgraf/libnl-1.1-stable.git