Set NETLINK_CAP_ACK, as we don't need a full copy of the request
payload, so it's "rather wasteful"[1] to not set NETLINK_CAP_ACK.

We don't check the return value of setsockopt(), as any capped
message will have NLM_F_CAPPED set in nlmsg_flags.

NETLINK_CAP_ACK was introduced in Linux v4.3 commit 0a6a3a23ea6e
("netlink: add NETLINK_CAP_ACK socket option"), and so AFAICT it
doesn't need to be added to netlink-sys.h.

[1] https://docs.kernel.org/userspace-api/netlink/intro.html

Signed-off-by: Asbjørn Sloth Tønnesen <[email protected]>
---
 sysdep/linux/netlink.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c
index 4268244a0..c9eedf8a4 100644
--- a/sysdep/linux/netlink.c
+++ b/sysdep/linux/netlink.c
@@ -67,6 +67,14 @@ static linpool *nl_linpool;
 static struct nl_sock nl_scan = {.fd = -1};    /* Netlink socket for 
synchronous scan */
 static struct nl_sock nl_req  = {.fd = -1};    /* Netlink socket for requests 
*/
 
+static void
+nl_set_cap_ack(struct nl_sock *nl UNUSED, int val UNUSED)
+{
+#ifdef SOL_NETLINK
+  setsockopt(nl->fd, SOL_NETLINK, NETLINK_CAP_ACK, &val, sizeof(val));
+#endif
+}
+
 static void
 nl_open_sock(struct nl_sock *nl)
 {
@@ -79,6 +87,8 @@ nl_open_sock(struct nl_sock *nl)
       nl->rx_buffer = xmalloc(NL_RX_SIZE);
       nl->last_hdr = NULL;
       nl->last_size = 0;
+
+      nl_set_cap_ack(nl, 1);
     }
 }
 
-- 
2.51.0

Reply via email to