aya: rename Bpf to Ebpf and BpfLoader to EbpfLoader

When I submitted the bpf* rustc targets, they were almost dismissed by some since people thought it was actually bpf and not ebpf, and they
said we should probably have ebpf targets intead. Whenever I blog or tweet about aya and related efforts, someone always gets confused
by bpf vs ebpf.

Fixes: #334
pull/341/head
Kensuke Kubo 3 years ago
parent a93a975cc6
commit b08bcaaaa4
No known key found for this signature in database
GPG Key ID: 8CBEE4EC1EE28340

@ -75,14 +75,14 @@ Aya supports a large chunk of the eBPF API. The following example shows how to u
```rust ```rust
use std::fs::File; use std::fs::File;
use aya::Bpf; use aya::Ebpf;
use aya::programs::{CgroupSkb, CgroupSkbAttachType}; use aya::programs::{CgroupSkb, CgroupSkbAttachType};
// load the BPF code // load the BPF code
let mut bpf = Bpf::load_file("bpf.o")?; let mut ebpf = Ebpf::load_file("ebpf.o")?;
// get the `ingress_filter` program compiled into `bpf.o`. // get the `ingress_filter` program compiled into `ebpf.o`.
let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?; let ingress: &mut CgroupSkb = ebpf.program_mut("ingress_filter")?.try_into()?;
// load the program into the kernel // load the program into the kernel
ingress.load()?; ingress.load()?;

@ -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::BpfLogger; //! use aya_log::BpfLogger;
//! //!
//! // initialize env_logger as the default logger //! // initialize env_logger as the default logger
@ -68,7 +68,7 @@ use aya::{
MapError, MapError,
}, },
util::online_cpus, util::online_cpus,
Bpf, Pod, Ebpf, Pod,
}; };
/// Log messages generated by `aya_log_ebpf` using the [log] crate. /// Log messages generated by `aya_log_ebpf` using the [log] crate.
@ -79,14 +79,14 @@ pub struct BpfLogger;
impl BpfLogger { impl BpfLogger {
/// 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<BpfLogger, Error> { pub fn init(bpf: &mut Ebpf) -> Result<BpfLogger, Error> {
BpfLogger::init_with_logger(bpf, DefaultLogger {}) BpfLogger::init_with_logger(bpf, DefaultLogger {})
} }
/// 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<BpfLogger, Error> { ) -> Result<BpfLogger, Error> {
let logger = Arc::new(logger); let logger = Arc::new(logger);

@ -75,14 +75,14 @@ Aya supports a large chunk of the eBPF API. The following example shows how to u
```rust ```rust
use std::fs::File; use std::fs::File;
use aya::Bpf; use aya::Ebpf;
use aya::programs::{CgroupSkb, CgroupSkbAttachType}; use aya::programs::{CgroupSkb, CgroupSkbAttachType};
// load the BPF code // load the BPF code
let mut bpf = Bpf::load_file("bpf.o")?; let mut ebpf = Ebpf::load_file("ebpf.o")?;
// get the `ingress_filter` program compiled into `bpf.o`. // get the `ingress_filter` program compiled into `ebpf.o`.
let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?; let ingress: &mut CgroupSkb = ebpf.program_mut("ingress_filter")?.try_into()?;
// load the program into the kernel // load the program into the kernel
ingress.load()?; ingress.load()?;

@ -165,19 +165,23 @@ impl Features {
} }
} }
/// Deprecated: `BpfLoader` was renamed to `EbpfLoader` to avoid confusion between eBPF and classic BPF.
#[deprecated(note = "Use `EbpfLoader` instead")]
pub type BpfLoader<'a> = EbpfLoader<'a>;
/// 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
@ -187,7 +191,7 @@ impl Features {
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```
#[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]>, globals: HashMap<&'a str, &'a [u8]>,
@ -198,7 +202,7 @@ pub struct BpfLoader<'a> {
} }
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()).
pub struct VerifierLogLevel: u32 { pub struct VerifierLogLevel: u32 {
/// Sets no verifier logging. /// Sets no verifier logging.
const DISABLE = 0; const DISABLE = 0;
@ -219,12 +223,12 @@ 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() -> BpfLoader<'a> { pub fn new() -> EbpfLoader<'a> {
let mut features = Features::default(); let mut features = Features::default();
features.probe_features(); features.probe_features();
BpfLoader { EbpfLoader {
btf: Btf::from_sys_fs().ok().map(Cow::Owned), btf: Btf::from_sys_fs().ok().map(Cow::Owned),
map_pin_path: None, map_pin_path: None,
globals: HashMap::new(), globals: HashMap::new(),
@ -243,16 +247,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::BpfError>(())
/// ``` /// ```
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
} }
@ -265,15 +269,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()
/// .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::BpfError>(())
/// ``` /// ```
/// ///
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
} }
@ -302,15 +306,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_global("VERSION", &2) /// .set_global("VERSION", &2)
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```
/// ///
pub fn set_global<V: Pod>(&mut self, name: &'a str, value: &'a V) -> &mut BpfLoader<'a> { pub fn set_global<V: Pod>(&mut self, name: &'a str, value: &'a V) -> &mut EbpfLoader<'a> {
// Safety: value is POD // Safety: value is POD
let data = unsafe { bytes_of(value) }; let data = unsafe { bytes_of(value) };
self.globals.insert(name, data); self.globals.insert(name, data);
@ -325,15 +329,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::BpfError>(())
/// ``` /// ```
/// ///
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
} }
@ -347,15 +351,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::BpfError>(())
/// ``` /// ```
/// ///
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
} }
@ -365,15 +369,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::BpfError>(())
/// ``` /// ```
/// ///
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
} }
@ -383,12 +387,12 @@ 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::BpfError>(())
/// ``` /// ```
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, BpfError> {
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| BpfError::FileError {
path: path.to_owned(), path: path.to_owned(),
@ -401,14 +405,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::BpfError>(())
/// ``` /// ```
pub fn load(&mut self, data: &[u8]) -> Result<Bpf, BpfError> { pub fn load(&mut self, data: &[u8]) -> Result<Ebpf, BpfError> {
let verifier_log_level = self.verifier_log_level.bits; let verifier_log_level = self.verifier_log_level.bits;
let mut obj = Object::parse(data)?; let mut obj = Object::parse(data)?;
obj.patch_map_data(self.globals.clone())?; obj.patch_map_data(self.globals.clone())?;
@ -642,42 +646,46 @@ impl<'a> BpfLoader<'a> {
.drain() .drain()
.map(|(name, map)| (name, MapLock::new(map))) .map(|(name, map)| (name, MapLock::new(map)))
.collect(); .collect();
Ok(Bpf { maps, programs }) Ok(Ebpf { maps, programs })
} }
} }
impl<'a> Default for BpfLoader<'a> { impl<'a> Default for EbpfLoader<'a> {
fn default() -> Self { fn default() -> Self {
BpfLoader::new() EbpfLoader::new()
} }
} }
/// Deprecated: `Bpf` was renamed to `Ebpf` to avoid confusion between eBPF and classic BPF.
#[deprecated(note = "Use `Ebpf` instead")]
pub type Bpf = Ebpf;
/// 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, MapLock>, maps: HashMap<String, MapLock>,
programs: HashMap<String, Program>, programs: HashMap<String, Program>,
} }
impl Bpf { 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::BpfError>(())
/// ``` /// ```
pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Bpf, BpfError> { pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Ebpf, BpfError> {
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)
} }
@ -688,21 +696,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::BpfError>(())
/// ``` /// ```
pub fn load(data: &[u8]) -> Result<Bpf, BpfError> { pub fn load(data: &[u8]) -> Result<Ebpf, BpfError> {
BpfLoader::new() EbpfLoader::new()
.btf(Btf::from_sys_fs().ok().as_ref()) .btf(Btf::from_sys_fs().ok().as_ref())
.load(data) .load(data)
} }
@ -761,7 +769,7 @@ 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 `{}` of type `{:?}`", /// "found map `{}` of type `{:?}`",
@ -793,7 +801,7 @@ 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::BpfError>(())
@ -810,7 +818,7 @@ 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()?;
@ -826,7 +834,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 `{:?}`",
@ -852,7 +860,7 @@ impl Bpf {
/// # #[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)?;
@ -864,7 +872,7 @@ 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 BpfError {
/// Error loading file /// Error loading file

@ -22,7 +22,7 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::Array; /// use aya::maps::Array;
/// ///
/// let mut array = Array::try_from(bpf.map_mut("ARRAY")?)?; /// let mut array = Array::try_from(bpf.map_mut("ARRAY")?)?;

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

@ -25,7 +25,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;
/// ///

@ -19,7 +19,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let 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")?)?; /// let mut bloom_filter = BloomFilter::try_from(bpf.map_mut("BLOOM_FILTER")?)?;

@ -19,7 +19,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::HashMap; /// use aya::maps::HashMap;
/// ///
/// let mut redirect_ports = HashMap::try_from(bpf.map_mut("REDIRECT_PORTS")?)?; /// let mut redirect_ports = HashMap::try_from(bpf.map_mut("REDIRECT_PORTS")?)?;

@ -26,7 +26,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::PerCpuHashMap; /// use aya::maps::PerCpuHashMap;
/// ///
/// const CPU_IDS: u8 = 1; /// const CPU_IDS: u8 = 1;
@ -110,7 +110,7 @@ impl<T: DerefMut<Target = Map>, K: Pod, V: Pod> PerCpuHashMap<T, K, V> {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::{PerCpuHashMap, PerCpuValues}; /// use aya::maps::{PerCpuHashMap, PerCpuValues};
/// use aya::util::nr_cpus; /// use aya::util::nr_cpus;
/// ///

@ -17,7 +17,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let 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;
/// ///

@ -2,20 +2,20 @@
//! //!
//! 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) and //! initialized and can then be accessed using [`Ebpf::map`](crate::Ebpf::map) and
//! [`Bpf::map_mut`](crate::Bpf::map_mut). //! [`Ebpf::map_mut`](crate::Ebpf::map_mut).
//! //!
//! # 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) and [`Bpf::map_mut`](crate::Bpf::map_mut) always return the //! [`Ebpf::map`](crate::Ebpf::map) and [`Ebpf::map_mut`](crate::Ebpf::map_mut) always return the
//! opaque [`MapRef`] and [`MapRefMut`] types respectively. Those two types can be converted to //! opaque [`MapRef`] and [`MapRefMut`] types respectively. Those two types can be converted to
//! *typed maps* using the [`TryFrom`](std::convert::TryFrom) trait. For example: //! *typed maps* using the [`TryFrom`](std::convert::TryFrom) trait. For example:
//! //!
//! ```no_run //! ```no_run
//! # 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;
//! //!
@ -564,7 +564,7 @@ impl PerCpuKernelMem {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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;
/// ///

@ -45,7 +45,7 @@ use crate::maps::{
/// # } /// # }
/// # #[cfg(feature = "async_tokio")] /// # #[cfg(feature = "async_tokio")]
/// # async fn try_main() -> Result<(), Error> { /// # async fn try_main() -> Result<(), Error> {
/// # let bpf = aya::Bpf::load(&[])?; /// # let 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 futures::future; /// use futures::future;

@ -64,7 +64,7 @@ impl<T: DerefMut<Target = Map>> AsRawFd for PerfEventArrayBuffer<T> {
/// A map that can be used to receive events from eBPF programs using the linux [`perf`] API. /// A map that can be used to receive events from eBPF programs using the linux [`perf`] API.
/// ///
/// Each element of a [`PerfEventArray`] is a separate [`PerfEventArrayBuffer`] which can be used /// Each element of a [`PerfEventArray`] is a separate [`PerfEventArrayBuffer`] which can be used
/// to receive events sent by eBPF programs that use `bpf_perf_event_output()`. /// to receive events sent by eBPF programs that use `bpf_perf_event_output()`.
/// ///
/// To receive events you need to: /// To receive events you need to:
/// * call [`PerfEventArray::open`] /// * call [`PerfEventArray::open`]
@ -105,7 +105,7 @@ impl<T: DerefMut<Target = Map>> AsRawFd for PerfEventArrayBuffer<T> {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # PerfBuf(#[from] aya::maps::perf::PerfBufferError), /// # PerfBuf(#[from] aya::maps::perf::PerfBufferError),
/// # } /// # }
/// # let bpf = aya::Bpf::load(&[])?; /// # let 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;
@ -138,7 +138,7 @@ impl<T: DerefMut<Target = Map>> AsRawFd for PerfEventArrayBuffer<T> {
/// ///
/// In the example above the implementation of `poll_buffers()` and `poll.poll_readable()` is not /// In the example above the implementation of `poll_buffers()` and `poll.poll_readable()` is not
/// given. [`PerfEventArrayBuffer`] implements the [`AsRawFd`] trait, so you can implement polling /// given. [`PerfEventArrayBuffer`] implements the [`AsRawFd`] trait, so you can implement polling
/// using any crate that can poll file descriptors, like [epoll], [mio] etc. /// using any crate that can poll file descriptors, like [epoll], [mio] etc.
/// ///
/// Perf buffers are internally implemented as ring buffers. If your eBPF programs produce large /// Perf buffers are internally implemented as ring buffers. If your eBPF programs produce large
/// amounts of data, in order not to lose events you might want to process each /// amounts of data, in order not to lose events you might want to process each

@ -20,7 +20,7 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::Queue; /// use aya::maps::Queue;
/// ///
/// let mut queue = Queue::try_from(bpf.map_mut("ARRAY")?)?; /// let mut queue = Queue::try_from(bpf.map_mut("ARRAY")?)?;

@ -40,7 +40,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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::unix::io::AsRawFd; /// use std::os::unix::io::AsRawFd;

@ -19,7 +19,7 @@ use crate::{
/// sockets. /// sockets.
/// ///
/// A `SockMap` can also be used to redirect packets to sockets contained by the /// A `SockMap` can also be used to redirect packets to sockets contained by the
/// map using `bpf_redirect_map()`, `bpf_sk_redirect_map()` etc. /// map using `bpf_redirect_map()`, `bpf_sk_redirect_map()` etc.
/// ///
/// # Minimum kernel version /// # Minimum kernel version
/// ///
@ -28,7 +28,7 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # 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;
/// ///

@ -20,7 +20,7 @@ use crate::{
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[])?; /// # let bpf = aya::Ebpf::load(&[])?;
/// use aya::maps::Stack; /// use aya::maps::Stack;
/// ///
/// let mut stack = Stack::try_from(bpf.map_mut("STACK")?)?; /// let mut stack = Stack::try_from(bpf.map_mut("STACK")?)?;

@ -19,7 +19,7 @@ use crate::{
/// # Minimum kernel version /// # Minimum kernel version
/// ///
/// The minimum kernel version required to use this feature is 4.6. /// The minimum kernel version required to use this feature is 4.6.
/// ///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
@ -32,7 +32,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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;
/// ///

@ -163,9 +163,9 @@ pub enum BtfError {
/// 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`](crate::Bpf::load_file). You /// Aya automatically loads BTF metadata if you use [`Ebpf::load_file`](crate::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`](crate::Bpf::load). /// location or if you are using [`Ebpf::load`](crate::Ebpf::load).
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Btf { pub struct Btf {
header: btf_header, header: btf_header,

@ -41,7 +41,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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};
/// ///

@ -40,7 +40,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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};
/// ///

@ -41,7 +41,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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};
/// ///

@ -38,7 +38,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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;
/// ///

@ -35,7 +35,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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;
/// ///

@ -34,9 +34,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())?;

@ -33,8 +33,8 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Bpf(#[from] aya::BpfError),
/// # } /// # }
/// # 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()?;

@ -33,8 +33,8 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Bpf(#[from] aya::BpfError),
/// # } /// # }
/// # 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()?;

@ -27,8 +27,8 @@ 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()?;

@ -113,7 +113,7 @@ impl FdLink {
/// # #[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)?;

@ -34,12 +34,12 @@ use libc::{close, dup};
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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)?;

@ -34,8 +34,8 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Bpf(#[from] aya::BpfError),
/// # } /// # }
/// # 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,18 +5,18 @@
//! //!
//! # 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()?;
@ -29,11 +29,11 @@
//! 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
pub mod cgroup_skb; pub mod cgroup_skb;
pub mod cgroup_sock; pub mod cgroup_sock;

@ -96,7 +96,7 @@ pub enum PerfEventScope {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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,8 +24,8 @@ 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()?;

@ -34,7 +34,7 @@ use super::links::FdLink;
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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,7 +33,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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::unix::io::AsRawFd; /// use std::os::unix::io::AsRawFd;

@ -34,7 +34,7 @@ pub enum SkSkbKind {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # 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;
/// ///

@ -34,7 +34,7 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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;
/// ///

@ -46,7 +46,7 @@ pub enum SocketFilterError {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Ebpf::load(&[])?;
/// use std::net::TcpStream; /// use std::net::TcpStream;
/// use std::os::unix::io::AsRawFd; /// use std::os::unix::io::AsRawFd;
/// use aya::programs::SocketFilter; /// use aya::programs::SocketFilter;

@ -54,7 +54,7 @@ pub enum TcAttachType {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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

@ -31,8 +31,8 @@ use crate::{
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError), /// # Bpf(#[from] aya::BpfError),
/// # } /// # }
/// # 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,7 +50,7 @@ pub enum TracePointError {
/// # #[error(transparent)] /// # #[error(transparent)]
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # 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()?;

@ -64,8 +64,8 @@ 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())?;

@ -108,7 +108,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
@ -116,9 +116,9 @@ 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"
/// ))?; /// ))?;
/// ///

@ -7,7 +7,7 @@ use aya::{
links::{FdLink, PinnedLink}, links::{FdLink, PinnedLink},
TracePoint, Xdp, XdpFlags, TracePoint, Xdp, XdpFlags,
}, },
Bpf, Ebpf,
}; };
use super::{integration_test, IntegrationTest}; use super::{integration_test, IntegrationTest};
@ -15,7 +15,7 @@ use super::{integration_test, IntegrationTest};
#[integration_test] #[integration_test]
fn long_name() -> anyhow::Result<()> { fn long_name() -> anyhow::Result<()> {
let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/name_test"); let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/name_test");
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
let name_prog: &mut Xdp = bpf.program_mut("ihaveaverylongname").unwrap().try_into()?; let name_prog: &mut Xdp = bpf.program_mut("ihaveaverylongname").unwrap().try_into()?;
name_prog.load().unwrap(); name_prog.load().unwrap();
name_prog.attach("lo", XdpFlags::default())?; name_prog.attach("lo", XdpFlags::default())?;
@ -31,7 +31,7 @@ fn long_name() -> anyhow::Result<()> {
fn multiple_maps() -> anyhow::Result<()> { fn multiple_maps() -> anyhow::Result<()> {
let bytes = let bytes =
include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/multimap.bpf.o"); include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/multimap.bpf.o");
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
let pass: &mut Xdp = bpf.program_mut("stats").unwrap().try_into().unwrap(); let pass: &mut Xdp = bpf.program_mut("stats").unwrap().try_into().unwrap();
pass.load().unwrap(); pass.load().unwrap();
pass.attach("lo", XdpFlags::default()).unwrap(); pass.attach("lo", XdpFlags::default()).unwrap();
@ -42,7 +42,7 @@ fn multiple_maps() -> anyhow::Result<()> {
fn multiple_btf_maps() -> anyhow::Result<()> { fn multiple_btf_maps() -> anyhow::Result<()> {
let bytes = let bytes =
include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/multimap-btf.bpf.o"); include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/multimap-btf.bpf.o");
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
let map_1: Array<MapRefMut, u64> = Array::try_from(bpf.map_mut("map_1")?)?; let map_1: Array<MapRefMut, u64> = Array::try_from(bpf.map_mut("map_1")?)?;
let map_2: Array<MapRefMut, u64> = Array::try_from(bpf.map_mut("map_2")?)?; let map_2: Array<MapRefMut, u64> = Array::try_from(bpf.map_mut("map_2")?)?;
@ -80,7 +80,7 @@ fn assert_loaded(name: &str, loaded: bool) {
#[integration_test] #[integration_test]
fn unload() -> anyhow::Result<()> { fn unload() -> anyhow::Result<()> {
let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/test"); let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/test");
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
let prog: &mut Xdp = bpf.program_mut("test_unload").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("test_unload").unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();
let link = prog.attach("lo", XdpFlags::default()).unwrap(); let link = prog.attach("lo", XdpFlags::default()).unwrap();
@ -106,7 +106,7 @@ fn unload() -> anyhow::Result<()> {
#[integration_test] #[integration_test]
fn pin_link() -> anyhow::Result<()> { fn pin_link() -> anyhow::Result<()> {
let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/test"); let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/test");
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
let prog: &mut Xdp = bpf.program_mut("test_unload").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("test_unload").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();
@ -137,7 +137,7 @@ fn pin_lifecycle() -> anyhow::Result<()> {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
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();
@ -151,7 +151,7 @@ fn pin_lifecycle() -> anyhow::Result<()> {
// 2. Load a new version of the program, unpin link, and atomically replace old program // 2. Load a new version of the program, unpin link, and atomically replace old program
{ {
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
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();

@ -1,7 +1,7 @@
use aya::{ use aya::{
include_bytes_aligned, include_bytes_aligned,
programs::{Extension, Xdp, XdpFlags}, programs::{Extension, Xdp, XdpFlags},
Bpf, BpfLoader, Ebpf, EbpfLoader,
}; };
use log::info; use log::info;
@ -10,7 +10,7 @@ use super::{integration_test, kernel_version, IntegrationTest};
#[integration_test] #[integration_test]
fn xdp() -> anyhow::Result<()> { fn xdp() -> anyhow::Result<()> {
let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/pass"); let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/pass");
let mut bpf = Bpf::load(bytes)?; let mut bpf = Ebpf::load(bytes)?;
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();
@ -30,13 +30,13 @@ fn extension() -> anyhow::Result<()> {
// TODO: Check kernel version == 5.9 or later // TODO: Check kernel version == 5.9 or later
let main_bytes = let main_bytes =
include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/main.bpf.o"); include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/main.bpf.o");
let mut bpf = Bpf::load(main_bytes)?; let mut bpf = Ebpf::load(main_bytes)?;
let pass: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let pass: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
pass.load().unwrap(); pass.load().unwrap();
pass.attach("lo", XdpFlags::default()).unwrap(); pass.attach("lo", XdpFlags::default()).unwrap();
let ext_bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/ext.bpf.o"); let ext_bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/ext.bpf.o");
let mut bpf = BpfLoader::new().extension("drop").load(ext_bytes).unwrap(); let mut bpf = EbpfLoader::new().extension("drop").load(ext_bytes).unwrap();
let drop_: &mut Extension = bpf.program_mut("drop").unwrap().try_into().unwrap(); let drop_: &mut Extension = bpf.program_mut("drop").unwrap().try_into().unwrap();
drop_.load(pass.fd().unwrap(), "xdp_pass").unwrap(); drop_.load(pass.fd().unwrap(), "xdp_pass").unwrap();
Ok(()) Ok(())

Loading…
Cancel
Save