summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-11-30 15:09:41 +0100
committerThomas Haller <thaller@redhat.com>2016-11-30 15:40:26 +0100
commit55ea6e6b6cd805f441b410971c9dd7575e783ef4 (patch)
tree674fa1461f678f54aa8750c72ffcaaf69945f559 /include
parent6f9620721200d171d6a317573b3c1c00141f036b (diff)
downloadlibnl-55ea6e6b6cd805f441b410971c9dd7575e783ef4.tar.gz
lib: use MSG_PEEK by default for nl_recvmsgs()
The MSG_PEEK API of recvmsg() should be avoid because it requires an additional syscall. But worse is to choose a too small buffer size and failing to receive the message. A user who is aware of the issue can avoid MSG_PEEK by either nl_socket_disable_msg_peek()/nl_socket_enable_msg_peek() or by setting a buffer size via nl_socket_set_msg_buf_size(). By default however we now use MSG_PEEK. This is more important since commit 90c6ebec9bd7a where the link dump request can be rather large. Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/netlink-private/types.h3
-rw-r--r--include/netlink/utils.h15
2 files changed, 17 insertions, 1 deletions
diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h
index d8c0e3fd..1b19b584 100644
--- a/include/netlink-private/types.h
+++ b/include/netlink-private/types.h
@@ -29,7 +29,8 @@
#define NL_SOCK_PASSCRED (1<<1)
#define NL_OWN_PORT (1<<2)
#define NL_MSG_PEEK (1<<3)
-#define NL_NO_AUTO_ACK (1<<4)
+#define NL_MSG_PEEK_EXPLICIT (1<<4)
+#define NL_NO_AUTO_ACK (1<<5)
#define NL_MSG_CRED_PRESENT 1
diff --git a/include/netlink/utils.h b/include/netlink/utils.h
index 6f984e18..a2ffe4b1 100644
--- a/include/netlink/utils.h
+++ b/include/netlink/utils.h
@@ -246,6 +246,21 @@ enum {
NL_CAPABILITY_LINK_BUILD_ADD_REQUEST_SET_CHANGE = 23,
#define NL_CAPABILITY_LINK_BUILD_ADD_REQUEST_SET_CHANGE NL_CAPABILITY_LINK_BUILD_ADD_REQUEST_SET_CHANGE
+ /* Older versions of libnl3 would not use MSG_PEEK for nl_recvmsgs() unless calling
+ * nl_socket_enable_msg_peek(). Instead, the user had to specify the buffer size via
+ * nl_socket_set_msg_buf_size(), which in turn would default to 4*getpagesize().
+ *
+ * The default value might not be large enough, so users who were not aware of the
+ * problem easily ended up using a too small receive buffer. Usually, one wants to
+ * avoid MSG_PEEK for recvmsg() because it requires an additional syscall.
+ *
+ * Now, as indicated by this capability, nl_recvmsgs() would use MSG_PEEK by default. The
+ * user still can explicitly disable MSG_PEEK by calling nl_socket_disable_msg_peek() or
+ * by setting the nl_socket_set_msg_buf_size() to a non-zero value.
+ */
+ NL_CAPABILITY_NL_RECVMSGS_PEEK_BY_DEFAULT = 24,
+#define NL_CAPABILITY_NL_RECVMSGS_PEEK_BY_DEFAULT NL_CAPABILITY_NL_RECVMSGS_PEEK_BY_DEFAULT
+
__NL_CAPABILITY_MAX,
NL_CAPABILITY_MAX = (__NL_CAPABILITY_MAX - 1),
#define NL_CAPABILITY_MAX NL_CAPABILITY_MAX