@@ -119,6 +119,66 @@ static int test_current_pid_tgid_cgrp(void *args)
119119 return ret ;
120120}
121121
122+ static int test_current_pid_tgid_sk_msg (void * args )
123+ {
124+ int verdict , map , server_fd = -1 , client_fd = -1 ;
125+ struct test_ns_current_pid_tgid__bss * bss ;
126+ static const char send_msg [] = "message" ;
127+ struct test_ns_current_pid_tgid * skel ;
128+ int ret = -1 , err , key = 0 ;
129+ pid_t tgid , pid ;
130+
131+ skel = test_ns_current_pid_tgid__open ();
132+ if (!ASSERT_OK_PTR (skel , "test_ns_current_pid_tgid__open" ))
133+ return ret ;
134+
135+ bpf_program__set_autoload (skel -> progs .sk_msg , true);
136+
137+ err = test_ns_current_pid_tgid__load (skel );
138+ if (!ASSERT_OK (err , "test_ns_current_pid_tgid__load" ))
139+ goto cleanup ;
140+
141+ bss = skel -> bss ;
142+ if (get_pid_tgid (& pid , & tgid , skel -> bss ))
143+ goto cleanup ;
144+
145+ verdict = bpf_program__fd (skel -> progs .sk_msg );
146+ map = bpf_map__fd (skel -> maps .sock_map );
147+ err = bpf_prog_attach (verdict , map , BPF_SK_MSG_VERDICT , 0 );
148+ if (!ASSERT_OK (err , "prog_attach" ))
149+ goto cleanup ;
150+
151+ server_fd = start_server (AF_INET6 , SOCK_STREAM , "::1" , 0 , 0 );
152+ if (!ASSERT_GE (server_fd , 0 , "start_server" ))
153+ goto cleanup ;
154+
155+ client_fd = connect_to_fd (server_fd , 0 );
156+ if (!ASSERT_GE (client_fd , 0 , "connect_to_fd" ))
157+ goto cleanup ;
158+
159+ err = bpf_map_update_elem (map , & key , & client_fd , BPF_ANY );
160+ if (!ASSERT_OK (err , "bpf_map_update_elem" ))
161+ goto cleanup ;
162+
163+ err = send (client_fd , send_msg , sizeof (send_msg ), 0 );
164+ if (!ASSERT_EQ (err , sizeof (send_msg ), "send(msg)" ))
165+ goto cleanup ;
166+
167+ if (!ASSERT_EQ (bss -> user_pid , pid , "pid" ))
168+ goto cleanup ;
169+ if (!ASSERT_EQ (bss -> user_tgid , tgid , "tgid" ))
170+ goto cleanup ;
171+ ret = 0 ;
172+
173+ cleanup :
174+ if (server_fd >= 0 )
175+ close (server_fd );
176+ if (client_fd >= 0 )
177+ close (client_fd );
178+ test_ns_current_pid_tgid__destroy (skel );
179+ return ret ;
180+ }
181+
122182static void test_ns_current_pid_tgid_new_ns (int (* fn )(void * ), void * arg )
123183{
124184 int wstatus ;
@@ -175,4 +235,6 @@ void serial_test_ns_current_pid_tgid(void)
175235 close (cgroup_fd );
176236 }
177237 }
238+ if (test__start_subtest ("new_ns_sk_msg" ))
239+ test_in_netns (test_current_pid_tgid_sk_msg , NULL );
178240}
0 commit comments