Commit 041c1dc9 authored by Vadim Fedorenko's avatar Vadim Fedorenko Committed by Daniel Borkmann

selftests/bpf: Validate CHECKSUM_COMPLETE option

Adjust skb program test to run with checksum validation.
Signed-off-by: default avatarVadim Fedorenko <vadfed@meta.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240606145851.229116-2-vadfed@meta.com
parent a3cfe84c
......@@ -11,6 +11,7 @@ static int sanity_run(struct bpf_program *prog)
.data_in = &pkt_v4,
.data_size_in = sizeof(pkt_v4),
.repeat = 1,
.flags = BPF_F_TEST_SKB_CHECKSUM_COMPLETE,
);
prog_fd = bpf_program__fd(prog);
......
......@@ -33,6 +33,8 @@ int main_prog(struct __sk_buff *skb)
struct iphdr *ip = NULL;
struct tcphdr *tcp;
__u8 proto = 0;
int urg_ptr;
u32 offset;
if (!(ip = get_iphdr(skb)))
goto out;
......@@ -48,7 +50,14 @@ int main_prog(struct __sk_buff *skb)
if (!tcp)
goto out;
return tcp->urg_ptr;
urg_ptr = tcp->urg_ptr;
/* Checksum validation part */
proto++;
offset = sizeof(struct ethhdr) + offsetof(struct iphdr, protocol);
bpf_skb_store_bytes(skb, offset, &proto, sizeof(proto), BPF_F_RECOMPUTE_CSUM);
return urg_ptr;
out:
return -1;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment