Skip to content

Commit

Permalink
chore: Update aya to 0.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vadorovsky committed Feb 27, 2025
1 parent d135aa5 commit 4ef97d2
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 34 deletions.
42 changes: 35 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ rules-engine = { path = "crates/modules/rules-engine" }
smtp-notifier = { path = "crates/modules/smtp-notifier" }
# External
anyhow = "1.0.75"
aya = { version = "0.12.0", features = ["async_tokio"] }
aya = { version = "0.13.1", features = ["async_tokio"] }
aya-ebpf-bindings = "0.1.0"
aya-obj = "0.1.0"
axum = { version = "0.8.1", features = ["ws"] }
Expand Down
32 changes: 21 additions & 11 deletions crates/bpf-common/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use aya::{
perf::{AsyncPerfEventArray, PerfBufferError},
Array, HashMap, Map, MapData,
},
programs::{CgroupSkb, CgroupSkbAttachType, KProbe, Lsm, RawTracePoint, TracePoint},
programs::{
CgroupAttachMode, CgroupSkb, CgroupSkbAttachType, KProbe, Lsm, RawTracePoint, TracePoint,
},
util::{online_cpus, KernelVersion},
Bpf, BpfLoader, Btf, BtfError, Pod,
Btf, BtfError, Ebpf, EbpfLoader, Pod,
};
use bpf_feature_autodetect::autodetect_features;
use bpf_features::BpfFeatures;
Expand Down Expand Up @@ -151,7 +153,7 @@ macro_rules! ebpf_program {
#[derive(Error, Debug)]
pub enum ProgramError {
#[error("loading probe")]
LoadingProbe(#[from] aya::BpfError),
LoadingProbe(#[from] aya::EbpfError),
#[error("program not found {0}")]
ProgramNotFound(String),
#[error("incorrect program type {0}")]
Expand Down Expand Up @@ -270,7 +272,7 @@ impl ProgramBuilder {

let bpf = tokio::task::spawn_blocking(move || {
let _ = std::fs::create_dir(&self.ctx.pinning_path);
let mut bpf = BpfLoader::new()
let mut bpf = EbpfLoader::new()
.map_pin_path(&self.ctx.pinning_path)
.btf(Some(btf.as_ref()))
.set_global("log_level", &(self.ctx.log_level as i32), true)
Expand All @@ -283,7 +285,7 @@ impl ProgramBuilder {
for program in self.programs {
program.attach(&mut bpf, &btf)?;
}
Result::<Bpf, ProgramError>::Ok(bpf)
Result::<Ebpf, ProgramError>::Ok(bpf)
})
.await
.expect("join error")?;
Expand Down Expand Up @@ -327,7 +329,7 @@ impl Display for ProgramType {
}

impl ProgramType {
fn attach(&self, bpf: &mut Bpf, btf: &Btf) -> Result<(), ProgramError> {
fn attach(&self, bpf: &mut Ebpf, btf: &Btf) -> Result<(), ProgramError> {
let load_err = |program_error| ProgramError::ProgramLoadError {
program: self.to_string(),
program_error: Box::new(program_error),
Expand Down Expand Up @@ -364,7 +366,11 @@ impl ProgramType {
.map_err(|source| MountinfoError::ReadFile { source, path })?;
program.load().map_err(load_err)?;
program
.attach(cgroup, CgroupSkbAttachType::Egress)
.attach(
cgroup,
CgroupSkbAttachType::Egress,
CgroupAttachMode::Single,
)
.map_err(attach_err)?;
}
ProgramType::CgroupSkbIngress(cgroup_skb) => {
Expand All @@ -374,15 +380,19 @@ impl ProgramType {
.map_err(|source| MountinfoError::ReadFile { source, path })?;
program.load().map_err(load_err)?;
program
.attach(cgroup, CgroupSkbAttachType::Ingress)
.attach(
cgroup,
CgroupSkbAttachType::Ingress,
CgroupAttachMode::Single,
)
.map_err(attach_err)?;
}
}
Ok(())
}
}

fn extract_program<'a, T>(bpf: &'a mut Bpf, program: &str) -> Result<&'a mut T, ProgramError>
fn extract_program<'a, T>(bpf: &'a mut Ebpf, program: &str) -> Result<&'a mut T, ProgramError>
where
T: 'a,
&'a mut T: TryFrom<&'a mut aya::programs::Program>,
Expand All @@ -399,7 +409,7 @@ pub struct Program {
tx_exit: watch::Sender<()>,
ctx: BpfContext,
name: String,
bpf: Bpf,
bpf: Ebpf,
used_maps: HashSet<String>,
}

Expand All @@ -412,7 +422,7 @@ impl Drop for Program {
}

impl Program {
pub fn bpf(&mut self) -> &mut Bpf {
pub fn bpf(&mut self) -> &mut Ebpf {
&mut self.bpf
}
/// Poll a BPF_MAP_TYPE_HASH with a certain interval
Expand Down
6 changes: 3 additions & 3 deletions crates/bpf-feature-autodetect/src/bpf_loop.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use aya::{include_bytes_aligned, programs::TracePoint, Bpf, BpfError};
use aya::{include_bytes_aligned, programs::TracePoint, Ebpf, EbpfError};
use log::warn;

fn load_probe() -> Result<(), BpfError> {
let mut bpf = Bpf::load(include_bytes_aligned!(concat!(
fn load_probe() -> Result<(), EbpfError> {
let mut bpf = Ebpf::load(include_bytes_aligned!(concat!(
env!("OUT_DIR"),
"/test_bpf_loop.none.bpf.o"
)))?;
Expand Down
4 changes: 2 additions & 2 deletions crates/bpf-feature-autodetect/src/lsm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Context, Result};
use aya::{include_bytes_aligned, programs::Lsm, BpfLoader, Btf};
use aya::{include_bytes_aligned, programs::Lsm, Btf, EbpfLoader};

/// Check if the system supports eBPF LSM programs.
/// The kernel must be build with CONFIG_BPF_LSM=y, which is available
Expand Down Expand Up @@ -40,7 +40,7 @@ fn try_load() -> Result<()> {
.ok_or_else(|| anyhow!("eBPF LSM programs disabled"))?;

// Check if we can load a program
let mut bpf = BpfLoader::new()
let mut bpf = EbpfLoader::new()
.load(TEST_LSM_PROBE)
.context("LSM enabled, but initial loading failed")?;
let program: &mut Lsm = bpf
Expand Down
6 changes: 3 additions & 3 deletions crates/bpf-filtering/src/initializer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{os::unix::prelude::OsStringExt, time::Duration};

use anyhow::{Context, Result};
use bpf_common::{aya::Bpf, Pid};
use bpf_common::{aya::Ebpf, Pid};
use pulsar_core::{
pdk::process_tracker::{ProcessTrackerHandle, TrackerUpdate},
Timestamp,
Expand Down Expand Up @@ -32,7 +32,7 @@ const INIT_TIMEOUT: Duration = Duration::from_millis(100);
/// this makes sure the eBPF code didn't fill map_interest with wrong data
/// because of unitialized entries.
pub async fn setup_events_filter(
bpf: &mut Bpf,
bpf: &mut Ebpf,
mut config: Config,
process_tracker: &ProcessTrackerHandle,
rx_processes: &mut mpsc::UnboundedReceiver<TrackerUpdate>,
Expand Down Expand Up @@ -137,7 +137,7 @@ struct Initializer {
}

impl Initializer {
fn new(bpf: &mut Bpf, config: Config) -> Result<Self> {
fn new(bpf: &mut Ebpf, config: Config) -> Result<Self> {
let mut interest_map = InterestMap::load(bpf, &config.interest_map_name)?;
// clear interest map
interest_map.clear()?;
Expand Down
6 changes: 3 additions & 3 deletions crates/bpf-filtering/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const DEFAULT_CGROUP_RULES: &str = "m_cgroup_rules";

impl InterestMap {
/// Try to load the map from eBPF
pub fn load(bpf: &mut aya::Bpf, name: &str) -> Result<Self> {
pub fn load(bpf: &mut aya::Ebpf, name: &str) -> Result<Self> {
Map::load(bpf, name).map(Self)
}

Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct RuleMap(Map<Image, u8>);

impl RuleMap {
/// Try to load the rule map
pub fn load(bpf: &mut aya::Bpf, name: &str) -> Result<Self> {
pub fn load(bpf: &mut aya::Ebpf, name: &str) -> Result<Self> {
Map::load(bpf, name).map(Self)
}

Expand Down Expand Up @@ -96,7 +96,7 @@ pub(crate) struct Map<K, V> {

impl<K: aya::Pod, V: aya::Pod> Map<K, V> {
/// Try to load the eBPF hash map with the given name
pub(crate) fn load(bpf: &mut aya::Bpf, name: &str) -> Result<Self> {
pub(crate) fn load(bpf: &mut aya::Ebpf, name: &str) -> Result<Self> {
let map = aya::maps::HashMap::try_from(
bpf.take_map(name)
.with_context(|| format!("Error finding eBPF map {name}"))?,
Expand Down
8 changes: 4 additions & 4 deletions crates/bpf-filtering/src/test_suite.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::Rule;
use crate::maps::{Cgroup, InterestMap, Map, PolicyDecision, RuleMap};
use bpf_common::aya::programs::RawTracePoint;
use bpf_common::aya::{self, Bpf, BpfLoader};
use bpf_common::aya::{self, Ebpf, EbpfLoader};
use bpf_common::program::BpfContext;
use bpf_common::test_runner::{TestCase, TestReport, TestSuite};
use bpf_common::test_utils::cgroup::fork_in_temp_cgroup;
Expand Down Expand Up @@ -278,7 +278,7 @@ fn cgroups_tracked() -> TestCase {
}

// attach a single tracepoint for test purposes
fn attach_raw_tracepoint(bpf: &mut Bpf, tp: &str) {
fn attach_raw_tracepoint(bpf: &mut Ebpf, tp: &str) {
let tracepoint: &mut RawTracePoint = bpf
.program_mut(tp)
.ok_or_else(|| ProgramError::ProgramNotFound(tp.to_string()))
Expand Down Expand Up @@ -357,7 +357,7 @@ fn exit_cleans_up_resources() -> TestCase {
})
}

fn load_ebpf() -> Bpf {
fn load_ebpf() -> Ebpf {
let ctx = BpfContext::new(
bpf_common::program::Pinning::Disabled,
bpf_common::program::PERF_PAGES_DEFAULT,
Expand All @@ -366,7 +366,7 @@ fn load_ebpf() -> Bpf {
.unwrap();
const PIN_PATH: &str = "/sys/fs/bpf/filtering-test";
let _ = std::fs::create_dir(PIN_PATH);
let bpf = BpfLoader::new()
let bpf = EbpfLoader::new()
.map_pin_path(PIN_PATH)
.load(ebpf_program!(&ctx, "filtering_example").as_slice())
.unwrap();
Expand Down

0 comments on commit 4ef97d2

Please sign in to comment.