From 8d07a4cd0513fa68a0ae4d6f09967930e7ded7a7 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Wed, 8 Oct 2025 11:40:12 +0530 Subject: [PATCH] add xdp struct to args Signed-off-by: varun-r-mallya --- examples/xdp_pass.py | 8 ++++---- tests/c-form/ex2.bpf.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/xdp_pass.py b/examples/xdp_pass.py index 17de6c9..bc77ad0 100644 --- a/examples/xdp_pass.py +++ b/examples/xdp_pass.py @@ -1,7 +1,7 @@ -from pythonbpf import bpf, map, section, bpfglobal, compile +from pythonbpf import bpf, map, section, bpfglobal, compile, compile_to_ir from pythonbpf.helper import XDP_PASS from pythonbpf.maps import HashMap - +from vmlinux import struct_xdp_md from ctypes import c_void_p, c_int64 # Instructions to how to run this program @@ -20,7 +20,7 @@ def count() -> HashMap: @bpf @section("xdp") -def hello_world(ctx: c_void_p) -> c_int64: +def hello_world(ctx: struct_xdp_md) -> c_int64: key = 0 one = 1 prev = count().lookup(key) @@ -40,5 +40,5 @@ def hello_world(ctx: c_void_p) -> c_int64: def LICENSE() -> str: return "GPL" - +compile_to_ir("xdp_pass.py", "xdp_pass.ll") compile() diff --git a/tests/c-form/ex2.bpf.c b/tests/c-form/ex2.bpf.c index 89a4428..9f6e63a 100644 --- a/tests/c-form/ex2.bpf.c +++ b/tests/c-form/ex2.bpf.c @@ -1,11 +1,11 @@ -#include +#include "vmlinux.h" #include -#define u64 unsigned long long -#define u32 unsigned int +#include SEC("xdp") int hello(struct xdp_md *ctx) { - bpf_printk("Hello, World!\n"); + // ctx. + bpf_printk("Hello, World! %ud \n", ctx->data); return XDP_PASS; }