Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux/helper-function Add example for bpf_for_each_map_elem #61

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions docs/linux/helper-function/bpf_for_each_map_elem.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,26 @@ This helper call can be used with the following map types:

### Example

!!! example "Docs could be improved"
This part of the docs is incomplete, contributions are very welcome
```c
static long callback_fn(struct bpf_map *map, const void *key, void *value, void *ctx)
{
bpf_printk("context value: %s\n", *(char **)ctx);
// delete elements with an odd key
if (*(__u32 *)key % 2)
bpf_map_delete_elem(map, key);
return 0;
}

int program(void *ctx)
{
/*
.
.
.
*/

char *context = "This string will pass to every callback call";
long (*cb_p)(struct bpf_map *, const void *, void *, void *) = &callback_fn;
bpf_for_each_map_elem(&my_map, cb_p, &context, 0);
}
```
Loading