mirror of
https://github.com/ParrotXray/Mantis.git
synced 2026-08-24 18:50:28 +09:00
feat: change ebpf build path
This commit is contained in:
parent
12050089c4
commit
511e1259f2
@ -15,7 +15,7 @@ fn main() {
|
||||
let rule_dir = manifest_dir.join("static").join("rules");
|
||||
let csv_dir = manifest_dir.parent().unwrap().join("records");
|
||||
|
||||
let lib_dir = manifest_dir.parent().unwrap().join("lib");
|
||||
let lib_dir = manifest_dir.parent().unwrap().join("lib");
|
||||
let onnxruntime_dir = lib_dir.join("onnxruntime").join("libonnxruntime.so");
|
||||
let ingress_edpf_dir = lib_dir.join("ebpf").join("mantis-ingress");
|
||||
let egress_edpf_dir = lib_dir.join("ebpf").join("mantis-egress");
|
||||
@ -49,21 +49,19 @@ fn main() {
|
||||
}
|
||||
|
||||
if env::var_os("SKIP_EBPF_BUILD").is_some() {
|
||||
let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
for name in &["mantis-ingress", "mantis-egress"] {
|
||||
let path = out.join(name);
|
||||
for path in &[&ingress_edpf_dir, &egress_edpf_dir] {
|
||||
if !path.exists() {
|
||||
fs::write(&path, []).unwrap_or_else(|e| panic!("cannot write stub {path:?}: {e}"));
|
||||
fs::write(path, []).unwrap_or_else(|e| panic!("cannot write stub {path:?}: {e}"));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
build_ingress_ebpf();
|
||||
build_egress_ebpf();
|
||||
build_ingress_ebpf(&ingress_edpf_dir);
|
||||
build_egress_ebpf(&egress_edpf_dir);
|
||||
build_frontend(&frontend_dir, &static_web);
|
||||
}
|
||||
|
||||
fn build_ingress_ebpf() {
|
||||
fn build_ingress_ebpf(dst: &PathBuf) {
|
||||
let Metadata { packages, .. } = MetadataCommand::new().no_deps().exec().unwrap();
|
||||
let ebpf_package = packages
|
||||
.into_iter()
|
||||
@ -162,14 +160,12 @@ fn build_ingress_ebpf() {
|
||||
|
||||
stderr.join().map_err(std::panic::resume_unwind).unwrap();
|
||||
|
||||
for (name, binary) in executables {
|
||||
let dst = out_dir.join(name);
|
||||
let _: u64 =
|
||||
fs::copy(&binary, &dst).unwrap_or_else(|err| panic!("failed to copy {binary:?} to {dst:?}: {err}"));
|
||||
for (_name, binary) in executables {
|
||||
let _: u64 = fs::copy(&binary, dst).unwrap_or_else(|err| panic!("failed to copy {binary:?} to {dst:?}: {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
fn build_egress_ebpf() {
|
||||
fn build_egress_ebpf(dst: &PathBuf) {
|
||||
let Metadata { packages, .. } = MetadataCommand::new().no_deps().exec().unwrap();
|
||||
let ebpf_package = packages
|
||||
.into_iter()
|
||||
@ -269,10 +265,8 @@ fn build_egress_ebpf() {
|
||||
|
||||
stderr.join().map_err(std::panic::resume_unwind).unwrap();
|
||||
|
||||
for (name, binary) in executables {
|
||||
let dst = out_dir.join(name);
|
||||
let _: u64 =
|
||||
fs::copy(&binary, &dst).unwrap_or_else(|err| panic!("failed to copy {binary:?} to {dst:?}: {err}"));
|
||||
for (_name, binary) in executables {
|
||||
let _: u64 = fs::copy(&binary, dst).unwrap_or_else(|err| panic!("failed to copy {binary:?} to {dst:?}: {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,10 @@ impl System {
|
||||
let (mut egress_ebpf, egress_program_array) = System::get_egress_ebpf()?;
|
||||
let app_config = Arc::new(AppConfig::new()?);
|
||||
|
||||
let inference_config = Arc::new(InferenceConfig::load_file(&app_config.models_config_name, &app_config.ae_threshold_method)?);
|
||||
let inference_config = Arc::new(InferenceConfig::load_file(
|
||||
&app_config.models_config_name,
|
||||
&app_config.ae_threshold_method,
|
||||
)?);
|
||||
|
||||
let ebpf_services = Arc::new(EbpfServices::new(
|
||||
app_config.clone(),
|
||||
@ -82,7 +85,9 @@ impl System {
|
||||
log!(SystemLog::InitializeComplete);
|
||||
self.attach_ebpf()?;
|
||||
|
||||
ebpf_services.run(app_services.ml_engine.clone(), app_services.suricata_engine.clone()).await?;
|
||||
ebpf_services
|
||||
.run(app_services.ml_engine.clone(), app_services.suricata_engine.clone())
|
||||
.await?;
|
||||
app_services.run().await?;
|
||||
self.run_http_server().await?;
|
||||
Ok(())
|
||||
@ -172,11 +177,8 @@ impl System {
|
||||
}
|
||||
|
||||
fn get_ingress_ebpf() -> Result<(Ebpf, ProgramArray<MapData>), Error> {
|
||||
let mut ingress_ebpf = Ebpf::load(aya::include_bytes_aligned!(concat!(
|
||||
env!("OUT_DIR"),
|
||||
"/mantis-ingress"
|
||||
)))
|
||||
.map_err(EbpfError::EbpfNotFound)?;
|
||||
let mut ingress_ebpf =
|
||||
Ebpf::load(aya::include_bytes_aligned!(env!("INGRESS_PATH"))).map_err(EbpfError::EbpfNotFound)?;
|
||||
let program_array = ingress_ebpf.take_map("PROGRAM_ARRAY").ok_or(EbpfError::MapNotFound)?;
|
||||
let mut program_array = ProgramArray::try_from(program_array).map_err(EbpfError::MapOperationError)?;
|
||||
Self::load_program(
|
||||
@ -197,11 +199,8 @@ impl System {
|
||||
}
|
||||
|
||||
fn get_egress_ebpf() -> Result<(Ebpf, ProgramArray<MapData>), Error> {
|
||||
let mut egress_ebpf = Ebpf::load(aya::include_bytes_aligned!(concat!(
|
||||
env!("OUT_DIR"),
|
||||
"/mantis-egress"
|
||||
)))
|
||||
.map_err(EbpfError::EbpfNotFound)?;
|
||||
let mut egress_ebpf =
|
||||
Ebpf::load(aya::include_bytes_aligned!(env!("EGRESS_PATH"))).map_err(EbpfError::EbpfNotFound)?;
|
||||
let program_array = egress_ebpf.take_map("PROGRAM_ARRAY").ok_or(EbpfError::MapNotFound)?;
|
||||
let mut program_array = ProgramArray::try_from(program_array).map_err(EbpfError::MapOperationError)?;
|
||||
Self::load_program(&mut egress_ebpf, &mut program_array, "statistics", egress::STATISTICS)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user