Merge pull request #376 from conectado/verifier-log-level

Update `VerifierLogLevel` to use bitflags
pull/387/head
Alessandro Decina 2 years ago committed by GitHub
commit fe22b02108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -196,22 +196,26 @@ pub struct BpfLoader<'a> {
verifier_log_level: VerifierLogLevel, verifier_log_level: VerifierLogLevel,
} }
/// Used to set the verifier log level in [BpfLoader](BpfLoader::verifier_log_level()). bitflags! {
#[repr(u32)] /// Used to set the verifier log level flags in [BpfLoader](BpfLoader::verifier_log_level()).
#[non_exhaustive] pub struct VerifierLogLevel: u32 {
#[derive(Debug, Clone, Copy)] /// Sets no verifier logging.
pub enum VerifierLogLevel { const DISABLE = 0;
/// Disable all logging. /// Enables debug verifier logging.
Disable = 0, const DEBUG = 1;
/// Enables verbose verifier logging.
/// Default level of logging, shows verifier stats. const VERBOSE = 2 | Self::DEBUG.bits;
Default = 4, /// Enables verifier stats.
const STATS = 4;
/// Prints verbose logs showing tracing. }
Verbose = 1, }
/// Prints full debug details. impl Default for VerifierLogLevel {
Debug = 7, fn default() -> Self {
Self {
bits: Self::DEBUG.bits | Self::STATS.bits,
}
}
} }
impl<'a> BpfLoader<'a> { impl<'a> BpfLoader<'a> {
@ -225,7 +229,7 @@ impl<'a> BpfLoader<'a> {
globals: HashMap::new(), globals: HashMap::new(),
features, features,
extensions: HashSet::new(), extensions: HashSet::new(),
verifier_log_level: VerifierLogLevel::Default, verifier_log_level: VerifierLogLevel::default(),
} }
} }
@ -341,7 +345,7 @@ impl<'a> BpfLoader<'a> {
/// use aya::{BpfLoader, VerifierLogLevel}; /// use aya::{BpfLoader, VerifierLogLevel};
/// ///
/// let bpf = BpfLoader::new() /// let bpf = BpfLoader::new()
/// .verifier_log_level(VerifierLogLevel::Verbose) /// .verifier_log_level(VerifierLogLevel::VERBOSE | VerifierLogLevel::STATS)
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```
@ -382,7 +386,7 @@ impl<'a> BpfLoader<'a> {
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```
pub fn load(&mut self, data: &[u8]) -> Result<Bpf, BpfError> { pub fn load(&mut self, data: &[u8]) -> Result<Bpf, BpfError> {
let verifier_log_level = self.verifier_log_level as u32; 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())?;

Loading…
Cancel
Save