Netlink
<templatestyles src="Module:Hatnote/styles.css"></templatestyles>
Stable release | Lua error in Module:Wd at line 405: invalid escape sequence near '"^'. / Lua error in Module:Wd at line 405: invalid escape sequence near '"^'. |
---|---|
Preview release | 4.7-rc1 (29 May 2016[±][1] | )
Operating system | Linux |
Platform | Linux kernel |
Type | Application programming interface |
License | GNU General Public License |
Website | wiki |
Netlink is a socket family used for inter-process communication (IPC) between both the kernel and userspace processes, and between different userspace processes, in a way similar to the Unix domain sockets available on certain Unix-like operating systems, including its original incarnation as a Linux kernel interface, as well as in the form of a later implementation on FreeBSD.[2] Similarly to the Unix domain sockets, and unlike INET sockets, Netlink communication cannot traverse host boundaries. However, while the Unix domain sockets use the file system namespace, Netlink sockets are usually addressed by process identifiers (PIDs).[3]
Netlink is designed and used for transferring miscellaneous networking information between the kernel space and userspace processes. Networking utilities, such as the iproute2 family and the utilities used for configuring mac80211-based wireless drivers, use Netlink to communicate with the Linux kernel from userspace. Netlink provides a standard socket-based interface for userspace processes, and a kernel-side API for internal use by kernel modules. Originally, Netlink used the
socket family.AF_NETLINK
Netlink is designed to be a more flexible successor to ioctl; RFC 3549 describes the protocol in detail.
Contents
History
Netlink was created by Alexey Kuznetsov[4] as a more flexible alternative to the sophisticated but awkward
communication method used for setting and getting external socket options. The Linux kernel continues to support ioctl
for backward compatibility.ioctl
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
.[5] The Netlink socket interface appeared in 2.2 series of the Linux kernel.rtnetlink
In 2022, experimental support for the Netlink protocol was added to FreeBSD. Initially, only a subset of the NETLINK_ROUTE family and NETLINK_GENERIC is supported.[2]:{{{3}}}
Packet structure
Bit offset | 0–15 | 16–31 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Message length | |||||||||||||||||||||||||||||||
32 | Type | Flags | ||||||||||||||||||||||||||||||
64 | Sequence number | |||||||||||||||||||||||||||||||
96 | PID | |||||||||||||||||||||||||||||||
128+ | Data |
Unlike BSD sockets using Internet protocols such as TCP, where the message headers are autogenerated, the Netlink message header (available as
) must be prepared by the caller. The Netlink socket generally works in a struct nlmsghdr
-like mode, even if SOCK_RAW
was used to create it.SOCK_DGRAM
The data portion then contains a subsystem-specific message that may be further nested.
Netlink socket families
The
family offers multiple protocol subsets. Each interfaces to a different kernel component and has a different messaging subset. The subset is referenced by the protocol field in the socket call:AF_NETLINK
int socket(AF_NETLINK, SOCK_DGRAM or SOCK_RAW, protocol)
Lacking a standard,
and SOCK_DGRAM
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.SOCK_RAW
Netlink protocols
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_ROUTE
- Link layer: RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK, RTM_SETLINK
- Address settings: RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
- Routing tables: RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
- Neighbor cache: RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
- Routing rules: RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
- Queuing discipline settings: RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
- Traffic classes used with queues: RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
- Traffic filters: RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
- Others: RTM_NEWACTION, RTM_DELACTION, RTM_GETACTION, RTM_NEWPREFIX, RTM_GETPREFIX, RTM_GETMULTICAST, RTM_GETANYCAST, RTM_NEWNEIGHTBL, RTM_GETNEIGHTBL, RTM_SETNEIGHTBL
- NETLINK_FIREWALL
provides an interface for a user-space app to receive packets from the firewall.NETLINK_FIREWALL
- NETLINK_NFLOG
provides an interface used to communicate between Netfilter and iptables.NETLINK_NFLOG
- NETLINK_ARPD
provides an interface to manage the ARP table from user-space.NETLINK_ARPD
- NETLINK_AUDIT
provides an interface to the audit subsystem found in Linux kernel versions 2.6.6 and later.NETLINK_AUDIT
- NETLINK_IP6_FW
provides an interface to transport packets from netfilter to user-space.NETLINK_IP6_FW
- NETLINK_ROUTE6
- NETLINK_TAPBASE
- NETLINK_NETFILTER
- NETLINK_TCPDIAG
- 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.NETLINK_XFRM
- NETLINK_KOBJECT_UEVENT
provides the interface in which the kernel broadcasts uevents, typically consumed by udev.NETLINK_KOBJECT_UEVENT
- NETLINK_GENERIC
One of the drawbacks of the Netlink protocol is that the number of protocol families is limited to 32 (
).This is one of the main reasons that the generic Netlink family was created—to provide support for adding a higher number of families. It acts as a Netlink multiplexer and works with a single Netlink family MAX_LINKS
. The generic Netlink protocol is based on the Netlink protocol and uses its API.NETLINK_GENERIC
User-defined Netlink protocol
Users can add a Netlink handler in their own kernel routines. This allows the development of additional Netlink protocols to address new kernel modules.[6]
See also
- Comparison of open-source wireless drivers – mac80211-based drivers rely on Netlink as the API to user space
- POSIX
References
<templatestyles src="Reflist/styles.css" />
Cite error: Invalid <references>
tag; parameter "group" is allowed only.
<references />
, or <references group="..." />
External links
- Pablo Neira Ayuso, Rafael M. Gasca, Laurent Lefèvre. Communicating between the kernel and user-space in Linux using Netlink sockets. Software: Practice and Experience, 40(9):797-810, August 2010
- Why and How to Use Netlink Sockets
- RFC 3549
- netfilter/iptables project homepage - The netfilter.org "libmnl" project – Minimalist Library for Netlink – userspace library for construction and parsing of Netlink messages
- libnl - Netlink Protocol Library Suite – Netlink Protocol Library Suite – full functional library covering almost all aspects of working with Netlink sockets
- Manipulating the Networking Environment Using RTNETLINK
- Netlink Sockets – An Overview
- Netlink Protocol Library Suite
- "Linux Kernel Networking" by Rami Rosen, Apress 2013: Chapter 2, Netlink Sockets
Template:Inter-process communication
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ 2.0 2.1 Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.