1010
1111static __u32 duration ;
1212
13- static void verify_result (int map_fd , int sock_map_fd )
13+ static void verify_result (struct tcpbpf_globals * result )
1414{
1515 __u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT ) |
1616 (1 << BPF_SOCK_OPS_RWND_INIT ) |
@@ -20,46 +20,31 @@ static void verify_result(int map_fd, int sock_map_fd)
2020 (1 << BPF_SOCK_OPS_NEEDS_ECN ) |
2121 (1 << BPF_SOCK_OPS_STATE_CB ) |
2222 (1 << BPF_SOCK_OPS_TCP_LISTEN_CB ));
23- struct tcpbpf_globals result ;
24- __u32 key = 0 ;
25- int res , rv ;
26-
27- rv = bpf_map_lookup_elem (map_fd , & key , & result );
28- if (CHECK (rv , "bpf_map_lookup_elem(map_fd)" , "err:%d errno:%d" ,
29- rv , errno ))
30- return ;
3123
3224 /* check global map */
33- CHECK (expected_events != result . event_map , "event_map" ,
25+ CHECK (expected_events != result -> event_map , "event_map" ,
3426 "unexpected event_map: actual 0x%08x != expected 0x%08x\n" ,
35- result . event_map , expected_events );
27+ result -> event_map , expected_events );
3628
37- ASSERT_EQ (result . bytes_received , 501 , "bytes_received" );
38- ASSERT_EQ (result . bytes_acked , 1002 , "bytes_acked" );
39- ASSERT_EQ (result . data_segs_in , 1 , "data_segs_in" );
40- ASSERT_EQ (result . data_segs_out , 1 , "data_segs_out" );
41- ASSERT_EQ (result . bad_cb_test_rv , 0x80 , "bad_cb_test_rv" );
42- ASSERT_EQ (result . good_cb_test_rv , 0 , "good_cb_test_rv" );
43- ASSERT_EQ (result . num_listen , 1 , "num_listen" );
29+ ASSERT_EQ (result -> bytes_received , 501 , "bytes_received" );
30+ ASSERT_EQ (result -> bytes_acked , 1002 , "bytes_acked" );
31+ ASSERT_EQ (result -> data_segs_in , 1 , "data_segs_in" );
32+ ASSERT_EQ (result -> data_segs_out , 1 , "data_segs_out" );
33+ ASSERT_EQ (result -> bad_cb_test_rv , 0x80 , "bad_cb_test_rv" );
34+ ASSERT_EQ (result -> good_cb_test_rv , 0 , "good_cb_test_rv" );
35+ ASSERT_EQ (result -> num_listen , 1 , "num_listen" );
4436
4537 /* 3 comes from one listening socket + both ends of the connection */
46- ASSERT_EQ (result . num_close_events , 3 , "num_close_events" );
38+ ASSERT_EQ (result -> num_close_events , 3 , "num_close_events" );
4739
4840 /* check setsockopt for SAVE_SYN */
49- rv = bpf_map_lookup_elem (sock_map_fd , & key , & res );
50- CHECK (rv , "bpf_map_lookup_elem(sock_map_fd)" , "err:%d errno:%d" ,
51- rv , errno );
52- ASSERT_EQ (res , 0 , "bpf_setsockopt(TCP_SAVE_SYN)" );
41+ ASSERT_EQ (result -> tcp_save_syn , 0 , "tcp_save_syn" );
5342
5443 /* check getsockopt for SAVED_SYN */
55- key = 1 ;
56- rv = bpf_map_lookup_elem (sock_map_fd , & key , & res );
57- CHECK (rv , "bpf_map_lookup_elem(sock_map_fd)" , "err:%d errno:%d" ,
58- rv , errno );
59- ASSERT_EQ (res , 1 , "bpf_getsockopt(TCP_SAVED_SYN)" );
44+ ASSERT_EQ (result -> tcp_saved_syn , 1 , "tcp_saved_syn" );
6045}
6146
62- static void run_test (int map_fd , int sock_map_fd )
47+ static void run_test (struct tcpbpf_globals * result )
6348{
6449 int listen_fd = -1 , cli_fd = -1 , accept_fd = -1 ;
6550 char buf [1000 ];
@@ -126,13 +111,12 @@ static void run_test(int map_fd, int sock_map_fd)
126111 close (listen_fd );
127112
128113 if (!err )
129- verify_result (map_fd , sock_map_fd );
114+ verify_result (result );
130115}
131116
132117void test_tcpbpf_user (void )
133118{
134119 struct test_tcpbpf_kern * skel ;
135- int map_fd , sock_map_fd ;
136120 int cg_fd = -1 ;
137121
138122 skel = test_tcpbpf_kern__open_and_load ();
@@ -144,14 +128,11 @@ void test_tcpbpf_user(void)
144128 "cg_fd:%d errno:%d" , cg_fd , errno ))
145129 goto err ;
146130
147- map_fd = bpf_map__fd (skel -> maps .global_map );
148- sock_map_fd = bpf_map__fd (skel -> maps .sockopt_results );
149-
150131 skel -> links .bpf_testcb = bpf_program__attach_cgroup (skel -> progs .bpf_testcb , cg_fd );
151132 if (!ASSERT_OK_PTR (skel -> links .bpf_testcb , "attach_cgroup(bpf_testcb)" ))
152133 goto err ;
153134
154- run_test (map_fd , sock_map_fd );
135+ run_test (& skel -> bss -> global );
155136
156137err :
157138 if (cg_fd != -1 )
0 commit comments