]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: BPF for lightweight tunnel infrastructure
authorThomas Graf <tgraf@suug.ch>
Wed, 30 Nov 2016 16:10:10 +0000 (17:10 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 2 Dec 2016 15:51:49 +0000 (10:51 -0500)
commit5504a378b4f2db0ff608258e5cf6edda31e14c9e
treed416e9fd84ccb9c7d66ac9d58e1ca9cd7000bd33
parent1cb8c7c2089971ee6da5388eee9d5ee80d91c57a
bpf: BPF for lightweight tunnel infrastructure

Registers new BPF program types which correspond to the LWT hooks:
  - BPF_PROG_TYPE_LWT_IN   => dst_input()
  - BPF_PROG_TYPE_LWT_OUT  => dst_output()
  - BPF_PROG_TYPE_LWT_XMIT => lwtunnel_xmit()

The separate program types are required to differentiate between the
capabilities each LWT hook allows:

 * Programs attached to dst_input() or dst_output() are restricted and
   may only read the data of an skb. This prevent modification and
   possible invalidation of already validated packet headers on receive
   and the construction of illegal headers while the IP headers are
   still being assembled.

 * Programs attached to lwtunnel_xmit() are allowed to modify packet
   content as well as prepending an L2 header via a newly introduced
   helper bpf_skb_change_head(). This is safe as lwtunnel_xmit() is
   invoked after the IP header has been assembled completely.

All BPF programs receive an skb with L3 headers attached and may return
one of the following error codes:

 BPF_OK - Continue routing as per nexthop
 BPF_DROP - Drop skb and return EPERM
 BPF_REDIRECT - Redirect skb to device as per redirect() helper.
                (Only valid in lwtunnel_xmit() context)

The return codes are binary compatible with their TC_ACT_
relatives to ease compatibility.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/filter.h
include/uapi/linux/bpf.h
include/uapi/linux/lwtunnel.h
kernel/bpf/verifier.c
net/Kconfig
net/core/Makefile
net/core/filter.c
net/core/lwt_bpf.c [new file with mode: 0644]
net/core/lwtunnel.c