Skip to content

Commit ad6adb1

Browse files
committed
x
1 parent 3a984dd commit ad6adb1

18 files changed

Lines changed: 21 additions & 76 deletions

File tree

‎docs/getting-started/quickstart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def trace_open(ctx: c_void_p) -> c_int64:
188188
For network packet processing:
189189

190190
```python
191-
from pythonbpf.helper import XDP_PASS
191+
from vmlinux import XDP_PASS
192192

193193
@section("xdp")
194194
def xdp_pass(ctx: c_void_p) -> c_int64:

‎docs/user-guide/decorators.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def trace_open_return(ctx):
108108
For network packet processing at the earliest point:
109109

110110
```python
111-
from pythonbpf.helper import XDP_PASS
111+
from vmlinux import XDP_PASS
112112
from ctypes import c_void_p, c_int64
113113

114114
@section("xdp")

‎docs/user-guide/structs.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ class MyStruct:
290290
```python
291291
from pythonbpf import bpf, struct, map, section
292292
from pythonbpf.maps import RingBuffer
293-
from pythonbpf.helper import ktime, XDP_PASS
293+
from pythonbpf.helper import ktime
294+
from vmlinux import XDP_PASS
294295
from ctypes import c_void_p, c_int64, c_uint8, c_uint16, c_uint32, c_uint64
295296

296297
@bpf

‎examples/xdp_pass.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pythonbpf import bpf, map, section, bpfglobal, compile, compile_to_ir
2-
from pythonbpf.helper import XDP_PASS
2+
from vmlinux import XDP_PASS
33
from pythonbpf.maps import HashMap
44
from ctypes import c_int64, c_void_p
55

‎pythonbpf/functions/functions_pass.py‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
LocalSymbol,
3131
)
3232
from .function_debug_info import generate_function_debug_info
33-
from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name
33+
from .return_utils import handle_none_return
3434
from .function_metadata import get_probe_string, is_global_function, infer_return_type
3535

3636

@@ -341,20 +341,6 @@ def handle_return(
341341
logger.info(f"Handling return statement: {ast.dump(stmt)}")
342342
if stmt.value is None:
343343
return handle_none_return(builder)
344-
elif (
345-
isinstance(stmt.value, ast.Name)
346-
and is_xdp_name(stmt.value.id)
347-
and stmt.value.id not in local_sym_tab
348-
and (
349-
compilation_context is None
350-
or stmt.value.id not in compilation_context.bpf_globals
351-
)
352-
):
353-
# The XDP fast path resolves names like XDP_PASS from the helper
354-
# constant table, but only as a fallback: a local or @bpfglobal of the
355-
# same name shadows it, mirroring C (a local shadows an enum constant)
356-
# and the resolution order everywhere else in the compiler.
357-
return handle_xdp_return(stmt, builder, ret_type)
358344
else:
359345
# Fallback for now if ctx not passed, but caller should pass it
360346
if compilation_context is None:
Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,12 @@
11
import logging
2-
import ast
32

43
from llvmlite import ir
54

65
logger: logging.Logger = logging.getLogger(__name__)
76

8-
XDP_ACTIONS = {
9-
"XDP_ABORTED": 0,
10-
"XDP_DROP": 1,
11-
"XDP_PASS": 2,
12-
"XDP_TX": 3,
13-
"XDP_REDIRECT": 4,
14-
}
15-
167

178
def handle_none_return(builder) -> bool:
189
"""Handle return or return None -> returns 0."""
1910
builder.ret(ir.Constant(ir.IntType(64), 0))
2011
logger.debug("Generated default return: 0")
2112
return True
22-
23-
24-
def is_xdp_name(name: str) -> bool:
25-
"""Check if a name is an XDP action"""
26-
return name in XDP_ACTIONS
27-
28-
29-
def handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
30-
"""Handle XDP returns"""
31-
if not isinstance(stmt.value, ast.Name):
32-
return False
33-
34-
action_name = stmt.value.id
35-
36-
if action_name not in XDP_ACTIONS:
37-
raise ValueError(
38-
f"Unknown XDP action: {action_name}. Available: {XDP_ACTIONS.keys()}"
39-
)
40-
41-
value = XDP_ACTIONS[action_name]
42-
builder.ret(ir.Constant(ret_type, value))
43-
logger.debug(f"Generated XDP action return: {action_name} = {value}")
44-
return True

‎pythonbpf/helper/__init__.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
skb_store_bytes,
1919
get_current_cgroup_id,
2020
get_stack,
21-
XDP_DROP,
22-
XDP_PASS,
2321
)
2422

2523

@@ -86,6 +84,4 @@ def helper_call_handler(call, compilation_context, builder, func, local_sym_tab)
8684
"uid",
8785
"skb_store_bytes",
8886
"get_stack",
89-
"XDP_DROP",
90-
"XDP_PASS",
9187
]

‎pythonbpf/helper/helpers.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,3 @@ def get_stack(buf, flags=0):
6060
def get_current_cgroup_id():
6161
"""Get the current cgroup ID"""
6262
return ctypes.c_int64(0)
63-
64-
65-
XDP_ABORTED = ctypes.c_int64(0)
66-
XDP_DROP = ctypes.c_int64(1)
67-
XDP_PASS = ctypes.c_int64(2)
68-
XDP_TX = ctypes.c_int64(3)
69-
XDP_REDIRECT = ctypes.c_int64(4)

tests/failing_tests/direct_assign.py renamed to tests/failing_tests/vmlinux/direct_assign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pythonbpf import bpf, map, section, bpfglobal, compile
2-
from pythonbpf.helper import XDP_PASS
2+
from vmlinux import XDP_PASS
33
from pythonbpf.maps import HashMap
44

55
from ctypes import c_void_p, c_int64
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pythonbpf import bpf, map, section, bpfglobal, compile
2-
from pythonbpf.helper import XDP_PASS
2+
from vmlinux import XDP_PASS
33
from pythonbpf.maps import HashMap
44

55
from ctypes import c_void_p, c_int64

0 commit comments

Comments
 (0)