Skip to content

Commit 83efebc

Browse files
committed
xdp_ddos01_blacklist_cmdline: Fix wrong usage of bpf_map_get_next_key
If inserting key 0 into hash, this code will cause issues listing IPs. First change the variable name to be prev_key and key like: bpf_map_get_next_key(fd, prev_key, &key) The prev_key need to be a real pointer, as we need to start with prev_key = NULL. Before prev_key was (a value on stack) implicit zero. Thus, we basically asked to start the listing with key 0. Thus, it is why it *looked* like it was all working when the hash doesn't contain key=0, as then it fails-to-start-at-0 and kernel provides the first-key. Signed-off-by: Jesper Dangaard Brouer <[email protected]>
1 parent b4e8635 commit 83efebc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ static void blacklist_print_port(int key, __u32 val, int countfds[])
234234

235235
static void blacklist_list_all_ipv4(int fd)
236236
{
237-
__u32 key = 0, next_key;
237+
__u32 key, *prev_key = NULL;
238238
__u64 value;
239239

240-
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
240+
while (bpf_map_get_next_key(fd, prev_key, &key) == 0) {
241241
printf("%s", key ? "," : "" );
242-
key = next_key;
243242
value = get_key32_value64_percpu(fd, key);
244243
blacklist_print_ipv4(key, value);
244+
prev_key = &key;
245245
}
246246
printf("%s", key ? "," : "");
247247
}

0 commit comments

Comments
 (0)