[DTrace-devel] [PATCH v2] Add 'endianness conversion' BPF instruction macro

eugene.loh at oracle.com eugene.loh at oracle.com
Thu Jul 8 02:03:02 PDT 2021


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

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 include/bpf_asm.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/bpf_asm.h b/include/bpf_asm.h
index cac60c24..d29fc7f0 100644
--- a/include/bpf_asm.h
+++ b/include/bpf_asm.h
@@ -36,6 +36,17 @@
 		.imm = 0						\
 	})
 
+#define BPF_END_REG(sz, dst, dir)					\
+	((struct bpf_insn) {						\
+		.code = BPF_ALU | BPF_END | (dir),			\
+		.dst_reg = (dst),					\
+		.src_reg = 0,						\
+		.off = 0,						\
+		.imm = (sz) == BPF_DW ? 64 :				\
+		       (sz) == BPF_W ? 32 :				\
+		       (sz) == BPF_H ? 16 : 0				\
+	})
+
 #define BPF_NEG_REG(dst)						\
 	((struct bpf_insn) {						\
 		.code = BPF_ALU64 | BPF_NEG,				\
-- 
2.18.4




More information about the DTrace-devel mailing list