Skip to content

Commit 77901ac

Browse files
fix xdp test c form test
Signed-off-by: varun-r-mallya <[email protected]>
1 parent 0616a2f commit 77901ac

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

BCC-Examples/disksnoop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from vmlinux import struct_request, struct_pt_regs
2-
from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile, map
2+
from pythonbpf import bpf, section, bpfglobal, compile, map
33
from pythonbpf.helper import ktime
44
from pythonbpf.maps import HashMap
55
from ctypes import c_int64, c_uint64, c_int32
@@ -54,4 +54,5 @@ def trace_start(ctx1: struct_pt_regs) -> c_int32:
5454
def LICENSE() -> str:
5555
return "GPL"
5656

57+
5758
compile()

tests/c-form/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BPF_CLANG := clang
2-
CFLAGS := -emit-llvm -target bpf -c
2+
CFLAGS := -emit-llvm -target bpf -c -D__TARGET_ARCH_x86
33

44
SRC := $(wildcard *.bpf.c)
55
LL := $(SRC:.bpf.c=.bpf.ll)
@@ -10,7 +10,7 @@ LL0 := $(SRC:.bpf.c=.bpf.o0.ll)
1010
all: $(LL) $(OBJ) $(LL0)
1111

1212
%.bpf.o: %.bpf.c
13-
$(BPF_CLANG) -O2 -g -target bpf -c $< -o $@
13+
$(BPF_CLANG) -O2 -D__TARGET_ARCH_x86 -g -target bpf -c $< -o $@
1414

1515
%.bpf.ll: %.bpf.c
1616
$(BPF_CLANG) $(CFLAGS) -O2 -g -S $< -o $@

tests/c-form/xdp_test.bpf.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
#include <linux/bpf.h>
2-
#include <linux/if_ether.h>
3-
#include <linux/ip.h>
1+
#include "vmlinux.h"
42
#include <bpf/bpf_helpers.h>
53

64
struct fake_iphdr {
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;
5+
unsigned short useless;
6+
unsigned short tot_len;
7+
unsigned short id;
8+
unsigned short frag_off;
9+
unsigned char ttl;
10+
unsigned char protocol;
11+
unsigned short check;
12+
unsigned int saddr;
13+
unsigned int daddr;
1614
};
1715

1816
SEC("xdp")
@@ -25,9 +23,9 @@ int xdp_prog(struct xdp_md *ctx) {
2523
}
2624
struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr);
2725

28-
bpf_printk("%d", iph->saddr);
26+
bpf_printk("%d", iph->saddr);
2927

30-
return XDP_PASS;
28+
return XDP_PASS;
3129
}
3230

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

0 commit comments

Comments
 (0)