bpf: Fix cgroup_skb macro

This commit ensures that if no attach type is provided, that we use the
cgroup/skb section. If an attach type is provided we use the
cgroup_skb/$attach_type section.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/112/head
Dave Tucker 3 years ago
parent 761cb79fe3
commit fa037a88e2

@ -215,14 +215,14 @@ impl SchedClassifier {
pub struct CgroupSkb { pub struct CgroupSkb {
item: ItemFn, item: ItemFn,
expected_attach_type: String, expected_attach_type: Option<String>,
name: Option<String>, name: Option<String>,
} }
impl CgroupSkb { impl CgroupSkb {
pub fn from_syn(mut args: Args, item: ItemFn) -> Result<CgroupSkb> { pub fn from_syn(mut args: Args, item: ItemFn) -> Result<CgroupSkb> {
let name = pop_arg(&mut args, "name"); let name = pop_arg(&mut args, "name");
let expected_attach_type = pop_arg(&mut args, "attach").unwrap_or_else(|| "skb".to_owned()); let expected_attach_type = pop_arg(&mut args, "attach");
Ok(CgroupSkb { Ok(CgroupSkb {
item, item,
@ -232,11 +232,16 @@ impl CgroupSkb {
} }
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let attach = &self.expected_attach_type; let section_name = if let Some(attach) = &self.expected_attach_type {
let section_name = if let Some(name) = &self.name { if let Some(name) = &self.name {
format!("cgroup_skb/{}/{}", attach, name) format!("cgroup_skb/{}/{}", attach, name)
} else { } else {
format!("cgroup_skb/{}", attach) format!("cgroup_skb/{}", attach)
}
} else if let Some(name) = &self.name {
format!("cgroup/skb/{}", name)
} else {
("cgroup/skb").to_owned()
}; };
let fn_name = &self.item.sig.ident; let fn_name = &self.item.sig.ident;
let item = &self.item; let item = &self.item;

Loading…
Cancel
Save