Skip to contentSkip to conversation

bpf: tcp_bpf_recvmsg should return EAGAIN when nonblocking and no data

PATCH Applied John Fastabend 3 participants 4 messages Oct 30, 2018 – Oct 31, 2018

Subsystems (4)
lore
Share & tools
lore

John Fastabend

author maintainer
#0 lore raw

PATCH 1/1 bpf: tcp_bpf_recvmsg should return EAGAIN when nonblocking and no data

We return 0 in the case of a nonblocking socket that has no data available. However, this is incorrect and may confuse applications. After this patch we do the correct thing and return the error EAGAIN.

Quoting return codes from recvmsg manpage,

EAGAIN or EWOULDBLOCK
The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.

---
 net/ipv4/tcp_bpf.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/tcp_bpf.c +1 -0
index b7918d4..3b45fe5 100644
@@ -145,6 +145,7 @@ int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 			ret = err;
 			goto out;
 		}
+		copied = -EAGAIN;
 	}
 	ret = copied;
 out:
Signature · 1 line
1.9.1
author maintainer
#1 lore raw
Quoted 7 lines · John Fastabend

We return 0 in the case of a nonblocking socket that has no data available. However, this is incorrect and may confuse applications. After this patch we do the correct thing and return the error EAGAIN.

Quoting return codes from recvmsg manpage,

Quoted 7 lines

EAGAIN or EWOULDBLOCK
The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.

---

Add fixes tag.

Fixes 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Acked-by
#2 lore raw
Quoted 7 lines · John Fastabend
Quoted 5 lines · John Fastabend

We return 0 in the case of a nonblocking socket that has no data available. However, this is incorrect and may confuse applications. After this patch we do the correct thing and return the error EAGAIN.

Quoted 8 lines
Quoted 8 lines

Quoting return codes from recvmsg manpage,

EAGAIN or EWOULDBLOCK
The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.

Quoted 9 lines
Quoted 1 line

---

Add fixes tag.

Fixes 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
#3 lore raw
In reply to John Fastabend
Quoted 5 lines · John Fastabend

We return 0 in the case of a nonblocking socket that has no data available. However, this is incorrect and may confuse applications. After this patch we do the correct thing and return the error EAGAIN.

Quoted 8 lines

Quoting return codes from recvmsg manpage,

EAGAIN or EWOULDBLOCK
The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.

Applied to bpf, thanks!