aya-bpf: Add multibuffer support for XDP

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/519/head
Dave Tucker 2 years ago
parent a18693b42d
commit 376c486400

@ -200,20 +200,33 @@ impl SkMsg {
pub struct Xdp { pub struct Xdp {
item: ItemFn, item: ItemFn,
name: Option<String>, name: Option<String>,
frags: bool,
} }
impl Xdp { impl Xdp {
pub fn from_syn(mut args: Args, item: ItemFn) -> Result<Xdp> { pub fn from_syn(mut args: Args, item: ItemFn) -> Result<Xdp> {
let name = name_arg(&mut args)?; let name = pop_arg(&mut args, "name");
let mut frags = false;
Ok(Xdp { item, name }) if let Some(s) = pop_arg(&mut args, "frags") {
if let Ok(m) = s.parse() {
frags = m
} else {
return Err(Error::new_spanned(
"mutlibuffer",
"invalid value. should be 'true' or 'false'",
));
}
}
err_on_unknown_args(&args)?;
Ok(Xdp { item, name, frags })
} }
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_prefix = if self.frags { "xdp.frags" } else { "xdp" };
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("xdp/{name}") format!("{section_prefix}/{name}")
} else { } else {
"xdp".to_owned() 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;

@ -313,8 +313,14 @@ impl FromStr for ProgramSection {
"kretprobe" => KRetProbe { name }, "kretprobe" => KRetProbe { name },
"uprobe" => UProbe { name }, "uprobe" => UProbe { name },
"uretprobe" => URetProbe { name }, "uretprobe" => URetProbe { name },
"xdp" => Xdp { name, frags_supported: false}, "xdp" => Xdp {
"xdp.frags" => Xdp { name, frags_supported: true}, name,
frags_supported: false,
},
"xdp.frags" => Xdp {
name,
frags_supported: true,
},
"tp_btf" => BtfTracePoint { name }, "tp_btf" => BtfTracePoint { name },
_ if kind.starts_with("tracepoint") || kind.starts_with("tp") => { _ if kind.starts_with("tracepoint") || kind.starts_with("tp") => {
// tracepoint sections are named `tracepoint/category/event_name`, // tracepoint sections are named `tracepoint/category/event_name`,
@ -1853,7 +1859,10 @@ mod tests {
assert_matches!( assert_matches!(
obj.programs.get("foo"), obj.programs.get("foo"),
Some(Program { Some(Program {
section: ProgramSection::Xdp { frags_supported: true, .. }, section: ProgramSection::Xdp {
frags_supported: true,
..
},
.. ..
}) })
); );

@ -14,7 +14,7 @@ static FOO: Array<u32> = Array::<u32>::with_max_entries(10, 0);
#[map(name = "BAR")] #[map(name = "BAR")]
static BAZ: Array<u32> = Array::<u32>::with_max_entries(10, 0); static BAZ: Array<u32> = Array::<u32>::with_max_entries(10, 0);
#[xdp] #[xdp(frags = "true")]
pub fn pass(ctx: XdpContext) -> u32 { pub fn pass(ctx: XdpContext) -> u32 {
match unsafe { try_pass(ctx) } { match unsafe { try_pass(ctx) } {
Ok(ret) => ret, Ok(ret) => ret,

@ -3,7 +3,7 @@
use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext}; use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};
#[xdp(name = "pass")] #[xdp(name = "pass", frags = "true")]
pub fn pass(ctx: XdpContext) -> u32 { pub fn pass(ctx: XdpContext) -> u32 {
match unsafe { try_pass(ctx) } { match unsafe { try_pass(ctx) } {
Ok(ret) => ret, Ok(ret) => ret,

Loading…
Cancel
Save