diff --git a/plugins/edriver-rust/.cargo/config.toml b/plugins/edriver-rust/.cargo/config.toml new file mode 100644 index 00000000..7d5bf695 --- /dev/null +++ b/plugins/edriver-rust/.cargo/config.toml @@ -0,0 +1,7 @@ +[target.x86_64-unknown-linux-musl] +rustflags = ["-C","target-feature=+crt-static"] +linker = "x86_64-linux-musl-gcc" + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" +rustflags = ["-C", "target-feature=+crt-static", "-L", "/usr/lib/aarch64-linux-gnu/", "-l", "zstd"] diff --git a/plugins/edriver-rust/Cargo.toml b/plugins/edriver-rust/Cargo.toml index 231291ed..823894be 100644 --- a/plugins/edriver-rust/Cargo.toml +++ b/plugins/edriver-rust/Cargo.toml @@ -19,9 +19,9 @@ governor = "0.6.0" lazy_static = "1.4.0" twox-hash = "1.6" hex = "0.4" -libbpf-rs = {version = "0.22.1", features=["static"]} -libbpf-sys = { version = "1.2.1" } +libbpf-rs = {version = "0.23.3", features = ["static"]} +libbpf-sys = { version = "1.4.3" } sdk = { path = "../../SDK/rust" } [build-dependencies] -libbpf-cargo = "0.22.1" \ No newline at end of file +libbpf-cargo = "0.23.3" diff --git a/plugins/edriver-rust/Makefile b/plugins/edriver-rust/Makefile index 6de7906d..918db05c 100644 --- a/plugins/edriver-rust/Makefile +++ b/plugins/edriver-rust/Makefile @@ -1,9 +1,11 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) CMD_CLANG ?= clang LIB_PATH := ../libs LIBBPF_CFLAGS = "-fPIC" LIBBPF_LDLAGS = LIBBPF_SRC = $(LIB_PATH)/libbpf/src +PLATFORM := $(shell uname -m) headers/libbpf/libbpf.a: \ $(LIBBPF_SRC) \ @@ -25,14 +27,14 @@ build: \ headers/libbpf/libbpf.a cargo fmt - RUSTFLAGS="-C target-feature=+crt-static -L /usr/lib/x86_64-linux-gnu/" cargo build --release --target x86_64-unknown-linux-gnu --features=static - + cargo build --release --bin edrivers --target $(PLATFORM)-unknown-linux-gnu --features=static + debug: \ headers/libbpf/libbpf.a cargo fmt - RUST_BACKTRACE=1 RUSTFLAGS="-C target-feature=+crt-static -L /usr/lib/x86_64-linux-gnu/" cargo build --release --target x86_64-unknown-linux-gnu --features=static,debug + cargo build --release --bin edrivers --target $(PLATFORM)-unknown-linux-gnu --features=static,debug test: cargo fmt - RUSTFLAGS="-C target-feature=+crt-static -L /usr/lib/x86_64-linux-gnu/" cargo test --target x86_64-unknown-linux-gnu --features=debug,static \ No newline at end of file + cargo test --bin edrivers --target $(PLATFORM)-unknown-linux-gnu --features=static,debug \ No newline at end of file diff --git a/plugins/edriver-rust/build.rs b/plugins/edriver-rust/build.rs index 2be26d3a..7672aa8a 100644 --- a/plugins/edriver-rust/build.rs +++ b/plugins/edriver-rust/build.rs @@ -8,18 +8,17 @@ fn main() { SkeletonBuilder::new() .source(SRC) - .clang_args( - "-c - -D__BPF_TRACING__ - -DCORE - -I src/bpf/headers/ - -I../libs/core/ - -I../libs/bpfheaders/ - -I src/bpf/ - -target bpf - -O2 -g - -march=bpf -mcpu=v2", - ) + .clang_args([ + "-c", + "-D__BPF_TRACING__", + "-DCORE", + "-Isrc/bpf/headers/", + "-I../libs/core/", + "-I../libs/bpfheaders/", + "-Isrc/bpf/", + "-O2 -g", + "-mcpu=v2", + ]) .debug(false) .build_and_generate(&out) .unwrap(); diff --git a/plugins/edriver-rust/src/bpf/headers/libbpf/libbpf.a b/plugins/edriver-rust/src/bpf/headers/libbpf/libbpf.a index 87144799..b9c77f6e 100644 Binary files a/plugins/edriver-rust/src/bpf/headers/libbpf/libbpf.a and b/plugins/edriver-rust/src/bpf/headers/libbpf/libbpf.a differ diff --git a/plugins/edriver-rust/src/bpf/headers/libbpf/obj/libbpf.a b/plugins/edriver-rust/src/bpf/headers/libbpf/obj/libbpf.a index 87144799..b9c77f6e 100644 Binary files a/plugins/edriver-rust/src/bpf/headers/libbpf/obj/libbpf.a and b/plugins/edriver-rust/src/bpf/headers/libbpf/obj/libbpf.a differ diff --git a/plugins/edriver/bpf/Makefile b/plugins/edriver/bpf/Makefile index 35c21542..bbc4a8cb 100644 --- a/plugins/edriver/bpf/Makefile +++ b/plugins/edriver/bpf/Makefile @@ -205,7 +205,7 @@ hades_ebpf_driver.bpf.core.o: \ -I $(LIB_PATH)/bpfheaders/ \ -target bpf \ -O2 -g \ - -march=bpf -mcpu=v2 \ + -mcpu=v2 \ -c $(HADES_SRC) \ -o $@ diff --git a/plugins/libs/bpfheaders/define.h b/plugins/libs/bpfheaders/define.h index 1b15190d..250fd366 100644 --- a/plugins/libs/bpfheaders/define.h +++ b/plugins/libs/bpfheaders/define.h @@ -265,6 +265,15 @@ static __always_inline __u64 *get_config(__u32 key) return bpf_map_lookup_elem(&config_map, &key); } +// compatibility for kernel version v6.4.x and higher +// iovec changed: iov to __iov +// referer: https://elixir.bootlin.com/linux/v6.4.16/source/include/linux/uio.h +// static __always_inline struct iovec hades_iter_iov(struct msghdr *msg) +// { +// struct iovec *iov = (struct iovec *)READ_KERN(msg->msg_iter.iov); +// return iov; +// } + /* config */ // #define DENY_BPF 0 #define STEXT 0