Re: [PATCH v3 01/30] tools lib bpf: Add missing BPF functions

From: Alexei Starovoitov
Date: Sat Nov 26 2016 - 12:10:58 EST


On Sat, Nov 26, 2016 at 07:03:25AM +0000, Wang Nan wrote:
> Add more BPF map operations to libbpf. Also add bpf_obj_{pin,get}(). They
> can be used on not only BPF maps but also BPF programs.
>
> Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
> Cc: Alexei Starovoitov <ast@xxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Joe Stringer <joe@xxxxxxx>
> Cc: Li Zefan <lizefan@xxxxxxxxxx>
> ---
> tools/lib/bpf/bpf.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> tools/lib/bpf/bpf.h | 7 +++++++
> 2 files changed, 63 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 4212ed6..8143536 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -110,3 +110,59 @@ int bpf_map_update_elem(int fd, void *key, void *value,
>
> return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
> }
> +
> +int bpf_map_lookup_elem(int fd, void *key, void *value)
> +{
> + union bpf_attr attr;
> +
> + bzero(&attr, sizeof(attr));
> + attr.map_fd = fd;
> + attr.key = ptr_to_u64(key);
> + attr.value = ptr_to_u64(value);
> +
> + return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
> +}

Acked-by: Alexei Starovoitov <ast@xxxxxxxxxx>