mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
Every program on the selftest audit's Tier 1 and Tier 2 lists that the compiler can express today: xdp_dummy, priv_prog, test_xdp_link, xdp_tx, tc_dummy, test_tc_bpf, cgroup_mprog, cgroup_skb_direct_packet_access, test_signed_loader, test_signed_loader_data, test_netfilter_link_attach, kprobe_multi_empty, uprobe_multi_bench, uprobe_multi_usdt, test_link_pinning and test_xdp_devmap_helpers. Fifteen pass at every level, bringing tc, tcx, cgroup/getsockopt, cgroup_skb, socket, netfilter, kprobe.multi, uprobe.multi, usdt and tp_btf program types under test for the first time. test_xdp_devmap_helpers is a negative fixture upstream: reading egress_ifindex is only legal with expected_attach_type = BPF_XDP_DEVMAP and the driver asserts the plain load fails. It is a strict verifier-level xfail here for the same reason, until expected_attach_type can be expressed. The porting notes record the batch and why each remaining program on the two lists is still out of reach. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
59 lines
1.1 KiB
Python
59 lines
1.1 KiB
Python
# Ported from Linux tools/testing/selftests/bpf/progs/test_link_pinning.c
|
|
#
|
|
# Two programs, one raw_tp and one tp_btf on the same tracepoint, each
|
|
# copying a global set by userspace into a global read by userspace.
|
|
# Upstream pins the link, closes every fd, then checks the program still
|
|
# fires by bumping `in` and watching `out` follow:
|
|
#
|
|
# int in = 0;
|
|
# int out = 0;
|
|
#
|
|
# SEC("raw_tp/sys_enter")
|
|
# int raw_tp_prog(const void *ctx)
|
|
# {
|
|
# out = in;
|
|
# return 0;
|
|
# }
|
|
#
|
|
# `in` is renamed `in_val` because `in` is a Python keyword.
|
|
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from ctypes import c_void_p, c_int64, c_int32
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def in_val() -> c_int32:
|
|
return c_int32(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def out() -> c_int32:
|
|
return c_int32(0)
|
|
|
|
|
|
@bpf
|
|
@section("raw_tp/sys_enter")
|
|
def raw_tp_prog(ctx: c_void_p) -> c_int64:
|
|
global out
|
|
out = in_val
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@section("tp_btf/sys_enter")
|
|
def tp_btf_prog(ctx: c_void_p) -> c_int64:
|
|
global out
|
|
out = in_val
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|