@@ -314,6 +314,95 @@ static void test_sockmap_ktls_tx_no_buf(int family, int sotype, bool push)
314
314
test_sockmap_ktls__destroy (skel );
315
315
}
316
316
317
+ static void test_sockmap_ktls_tx_pop (int family , int sotype )
318
+ {
319
+ char msg [37 ] = "0123456789abcdefghijklmnopqrstuvwxyz\0" ;
320
+ int c = 0 , p = 0 , one = 1 , sent , recvd ;
321
+ struct test_sockmap_ktls * skel ;
322
+ int prog_fd , map_fd ;
323
+ char rcv [50 ] = {0 };
324
+ int err ;
325
+ int i , m , r ;
326
+
327
+ skel = test_sockmap_ktls__open_and_load ();
328
+ if (!ASSERT_TRUE (skel , "open ktls skel" ))
329
+ return ;
330
+
331
+ err = create_pair (family , sotype , & c , & p );
332
+ if (!ASSERT_OK (err , "create_pair()" ))
333
+ goto out ;
334
+
335
+ prog_fd = bpf_program__fd (skel -> progs .prog_sk_policy );
336
+ map_fd = bpf_map__fd (skel -> maps .sock_map );
337
+
338
+ err = bpf_prog_attach (prog_fd , map_fd , BPF_SK_MSG_VERDICT , 0 );
339
+ if (!ASSERT_OK (err , "bpf_prog_attach sk msg" ))
340
+ goto out ;
341
+
342
+ err = bpf_map_update_elem (map_fd , & one , & c , BPF_NOEXIST );
343
+ if (!ASSERT_OK (err , "bpf_map_update_elem(c)" ))
344
+ goto out ;
345
+
346
+ err = init_ktls_pairs (c , p );
347
+ if (!ASSERT_OK (err , "init_ktls_pairs(c, p)" ))
348
+ goto out ;
349
+
350
+ struct {
351
+ int pop_start ;
352
+ int pop_len ;
353
+ } pop_policy [] = {
354
+ /* trim the start */
355
+ {0 , 2 },
356
+ {0 , 10 },
357
+ {1 , 2 },
358
+ {1 , 10 },
359
+ /* trim the end */
360
+ {35 , 2 },
361
+ /* New entries should be added before this line */
362
+ {-1 , -1 },
363
+ };
364
+
365
+ i = 0 ;
366
+ while (pop_policy [i ].pop_start >= 0 ) {
367
+ skel -> bss -> pop_start = pop_policy [i ].pop_start ;
368
+ skel -> bss -> pop_end = pop_policy [i ].pop_len ;
369
+
370
+ sent = send (c , msg , sizeof (msg ), 0 );
371
+ if (!ASSERT_EQ (sent , sizeof (msg ), "send(msg)" ))
372
+ goto out ;
373
+
374
+ recvd = recv_timeout (p , rcv , sizeof (rcv ), MSG_DONTWAIT , 1 );
375
+ if (!ASSERT_EQ (recvd , sizeof (msg ) - pop_policy [i ].pop_len , "pop len mismatch" ))
376
+ goto out ;
377
+
378
+ /* verify the data
379
+ * msg: 0123456789a bcdefghij klmnopqrstuvwxyz
380
+ * | |
381
+ * popped data
382
+ */
383
+ for (m = 0 , r = 0 ; m < sizeof (msg );) {
384
+ /* skip checking the data that has been popped */
385
+ if (m >= pop_policy [i ].pop_start &&
386
+ m <= pop_policy [i ].pop_start + pop_policy [i ].pop_len - 1 ) {
387
+ m ++ ;
388
+ continue ;
389
+ }
390
+
391
+ if (!ASSERT_EQ (msg [m ], rcv [r ], "data mismatch" ))
392
+ goto out ;
393
+ m ++ ;
394
+ r ++ ;
395
+ }
396
+ i ++ ;
397
+ }
398
+ out :
399
+ if (c )
400
+ close (c );
401
+ if (p )
402
+ close (p );
403
+ test_sockmap_ktls__destroy (skel );
404
+ }
405
+
317
406
static void run_tests (int family , enum bpf_map_type map_type )
318
407
{
319
408
int map ;
@@ -338,6 +427,8 @@ static void run_ktls_test(int family, int sotype)
338
427
test_sockmap_ktls_tx_cork (family , sotype , true);
339
428
if (test__start_subtest ("tls tx egress with no buf" ))
340
429
test_sockmap_ktls_tx_no_buf (family , sotype , true);
430
+ if (test__start_subtest ("tls tx with pop" ))
431
+ test_sockmap_ktls_tx_pop (family , sotype );
341
432
}
342
433
343
434
void test_sockmap_ktls (void )
0 commit comments