11
11
12
12
static __u32 duration ;
13
13
14
- static void verify_result (int map_fd , int sock_map_fd )
14
+ static void verify_result (struct tcpbpf_globals * result )
15
15
{
16
16
__u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT ) |
17
17
(1 << BPF_SOCK_OPS_RWND_INIT ) |
@@ -21,48 +21,31 @@ static void verify_result(int map_fd, int sock_map_fd)
21
21
(1 << BPF_SOCK_OPS_NEEDS_ECN ) |
22
22
(1 << BPF_SOCK_OPS_STATE_CB ) |
23
23
(1 << BPF_SOCK_OPS_TCP_LISTEN_CB ));
24
- struct tcpbpf_globals result = { 0 };
25
- __u32 key = 0 ;
26
- int res ;
27
- int rv ;
28
-
29
- rv = bpf_map_lookup_elem (map_fd , & key , & result );
30
- if (CHECK (rv , "bpf_map_lookup_elem(map_fd)" , "err:%d errno:%d" ,
31
- rv , errno ))
32
- return ;
33
24
34
25
/* check global map */
35
- CHECK (expected_events != result . event_map , "event_map" ,
26
+ CHECK (expected_events != result -> event_map , "event_map" ,
36
27
"unexpected event_map: actual %#" PRIx32 " != expected %#" PRIx32 "\n" ,
37
- result . event_map , expected_events );
28
+ result -> event_map , expected_events );
38
29
39
- ASSERT_EQ (result . bytes_received , 501 , "bytes_received" );
40
- ASSERT_EQ (result . bytes_acked , 1002 , "bytes_acked" );
41
- ASSERT_EQ (result . data_segs_in , 1 , "data_segs_in" );
42
- ASSERT_EQ (result . data_segs_out , 1 , "data_segs_out" );
43
- ASSERT_EQ (result . bad_cb_test_rv , 0x80 , "bad_cb_test_rv" );
44
- ASSERT_EQ (result . good_cb_test_rv , 0 , "good_cb_test_rv" );
45
- ASSERT_EQ (result . num_listen , 1 , "num_listen" );
30
+ ASSERT_EQ (result -> bytes_received , 501 , "bytes_received" );
31
+ ASSERT_EQ (result -> bytes_acked , 1002 , "bytes_acked" );
32
+ ASSERT_EQ (result -> data_segs_in , 1 , "data_segs_in" );
33
+ ASSERT_EQ (result -> data_segs_out , 1 , "data_segs_out" );
34
+ ASSERT_EQ (result -> bad_cb_test_rv , 0x80 , "bad_cb_test_rv" );
35
+ ASSERT_EQ (result -> good_cb_test_rv , 0 , "good_cb_test_rv" );
36
+ ASSERT_EQ (result -> num_listen , 1 , "num_listen" );
46
37
47
38
/* 3 comes from one listening socket + both ends of the connection */
48
- ASSERT_EQ (result . num_close_events , 3 , "num_close_events" );
39
+ ASSERT_EQ (result -> num_close_events , 3 , "num_close_events" );
49
40
50
41
/* check setsockopt for SAVE_SYN */
51
- key = 0 ;
52
- rv = bpf_map_lookup_elem (sock_map_fd , & key , & res );
53
- CHECK (rv , "bpf_map_lookup_elem(sock_map_fd)" , "err:%d errno:%d" ,
54
- rv , errno );
55
- ASSERT_EQ (res , 0 , "bpf_setsockopt(TCP_SAVE_SYN)" );
42
+ ASSERT_EQ (result -> tcp_save_syn , 0 , "tcp_save_syn" );
56
43
57
44
/* check getsockopt for SAVED_SYN */
58
- key = 1 ;
59
- rv = bpf_map_lookup_elem (sock_map_fd , & key , & res );
60
- CHECK (rv , "bpf_map_lookup_elem(sock_map_fd)" , "err:%d errno:%d" ,
61
- rv , errno );
62
- ASSERT_EQ (res , 1 , "bpf_getsockopt(TCP_SAVED_SYN)" );
45
+ ASSERT_EQ (result -> tcp_saved_syn , 1 , "tcp_saved_syn" );
63
46
}
64
47
65
- static void run_test (int map_fd , int sock_map_fd )
48
+ static void run_test (struct tcpbpf_globals * result )
66
49
{
67
50
int listen_fd = -1 , cli_fd = -1 , accept_fd = -1 ;
68
51
char buf [1000 ];
@@ -129,13 +112,12 @@ static void run_test(int map_fd, int sock_map_fd)
129
112
close (listen_fd );
130
113
131
114
if (!err )
132
- verify_result (map_fd , sock_map_fd );
115
+ verify_result (result );
133
116
}
134
117
135
118
void test_tcpbpf_user (void )
136
119
{
137
120
struct test_tcpbpf_kern * skel ;
138
- int map_fd , sock_map_fd ;
139
121
int cg_fd = -1 ;
140
122
141
123
skel = test_tcpbpf_kern__open_and_load ();
@@ -147,14 +129,11 @@ void test_tcpbpf_user(void)
147
129
"cg_fd:%d errno:%d" , cg_fd , errno ))
148
130
goto cleanup_skel ;
149
131
150
- map_fd = bpf_map__fd (skel -> maps .global_map );
151
- sock_map_fd = bpf_map__fd (skel -> maps .sockopt_results );
152
-
153
132
skel -> links .bpf_testcb = bpf_program__attach_cgroup (skel -> progs .bpf_testcb , cg_fd );
154
133
if (ASSERT_OK_PTR (skel -> links .bpf_testcb , "attach_cgroup(bpf_testcb)" ))
155
134
goto cleanup_namespace ;
156
135
157
- run_test (map_fd , sock_map_fd );
136
+ run_test (& skel -> bss -> global );
158
137
159
138
cleanup_namespace :
160
139
if (cg_fd != -1 )
0 commit comments