-
Notifications
You must be signed in to change notification settings - Fork 68
Description
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:
u128::from_be(ctx.load(offset_of!(ipv6hdr, saddr)).unwrap())
It is obvious that this is not an IP address as this is changing all the time. This is ipv6hdr:
pub struct ipv6hdr {
pub _bitfield_align_1: [u8; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>,
pub flow_lbl: [__u8; 3usize],
pub payload_len: __be16,
pub nexthdr: __u8,
pub hop_limit: __u8,
pub saddr: [__be32; 4usize],
pub daddr: [__be32; 4usize],
}
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.