Skip to content

Commit f95fce1

Browse files
qsnkuba-moo
authored andcommitted
selftests: net: tls: add tests for cmsg vs MSG_MORE
We don't have a test to check that MSG_MORE won't let us merge records of different types across sendmsg calls. Add new tests that check: - MSG_MORE is only allowed for DATA records - a pending DATA record gets closed and pushed before a non-DATA record is processed Signed-off-by: Sabrina Dubroca <[email protected]> Link: https://patch.msgid.link/b34feeadefe8a997f068d5ed5617afd0072df3c0.1760432043.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7f846c6 commit f95fce1

File tree

1 file changed

+34
-0
lines changed
  • tools/testing/selftests/net

1 file changed

+34
-0
lines changed

tools/testing/selftests/net/tls.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,40 @@ TEST_F(tls, msg_more)
564564
EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
565565
}
566566

567+
TEST_F(tls, cmsg_msg_more)
568+
{
569+
char *test_str = "test_read";
570+
char record_type = 100;
571+
int send_len = 10;
572+
573+
/* we don't allow MSG_MORE with non-DATA records */
574+
EXPECT_EQ(tls_send_cmsg(self->fd, record_type, test_str, send_len,
575+
MSG_MORE), -1);
576+
EXPECT_EQ(errno, EINVAL);
577+
}
578+
579+
TEST_F(tls, msg_more_then_cmsg)
580+
{
581+
char *test_str = "test_read";
582+
char record_type = 100;
583+
int send_len = 10;
584+
char buf[10 * 2];
585+
int ret;
586+
587+
EXPECT_EQ(send(self->fd, test_str, send_len, MSG_MORE), send_len);
588+
EXPECT_EQ(recv(self->cfd, buf, send_len, MSG_DONTWAIT), -1);
589+
590+
ret = tls_send_cmsg(self->fd, record_type, test_str, send_len, 0);
591+
EXPECT_EQ(ret, send_len);
592+
593+
/* initial DATA record didn't get merged with the non-DATA record */
594+
EXPECT_EQ(recv(self->cfd, buf, send_len * 2, 0), send_len);
595+
596+
EXPECT_EQ(tls_recv_cmsg(_metadata, self->cfd, record_type,
597+
buf, sizeof(buf), MSG_WAITALL),
598+
send_len);
599+
}
600+
567601
TEST_F(tls, msg_more_unsent)
568602
{
569603
char const *test_str = "test_read";

0 commit comments

Comments
 (0)