[DTrace-devel] [PATCH 35/61] Implement dt_bpf_map_next_key()

eugene.loh at oracle.com eugene.loh at oracle.com
Fri Jul 8 14:45:19 UTC 2022


From: Eugene Loh <eugene.loh at oracle.com>

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_bpf.c | 15 +++++++++++++++
 libdtrace/dt_bpf.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index f0d1a99e..8a5149d4 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -87,6 +87,21 @@ int dt_bpf_map_lookup(int fd, const void *key, void *val)
 	return bpf(BPF_MAP_LOOKUP_ELEM, &attr);
 }
 
+/*
+ * Find the next key after the given key in the map referenced by the given fd.
+ */
+int dt_bpf_map_next_key(int fd, const void *key, void *nxt)
+{
+	union bpf_attr attr;
+
+	memset(&attr, 0, sizeof(attr));
+	attr.map_fd = fd;
+	attr.key = (uint64_t)(unsigned long)key;
+	attr.next_key = (uint64_t)(unsigned long)nxt;
+
+	return bpf(BPF_MAP_GET_NEXT_KEY, &attr);
+}
+
 /*
  * Delete the given key from the map referenced by the given fd.
  */
diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
index 40cbcf43..edf9c5d7 100644
--- a/libdtrace/dt_bpf.h
+++ b/libdtrace/dt_bpf.h
@@ -44,6 +44,7 @@ extern int bpf(enum bpf_cmd cmd, union bpf_attr *attr);
 
 extern int dt_bpf_gmap_create(struct dtrace_hdl *);
 extern int dt_bpf_map_lookup(int fd, const void *key, void *val);
+extern int dt_bpf_map_next_key(int fd, const void *key, void *nxt);
 extern int dt_bpf_map_update(int fd, const void *key, const void *val);
 extern int dt_bpf_map_delete(int fd, const void *key);
 extern int dt_bpf_func_id_in_range(int func_id);
-- 
2.18.4




More information about the DTrace-devel mailing list