@@ -623,6 +623,78 @@ static void test_sockmap_many_socket(void)
623623 test_sockmap_pass_prog__destroy (skel );
624624}
625625
626+ static void test_sockmap_many_maps (void )
627+ {
628+ struct test_sockmap_pass_prog * skel ;
629+ int stream [2 ], dgram , udp , tcp ;
630+ int i , err , map [2 ], entry = 0 ;
631+
632+ skel = test_sockmap_pass_prog__open_and_load ();
633+ if (!ASSERT_OK_PTR (skel , "open_and_load" ))
634+ return ;
635+
636+ map [0 ] = bpf_map__fd (skel -> maps .sock_map_rx );
637+ map [1 ] = bpf_map__fd (skel -> maps .sock_map_tx );
638+
639+ dgram = xsocket (AF_UNIX , SOCK_DGRAM , 0 );
640+ if (dgram < 0 ) {
641+ test_sockmap_pass_prog__destroy (skel );
642+ return ;
643+ }
644+
645+ tcp = connected_socket_v4 ();
646+ if (!ASSERT_GE (tcp , 0 , "connected_socket_v4" )) {
647+ close (dgram );
648+ test_sockmap_pass_prog__destroy (skel );
649+ return ;
650+ }
651+
652+ udp = xsocket (AF_INET , SOCK_DGRAM | SOCK_NONBLOCK , 0 );
653+ if (udp < 0 ) {
654+ close (dgram );
655+ close (tcp );
656+ test_sockmap_pass_prog__destroy (skel );
657+ return ;
658+ }
659+
660+ err = socketpair (AF_UNIX , SOCK_STREAM , 0 , stream );
661+ ASSERT_OK (err , "socketpair(af_unix, sock_stream)" );
662+ if (err )
663+ goto out ;
664+
665+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
666+ err = bpf_map_update_elem (map [i ], & entry , & stream [0 ], BPF_ANY );
667+ ASSERT_OK (err , "bpf_map_update_elem(stream)" );
668+ }
669+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
670+ err = bpf_map_update_elem (map [i ], & entry , & dgram , BPF_ANY );
671+ ASSERT_OK (err , "bpf_map_update_elem(dgram)" );
672+ }
673+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
674+ err = bpf_map_update_elem (map [i ], & entry , & udp , BPF_ANY );
675+ ASSERT_OK (err , "bpf_map_update_elem(udp)" );
676+ }
677+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
678+ err = bpf_map_update_elem (map [i ], & entry , & tcp , BPF_ANY );
679+ ASSERT_OK (err , "bpf_map_update_elem(tcp)" );
680+ }
681+ for (entry -- ; entry >= 0 ; entry -- ) {
682+ err = bpf_map_delete_elem (map [1 ], & entry );
683+ entry -- ;
684+ ASSERT_OK (err , "bpf_map_delete_elem(entry)" );
685+ err = bpf_map_delete_elem (map [0 ], & entry );
686+ ASSERT_OK (err , "bpf_map_delete_elem(entry)" );
687+ }
688+
689+ close (stream [0 ]);
690+ close (stream [1 ]);
691+ out :
692+ close (dgram );
693+ close (tcp );
694+ close (udp );
695+ test_sockmap_pass_prog__destroy (skel );
696+ }
697+
626698void test_sockmap_basic (void )
627699{
628700 if (test__start_subtest ("sockmap create_update_free" ))
@@ -669,4 +741,6 @@ void test_sockmap_basic(void)
669741 test_sockmap_unconnected_unix ();
670742 if (test__start_subtest ("sockmap one socket to many map entries" ))
671743 test_sockmap_many_socket ();
744+ if (test__start_subtest ("sockmap one socket to many maps" ))
745+ test_sockmap_many_maps ();
672746}
0 commit comments