Skip to content

Commit

Permalink
chore: use aya kernel version implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
banditopazzo authored and vadorovsky committed Dec 11, 2024
1 parent 9a3caae commit 58bd969
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 182 deletions.
14 changes: 5 additions & 9 deletions crates/bpf-common/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use aya::{
Array, HashMap, Map, MapData,
},
programs::{CgroupSkb, CgroupSkbAttachType, KProbe, Lsm, RawTracePoint, TracePoint},
util::online_cpus,
util::{online_cpus, KernelVersion},
Bpf, BpfLoader, Btf, BtfError, Pod,
};
use bpf_feature_autodetect::{autodetect_features, kernel_version::KernelVersion};
use bpf_feature_autodetect::autodetect_features;
use bpf_features::BpfFeatures;
use bytes::{Buf, Bytes, BytesMut};
use thiserror::Error;
Expand Down Expand Up @@ -83,15 +83,11 @@ impl BpfContext {
log::warn!("The default value {PERF_PAGES_DEFAULT} will be used.");
perf_pages = PERF_PAGES_DEFAULT;
}
let kernel_version = match KernelVersion::autodetect() {
let kernel_version = match KernelVersion::current() {
Ok(version) => version,
Err(err) => {
log::warn!("Error identifying kernel version {err:?}. Assuming kernel 5.0.4");
KernelVersion {
major: 5,
minor: 0,
patch: 4,
}
KernelVersion::new(5, 0, 4)
}
};
// aya doesn't support specifying from userspace wether or not to pin maps.
Expand Down Expand Up @@ -280,7 +276,7 @@ impl ProgramBuilder {
.set_global("log_level", &(self.ctx.log_level as i32), true)
.set_global(
"LINUX_KERNEL_VERSION",
&self.ctx.kernel_version.as_i32(),
&self.ctx.kernel_version.code(),
true,
)
.load(&self.probe)?;
Expand Down
165 changes: 0 additions & 165 deletions crates/bpf-feature-autodetect/src/kernel_version.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/bpf-feature-autodetect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod atomic;
pub mod bpf_loop;
pub mod func;
pub mod insn;
pub mod kernel_version;
pub mod lsm;

use crate::{
Expand Down
9 changes: 2 additions & 7 deletions crates/modules/process-monitor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Context;
use bpf_common::{
bpf_feature_autodetect::kernel_version::KernelVersion,
aya::util::KernelVersion,
containers::ContainerError,
ebpf_program,
parsing::{BufferIndex, IndexError},
Expand All @@ -19,12 +19,7 @@ pub async fn program(
let binary = ebpf_program!(&ctx, "probes");
let attach_to_lsm = ctx.lsm_supported();
// LSM task_fix_set* calls are available since kernel commit 39030e1351aa1, in 5.10
let has_cred_specific_functions = ctx.kernel_version()
>= &KernelVersion {
major: 5,
minor: 10,
patch: 0,
};
let has_cred_specific_functions = ctx.kernel_version() >= &KernelVersion::new(5, 10, 0);
let mut builder = ProgramBuilder::new(ctx, MODULE_NAME, binary)
.raw_tracepoint("sched_process_exec")
.raw_tracepoint("sched_process_exit")
Expand Down

0 comments on commit 58bd969

Please sign in to comment.