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 <sd@queasysnail.net>
Link: https://patch.msgid.link/b34feeadefe8a997f068d5ed5617afd0072df3c0.1760432043.git.sd@queasysnail.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Sabrina Dubroca
2025-10-14 11:17:01 +02:00
committed by Jakub Kicinski
parent 7f846c65ca
commit f95fce1e95

View File

@@ -564,6 +564,40 @@ TEST_F(tls, msg_more)
EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
}
TEST_F(tls, cmsg_msg_more)
{
char *test_str = "test_read";
char record_type = 100;
int send_len = 10;
/* we don't allow MSG_MORE with non-DATA records */
EXPECT_EQ(tls_send_cmsg(self->fd, record_type, test_str, send_len,
MSG_MORE), -1);
EXPECT_EQ(errno, EINVAL);
}
TEST_F(tls, msg_more_then_cmsg)
{
char *test_str = "test_read";
char record_type = 100;
int send_len = 10;
char buf[10 * 2];
int ret;
EXPECT_EQ(send(self->fd, test_str, send_len, MSG_MORE), send_len);
EXPECT_EQ(recv(self->cfd, buf, send_len, MSG_DONTWAIT), -1);
ret = tls_send_cmsg(self->fd, record_type, test_str, send_len, 0);
EXPECT_EQ(ret, send_len);
/* initial DATA record didn't get merged with the non-DATA record */
EXPECT_EQ(recv(self->cfd, buf, send_len * 2, 0), send_len);
EXPECT_EQ(tls_recv_cmsg(_metadata, self->cfd, record_type,
buf, sizeof(buf), MSG_WAITALL),
send_len);
}
TEST_F(tls, msg_more_unsent)
{
char const *test_str = "test_read";