]> git.baikalelectronics.ru Git - kernel.git/commit
ipv6: sr: Add seg6local action End.BPF
authorMathieu Xhonneux <m.xhonneux@gmail.com>
Sun, 20 May 2018 13:58:16 +0000 (14:58 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 24 May 2018 09:57:36 +0000 (11:57 +0200)
commit9fce1a7aec1b5b409d66c9bd8711dedc39abb947
tree055296b26fe485082f0f7c8c5c8d721d07016355
parentab696fa9ab87f651329366692d7eba1e354ad69e
ipv6: sr: Add seg6local action End.BPF

This patch adds the End.BPF action to the LWT seg6local infrastructure.
This action works like any other seg6local End action, meaning that an IPv6
header with SRH is needed, whose DA has to be equal to the SID of the
action. It will also advance the SRH to the next segment, the BPF program
does not have to take care of this.

Since the BPF program may not be a source of instability in the kernel, it
is important to ensure that the integrity of the packet is maintained
before yielding it back to the IPv6 layer. The hook hence keeps track if
the SRH has been altered through the helpers, and re-validates its
content if needed with seg6_validate_srh. The state kept for validation is
stored in a per-CPU buffer. The BPF program is not allowed to directly
write into the packet, and only some fields of the SRH can be altered
through the helper bpf_lwt_seg6_store_bytes.

Performances profiling has shown that the SRH re-validation does not induce
a significant overhead. If the altered SRH is deemed as invalid, the packet
is dropped.

This validation is also done before executing any action through
bpf_lwt_seg6_action, and will not be performed again if the SRH is not
modified after calling the action.

The BPF program may return 3 types of return codes:
    - BPF_OK: the End.BPF action will look up the next destination through
             seg6_lookup_nexthop.
    - BPF_REDIRECT: if an action has been executed through the
          bpf_lwt_seg6_action helper, the BPF program should return this
          value, as the skb's destination is already set and the default
          lookup should not be performed.
    - BPF_DROP : the packet will be dropped.

Signed-off-by: Mathieu Xhonneux <m.xhonneux@gmail.com>
Acked-by: David Lebrun <dlebrun@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/linux/bpf_types.h
include/uapi/linux/bpf.h
include/uapi/linux/seg6_local.h
kernel/bpf/verifier.c
net/core/filter.c
net/ipv6/seg6_local.c
tools/lib/bpf/libbpf.c