Skip to content

Commit 3078d42

Browse files
committed
Add typed scratch space support to the bpf_skb_store_bytes helper
1 parent 7d29790 commit 3078d42

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,11 @@ def bpf_get_current_uid_gid_emitter(
567567
return pid, ir.IntType(64)
568568

569569

570-
@HelperHandlerRegistry.register("skb_store_bytes")
570+
@HelperHandlerRegistry.register(
571+
"skb_store_bytes",
572+
param_types=[ir.IntType(32), ir.PointerType(), ir.IntType(32), ir.IntType(64)],
573+
return_type=ir.IntType(64),
574+
)
571575
def bpf_skb_store_bytes_emitter(
572576
call,
573577
map_ptr,
@@ -583,6 +587,14 @@ def bpf_skb_store_bytes_emitter(
583587
Expected call signature: skb_store_bytes(skb, offset, from, len, flags)
584588
"""
585589

590+
args_signature = [
591+
ir.PointerType(), # skb pointer
592+
ir.IntType(32), # offset
593+
ir.PointerType(), # from
594+
ir.IntType(32), # len
595+
ir.IntType(64), # flags
596+
]
597+
586598
if len(call.args) not in (3, 4):
587599
raise ValueError(
588600
f"skb_store_bytes expects 3 or 4 args (offset, from, len, flags), got {len(call.args)}"
@@ -596,10 +608,18 @@ def bpf_skb_store_bytes_emitter(
596608
builder,
597609
local_sym_tab,
598610
map_sym_tab,
611+
args_signature[1],
599612
struct_sym_tab,
600613
)
601614
from_ptr = get_or_create_ptr_from_arg(
602-
func, module, call.args[1], builder, local_sym_tab, map_sym_tab, struct_sym_tab
615+
func,
616+
module,
617+
call.args[1],
618+
builder,
619+
local_sym_tab,
620+
map_sym_tab,
621+
args_signature[2],
622+
struct_sym_tab,
603623
)
604624
len_val = get_int_value_from_arg(
605625
call.args[2],
@@ -608,6 +628,7 @@ def bpf_skb_store_bytes_emitter(
608628
builder,
609629
local_sym_tab,
610630
map_sym_tab,
631+
args_signature[3],
611632
struct_sym_tab,
612633
)
613634
if len(call.args) == 4:
@@ -617,13 +638,7 @@ def bpf_skb_store_bytes_emitter(
617638
flags = ir.Constant(ir.IntType(64), flags_val)
618639
fn_type = ir.FunctionType(
619640
ir.IntType(64),
620-
[
621-
ir.PointerType(), # skb
622-
ir.IntType(32), # offset
623-
ir.PointerType(), # from
624-
ir.IntType(32), # len
625-
ir.IntType(64), # flags
626-
],
641+
args_signature,
627642
var_arg=False,
628643
)
629644
fn_ptr = builder.inttoptr(

0 commit comments

Comments
 (0)