Projects STRLCPY ebpfguard Commits 0b8f033b
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    guardity-ebpf/Cargo.toml
    skipped 6 lines
    7 7  aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
    8 8  guardity-common = { path = "../guardity-common" }
    9 9   
     10 +[build-dependencies]
     11 +aya-tool = { git = "https://github.com/aya-rs/aya", branch = "main" }
     12 + 
    10 13  [lib]
    11 14  name = "guardity_ebpf"
    12 15  path = "src/lib.rs"
    skipped 23 lines
  • ■ ■ ■ ■ ■ ■
    guardity-ebpf/build.rs
     1 +use std::{
     2 + env,
     3 + fs::File,
     4 + io::Write,
     5 + path::{Path, PathBuf},
     6 +};
     7 + 
     8 +use aya_tool::generate::InputFile;
     9 + 
     10 +fn main() {
     11 + let out_dir = env::var_os("OUT_DIR").unwrap();
     12 + let dest_path = Path::new(&out_dir).join("vmlinux.rs");
     13 + 
     14 + let names: Vec<&str> = vec![
     15 + "cred",
     16 + "sock",
     17 + "sockaddr",
     18 + "sockaddr_in",
     19 + "sockaddr_in6",
     20 + "task_struct",
     21 + ];
     22 + 
     23 + let bindings = aya_tool::generate(
     24 + InputFile::Btf(PathBuf::from("/sys/kernel/btf/vmlinux")),
     25 + &names,
     26 + &[],
     27 + )
     28 + .unwrap();
     29 + 
     30 + let mut out = File::create(&dest_path).unwrap();
     31 + write!(out, "{}", bindings).unwrap();
     32 + 
     33 + println!("cargo:rerun-if-changed=build.rs");
     34 +}
     35 + 
  • guardity-ebpf/src/vmlinux.rs
    Diff is too large to be displayed.
  • ■ ■ ■ ■ ■ ■
    xtask/src/codegen.rs
    1  -use aya_tool::generate::InputFile;
    2  -use std::{fs::File, io::Write, path::PathBuf};
    3  - 
    4  -pub fn generate() -> Result<(), anyhow::Error> {
    5  - let dir = PathBuf::from("guardity-ebpf/src");
    6  - let names: Vec<&str> = vec![
    7  - "cred",
    8  - "sock",
    9  - "sockaddr",
    10  - "sockaddr_in",
    11  - "sockaddr_in6",
    12  - "task_struct",
    13  - ];
    14  - let bindings = aya_tool::generate(
    15  - InputFile::Btf(PathBuf::from("/sys/kernel/btf/vmlinux")),
    16  - &names,
    17  - &[],
    18  - )?;
    19  - // Write the bindings to the $OUT_DIR/bindings.rs file.
    20  - let mut out = File::create(dir.join("vmlinux.rs"))?;
    21  - write!(out, "{}", bindings)?;
    22  - Ok(())
    23  -}
    24  - 
  • ■ ■ ■ ■ ■ ■
    xtask/src/main.rs
    1 1  mod build_ebpf;
    2  -mod codegen;
    3 2  mod run;
    4 3   
    5 4  use std::process::exit;
    skipped 9 lines
    15 14  #[derive(Debug, Parser)]
    16 15  enum Command {
    17 16   BuildEbpf(build_ebpf::Options),
    18  - Codegen,
    19 17   Run(run::Options),
    20 18  }
    21 19   
    skipped 3 lines
    25 23   use Command::*;
    26 24   let ret = match opts.command {
    27 25   BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
    28  - Codegen => codegen::generate(),
    29 26   Run(opts) => run::run(opts),
    30 27   };
    31 28   
    skipped 6 lines
Please wait...
Page is in error, reload to recover