mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
failing_tests/vmlinux/assignment_handling.py pinned exactly this gap
("This gives an error, but / this does not"); it moves to the passing
suite and its xfail entry goes. enum_to_local.py adds the C shape
`int act = XDP_PASS; if (...) act = XDP_DROP; return act;`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
27 lines
689 B
Python
27 lines
689 B
Python
# A local initialised from a vmlinux enum constant, the C shape
|
|
# `int act = XDP_PASS;`. Reads of a bare name resolve local, then BPF global,
|
|
# then vmlinux enum everywhere else; the allocation pass used to stop one step
|
|
# short for this shape and reject it, while `act = XDP_PASS + 0` compiled.
|
|
from ctypes import c_int64
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from vmlinux import struct_xdp_md
|
|
from vmlinux import XDP_PASS, XDP_DROP
|
|
|
|
|
|
@bpf
|
|
@section("xdp")
|
|
def prog(ctx: struct_xdp_md) -> c_int64:
|
|
act = XDP_PASS
|
|
if ctx.data_end - ctx.data > 1500:
|
|
act = XDP_DROP
|
|
return c_int64(act)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|