aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2019-01-31 18:40:11 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2019-02-01 14:55:39 -0500
commitdf5d22facd78e475da2e0d506f239e32cdffaf99 (patch)
tree9813b34f038fee9301b79f74683496f9025248a5
parente44ac9a22b19eec92d10c7b7c69ad6f1995b4dcf (diff)
libbpf: introduce bpf_map_lookup_elem_flags()
Introduce int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, __u64 flags) helper to lookup array/hash/cgroup_local_storage elements with BPF_F_LOCK flag. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--tools/lib/bpf/bpf.c13
-rw-r--r--tools/lib/bpf/bpf.h2
-rw-r--r--tools/lib/bpf/libbpf.map1
3 files changed, 16 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 88cbd110ae58..3defad77dc7a 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -368,6 +368,19 @@ int bpf_map_lookup_elem(int fd, const void *key, void *value)
368 return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); 368 return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
369} 369}
370 370
371int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, __u64 flags)
372{
373 union bpf_attr attr;
374
375 bzero(&attr, sizeof(attr));
376 attr.map_fd = fd;
377 attr.key = ptr_to_u64(key);
378 attr.value = ptr_to_u64(value);
379 attr.flags = flags;
380
381 return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
382}
383
371int bpf_map_lookup_and_delete_elem(int fd, const void *key, void *value) 384int bpf_map_lookup_and_delete_elem(int fd, const void *key, void *value)
372{ 385{
373 union bpf_attr attr; 386 union bpf_attr attr;
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 8f09de482839..ed09eed2dc3b 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -110,6 +110,8 @@ LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,
110 __u64 flags); 110 __u64 flags);
111 111
112LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value); 112LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value);
113LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value,
114 __u64 flags);
113LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key, 115LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,
114 void *value); 116 void *value);
115LIBBPF_API int bpf_map_delete_elem(int fd, const void *key); 117LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 266bc95d0142..f6f96fc38c50 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -130,4 +130,5 @@ LIBBPF_0.0.2 {
130 bpf_probe_helper; 130 bpf_probe_helper;
131 bpf_probe_map_type; 131 bpf_probe_map_type;
132 bpf_probe_prog_type; 132 bpf_probe_prog_type;
133 bpf_map_lookup_elem_flags;
133} LIBBPF_0.0.1; 134} LIBBPF_0.0.1;