-
Notifications
You must be signed in to change notification settings - Fork 60
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
SkBuffContext and IPv6 #82
Comments
Are you taking into account the ethernet header offset? ETH_HDR_LEN + offset_of!(iphdr, saddr) |
Thanks for the quick answer. For IPv4 for sock_filter (not TC) it is not needed and it works there perfectly without ETH_HDR. For IPv6 with or without it makes no difference - Maybe I do not correctly understand what is in SkBuffContext when an AF_INET6 socket is used... |
Maybe some more context. This is my ebpf program
As said - the IPv4 part works correctly (correct IP etc.), the IPv6 part - I think I am missing something. |
Ahh I see, if the protocol is IPv6 then I do not get the IP header in the data of skbuff, but only the TCP header... So this part is consistent with the raw socket API for IPv6. |
Or if this is feasible at all? I just want to explore what is possible with a socket filter, I am aware that I can also use XDP or TC. |
Oh, I've never used skb before. Had no idea it was any different. Sorry if I'm not following. Are you saying https://docs.aya-rs.dev/bpf/aya_bpf/bindings/struct.__sk_buff.html has |
Well the ip address fields are only filled out for BPF type: BPF_PROG_TYPE_SK_SKB (see: https://blogs.oracle.com/linux/post/bpf-a-tour-of-program-types) - not for BPF_PROG_TYPE_SOCKET_FILTER It seems - the only way to access ancialliary data (ie the ipv6 header) is to load it from a negative offset: It seems that aya only allows unsigned (positive) offsets. Can anyone confirm this assumption? |
Hmm, interesting. It seems like aya will only load with an offset |
What makes you think this? Here's an example of a socket filter parsing IP headers https://github.com/torvalds/linux/blob/03421a92f5627430d23ed95df55958e04848f184/samples/bpf/sockex2_kern.c#L100
I haven't written a socket filter in a long time but from what I can see in the kernel source, this doesn't seem to be true either? |
thanks a lot.
Because the data starts with the TCP header - I can parse port etc. successfully. It could be the different ways on how the raw socket is opened. I use:
In this way - even without eBPF - I receive in the user space program only the TCP header, which is normal (cf. e.g.https://schoenitzer.de/blog/2018/Linux%20Raw%20Sockets.html). Will try with
Well I just quoted the blog - this can have changed in different kernel versions, but contrary to see BPF functions to see which one are allowed and which one are not, finding out which fields are filled out in the view __sk_buff by the kernel is not so obvious (or I look in the wrong place). Where do you see this in the kernel source? Just for clarification - some of the fields in the view __sk_buff are filled, but not all - especially not the ip address ones if i use sock_filter. It seems according to the tests the blog is correct: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/verifier/ctx_skb.c Nevertheless, I could also overlook sth. here. Maybe the confusion comes from the different types of raw sockets used (I used an AF_INET6 one, the example you reference seems to be at a lower level, possibly AF_PACKET). |
Somehow, I have issues with Rust and a raw socket with AF_PACKET. For example, this quick and dirty C program works
It shows packages are received over the raw socket with AF_PACKET. However the equivalent quick and dirty Rust program does not show anything. It shows just "Enter loop" and then it is blocked in recv.
It works though with AF_INET,AF_INET6 |
Ok, found the issue in the Rust program (had to simulate htons(ETH_P_ALL)
Will for now with the raw packets, I just wonder if the following makes in aya sense (or if I misunderstood how it works)?
If it makes sense then I can close this issue and create a new issue for aya on this, if not then I simply close this issue. Please let me know. |
It seems to me that that stuff is only for (classic) BPF and is mapped to just accessing |
Good question, I will investigate. I can confirm so that with an aya socket filter I did not had access to remote_ip etc. only to protocol (essentially that were allowed by the tests shown in the Linux kernel). I do not think this was related to aya. |
Hi,
I am writing a socket filter (will be open sourced once working). I use this as a basis: https://github.com/aya-rs/book/tree/main/examples/cgroup-skb-egress, but it is not for cgroups_skb, but for socket filter.
I have made it working for IPv4 and IPv6. However, in the eBPF program itself I am only able to get properly the IPv4 address. In case of IPv6 sockets, I somehow get no proper IP address.
I extract the IPv4 address similarly to here:
https://github.com/aya-rs/book/blob/main/examples/cgroup-skb-egress/cgroup-skb-egress-ebpf/src/main.rs#L46
This is my code to extract the IPv6 address:
It is obvious that this is not an IP address as this is changing all the time. This is ipv6hdr:
I am not sure if case of IPv6 the ipv6hdr is at a different offset and I need to add sth.
Any idea?
Thanks a lot.
The text was updated successfully, but these errors were encountered: