From f131e87764c5a5374d44d96e71713d1627ac0734 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 13 Oct 2024 11:37:43 -0400 Subject: [PATCH] Use TCP listener instead of stream This doesn't require a listener on the other side. --- {{project-name}}/src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index 15103ea..b97cd5d 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -35,8 +35,6 @@ use aya::{ {%- when "tp_btf" -%} use aya::{programs::BtfTracePoint, Btf}; {%- when "socket_filter" -%} -use std::net::TcpStream; - use aya::programs::SocketFilter; {%- when "raw_tracepoint" -%} use aya::programs::RawTracePoint; @@ -163,10 +161,10 @@ async fn main() -> anyhow::Result<()> { program.load("{{tracepoint_name}}", &btf)?; program.attach()?; {%- when "socket_filter" -%} - let client = TcpStream::connect("127.0.0.1:1234")?; + let listener = std::net::TcpListener::bind("localhost:0")?; let prog: &mut SocketFilter = ebpf.program_mut("{{crate_name}}").unwrap().try_into()?; prog.load()?; - prog.attach(client)?; + prog.attach(&listener)?; {%- when "cgroup_sysctl" -%} let program: &mut CgroupSysctl = ebpf.program_mut("{{crate_name}}").unwrap().try_into()?; let cgroup = std::fs::File::open(opt.cgroup_path)?;