{"id":4114,"date":"2022-12-20T17:39:26","date_gmt":"2022-12-20T20:39:26","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/netlink-man7\/"},"modified":"2022-12-20T17:39:26","modified_gmt":"2022-12-20T20:39:26","slug":"netlink-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/netlink-man7\/","title":{"rendered":"NETLINK (man7)"},"content":{"rendered":"<h1 align=\"center\">NETLINK<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#VERSIONS\">VERSIONS<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#BUGS\">BUGS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">netlink \u2212 communication between kernel and user space (AF_NETLINK)<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <asm\/types.h> <br \/> #include <sys\/socket.h> <br \/> #include <linux\/netlink.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>netlink_socket = socket(AF_NETLINK,<\/b> <i>socket_type<\/i><b>,<\/b> <i>netlink_family<\/i><b>);<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Netlink is used to transfer information between the kernel and user-space processes. It consists of a standard sockets-based interface for user space processes and an internal kernel API for kernel modules. The internal kernel interface is not documented in this manual page. There is also an obsolete netlink interface via netlink character devices; this interface is not documented here and is provided only for backward compatibility.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Netlink is a datagram-oriented service. Both <b>SOCK_RAW<\/b> and <b>SOCK_DGRAM<\/b> are valid values for <i>socket_type<\/i>. However, the netlink protocol does not distinguish between datagram and raw sockets.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>netlink_family<\/i> selects the kernel module or netlink group to communicate with. The currently assigned netlink families are: <b><br \/> NETLINK_ROUTE<\/b><\/p>\n<p style=\"margin-left:22%;\">Receives routing and link updates and may be used to modify the routing tables (both IPv4 and IPv6), IP addresses, link parameters, neighbor setups, queueing disciplines, traffic classes and packet classifiers (see <b>rtnetlink<\/b>(7)).<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_W1<\/b> (Linux 2.6.13 to 2.16.17)<\/p>\n<p style=\"margin-left:22%;\">Messages from 1-wire subsystem.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_USERSOCK<\/b><\/p>\n<p style=\"margin-left:22%;\">Reserved for user-mode socket protocols.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_FIREWALL<\/b> (up to and including Linux 3.4)<\/p>\n<p style=\"margin-left:22%;\">Transport IPv4 packets from netfilter to user space. Used by <i>ip_queue<\/i> kernel module. After a long period of being declared obsolete (in favor of the more advanced <i>nfnetlink_queue<\/i> feature), <b>NETLINK_FIREWALL<\/b> was removed in Linux 3.5.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_SOCK_DIAG<\/b> (since Linux 3.3)<\/p>\n<p style=\"margin-left:22%;\">Query information about sockets of various protocol families from the kernel (see <b>sock_diag<\/b>(7)).<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_INET_DIAG<\/b> (since Linux 2.6.14)<\/p>\n<p style=\"margin-left:22%;\">An obsolete synonym for <b>NETLINK_SOCK_DIAG<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_NFLOG<\/b> (up to and including Linux 3.16)<\/p>\n<p style=\"margin-left:22%;\">Netfilter\/iptables ULOG.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_XFRM<\/b><\/p>\n<p style=\"margin-left:22%;\">IPsec.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_SELINUX<\/b> (since Linux 2.6.4)<\/p>\n<p style=\"margin-left:22%;\">SELinux event notifications.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_ISCSI<\/b> (since Linux 2.6.15)<\/p>\n<p style=\"margin-left:22%;\">Open-iSCSI.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_AUDIT<\/b> (since Linux 2.6.6)<\/p>\n<p style=\"margin-left:22%;\">Auditing.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_FIB_LOOKUP<\/b> (since Linux 2.6.13)<\/p>\n<p style=\"margin-left:22%;\">Access to FIB lookup from user space.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_CONNECTOR<\/b> (since Linux 2.6.14)<\/p>\n<p style=\"margin-left:22%;\">Kernel connector. See <i>Documentation\/driver-api\/connector.rst<\/i> (or <i>\/Documentation\/connector\/connector.*<\/i> in kernel 5.2 and earlier) in the Linux kernel source tree for further information.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_NETFILTER<\/b> (since Linux 2.6.14)<\/p>\n<p style=\"margin-left:22%;\">Netfilter subsystem.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_SCSITRANSPORT<\/b> (since Linux 2.6.19)<\/p>\n<p style=\"margin-left:22%;\">SCSI Transports.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_RDMA<\/b> (since Linux 3.0)<\/p>\n<p style=\"margin-left:22%;\">Infiniband RDMA.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_IP6_FW<\/b> (up to and including Linux 3.4)<\/p>\n<p style=\"margin-left:22%;\">Transport IPv6 packets from netfilter to user space. Used by <i>ip6_queue<\/i> kernel module.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_DNRTMSG<\/b><\/p>\n<p style=\"margin-left:22%;\">DECnet routing messages.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_KOBJECT_UEVENT<\/b> (since Linux 2.6.10)<\/p>\n<p style=\"margin-left:22%;\">Kernel messages to user space.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_GENERIC<\/b> (since Linux 2.6.15)<\/p>\n<p style=\"margin-left:22%;\">Generic netlink family for simplified netlink usage.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_CRYPTO<\/b> (since Linux 3.2)<\/p>\n<p style=\"margin-left:22%;\">Netlink interface to request information about ciphers registered with the kernel crypto API as well as allow configuration of the kernel crypto API.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Netlink messages consist of a byte stream with one or multiple <i>nlmsghdr<\/i> headers and associated payload. The byte stream should be accessed only with the standard <b>NLMSG_*<\/b> macros. See <b>netlink<\/b>(3) for further information.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In multipart messages (multiple <i>nlmsghdr<\/i> headers with associated payload in one byte stream) the first and all following headers have the <b>NLM_F_MULTI<\/b> flag set, except for the last header which has the type <b>NLMSG_DONE<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">After each <i>nlmsghdr<\/i> the payload follows.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct nlmsghdr { <br \/> __u32 nlmsg_len; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Length of message including header bodies\/ usr\/ <br \/> __u16 nlmsg_type; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Type of message content bodies\/ usr\/ <br \/> __u16 nlmsg_flags; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Additional flags bodies\/ usr\/ <br \/> __u32 nlmsg_seq; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Sequence number bodies\/ usr\/ <br \/> __u32 nlmsg_pid; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Sender port ID bodies\/ usr\/ <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>nlmsg_type<\/i> can be one of the standard message types: <b>NLMSG_NOOP<\/b> message is to be ignored, <b>NLMSG_ERROR<\/b> message signals an error and the payload contains an <i>nlmsgerr<\/i> structure, <b>NLMSG_DONE<\/b> message terminates a multipart message.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct nlmsgerr { <br \/> int error; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Negative errno or 0 for acknowledgements bodies\/ usr\/ <br \/> struct nlmsghdr msg; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Message header that caused the error bodies\/ usr\/ <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">A netlink family usually specifies more message types, see the appropriate manual pages for that, for example, <b>rtnetlink<\/b>(7) for <b>NETLINK_ROUTE<\/b>.<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-909041.png\" alt=\"Image grohtml-909041.png\"><\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-909042.png\" alt=\"Image grohtml-909042.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that <b>NLM_F_ATOMIC<\/b> requires the <b>CAP_NET_ADMIN<\/b> capability or an effective UID of 0.<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-909043.png\" alt=\"Image grohtml-909043.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>nlmsg_seq<\/i> and <i>nlmsg_pid<\/i> are used to track messages. <i>nlmsg_pid<\/i> shows the origin of the message. Note that there isn\u2019t a 1:1 relationship between <i>nlmsg_pid<\/i> and the PID of the process if the message originated from a netlink socket. See the <b>ADDRESS FORMATS<\/b> section for further information.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Both <i>nlmsg_seq<\/i> and <i>nlmsg_pid<\/i> are opaque to netlink core.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Netlink is not a reliable protocol. It tries its best to deliver a message to its destination(s), but may drop messages when an out-of-memory condition or other error occurs. For reliable transfer the sender can request an acknowledgement from the receiver by setting the <b>NLM_F_ACK<\/b> flag. An acknowledgment is an <b>NLMSG_ERROR<\/b> packet with the error field set to 0. The application must generate acknowledgements for received messages itself. The kernel tries to send an <b>NLMSG_ERROR<\/b> message for every failed packet. A user process should follow this convention too.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">However, reliable transmissions from kernel to user are impossible in any case. The kernel can\u2019t send a netlink message if the socket buffer is full: the message will be dropped and the kernel and the user-space process will no longer have the same view of kernel state. It is up to the application to detect when this happens (via the <b>ENOBUFS<\/b> error returned by <b>recvmsg<\/b>(2)) and resynchronize.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Address formats<\/b> <br \/> The <i>sockaddr_nl<\/i> structure describes a netlink client in user space or in the kernel. A <i>sockaddr_nl<\/i> can be either unicast (only sent to one peer) or sent to netlink multicast groups (<i>nl_groups<\/i> not equal 0).<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct sockaddr_nl { <br \/> sa_family_t nl_family; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var AF_NETLINK bodies\/ usr\/ <br \/> unsigned short nl_pad; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Zero bodies\/ usr\/ <br \/> pid_t nl_pid; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Port ID bodies\/ usr\/ <br \/> __u32 nl_groups; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Multicast groups mask bodies\/ usr\/ <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>nl_pid<\/i> is the unicast address of netlink socket. It\u2019s always 0 if the destination is in the kernel. For a user-space process, <i>nl_pid<\/i> is usually the PID of the process owning the destination socket. However, <i>nl_pid<\/i> identifies a netlink socket, not a process. If a process owns several netlink sockets, then <i>nl_pid<\/i> can be equal to the process ID only for at most one socket. There are two ways to assign <i>nl_pid<\/i> to a netlink socket. If the application sets <i>nl_pid<\/i> before calling <b>bind<\/b>(2), then it is up to the application to make sure that <i>nl_pid<\/i> is unique. If the application sets it to 0, the kernel takes care of assigning it. The kernel assigns the process ID to the first netlink socket the process opens and assigns a unique <i>nl_pid<\/i> to every netlink socket that the process subsequently creates.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>nl_groups<\/i> is a bit mask with every bit representing a netlink group number. Each netlink family has a set of 32 multicast groups. When <b>bind<\/b>(2) is called on the socket, the <i>nl_groups<\/i> field in the <i>sockaddr_nl<\/i> should be set to a bit mask of the groups which it wishes to listen to. The default value for this field is zero which means that no multicasts will be received. A socket may multicast messages to any of the multicast groups by setting <i>nl_groups<\/i> to a bit mask of the groups it wishes to send to when it calls <b>sendmsg<\/b>(2) or does a <b>connect<\/b>(2). Only processes with an effective UID of 0 or the <b>CAP_NET_ADMIN<\/b> capability may send or listen to a netlink multicast group. Since Linux 2.6.13, messages can\u2019t be broadcast to multiple groups. Any replies to a message received for a multicast group should be sent back to the sending PID and the multicast group. Some Linux kernel subsystems may additionally allow other users to send and\/or receive messages. As at Linux 3.0, the <b>NETLINK_KOBJECT_UEVENT<\/b>, <b>NETLINK_GENERIC<\/b>, <b>NETLINK_ROUTE<\/b>, and <b>NETLINK_SELINUX<\/b> groups allow other users to receive messages. No groups allow other users to send messages.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Socket options<\/b> <br \/> To set or get a netlink socket option, call <b>getsockopt<\/b>(2) to read or <b>setsockopt<\/b>(2) to write the option with the option level argument set to <b>SOL_NETLINK<\/b>. Unless otherwise noted, <i>optval<\/i> is a pointer to an <i>int<\/i>. <b><br \/> NETLINK_PKTINFO<\/b> (since Linux 2.6.14)<\/p>\n<p style=\"margin-left:22%;\">Enable <b>nl_pktinfo<\/b> control messages for received packets to get the extended destination group number.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_ADD_MEMBERSHIP<\/b>,\u00a0<b>NETLINK_DROP_MEMBERSHIP<\/b> (since Linux 2.6.14)<\/p>\n<p style=\"margin-left:22%;\">Join\/leave a group specified by <i>optval<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_LIST_MEMBERSHIPS<\/b> (since Linux 4.2)<\/p>\n<p style=\"margin-left:22%;\">Retrieve all groups a socket is a member of. <i>optval<\/i> is a pointer to <b>__u32<\/b> and <i>optlen<\/i> is the size of the array. The array is filled with the full membership set of the socket, and the required array size is returned in <i>optlen<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_BROADCAST_ERROR<\/b> (since Linux 2.6.30)<\/p>\n<p style=\"margin-left:22%;\">When not set, <b>netlink_broadcast()<\/b> only reports <b>ESRCH<\/b> errors and silently ignore <b>ENOBUFS<\/b> errors.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_NO_ENOBUFS<\/b> (since Linux 2.6.30)<\/p>\n<p style=\"margin-left:22%;\">This flag can be used by unicast and broadcast listeners to avoid receiving <b>ENOBUFS<\/b> errors.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_LISTEN_ALL_NSID<\/b> (since Linux 4.2)<\/p>\n<p style=\"margin-left:22%;\">When set, this socket will receive netlink notifications from all network namespaces that have an <i>nsid<\/i> assigned into the network namespace where the socket has been opened. The <i>nsid<\/i> is sent to user space via an ancillary data.<\/p>\n<p style=\"margin-left:11%;\"><b>NETLINK_CAP_ACK<\/b> (since Linux 4.2)<\/p>\n<p style=\"margin-left:22%;\">The kernel may fail to allocate the necessary room for the acknowledgment message back to user space. This option trims off the payload of the original netlink message. The netlink message header is still included, so the user can guess from the sequence number which message triggered the acknowledgment.<\/p>\n<h2>VERSIONS <a name=\"VERSIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The socket interface to netlink first appeared Linux 2.2.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Linux 2.0 supported a more primitive device-based netlink interface (which is still available as a compatibility option). This obsolete interface is not described here.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">It is often better to use netlink via <i>libnetlink<\/i> or <i>libnl<\/i> than via the low-level kernel interface.<\/p>\n<h2>BUGS <a name=\"BUGS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is not complete.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following example creates a <b>NETLINK_ROUTE<\/b> netlink socket which will listen to the <b>RTMGRP_LINK<\/b> (network interface create\/delete\/up\/down events) and <b>RTMGRP_IPV4_IFADDR<\/b> (IPv4 addresses add\/delete events) multicast groups.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct sockaddr_nl sa;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">memset(&#038;sa, 0, sizeof(sa)); <br \/> sa.nl_family = AF_NETLINK; <br \/> sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); <br \/> bind(fd, (struct sockaddr *) &#038;sa, sizeof(sa));<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The next example demonstrates how to send a netlink message to the kernel (pid 0). Note that the application must take care of message sequence numbers in order to reliably track acknowledgements.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct nlmsghdr *nh; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var The nlmsghdr with payload to send bodies\/ usr\/ <br \/> struct sockaddr_nl sa; <br \/> struct iovec iov = { nh, nh\u2212>nlmsg_len }; <br \/> struct msghdr msg;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">msg = { &#038;sa, sizeof(sa), &#038;iov, 1, NULL, 0, 0 }; <br \/> memset(&#038;sa, 0, sizeof(sa)); <br \/> sa.nl_family = AF_NETLINK; <br \/> nh\u2212>nlmsg_pid = 0; <br \/> nh\u2212>nlmsg_seq = ++sequence_number; <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Request an ack from kernel by setting NLM_F_ACK bodies\/ usr\/ <br \/> nh\u2212>nlmsg_flags |= NLM_F_ACK;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">sendmsg(fd, &#038;msg, 0);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">And the last example is about reading netlink message.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">int len; <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var 8192 to avoid message truncation on platforms with <br \/> page size > 4096 bodies\/ usr\/ <br \/> struct nlmsghdr buf[8192\/sizeof(struct nlmsghdr)]; <br \/> struct iovec iov = { buf, sizeof(buf) }; <br \/> struct sockaddr_nl sa; <br \/> struct msghdr msg; <br \/> struct nlmsghdr *nh;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">msg = { &#038;sa, sizeof(sa), &#038;iov, 1, NULL, 0, 0 }; <br \/> len = recvmsg(fd, &#038;msg, 0);<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len); <br \/> nh = NLMSG_NEXT (nh, len)) { <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var The end of multipart message bodies\/ usr\/ <br \/> if (nh\u2212>nlmsg_type == NLMSG_DONE) <br \/> return;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">if (nh\u2212>nlmsg_type == NLMSG_ERROR) <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Do some error handling bodies\/ usr\/ <br \/> &#8230;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\/* Continue with parsing payload bodies\/ usr\/ <br \/> &#8230; <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>cmsg<\/b>(3), <b>netlink<\/b>(3), <b>capabilities<\/b>(7), <b>rtnetlink<\/b>(7), <b>sock_diag<\/b>(7) <br \/> <a href=\"ftp:\/\/ftp.inr.ac.ru\/ip-routing\/iproute2*\">information about libnetlink<\/a> <br \/> <a href=\"http:\/\/www.infradead.org\/~tgr\/libnl\/\">information about libnl<\/a><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">RFC 3549 &#8220;Linux Netlink as an IP Services Protocol&#8221;<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  netlink \u2212 communication between kernel and user space (AF_NETLINK) <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,972,1193],"class_list":["post-4114","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-man7","tag-netlink"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4114"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4114\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}