8
8
#include "test_sockmap_invalid_update.skel.h"
9
9
#include "bpf_iter_sockmap.skel.h"
10
10
11
- #include "progs/bpf_iter_sockmap.h"
12
-
13
11
#define TCP_REPAIR 19 /* TCP sock is under repair right now */
14
12
15
13
#define TCP_REPAIR_ON 1
@@ -179,9 +177,9 @@ static void test_sockmap_iter(enum bpf_map_type map_type)
179
177
DECLARE_LIBBPF_OPTS (bpf_iter_attach_opts , opts );
180
178
int err , len , src_fd , iter_fd , duration = 0 ;
181
179
union bpf_iter_link_info linfo = {0 };
182
- __s64 sock_fd [SOCKMAP_MAX_ENTRIES ];
183
- __u32 i , num_sockets , max_elems ;
180
+ __u32 i , num_sockets , num_elems ;
184
181
struct bpf_iter_sockmap * skel ;
182
+ __s64 * sock_fd = NULL ;
185
183
struct bpf_link * link ;
186
184
struct bpf_map * src ;
187
185
char buf [64 ];
@@ -190,22 +188,26 @@ static void test_sockmap_iter(enum bpf_map_type map_type)
190
188
if (CHECK (!skel , "bpf_iter_sockmap__open_and_load" , "skeleton open_and_load failed\n" ))
191
189
return ;
192
190
193
- for (i = 0 ; i < ARRAY_SIZE (sock_fd ); i ++ )
194
- sock_fd [i ] = -1 ;
195
-
196
- /* Make sure we have at least one "empty" entry to test iteration of
197
- * an empty slot.
198
- */
199
- num_sockets = ARRAY_SIZE (sock_fd ) - 1 ;
200
-
201
191
if (map_type == BPF_MAP_TYPE_SOCKMAP ) {
202
192
src = skel -> maps .sockmap ;
203
- max_elems = bpf_map__max_entries (src );
193
+ num_elems = bpf_map__max_entries (src );
204
194
} else {
205
195
src = skel -> maps .sockhash ;
206
- max_elems = num_sockets ;
196
+ num_elems = bpf_map__max_entries ( src ) - 1 ;
207
197
}
208
198
199
+ /* Make sure we have at least one "empty" entry to test iteration of
200
+ * an empty slot.
201
+ */
202
+ num_sockets = bpf_map__max_entries (src ) - 1 ;
203
+
204
+ sock_fd = calloc (num_sockets , sizeof (* sock_fd ));
205
+ if (CHECK (!sock_fd , "calloc(sock_fd)" , "failed to allocate\n" ))
206
+ goto out ;
207
+
208
+ for (i = 0 ; i < num_sockets ; i ++ )
209
+ sock_fd [i ] = -1 ;
210
+
209
211
src_fd = bpf_map__fd (src );
210
212
211
213
for (i = 0 ; i < num_sockets ; i ++ ) {
@@ -236,8 +238,8 @@ static void test_sockmap_iter(enum bpf_map_type map_type)
236
238
goto close_iter ;
237
239
238
240
/* test results */
239
- if (CHECK (skel -> bss -> elems != max_elems , "elems" , "got %u expected %u\n" ,
240
- skel -> bss -> elems , max_elems ))
241
+ if (CHECK (skel -> bss -> elems != num_elems , "elems" , "got %u expected %u\n" ,
242
+ skel -> bss -> elems , num_elems ))
241
243
goto close_iter ;
242
244
243
245
if (CHECK (skel -> bss -> socks != num_sockets , "socks" , "got %u expected %u\n" ,
@@ -249,10 +251,11 @@ static void test_sockmap_iter(enum bpf_map_type map_type)
249
251
free_link :
250
252
bpf_link__destroy (link );
251
253
out :
252
- for (i = 0 ; i < num_sockets ; i ++ ) {
254
+ for (i = 0 ; sock_fd && i < num_sockets ; i ++ )
253
255
if (sock_fd [i ] >= 0 )
254
256
close (sock_fd [i ]);
255
- }
257
+ if (sock_fd )
258
+ free (sock_fd );
256
259
bpf_iter_sockmap__destroy (skel );
257
260
}
258
261
0 commit comments