Skip to content

Commit e6e2a69

Browse files
committed
Add _is_xdp_name
1 parent e4e9271 commit e6e2a69

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pythonbpf/functions/functions_pass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pythonbpf.binary_ops import handle_binary_op
1010
from pythonbpf.expr_pass import eval_expr, handle_expr
1111

12-
from .return_utils import _handle_none_return, _handle_xdp_return
12+
from .return_utils import _handle_none_return, _handle_xdp_return, _is_xdp_name
1313

1414

1515
logger = logging.getLogger(__name__)
@@ -357,7 +357,7 @@ def handle_return(builder, stmt, local_sym_tab, ret_type):
357357
logger.info(f"Handling return statement: {ast.dump(stmt)}")
358358
if stmt.value is None:
359359
return _handle_none_return(builder)
360-
elif isinstance(stmt.value, ast.Name):
360+
elif isinstance(stmt.value, ast.Name) and _is_xdp_name(stmt.value.id):
361361
return _handle_xdp_return(stmt, builder, ret_type)
362362
elif (
363363
isinstance(stmt.value, ast.Call)

pythonbpf/functions/return_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def _handle_wrapped_return(stmt: ast.Return, builder, ret_type, local_sym_tab) -
111111
raise ValueError(f"Unsupported return argument type: {type(arg).__name__}")
112112

113113

114+
def _is_xdp_name(name: str) -> bool:
115+
"""Check if a name is an XDP action"""
116+
return name in XDP_ACTIONS
117+
118+
114119
def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
115120
"""Handle XDP returns"""
116121
if not isinstance(stmt.value, ast.Name):

0 commit comments

Comments
 (0)