From 6dfb9d82af9c178f4effd7a0c9095442816a014c Mon Sep 17 00:00:00 2001 From: epompeii Date: Fri, 17 Mar 2023 15:40:09 -0400 Subject: [PATCH] macro --- aya-bpf-macros/src/expand.rs | 31 ++++++++++++++++++++++++++----- aya-obj/src/obj.rs | 6 +++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/aya-bpf-macros/src/expand.rs b/aya-bpf-macros/src/expand.rs index 506cfa89..bf60c8e5 100644 --- a/aya-bpf-macros/src/expand.rs +++ b/aya-bpf-macros/src/expand.rs @@ -613,18 +613,39 @@ impl RawTracePoint { pub struct Lsm { item: ItemFn, - name: String, + name: Option, + sleepable: bool, } impl Lsm { pub fn from_syn(mut args: Args, item: ItemFn) -> Result { - let name = name_arg(&mut args)?.unwrap_or_else(|| item.sig.ident.to_string()); - - Ok(Lsm { item, name }) + let name = pop_arg(&mut args, "name"); + let mut sleepable = false; + if let Some(s) = pop_arg(&mut args, "sleepable") { + if let Ok(m) = s.parse() { + sleepable = m + } else { + return Err(Error::new_spanned( + "mutlibuffer", + "invalid value. should be 'true' or 'false'", + )); + } + } + err_on_unknown_args(&args)?; + Ok(Lsm { + item, + name, + sleepable, + }) } pub fn expand(&self) -> Result { - let section_name = format!("lsm/{}", self.name); + let section_prefix = if self.sleepable { "lsm.s" } else { "lsm" }; + let section_name = if let Some(name) = &self.name { + format!("{section_prefix}/{name}") + } else { + section_prefix.to_string() + }; let fn_vis = &self.item.vis; let fn_name = &self.item.sig.ident; let item = &self.item; diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 5ea7a40b..af78ac87 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -148,7 +148,7 @@ pub struct Function { /// - `uprobe.s+` or `uretprobe.s+` /// - `usdt+` /// - `kprobe.multi+` or `kretprobe.multi+`: `BPF_TRACE_KPROBE_MULTI` -/// - `lsm_cgroup+` or `lsm.s+` +/// - `lsm_cgroup+` /// - `lwt_in`, `lwt_out`, `lwt_seg6local`, `lwt_xmit` /// - `raw_tp.w+`, `raw_tracepoint.w+` /// - `action` @@ -477,7 +477,7 @@ impl FromStr for ProgramSection { name, sleepable_supported: false, }, - "lsm.s+" => Lsm { + "lsm.s" => Lsm { name, sleepable_supported: true, }, @@ -1941,7 +1941,7 @@ mod tests { assert_matches!( obj.parse_section(fake_section( BpfSectionKind::Program, - "lsm.s+/foo", + "lsm.s/foo", bytes_of(&fake_ins()) )), Ok(())