tc: bpf: add checksum helpers
Commit 608cd71a9c
("tc: bpf: generalize pedit action") has added the
possibility to mangle packet data to BPF programs in the tc pipeline.
This patch adds two helpers bpf_l3_csum_replace() and bpf_l4_csum_replace()
for fixing up the protocol checksums after the packet mangling.
It also adds 'flags' argument to bpf_skb_store_bytes() helper to avoid
unnecessary checksum recomputations when BPF programs adjusting l3/l4
checksums and documents all three helpers in uapi header.
Moreover, a sample program is added to show how BPF programs can make use
of the mangle and csum helpers.
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
5888b93b75
commit
91bc4822c3
@@ -168,7 +168,43 @@ enum bpf_func_id {
|
||||
BPF_FUNC_map_delete_elem, /* int map_delete_elem(&map, &key) */
|
||||
BPF_FUNC_get_prandom_u32, /* u32 prandom_u32(void) */
|
||||
BPF_FUNC_get_smp_processor_id, /* u32 raw_smp_processor_id(void) */
|
||||
BPF_FUNC_skb_store_bytes, /* int skb_store_bytes(skb, offset, from, len) */
|
||||
|
||||
/**
|
||||
* skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet
|
||||
* @skb: pointer to skb
|
||||
* @offset: offset within packet from skb->data
|
||||
* @from: pointer where to copy bytes from
|
||||
* @len: number of bytes to store into packet
|
||||
* @flags: bit 0 - if true, recompute skb->csum
|
||||
* other bits - reserved
|
||||
* Return: 0 on success
|
||||
*/
|
||||
BPF_FUNC_skb_store_bytes,
|
||||
|
||||
/**
|
||||
* l3_csum_replace(skb, offset, from, to, flags) - recompute IP checksum
|
||||
* @skb: pointer to skb
|
||||
* @offset: offset within packet where IP checksum is located
|
||||
* @from: old value of header field
|
||||
* @to: new value of header field
|
||||
* @flags: bits 0-3 - size of header field
|
||||
* other bits - reserved
|
||||
* Return: 0 on success
|
||||
*/
|
||||
BPF_FUNC_l3_csum_replace,
|
||||
|
||||
/**
|
||||
* l4_csum_replace(skb, offset, from, to, flags) - recompute TCP/UDP checksum
|
||||
* @skb: pointer to skb
|
||||
* @offset: offset within packet where TCP/UDP checksum is located
|
||||
* @from: old value of header field
|
||||
* @to: new value of header field
|
||||
* @flags: bits 0-3 - size of header field
|
||||
* bit 4 - is pseudo header
|
||||
* other bits - reserved
|
||||
* Return: 0 on success
|
||||
*/
|
||||
BPF_FUNC_l4_csum_replace,
|
||||
__BPF_FUNC_MAX_ID,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user