feature_probe: clarify composite logic

reviewable/pr1357/r6
Tamir Duberstein 1 month ago
parent 8e63960fee
commit 34c5328dcf
No known key found for this signature in database

@ -13,7 +13,9 @@ use crate::utils::kernel_assert;
#[test_log::test] #[test_log::test]
fn probe_supported_programs() { fn probe_supported_programs() {
let current = aya::util::KernelVersion::current().unwrap();
let kernel_config = kernel_config().unwrap_or_default(); let kernel_config = kernel_config().unwrap_or_default();
macro_rules! is_supported { macro_rules! is_supported {
($prog_type:expr) => { ($prog_type:expr) => {
is_program_supported($prog_type).unwrap() is_program_supported($prog_type).unwrap()
@ -61,22 +63,25 @@ fn probe_supported_programs() {
let kern_version = KernelVersion::new(4, 18, 0); let kern_version = KernelVersion::new(4, 18, 0);
kernel_assert!(is_supported!(ProgramType::LwtSeg6local), kern_version); kernel_assert!(is_supported!(ProgramType::LwtSeg6local), kern_version);
// `lirc_mode2` requires CONFIG_BPF_LIRC_MODE2=y if current >= kern_version {
let lirc_mode2_config = matches!( // `lirc_mode2` requires CONFIG_BPF_LIRC_MODE2=y
kernel_config.get("CONFIG_BPF_LIRC_MODE2"), let lirc_mode2_config = matches!(
Some(procfs::ConfigSetting::Yes) kernel_config.get("CONFIG_BPF_LIRC_MODE2"),
); Some(procfs::ConfigSetting::Yes)
let lirc_mode2 = is_supported!(ProgramType::LircMode2); );
kernel_assert!( assert_eq!(
if aya::util::KernelVersion::current().unwrap() >= kern_version { is_supported!(ProgramType::LircMode2),
lirc_mode2 == lirc_mode2_config lirc_mode2_config,
} else { "current={current}"
lirc_mode2 );
}, if !lirc_mode2_config {
kern_version eprintln!("CONFIG_BPF_LIRC_MODE2 required for lirc_mode2 program type");
); }
if !lirc_mode2_config { } else {
eprintln!("CONFIG_BPF_LIRC_MODE2 required for lirc_mode2 program type"); assert!(
!is_supported!(ProgramType::LircMode2),
"{current} < {kern_version}"
);
} }
let kern_version = KernelVersion::new(4, 19, 0); let kern_version = KernelVersion::new(4, 19, 0);
@ -106,24 +111,27 @@ fn probe_supported_programs() {
// `lsm` requires `CONFIG_DEBUG_INFO_BTF=y` & `CONFIG_BPF_LSM=y` // `lsm` requires `CONFIG_DEBUG_INFO_BTF=y` & `CONFIG_BPF_LSM=y`
// Ways to check if `CONFIG_BPF_LSM` is enabled: // Ways to check if `CONFIG_BPF_LSM` is enabled:
// - kernel config has `CONFIG_BPF_LSM=y`, but config is not always exposed. // - kernel config has `CONFIG_BPF_LSM=y`, but config is not always exposed.
// - an LSM hooks is present in BTF, e.g. `bpf_lsm_bpf`. hooks are found in `bpf_lsm.c` // - an LSM hook is present in BTF, e.g. `bpf_lsm_bpf`. hooks are found in `bpf_lsm.c`
let lsm_enabled = matches!( if current >= kern_version {
kernel_config.get("CONFIG_BPF_LSM"), let lsm_enabled = matches!(
Some(procfs::ConfigSetting::Yes) kernel_config.get("CONFIG_BPF_LSM"),
) || Btf::from_sys_fs() Some(procfs::ConfigSetting::Yes)
.and_then(|btf| btf.id_by_type_name_kind("bpf_lsm_bpf", aya_obj::btf::BtfKind::Func)) ) || Btf::from_sys_fs()
.is_ok(); .and_then(|btf| btf.id_by_type_name_kind("bpf_lsm_bpf", aya_obj::btf::BtfKind::Func))
let lsm = is_supported!(ProgramType::Lsm); .is_ok();
kernel_assert!( assert_eq!(
if aya::util::KernelVersion::current().unwrap() >= kern_version { is_supported!(ProgramType::Lsm),
lsm == lsm_enabled lsm_enabled,
} else { "current={current}"
lsm );
}, if !lsm_enabled {
kern_version eprintln!("CONFIG_BPF_LSM required for lsm program type");
); }
if !lsm_enabled { } else {
eprintln!("CONFIG_BPF_LSM required for lsm program type"); assert!(
!is_supported!(ProgramType::Lsm),
"{current} < {kern_version}"
);
} }
let kern_version = KernelVersion::new(5, 9, 0); let kern_version = KernelVersion::new(5, 9, 0);

Loading…
Cancel
Save