feat(aya): Rename Bpf to Ebpf

And BpfLoader to EbpfLoader.
This also adds type aliases to preserve the use of the old names, making
updating to a new Aya release less of a burden. These aliases are marked
as deprecated since we'll likely remove them in a later release.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/528/head
Dave Tucker 7 months ago
parent fd48c55466
commit 8c79b71bd5

@ -12,7 +12,7 @@
//! This example uses the [env_logger] crate to log messages to the terminal. //! This example uses the [env_logger] crate to log messages to the terminal.
//! //!
//! ```no_run //! ```no_run
//! # let mut bpf = aya::Bpf::load(&[]).unwrap(); //! # let mut bpf = aya::Ebpf::load(&[]).unwrap();
//! use aya_log::EbpfLogger; //! use aya_log::EbpfLogger;
//! //!
//! // initialize env_logger as the default logger //! // initialize env_logger as the default logger
@ -65,7 +65,7 @@ use aya::{
MapError, MapError,
}, },
util::online_cpus, util::online_cpus,
Bpf, Pod, Ebpf, Pod,
}; };
use aya_log_common::{ use aya_log_common::{
Argument, DisplayHint, Level, LogValueLength, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS, Argument, DisplayHint, Level, LogValueLength, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS,
@ -102,14 +102,14 @@ pub type BpfLogger = EbpfLogger;
impl EbpfLogger { impl EbpfLogger {
/// Starts reading log records created with `aya-log-ebpf` and logs them /// Starts reading log records created with `aya-log-ebpf` and logs them
/// with the default logger. See [log::logger]. /// with the default logger. See [log::logger].
pub fn init(bpf: &mut Bpf) -> Result<EbpfLogger, Error> { pub fn init(bpf: &mut Ebpf) -> Result<EbpfLogger, Error> {
EbpfLogger::init_with_logger(bpf, log::logger()) EbpfLogger::init_with_logger(bpf, log::logger())
} }
/// Starts reading log records created with `aya-log-ebpf` and logs them /// Starts reading log records created with `aya-log-ebpf` and logs them
/// with the given logger. /// with the given logger.
pub fn init_with_logger<T: Log + 'static>( pub fn init_with_logger<T: Log + 'static>(
bpf: &mut Bpf, bpf: &mut Ebpf,
logger: T, logger: T,
) -> Result<EbpfLogger, Error> { ) -> Result<EbpfLogger, Error> {
let logger = Arc::new(logger); let logger = Arc::new(logger);

@ -235,14 +235,14 @@ impl BtfFeatures {
} }
} }
/// Bpf Type Format metadata. /// BPF Type Format metadata.
/// ///
/// BTF is a kind of debug metadata that allows eBPF programs compiled against one kernel version /// BTF is a kind of debug metadata that allows eBPF programs compiled against one kernel version
/// to be loaded into different kernel versions. /// to be loaded into different kernel versions.
/// ///
/// Aya automatically loads BTF metadata if you use `Bpf::load_file`. You /// Aya automatically loads BTF metadata if you use `Ebpf::load_file`. You
/// only need to explicitly use this type if you want to load BTF from a non-standard /// only need to explicitly use this type if you want to load BTF from a non-standard
/// location or if you are using `Bpf::load`. /// location or if you are using `Ebpf::load`.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Btf { pub struct Btf {
header: btf_header, header: btf_header,

@ -110,26 +110,26 @@ pub fn features() -> &'static Features {
/// Builder style API for advanced loading of eBPF programs. /// Builder style API for advanced loading of eBPF programs.
/// ///
/// Loading eBPF code involves a few steps, including loading maps and applying /// Loading eBPF code involves a few steps, including loading maps and applying
/// relocations. You can use `BpfLoader` to customize some of the loading /// relocations. You can use `EbpfLoader` to customize some of the loading
/// options. /// options.
/// ///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya::{BpfLoader, Btf}; /// use aya::{EbpfLoader, Btf};
/// use std::fs; /// use std::fs;
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// // load the BTF data from /sys/kernel/btf/vmlinux /// // load the BTF data from /sys/kernel/btf/vmlinux
/// .btf(Btf::from_sys_fs().ok().as_ref()) /// .btf(Btf::from_sys_fs().ok().as_ref())
/// // load pinned maps from /sys/fs/bpf/my-program /// // load pinned maps from /sys/fs/bpf/my-program
/// .map_pin_path("/sys/fs/bpf/my-program") /// .map_pin_path("/sys/fs/bpf/my-program")
/// // finally load the code /// // finally load the code
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
pub struct BpfLoader<'a> { pub struct EbpfLoader<'a> {
btf: Option<Cow<'a, Btf>>, btf: Option<Cow<'a, Btf>>,
map_pin_path: Option<PathBuf>, map_pin_path: Option<PathBuf>,
globals: HashMap<&'a str, (&'a [u8], bool)>, globals: HashMap<&'a str, (&'a [u8], bool)>,
@ -139,8 +139,12 @@ pub struct BpfLoader<'a> {
allow_unsupported_maps: bool, allow_unsupported_maps: bool,
} }
/// Builder style API for advanced loading of eBPF programs.
#[deprecated(since = "0.13.0", note = "use `EbpfLoader` instead")]
pub type BpfLoader<'a> = EbpfLoader<'a>;
bitflags::bitflags! { bitflags::bitflags! {
/// Used to set the verifier log level flags in [BpfLoader](BpfLoader::verifier_log_level()). /// Used to set the verifier log level flags in [EbpfLoader](EbpfLoader::verifier_log_level()).
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct VerifierLogLevel: u32 { pub struct VerifierLogLevel: u32 {
/// Sets no verifier logging. /// Sets no verifier logging.
@ -160,7 +164,7 @@ impl Default for VerifierLogLevel {
} }
} }
impl<'a> BpfLoader<'a> { impl<'a> EbpfLoader<'a> {
/// Creates a new loader instance. /// Creates a new loader instance.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -182,16 +186,16 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::{BpfLoader, Btf, Endianness}; /// use aya::{EbpfLoader, Btf, Endianness};
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// // load the BTF data from a custom location /// // load the BTF data from a custom location
/// .btf(Btf::parse_file("/custom_btf_file", Endianness::default()).ok().as_ref()) /// .btf(Btf::parse_file("/custom_btf_file", Endianness::default()).ok().as_ref())
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn btf(&mut self, btf: Option<&'a Btf>) -> &mut BpfLoader<'a> { pub fn btf(&mut self, btf: Option<&'a Btf>) -> &mut EbpfLoader<'a> {
self.btf = btf.map(Cow::Borrowed); self.btf = btf.map(Cow::Borrowed);
self self
} }
@ -207,15 +211,15 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// .allow_unsupported_maps() /// .allow_unsupported_maps()
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn allow_unsupported_maps(&mut self) -> &mut BpfLoader<'a> { pub fn allow_unsupported_maps(&mut self) -> &mut EbpfLoader<'a> {
self.allow_unsupported_maps = true; self.allow_unsupported_maps = true;
self self
} }
@ -228,22 +232,22 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// .map_pin_path("/sys/fs/bpf/my-program") /// .map_pin_path("/sys/fs/bpf/my-program")
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn map_pin_path<P: AsRef<Path>>(&mut self, path: P) -> &mut BpfLoader<'a> { pub fn map_pin_path<P: AsRef<Path>>(&mut self, path: P) -> &mut EbpfLoader<'a> {
self.map_pin_path = Some(path.as_ref().to_owned()); self.map_pin_path = Some(path.as_ref().to_owned());
self self
} }
/// Sets the value of a global variable. /// Sets the value of a global variable.
/// ///
/// If the `must_exist` argument is `true`, [`BpfLoader::load`] will fail with [`ParseError::SymbolNotFound`] if the loaded object code does not contain the variable. /// If the `must_exist` argument is `true`, [`EbpfLoader::load`] will fail with [`ParseError::SymbolNotFound`] if the loaded object code does not contain the variable.
/// ///
/// From Rust eBPF, a global variable can be defined as follows: /// From Rust eBPF, a global variable can be defined as follows:
/// ///
@ -271,13 +275,13 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// .set_global("VERSION", &2, true) /// .set_global("VERSION", &2, true)
/// .set_global("PIDS", &[1234u16, 5678], true) /// .set_global("PIDS", &[1234u16, 5678], true)
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn set_global<T: Into<GlobalData<'a>>>( pub fn set_global<T: Into<GlobalData<'a>>>(
@ -285,7 +289,7 @@ impl<'a> BpfLoader<'a> {
name: &'a str, name: &'a str,
value: T, value: T,
must_exist: bool, must_exist: bool,
) -> &mut BpfLoader<'a> { ) -> &mut EbpfLoader<'a> {
self.globals.insert(name, (value.into().bytes, must_exist)); self.globals.insert(name, (value.into().bytes, must_exist));
self self
} }
@ -298,15 +302,15 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// .set_max_entries("map", 64) /// .set_max_entries("map", 64)
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn set_max_entries(&mut self, name: &'a str, size: u32) -> &mut BpfLoader<'a> { pub fn set_max_entries(&mut self, name: &'a str, size: u32) -> &mut EbpfLoader<'a> {
self.max_entries.insert(name, size); self.max_entries.insert(name, size);
self self
} }
@ -320,15 +324,15 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// .extension("myfunc") /// .extension("myfunc")
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn extension(&mut self, name: &'a str) -> &mut BpfLoader<'a> { pub fn extension(&mut self, name: &'a str) -> &mut EbpfLoader<'a> {
self.extensions.insert(name); self.extensions.insert(name);
self self
} }
@ -338,15 +342,15 @@ impl<'a> BpfLoader<'a> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use aya::{BpfLoader, VerifierLogLevel}; /// use aya::{EbpfLoader, VerifierLogLevel};
/// ///
/// let bpf = BpfLoader::new() /// let bpf = EbpfLoader::new()
/// .verifier_log_level(VerifierLogLevel::VERBOSE | VerifierLogLevel::STATS) /// .verifier_log_level(VerifierLogLevel::VERBOSE | VerifierLogLevel::STATS)
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn verifier_log_level(&mut self, level: VerifierLogLevel) -> &mut BpfLoader<'a> { pub fn verifier_log_level(&mut self, level: VerifierLogLevel) -> &mut EbpfLoader<'a> {
self.verifier_log_level = level; self.verifier_log_level = level;
self self
} }
@ -356,14 +360,14 @@ impl<'a> BpfLoader<'a> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = BpfLoader::new().load_file("file.o")?; /// let bpf = EbpfLoader::new().load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn load_file<P: AsRef<Path>>(&mut self, path: P) -> Result<Bpf, BpfError> { pub fn load_file<P: AsRef<Path>>(&mut self, path: P) -> Result<Ebpf, EbpfError> {
let path = path.as_ref(); let path = path.as_ref();
self.load(&fs::read(path).map_err(|error| BpfError::FileError { self.load(&fs::read(path).map_err(|error| EbpfError::FileError {
path: path.to_owned(), path: path.to_owned(),
error, error,
})?) })?)
@ -374,14 +378,14 @@ impl<'a> BpfLoader<'a> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya::BpfLoader; /// use aya::EbpfLoader;
/// use std::fs; /// use std::fs;
/// ///
/// let data = fs::read("file.o").unwrap(); /// let data = fs::read("file.o").unwrap();
/// let bpf = BpfLoader::new().load(&data)?; /// let bpf = EbpfLoader::new().load(&data)?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn load(&mut self, data: &[u8]) -> Result<Bpf, BpfError> { pub fn load(&mut self, data: &[u8]) -> Result<Ebpf, EbpfError> {
let Self { let Self {
btf, btf,
map_pin_path, map_pin_path,
@ -407,7 +411,7 @@ impl<'a> BpfLoader<'a> {
| ProgramSection::FExit { sleepable: _ } | ProgramSection::FExit { sleepable: _ }
| ProgramSection::Lsm { sleepable: _ } | ProgramSection::Lsm { sleepable: _ }
| ProgramSection::BtfTracePoint => { | ProgramSection::BtfTracePoint => {
return Err(BpfError::BtfError(err)) return Err(EbpfError::BtfError(err))
} }
ProgramSection::KRetProbe ProgramSection::KRetProbe
| ProgramSection::KProbe | ProgramSection::KProbe
@ -461,9 +465,9 @@ impl<'a> BpfLoader<'a> {
{ {
continue; continue;
} }
let num_cpus = || -> Result<u32, BpfError> { let num_cpus = || -> Result<u32, EbpfError> {
Ok(possible_cpus() Ok(possible_cpus()
.map_err(|error| BpfError::FileError { .map_err(|error| EbpfError::FileError {
path: PathBuf::from(POSSIBLE_CPUS), path: PathBuf::from(POSSIBLE_CPUS),
error, error,
})? })?
@ -694,22 +698,22 @@ impl<'a> BpfLoader<'a> {
let maps = maps let maps = maps
.drain() .drain()
.map(parse_map) .map(parse_map)
.collect::<Result<HashMap<String, Map>, BpfError>>()?; .collect::<Result<HashMap<String, Map>, EbpfError>>()?;
if !*allow_unsupported_maps { if !*allow_unsupported_maps {
maps.iter().try_for_each(|(_, x)| match x { maps.iter().try_for_each(|(_, x)| match x {
Map::Unsupported(map) => Err(BpfError::MapError(MapError::Unsupported { Map::Unsupported(map) => Err(EbpfError::MapError(MapError::Unsupported {
map_type: map.obj().map_type(), map_type: map.obj().map_type(),
})), })),
_ => Ok(()), _ => Ok(()),
})?; })?;
}; };
Ok(Bpf { maps, programs }) Ok(Ebpf { maps, programs })
} }
} }
fn parse_map(data: (String, MapData)) -> Result<(String, Map), BpfError> { fn parse_map(data: (String, MapData)) -> Result<(String, Map), EbpfError> {
let (name, map) = data; let (name, map) = data;
let map_type = bpf_map_type::try_from(map.obj().map_type()).map_err(MapError::from)?; let map_type = bpf_map_type::try_from(map.obj().map_type()).map_err(MapError::from)?;
let map = match map_type { let map = match map_type {
@ -748,9 +752,9 @@ fn max_entries_override(
map_type: bpf_map_type, map_type: bpf_map_type,
user_override: Option<u32>, user_override: Option<u32>,
current_value: impl Fn() -> u32, current_value: impl Fn() -> u32,
num_cpus: impl Fn() -> Result<u32, BpfError>, num_cpus: impl Fn() -> Result<u32, EbpfError>,
page_size: impl Fn() -> u32, page_size: impl Fn() -> u32,
) -> Result<Option<u32>, BpfError> { ) -> Result<Option<u32>, EbpfError> {
let max_entries = || user_override.unwrap_or_else(&current_value); let max_entries = || user_override.unwrap_or_else(&current_value);
Ok(match map_type { Ok(match map_type {
BPF_MAP_TYPE_PERF_EVENT_ARRAY if max_entries() == 0 => Some(num_cpus()?), BPF_MAP_TYPE_PERF_EVENT_ARRAY if max_entries() == 0 => Some(num_cpus()?),
@ -841,38 +845,42 @@ mod tests {
} }
} }
impl Default for BpfLoader<'_> { impl Default for EbpfLoader<'_> {
fn default() -> Self { fn default() -> Self {
BpfLoader::new() EbpfLoader::new()
} }
} }
/// The main entry point into the library, used to work with eBPF programs and maps. /// The main entry point into the library, used to work with eBPF programs and maps.
#[derive(Debug)] #[derive(Debug)]
pub struct Bpf { pub struct Ebpf {
maps: HashMap<String, Map>, maps: HashMap<String, Map>,
programs: HashMap<String, Program>, programs: HashMap<String, Program>,
} }
impl Bpf { /// The main entry point into the library, used to work with eBPF programs and maps.
#[deprecated(since = "0.13.0", note = "use `Ebpf` instead")]
pub type Bpf = Ebpf;
impl Ebpf {
/// Loads eBPF bytecode from a file. /// Loads eBPF bytecode from a file.
/// ///
/// Parses the given object code file and initializes the [maps](crate::maps) defined in it. If /// Parses the given object code file and initializes the [maps](crate::maps) defined in it. If
/// the kernel supports [BTF](Btf) debug info, it is automatically loaded from /// the kernel supports [BTF](Btf) debug info, it is automatically loaded from
/// `/sys/kernel/btf/vmlinux`. /// `/sys/kernel/btf/vmlinux`.
/// ///
/// For more loading options, see [BpfLoader]. /// For more loading options, see [EbpfLoader].
/// ///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya::Bpf; /// use aya::Ebpf;
/// ///
/// let bpf = Bpf::load_file("file.o")?; /// let bpf = Ebpf::load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Self, BpfError> { pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Self, EbpfError> {
BpfLoader::new() EbpfLoader::new()
.btf(Btf::from_sys_fs().ok().as_ref()) .btf(Btf::from_sys_fs().ok().as_ref())
.load_file(path) .load_file(path)
} }
@ -883,21 +891,21 @@ impl Bpf {
/// [maps](crate::maps) defined in it. If the kernel supports [BTF](Btf) /// [maps](crate::maps) defined in it. If the kernel supports [BTF](Btf)
/// debug info, it is automatically loaded from `/sys/kernel/btf/vmlinux`. /// debug info, it is automatically loaded from `/sys/kernel/btf/vmlinux`.
/// ///
/// For more loading options, see [BpfLoader]. /// For more loading options, see [EbpfLoader].
/// ///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya::{Bpf, Btf}; /// use aya::{Ebpf, Btf};
/// use std::fs; /// use std::fs;
/// ///
/// let data = fs::read("file.o").unwrap(); /// let data = fs::read("file.o").unwrap();
/// // load the BTF data from /sys/kernel/btf/vmlinux /// // load the BTF data from /sys/kernel/btf/vmlinux
/// let bpf = Bpf::load(&data)?; /// let bpf = Ebpf::load(&data)?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn load(data: &[u8]) -> Result<Self, BpfError> { pub fn load(data: &[u8]) -> Result<Self, EbpfError> {
BpfLoader::new() EbpfLoader::new()
.btf(Btf::from_sys_fs().ok().as_ref()) .btf(Btf::from_sys_fs().ok().as_ref())
.load(data) .load(data)
} }
@ -926,7 +934,7 @@ impl Bpf {
/// Takes ownership of a map with the given name. /// Takes ownership of a map with the given name.
/// ///
/// Use this when borrowing with [`map`](crate::Bpf::map) or [`map_mut`](crate::Bpf::map_mut) /// Use this when borrowing with [`map`](crate::Ebpf::map) or [`map_mut`](crate::Ebpf::map_mut)
/// is not possible (eg when using the map from an async task). The returned /// is not possible (eg when using the map from an async task). The returned
/// map will be closed on `Drop`, therefore the caller is responsible for /// map will be closed on `Drop`, therefore the caller is responsible for
/// managing its lifetime. /// managing its lifetime.
@ -944,14 +952,14 @@ impl Bpf {
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// for (name, map) in bpf.maps() { /// for (name, map) in bpf.maps() {
/// println!( /// println!(
/// "found map `{}`", /// "found map `{}`",
/// name, /// name,
/// ); /// );
/// } /// }
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn maps(&self) -> impl Iterator<Item = (&str, &Map)> { pub fn maps(&self) -> impl Iterator<Item = (&str, &Map)> {
self.maps.iter().map(|(name, map)| (name.as_str(), map)) self.maps.iter().map(|(name, map)| (name.as_str(), map))
@ -965,11 +973,11 @@ impl Bpf {
/// # #[derive(thiserror::Error, Debug)] /// # #[derive(thiserror::Error, Debug)]
/// # enum Error { /// # enum Error {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Pin(#[from] aya::pin::PinError) /// # Pin(#[from] aya::pin::PinError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// # let pin_path = Path::new("/tmp/pin_path"); /// # let pin_path = Path::new("/tmp/pin_path");
/// for (_, map) in bpf.maps_mut() { /// for (_, map) in bpf.maps_mut() {
/// map.pin(pin_path)?; /// map.pin(pin_path)?;
@ -991,10 +999,10 @@ impl Bpf {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// let program = bpf.program("SSL_read").unwrap(); /// let program = bpf.program("SSL_read").unwrap();
/// println!("program SSL_read is of type {:?}", program.prog_type()); /// println!("program SSL_read is of type {:?}", program.prog_type());
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn program(&self, name: &str) -> Option<&Program> { pub fn program(&self, name: &str) -> Option<&Program> {
self.programs.get(name) self.programs.get(name)
@ -1008,13 +1016,13 @@ impl Bpf {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::programs::UProbe; /// use aya::programs::UProbe;
/// ///
/// let program: &mut UProbe = bpf.program_mut("SSL_read").unwrap().try_into()?; /// let program: &mut UProbe = bpf.program_mut("SSL_read").unwrap().try_into()?;
/// program.load()?; /// program.load()?;
/// program.attach(Some("SSL_read"), 0, "libssl", None)?; /// program.attach(Some("SSL_read"), 0, "libssl", None)?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn program_mut(&mut self, name: &str) -> Option<&mut Program> { pub fn program_mut(&mut self, name: &str) -> Option<&mut Program> {
self.programs.get_mut(name) self.programs.get_mut(name)
@ -1024,7 +1032,7 @@ impl Bpf {
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// for (name, program) in bpf.programs() { /// for (name, program) in bpf.programs() {
/// println!( /// println!(
/// "found program `{}` of type `{:?}`", /// "found program `{}` of type `{:?}`",
@ -1032,7 +1040,7 @@ impl Bpf {
/// program.prog_type() /// program.prog_type()
/// ); /// );
/// } /// }
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
pub fn programs(&self) -> impl Iterator<Item = (&str, &Program)> { pub fn programs(&self) -> impl Iterator<Item = (&str, &Program)> {
self.programs.iter().map(|(s, p)| (s.as_str(), p)) self.programs.iter().map(|(s, p)| (s.as_str(), p))
@ -1046,11 +1054,11 @@ impl Bpf {
/// # #[derive(thiserror::Error, Debug)] /// # #[derive(thiserror::Error, Debug)]
/// # enum Error { /// # enum Error {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Pin(#[from] aya::pin::PinError) /// # Pin(#[from] aya::pin::PinError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// # let pin_path = Path::new("/tmp/pin_path"); /// # let pin_path = Path::new("/tmp/pin_path");
/// for (_, program) in bpf.programs_mut() { /// for (_, program) in bpf.programs_mut() {
/// program.pin(pin_path)?; /// program.pin(pin_path)?;
@ -1062,9 +1070,9 @@ impl Bpf {
} }
} }
/// The error type returned by [`Bpf::load_file`] and [`Bpf::load`]. /// The error type returned by [`Ebpf::load_file`] and [`Ebpf::load`].
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum BpfError { pub enum EbpfError {
/// Error loading file /// Error loading file
#[error("error loading {path}")] #[error("error loading {path}")]
FileError { FileError {
@ -1124,7 +1132,7 @@ fn load_btf(raw_btf: Vec<u8>, verifier_log_level: VerifierLogLevel) -> Result<Ow
/// Global data that can be exported to eBPF programs before they are loaded. /// Global data that can be exported to eBPF programs before they are loaded.
/// ///
/// Valid global data includes `Pod` types and slices of `Pod` types. See also /// Valid global data includes `Pod` types and slices of `Pod` types. See also
/// [BpfLoader::set_global]. /// [EbpfLoader::set_global].
pub struct GlobalData<'a> { pub struct GlobalData<'a> {
bytes: &'a [u8], bytes: &'a [u8],
} }

@ -21,13 +21,13 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::Array; /// use aya::maps::Array;
/// ///
/// let mut array = Array::try_from(bpf.map_mut("ARRAY").unwrap())?; /// let mut array = Array::try_from(bpf.map_mut("ARRAY").unwrap())?;
/// array.set(1, 42, 0)?; /// array.set(1, 42, 0)?;
/// assert_eq!(array.get(&1, 0)?, 42); /// assert_eq!(array.get(&1, 0)?, 42);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_ARRAY")] #[doc(alias = "BPF_MAP_TYPE_ARRAY")]
pub struct Array<T, V: Pod> { pub struct Array<T, V: Pod> {

@ -28,9 +28,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Map(#[from] aya::maps::MapError), /// # Map(#[from] aya::maps::MapError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::{PerCpuArray, PerCpuValues}; /// use aya::maps::{PerCpuArray, PerCpuValues};
/// use aya::util::nr_cpus; /// use aya::util::nr_cpus;
/// ///

@ -23,7 +23,7 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::ProgramArray; /// use aya::maps::ProgramArray;
/// use aya::programs::CgroupSkb; /// use aya::programs::CgroupSkb;
/// ///
@ -44,7 +44,7 @@ use crate::{
/// ///
/// // bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2 /// // bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2
/// prog_array.set(2, &prog_2_fd, flags); /// prog_array.set(2, &prog_2_fd, flags);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_PROG_ARRAY")] #[doc(alias = "BPF_MAP_TYPE_PROG_ARRAY")]
pub struct ProgramArray<T> { pub struct ProgramArray<T> {

@ -20,7 +20,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::bloom_filter::BloomFilter; /// use aya::maps::bloom_filter::BloomFilter;
/// ///
/// let mut bloom_filter = BloomFilter::try_from(bpf.map_mut("BLOOM_FILTER").unwrap())?; /// let mut bloom_filter = BloomFilter::try_from(bpf.map_mut("BLOOM_FILTER").unwrap())?;
@ -30,7 +30,7 @@ use crate::{
/// assert!(bloom_filter.contains(&1, 0).is_ok()); /// assert!(bloom_filter.contains(&1, 0).is_ok());
/// assert!(bloom_filter.contains(&2, 0).is_err()); /// assert!(bloom_filter.contains(&2, 0).is_err());
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_BLOOM_FILTER")] #[doc(alias = "BPF_MAP_TYPE_BLOOM_FILTER")]
@ -114,7 +114,7 @@ mod tests {
fn new_map(obj: obj::Map) -> MapData { fn new_map(obj: obj::Map) -> MapData {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_CREATE, cmd: bpf_cmd::BPF_MAP_CREATE,
.. ..
} => Ok(1337), } => Ok(1337),
@ -197,7 +197,7 @@ mod tests {
let mut bloom_filter = BloomFilter::<_, u32>::new(&mut map).unwrap(); let mut bloom_filter = BloomFilter::<_, u32>::new(&mut map).unwrap();
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM, cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM,
.. ..
} => Ok(1), } => Ok(1),
@ -226,7 +226,7 @@ mod tests {
let bloom_filter = BloomFilter::<_, u32>::new(&map).unwrap(); let bloom_filter = BloomFilter::<_, u32>::new(&map).unwrap();
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
.. ..
} => sys_error(ENOENT), } => sys_error(ENOENT),

@ -19,7 +19,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::HashMap; /// use aya::maps::HashMap;
/// ///
/// let mut redirect_ports = HashMap::try_from(bpf.map_mut("REDIRECT_PORTS").unwrap())?; /// let mut redirect_ports = HashMap::try_from(bpf.map_mut("REDIRECT_PORTS").unwrap())?;
@ -28,7 +28,7 @@ use crate::{
/// redirect_ports.insert(80, 8080, 0); /// redirect_ports.insert(80, 8080, 0);
/// // redirect port 443 to 8443 /// // redirect port 443 to 8443
/// redirect_ports.insert(443, 8443, 0); /// redirect_ports.insert(443, 8443, 0);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_HASH")] #[doc(alias = "BPF_MAP_TYPE_HASH")]
#[doc(alias = "BPF_MAP_TYPE_LRU_HASH")] #[doc(alias = "BPF_MAP_TYPE_LRU_HASH")]
@ -218,7 +218,7 @@ mod tests {
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap(); let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM, cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM,
.. ..
} => Ok(1), } => Ok(1),
@ -234,7 +234,7 @@ mod tests {
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap(); let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM, cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM,
.. ..
} => Ok(1), } => Ok(1),
@ -263,7 +263,7 @@ mod tests {
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap(); let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_DELETE_ELEM, cmd: bpf_cmd::BPF_MAP_DELETE_ELEM,
.. ..
} => Ok(1), } => Ok(1),
@ -289,7 +289,7 @@ mod tests {
fn test_get_not_found() { fn test_get_not_found() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
.. ..
} => sys_error(ENOENT), } => sys_error(ENOENT),
@ -321,7 +321,7 @@ mod tests {
fn test_keys_empty() { fn test_keys_empty() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
.. ..
} => sys_error(ENOENT), } => sys_error(ENOENT),
@ -365,7 +365,7 @@ mod tests {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
attr, attr,
} => get_next_key(attr), } => get_next_key(attr),
@ -386,7 +386,7 @@ mod tests {
fn test_keys_error() { fn test_keys_error() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
attr, attr,
} => { } => {
@ -423,11 +423,11 @@ mod tests {
fn test_iter() { fn test_iter() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
attr, attr,
} => get_next_key(attr), } => get_next_key(attr),
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
attr, attr,
} => lookup_elem(attr), } => lookup_elem(attr),
@ -446,11 +446,11 @@ mod tests {
fn test_iter_key_deleted() { fn test_iter_key_deleted() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
attr, attr,
} => get_next_key(attr), } => get_next_key(attr),
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
attr, attr,
} => { } => {
@ -480,7 +480,7 @@ mod tests {
fn test_iter_key_error() { fn test_iter_key_error() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
attr, attr,
} => { } => {
@ -494,7 +494,7 @@ mod tests {
Ok(1) Ok(1)
} }
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
attr, attr,
} => lookup_elem(attr), } => lookup_elem(attr),
@ -523,11 +523,11 @@ mod tests {
fn test_iter_value_error() { fn test_iter_value_error() {
let map = new_map(new_obj_map()); let map = new_map(new_obj_map());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY, cmd: bpf_cmd::BPF_MAP_GET_NEXT_KEY,
attr, attr,
} => get_next_key(attr), } => get_next_key(attr),
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
attr, attr,
} => { } => {

@ -56,7 +56,7 @@ mod test_utils {
pub(super) fn new_map(obj: obj::Map) -> MapData { pub(super) fn new_map(obj: obj::Map) -> MapData {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_CREATE, cmd: bpf_cmd::BPF_MAP_CREATE,
.. ..
} => Ok(1337), } => Ok(1337),

@ -26,7 +26,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::PerCpuHashMap; /// use aya::maps::PerCpuHashMap;
/// ///
/// const CPU_IDS: u8 = 1; /// const CPU_IDS: u8 = 1;
@ -38,7 +38,7 @@ use crate::{
/// for (cpu_id, wakeups) in cpu_ids.iter().zip(wakeups.iter()) { /// for (cpu_id, wakeups) in cpu_ids.iter().zip(wakeups.iter()) {
/// println!("cpu {} woke up {} times", cpu_id, wakeups); /// println!("cpu {} woke up {} times", cpu_id, wakeups);
/// } /// }
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_LRU_PERCPU_HASH")] #[doc(alias = "BPF_MAP_TYPE_LRU_PERCPU_HASH")]
#[doc(alias = "BPF_MAP_TYPE_PERCPU_HASH")] #[doc(alias = "BPF_MAP_TYPE_PERCPU_HASH")]
@ -97,9 +97,9 @@ impl<T: BorrowMut<MapData>, K: Pod, V: Pod> PerCpuHashMap<T, K, V> {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Map(#[from] aya::maps::MapError), /// # Map(#[from] aya::maps::MapError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::{PerCpuHashMap, PerCpuValues}; /// use aya::maps::{PerCpuHashMap, PerCpuValues};
/// use aya::util::nr_cpus; /// use aya::util::nr_cpus;
/// ///

@ -20,7 +20,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::lpm_trie::{LpmTrie, Key}; /// use aya::maps::lpm_trie::{LpmTrie, Key};
/// use std::net::Ipv4Addr; /// use std::net::Ipv4Addr;
/// ///
@ -42,7 +42,7 @@ use crate::{
/// trie.insert(&longer_key, 2, 0)?; /// trie.insert(&longer_key, 2, 0)?;
/// let value = trie.get(&lookup, 0)?; /// let value = trie.get(&lookup, 0)?;
/// assert_eq!(value, 2); /// assert_eq!(value, 2);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_LPM_TRIE")] #[doc(alias = "BPF_MAP_TYPE_LPM_TRIE")]
@ -231,7 +231,7 @@ mod tests {
fn new_map(obj: obj::Map) -> MapData { fn new_map(obj: obj::Map) -> MapData {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_CREATE, cmd: bpf_cmd::BPF_MAP_CREATE,
.. ..
} => Ok(1337), } => Ok(1337),
@ -330,7 +330,7 @@ mod tests {
let key = Key::new(16, u32::from(ipaddr).to_be()); let key = Key::new(16, u32::from(ipaddr).to_be());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM, cmd: bpf_cmd::BPF_MAP_UPDATE_ELEM,
.. ..
} => Ok(1), } => Ok(1),
@ -363,7 +363,7 @@ mod tests {
let key = Key::new(16, u32::from(ipaddr).to_be()); let key = Key::new(16, u32::from(ipaddr).to_be());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_DELETE_ELEM, cmd: bpf_cmd::BPF_MAP_DELETE_ELEM,
.. ..
} => Ok(1), } => Ok(1),
@ -396,7 +396,7 @@ mod tests {
let key = Key::new(16, u32::from(ipaddr).to_be()); let key = Key::new(16, u32::from(ipaddr).to_be());
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM,
.. ..
} => sys_error(ENOENT), } => sys_error(ENOENT),

@ -2,17 +2,17 @@
//! //!
//! The eBPF platform provides data structures - maps in eBPF speak - that are //! The eBPF platform provides data structures - maps in eBPF speak - that are
//! used to setup and share data with eBPF programs. When you call //! used to setup and share data with eBPF programs. When you call
//! [`Bpf::load_file`](crate::Bpf::load_file) or //! [`Ebpf::load_file`](crate::Ebpf::load_file) or
//! [`Bpf::load`](crate::Bpf::load), all the maps defined in the eBPF code get //! [`Ebpf::load`](crate::Ebpf::load), all the maps defined in the eBPF code get
//! initialized and can then be accessed using [`Bpf::map`](crate::Bpf::map), //! initialized and can then be accessed using [`Ebpf::map`](crate::Ebpf::map),
//! [`Bpf::map_mut`](crate::Bpf::map_mut), or //! [`Ebpf::map_mut`](crate::Ebpf::map_mut), or
//! [`Bpf::take_map`](crate::Bpf::take_map). //! [`Ebpf::take_map`](crate::Ebpf::take_map).
//! //!
//! # Typed maps //! # Typed maps
//! //!
//! The eBPF API includes many map types each supporting different operations. //! The eBPF API includes many map types each supporting different operations.
//! [`Bpf::map`](crate::Bpf::map), [`Bpf::map_mut`](crate::Bpf::map_mut), and //! [`Ebpf::map`](crate::Ebpf::map), [`Ebpf::map_mut`](crate::Ebpf::map_mut), and
//! [`Bpf::take_map`](crate::Bpf::take_map) always return the opaque //! [`Ebpf::take_map`](crate::Ebpf::take_map) always return the opaque
//! [`&Map`](crate::maps::Map), [`&mut Map`](crate::maps::Map), and [`Map`] //! [`&Map`](crate::maps::Map), [`&mut Map`](crate::maps::Map), and [`Map`]
//! types respectively. Those three types can be converted to *typed maps* using //! types respectively. Those three types can be converted to *typed maps* using
//! the [`TryFrom`] or [`TryInto`] trait. For example: //! the [`TryFrom`] or [`TryInto`] trait. For example:
@ -27,9 +27,9 @@
//! # #[error(transparent)] //! # #[error(transparent)]
//! # Program(#[from] aya::programs::ProgramError), //! # Program(#[from] aya::programs::ProgramError),
//! # #[error(transparent)] //! # #[error(transparent)]
//! # Bpf(#[from] aya::BpfError) //! # Ebpf(#[from] aya::EbpfError)
//! # } //! # }
//! # let mut bpf = aya::Bpf::load(&[])?; //! # let mut bpf = aya::Ebpf::load(&[])?;
//! use aya::maps::SockMap; //! use aya::maps::SockMap;
//! use aya::programs::SkMsg; //! use aya::programs::SkMsg;
//! //!
@ -678,7 +678,7 @@ impl MapData {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// # use aya::maps::MapData; /// # use aya::maps::MapData;
/// ///
/// let mut map = MapData::from_pin("/sys/fs/bpf/my_map")?; /// let mut map = MapData::from_pin("/sys/fs/bpf/my_map")?;
@ -833,9 +833,9 @@ impl PerCpuKernelMem {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Map(#[from] aya::maps::MapError), /// # Map(#[from] aya::maps::MapError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::PerCpuValues; /// use aya::maps::PerCpuValues;
/// use aya::util::nr_cpus; /// use aya::util::nr_cpus;
/// ///
@ -992,8 +992,8 @@ impl MapInfo {
/// Returns an iterator over all loaded bpf maps. /// Returns an iterator over all loaded bpf maps.
/// ///
/// This differs from [`crate::Bpf::maps`] since it will return all maps /// This differs from [`crate::Ebpf::maps`] since it will return all maps
/// listed on the host system and not only maps for a specific [`crate::Bpf`] instance. /// listed on the host system and not only maps for a specific [`crate::Ebpf`] instance.
/// ///
/// # Example /// # Example
/// ``` /// ```
@ -1054,7 +1054,7 @@ mod tests {
#[test] #[test]
fn test_from_map_id() { fn test_from_map_id() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_FD_BY_ID, cmd: bpf_cmd::BPF_MAP_GET_FD_BY_ID,
attr, attr,
} => { } => {
@ -1064,7 +1064,7 @@ mod tests {
); );
Ok(42) Ok(42)
} }
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD, cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD,
attr, attr,
} => { } => {
@ -1086,7 +1086,7 @@ mod tests {
#[test] #[test]
fn test_create() { fn test_create() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_CREATE, cmd: bpf_cmd::BPF_MAP_CREATE,
.. ..
} => Ok(42), } => Ok(42),
@ -1113,11 +1113,11 @@ mod tests {
const TEST_NAME: &str = "foo"; const TEST_NAME: &str = "foo";
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_CREATE, cmd: bpf_cmd::BPF_MAP_CREATE,
.. ..
} => Ok(42), } => Ok(42),
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD, cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD,
attr, attr,
} => { } => {
@ -1146,7 +1146,7 @@ mod tests {
use crate::generated::bpf_map_info; use crate::generated::bpf_map_info;
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_ID, cmd: bpf_cmd::BPF_MAP_GET_NEXT_ID,
attr, attr,
} => unsafe { } => unsafe {
@ -1158,11 +1158,11 @@ mod tests {
Err((-1, io::Error::from_raw_os_error(libc::ENOENT))) Err((-1, io::Error::from_raw_os_error(libc::ENOENT)))
} }
}, },
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_FD_BY_ID, cmd: bpf_cmd::BPF_MAP_GET_FD_BY_ID,
attr, attr,
} => Ok((1000 + unsafe { attr.__bindgen_anon_6.__bindgen_anon_1.map_id }) as c_long), } => Ok((1000 + unsafe { attr.__bindgen_anon_6.__bindgen_anon_1.map_id }) as c_long),
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD, cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD,
attr, attr,
} => { } => {

@ -42,13 +42,13 @@ use crate::maps::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Map(#[from] aya::maps::MapError), /// # Map(#[from] aya::maps::MapError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # PerfBuf(#[from] aya::maps::perf::PerfBufferError), /// # PerfBuf(#[from] aya::maps::perf::PerfBufferError),
/// # } /// # }
/// # #[cfg(feature = "async_tokio")] /// # #[cfg(feature = "async_tokio")]
/// # async fn try_main() -> Result<(), Error> { /// # async fn try_main() -> Result<(), Error> {
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::perf::{AsyncPerfEventArray, PerfBufferError}; /// use aya::maps::perf::{AsyncPerfEventArray, PerfBufferError};
/// use aya::util::online_cpus; /// use aya::util::online_cpus;
/// use bytes::BytesMut; /// use bytes::BytesMut;

@ -108,11 +108,11 @@ impl<T: BorrowMut<MapData>> AsRawFd for PerfEventArrayBuffer<T> {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Map(#[from] aya::maps::MapError), /// # Map(#[from] aya::maps::MapError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # PerfBuf(#[from] aya::maps::perf::PerfBufferError), /// # PerfBuf(#[from] aya::maps::perf::PerfBufferError),
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::PerfEventArray; /// use aya::maps::PerfEventArray;
/// use aya::util::online_cpus; /// use aya::util::online_cpus;
/// use bytes::BytesMut; /// use bytes::BytesMut;

@ -19,14 +19,14 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::Queue; /// use aya::maps::Queue;
/// ///
/// let mut queue = Queue::try_from(bpf.map_mut("ARRAY").unwrap())?; /// let mut queue = Queue::try_from(bpf.map_mut("ARRAY").unwrap())?;
/// queue.push(42, 0)?; /// queue.push(42, 0)?;
/// queue.push(43, 0)?; /// queue.push(43, 0)?;
/// assert_eq!(queue.pop(0)?, 42); /// assert_eq!(queue.pop(0)?, 42);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_QUEUE")] #[doc(alias = "BPF_MAP_TYPE_QUEUE")]
pub struct Queue<T, V: Pod> { pub struct Queue<T, V: Pod> {

@ -68,7 +68,7 @@ use crate::{
/// # } /// # }
/// # fn clear_ready(&mut self) {} /// # fn clear_ready(&mut self) {}
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::RingBuf; /// use aya::maps::RingBuf;
/// use std::convert::TryFrom; /// use std::convert::TryFrom;
/// ///
@ -82,7 +82,7 @@ use crate::{
/// } /// }
/// guard.clear_ready(); /// guard.clear_ready();
/// } /// }
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
/// # Polling /// # Polling

@ -38,9 +38,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::io::Write; /// use std::io::Write;
/// use std::net::TcpStream; /// use std::net::TcpStream;
/// use std::os::fd::AsRawFd; /// use std::os::fd::AsRawFd;

@ -35,9 +35,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::SockMap; /// use aya::maps::SockMap;
/// use aya::programs::SkSkb; /// use aya::programs::SkSkb;
/// ///

@ -19,14 +19,14 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::Stack; /// use aya::maps::Stack;
/// ///
/// let mut stack = Stack::try_from(bpf.map_mut("STACK").unwrap())?; /// let mut stack = Stack::try_from(bpf.map_mut("STACK").unwrap())?;
/// stack.push(42, 0)?; /// stack.push(42, 0)?;
/// stack.push(43, 0)?; /// stack.push(43, 0)?;
/// assert_eq!(stack.pop(0)?, 43); /// assert_eq!(stack.pop(0)?, 43);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_STACK")] #[doc(alias = "BPF_MAP_TYPE_STACK")]
pub struct Stack<T, V: Pod> { pub struct Stack<T, V: Pod> {

@ -35,9 +35,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Map(#[from] aya::maps::MapError), /// # Map(#[from] aya::maps::MapError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::StackTraceMap; /// use aya::maps::StackTraceMap;
/// use aya::util::kernel_symbols; /// use aya::util::kernel_symbols;
/// ///

@ -31,7 +31,7 @@ use crate::{
/// use aya::maps::xdp::CpuMap; /// use aya::maps::xdp::CpuMap;
/// ///
/// let ncpus = aya::util::nr_cpus().unwrap() as u32; /// let ncpus = aya::util::nr_cpus().unwrap() as u32;
/// let mut bpf = aya::BpfLoader::new() /// let mut bpf = aya::EbpfLoader::new()
/// .set_max_entries("CPUS", ncpus) /// .set_max_entries("CPUS", ncpus)
/// .load(elf_bytes) /// .load(elf_bytes)
/// .unwrap(); /// .unwrap();
@ -42,7 +42,7 @@ use crate::{
/// cpumap.set(i, queue_size, None, flags); /// cpumap.set(i, queue_size, None, flags);
/// } /// }
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
/// # See also /// # See also

@ -27,14 +27,14 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::xdp::DevMap; /// use aya::maps::xdp::DevMap;
/// ///
/// let mut devmap = DevMap::try_from(bpf.map_mut("IFACES").unwrap())?; /// let mut devmap = DevMap::try_from(bpf.map_mut("IFACES").unwrap())?;
/// // Lookups at index 2 will redirect packets to interface with index 3 (e.g. eth1) /// // Lookups at index 2 will redirect packets to interface with index 3 (e.g. eth1)
/// devmap.set(2, 3, None, 0); /// devmap.set(2, 3, None, 0);
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
/// # See also /// # See also

@ -27,14 +27,14 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::xdp::DevMapHash; /// use aya::maps::xdp::DevMapHash;
/// ///
/// let mut devmap = DevMapHash::try_from(bpf.map_mut("IFACES").unwrap())?; /// let mut devmap = DevMapHash::try_from(bpf.map_mut("IFACES").unwrap())?;
/// // Lookups with key 2 will redirect packets to interface with index 3 (e.g. eth1) /// // Lookups with key 2 will redirect packets to interface with index 3 (e.g. eth1)
/// devmap.insert(2, 3, None, 0); /// devmap.insert(2, 3, None, 0);
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
/// # See also /// # See also

@ -21,14 +21,14 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// # let socket_fd = 1; /// # let socket_fd = 1;
/// use aya::maps::XskMap; /// use aya::maps::XskMap;
/// ///
/// let mut xskmap = XskMap::try_from(bpf.map_mut("SOCKETS").unwrap())?; /// let mut xskmap = XskMap::try_from(bpf.map_mut("SOCKETS").unwrap())?;
/// // socket_fd is the RawFd of an AF_XDP socket /// // socket_fd is the RawFd of an AF_XDP socket
/// xskmap.set(0, socket_fd, 0); /// xskmap.set(0, socket_fd, 0);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
/// # See also /// # See also

@ -35,9 +35,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::programs::CgroupDevice; /// use aya::programs::CgroupDevice;
/// ///
/// let cgroup = std::fs::File::open("/sys/fs/cgroup/unified")?; /// let cgroup = std::fs::File::open("/sys/fs/cgroup/unified")?;

@ -39,9 +39,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::{CgroupSkb, CgroupSkbAttachType}; /// use aya::programs::{CgroupSkb, CgroupSkbAttachType};
/// ///

@ -37,9 +37,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::{CgroupSock, CgroupSockAttachType}; /// use aya::programs::{CgroupSock, CgroupSockAttachType};
/// ///

@ -38,9 +38,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::{CgroupSockAddr, CgroupSockAddrAttachType}; /// use aya::programs::{CgroupSockAddr, CgroupSockAddrAttachType};
/// ///

@ -35,9 +35,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::CgroupSockopt; /// use aya::programs::CgroupSockopt;
/// ///

@ -32,9 +32,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::CgroupSysctl; /// use aya::programs::CgroupSysctl;
/// ///

@ -35,9 +35,9 @@ pub enum ExtensionError {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya::{BpfLoader, programs::{Xdp, XdpFlags, Extension}}; /// use aya::{EbpfLoader, programs::{Xdp, XdpFlags, Extension}};
/// ///
/// let mut bpf = BpfLoader::new().extension("extension").load_file("app.o")?; /// let mut bpf = EbpfLoader::new().extension("extension").load_file("app.o")?;
/// let prog: &mut Xdp = bpf.program_mut("main").unwrap().try_into()?; /// let prog: &mut Xdp = bpf.program_mut("main").unwrap().try_into()?;
/// prog.load()?; /// prog.load()?;
/// prog.attach("eth0", XdpFlags::default())?; /// prog.attach("eth0", XdpFlags::default())?;
@ -47,7 +47,7 @@ pub enum ExtensionError {
/// let ext: &mut Extension = bpf.program_mut("extension").unwrap().try_into()?; /// let ext: &mut Extension = bpf.program_mut("extension").unwrap().try_into()?;
/// ext.load(prog_fd, "function_to_replace")?; /// ext.load(prog_fd, "function_to_replace")?;
/// ext.attach()?; /// ext.attach()?;
/// Ok::<(), aya::BpfError>(()) /// Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
#[doc(alias = "BPF_PROG_TYPE_EXT")] #[doc(alias = "BPF_PROG_TYPE_EXT")]

@ -31,10 +31,10 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # } /// # }
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::FEntry, BtfError, Btf}; /// use aya::{Ebpf, programs::FEntry, BtfError, Btf};
/// ///
/// let btf = Btf::from_sys_fs()?; /// let btf = Btf::from_sys_fs()?;
/// let program: &mut FEntry = bpf.program_mut("filename_lookup").unwrap().try_into()?; /// let program: &mut FEntry = bpf.program_mut("filename_lookup").unwrap().try_into()?;

@ -31,10 +31,10 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # } /// # }
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::FExit, BtfError, Btf}; /// use aya::{Ebpf, programs::FExit, BtfError, Btf};
/// ///
/// let btf = Btf::from_sys_fs()?; /// let btf = Btf::from_sys_fs()?;
/// let program: &mut FExit = bpf.program_mut("filename_lookup").unwrap().try_into()?; /// let program: &mut FExit = bpf.program_mut("filename_lookup").unwrap().try_into()?;

@ -35,13 +35,13 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::KProbe}; /// use aya::{Ebpf, programs::KProbe};
/// ///
/// let program: &mut KProbe = bpf.program_mut("intercept_wakeups").unwrap().try_into()?; /// let program: &mut KProbe = bpf.program_mut("intercept_wakeups").unwrap().try_into()?;
/// program.load()?; /// program.load()?;
/// program.attach("try_to_wake_up", 0)?; /// program.attach("try_to_wake_up", 0)?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
#[doc(alias = "BPF_PROG_TYPE_KPROBE")] #[doc(alias = "BPF_PROG_TYPE_KPROBE")]

@ -93,8 +93,8 @@ pub struct FdLinkId(pub(crate) RawFd);
/// # Example /// # Example
/// ///
///```no_run ///```no_run
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::{links::FdLink, KProbe}}; /// use aya::{Ebpf, programs::{links::FdLink, KProbe}};
/// ///
/// let program: &mut KProbe = bpf.program_mut("intercept_wakeups").unwrap().try_into()?; /// let program: &mut KProbe = bpf.program_mut("intercept_wakeups").unwrap().try_into()?;
/// program.load()?; /// program.load()?;
@ -103,7 +103,7 @@ pub struct FdLinkId(pub(crate) RawFd);
/// let fd_link: FdLink = link.try_into().unwrap(); /// let fd_link: FdLink = link.try_into().unwrap();
/// fd_link.pin("/sys/fs/bpf/intercept_wakeups_link").unwrap(); /// fd_link.pin("/sys/fs/bpf/intercept_wakeups_link").unwrap();
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
pub struct FdLink { pub struct FdLink {
@ -130,13 +130,13 @@ impl FdLink {
/// # #[derive(thiserror::Error, Debug)] /// # #[derive(thiserror::Error, Debug)]
/// # enum Error { /// # enum Error {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Pin(#[from] aya::pin::PinError), /// # Pin(#[from] aya::pin::PinError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError) /// # Program(#[from] aya::programs::ProgramError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// # let prog: &mut Extension = bpf.program_mut("example").unwrap().try_into()?; /// # let prog: &mut Extension = bpf.program_mut("example").unwrap().try_into()?;
/// let link_id = prog.attach()?; /// let link_id = prog.attach()?;
/// let owned_link = prog.take_link(link_id)?; /// let owned_link = prog.take_link(link_id)?;

@ -30,14 +30,14 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::LircMode2; /// use aya::programs::LircMode2;
/// ///
/// let file = File::open("/dev/lirc0")?; /// let file = File::open("/dev/lirc0")?;
/// let mut bpf = aya::Bpf::load_file("imon_rsc.o")?; /// let mut bpf = aya::Ebpf::load_file("imon_rsc.o")?;
/// let decoder: &mut LircMode2 = bpf.program_mut("imon_rsc").unwrap().try_into().unwrap(); /// let decoder: &mut LircMode2 = bpf.program_mut("imon_rsc").unwrap().try_into().unwrap();
/// decoder.load()?; /// decoder.load()?;
/// decoder.attach(file)?; /// decoder.attach(file)?;

@ -33,10 +33,10 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # } /// # }
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::Lsm, BtfError, Btf}; /// use aya::{Ebpf, programs::Lsm, BtfError, Btf};
/// ///
/// let btf = Btf::from_sys_fs()?; /// let btf = Btf::from_sys_fs()?;
/// let program: &mut Lsm = bpf.program_mut("lsm_prog").unwrap().try_into()?; /// let program: &mut Lsm = bpf.program_mut("lsm_prog").unwrap().try_into()?;

@ -5,35 +5,35 @@
//! //!
//! # Loading and attaching programs //! # Loading and attaching programs
//! //!
//! When you call [`Bpf::load_file`] or [`Bpf::load`], all the programs included //! When you call [`Ebpf::load_file`] or [`Ebpf::load`], all the programs included
//! in the object code are parsed and relocated. Programs are not loaded //! in the object code are parsed and relocated. Programs are not loaded
//! automatically though, since often you will need to do some application //! automatically though, since often you will need to do some application
//! specific setup before you can actually load them. //! specific setup before you can actually load them.
//! //!
//! In order to load and attach a program, you need to retrieve it using [`Bpf::program_mut`], //! In order to load and attach a program, you need to retrieve it using [`Ebpf::program_mut`],
//! then call the `load()` and `attach()` methods, for example: //! then call the `load()` and `attach()` methods, for example:
//! //!
//! ```no_run //! ```no_run
//! use aya::{Bpf, programs::KProbe}; //! use aya::{Ebpf, programs::KProbe};
//! //!
//! let mut bpf = Bpf::load_file("ebpf_programs.o")?; //! let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
//! // intercept_wakeups is the name of the program we want to load //! // intercept_wakeups is the name of the program we want to load
//! let program: &mut KProbe = bpf.program_mut("intercept_wakeups").unwrap().try_into()?; //! let program: &mut KProbe = bpf.program_mut("intercept_wakeups").unwrap().try_into()?;
//! program.load()?; //! program.load()?;
//! // intercept_wakeups will be called every time try_to_wake_up() is called //! // intercept_wakeups will be called every time try_to_wake_up() is called
//! // inside the kernel //! // inside the kernel
//! program.attach("try_to_wake_up", 0)?; //! program.attach("try_to_wake_up", 0)?;
//! # Ok::<(), aya::BpfError>(()) //! # Ok::<(), aya::EbpfError>(())
//! ``` //! ```
//! //!
//! The signature of the `attach()` method varies depending on what kind of //! The signature of the `attach()` method varies depending on what kind of
//! program you're trying to attach. //! program you're trying to attach.
//! //!
//! [`Bpf::load_file`]: crate::Bpf::load_file //! [`Ebpf::load_file`]: crate::Ebpf::load_file
//! [`Bpf::load`]: crate::Bpf::load //! [`Ebpf::load`]: crate::Ebpf::load
//! [`Bpf::programs`]: crate::Bpf::programs //! [`Ebpf::programs`]: crate::Ebpf::programs
//! [`Bpf::program`]: crate::Bpf::program //! [`Ebpf::program`]: crate::Ebpf::program
//! [`Bpf::program_mut`]: crate::Bpf::program_mut //! [`Ebpf::program_mut`]: crate::Ebpf::program_mut
//! [`maps`]: crate::maps //! [`maps`]: crate::maps
// modules we don't export // modules we don't export
@ -124,7 +124,7 @@ use crate::{
bpf_btf_get_fd_by_id, bpf_get_object, bpf_link_get_fd_by_id, bpf_link_get_info_by_fd, bpf_btf_get_fd_by_id, bpf_get_object, bpf_link_get_fd_by_id, bpf_link_get_info_by_fd,
bpf_load_program, bpf_pin_object, bpf_prog_get_fd_by_id, bpf_prog_get_info_by_fd, bpf_load_program, bpf_pin_object, bpf_prog_get_fd_by_id, bpf_prog_get_info_by_fd,
bpf_prog_query, iter_link_ids, iter_prog_ids, retry_with_verifier_logs, bpf_prog_query, iter_link_ids, iter_prog_ids, retry_with_verifier_logs,
BpfLoadProgramAttrs, SyscallError, EbpfLoadProgramAttrs, SyscallError,
}, },
util::{bytes_of_bpf_name, KernelVersion}, util::{bytes_of_bpf_name, KernelVersion},
VerifierLogLevel, VerifierLogLevel,
@ -641,7 +641,7 @@ fn load_program<T: Link>(
None None
}; };
let attr = BpfLoadProgramAttrs { let attr = EbpfLoadProgramAttrs {
name: prog_name, name: prog_name,
ty: prog_type, ty: prog_type,
insns: instructions, insns: instructions,
@ -1117,8 +1117,8 @@ impl ProgramInfo {
/// Returns an iterator over all loaded bpf programs. /// Returns an iterator over all loaded bpf programs.
/// ///
/// This differs from [`crate::Bpf::programs`] since it will return all programs /// This differs from [`crate::Ebpf::programs`] since it will return all programs
/// listed on the host system and not only programs a specific [`crate::Bpf`] instance. /// listed on the host system and not only programs a specific [`crate::Ebpf`] instance.
/// ///
/// # Example /// # Example
/// ``` /// ```

@ -98,9 +98,9 @@ pub enum PerfEventScope {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::util::online_cpus; /// use aya::util::online_cpus;
/// use aya::programs::perf_event::{ /// use aya::programs::perf_event::{
/// perf_sw_ids::PERF_COUNT_SW_CPU_CLOCK, PerfEvent, PerfEventScope, PerfTypeId, SamplePolicy, /// perf_sw_ids::PERF_COUNT_SW_CPU_CLOCK, PerfEvent, PerfEventScope, PerfTypeId, SamplePolicy,

@ -24,13 +24,13 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::RawTracePoint}; /// use aya::{Ebpf, programs::RawTracePoint};
/// ///
/// let program: &mut RawTracePoint = bpf.program_mut("sys_enter").unwrap().try_into()?; /// let program: &mut RawTracePoint = bpf.program_mut("sys_enter").unwrap().try_into()?;
/// program.load()?; /// program.load()?;
/// program.attach("sys_enter")?; /// program.attach("sys_enter")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
#[doc(alias = "BPF_PROG_TYPE_RAW_TRACEPOINT")] #[doc(alias = "BPF_PROG_TYPE_RAW_TRACEPOINT")]

@ -32,9 +32,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::SkLookup; /// use aya::programs::SkLookup;
/// ///

@ -33,9 +33,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::io::Write; /// use std::io::Write;
/// use std::net::TcpStream; /// use std::net::TcpStream;
/// use std::os::fd::AsRawFd; /// use std::os::fd::AsRawFd;

@ -46,9 +46,9 @@ pub enum SkSkbKind {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::SockMap; /// use aya::maps::SockMap;
/// use aya::programs::SkSkb; /// use aya::programs::SkSkb;
/// ///

@ -31,9 +31,9 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::fs::File; /// use std::fs::File;
/// use aya::programs::SockOps; /// use aya::programs::SockOps;
/// ///

@ -17,7 +17,7 @@ use crate::{
pub enum SocketFilterError { pub enum SocketFilterError {
/// Setting the `SO_ATTACH_BPF` socket option failed. /// Setting the `SO_ATTACH_BPF` socket option failed.
#[error("setsockopt SO_ATTACH_BPF failed")] #[error("setsockopt SO_ATTACH_BPF failed")]
SoAttachBpfError { SoAttachEbpfError {
/// original [`io::Error`] /// original [`io::Error`]
#[source] #[source]
io_error: io::Error, io_error: io::Error,
@ -45,9 +45,9 @@ pub enum SocketFilterError {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::net::TcpStream; /// use std::net::TcpStream;
/// use aya::programs::SocketFilter; /// use aya::programs::SocketFilter;
/// ///
@ -89,7 +89,7 @@ impl SocketFilter {
) )
}; };
if ret < 0 { if ret < 0 {
return Err(SocketFilterError::SoAttachBpfError { return Err(SocketFilterError::SoAttachEbpfError {
io_error: io::Error::last_os_error(), io_error: io::Error::last_os_error(),
} }
.into()); .into());

@ -55,9 +55,9 @@ pub enum TcAttachType {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::programs::{tc, SchedClassifier, TcAttachType}; /// use aya::programs::{tc, SchedClassifier, TcAttachType};
/// ///
/// // the clsact qdisc needs to be added before SchedClassifier programs can be /// // the clsact qdisc needs to be added before SchedClassifier programs can be

@ -30,10 +30,10 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Ebpf(#[from] aya::EbpfError),
/// # } /// # }
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::BtfTracePoint, BtfError, Btf}; /// use aya::{Ebpf, programs::BtfTracePoint, BtfError, Btf};
/// ///
/// let btf = Btf::from_sys_fs()?; /// let btf = Btf::from_sys_fs()?;
/// let program: &mut BtfTracePoint = bpf.program_mut("sched_process_fork").unwrap().try_into()?; /// let program: &mut BtfTracePoint = bpf.program_mut("sched_process_fork").unwrap().try_into()?;

@ -50,9 +50,9 @@ pub enum TracePointError {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError), /// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Ebpf(#[from] aya::EbpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use aya::programs::TracePoint; /// use aya::programs::TracePoint;
/// ///
/// let prog: &mut TracePoint = bpf.program_mut("trace_context_switch").unwrap().try_into()?; /// let prog: &mut TracePoint = bpf.program_mut("trace_context_switch").unwrap().try_into()?;

@ -71,12 +71,12 @@ bitflags::bitflags! {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let mut bpf = Bpf::load_file("ebpf_programs.o")?; /// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Bpf, programs::{Xdp, XdpFlags}}; /// use aya::{Ebpf, programs::{Xdp, XdpFlags}};
/// ///
/// let program: &mut Xdp = bpf.program_mut("intercept_packets").unwrap().try_into()?; /// let program: &mut Xdp = bpf.program_mut("intercept_packets").unwrap().try_into()?;
/// program.attach("eth0", XdpFlags::default())?; /// program.attach("eth0", XdpFlags::default())?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
#[doc(alias = "BPF_PROG_TYPE_XDP")] #[doc(alias = "BPF_PROG_TYPE_XDP")]

@ -112,7 +112,7 @@ pub(crate) fn bpf_get_object(path: &CStr) -> SysResult<OwnedFd> {
unsafe { fd_sys_bpf(bpf_cmd::BPF_OBJ_GET, &mut attr) } unsafe { fd_sys_bpf(bpf_cmd::BPF_OBJ_GET, &mut attr) }
} }
pub(crate) struct BpfLoadProgramAttrs<'a> { pub(crate) struct EbpfLoadProgramAttrs<'a> {
pub(crate) name: Option<CString>, pub(crate) name: Option<CString>,
pub(crate) ty: bpf_prog_type, pub(crate) ty: bpf_prog_type,
pub(crate) insns: &'a [bpf_insn], pub(crate) insns: &'a [bpf_insn],
@ -131,7 +131,7 @@ pub(crate) struct BpfLoadProgramAttrs<'a> {
} }
pub(crate) fn bpf_load_program( pub(crate) fn bpf_load_program(
aya_attr: &BpfLoadProgramAttrs<'_>, aya_attr: &EbpfLoadProgramAttrs<'_>,
log_buf: &mut [u8], log_buf: &mut [u8],
verifier_log_level: VerifierLogLevel, verifier_log_level: VerifierLogLevel,
) -> SysResult<OwnedFd> { ) -> SysResult<OwnedFd> {
@ -993,7 +993,7 @@ fn bpf_prog_load(attr: &mut bpf_attr) -> SysResult<OwnedFd> {
} }
fn sys_bpf(cmd: bpf_cmd, attr: &mut bpf_attr) -> SysResult<c_long> { fn sys_bpf(cmd: bpf_cmd, attr: &mut bpf_attr) -> SysResult<c_long> {
syscall(Syscall::Bpf { cmd, attr }) syscall(Syscall::Ebpf { cmd, attr })
} }
fn bpf_obj_get_next_id( fn bpf_obj_get_next_id(
@ -1096,7 +1096,7 @@ mod tests {
#[test] #[test]
fn test_perf_link_supported() { fn test_perf_link_supported() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_LINK_CREATE, cmd: bpf_cmd::BPF_LINK_CREATE,
.. ..
} => Err((-1, io::Error::from_raw_os_error(EBADF))), } => Err((-1, io::Error::from_raw_os_error(EBADF))),
@ -1106,7 +1106,7 @@ mod tests {
assert!(supported); assert!(supported);
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Ebpf {
cmd: bpf_cmd::BPF_LINK_CREATE, cmd: bpf_cmd::BPF_LINK_CREATE,
.. ..
} => Err((-1, io::Error::from_raw_os_error(EINVAL))), } => Err((-1, io::Error::from_raw_os_error(EINVAL))),

@ -26,7 +26,7 @@ use crate::generated::{bpf_attr, bpf_cmd, perf_event_attr};
pub(crate) type SysResult<T> = Result<T, (c_long, io::Error)>; pub(crate) type SysResult<T> = Result<T, (c_long, io::Error)>;
pub(crate) enum Syscall<'a> { pub(crate) enum Syscall<'a> {
Bpf { Ebpf {
cmd: bpf_cmd, cmd: bpf_cmd,
attr: &'a mut bpf_attr, attr: &'a mut bpf_attr,
}, },
@ -57,8 +57,8 @@ pub struct SyscallError {
impl std::fmt::Debug for Syscall<'_> { impl std::fmt::Debug for Syscall<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Bpf { cmd, attr: _ } => f Self::Ebpf { cmd, attr: _ } => f
.debug_struct("Syscall::Bpf") .debug_struct("Syscall::Ebpf")
.field("cmd", cmd) .field("cmd", cmd)
.field("attr", &format_args!("_")) .field("attr", &format_args!("_"))
.finish(), .finish(),
@ -93,7 +93,7 @@ fn syscall(call: Syscall<'_>) -> SysResult<c_long> {
#[cfg_attr(test, allow(unreachable_code))] #[cfg_attr(test, allow(unreachable_code))]
match unsafe { match unsafe {
match call { match call {
Syscall::Bpf { cmd, attr } => { Syscall::Ebpf { cmd, attr } => {
libc::syscall(SYS_bpf, cmd, attr, mem::size_of::<bpf_attr>()) libc::syscall(SYS_bpf, cmd, attr, mem::size_of::<bpf_attr>())
} }
Syscall::PerfEventOpen { Syscall::PerfEventOpen {

@ -307,7 +307,7 @@ pub(crate) fn tc_handler_make(major: u32, minor: u32) -> u32 {
(major & TC_H_MAJ_MASK) | (minor & TC_H_MIN_MASK) (major & TC_H_MAJ_MASK) | (minor & TC_H_MIN_MASK)
} }
/// Include bytes from a file for use in a subsequent [`crate::Bpf::load`]. /// Include bytes from a file for use in a subsequent [`crate::Ebpf::load`].
/// ///
/// This macro differs from the standard `include_bytes!` macro since it also ensures that /// This macro differs from the standard `include_bytes!` macro since it also ensures that
/// the bytes are correctly aligned to be parsed as an ELF binary. This avoid some nasty /// the bytes are correctly aligned to be parsed as an ELF binary. This avoid some nasty
@ -315,13 +315,13 @@ pub(crate) fn tc_handler_make(major: u32, minor: u32) -> u32 {
/// ///
/// # Examples /// # Examples
/// ```ignore /// ```ignore
/// use aya::{Bpf, include_bytes_aligned}; /// use aya::{Ebpf, include_bytes_aligned};
/// ///
/// let mut bpf = Bpf::load(include_bytes_aligned!( /// let mut bpf = Ebpf::load(include_bytes_aligned!(
/// "/path/to/bpf.o" /// "/path/to/bpf.o"
/// ))?; /// ))?;
/// ///
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! include_bytes_aligned { macro_rules! include_bytes_aligned {

@ -1,4 +1,4 @@
use aya::{maps::Array, programs::UProbe, Bpf}; use aya::{maps::Array, programs::UProbe, Ebpf};
use test_log::test; use test_log::test;
const RESULT_BUF_LEN: usize = 1024; const RESULT_BUF_LEN: usize = 1024;
@ -64,7 +64,7 @@ fn bpf_probe_read_kernel_str_bytes_empty_dest() {
assert_eq!(result_bytes(&bpf), b""); assert_eq!(result_bytes(&bpf), b"");
} }
fn set_user_buffer(bytes: &[u8], dest_len: usize) -> Bpf { fn set_user_buffer(bytes: &[u8], dest_len: usize) -> Ebpf {
let bpf = load_and_attach_uprobe( let bpf = load_and_attach_uprobe(
"test_bpf_probe_read_user_str_bytes", "test_bpf_probe_read_user_str_bytes",
"trigger_bpf_probe_read_user", "trigger_bpf_probe_read_user",
@ -74,7 +74,7 @@ fn set_user_buffer(bytes: &[u8], dest_len: usize) -> Bpf {
bpf bpf
} }
fn set_kernel_buffer(bytes: &[u8], dest_len: usize) -> Bpf { fn set_kernel_buffer(bytes: &[u8], dest_len: usize) -> Ebpf {
let mut bpf = load_and_attach_uprobe( let mut bpf = load_and_attach_uprobe(
"test_bpf_probe_read_kernel_str_bytes", "test_bpf_probe_read_kernel_str_bytes",
"trigger_bpf_probe_read_kernel", "trigger_bpf_probe_read_kernel",
@ -85,7 +85,7 @@ fn set_kernel_buffer(bytes: &[u8], dest_len: usize) -> Bpf {
bpf bpf
} }
fn set_kernel_buffer_element(bpf: &mut Bpf, bytes: &[u8]) { fn set_kernel_buffer_element(bpf: &mut Ebpf, bytes: &[u8]) {
let mut bytes = bytes.to_vec(); let mut bytes = bytes.to_vec();
bytes.resize(1024, 0xFF); bytes.resize(1024, 0xFF);
let bytes: [u8; 1024] = bytes.try_into().unwrap(); let bytes: [u8; 1024] = bytes.try_into().unwrap();
@ -94,7 +94,7 @@ fn set_kernel_buffer_element(bpf: &mut Bpf, bytes: &[u8]) {
} }
#[track_caller] #[track_caller]
fn result_bytes(bpf: &Bpf) -> Vec<u8> { fn result_bytes(bpf: &Ebpf) -> Vec<u8> {
let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).unwrap(); let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).unwrap();
let TestResult { buf, len } = m.get(&0, 0).unwrap(); let TestResult { buf, len } = m.get(&0, 0).unwrap();
let len = len.unwrap(); let len = len.unwrap();
@ -104,8 +104,8 @@ fn result_bytes(bpf: &Bpf) -> Vec<u8> {
buf[..len].to_vec() buf[..len].to_vec()
} }
fn load_and_attach_uprobe(prog_name: &str, func_name: &str, bytes: &[u8]) -> Bpf { fn load_and_attach_uprobe(prog_name: &str, func_name: &str, bytes: &[u8]) -> Ebpf {
let mut bpf = Bpf::load(bytes).unwrap(); let mut bpf = Ebpf::load(bytes).unwrap();
let prog: &mut UProbe = bpf.program_mut(prog_name).unwrap().try_into().unwrap(); let prog: &mut UProbe = bpf.program_mut(prog_name).unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();

@ -1,4 +1,4 @@
use aya::{maps::Array, programs::UProbe, util::KernelVersion, BpfLoader, Btf, Endianness}; use aya::{maps::Array, programs::UProbe, util::KernelVersion, Btf, EbpfLoader, Endianness};
use test_case::test_case; use test_case::test_case;
#[test_case("enum_signed_32", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)] #[test_case("enum_signed_32", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
@ -36,7 +36,7 @@ fn relocation_tests(
return; return;
} }
} }
let mut bpf = BpfLoader::new() let mut bpf = EbpfLoader::new()
.btf( .btf(
with_relocations with_relocations
.then(|| Btf::parse(crate::RELOC_BTF, Endianness::default()).unwrap()) .then(|| Btf::parse(crate::RELOC_BTF, Endianness::default()).unwrap())

@ -13,7 +13,7 @@ use aya::{
loaded_links, loaded_programs, KProbe, TracePoint, UProbe, Xdp, XdpFlags, loaded_links, loaded_programs, KProbe, TracePoint, UProbe, Xdp, XdpFlags,
}, },
util::KernelVersion, util::KernelVersion,
Bpf, Ebpf,
}; };
use aya_obj::programs::XdpAttachType; use aya_obj::programs::XdpAttachType;
use test_log::test; use test_log::test;
@ -23,7 +23,7 @@ const RETRY_DURATION: Duration = Duration::from_millis(10);
#[test] #[test]
fn long_name() { fn long_name() {
let mut bpf = Bpf::load(crate::NAME_TEST).unwrap(); let mut bpf = Ebpf::load(crate::NAME_TEST).unwrap();
let name_prog: &mut Xdp = bpf let name_prog: &mut Xdp = bpf
.program_mut("ihaveaverylongname") .program_mut("ihaveaverylongname")
.unwrap() .unwrap()
@ -39,7 +39,7 @@ fn long_name() {
#[test] #[test]
fn multiple_btf_maps() { fn multiple_btf_maps() {
let mut bpf = Bpf::load(crate::MULTIMAP_BTF).unwrap(); let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap();
let map_1: Array<_, u64> = bpf.take_map("map_1").unwrap().try_into().unwrap(); let map_1: Array<_, u64> = bpf.take_map("map_1").unwrap().try_into().unwrap();
let map_2: Array<_, u64> = bpf.take_map("map_2").unwrap().try_into().unwrap(); let map_2: Array<_, u64> = bpf.take_map("map_2").unwrap().try_into().unwrap();
@ -69,7 +69,7 @@ fn multiple_btf_maps() {
#[test] #[test]
fn pin_lifecycle_multiple_btf_maps() { fn pin_lifecycle_multiple_btf_maps() {
let mut bpf = Bpf::load(crate::MULTIMAP_BTF).unwrap(); let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap();
// "map_pin_by_name" should already be pinned, unpin and pin again later // "map_pin_by_name" should already be pinned, unpin and pin again later
let map_pin_by_name_path = Path::new("/sys/fs/bpf/map_pin_by_name"); let map_pin_by_name_path = Path::new("/sys/fs/bpf/map_pin_by_name");
@ -198,7 +198,7 @@ fn assert_unloaded(name: &str) {
#[test] #[test]
fn unload_xdp() { fn unload_xdp() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
assert_loaded("pass"); assert_loaded("pass");
@ -223,7 +223,7 @@ fn unload_xdp() {
#[test] #[test]
fn test_loaded_at() { fn test_loaded_at() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
// SystemTime is not monotonic, which can cause this test to flake. We don't expect the clock // SystemTime is not monotonic, which can cause this test to flake. We don't expect the clock
@ -259,7 +259,7 @@ fn test_loaded_at() {
#[test] #[test]
fn unload_kprobe() { fn unload_kprobe() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap(); let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
assert_loaded("test_kprobe"); assert_loaded("test_kprobe");
@ -284,7 +284,7 @@ fn unload_kprobe() {
#[test] #[test]
fn basic_tracepoint() { fn basic_tracepoint() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut TracePoint = bpf let prog: &mut TracePoint = bpf
.program_mut("test_tracepoint") .program_mut("test_tracepoint")
.unwrap() .unwrap()
@ -315,7 +315,7 @@ fn basic_tracepoint() {
#[test] #[test]
fn basic_uprobe() { fn basic_uprobe() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap(); let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
@ -351,7 +351,7 @@ fn pin_link() {
return; return;
} }
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
let link_id = prog.attach("lo", XdpFlags::default()).unwrap(); let link_id = prog.attach("lo", XdpFlags::default()).unwrap();
@ -384,7 +384,7 @@ fn pin_lifecycle() {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
let mut bpf = Bpf::load(crate::PASS).unwrap(); let mut bpf = Ebpf::load(crate::PASS).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
prog.pin("/sys/fs/bpf/aya-xdp-test-prog").unwrap(); prog.pin("/sys/fs/bpf/aya-xdp-test-prog").unwrap();
@ -419,7 +419,7 @@ fn pin_lifecycle() {
// 4. Load a new version of the program, unpin link, and atomically replace old program // 4. Load a new version of the program, unpin link, and atomically replace old program
{ {
let mut bpf = Bpf::load(crate::PASS).unwrap(); let mut bpf = Ebpf::load(crate::PASS).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
@ -439,7 +439,7 @@ fn pin_lifecycle() {
fn pin_lifecycle_tracepoint() { fn pin_lifecycle_tracepoint() {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut TracePoint = bpf let prog: &mut TracePoint = bpf
.program_mut("test_tracepoint") .program_mut("test_tracepoint")
.unwrap() .unwrap()
@ -493,7 +493,7 @@ fn pin_lifecycle_tracepoint() {
fn pin_lifecycle_kprobe() { fn pin_lifecycle_kprobe() {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap(); let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
prog.pin("/sys/fs/bpf/aya-kprobe-test-prog").unwrap(); prog.pin("/sys/fs/bpf/aya-kprobe-test-prog").unwrap();
@ -560,7 +560,7 @@ fn pin_lifecycle_uprobe() {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap(); let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
prog.pin(FIRST_PIN_PATH).unwrap(); prog.pin(FIRST_PIN_PATH).unwrap();

@ -3,7 +3,7 @@ use std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
use aya::{programs::UProbe, Bpf}; use aya::{programs::UProbe, Ebpf};
use aya_log::EbpfLogger; use aya_log::EbpfLogger;
use log::{Level, Log, Record}; use log::{Level, Log, Record};
use test_log::test; use test_log::test;
@ -40,7 +40,7 @@ struct CapturedLog<'a> {
#[test(tokio::test)] #[test(tokio::test)]
async fn log() { async fn log() {
let mut bpf = Bpf::load(crate::LOG).unwrap(); let mut bpf = Ebpf::load(crate::LOG).unwrap();
let captured_logs = Arc::new(Mutex::new(Vec::new())); let captured_logs = Arc::new(Mutex::new(Vec::new()));
{ {

@ -1,4 +1,4 @@
use aya::{programs::UProbe, util::KernelVersion, Bpf}; use aya::{programs::UProbe, util::KernelVersion, Ebpf};
use test_log::test; use test_log::test;
#[test] #[test]
@ -33,8 +33,8 @@ fn text_64_64_reloc() {
assert_eq!(m.get(&1, 0).unwrap(), 3); assert_eq!(m.get(&1, 0).unwrap(), 3);
} }
fn load_and_attach(name: &str, bytes: &[u8]) -> Bpf { fn load_and_attach(name: &str, bytes: &[u8]) -> Ebpf {
let mut bpf = Bpf::load(bytes).unwrap(); let mut bpf = Ebpf::load(bytes).unwrap();
let prog: &mut UProbe = bpf.program_mut(name).unwrap().try_into().unwrap(); let prog: &mut UProbe = bpf.program_mut(name).unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();

@ -13,7 +13,7 @@ use assert_matches::assert_matches;
use aya::{ use aya::{
maps::{array::PerCpuArray, ring_buf::RingBuf, MapData}, maps::{array::PerCpuArray, ring_buf::RingBuf, MapData},
programs::UProbe, programs::UProbe,
Bpf, BpfLoader, Pod, Ebpf, EbpfLoader, Pod,
}; };
use aya_obj::generated::BPF_RINGBUF_HDR_SZ; use aya_obj::generated::BPF_RINGBUF_HDR_SZ;
use rand::Rng as _; use rand::Rng as _;
@ -50,7 +50,7 @@ impl<'a> std::iter::Sum<&'a Registers> for Registers {
unsafe impl Pod for Registers {} unsafe impl Pod for Registers {}
struct RingBufTest { struct RingBufTest {
_bpf: Bpf, _bpf: Ebpf,
ring_buf: RingBuf<MapData>, ring_buf: RingBuf<MapData>,
regs: PerCpuArray<MapData, Registers>, regs: PerCpuArray<MapData, Registers>,
} }
@ -67,7 +67,7 @@ impl RingBufTest {
(RING_BUF_MAX_ENTRIES * (mem::size_of::<u64>() + BPF_RINGBUF_HDR_SZ as usize)) as u32; (RING_BUF_MAX_ENTRIES * (mem::size_of::<u64>() + BPF_RINGBUF_HDR_SZ as usize)) as u32;
// Use the loader API to control the size of the ring_buf. // Use the loader API to control the size of the ring_buf.
let mut bpf = BpfLoader::new() let mut bpf = EbpfLoader::new()
.set_max_entries("RING_BUF", RING_BUF_BYTE_SIZE) .set_max_entries("RING_BUF", RING_BUF_BYTE_SIZE)
.load(crate::RING_BUF) .load(crate::RING_BUF)
.unwrap(); .unwrap();

@ -2,7 +2,7 @@ use aya::{
maps::loaded_maps, maps::loaded_maps,
programs::{loaded_programs, Extension, TracePoint, Xdp, XdpFlags}, programs::{loaded_programs, Extension, TracePoint, Xdp, XdpFlags},
util::KernelVersion, util::KernelVersion,
Bpf, BpfLoader, Ebpf, EbpfLoader,
}; };
use test_log::test; use test_log::test;
@ -18,7 +18,7 @@ fn xdp() {
let _netns = NetNsGuard::new(); let _netns = NetNsGuard::new();
let mut bpf = Bpf::load(crate::PASS).unwrap(); let mut bpf = Ebpf::load(crate::PASS).unwrap();
let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
dispatcher.load().unwrap(); dispatcher.load().unwrap();
dispatcher.attach("lo", XdpFlags::default()).unwrap(); dispatcher.attach("lo", XdpFlags::default()).unwrap();
@ -26,7 +26,7 @@ fn xdp() {
#[test] #[test]
fn two_progs() { fn two_progs() {
let mut bpf = Bpf::load(crate::TWO_PROGS).unwrap(); let mut bpf = Ebpf::load(crate::TWO_PROGS).unwrap();
let prog_one: &mut TracePoint = bpf let prog_one: &mut TracePoint = bpf
.program_mut("test_tracepoint_one") .program_mut("test_tracepoint_one")
@ -56,12 +56,12 @@ fn extension() {
let _netns = NetNsGuard::new(); let _netns = NetNsGuard::new();
let mut bpf = Bpf::load(crate::MAIN).unwrap(); let mut bpf = Ebpf::load(crate::MAIN).unwrap();
let pass: &mut Xdp = bpf.program_mut("xdp_pass").unwrap().try_into().unwrap(); let pass: &mut Xdp = bpf.program_mut("xdp_pass").unwrap().try_into().unwrap();
pass.load().unwrap(); pass.load().unwrap();
pass.attach("lo", XdpFlags::default()).unwrap(); pass.attach("lo", XdpFlags::default()).unwrap();
let mut bpf = BpfLoader::new() let mut bpf = EbpfLoader::new()
.extension("xdp_drop") .extension("xdp_drop")
.load(crate::EXT) .load(crate::EXT)
.unwrap(); .unwrap();
@ -74,7 +74,7 @@ fn extension() {
#[test] #[test]
fn list_loaded_programs() { fn list_loaded_programs() {
// Load a program. // Load a program.
let mut bpf = Bpf::load(crate::PASS).unwrap(); let mut bpf = Ebpf::load(crate::PASS).unwrap();
let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
dispatcher.load().unwrap(); dispatcher.load().unwrap();
dispatcher.attach("lo", XdpFlags::default()).unwrap(); dispatcher.attach("lo", XdpFlags::default()).unwrap();
@ -103,7 +103,7 @@ fn list_loaded_programs() {
#[test] #[test]
fn list_loaded_maps() { fn list_loaded_maps() {
// Load a program with maps. // Load a program with maps.
let mut bpf = Bpf::load(crate::MAP_TEST).unwrap(); let mut bpf = Ebpf::load(crate::MAP_TEST).unwrap();
let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
dispatcher.load().unwrap(); dispatcher.load().unwrap();
dispatcher.attach("lo", XdpFlags::default()).unwrap(); dispatcher.attach("lo", XdpFlags::default()).unwrap();

@ -3,7 +3,7 @@ use std::{ffi::CStr, mem::MaybeUninit, net::UdpSocket, num::NonZeroU32, time::Du
use aya::{ use aya::{
maps::{Array, CpuMap, XskMap}, maps::{Array, CpuMap, XskMap},
programs::{Xdp, XdpFlags}, programs::{Xdp, XdpFlags},
Bpf, Ebpf,
}; };
use object::{Object, ObjectSection, ObjectSymbol, SymbolSection}; use object::{Object, ObjectSection, ObjectSymbol, SymbolSection};
use test_log::test; use test_log::test;
@ -15,7 +15,7 @@ use crate::utils::NetNsGuard;
fn af_xdp() { fn af_xdp() {
let _netns = NetNsGuard::new(); let _netns = NetNsGuard::new();
let mut bpf = Bpf::load(crate::REDIRECT).unwrap(); let mut bpf = Ebpf::load(crate::REDIRECT).unwrap();
let mut socks: XskMap<_> = bpf.take_map("SOCKS").unwrap().try_into().unwrap(); let mut socks: XskMap<_> = bpf.take_map("SOCKS").unwrap().try_into().unwrap();
let xdp: &mut Xdp = bpf let xdp: &mut Xdp = bpf
@ -122,7 +122,7 @@ fn ensure_symbol(obj_file: &object::File, sec_name: &str, sym_name: &str) {
#[test] #[test]
fn map_load() { fn map_load() {
let bpf = Bpf::load(crate::XDP_SEC).unwrap(); let bpf = Ebpf::load(crate::XDP_SEC).unwrap();
bpf.program("xdp_plain").unwrap(); bpf.program("xdp_plain").unwrap();
bpf.program("xdp_frags").unwrap(); bpf.program("xdp_frags").unwrap();
@ -136,7 +136,7 @@ fn map_load() {
fn cpumap_chain() { fn cpumap_chain() {
let _netns = NetNsGuard::new(); let _netns = NetNsGuard::new();
let mut bpf = Bpf::load(crate::REDIRECT).unwrap(); let mut bpf = Ebpf::load(crate::REDIRECT).unwrap();
// Load our cpumap and our canary map // Load our cpumap and our canary map
let mut cpus: CpuMap<_> = bpf.take_map("CPUS").unwrap().try_into().unwrap(); let mut cpus: CpuMap<_> = bpf.take_map("CPUS").unwrap().try_into().unwrap();

Loading…
Cancel
Save