OSDN Git Service

bpf: Add csum_level helper for fixing up csum levels
authorDaniel Borkmann <daniel@iogearbox.net>
Tue, 2 Jun 2020 14:58:33 +0000 (16:58 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 2 Jun 2020 18:50:23 +0000 (11:50 -0700)
commit7cdec54f9713256bb170873a1fc5c75c9127c9d2
tree2de575e883f9cb33b9722b135a4a54c352cdb984
parent836e66c218f355ec01ba57671c85abf32961dcea
bpf: Add csum_level helper for fixing up csum levels

Add a bpf_csum_level() helper which BPF programs can use in combination
with bpf_skb_adjust_room() when they pass in BPF_F_ADJ_ROOM_NO_CSUM_RESET
flag to the latter to avoid falling back to CHECKSUM_NONE.

The bpf_csum_level() allows to adjust CHECKSUM_UNNECESSARY skb->csum_levels
via BPF_CSUM_LEVEL_{INC,DEC} which calls __skb_{incr,decr}_checksum_unnecessary()
on the skb. The helper also allows a BPF_CSUM_LEVEL_RESET which sets the skb's
csum to CHECKSUM_NONE as well as a BPF_CSUM_LEVEL_QUERY to just return the
current level. Without this helper, there is no way to otherwise adjust the
skb->csum_level. I did not add an extra dummy flags as there is plenty of free
bitspace in level argument itself iff ever needed in future.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Acked-by: Lorenz Bauer <lmb@cloudflare.com>
Link: https://lore.kernel.org/bpf/279ae3717cb3d03c0ffeb511493c93c450a01e1a.1591108731.git.daniel@iogearbox.net
include/uapi/linux/bpf.h
net/core/filter.c
tools/include/uapi/linux/bpf.h