Skip to content

Commit 8d07a4c

Browse files
add xdp struct to args
Signed-off-by: varun-r-mallya <[email protected]>
1 parent 1207730 commit 8d07a4c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

examples/xdp_pass.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from pythonbpf import bpf, map, section, bpfglobal, compile
1+
from pythonbpf import bpf, map, section, bpfglobal, compile, compile_to_ir
22
from pythonbpf.helper import XDP_PASS
33
from pythonbpf.maps import HashMap
4-
4+
from vmlinux import struct_xdp_md
55
from ctypes import c_void_p, c_int64
66

77
# Instructions to how to run this program
@@ -20,7 +20,7 @@ def count() -> HashMap:
2020

2121
@bpf
2222
@section("xdp")
23-
def hello_world(ctx: c_void_p) -> c_int64:
23+
def hello_world(ctx: struct_xdp_md) -> c_int64:
2424
key = 0
2525
one = 1
2626
prev = count().lookup(key)
@@ -40,5 +40,5 @@ def hello_world(ctx: c_void_p) -> c_int64:
4040
def LICENSE() -> str:
4141
return "GPL"
4242

43-
43+
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
4444
compile()

tests/c-form/ex2.bpf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#include <linux/bpf.h>
1+
#include "vmlinux.h"
22
#include <bpf/bpf_helpers.h>
3-
#define u64 unsigned long long
4-
#define u32 unsigned int
3+
#include <bpf/bpf_endian.h>
54

65
SEC("xdp")
76
int hello(struct xdp_md *ctx) {
8-
bpf_printk("Hello, World!\n");
7+
// ctx.
8+
bpf_printk("Hello, World! %ud \n", ctx->data);
99
return XDP_PASS;
1010
}
1111

0 commit comments

Comments
 (0)