Skip to content

Commit 436352e

Browse files
q2venPaolo Abeni
authored andcommitted
selftest: af_unix: Add SO_OOBINLINE test cases in msg_oob.c
When SO_OOBINLINE is enabled on a socket, MSG_OOB can be recv()ed without MSG_OOB flag, and ioctl(SIOCATMARK) will behaves differently. This patch adds some test cases for SO_OOBINLINE. Note the new test cases found two bugs in TCP. 1) After reading OOB data with non-inline mode, we can re-read the data by setting SO_OOBINLINE. # RUN msg_oob.no_peek.inline_oob_ahead_break ... # msg_oob.c:146:inline_oob_ahead_break:AF_UNIX :world # msg_oob.c:147:inline_oob_ahead_break:TCP :oworld # OK msg_oob.no_peek.inline_oob_ahead_break ok 14 msg_oob.no_peek.inline_oob_ahead_break 2) The head OOB data is dropped if SO_OOBINLINE is disabled if a new OOB data is queued. # RUN msg_oob.no_peek.inline_ex_oob_drop ... # msg_oob.c:171:inline_ex_oob_drop:AF_UNIX :x # msg_oob.c:172:inline_ex_oob_drop:TCP :y # msg_oob.c:146:inline_ex_oob_drop:AF_UNIX :y # msg_oob.c:147:inline_ex_oob_drop:TCP :Resource temporarily unavailable # OK msg_oob.no_peek.inline_ex_oob_drop ok 17 msg_oob.no_peek.inline_ex_oob_drop Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 36893ef commit 436352e

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

tools/testing/selftests/net/af_unix/msg_oob.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ static void __recvpair(struct __test_metadata *_metadata,
178178
}
179179
}
180180

181+
static void __setinlinepair(struct __test_metadata *_metadata,
182+
FIXTURE_DATA(msg_oob) *self)
183+
{
184+
int i, oob_inline = 1;
185+
186+
for (i = 0; i < 2; i++) {
187+
int ret;
188+
189+
ret = setsockopt(self->fd[i * 2 + 1], SOL_SOCKET, SO_OOBINLINE,
190+
&oob_inline, sizeof(oob_inline));
191+
ASSERT_EQ(ret, 0);
192+
}
193+
}
194+
181195
#define sendpair(buf, len, flags) \
182196
__sendpair(_metadata, self, buf, len, flags)
183197

@@ -191,6 +205,9 @@ static void __recvpair(struct __test_metadata *_metadata,
191205
expected_buf, expected_len, buf_len, flags); \
192206
} while (0)
193207

208+
#define setinlinepair() \
209+
__setinlinepair(_metadata, self)
210+
194211
#define tcp_incompliant \
195212
for (self->tcp_compliant = false; \
196213
self->tcp_compliant == false; \
@@ -304,4 +321,78 @@ TEST_F(msg_oob, ex_oob_ahead_break)
304321
recvpair("d", 1, 1, MSG_OOB);
305322
}
306323

324+
TEST_F(msg_oob, inline_oob)
325+
{
326+
setinlinepair();
327+
328+
sendpair("x", 1, MSG_OOB);
329+
330+
recvpair("", -EINVAL, 1, MSG_OOB);
331+
recvpair("x", 1, 1, 0);
332+
}
333+
334+
TEST_F(msg_oob, inline_oob_break)
335+
{
336+
setinlinepair();
337+
338+
sendpair("hello", 5, MSG_OOB);
339+
340+
recvpair("", -EINVAL, 1, MSG_OOB);
341+
recvpair("hell", 4, 5, 0); /* Break at OOB but not at ex-OOB. */
342+
recvpair("o", 1, 1, 0);
343+
}
344+
345+
TEST_F(msg_oob, inline_oob_ahead_break)
346+
{
347+
sendpair("hello", 5, MSG_OOB);
348+
sendpair("world", 5, 0);
349+
350+
recvpair("o", 1, 1, MSG_OOB);
351+
352+
setinlinepair();
353+
354+
recvpair("hell", 4, 9, 0); /* Break at OOB even with enough buffer. */
355+
356+
tcp_incompliant {
357+
recvpair("world", 5, 6, 0); /* TCP recv()s "oworld", ... "o" ??? */
358+
}
359+
}
360+
361+
TEST_F(msg_oob, inline_ex_oob_break)
362+
{
363+
sendpair("hello", 5, MSG_OOB);
364+
sendpair("wor", 3, MSG_OOB);
365+
sendpair("ld", 2, 0);
366+
367+
setinlinepair();
368+
369+
recvpair("hellowo", 7, 10, 0); /* Break at OOB but not at ex-OOB. */
370+
recvpair("rld", 3, 3, 0);
371+
}
372+
373+
TEST_F(msg_oob, inline_ex_oob_no_drop)
374+
{
375+
sendpair("x", 1, MSG_OOB);
376+
377+
setinlinepair();
378+
379+
sendpair("y", 1, MSG_OOB); /* TCP does NOT drops "x" at this moment. */
380+
381+
recvpair("x", 1, 1, 0);
382+
recvpair("y", 1, 1, 0);
383+
}
384+
385+
TEST_F(msg_oob, inline_ex_oob_drop)
386+
{
387+
sendpair("x", 1, MSG_OOB);
388+
sendpair("y", 1, MSG_OOB); /* TCP drops "x" at this moment. */
389+
390+
setinlinepair();
391+
392+
tcp_incompliant {
393+
recvpair("x", 1, 1, 0); /* TCP recv()s "y". */
394+
recvpair("y", 1, 1, 0); /* TCP returns -EAGAIN. */
395+
}
396+
}
397+
307398
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)