mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add xdp struct to args
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
@ -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.helper import XDP_PASS
|
||||||
from pythonbpf.maps import HashMap
|
from pythonbpf.maps import HashMap
|
||||||
|
from vmlinux import struct_xdp_md
|
||||||
from ctypes import c_void_p, c_int64
|
from ctypes import c_void_p, c_int64
|
||||||
|
|
||||||
# Instructions to how to run this program
|
# Instructions to how to run this program
|
||||||
@ -20,7 +20,7 @@ def count() -> HashMap:
|
|||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@section("xdp")
|
@section("xdp")
|
||||||
def hello_world(ctx: c_void_p) -> c_int64:
|
def hello_world(ctx: struct_xdp_md) -> c_int64:
|
||||||
key = 0
|
key = 0
|
||||||
one = 1
|
one = 1
|
||||||
prev = count().lookup(key)
|
prev = count().lookup(key)
|
||||||
@ -40,5 +40,5 @@ def hello_world(ctx: c_void_p) -> c_int64:
|
|||||||
def LICENSE() -> str:
|
def LICENSE() -> str:
|
||||||
return "GPL"
|
return "GPL"
|
||||||
|
|
||||||
|
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
|
||||||
compile()
|
compile()
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
#include <linux/bpf.h>
|
#include "vmlinux.h"
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#define u64 unsigned long long
|
#include <bpf/bpf_endian.h>
|
||||||
#define u32 unsigned int
|
|
||||||
|
|
||||||
SEC("xdp")
|
SEC("xdp")
|
||||||
int hello(struct xdp_md *ctx) {
|
int hello(struct xdp_md *ctx) {
|
||||||
bpf_printk("Hello, World!\n");
|
// ctx.
|
||||||
|
bpf_printk("Hello, World! %ud \n", ctx->data);
|
||||||
return XDP_PASS;
|
return XDP_PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user