From 7b143199fb61edd168f3efc860a8e8c1d4cd9136 Mon Sep 17 00:00:00 2001 From: conectado Date: Wed, 31 Aug 2022 20:10:40 -0300 Subject: [PATCH 1/3] aya: update `VerifierLogLevel` to use bitflags --- aya/src/bpf.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 2d81bbbc..2f4e948e 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -196,22 +196,26 @@ pub struct BpfLoader<'a> { verifier_log_level: VerifierLogLevel, } -/// Used to set the verifier log level in [BpfLoader](BpfLoader::verifier_log_level()). -#[repr(u32)] -#[non_exhaustive] -#[derive(Debug, Clone, Copy)] -pub enum VerifierLogLevel { - /// Disable all logging. - Disable = 0, - - /// Default level of logging, shows verifier stats. - Default = 4, - - /// Prints verbose logs showing tracing. - Verbose = 1, +bitflags! { + /// Used to set the verifier log level in [BpfLoader](BpfLoader::verifier_log_level()). + pub struct VerifierLogLevel: u32 { + /// Used to disable all logging. + const DISABLE = 0; + /// Logs tracing with details level 1 + const LEVEL1 = 1; + /// Log tracing with details level 2 + const LEVEL2 = 2 | Self::LEVEL1.bits; + /// Logs eBPF verifier stats + const STATS = 4; + } +} - /// Prints full debug details. - Debug = 7, +impl Default for VerifierLogLevel { + fn default() -> Self { + Self { + bits: Self::LEVEL1.bits | Self::STATS.bits, + } + } } impl<'a> BpfLoader<'a> { @@ -225,7 +229,7 @@ impl<'a> BpfLoader<'a> { globals: HashMap::new(), features, 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}; /// /// let bpf = BpfLoader::new() - /// .verifier_log_level(VerifierLogLevel::Verbose) + /// .verifier_log_level(VerifierLogLevel::LEVEL2 | VerifierLogLevel::STATS) /// .load_file("file.o")?; /// # Ok::<(), aya::BpfError>(()) /// ``` @@ -382,7 +386,7 @@ impl<'a> BpfLoader<'a> { /// # Ok::<(), aya::BpfError>(()) /// ``` pub fn load(&mut self, data: &[u8]) -> Result { - 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)?; obj.patch_map_data(self.globals.clone())?; From c30ae6e0010adda3d3e3de792cf2919f3c1dcf32 Mon Sep 17 00:00:00 2001 From: conectado Date: Tue, 6 Sep 2022 15:23:33 -0300 Subject: [PATCH 2/3] aya: change variant names --- aya/src/bpf.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 2f4e948e..1a099bd4 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -197,15 +197,15 @@ pub struct BpfLoader<'a> { } bitflags! { - /// Used to set the verifier log level in [BpfLoader](BpfLoader::verifier_log_level()). + /// Used to set the verifier log level flags in [BpfLoader](BpfLoader::verifier_log_level()). pub struct VerifierLogLevel: u32 { - /// Used to disable all logging. + /// Sets no verifier logging. const DISABLE = 0; - /// Logs tracing with details level 1 - const LEVEL1 = 1; - /// Log tracing with details level 2 - const LEVEL2 = 2 | Self::LEVEL1.bits; - /// Logs eBPF verifier stats + /// Enables debug verifier logging. + const DEBUG = 1; + /// Enables verbose verifier logging. + const VERBOSE = 2 | Self::DEBUG.bits; + /// Enables verifier stats const STATS = 4; } } @@ -213,7 +213,7 @@ bitflags! { impl Default for VerifierLogLevel { fn default() -> Self { Self { - bits: Self::LEVEL1.bits | Self::STATS.bits, + bits: Self::DEBUG.bits | Self::STATS.bits, } } } @@ -345,7 +345,7 @@ impl<'a> BpfLoader<'a> { /// use aya::{BpfLoader, VerifierLogLevel}; /// /// let bpf = BpfLoader::new() - /// .verifier_log_level(VerifierLogLevel::LEVEL2 | VerifierLogLevel::STATS) + /// .verifier_log_level(VerifierLogLevel::VERBOSE | VerifierLogLevel::STATS) /// .load_file("file.o")?; /// # Ok::<(), aya::BpfError>(()) /// ``` From 3bed2c2b94a47503ba32e9879c7a29fe9f8e9227 Mon Sep 17 00:00:00 2001 From: conectado Date: Tue, 6 Sep 2022 19:11:11 -0300 Subject: [PATCH 3/3] aya: fix miss doc period --- aya/src/bpf.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 1a099bd4..bd9ce595 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -205,7 +205,7 @@ bitflags! { const DEBUG = 1; /// Enables verbose verifier logging. const VERBOSE = 2 | Self::DEBUG.bits; - /// Enables verifier stats + /// Enables verifier stats. const STATS = 4; } }