Skip to content

Commit 8d3c4b6

Browse files
mmhalKernel Patches Daemon
authored andcommitted
selftests/bpf: sockmap_redir: Simplify try_recv()
try_recv() was meant to support both @expect_success cases, but all the callers use @expect_success=false anyway. Drop the unused logic and fold in MSG_DONTWAIT. Adapt callers. Subtle change here: recv() return value of 0 will also be considered (an unexpected) success. Signed-off-by: Michal Luczaj <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]>
1 parent cd9a59e commit 8d3c4b6

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_redir.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,14 @@ static void get_redir_params(struct redir_spec *redir,
144144
*redirect_flags = 0;
145145
}
146146

147-
static void try_recv(const char *prefix, int fd, int flags, bool expect_success)
147+
static void fail_recv(const char *prefix, int fd, int more_flags)
148148
{
149149
ssize_t n;
150150
char buf;
151151

152-
errno = 0;
153-
n = recv(fd, &buf, 1, flags);
154-
if (n < 0 && expect_success)
155-
FAIL_ERRNO("%s: unexpected failure: retval=%zd", prefix, n);
156-
if (!n && !expect_success)
157-
FAIL("%s: expected failure: retval=%zd", prefix, n);
152+
n = recv(fd, &buf, 1, MSG_DONTWAIT | more_flags);
153+
if (n >= 0)
154+
FAIL("%s: unexpected success: retval=%zd", prefix, n);
158155
}
159156

160157
static void handle_unsupported(int sd_send, int sd_peer, int sd_in, int sd_out,
@@ -188,13 +185,13 @@ static void handle_unsupported(int sd_send, int sd_peer, int sd_in, int sd_out,
188185
}
189186

190187
/* Ensure queues are empty */
191-
try_recv("bpf.recv(sd_send)", sd_send, MSG_DONTWAIT, false);
188+
fail_recv("bpf.recv(sd_send)", sd_send, 0);
192189
if (sd_in != sd_send)
193-
try_recv("bpf.recv(sd_in)", sd_in, MSG_DONTWAIT, false);
190+
fail_recv("bpf.recv(sd_in)", sd_in, 0);
194191

195-
try_recv("bpf.recv(sd_out)", sd_out, MSG_DONTWAIT, false);
192+
fail_recv("bpf.recv(sd_out)", sd_out, 0);
196193
if (sd_recv != sd_out)
197-
try_recv("bpf.recv(sd_recv)", sd_recv, MSG_DONTWAIT, false);
194+
fail_recv("bpf.recv(sd_recv)", sd_recv, 0);
198195
}
199196

200197
static void test_send_redir_recv(int sd_send, int send_flags, int sd_peer,
@@ -257,15 +254,13 @@ static void test_send_redir_recv(int sd_send, int send_flags, int sd_peer,
257254

258255
if (send_flags & MSG_OOB) {
259256
/* Fail reading OOB while in sockmap */
260-
try_recv("bpf.recv(sd_out, MSG_OOB)", sd_out,
261-
MSG_OOB | MSG_DONTWAIT, false);
257+
fail_recv("bpf.recv(sd_out, MSG_OOB)", sd_out, MSG_OOB);
262258

263259
/* Remove sd_out from sockmap */
264260
xbpf_map_delete_elem(maps->out, &u32(0));
265261

266262
/* Check that OOB was dropped on redirect */
267-
try_recv("recv(sd_out, MSG_OOB)", sd_out,
268-
MSG_OOB | MSG_DONTWAIT, false);
263+
fail_recv("recv(sd_out, MSG_OOB)", sd_out, MSG_OOB);
269264

270265
goto del_in;
271266
}

0 commit comments

Comments
 (0)