Fixups in response to alessandrod review

Move BpfError::UnsupportedMap into MapError and add a map_type field to
the error.

Update the `allow_unsupported_maps` function comment.

Update the logic to check if any unsupported maps are being used. More
specifically only search a program's maps if `allow_unsupported_maps` is
set and then use the iter function `try_for_each` with a match statement
which allows us to return the inner map type if it's unsupported.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
pull/520/head
Andrew Stoycos 1 year ago
parent b5719c5b3f
commit 17930a88c5
No known key found for this signature in database
GPG Key ID: 66735B92BB71C096

@ -183,12 +183,13 @@ impl<'a> BpfLoader<'a> {
self self
} }
/// Allows bytecode containing maps unsupported by Aya to be loaded. /// Allows programs containing unsupported maps to be loaded.
/// ///
/// By default, programs containing maps unsupported by Aya will not be loaded. /// By default programs containing unsupported maps will fail to load. This
/// This function changes the default behavior, allowing programs to be loaded. /// method can be used to configure the loader so that unsupported maps will
/// This should only be used in cases where you do not require access to eBPF /// be loaded, but won't be accessible from userspace. Can be useful when
/// maps from this crate. /// using unsupported maps that are only accessed from eBPF code and don't
/// require any userspace interaction.
/// ///
/// # Example /// # Example
/// ///
@ -629,15 +630,14 @@ impl<'a> BpfLoader<'a> {
.map(parse_map) .map(parse_map)
.collect::<Result<HashMap<String, Map>, BpfError>>()?; .collect::<Result<HashMap<String, Map>, BpfError>>()?;
if !self.allow_unsupported_maps if !self.allow_unsupported_maps {
&& maps maps.iter().try_for_each(|(_, x)| match x {
.iter() Map::Unsupported(map) => Err(BpfError::MapError(MapError::Unsupported {
.filter(|(_, x)| matches!(x, Map::Unsupported(_))) map_type: map.obj.map_type(),
.count() })),
!= 0 _ => Ok(()),
{ })?;
return Err(BpfError::UnsupportedMap); };
}
Ok(Bpf { maps, programs }) Ok(Bpf { maps, programs })
} }
@ -931,10 +931,6 @@ pub enum BpfError {
#[error("program error: {0}")] #[error("program error: {0}")]
/// A program error /// A program error
ProgramError(#[from] ProgramError), ProgramError(#[from] ProgramError),
/// Unsupported Map type
#[error("Unsupported map types found")]
UnsupportedMap,
} }
fn load_btf(raw_btf: Vec<u8>) -> Result<RawFd, BtfError> { fn load_btf(raw_btf: Vec<u8>) -> Result<RawFd, BtfError> {

@ -182,6 +182,13 @@ pub enum MapError {
#[source] #[source]
error: PinError, error: PinError,
}, },
/// Unsupported Map type
#[error("Unsupported map type found {map_type}")]
Unsupported {
/// The map type
map_type: u32,
},
} }
/// A map file descriptor. /// A map file descriptor.

Loading…
Cancel
Save