|
|
@ -35,8 +35,8 @@ use crate::{
|
|
|
|
sys::{
|
|
|
|
sys::{
|
|
|
|
bpf_load_btf, bpf_map_freeze, bpf_map_update_elem_ptr, is_btf_datasec_supported,
|
|
|
|
bpf_load_btf, bpf_map_freeze, bpf_map_update_elem_ptr, is_btf_datasec_supported,
|
|
|
|
is_btf_decl_tag_supported, is_btf_float_supported, is_btf_func_global_supported,
|
|
|
|
is_btf_decl_tag_supported, is_btf_float_supported, is_btf_func_global_supported,
|
|
|
|
is_btf_func_supported, is_btf_supported, is_btf_type_tag_supported, is_prog_name_supported,
|
|
|
|
is_btf_func_supported, is_btf_supported, is_btf_type_tag_supported, is_perf_link_supported,
|
|
|
|
retry_with_verifier_logs,
|
|
|
|
is_prog_name_supported, retry_with_verifier_logs,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
util::{bytes_of, possible_cpus, VerifierLog, POSSIBLE_CPUS},
|
|
|
|
util::{bytes_of, possible_cpus, VerifierLog, POSSIBLE_CPUS},
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -65,50 +65,39 @@ unsafe impl<T: Pod, const N: usize> Pod for [T; N] {}
|
|
|
|
|
|
|
|
|
|
|
|
pub use aya_obj::maps::{bpf_map_def, PinningType};
|
|
|
|
pub use aya_obj::maps::{bpf_map_def, PinningType};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
|
|
|
pub(crate) static ref FEATURES: Features = Features::new();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Features implements BPF and BTF feature detection
|
|
|
|
// Features implements BPF and BTF feature detection
|
|
|
|
#[derive(Default, Debug)]
|
|
|
|
#[derive(Default, Debug)]
|
|
|
|
pub(crate) struct Features {
|
|
|
|
pub(crate) struct Features {
|
|
|
|
pub bpf_name: bool,
|
|
|
|
pub bpf_name: bool,
|
|
|
|
|
|
|
|
pub bpf_perf_link: bool,
|
|
|
|
pub btf: Option<BtfFeatures>,
|
|
|
|
pub btf: Option<BtfFeatures>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Features {
|
|
|
|
impl Features {
|
|
|
|
fn probe_features(&mut self) {
|
|
|
|
fn new() -> Self {
|
|
|
|
self.bpf_name = is_prog_name_supported();
|
|
|
|
let btf = if is_btf_supported() {
|
|
|
|
debug!("[FEAT PROBE] BPF program name support: {}", self.bpf_name);
|
|
|
|
Some(BtfFeatures {
|
|
|
|
|
|
|
|
btf_func: is_btf_func_supported(),
|
|
|
|
self.btf = if is_btf_supported() {
|
|
|
|
btf_func_global: is_btf_func_global_supported(),
|
|
|
|
Some(BtfFeatures::default())
|
|
|
|
btf_datasec: is_btf_datasec_supported(),
|
|
|
|
|
|
|
|
btf_float: is_btf_float_supported(),
|
|
|
|
|
|
|
|
btf_decl_tag: is_btf_decl_tag_supported(),
|
|
|
|
|
|
|
|
btf_type_tag: is_btf_type_tag_supported(),
|
|
|
|
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
None
|
|
|
|
};
|
|
|
|
};
|
|
|
|
debug!("[FEAT PROBE] BTF support: {}", self.btf.is_some());
|
|
|
|
let f = Features {
|
|
|
|
|
|
|
|
bpf_name: is_prog_name_supported(),
|
|
|
|
if let Some(ref mut btf) = self.btf {
|
|
|
|
bpf_perf_link: is_perf_link_supported(),
|
|
|
|
btf.btf_func = is_btf_func_supported();
|
|
|
|
btf,
|
|
|
|
debug!("[FEAT PROBE] BTF func support: {}", btf.btf_func);
|
|
|
|
};
|
|
|
|
|
|
|
|
debug!("BPF Feature Detection: {:#?}", f);
|
|
|
|
btf.btf_func_global = is_btf_func_global_supported();
|
|
|
|
f
|
|
|
|
debug!(
|
|
|
|
|
|
|
|
"[FEAT PROBE] BTF global func support: {}",
|
|
|
|
|
|
|
|
btf.btf_func_global
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btf.btf_datasec = is_btf_datasec_supported();
|
|
|
|
|
|
|
|
debug!(
|
|
|
|
|
|
|
|
"[FEAT PROBE] BTF var and datasec support: {}",
|
|
|
|
|
|
|
|
btf.btf_datasec
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btf.btf_float = is_btf_float_supported();
|
|
|
|
|
|
|
|
debug!("[FEAT PROBE] BTF float support: {}", btf.btf_float);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btf.btf_decl_tag = is_btf_decl_tag_supported();
|
|
|
|
|
|
|
|
debug!("[FEAT PROBE] BTF decl_tag support: {}", btf.btf_decl_tag);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btf.btf_type_tag = is_btf_type_tag_supported();
|
|
|
|
|
|
|
|
debug!("[FEAT PROBE] BTF type_tag support: {}", btf.btf_type_tag);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -139,7 +128,6 @@ pub struct BpfLoader<'a> {
|
|
|
|
map_pin_path: Option<PathBuf>,
|
|
|
|
map_pin_path: Option<PathBuf>,
|
|
|
|
globals: HashMap<&'a str, &'a [u8]>,
|
|
|
|
globals: HashMap<&'a str, &'a [u8]>,
|
|
|
|
max_entries: HashMap<&'a str, u32>,
|
|
|
|
max_entries: HashMap<&'a str, u32>,
|
|
|
|
features: Features,
|
|
|
|
|
|
|
|
extensions: HashSet<&'a str>,
|
|
|
|
extensions: HashSet<&'a str>,
|
|
|
|
verifier_log_level: VerifierLogLevel,
|
|
|
|
verifier_log_level: VerifierLogLevel,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -169,14 +157,11 @@ impl Default for VerifierLogLevel {
|
|
|
|
impl<'a> BpfLoader<'a> {
|
|
|
|
impl<'a> BpfLoader<'a> {
|
|
|
|
/// Creates a new loader instance.
|
|
|
|
/// Creates a new loader instance.
|
|
|
|
pub fn new() -> BpfLoader<'a> {
|
|
|
|
pub fn new() -> BpfLoader<'a> {
|
|
|
|
let mut features = Features::default();
|
|
|
|
|
|
|
|
features.probe_features();
|
|
|
|
|
|
|
|
BpfLoader {
|
|
|
|
BpfLoader {
|
|
|
|
btf: Btf::from_sys_fs().ok().map(Cow::Owned),
|
|
|
|
btf: Btf::from_sys_fs().ok().map(Cow::Owned),
|
|
|
|
map_pin_path: None,
|
|
|
|
map_pin_path: None,
|
|
|
|
globals: HashMap::new(),
|
|
|
|
globals: HashMap::new(),
|
|
|
|
max_entries: HashMap::new(),
|
|
|
|
max_entries: HashMap::new(),
|
|
|
|
features,
|
|
|
|
|
|
|
|
extensions: HashSet::new(),
|
|
|
|
extensions: HashSet::new(),
|
|
|
|
verifier_log_level: VerifierLogLevel::default(),
|
|
|
|
verifier_log_level: VerifierLogLevel::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -360,8 +345,8 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
let mut obj = Object::parse(data)?;
|
|
|
|
let mut obj = Object::parse(data)?;
|
|
|
|
obj.patch_map_data(self.globals.clone())?;
|
|
|
|
obj.patch_map_data(self.globals.clone())?;
|
|
|
|
|
|
|
|
|
|
|
|
let btf_fd = if let Some(ref btf) = self.features.btf {
|
|
|
|
let btf_fd = if let Some(features) = &FEATURES.btf {
|
|
|
|
if let Some(btf) = obj.fixup_and_sanitize_btf(btf)? {
|
|
|
|
if let Some(btf) = obj.fixup_and_sanitize_btf(features)? {
|
|
|
|
// load btf to the kernel
|
|
|
|
// load btf to the kernel
|
|
|
|
Some(load_btf(btf.to_bytes())?)
|
|
|
|
Some(load_btf(btf.to_bytes())?)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -449,7 +434,7 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
.programs
|
|
|
|
.programs
|
|
|
|
.drain()
|
|
|
|
.drain()
|
|
|
|
.map(|(name, obj)| {
|
|
|
|
.map(|(name, obj)| {
|
|
|
|
let prog_name = if self.features.bpf_name {
|
|
|
|
let prog_name = if FEATURES.bpf_name {
|
|
|
|
Some(name.clone())
|
|
|
|
Some(name.clone())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
None
|
|
|
|