From Wikipedia, the free encyclopedia - View original article

Stable release3.17.1 (15 October 2014; 3 days ago (2014-10-15)) [±][1]
Operating systemLinux
PlatformLinux kernel
TypeApplication programming interface
LicenseGNU General Public License
Jump to: navigation, search
For the modem, see Sega NetLink.
Stable release3.17.1 (15 October 2014; 3 days ago (2014-10-15)) [±][1]
Operating systemLinux
PlatformLinux kernel
TypeApplication programming interface
LicenseGNU General Public License

Netlink socket family is a Linux kernel interface used for inter-process communication (IPC) between the kernel and user-space processes, as well as between user processes (e.g. Unix domain sockets) or a mixture of both types. However, unlike INET sockets, it cannot traverse host boundaries, because it addresses processes by their (inherently local) PIDs.

Netlink was designed for and is used for transferring miscellaneous networking information between the kernel space and user-space processes. Networking utilities, such as the iproute2 family or the utilities used for configuring mac80211-based wireless drivers, use Netlink to communicate with the Linux kernel from user space. Netlink consists of a standard socket-based interface for user space processes and a kernel-side API used internally for kernel modules. Originally, Netlink used the AF_NETLINK socket family.

It is designed to be a more flexible successor to ioctl. RFC 3549 describes the Netlink protocol in detail.


Netlink was created by Alexey Kuznetsov[2] as a more flexible alternative to the sophisticated but awkward ioctl communication method which software used for setting and getting external socket options. The Linux kernel continues to support ioctl for backward compatibility. It can be used as follows:

error = ioctl(ip_socket, ioctl_type, &value_result);

Netlink was first provided in the 2.0 series of the Linux kernel, implemented as a character device. By 2013, this interface is obsolete, but still forms an ioctl communication method; compare the use of rtnetlink.[3] The Netlink socket interface appeared in 2.2 series of the Linux kernel.

Packet structure[edit]

Bit offset0–1516–31
0Message length
64Sequence number

Unlike the BSD socket access to Internet protocols such as TCP where the headers specifying flags and destination are autogenerated, the Netlink message header (available as struct nlmsghdr) must be prepared by the caller, because the socket generally works in a SOCK_RAW-like mode, even if SOCK_DGRAM was used to create it.

The data portion then contains a subsystem-specific message that may be further nested.

Netlink socket families[edit]

The AF_NETLINK family offers multiple protocol subsets. Each interfaces to a different kernel component and has a different messaging subset. The following protocol is referenced in the field below:

int socket(AF_NETLINK, SOCK_DGRAM or SOCK_RAW, protocol)

Lacking a standard, SOCK_DGRAM and SOCK_RAW are not guaranteed to be implemented in a given Linux (or other OS) release. Some sources state that both options are legitimate, and the reference below from Red Hat states that SOCK_RAW is always the parameter, however iproute2 uses both interchangeably.

Netlink protocols[edit]

A non-exhaustive list of the supported protocol entries follows:


NETLINK_ROUTE provides routing and link information. This information is used primarily for user-space routing daemons. Linux implements a large subset of messages:


NETLINK_FIREWALL provides an interface for a user-space app to receive packets from the firewall.


NETLINK_NFLOG provides an interface used to communicate between used Netfilter and iptables.


NETLINK_ARPD provides an interface to manage the ARP table from user-space.


NETLINK_AUDIT provides an interface to the audit subsystem found in Linux kernel versions 2.6.6 and later.


NETLINK_IPV6_FW provides an interface to transport packets from netfilter to user-space.


NETLINK_XFRM provides an interface to manage the IPsec security association and security policy databases - mostly used by key-manager daemons using the Internet Key Exchange protocol.

User-defined Netlink protocol[edit]

Users can add a Netlink handler in their own kernel routines. This allows the development of additional Netlink protocols to address new kernel modules.[4]

See also[edit]


  1. ^ Kroah-Hartman, Greg (October 5 2014). "Linux 3.17.1". linux-kernel-mailing-list mailing list.
  2. ^ "kernel/git/torvalds/linux.git: root/net/core/rtnetlink.c". Linux kernel source tree. Retrieved 2014-05-27. 
  3. ^ Crowcroft, Jon; Phillips, Iain, eds. (2002). TCP/IP and Linux protocol implementation: systems code for the Linux Internet. Wiley Networking Council series. Wiley. p. 624. ISBN 9780471408826. Retrieved 2013-05-21. "All rtnetlink messages consist of a netlink message header and appended attributes." 
  4. ^ Why and How to Use Netlink Sockets

External links[edit]