Skip to content

Commit d87d67f

Browse files
committed
selftests: tls: test splicing cmsgs
Make sure we correctly reject splicing non-data records. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 520493f commit d87d67f

File tree

1 file changed

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

1 file changed

+40
-0
lines changed

tools/testing/selftests/net/tls.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,46 @@ TEST_F(tls, splice_to_pipe)
639639
EXPECT_EQ(memcmp(mem_send, mem_recv, send_len), 0);
640640
}
641641

642+
TEST_F(tls, splice_cmsg_to_pipe)
643+
{
644+
char *test_str = "test_read";
645+
char record_type = 100;
646+
int send_len = 10;
647+
char buf[10];
648+
int p[2];
649+
650+
ASSERT_GE(pipe(p), 0);
651+
EXPECT_EQ(tls_send_cmsg(self->fd, 100, test_str, send_len, 0), 10);
652+
EXPECT_EQ(splice(self->cfd, NULL, p[1], NULL, send_len, 0), -1);
653+
EXPECT_EQ(errno, EINVAL);
654+
EXPECT_EQ(recv(self->cfd, buf, send_len, 0), -1);
655+
EXPECT_EQ(errno, EIO);
656+
EXPECT_EQ(tls_recv_cmsg(_metadata, self->cfd, record_type,
657+
buf, sizeof(buf), MSG_WAITALL),
658+
send_len);
659+
EXPECT_EQ(memcmp(test_str, buf, send_len), 0);
660+
}
661+
662+
TEST_F(tls, splice_dec_cmsg_to_pipe)
663+
{
664+
char *test_str = "test_read";
665+
char record_type = 100;
666+
int send_len = 10;
667+
char buf[10];
668+
int p[2];
669+
670+
ASSERT_GE(pipe(p), 0);
671+
EXPECT_EQ(tls_send_cmsg(self->fd, 100, test_str, send_len, 0), 10);
672+
EXPECT_EQ(recv(self->cfd, buf, send_len, 0), -1);
673+
EXPECT_EQ(errno, EIO);
674+
EXPECT_EQ(splice(self->cfd, NULL, p[1], NULL, send_len, 0), -1);
675+
EXPECT_EQ(errno, EINVAL);
676+
EXPECT_EQ(tls_recv_cmsg(_metadata, self->cfd, record_type,
677+
buf, sizeof(buf), MSG_WAITALL),
678+
send_len);
679+
EXPECT_EQ(memcmp(test_str, buf, send_len), 0);
680+
}
681+
642682
TEST_F(tls, recvmsg_single)
643683
{
644684
char const *test_str = "test_recvmsg_single";

0 commit comments

Comments
 (0)