Skip to content

Commit 0e6fbe3

Browse files
ptrivedidavem330
authored andcommitted
net/tls(TLS_SW): Add selftest for 'chunked' sendfile test
This selftest tests for cases where sendfile's 'count' parameter is provided with a size greater than the intended file size. Motivation: When sendfile is provided with 'count' parameter value that is greater than the size of the file, kTLS example fails to send the file correctly. Last chunk of the file is not sent, and the data integrity is compromised. The reason is that the last chunk has MSG_MORE flag set because of which it gets added to pending records, but is not pushed. Note that if user space were to send SSL_shutdown control message, pending records would get flushed and the issue would not happen. So a shutdown control message following sendfile can mask the issue. Signed-off-by: Pooja Trivedi <[email protected]> Signed-off-by: Mallesham Jatharkonda <[email protected]> Signed-off-by: Josh Tway <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6b1ad5a commit 0e6fbe3

File tree

1 file changed

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

1 file changed

+58
-0
lines changed

tools/testing/selftests/net/tls.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,64 @@ TEST_F(tls, send_then_sendfile)
213213
EXPECT_EQ(recv(self->cfd, buf, st.st_size, MSG_WAITALL), st.st_size);
214214
}
215215

216+
static void chunked_sendfile(struct __test_metadata *_metadata,
217+
struct _test_data_tls *self,
218+
uint16_t chunk_size,
219+
uint16_t extra_payload_size)
220+
{
221+
char buf[TLS_PAYLOAD_MAX_LEN];
222+
uint16_t test_payload_size;
223+
int size = 0;
224+
int ret;
225+
char filename[] = "/tmp/mytemp.XXXXXX";
226+
int fd = mkstemp(filename);
227+
off_t offset = 0;
228+
229+
unlink(filename);
230+
ASSERT_GE(fd, 0);
231+
EXPECT_GE(chunk_size, 1);
232+
test_payload_size = chunk_size + extra_payload_size;
233+
ASSERT_GE(TLS_PAYLOAD_MAX_LEN, test_payload_size);
234+
memset(buf, 1, test_payload_size);
235+
size = write(fd, buf, test_payload_size);
236+
EXPECT_EQ(size, test_payload_size);
237+
fsync(fd);
238+
239+
while (size > 0) {
240+
ret = sendfile(self->fd, fd, &offset, chunk_size);
241+
EXPECT_GE(ret, 0);
242+
size -= ret;
243+
}
244+
245+
EXPECT_EQ(recv(self->cfd, buf, test_payload_size, MSG_WAITALL),
246+
test_payload_size);
247+
248+
close(fd);
249+
}
250+
251+
TEST_F(tls, multi_chunk_sendfile)
252+
{
253+
chunked_sendfile(_metadata, self, 4096, 4096);
254+
chunked_sendfile(_metadata, self, 4096, 0);
255+
chunked_sendfile(_metadata, self, 4096, 1);
256+
chunked_sendfile(_metadata, self, 4096, 2048);
257+
chunked_sendfile(_metadata, self, 8192, 2048);
258+
chunked_sendfile(_metadata, self, 4096, 8192);
259+
chunked_sendfile(_metadata, self, 8192, 4096);
260+
chunked_sendfile(_metadata, self, 12288, 1024);
261+
chunked_sendfile(_metadata, self, 12288, 2000);
262+
chunked_sendfile(_metadata, self, 15360, 100);
263+
chunked_sendfile(_metadata, self, 15360, 300);
264+
chunked_sendfile(_metadata, self, 1, 4096);
265+
chunked_sendfile(_metadata, self, 2048, 4096);
266+
chunked_sendfile(_metadata, self, 2048, 8192);
267+
chunked_sendfile(_metadata, self, 4096, 8192);
268+
chunked_sendfile(_metadata, self, 1024, 12288);
269+
chunked_sendfile(_metadata, self, 2000, 12288);
270+
chunked_sendfile(_metadata, self, 100, 15360);
271+
chunked_sendfile(_metadata, self, 300, 15360);
272+
}
273+
216274
TEST_F(tls, recv_max)
217275
{
218276
unsigned int send_len = TLS_PAYLOAD_MAX_LEN;

0 commit comments

Comments
 (0)