30
30
#define MAX_STRERR_LEN 256
31
31
#define MAX_TEST_NAME 80
32
32
33
+ #define __always_unused __attribute__((__unused__))
34
+
33
35
#define _FAIL (errnum , fmt ...) \
34
36
({ \
35
37
error_at_line(0, (errnum), __func__, __LINE__, fmt); \
@@ -321,7 +323,8 @@ static int socket_loopback(int family, int sotype)
321
323
return socket_loopback_reuseport (family , sotype , -1 );
322
324
}
323
325
324
- static void test_insert_invalid (int family , int sotype , int mapfd )
326
+ static void test_insert_invalid (struct test_sockmap_listen * skel __always_unused ,
327
+ int family , int sotype , int mapfd )
325
328
{
326
329
u32 key = 0 ;
327
330
u64 value ;
@@ -338,7 +341,8 @@ static void test_insert_invalid(int family, int sotype, int mapfd)
338
341
FAIL_ERRNO ("map_update: expected EBADF" );
339
342
}
340
343
341
- static void test_insert_opened (int family , int sotype , int mapfd )
344
+ static void test_insert_opened (struct test_sockmap_listen * skel __always_unused ,
345
+ int family , int sotype , int mapfd )
342
346
{
343
347
u32 key = 0 ;
344
348
u64 value ;
@@ -359,7 +363,8 @@ static void test_insert_opened(int family, int sotype, int mapfd)
359
363
xclose (s );
360
364
}
361
365
362
- static void test_insert_bound (int family , int sotype , int mapfd )
366
+ static void test_insert_bound (struct test_sockmap_listen * skel __always_unused ,
367
+ int family , int sotype , int mapfd )
363
368
{
364
369
struct sockaddr_storage addr ;
365
370
socklen_t len ;
@@ -386,7 +391,8 @@ static void test_insert_bound(int family, int sotype, int mapfd)
386
391
xclose (s );
387
392
}
388
393
389
- static void test_insert (int family , int sotype , int mapfd )
394
+ static void test_insert (struct test_sockmap_listen * skel __always_unused ,
395
+ int family , int sotype , int mapfd )
390
396
{
391
397
u64 value ;
392
398
u32 key ;
@@ -402,7 +408,8 @@ static void test_insert(int family, int sotype, int mapfd)
402
408
xclose (s );
403
409
}
404
410
405
- static void test_delete_after_insert (int family , int sotype , int mapfd )
411
+ static void test_delete_after_insert (struct test_sockmap_listen * skel __always_unused ,
412
+ int family , int sotype , int mapfd )
406
413
{
407
414
u64 value ;
408
415
u32 key ;
@@ -419,7 +426,8 @@ static void test_delete_after_insert(int family, int sotype, int mapfd)
419
426
xclose (s );
420
427
}
421
428
422
- static void test_delete_after_close (int family , int sotype , int mapfd )
429
+ static void test_delete_after_close (struct test_sockmap_listen * skel __always_unused ,
430
+ int family , int sotype , int mapfd )
423
431
{
424
432
int err , s ;
425
433
u64 value ;
@@ -442,7 +450,8 @@ static void test_delete_after_close(int family, int sotype, int mapfd)
442
450
FAIL_ERRNO ("map_delete: expected EINVAL/EINVAL" );
443
451
}
444
452
445
- static void test_lookup_after_insert (int family , int sotype , int mapfd )
453
+ static void test_lookup_after_insert (struct test_sockmap_listen * skel __always_unused ,
454
+ int family , int sotype , int mapfd )
446
455
{
447
456
u64 cookie , value ;
448
457
socklen_t len ;
@@ -470,7 +479,8 @@ static void test_lookup_after_insert(int family, int sotype, int mapfd)
470
479
xclose (s );
471
480
}
472
481
473
- static void test_lookup_after_delete (int family , int sotype , int mapfd )
482
+ static void test_lookup_after_delete (struct test_sockmap_listen * skel __always_unused ,
483
+ int family , int sotype , int mapfd )
474
484
{
475
485
int err , s ;
476
486
u64 value ;
@@ -493,7 +503,8 @@ static void test_lookup_after_delete(int family, int sotype, int mapfd)
493
503
xclose (s );
494
504
}
495
505
496
- static void test_lookup_32_bit_value (int family , int sotype , int mapfd )
506
+ static void test_lookup_32_bit_value (struct test_sockmap_listen * skel __always_unused ,
507
+ int family , int sotype , int mapfd )
497
508
{
498
509
u32 key , value32 ;
499
510
int err , s ;
@@ -523,7 +534,8 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd)
523
534
xclose (s );
524
535
}
525
536
526
- static void test_update_existing (int family , int sotype , int mapfd )
537
+ static void test_update_existing (struct test_sockmap_listen * skel __always_unused ,
538
+ int family , int sotype , int mapfd )
527
539
{
528
540
int s1 , s2 ;
529
541
u64 value ;
@@ -551,7 +563,7 @@ static void test_update_existing(int family, int sotype, int mapfd)
551
563
/* Exercise the code path where we destroy child sockets that never
552
564
* got accept()'ed, aka orphans, when parent socket gets closed.
553
565
*/
554
- static void test_destroy_orphan_child (int family , int sotype , int mapfd )
566
+ static void do_destroy_orphan_child (int family , int sotype , int mapfd )
555
567
{
556
568
struct sockaddr_storage addr ;
557
569
socklen_t len ;
@@ -582,10 +594,38 @@ static void test_destroy_orphan_child(int family, int sotype, int mapfd)
582
594
xclose (s );
583
595
}
584
596
597
+ static void test_destroy_orphan_child (struct test_sockmap_listen * skel ,
598
+ int family , int sotype , int mapfd )
599
+ {
600
+ int msg_verdict = bpf_program__fd (skel -> progs .prog_msg_verdict );
601
+ int skb_verdict = bpf_program__fd (skel -> progs .prog_skb_verdict );
602
+ const struct test {
603
+ int progfd ;
604
+ enum bpf_attach_type atype ;
605
+ } tests [] = {
606
+ { -1 , -1 },
607
+ { msg_verdict , BPF_SK_MSG_VERDICT },
608
+ { skb_verdict , BPF_SK_SKB_VERDICT },
609
+ };
610
+ const struct test * t ;
611
+
612
+ for (t = tests ; t < tests + ARRAY_SIZE (tests ); t ++ ) {
613
+ if (t -> progfd != -1 &&
614
+ xbpf_prog_attach (t -> progfd , mapfd , t -> atype , 0 ) != 0 )
615
+ return ;
616
+
617
+ do_destroy_orphan_child (family , sotype , mapfd );
618
+
619
+ if (t -> progfd != -1 )
620
+ xbpf_prog_detach2 (t -> progfd , mapfd , t -> atype );
621
+ }
622
+ }
623
+
585
624
/* Perform a passive open after removing listening socket from SOCKMAP
586
625
* to ensure that callbacks get restored properly.
587
626
*/
588
- static void test_clone_after_delete (int family , int sotype , int mapfd )
627
+ static void test_clone_after_delete (struct test_sockmap_listen * skel __always_unused ,
628
+ int family , int sotype , int mapfd )
589
629
{
590
630
struct sockaddr_storage addr ;
591
631
socklen_t len ;
@@ -621,7 +661,8 @@ static void test_clone_after_delete(int family, int sotype, int mapfd)
621
661
* SOCKMAP, but got accept()'ed only after the parent has been removed
622
662
* from SOCKMAP, gets cloned without parent psock state or callbacks.
623
663
*/
624
- static void test_accept_after_delete (int family , int sotype , int mapfd )
664
+ static void test_accept_after_delete (struct test_sockmap_listen * skel __always_unused ,
665
+ int family , int sotype , int mapfd )
625
666
{
626
667
struct sockaddr_storage addr ;
627
668
const u32 zero = 0 ;
@@ -675,7 +716,8 @@ static void test_accept_after_delete(int family, int sotype, int mapfd)
675
716
/* Check that child socket that got created and accepted while parent
676
717
* was in a SOCKMAP is cloned without parent psock state or callbacks.
677
718
*/
678
- static void test_accept_before_delete (int family , int sotype , int mapfd )
719
+ static void test_accept_before_delete (struct test_sockmap_listen * skel __always_unused ,
720
+ int family , int sotype , int mapfd )
679
721
{
680
722
struct sockaddr_storage addr ;
681
723
const u32 zero = 0 , one = 1 ;
@@ -784,7 +826,8 @@ static void *connect_accept_thread(void *arg)
784
826
return NULL ;
785
827
}
786
828
787
- static void test_syn_recv_insert_delete (int family , int sotype , int mapfd )
829
+ static void test_syn_recv_insert_delete (struct test_sockmap_listen * skel __always_unused ,
830
+ int family , int sotype , int mapfd )
788
831
{
789
832
struct connect_accept_ctx ctx = { 0 };
790
833
struct sockaddr_storage addr ;
@@ -847,7 +890,8 @@ static void *listen_thread(void *arg)
847
890
return NULL ;
848
891
}
849
892
850
- static void test_race_insert_listen (int family , int socktype , int mapfd )
893
+ static void test_race_insert_listen (struct test_sockmap_listen * skel __always_unused ,
894
+ int family , int socktype , int mapfd )
851
895
{
852
896
struct connect_accept_ctx ctx = { 0 };
853
897
const u32 zero = 0 ;
@@ -1473,7 +1517,8 @@ static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map,
1473
1517
int family , int sotype )
1474
1518
{
1475
1519
const struct op_test {
1476
- void (* fn )(int family , int sotype , int mapfd );
1520
+ void (* fn )(struct test_sockmap_listen * skel ,
1521
+ int family , int sotype , int mapfd );
1477
1522
const char * name ;
1478
1523
int sotype ;
1479
1524
} tests [] = {
@@ -1520,7 +1565,7 @@ static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map,
1520
1565
if (!test__start_subtest (s ))
1521
1566
continue ;
1522
1567
1523
- t -> fn (family , sotype , map_fd );
1568
+ t -> fn (skel , family , sotype , map_fd );
1524
1569
test_ops_cleanup (map );
1525
1570
}
1526
1571
}
0 commit comments