pull/545/head
epompeii 2 years ago
parent 17f497ce42
commit 6dfb9d82af

@ -613,18 +613,39 @@ impl RawTracePoint {
pub struct Lsm { pub struct Lsm {
item: ItemFn, item: ItemFn,
name: String, name: Option<String>,
sleepable: bool,
} }
impl Lsm { impl Lsm {
pub fn from_syn(mut args: Args, item: ItemFn) -> Result<Lsm> { pub fn from_syn(mut args: Args, item: ItemFn) -> Result<Lsm> {
let name = name_arg(&mut args)?.unwrap_or_else(|| item.sig.ident.to_string()); let name = pop_arg(&mut args, "name");
let mut sleepable = false;
Ok(Lsm { item, name }) 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<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
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_vis = &self.item.vis;
let fn_name = &self.item.sig.ident; let fn_name = &self.item.sig.ident;
let item = &self.item; let item = &self.item;

@ -148,7 +148,7 @@ pub struct Function {
/// - `uprobe.s+` or `uretprobe.s+` /// - `uprobe.s+` or `uretprobe.s+`
/// - `usdt+` /// - `usdt+`
/// - `kprobe.multi+` or `kretprobe.multi+`: `BPF_TRACE_KPROBE_MULTI` /// - `kprobe.multi+` or `kretprobe.multi+`: `BPF_TRACE_KPROBE_MULTI`
/// - `lsm_cgroup+` or `lsm.s+` /// - `lsm_cgroup+`
/// - `lwt_in`, `lwt_out`, `lwt_seg6local`, `lwt_xmit` /// - `lwt_in`, `lwt_out`, `lwt_seg6local`, `lwt_xmit`
/// - `raw_tp.w+`, `raw_tracepoint.w+` /// - `raw_tp.w+`, `raw_tracepoint.w+`
/// - `action` /// - `action`
@ -477,7 +477,7 @@ impl FromStr for ProgramSection {
name, name,
sleepable_supported: false, sleepable_supported: false,
}, },
"lsm.s+" => Lsm { "lsm.s" => Lsm {
name, name,
sleepable_supported: true, sleepable_supported: true,
}, },
@ -1941,7 +1941,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, BpfSectionKind::Program,
"lsm.s+/foo", "lsm.s/foo",
bytes_of(&fake_ins()) bytes_of(&fake_ins())
)), )),
Ok(()) Ok(())

Loading…
Cancel
Save