10
10
static int run_test (int cgroup_fd , int server_fd , bool classid )
11
11
{
12
12
struct connect4_dropper * skel ;
13
- int fd , err = 0 ;
13
+ int fd , err = 0 , port ;
14
14
15
15
skel = connect4_dropper__open_and_load ();
16
16
if (!ASSERT_OK_PTR (skel , "skel_open" ))
17
17
return -1 ;
18
18
19
+ port = get_socket_local_port (server_fd );
20
+ if (!ASSERT_GE (port , 0 , "get_socket_local_port" ))
21
+ return -1 ;
22
+
23
+ skel -> bss -> port = ntohs (port );
24
+
19
25
skel -> links .connect_v4_dropper =
20
26
bpf_program__attach_cgroup (skel -> progs .connect_v4_dropper ,
21
27
cgroup_fd );
@@ -48,10 +54,9 @@ void test_cgroup_v1v2(void)
48
54
{
49
55
struct network_helper_opts opts = {};
50
56
int server_fd , client_fd , cgroup_fd ;
51
- static const int port = 60120 ;
52
57
53
58
/* Step 1: Check base connectivity works without any BPF. */
54
- server_fd = start_server (AF_INET , SOCK_STREAM , NULL , port , 0 );
59
+ server_fd = start_server (AF_INET , SOCK_STREAM , NULL , 0 , 0 );
55
60
if (!ASSERT_GE (server_fd , 0 , "server_fd" ))
56
61
return ;
57
62
client_fd = connect_to_fd_opts (server_fd , & opts );
@@ -66,7 +71,7 @@ void test_cgroup_v1v2(void)
66
71
cgroup_fd = test__join_cgroup ("/connect_dropper" );
67
72
if (!ASSERT_GE (cgroup_fd , 0 , "cgroup_fd" ))
68
73
return ;
69
- server_fd = start_server (AF_INET , SOCK_STREAM , NULL , port , 0 );
74
+ server_fd = start_server (AF_INET , SOCK_STREAM , NULL , 0 , 0 );
70
75
if (!ASSERT_GE (server_fd , 0 , "server_fd" )) {
71
76
close (cgroup_fd );
72
77
return ;
0 commit comments