Commit 54044d51 authored by detailyang's avatar detailyang Committed by yonghong-song

tools: allow tcpaccept filter via PID (#2117)

add missing FILTER in the bpf program.
parent 9f851e2a
...@@ -84,6 +84,8 @@ int kretprobe__inet_csk_accept(struct pt_regs *ctx) ...@@ -84,6 +84,8 @@ int kretprobe__inet_csk_accept(struct pt_regs *ctx)
struct sock *newsk = (struct sock *)PT_REGS_RC(ctx); struct sock *newsk = (struct sock *)PT_REGS_RC(ctx);
u32 pid = bpf_get_current_pid_tgid(); u32 pid = bpf_get_current_pid_tgid();
##FILTER_PID##
if (newsk == NULL) if (newsk == NULL)
return 0; return 0;
...@@ -161,6 +163,9 @@ TRACEPOINT_PROBE(sock, inet_sock_set_state) ...@@ -161,6 +163,9 @@ TRACEPOINT_PROBE(sock, inet_sock_set_state)
if (args->protocol != IPPROTO_TCP) if (args->protocol != IPPROTO_TCP)
return 0; return 0;
u32 pid = bpf_get_current_pid_tgid(); u32 pid = bpf_get_current_pid_tgid();
##FILTER_PID##
// pull in details // pull in details
u16 family = 0, lport = 0; u16 family = 0, lport = 0;
family = args->family; family = args->family;
...@@ -197,10 +202,10 @@ else: ...@@ -197,10 +202,10 @@ else:
# code substitutions # code substitutions
if args.pid: if args.pid:
bpf_text = bpf_text.replace('FILTER', bpf_text = bpf_text.replace('##FILTER_PID##',
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('##FILTER_PID##', '')
if debug or args.ebpf: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf: if args.ebpf:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment