Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

libbpf-tools/tcptracer: unused ctx parameter in enter_tcp_connect/exit_tcp_connect can be safely removed #5229

Open
yu410621 opened this issue Mar 12, 2025 · 0 comments

Comments

@yu410621
Copy link

Hello,

In the code of the tcptracer tool, the ctx parameter (of type struct pt_regs *) of the function enter_tcp_connect/exit_tcp_connect is not actually used, but the current code still keeps it as a function parameter.

static __always_inline int
enter_tcp_connect(struct pt_regs *ctx, struct sock *sk)
{
	__u64 pid_tgid = bpf_get_current_pid_tgid();
	__u32 pid = pid_tgid >> 32;
	__u32 tid = pid_tgid;
	__u64 uid_gid = bpf_get_current_uid_gid();
	__u32 uid = uid_gid;

	if (filter_event(sk, uid, pid))
		return 0;

	bpf_map_update_elem(&sockets, &tid, &sk, 0);
	return 0;
}

After testing, after removing the ctx parameter, the tool compiles and runs normally with no impact on its functionality.

So, is keeping the ctx parameter an idiomatic way of writing it, or does it serve some other purpose?

Thanks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant