|
|
|
@ -2,10 +2,7 @@
|
|
|
|
|
#![no_main]
|
|
|
|
|
{% case program_type -%}
|
|
|
|
|
{%- when "kprobe" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
macros::kprobe,
|
|
|
|
|
programs::ProbeContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_bpf::{macros::kprobe, programs::ProbeContext};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
|
#[kprobe(name = "{{crate_name}}")]
|
|
|
|
@ -21,10 +18,7 @@ fn try_{{crate_name}}(ctx: ProbeContext) -> Result<u32, u32> {
|
|
|
|
|
Ok(0)
|
|
|
|
|
}
|
|
|
|
|
{%- when "kretprobe" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
macros::kretprobe,
|
|
|
|
|
programs::ProbeContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_bpf::{macros::kretprobe, programs::ProbeContext};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
|
#[kretprobe(name = "{{crate_name}}")]
|
|
|
|
@ -160,11 +154,7 @@ fn try_{{crate_name}}(ctx: SkMsgContext) -> Result<u32, u32> {
|
|
|
|
|
Ok(0)
|
|
|
|
|
}
|
|
|
|
|
{%- when "xdp" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
bindings::xdp_action,
|
|
|
|
|
macros::xdp,
|
|
|
|
|
programs::XdpContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
|
#[xdp(name = "{{crate_name}}")]
|
|
|
|
@ -180,10 +170,7 @@ fn try_{{crate_name}}(ctx: XdpContext) -> Result<u32, u32> {
|
|
|
|
|
Ok(xdp_action::XDP_PASS)
|
|
|
|
|
}
|
|
|
|
|
{%- when "classifier" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
macros::classifier,
|
|
|
|
|
programs::TcContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_bpf::{macros::classifier, programs::TcContext};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
|
#[classifier(name = "{{crate_name}}")]
|
|
|
|
@ -304,10 +291,7 @@ fn try_{{crate_name}}(ctx: SysctlContext) -> Result<i32, i32> {
|
|
|
|
|
Ok(0)
|
|
|
|
|
}
|
|
|
|
|
{%- when "cgroup_sockopt" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
macros::cgroup_sockopt,
|
|
|
|
|
programs::SockoptContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_bpf::{macros::cgroup_sockopt, programs::SockoptContext};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
|
#[cgroup_sockopt({{sockopt_target}}, name = "{{crate_name}}")]
|
|
|
|
@ -323,10 +307,7 @@ fn try_{{crate_name}}(ctx: SockoptContext) -> Result<i32, i32> {
|
|
|
|
|
Ok(0)
|
|
|
|
|
}
|
|
|
|
|
{%- when "raw_tracepoint" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
macros::raw_tracepoint,
|
|
|
|
|
programs::RawTracePointContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_bpf::{macros::raw_tracepoint, programs::RawTracePointContext};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
|
#[raw_tracepoint(name = "{{crate_name}}")]
|
|
|
|
@ -343,10 +324,7 @@ fn try_{{crate_name}}(ctx: RawTracePointContext) -> Result<i32, i32> {
|
|
|
|
|
}
|
|
|
|
|
{%- when "perf_event" %}
|
|
|
|
|
use aya_bpf::{
|
|
|
|
|
helpers::bpf_get_smp_processor_id,
|
|
|
|
|
macros::perf_event,
|
|
|
|
|
programs::PerfEventContext,
|
|
|
|
|
BpfContext,
|
|
|
|
|
helpers::bpf_get_smp_processor_id, macros::perf_event, programs::PerfEventContext, BpfContext,
|
|
|
|
|
};
|
|
|
|
|
use aya_log_ebpf::info;
|
|
|
|
|
|
|
|
|
@ -361,8 +339,14 @@ pub fn {{crate_name}}(ctx: PerfEventContext) -> u32 {
|
|
|
|
|
fn try_{{crate_name}}(ctx: PerfEventContext) -> Result<u32, u32> {
|
|
|
|
|
let cpu = unsafe { bpf_get_smp_processor_id() };
|
|
|
|
|
match ctx.pid() {
|
|
|
|
|
0 => info!(&ctx, "perf_event '{{crate_name}}' triggered on CPU {}, running a kernel task", cpu),
|
|
|
|
|
pid => info!(&ctx, "perf_event '{{crate_name}}' triggered on CPU {}, running PID {}", cpu, pid),
|
|
|
|
|
0 => info!(
|
|
|
|
|
&ctx,
|
|
|
|
|
"perf_event 'perftest' triggered on CPU {}, running a kernel task", cpu
|
|
|
|
|
),
|
|
|
|
|
pid => info!(
|
|
|
|
|
&ctx,
|
|
|
|
|
"perf_event 'perftest' triggered on CPU {}, running PID {}", cpu, pid
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|