fentry/fexit: Add template for fentry/fexit programs

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
pull/25/head
Michal Rostecki 3 years ago
parent b0577674b2
commit e1fb8024a6

@ -21,6 +21,8 @@ jobs:
program:
- kprobe
- kretprobe
- fentry
- fexit
- uprobe
- uretprobe
- sock_ops
@ -38,13 +40,13 @@ jobs:
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: stable
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rust-src
toolchain: nightly
components: rust-src
- name: Install bpf-linker
run: cargo +nightly install bpf-linker

@ -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