3030#define MAX_STRERR_LEN 256
3131#define MAX_TEST_NAME 80
3232
33+ #define __always_unused __attribute__((__unused__))
34+
3335#define _FAIL (errnum , fmt ...) \
3436 ({ \
3537 error_at_line(0, (errnum), __func__, __LINE__, fmt); \
@@ -321,7 +323,8 @@ static int socket_loopback(int family, int sotype)
321323 return socket_loopback_reuseport (family , sotype , -1 );
322324}
323325
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 )
325328{
326329 u32 key = 0 ;
327330 u64 value ;
@@ -338,7 +341,8 @@ static void test_insert_invalid(int family, int sotype, int mapfd)
338341 FAIL_ERRNO ("map_update: expected EBADF" );
339342}
340343
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 )
342346{
343347 u32 key = 0 ;
344348 u64 value ;
@@ -359,7 +363,8 @@ static void test_insert_opened(int family, int sotype, int mapfd)
359363 xclose (s );
360364}
361365
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 )
363368{
364369 struct sockaddr_storage addr ;
365370 socklen_t len ;
@@ -386,7 +391,8 @@ static void test_insert_bound(int family, int sotype, int mapfd)
386391 xclose (s );
387392}
388393
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 )
390396{
391397 u64 value ;
392398 u32 key ;
@@ -402,7 +408,8 @@ static void test_insert(int family, int sotype, int mapfd)
402408 xclose (s );
403409}
404410
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 )
406413{
407414 u64 value ;
408415 u32 key ;
@@ -419,7 +426,8 @@ static void test_delete_after_insert(int family, int sotype, int mapfd)
419426 xclose (s );
420427}
421428
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 )
423431{
424432 int err , s ;
425433 u64 value ;
@@ -442,7 +450,8 @@ static void test_delete_after_close(int family, int sotype, int mapfd)
442450 FAIL_ERRNO ("map_delete: expected EINVAL/EINVAL" );
443451}
444452
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 )
446455{
447456 u64 cookie , value ;
448457 socklen_t len ;
@@ -470,7 +479,8 @@ static void test_lookup_after_insert(int family, int sotype, int mapfd)
470479 xclose (s );
471480}
472481
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 )
474484{
475485 int err , s ;
476486 u64 value ;
@@ -493,7 +503,8 @@ static void test_lookup_after_delete(int family, int sotype, int mapfd)
493503 xclose (s );
494504}
495505
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 )
497508{
498509 u32 key , value32 ;
499510 int err , s ;
@@ -523,7 +534,8 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd)
523534 xclose (s );
524535}
525536
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 )
527539{
528540 int s1 , s2 ;
529541 u64 value ;
@@ -551,7 +563,7 @@ static void test_update_existing(int family, int sotype, int mapfd)
551563/* Exercise the code path where we destroy child sockets that never
552564 * got accept()'ed, aka orphans, when parent socket gets closed.
553565 */
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 )
555567{
556568 struct sockaddr_storage addr ;
557569 socklen_t len ;
@@ -582,10 +594,38 @@ static void test_destroy_orphan_child(int family, int sotype, int mapfd)
582594 xclose (s );
583595}
584596
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+
585624/* Perform a passive open after removing listening socket from SOCKMAP
586625 * to ensure that callbacks get restored properly.
587626 */
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 )
589629{
590630 struct sockaddr_storage addr ;
591631 socklen_t len ;
@@ -621,7 +661,8 @@ static void test_clone_after_delete(int family, int sotype, int mapfd)
621661 * SOCKMAP, but got accept()'ed only after the parent has been removed
622662 * from SOCKMAP, gets cloned without parent psock state or callbacks.
623663 */
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 )
625666{
626667 struct sockaddr_storage addr ;
627668 const u32 zero = 0 ;
@@ -675,7 +716,8 @@ static void test_accept_after_delete(int family, int sotype, int mapfd)
675716/* Check that child socket that got created and accepted while parent
676717 * was in a SOCKMAP is cloned without parent psock state or callbacks.
677718 */
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 )
679721{
680722 struct sockaddr_storage addr ;
681723 const u32 zero = 0 , one = 1 ;
@@ -784,7 +826,8 @@ static void *connect_accept_thread(void *arg)
784826 return NULL ;
785827}
786828
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 )
788831{
789832 struct connect_accept_ctx ctx = { 0 };
790833 struct sockaddr_storage addr ;
@@ -847,7 +890,8 @@ static void *listen_thread(void *arg)
847890 return NULL ;
848891}
849892
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 )
851895{
852896 struct connect_accept_ctx ctx = { 0 };
853897 const u32 zero = 0 ;
@@ -1473,7 +1517,8 @@ static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map,
14731517 int family , int sotype )
14741518{
14751519 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 );
14771522 const char * name ;
14781523 int sotype ;
14791524 } tests [] = {
@@ -1520,7 +1565,7 @@ static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map,
15201565 if (!test__start_subtest (s ))
15211566 continue ;
15221567
1523- t -> fn (family , sotype , map_fd );
1568+ t -> fn (skel , family , sotype , map_fd );
15241569 test_ops_cleanup (map );
15251570 }
15261571}
0 commit comments