BPF setsockopt with ICMP6

44 Views Asked by At

We are using ebpf to mark ICMP6 packets, if the ToS Socket Option is used. We are using the setsockopt ebpf program. We are also using ip -6 rule with the correct fwmark to route the packets to a non-default routing table. This works for IPv6 with UDP/TCP/SCTP. It also works for all IPv4 (incl. icmp). Only for the case of ICMPv6 (ping), it does not work as expected. If the default table is used, we can see over nftables, that the packets are marked.

We are using:

int tos_setsockopt(struct bpf_sockopt * ctx) { int *optval = ctx->optval;    bpf_setsockopt(ctx->sk, SOL_SOCKET, SO_MARK, optval, 4)

and the following ip6 rule

from all fwmark 0x20 lookup 8 (for ToS 32)

Marking the packet in alternative ways does work:

If we set the mark with ping (-m), we can see with strace that setsockopt(SO_MARK) is also used the same way, but the qos routing using fwmark does work in this case. If another program type (cgroup/sock_create) is used, we can use helper functions, which can give us direct access to the socket structure. Here we can set the socket mark value to a fixed value (bpf_sock->mark). This way, the packet is also transmitted via fwmarking correctly.

Do we need to use here tailing and call another ebpf program type which can access the socket directly? Are there issues with the combination of fwmark & ICMPv6?

0

There are 0 best solutions below