Merge pull request #65 from vadorovsky/raw-tracepoint

Add raw_tracepoint program type
pull/72/head
Michal Rostecki 2 years ago committed by GitHub
commit 806571f3d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,6 +36,7 @@ jobs:
- tracepoint
- lsm
- tp_btf
- raw_tracepoint
steps:
- uses: actions/checkout@v2

@ -22,7 +22,8 @@ choices = [
"cgroup_sockopt",
"tracepoint",
"lsm",
"tp_btf"
"tp_btf",
"raw_tracepoint"
]
default = "xdp"
@ -62,7 +63,7 @@ type = "string"
prompt = "Which tracepoint category? (e.g sched, net etc...)"
regex = "^[a-z_]+$"
[conditional.'program_type == "tracepoint" || program_type == "tp_btf"'.placeholders.tracepoint_name]
[conditional.'program_type == "tracepoint" || program_type == "tp_btf" || program_type == "raw_tracepoint"'.placeholders.tracepoint_name]
type = "string"
prompt = "Which tracepoint name? (e.g sched_switch, net_dev_queue)"
regex = "^[a-z_]+$"

@ -42,6 +42,9 @@ case "$PROG_TYPE" in
"cgroup_sockopt")
ADDITIONAL_ARGS="-d sockopt_target=getsockopt"
;;
"raw_tracepoint")
ADDITIONAL_ARGS="-d tracepoint_name=sys_enter"
;;
*)
ADDITIONAL_ARGS=''
esac

@ -322,6 +322,25 @@ fn try_{{crate_name}}(ctx: SockoptContext) -> Result<i32, i32> {
info!(&ctx, "{{sockopt_target}} called");
Ok(0)
}
{%- when "raw_tracepoint" %}
use aya_bpf::{
macros::raw_tracepoint,
programs::RawTracePointContext,
};
use aya_log_ebpf::info;
#[raw_tracepoint(name="{{crate_name}}")]
pub fn {{crate_name}}(ctx: RawTracePointContext) -> i32 {
match try_{{crate_name}}(ctx) {
Ok(ret) => ret,
Err(ret) => ret,
}
}
fn try_{{crate_name}}(ctx: RawTracePointContext) -> Result<i32, i32> {
info!(&ctx, "tracepoint {{tracepoint_name}} called");
Ok(0)
}
{%- endcase %}
#[panic_handler]

@ -35,6 +35,8 @@ use aya::{programs::BtfTracePoint, Btf};
use std::net::TcpStream;
use std::os::unix::io::AsRawFd;
use aya::programs::SocketFilter;
{%- when "raw_tracepoint" -%}
use aya::programs::RawTracePoint;
{%- endcase %}
use aya_log::BpfLogger;
use clap::Parser;
@ -153,6 +155,10 @@ async fn main() -> Result<(), anyhow::Error> {
let cgroup = std::fs::File::open(opt.cgroup_path)?;
program.load()?;
program.attach(cgroup)?;
{%- when "raw_tracepoint" -%}
let program: &mut RawTracePoint = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
program.load()?;
program.attach("{{tracepoint_name}}")?;
{%- endcase %}
info!("Waiting for Ctrl-C...");

Loading…
Cancel
Save