Skip to content

Commit 5e37178

Browse files
committed
Fix the number of args for skb_store_bytes by making the first arg implicit
1 parent 67c9d9b commit 5e37178

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,14 @@ def bpf_skb_store_bytes_emitter(
583583
Expected call signature: skb_store_bytes(skb, offset, from, len, flags)
584584
"""
585585

586-
if len(call.args) not in (4, 5):
586+
if len(call.args) not in (3, 4):
587587
raise ValueError(
588-
f"skb_store_bytes expects 4 or 5 args (skb, offset, from, len, flags), got {len(call.args)}"
588+
f"skb_store_bytes expects 3 or 4 args (offset, from, len, flags), got {len(call.args)}"
589589
)
590590

591-
skb_ptr = get_or_create_ptr_from_arg(
592-
func, module, call.args[0], builder, local_sym_tab, map_sym_tab, struct_sym_tab
593-
)
591+
skb_ptr = func.args[0] # First argument to the function is skb
594592
offset_val = get_int_value_from_arg(
595-
call.args[1],
593+
call.args[0],
596594
func,
597595
module,
598596
builder,
@@ -601,21 +599,22 @@ def bpf_skb_store_bytes_emitter(
601599
struct_sym_tab,
602600
)
603601
from_ptr = get_or_create_ptr_from_arg(
604-
func, module, call.args[2], builder, local_sym_tab, map_sym_tab, struct_sym_tab
602+
func, module, call.args[1], builder, local_sym_tab, map_sym_tab, struct_sym_tab
605603
)
606604
len_val = get_int_value_from_arg(
607-
call.args[3],
605+
call.args[2],
608606
func,
609607
module,
610608
builder,
611609
local_sym_tab,
612610
map_sym_tab,
613611
struct_sym_tab,
614612
)
615-
if len(call.args) == 5:
616-
flags_val = get_flags_val(call.args[4], builder, local_sym_tab)
613+
if len(call.args) == 4:
614+
flags_val = get_flags_val(call.args[3], builder, local_sym_tab)
617615
else:
618-
flags_val = ir.Constant(ir.IntType(64), 0)
616+
flags_val = 0
617+
flags = ir.Constant(ir.IntType(64), flags_val)
619618
fn_type = ir.FunctionType(
620619
ir.IntType(64),
621620
[
@@ -638,7 +637,7 @@ def bpf_skb_store_bytes_emitter(
638637
builder.trunc(offset_val, ir.IntType(32)),
639638
builder.bitcast(from_ptr, ir.PointerType()),
640639
builder.trunc(len_val, ir.IntType(32)),
641-
flags_val,
640+
flags,
642641
],
643642
tail=False,
644643
)

pythonbpf/helper/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def uid():
4747
return ctypes.c_int32(0)
4848

4949

50-
def skb_store_bytes(skb, offset, from_buf, size, flags=0):
50+
def skb_store_bytes(offset, from_buf, size, flags=0):
5151
"""store bytes into a socket buffer"""
5252
return ctypes.c_int64(0)
5353

0 commit comments

Comments
 (0)