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>
42 lines
893 B
Python
42 lines
893 B
Python
# Counts packets in a one-entry map and lets every packet through. It used to
|
|
# be an xfail, but the only thing failing was the old `count().lookup(...)`
|
|
# spelling of a map call; `count.lookup(...)` is the current one.
|
|
|
|
from pythonbpf import bpf, map, section, bpfglobal, compile
|
|
from pythonbpf.maps import HashMap
|
|
from vmlinux import XDP_PASS
|
|
from vmlinux import struct_xdp_md
|
|
from ctypes import c_int64
|
|
|
|
|
|
@bpf
|
|
@map
|
|
def count() -> HashMap:
|
|
return HashMap(key=c_int64, value=c_int64, max_entries=1)
|
|
|
|
|
|
@bpf
|
|
@section("xdp")
|
|
def hello_world(ctx: struct_xdp_md) -> c_int64:
|
|
key = 0
|
|
one = 1
|
|
prev = count.lookup(key)
|
|
if prev:
|
|
prevval = prev + 1
|
|
print(f"count: {prevval}")
|
|
count.update(key, prevval)
|
|
return XDP_PASS
|
|
else:
|
|
count.update(key, one)
|
|
|
|
return XDP_PASS
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|