summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/skb_pkt_end.c
diff options
context:
space:
mode:
authorVadim Fedorenko <vadfed@meta.com>2024-06-06 16:58:51 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2024-06-13 14:29:53 +0200
commit041c1dc988fdffd5eb0c13f1ce5d1b3b0125f208 (patch)
tree81b6698d112bb09cd4ee9a04c79a397d02110abd /tools/testing/selftests/bpf/progs/skb_pkt_end.c
parentbpf: Add CHECKSUM_COMPLETE to bpf test progs (diff)
downloadlinux-041c1dc988fdffd5eb0c13f1ce5d1b3b0125f208.tar.xz
linux-041c1dc988fdffd5eb0c13f1ce5d1b3b0125f208.zip
selftests/bpf: Validate CHECKSUM_COMPLETE option
Adjust skb program test to run with checksum validation. Signed-off-by: Vadim Fedorenko <vadfed@meta.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20240606145851.229116-2-vadfed@meta.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/skb_pkt_end.c')
-rw-r--r--tools/testing/selftests/bpf/progs/skb_pkt_end.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/progs/skb_pkt_end.c b/tools/testing/selftests/bpf/progs/skb_pkt_end.c
index db4abd2682fc..3bb4451524a1 100644
--- a/tools/testing/selftests/bpf/progs/skb_pkt_end.c
+++ b/tools/testing/selftests/bpf/progs/skb_pkt_end.c
@@ -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;
}