netlink

{{Short description|Linux kernel interface for inter-process communication between processes}}

{{For|the modem|Sega NetLink}}

{{Infobox software

| name = Linux kernel

| title = Netlink

| logo =

| logo caption =

| logo_size =

| logo_alt =

| screenshot =

| caption =

| screenshot_size =

| screenshot_alt =

| collapsible =

| author =

| developer =

| released =

| discontinued =

| latest release version = {{wikidata|property|edit|reference|Q14579|P548=Q2804309|P348}}

| latest release date = {{start date and age|{{wikidata|qualifier|Q14579|P548=Q2804309|P348|P577}}}}

| latest preview version =

| latest preview date = {{start date and age|{{wikidata|qualifier|Q14579|P548=Q51930650|P348|P577}}}}

| programming language =

| operating system = Linux

| platform = Linux kernel

| genre = Application programming interface

| license = GNU General Public License

| website = {{URL|https://wiki.linuxfoundation.org/networking/generic_netlink_howto}}

}}

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.{{Cite web|url=https://cgit.freebsd.org/src/commit/?id=7e5bf68495cc0a8c9793a338a8a02009a7f6dbb6|title=netlink: add netlink support}} 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).{{Cite web|url=https://man7.org/linux/man-pages/man7/netlink.7.html|title=netlink(7) - Linux manual page|website=man7.org}}

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 {{code|AF_NETLINK}} socket family.

Netlink is designed to be a more flexible successor to ioctl; [https://tools.ietf.org/html/rfc3549 RFC 3549] describes the protocol in detail.

History

Netlink was created by Alexey Kuznetsov{{cite web|url=https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c |title=kernel/git/torvalds/linux.git: root/net/core/rtnetlink.c | work=Linux kernel source tree |publisher=kernel.org |access-date=2014-05-27}} as a more flexible alternative to the sophisticated but awkward ioctl communication method used for setting and getting external socket options. The Linux kernel continues to support {{code|ioctl}} for backward compatibility.

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 {{code|rtnetlink}}.{{cite book

| editor1-last = Crowcroft

| editor1-first = Jon

| editor1-link = Jon Crowcroft

| editor2-last = Phillips

| editor2-first = Iain

| title = TCP/IP and Linux protocol implementation: systems code for the Linux Internet

| url = https://books.google.com/books?id=qOdSAAAAMAAJ

| access-date = 2013-05-21

| series = Wiley Networking Council series

| year = 2002

| publisher = Wiley

| isbn = 9780471408826

| page = 624

| quote = All rtnetlink messages consist of a netlink message header and appended attributes.}} The Netlink socket interface appeared in 2.2 series of the Linux kernel.

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.{{r|freebsd}}

Packet structure

class="wikitable floatright" style="text-align: center; max-width: 20em; margin-left: 1.5em;"
style="width:4%;" | Bit offset

! colspan="16" style="width:48%;" | 0–15

! colspan="16" style="width:48%;" | 16–31

0

| colspan="32" | Message length

32

| colspan="16" | Type

| colspan="16" | Flags

64

| colspan="32" | Sequence number

96

| colspan="32" | PID

128+

| colspan="32" |  {{br}}Data{{br}} 

Unlike BSD sockets using Internet protocols such as TCP, where the message headers are autogenerated, the Netlink message header (available as {{code|struct nlmsghdr}}) must be prepared by the caller. The Netlink socket generally works in a {{code|SOCK_RAW}}-like mode, even if {{code|SOCK_DGRAM}} was used to create it.

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

See also

{{Portal|Computer programming|Free and open-source software|Linux}}

References

{{Reflist}}