Merge pull request #33 from nak3/add-socket-filter

Add template for socket_filter program type
pull/45/head
Dave Tucker 3 years ago committed by GitHub
commit 807131b955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,6 +26,7 @@ jobs:
- uprobe
- uretprobe
- sock_ops
- socket_filter
- sk_msg
- xdp
- classifier

@ -13,6 +13,7 @@ choices = [
"uprobe",
"uretprobe",
"sock_ops",
"socket_filter",
"sk_msg",
"xdp",
"classifier",

@ -274,6 +274,16 @@ unsafe fn try_{{tracepoint_name}}(ctx: BtfTracePointContext) -> Result<i32, i32>
info!(&ctx, "tracepoint {{tracepoint_name}} called");
Ok(0)
}
{%- when "socket_filter" %}
use aya_bpf::{
macros::socket_filter,
programs::SkBuffContext,
};
#[socket_filter(name="{{crate_name}}")]
pub fn {{crate_name}}(_ctx: SkBuffContext) -> i64 {
return 0
}
{%- endcase %}
#[panic_handler]

@ -27,6 +27,10 @@ use aya::programs::TracePoint;
use aya::{programs::Lsm, Btf};
{%- when "tp_btf" -%}
use aya::{programs::BtfTracePoint, Btf};
{%- when "socket_filter" -%}
use std::net::TcpStream;
use std::os::unix::io::AsRawFd;
use aya::programs::SocketFilter;
{%- endcase %}
use aya_log::BpfLogger;
use clap::Parser;
@ -136,6 +140,11 @@ async fn main() -> Result<(), anyhow::Error> {
let program: &mut BtfTracePoint = bpf.program_mut("{{tracepoint_name}}").unwrap().try_into()?;
program.load("{{tracepoint_name}}", &btf)?;
program.attach()?;
{%- when "socket_filter" -%}
let client = TcpStream::connect("127.0.0.1:1234")?;
let prog: &mut SocketFilter = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
prog.load()?;
prog.attach(client.as_raw_fd())?;
{%- endcase %}
info!("Waiting for Ctrl-C...");

Loading…
Cancel
Save