Skip to content

Commit fa2ff0a

Browse files
committed
Use BPFHelperID Enums in bpf_helper_handler
1 parent c1466a5 commit fa2ff0a

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

pythonbpf/bpf_helper_handler.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def bpf_ktime_get_ns_emitter(call, map_ptr, module, builder, func, local_sym_tab
1919
Emit LLVM IR for bpf_ktime_get_ns helper function call.
2020
"""
2121
# func is an arg to just have a uniform signature with other emitters
22-
helper_id = ir.Constant(ir.IntType(64), 5)
22+
helper_id = ir.Constant(ir.IntType(64), BPFHelperID.BPF_KTIME_GET_NS.value)
2323
fn_type = ir.FunctionType(ir.IntType(64), [], var_arg=False)
2424
fn_ptr_type = ir.PointerType(fn_type)
2525
fn_ptr = builder.inttoptr(helper_id, fn_ptr_type)
@@ -66,7 +66,7 @@ def bpf_map_lookup_elem_emitter(call, map_ptr, module, builder, func, local_sym_
6666
fn_ptr_type = ir.PointerType(fn_type)
6767

6868
# Helper ID 1 is bpf_map_lookup_elem
69-
fn_addr = ir.Constant(ir.IntType(64), 1)
69+
fn_addr = ir.Constant(ir.IntType(64), BPFHelperID.BPF_MAP_LOOKUP_ELEM.value)
7070
fn_ptr = builder.inttoptr(fn_addr, fn_ptr_type)
7171

7272
result = builder.call(fn_ptr, [map_void_ptr, key_ptr], tail=False)
@@ -225,7 +225,7 @@ def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None,
225225
fn_type = ir.FunctionType(ir.IntType(
226226
64), [ir.PointerType(), ir.IntType(32)], var_arg=True)
227227
fn_ptr_type = ir.PointerType(fn_type)
228-
fn_addr = ir.Constant(ir.IntType(64), 6)
228+
fn_addr = ir.Constant(ir.IntType(64), BPFHelperID.BPF_PRINTK.value)
229229
fn_ptr = builder.inttoptr(fn_addr, fn_ptr_type)
230230

231231
builder.call(fn_ptr, [fmt_ptr, ir.Constant(
@@ -315,7 +315,7 @@ def bpf_map_update_elem_emitter(call, map_ptr, module, builder, func, local_sym_
315315
fn_ptr_type = ir.PointerType(fn_type)
316316

317317
# helper id
318-
fn_addr = ir.Constant(ir.IntType(64), 2)
318+
fn_addr = ir.Constant(ir.IntType(64), BPFHelperID.BPF_MAP_UPDATE_ELEM.value)
319319
fn_ptr = builder.inttoptr(fn_addr, fn_ptr_type)
320320

321321
if isinstance(flags_val, int):
@@ -375,7 +375,7 @@ def bpf_map_delete_elem_emitter(call, map_ptr, module, builder, func, local_sym_
375375
fn_ptr_type = ir.PointerType(fn_type)
376376

377377
# Helper ID 3 is bpf_map_delete_elem
378-
fn_addr = ir.Constant(ir.IntType(64), 3)
378+
fn_addr = ir.Constant(ir.IntType(64), BPFHelperID.BPF_MAP_DELETE_ELEM.value)
379379
fn_ptr = builder.inttoptr(fn_addr, fn_ptr_type)
380380

381381
# Call the helper function
@@ -389,7 +389,7 @@ def bpf_get_current_pid_tgid_emitter(call, map_ptr, module, builder, func, local
389389
Emit LLVM IR for bpf_get_current_pid_tgid helper function call.
390390
"""
391391
# func is an arg to just have a uniform signature with other emitters
392-
helper_id = ir.Constant(ir.IntType(64), 14)
392+
helper_id = ir.Constant(ir.IntType(64), BPFHelperID.BPF_GET_CURRENT_PID_TGID.value)
393393
fn_type = ir.FunctionType(ir.IntType(64), [], var_arg=False)
394394
fn_ptr_type = ir.PointerType(fn_type)
395395
fn_ptr = builder.inttoptr(helper_id, fn_ptr_type)
@@ -442,7 +442,7 @@ def bpf_perf_event_output_handler(call, map_ptr, module, builder, func, local_sy
442442
fn_ptr_type = ir.PointerType(fn_type)
443443

444444
# helper id
445-
fn_addr = ir.Constant(ir.IntType(64), 25)
445+
fn_addr = ir.Constant(ir.IntType(64), BPFHelperID.BPF_PERF_EVENT_OUTPUT.value)
446446
fn_ptr = builder.inttoptr(fn_addr, fn_ptr_type)
447447

448448
result = builder.call(

0 commit comments

Comments
 (0)