Skip to content

Commit

Permalink
fix: Only handle tcp socket when probe connect and accept
Browse files Browse the repository at this point in the history
It's unnecessary to record excluding-tcp sockets' info.

So, when probe connect and accept, we only handle tcp socket by
filtering `sk->sk_protocol`.

Signed-off-by: Leon Hwang <[email protected]>
  • Loading branch information
Asphaltt committed Dec 13, 2024
1 parent 19b9bb6 commit ff0807c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kern/openssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static __inline int kretprobe_connect(struct pt_regs *ctx, int fd, struct sock *
u64 current_uid_gid = bpf_get_current_uid_gid();
u32 uid = current_uid_gid;
u16 address_family = 0;
u16 protocol;
u64 addrs;
u32 ports;

Expand All @@ -532,6 +533,11 @@ static __inline int kretprobe_connect(struct pt_regs *ctx, int fd, struct sock *
return 0;
}

bpf_probe_read_kernel(&protocol, sizeof(protocol), &sk->sk_protocol);
if (protocol != IPPROTO_TCP) {
return 0;
}

// if the connection hasn't been established yet, the ports or addrs are 0.
bpf_probe_read_kernel(&addrs, sizeof(addrs), &sk->__sk_common.skc_addrpair);
bpf_probe_read_kernel(&ports, sizeof(ports), &sk->__sk_common.skc_portpair);
Expand Down

0 comments on commit ff0807c

Please sign in to comment.