mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
format chore
This commit is contained in:
@ -117,7 +117,9 @@ def _allocate_for_call(
|
|||||||
if len(rval.args) == 0:
|
if len(rval.args) == 0:
|
||||||
# Zero-arg constructor: allocate the struct itself
|
# Zero-arg constructor: allocate the struct itself
|
||||||
var = builder.alloca(struct_info.ir_type, name=var_name)
|
var = builder.alloca(struct_info.ir_type, name=var_name)
|
||||||
local_sym_tab[var_name] = LocalSymbol(var, struct_info.ir_type, call_type)
|
local_sym_tab[var_name] = LocalSymbol(
|
||||||
|
var, struct_info.ir_type, call_type
|
||||||
|
)
|
||||||
logger.info(f"Pre-allocated {var_name} for struct {call_type}")
|
logger.info(f"Pre-allocated {var_name} for struct {call_type}")
|
||||||
else:
|
else:
|
||||||
# Pointer cast: allocate as pointer to struct
|
# Pointer cast: allocate as pointer to struct
|
||||||
@ -125,7 +127,9 @@ def _allocate_for_call(
|
|||||||
var = builder.alloca(ptr_type, name=var_name)
|
var = builder.alloca(ptr_type, name=var_name)
|
||||||
var.align = 8
|
var.align = 8
|
||||||
local_sym_tab[var_name] = LocalSymbol(var, ptr_type, call_type)
|
local_sym_tab[var_name] = LocalSymbol(var, ptr_type, call_type)
|
||||||
logger.info(f"Pre-allocated {var_name} for struct pointer cast to {call_type}")
|
logger.info(
|
||||||
|
f"Pre-allocated {var_name} for struct pointer cast to {call_type}"
|
||||||
|
)
|
||||||
|
|
||||||
elif VmlinuxHandlerRegistry.is_vmlinux_struct(call_type):
|
elif VmlinuxHandlerRegistry.is_vmlinux_struct(call_type):
|
||||||
# When calling struct_name(pointer), we're doing a cast, not construction
|
# When calling struct_name(pointer), we're doing a cast, not construction
|
||||||
|
|||||||
@ -682,13 +682,13 @@ def _handle_vmlinux_cast(
|
|||||||
|
|
||||||
|
|
||||||
def _handle_user_defined_struct_cast(
|
def _handle_user_defined_struct_cast(
|
||||||
func,
|
func,
|
||||||
module,
|
module,
|
||||||
builder,
|
builder,
|
||||||
expr,
|
expr,
|
||||||
local_sym_tab,
|
local_sym_tab,
|
||||||
map_sym_tab,
|
map_sym_tab,
|
||||||
structs_sym_tab,
|
structs_sym_tab,
|
||||||
):
|
):
|
||||||
"""Handle user-defined struct cast expressions like iphdr(nh).
|
"""Handle user-defined struct cast expressions like iphdr(nh).
|
||||||
|
|
||||||
@ -744,6 +744,7 @@ def _handle_user_defined_struct_cast(
|
|||||||
|
|
||||||
return casted_ptr, struct_name
|
return casted_ptr, struct_name
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Expression Dispatcher
|
# Expression Dispatcher
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from vmlinux import (
|
|||||||
from pythonbpf import bpf, section, bpfglobal, compile, compile_to_ir, struct
|
from pythonbpf import bpf, section, bpfglobal, compile, compile_to_ir, struct
|
||||||
from ctypes import c_int64, c_ubyte, c_ushort, c_uint32
|
from ctypes import c_int64, c_ubyte, c_ushort, c_uint32
|
||||||
|
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@struct
|
@struct
|
||||||
class iphdr:
|
class iphdr:
|
||||||
@ -19,6 +20,7 @@ class iphdr:
|
|||||||
saddr: c_uint32
|
saddr: c_uint32
|
||||||
daddr: c_uint32
|
daddr: c_uint32
|
||||||
|
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@section("xdp")
|
@section("xdp")
|
||||||
def ip_detector(ctx: struct_xdp_md) -> c_int64:
|
def ip_detector(ctx: struct_xdp_md) -> c_int64:
|
||||||
|
|||||||
Reference in New Issue
Block a user