-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get ipv6 tuple info for -m text #724
Comments
To obtain IPv6 tuple information in the
Here is a basic outline of how you might modify the function: static __inline int kretprobe_connect(struct pt_regs *ctx, int fd, struct sock *sk, const bool active) {
u64 current_pid_tgid = bpf_get_current_pid_tgid();
u32 pid = current_pid_tgid >> 32;
u64 current_uid_gid = bpf_get_current_uid_gid();
u32 uid = current_uid_gid;
u16 address_family = 0;
bpf_probe_read_kernel(&address_family, sizeof(address_family), &sk->__sk_common.skc_family);
if (address_family == AF_INET) {
// Existing IPv4 handling code
} else if (address_family == AF_INET6) {
u32 src_ip6[4], dst_ip6[4];
bpf_probe_read_kernel(&src_ip6, sizeof(src_ip6), &sk->__sk_common.skc_v6_rcv_saddr);
bpf_probe_read_kernel(&dst_ip6, sizeof(dst_ip6), &sk->__sk_common.skc_v6_daddr);
// Process the IPv6 addresses and ports
// Add your logic here to handle the IPv6 tuple
} else {
return 0;
}
// Continue with the rest of the function
} By implementing these changes, you should be able to capture IPv6 tuple information alongside IPv4. This approach aligns with the suggestions in the pull requests you mentioned, which aim to enhance IPv6 support by modifying existing hooks or implementing new ones [1]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
But hook function __sys_accept4 only support ipv4 connect event @dosu |
To extend the
Here's a basic outline of how you might modify the function: SEC("kretprobe/__sys_accept4")
int retprobe_accept4(struct pt_regs* ctx) {
struct sock *sk;
u16 address_family = 0;
// Retrieve the socket and address family
bpf_probe_read_kernel(&sk, sizeof(sk), /* appropriate method to get sk */);
bpf_probe_read_kernel(&address_family, sizeof(address_family), &sk->__sk_common.skc_family);
if (address_family == AF_INET) {
// Existing IPv4 handling code
} else if (address_family == AF_INET6) {
u32 src_ip6[4], dst_ip6[4];
bpf_probe_read_kernel(&src_ip6, sizeof(src_ip6), &sk->__sk_common.skc_v6_rcv_saddr);
bpf_probe_read_kernel(&dst_ip6, sizeof(dst_ip6), &sk->__sk_common.skc_v6_daddr);
// Process the IPv6 addresses and ports
// Add your logic here to handle the IPv6 tuple
} else {
return 0;
}
// Continue with the rest of the function
} By implementing these changes, you should be able to capture IPv6 connection events in the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
kernel function __sys_accept4 can not handle ipv6 connect, I think we should found another kernel function to hook to get ipv6 tuple |
As feat #684 and #695 already support get 4-tuple info for decrypt ssl data from UUID. But the kernel hook function such as sys_connect, __sys_accept4, tcp_v4_destroy_sock only works for ipv4 connection, is there any solutions to obtain ipv6 tuple info? Thks @Asphaltt
code kretprobe_connect only deal with AF_INET, and AF_INET6 packet will be dropped.
The text was updated successfully, but these errors were encountered: