Merge pull request #25 from vadorovsky/fentry

fentry/fexit: Add template for fentry/fexit programs
pull/8/head
Dave Tucker 3 years ago committed by GitHub
commit bc7cd9ad46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,8 @@ jobs:
program:
- kprobe
- kretprobe
- fentry
- fexit
- uprobe
- uretprobe
- sock_ops

@ -5,13 +5,32 @@ ignore = [".github", "test.sh"]
[placeholders.program_type]
type = "string"
prompt = "Which type of eBPF program?"
choices = ["kprobe", "kretprobe", "uprobe", "uretprobe", "sock_ops", "sk_msg", "xdp", "classifier", "cgroup_skb", "tracepoint", "lsm", "tp_btf"]
choices = [
"kprobe",
"kretprobe",
"fentry",
"fexit",
"uprobe",
"uretprobe",
"sock_ops",
"sk_msg",
"xdp",
"classifier",
"cgroup_skb",
"tracepoint",
"lsm",
"tp_btf"
]
default = "xdp"
[conditional.'program_type == "kprobe" || program_type == "kretprobe"'.placeholders.kprobe]
type = "string"
prompt = "Where to attach the (k|kret)probe? (e.g try_to_wake_up)"
[conditional.'program_type == "fentry" || program_type == "fexit"'.placeholders.fn_name]
type = "string"
prompt = "Where to attach the f(entry|exit)? (e.g try_to_wake_up)"
[conditional.'program_type == "uprobe" || program_type == "uretprobe"'.placeholders.uprobe_target]
type = "string"
prompt = "Target to attach the (u|uret)probe? (e.g libc)"

@ -18,6 +18,9 @@ case "$PROG_TYPE" in
"kprobe"|"kretprobe")
ADDITIONAL_ARGS="-d kprobe=test"
;;
"fentry"|"fexit")
ADDITIONAL_ARGS="-d fn_name=try_to_wake_up"
;;
"uprobe"|"uretprobe")
ADDITIONAL_ARGS="-d uprobe_target=testlib -d uprobe_fn_name=testfn"
;;

@ -35,6 +35,40 @@ pub fn {{crate_name}}(ctx: ProbeContext) -> u32 {
unsafe fn try_{{crate_name}}(_ctx: ProbeContext) -> Result<u32, u32> {
Ok(0)
}
{%- when "fentry" %}
use aya_bpf::{
macros::fentry,
programs::FEntryContext,
};
#[fentry(name="{{crate_name}}")]
pub fn {{crate_name}}(ctx: FEntryContext) -> u32 {
match unsafe { try_{{crate_name}}(ctx) } {
Ok(ret) => ret,
Err(ret) => ret,
}
}
unsafe fn try_{{crate_name}}(_ctx: FEntryContext) -> Result<u32, u32> {
Ok(0)
}
{%- when "fexit" %}
use aya_bpf::{
macros::fexit,
programs::FExitContext,
};
#[fexit(name="{{crate_name}}")]
pub fn {{crate_name}}(ctx: FExitContext) -> u32 {
match unsafe { try_{{crate_name}}(ctx) } {
Ok(ret) => ret,
Err(ret) => ret,
}
}
unsafe fn try_{{crate_name}}(_ctx: FExitContext) -> Result<u32, u32> {
Ok(0)
}
{%- when "uprobe" %}
use aya_bpf::{
macros::uprobe,

@ -2,6 +2,10 @@ use aya::{Bpf, include_bytes_aligned};
{% case program_type -%}
{%- when "kprobe", "kretprobe" -%}
use aya::programs::KProbe;
{%- when "fentry" -%}
use aya::{programs::FEntry, Btf};
{%- when "fexit" -%}
use aya::{programs::FExit, Btf};
{%- when "uprobe", "uretprobe" -%}
use aya::programs::UProbe;
{%- when "sock_ops" -%}
@ -71,6 +75,16 @@ fn try_main() -> Result<(), anyhow::Error> {
let program: &mut KProbe = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
program.load()?;
program.attach("{{kprobe}}", 0)?;
{%- when "fentry" -%}
let btf = Btf::from_sys_fs()?;
let program: &mut FEntry = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
program.load("{{fn_name}}", &btf)?;
program.attach()?;
{%- when "fexit" -%}
let btf = Btf::from_sys_fs()?;
let program: &mut FExit = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
program.load("{{fn_name}}", &btf)?;
program.attach()?;
{%- when "uprobe", "uretprobe" -%}
let program: &mut UProbe = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
program.load()?;

Loading…
Cancel
Save