From 5ba29db3624cc6d5af7637e22f2e551d46cc771c Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Thu, 27 Nov 2025 23:44:44 +0530 Subject: [PATCH] fix the c form of the xdp program --- tests/c-form/xdp_test.bpf.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/c-form/xdp_test.bpf.c b/tests/c-form/xdp_test.bpf.c index e553c37..c039e11 100644 --- a/tests/c-form/xdp_test.bpf.c +++ b/tests/c-form/xdp_test.bpf.c @@ -1,19 +1,18 @@ -#include "vmlinux.h" -#include #include #include #include +#include struct fake_iphdr { - unsigned short useless; - unsigned short tot_len; - unsigned short id; - unsigned short frag_off; - unsigned char ttl; - unsigned char protocol; - unsigned short check; - unsigned int saddr; - unsigned int daddr; + unsigned short useless; + unsigned short tot_len; + unsigned short id; + unsigned short frag_off; + unsigned char ttl; + unsigned char protocol; + unsigned short check; + unsigned int saddr; + unsigned int daddr; }; SEC("xdp") @@ -21,16 +20,14 @@ int xdp_prog(struct xdp_md *ctx) { unsigned long data = ctx->data; unsigned long data_end = ctx->data_end; - if (data + sizeof(struct ethhdr) + sizeof(struct fake_iphdr) <= data_end) { - struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr); - - bpf_printk("%d", iph->saddr); - - return XDP_PASS; - } else { + if (data + sizeof(struct ethhdr) + sizeof(struct fake_iphdr) > data_end) { return XDP_ABORTED; } - struct task_struct * a = btf_bpf_get_current_task_btf(); + struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr); + + bpf_printk("%d", iph->saddr); + + return XDP_PASS; } char _license[] SEC("license") = "GPL";