Skip to content

Commit 5ba29db

Browse files
fix the c form of the xdp program
1 parent de8c486 commit 5ba29db

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

tests/c-form/xdp_test.bpf.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
1-
#include "vmlinux.h"
2-
#include <bpf/bpf_helpers.h>
31
#include <linux/bpf.h>
42
#include <linux/if_ether.h>
53
#include <linux/ip.h>
4+
#include <bpf/bpf_helpers.h>
65

76
struct fake_iphdr {
8-
unsigned short useless;
9-
unsigned short tot_len;
10-
unsigned short id;
11-
unsigned short frag_off;
12-
unsigned char ttl;
13-
unsigned char protocol;
14-
unsigned short check;
15-
unsigned int saddr;
16-
unsigned int daddr;
7+
unsigned short useless;
8+
unsigned short tot_len;
9+
unsigned short id;
10+
unsigned short frag_off;
11+
unsigned char ttl;
12+
unsigned char protocol;
13+
unsigned short check;
14+
unsigned int saddr;
15+
unsigned int daddr;
1716
};
1817

1918
SEC("xdp")
2019
int xdp_prog(struct xdp_md *ctx) {
2120
unsigned long data = ctx->data;
2221
unsigned long data_end = ctx->data_end;
2322

24-
if (data + sizeof(struct ethhdr) + sizeof(struct fake_iphdr) <= data_end) {
25-
struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr);
26-
27-
bpf_printk("%d", iph->saddr);
28-
29-
return XDP_PASS;
30-
} else {
23+
if (data + sizeof(struct ethhdr) + sizeof(struct fake_iphdr) > data_end) {
3124
return XDP_ABORTED;
3225
}
33-
struct task_struct * a = btf_bpf_get_current_task_btf();
26+
struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr);
27+
28+
bpf_printk("%d", iph->saddr);
29+
30+
return XDP_PASS;
3431
}
3532

3633
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)