Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1293643
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 06/10] bpf tools: Support new map operations |
| Date | 2015-12-17 07:20 +0100 |
| Message-ID | <qGA4V-3Zu-3@gated-at.bofh.it> (permalink) |
| References | <qGziz-3tt-31@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Add bpf_map_lookup_elem(), bpf_map_delete_elem() and bpf_map_get_next_key()
to libbpf so it can issue all BPF map operations.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
---
v1 -> v2: Remove tailing whitespaces.
---
tools/lib/bpf/bpf.c | 32 ++++++++++++++++++++++++++++++++
tools/lib/bpf/bpf.h | 4 ++++
2 files changed, 36 insertions(+)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index e0dccea..b8e7aaa 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -97,3 +97,35 @@ 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 = {
+ .map_fd = fd,
+ .key = ptr_to_u64(key),
+ .value = ptr_to_u64(value),
+ };
+
+ return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
+}
+
+int bpf_map_delete_elem(int fd, void *key)
+{
+ union bpf_attr attr = {
+ .map_fd = fd,
+ .key = ptr_to_u64(key),
+ };
+
+ return sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
+}
+
+int bpf_map_get_next_key(int fd, void *key, void *next_key)
+{
+ union bpf_attr attr = {
+ .map_fd = fd,
+ .key = ptr_to_u64(key),
+ .next_key = ptr_to_u64(next_key),
+ };
+
+ return sys_bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr));
+}
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 01a421a..3d22048 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -23,4 +23,8 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
int bpf_map_update_elem(int fd, void *key, void *value,
__u64 flags);
+
+int bpf_map_lookup_elem(int fd, void *key, void *value);
+int bpf_map_delete_elem(int fd, void *key);
+int bpf_map_get_next_key(int fd, void *key, void *next_key);
#endif
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
[PATCH 01/10] bpf samples: bpf: Fix tracex5_kern.c compiling error Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
[PATCH 05/10] bpf tools: Support load different type of programs Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
[PATCH 03/10] bpf tools: Add const decoretor to 'license' and 'insns' for bpf_load_program() Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
[PATCH 02/10] bpf tools: Define LD and RM in Makefile for 'make -R' Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
[PATCH 06/10] bpf tools: Support new map operations Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
Re: [PATCH 06/10] bpf tools: Support new map operations "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-17 07:10 +0100
[PATCH v2 06/10] bpf tools: Support new map operations Wang Nan <wangnan0@huawei.com> - 2015-12-17 07:20 +0100
[PATCH 07/10] bpf tools: Support BPF_OBJ_PIN and BPF_OBJ_GET Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:30 +0100
[PATCH 09/10] bpf samples: Uses libbpf in tools/lib to deal with BPF operations Wang Nan <wangnan0@huawei.com> - 2015-12-17 06:40 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-17 07:40 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-17 08:00 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-17 08:10 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-17 09:30 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-17 11:20 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-17 14:50 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-18 04:10 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-18 10:00 +0100
[PATCH] tools build: Output more data during feature detection Wang Nan <wangnan0@huawei.com> - 2015-12-18 12:00 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-18 12:10 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-18 14:00 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations pi3orama <pi3orama@163.com> - 2015-12-18 15:20 +0100
Re: [PATCH 00/10] bpf samples: Uses libbpf in tools/lib to do BPF operations Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-12-18 15:30 +0100
csiph-web