@@ -306,6 +306,80 @@ static void test_sockmap_ktls_tx_cork(int family, int sotype, bool push)
306
306
test_sockmap_ktls__destroy (skel );
307
307
}
308
308
309
+ static void test_sockmap_ktls_tx_no_buf (int family , int sotype , bool push )
310
+ {
311
+ int c = 0 , p = 0 , one = 1 , two = 2 ;
312
+ struct test_sockmap_ktls * skel ;
313
+ unsigned char * data = NULL ;
314
+ struct msghdr msg = {0 };
315
+ struct iovec iov [2 ];
316
+ int prog_fd , map_fd ;
317
+ int txrx_buf = 1024 ;
318
+ int iov_length = 8192 ;
319
+ int err ;
320
+
321
+ skel = test_sockmap_ktls__open_and_load ();
322
+ if (!ASSERT_TRUE (skel , "open ktls skel" ))
323
+ return ;
324
+
325
+ err = create_pair (family , sotype , & c , & p );
326
+ if (!ASSERT_OK (err , "create_pair()" ))
327
+ goto out ;
328
+
329
+ err = setsockopt (c , SOL_SOCKET , SO_RCVBUFFORCE , & txrx_buf , sizeof (int ));
330
+ err |= setsockopt (p , SOL_SOCKET , SO_SNDBUFFORCE , & txrx_buf , sizeof (int ));
331
+ if (!ASSERT_OK (err , "set buf limit" ))
332
+ goto out ;
333
+
334
+ prog_fd = bpf_program__fd (skel -> progs .prog_sk_policy_redir );
335
+ map_fd = bpf_map__fd (skel -> maps .sock_map );
336
+
337
+ err = bpf_prog_attach (prog_fd , map_fd , BPF_SK_MSG_VERDICT , 0 );
338
+ if (!ASSERT_OK (err , "bpf_prog_attach sk msg" ))
339
+ goto out ;
340
+
341
+ err = bpf_map_update_elem (map_fd , & one , & c , BPF_NOEXIST );
342
+ if (!ASSERT_OK (err , "bpf_map_update_elem(c)" ))
343
+ goto out ;
344
+
345
+ err = bpf_map_update_elem (map_fd , & two , & p , BPF_NOEXIST );
346
+ if (!ASSERT_OK (err , "bpf_map_update_elem(p)" ))
347
+ goto out ;
348
+
349
+ skel -> bss -> apply_bytes = 1024 ;
350
+
351
+ err = init_ktls_pairs (c , p );
352
+ if (!ASSERT_OK (err , "init_ktls_pairs(c, p)" ))
353
+ goto out ;
354
+
355
+ data = calloc (iov_length , sizeof (char ));
356
+ if (!data )
357
+ goto out ;
358
+
359
+ iov [0 ].iov_base = data ;
360
+ iov [0 ].iov_len = iov_length ;
361
+ iov [1 ].iov_base = data ;
362
+ iov [1 ].iov_len = iov_length ;
363
+ msg .msg_iov = iov ;
364
+ msg .msg_iovlen = 2 ;
365
+
366
+ for (;;) {
367
+ err = sendmsg (c , & msg , MSG_DONTWAIT );
368
+ if (err <= 0 )
369
+ break ;
370
+ }
371
+
372
+ out :
373
+ if (data )
374
+ free (data );
375
+ if (c )
376
+ close (c );
377
+ if (p )
378
+ close (p );
379
+
380
+ test_sockmap_ktls__destroy (skel );
381
+ }
382
+
309
383
static void run_tests (int family , enum bpf_map_type map_type )
310
384
{
311
385
int map ;
@@ -330,6 +404,8 @@ static void run_ktls_test(int family, int sotype)
330
404
test_sockmap_ktls_tx_cork (family , sotype , false);
331
405
if (test__start_subtest ("tls tx cork with push" ))
332
406
test_sockmap_ktls_tx_cork (family , sotype , true);
407
+ if (test__start_subtest ("tls tx egress with no buf" ))
408
+ test_sockmap_ktls_tx_no_buf (family , sotype , true);
333
409
}
334
410
335
411
void test_sockmap_ktls (void )
0 commit comments