@@ -555,6 +555,74 @@ static void test_sockmap_unconnected_unix(void)
555555 close (dgram );
556556}
557557
558+ static void test_sockmap_many_socket (void )
559+ {
560+ struct test_sockmap_pass_prog * skel ;
561+ int stream [2 ], dgram , udp , tcp ;
562+ int i , err , map , entry = 0 ;
563+
564+ skel = test_sockmap_pass_prog__open_and_load ();
565+ if (!ASSERT_OK_PTR (skel , "open_and_load" ))
566+ return ;
567+
568+ map = bpf_map__fd (skel -> maps .sock_map_rx );
569+
570+ dgram = xsocket (AF_UNIX , SOCK_DGRAM , 0 );
571+ if (dgram < 0 ) {
572+ test_sockmap_pass_prog__destroy (skel );
573+ return ;
574+ }
575+
576+ tcp = connected_socket_v4 ();
577+ if (!ASSERT_GE (tcp , 0 , "connected_socket_v4" )) {
578+ close (dgram );
579+ test_sockmap_pass_prog__destroy (skel );
580+ return ;
581+ }
582+
583+ udp = xsocket (AF_INET , SOCK_DGRAM | SOCK_NONBLOCK , 0 );
584+ if (udp < 0 ) {
585+ close (dgram );
586+ close (tcp );
587+ test_sockmap_pass_prog__destroy (skel );
588+ return ;
589+ }
590+
591+ err = socketpair (AF_UNIX , SOCK_STREAM , 0 , stream );
592+ ASSERT_OK (err , "socketpair(af_unix, sock_stream)" );
593+ if (err )
594+ goto out ;
595+
596+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
597+ err = bpf_map_update_elem (map , & entry , & stream [0 ], BPF_ANY );
598+ ASSERT_OK (err , "bpf_map_update_elem(stream)" );
599+ }
600+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
601+ err = bpf_map_update_elem (map , & entry , & dgram , BPF_ANY );
602+ ASSERT_OK (err , "bpf_map_update_elem(dgram)" );
603+ }
604+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
605+ err = bpf_map_update_elem (map , & entry , & udp , BPF_ANY );
606+ ASSERT_OK (err , "bpf_map_update_elem(udp)" );
607+ }
608+ for (i = 0 ; i < 2 ; i ++ , entry ++ ) {
609+ err = bpf_map_update_elem (map , & entry , & tcp , BPF_ANY );
610+ ASSERT_OK (err , "bpf_map_update_elem(tcp)" );
611+ }
612+ for (entry -- ; entry >= 0 ; entry -- ) {
613+ err = bpf_map_delete_elem (map , & entry );
614+ ASSERT_OK (err , "bpf_map_delete_elem(entry)" );
615+ }
616+
617+ close (stream [0 ]);
618+ close (stream [1 ]);
619+ out :
620+ close (dgram );
621+ close (tcp );
622+ close (udp );
623+ test_sockmap_pass_prog__destroy (skel );
624+ }
625+
558626void test_sockmap_basic (void )
559627{
560628 if (test__start_subtest ("sockmap create_update_free" ))
@@ -597,7 +665,8 @@ void test_sockmap_basic(void)
597665 test_sockmap_skb_verdict_fionread (false);
598666 if (test__start_subtest ("sockmap skb_verdict msg_f_peek" ))
599667 test_sockmap_skb_verdict_peek ();
600-
601668 if (test__start_subtest ("sockmap unconnected af_unix" ))
602669 test_sockmap_unconnected_unix ();
670+ if (test__start_subtest ("sockmap one socket to many map entries" ))
671+ test_sockmap_many_socket ();
603672}
0 commit comments