aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/lib/bpf/libbpf_internal.h
diff options
context:
space:
mode:
authorTony Ambardar <tony.ambardar@gmail.com>2024-09-16 01:37:44 -0700
committerAlexei Starovoitov <ast@kernel.org>2024-10-03 17:47:36 -0700
commitbcc60abd67c7741a065480df4875534f62f758b1 (patch)
tree752d3fe262f2ecff34cc710a9f8be33609082f3b /tools/lib/bpf/libbpf_internal.h
parentlibbpf: Support BTF.ext loading and output in either endianness (diff)
downloadwireguard-linux-bcc60abd67c7741a065480df4875534f62f758b1.tar.xz
wireguard-linux-bcc60abd67c7741a065480df4875534f62f758b1.zip
libbpf: Support opening bpf objects of either endianness
Allow bpf_object__open() to access files of either endianness, and convert included BPF programs to native byte-order in-memory for introspection. Loading BPF objects of non-native byte-order is still disallowed however. Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/26353c1a1887a54400e1acd6c138fa90c99cdd40.1726475448.git.tony.ambardar@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/libbpf_internal.h')
-rw-r--r--tools/lib/bpf/libbpf_internal.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 182529360c84..de498e2dd6b0 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -617,6 +617,16 @@ static inline bool is_ldimm64_insn(struct bpf_insn *insn)
return insn->code == (BPF_LD | BPF_IMM | BPF_DW);
}
+static inline void bpf_insn_bswap(struct bpf_insn *insn)
+{
+ __u8 tmp_reg = insn->dst_reg;
+
+ insn->dst_reg = insn->src_reg;
+ insn->src_reg = tmp_reg;
+ insn->off = bswap_16(insn->off);
+ insn->imm = bswap_32(insn->imm);
+}
+
/* Unconditionally dup FD, ensuring it doesn't use [0, 2] range.
* Original FD is not closed or altered in any other way.
* Preserves original FD value, if it's invalid (negative).