@ -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 ` B pfLoader` to customize some of the loading
/// relocations. You can use ` Eb pfLoader` to customize some of the loading
/// options.
/// options.
///
///
/// # Examples
/// # Examples
///
///
/// ```no_run
/// ```no_run
/// use aya::{ B pfLoader, Btf};
/// use aya::{ Eb pfLoader, Btf};
/// use std::fs;
/// use std::fs;
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
#[ derive(Debug) ]
#[ derive(Debug) ]
pub struct B pfLoader< ' a > {
pub struct Eb pfLoader< ' 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](Eb pfLoader::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 > B pfLoader< ' a > {
impl < ' a > Eb pfLoader< ' 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::{ B pfLoader, Btf, Endianness};
/// use aya::{ Eb pfLoader, Btf, Endianness};
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
pub fn btf ( & mut self , btf : Option < & ' a Btf > ) -> & mut B pfLoader< ' a > {
pub fn btf ( & mut self , btf : Option < & ' a Btf > ) -> & mut Eb pfLoader< ' 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:: B pfLoader;
/// use aya:: Eb pfLoader;
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::new()
/// .allow_unsupported_maps()
/// .allow_unsupported_maps()
/// .load_file("file.o")?;
/// .load_file("file.o")?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
///
///
pub fn allow_unsupported_maps ( & mut self ) -> & mut B pfLoader< ' a > {
pub fn allow_unsupported_maps ( & mut self ) -> & mut Eb pfLoader< ' 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:: B pfLoader;
/// use aya:: Eb pfLoader;
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
///
///
pub fn map_pin_path < P : AsRef < Path > > ( & mut self , path : P ) -> & mut B pfLoader< ' a > {
pub fn map_pin_path < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Eb pfLoader< ' 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`, [` B pfLoader::load`] will fail with [`ParseError::SymbolNotFound`] if the loaded object code does not contain the variable.
/// If the `must_exist` argument is `true`, [` Eb pfLoader::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:: B pfLoader;
/// use aya:: Eb pfLoader;
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
///
///
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 B pfLoader< ' a > {
) -> & mut Eb pfLoader< ' 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:: B pfLoader;
/// use aya:: Eb pfLoader;
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::new()
/// .set_max_entries("map", 64)
/// .set_max_entries("map", 64)
/// .load_file("file.o")?;
/// .load_file("file.o")?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
///
///
pub fn set_max_entries ( & mut self , name : & ' a str , size : u32 ) -> & mut B pfLoader< ' a > {
pub fn set_max_entries ( & mut self , name : & ' a str , size : u32 ) -> & mut Eb pfLoader< ' 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:: B pfLoader;
/// use aya:: Eb pfLoader;
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::new()
/// .extension("myfunc")
/// .extension("myfunc")
/// .load_file("file.o")?;
/// .load_file("file.o")?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
///
///
pub fn extension ( & mut self , name : & ' a str ) -> & mut B pfLoader< ' a > {
pub fn extension ( & mut self , name : & ' a str ) -> & mut Eb pfLoader< ' 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::{ B pfLoader, VerifierLogLevel};
/// use aya::{ Eb pfLoader, VerifierLogLevel};
///
///
/// let bpf = B pfLoader::new()
/// let bpf = Eb pfLoader::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
///
///
pub fn verifier_log_level ( & mut self , level : VerifierLogLevel ) -> & mut B pfLoader< ' a > {
pub fn verifier_log_level ( & mut self , level : VerifierLogLevel ) -> & mut Eb pfLoader< ' 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:: B pfLoader;
/// use aya:: Eb pfLoader;
///
///
/// let bpf = B pfLoader::new().load_file("file.o")?;
/// let bpf = Eb pfLoader::new().load_file("file.o")?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
pub fn load_file < P : AsRef < Path > > ( & mut self , path : P ) -> Result < Bpf, B pfError> {
pub fn load_file < P : AsRef < Path > > ( & mut self , path : P ) -> Result < Ebpf, Eb pfError> {
let path = path . as_ref ( ) ;
let path = path . as_ref ( ) ;
self . load ( & fs ::read ( path ) . map_err ( | error | B pfError::FileError {
self . load ( & fs ::read ( path ) . map_err ( | error | Eb pfError::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:: B pfLoader;
/// use aya:: Eb pfLoader;
/// use std::fs;
/// use std::fs;
///
///
/// let data = fs::read("file.o").unwrap();
/// let data = fs::read("file.o").unwrap();
/// let bpf = B pfLoader::new().load(&data)?;
/// let bpf = Eb pfLoader::new().load(&data)?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
pub fn load ( & mut self , data : & [ u8 ] ) -> Result < Bpf, B pfError> {
pub fn load ( & mut self , data : & [ u8 ] ) -> Result < Ebpf, Eb pfError> {
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 ( B pfError::BtfError ( err ) )
return Err ( Eb pfError::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 , B pfError> {
let num_cpus = | | -> Result < u32 , Eb pfError> {
Ok ( possible_cpus ( )
Ok ( possible_cpus ( )
. map_err ( | error | B pfError::FileError {
. map_err ( | error | Eb pfError::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 > , B pfError> > ( ) ? ;
. collect ::< Result < HashMap < String , Map > , Eb pfError> > ( ) ? ;
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 ( B pfError::MapError ( MapError ::Unsupported {
Map ::Unsupported ( map ) = > Err ( Eb pfError::MapError ( MapError ::Unsupported {
map_type : map . obj ( ) . map_type ( ) ,
map_type : map . obj ( ) . map_type ( ) ,
} ) ) ,
} ) ) ,
_ = > Ok ( ( ) ) ,
_ = > Ok ( ( ) ) ,
} ) ? ;
} ) ? ;
} ;
} ;
Ok ( B pf { maps , programs } )
Ok ( Eb pf { maps , programs } )
}
}
}
}
fn parse_map ( data : ( String , MapData ) ) -> Result < ( String , Map ) , B pfError> {
fn parse_map ( data : ( String , MapData ) ) -> Result < ( String , Map ) , Eb pfError> {
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 , B pfError> ,
num_cpus : impl Fn ( ) -> Result < u32 , Eb pfError> ,
page_size : impl Fn ( ) -> u32 ,
page_size : impl Fn ( ) -> u32 ,
) -> Result < Option < u32 > , B pfError> {
) -> Result < Option < u32 > , Eb pfError> {
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 B pfLoader< ' _ > {
impl Default for Eb pfLoader< ' _ > {
fn default ( ) -> Self {
fn default ( ) -> Self {
B pfLoader::new ( )
Eb pfLoader::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 B pf {
pub struct Eb pf {
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 [ B pfLoader].
/// For more loading options, see [ Eb pfLoader].
///
///
/// # Examples
/// # Examples
///
///
/// ```no_run
/// ```no_run
/// use aya:: B pf;
/// use aya:: Eb pf;
///
///
/// let bpf = B pf::load_file("file.o")?;
/// let bpf = Eb pf::load_file("file.o")?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
pub fn load_file < P : AsRef < Path > > ( path : P ) -> Result < Self , B pfError> {
pub fn load_file < P : AsRef < Path > > ( path : P ) -> Result < Self , Eb pfError> {
B pfLoader::new ( )
Eb pfLoader::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 [ B pfLoader].
/// For more loading options, see [ Eb pfLoader].
///
///
/// # Examples
/// # Examples
///
///
/// ```no_run
/// ```no_run
/// use aya::{ B pf, Btf};
/// use aya::{ Eb pf, 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 = B pf::load(&data)?;
/// let bpf = Eb pf::load(&data)?;
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
pub fn load ( data : & [ u8 ] ) -> Result < Self , B pfError> {
pub fn load ( data : & [ u8 ] ) -> Result < Self , Eb pfError> {
B pfLoader::new ( )
Eb pfLoader::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::B pf::map_mut)
/// Use this when borrowing with [`map`](crate:: Ebpf::map) or [`map_mut`](crate::Eb pf::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:: B pf::load(&[])?;
/// # let mut bpf = aya:: Eb pf::load(&[])?;
/// for (name, map) in bpf.maps() {
/// for (name, map) in bpf.maps() {
/// println!(
/// println!(
/// "found map `{}`",
/// "found map `{}`",
/// name,
/// name,
/// );
/// );
/// }
/// }
/// # Ok::<(), aya:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
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::B pfError),
/// # Ebpf(#[from] aya::Eb pfError),
/// # #[error(transparent)]
/// # #[error(transparent)]
/// # Pin(#[from] aya::pin::PinError)
/// # Pin(#[from] aya::pin::PinError)
/// # }
/// # }
/// # let mut bpf = aya:: B pf::load(&[])?;
/// # let mut bpf = aya:: Eb pf::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:: B pf::load(&[])?;
/// # let bpf = aya:: Eb pf::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
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:: B pf::load(&[])?;
/// # let mut bpf = aya:: Eb pf::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
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:: B pf::load(&[])?;
/// # let bpf = aya:: Eb pf::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:: B pfError>(())
/// # Ok::<(), aya:: Eb pfError>(())
/// ```
/// ```
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::B pfError),
/// # Ebpf(#[from] aya::Eb pfError),
/// # #[error(transparent)]
/// # #[error(transparent)]
/// # Pin(#[from] aya::pin::PinError)
/// # Pin(#[from] aya::pin::PinError)
/// # }
/// # }
/// # let mut bpf = aya:: B pf::load(&[])?;
/// # let mut bpf = aya:: Eb pf::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 [`B pf::load`].
/// The error type returned by [` Ebpf::load_file`] and [`Eb pf::load`].
#[ derive(Debug, Error) ]
#[ derive(Debug, Error) ]
pub enum B pfError {
pub enum Eb pfError {
/// 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
/// [ B pfLoader::set_global].
/// [ Eb pfLoader::set_global].
pub struct GlobalData < ' a > {
pub struct GlobalData < ' a > {
bytes : & ' a [ u8 ] ,
bytes : & ' a [ u8 ] ,
}
}