bpf, sockmap: Add skb_adjust_room to pop bytes off ingress payload
authorJohn Fastabend <john.fastabend@gmail.com>
Fri, 2 Oct 2020 01:09:52 +0000 (18:09 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 2 Oct 2020 22:18:39 +0000 (15:18 -0700)
commit18ebe16d10496db795a9930c320c45653207a548
treeaa229591d26c24c5274a860cb8c8cb9e57698fe2
parent60a128b532d88ac78d8dd60577700dea70ee8c38
bpf, sockmap: Add skb_adjust_room to pop bytes off ingress payload

This implements a new helper skb_adjust_room() so users can push/pop
extra bytes from a BPF_SK_SKB_STREAM_VERDICT program.

Some protocols may include headers and other information that we may
not want to include when doing a redirect from a BPF_SK_SKB_STREAM_VERDICT
program. One use case is to redirect TLS packets into a receive socket
that doesn't expect TLS data. In TLS case the first 13B or so contain the
protocol header. With KTLS the payload is decrypted so we should be able
to redirect this to a receiving socket, but the receiving socket may not
be expecting to receive a TLS header and discard the data. Using the
above helper we can pop the header off and put an appropriate header on
the payload. This allows for creating a proxy between protocols without
extra hops through the stack or userspace.

So in order to fix this case add skb_adjust_room() so users can strip the
header. After this the user can strip the header and an unmodified receiver
thread will work correctly when data is redirected into the ingress path
of a sock.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160160099197.7052.8443193973242831692.stgit@john-Precision-5820-Tower
net/core/filter.c