mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
retype, helper_cond, direct_assign and globals had no xfail entry and have been passing at every level; their NOTE headers describe limits that have since been lifted, so they are rewritten. xdp_pass was an xfail only because it used the old count().lookup() spelling of a map call; in the current syntax it compiles. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
38 lines
771 B
Python
38 lines
771 B
Python
from pythonbpf import bpf, map, section, bpfglobal, compile
|
|
from vmlinux import XDP_PASS
|
|
from pythonbpf.maps import HashMap
|
|
|
|
from ctypes import c_void_p, c_int64
|
|
|
|
# An expression (`prev + 1`) passed straight to map.update(): it is evaluated
|
|
# into a scratch slot and the helper gets that slot's address. This was once
|
|
# refused for want of a slot allocated up front, and now works.
|
|
|
|
|
|
@bpf
|
|
@map
|
|
def count() -> HashMap:
|
|
return HashMap(key=c_int64, value=c_int64, max_entries=1)
|
|
|
|
|
|
@bpf
|
|
@section("xdp")
|
|
def hello_world(ctx: c_void_p) -> c_int64:
|
|
prev = count.lookup(0)
|
|
if prev:
|
|
count.update(0, prev + 1)
|
|
return XDP_PASS
|
|
else:
|
|
count.update(0, 1)
|
|
|
|
return XDP_PASS
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|