summaryrefslogtreecommitdiff
path: root/lib/nl.c
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 /lib/nl.c
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 'lib/nl.c')
-rw-r--r--lib/nl.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/nl.c b/lib/nl.c
index a45c3ead..f2c427b7 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -672,7 +672,8 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
if (!buf || !nla)
return -NLE_INVAL;
- if (sk->s_flags & NL_MSG_PEEK)
+ if ( (sk->s_flags & NL_MSG_PEEK)
+ || (!(sk->s_flags & NL_MSG_PEEK_EXPLICIT) && sk->s_bufsize == 0))
flags |= MSG_PEEK | MSG_TRUNC;
if (page_size == 0)
@@ -736,7 +737,7 @@ retry:
void *tmp;
/* respond with error to an incomplete message */
- if (!(sk->s_flags & NL_MSG_PEEK)) {
+ if (flags == 0) {
retval = -NLE_MSG_TRUNC;
goto abort;
}