@@ -224,7 +224,7 @@ let get_kprobe_program_template target_function btf_path =
224
224
in
225
225
226
226
{
227
- program_type = " kprobe " ;
227
+ program_type = " probe " ;
228
228
context_type = context_type;
229
229
return_type = return_type;
230
230
includes = [" linux/bpf.h" ; " linux/pkt_cls.h" ; " linux/if_ether.h" ; " linux/ip.h" ; " linux/tcp.h" ; " linux/udp.h" ];
@@ -358,21 +358,24 @@ let generate_kprobe_function_from_signature func_name signature =
358
358
359
359
(* * Generate KernelScript source code from template *)
360
360
let generate_kernelscript_source ?extra_param ?include_kfuncs template project_name =
361
- let context_comment = match template.program_type with
362
- | "xdp" -> " // XDP (eXpress Data Path) program for high-performance packet processing"
363
- | "tc" -> " // TC (Traffic Control) program for network traffic shaping and filtering"
364
- | "kprobe" -> " // Kprobe program for dynamic kernel tracing"
365
- | "uprobe" -> " // Uprobe program for userspace function tracing"
366
- | "tracepoint" -> " // Tracepoint program for static kernel tracing"
367
- | "lsm" -> " // LSM (Linux Security Module) program for security enforcement"
368
- | "cgroup_skb" -> " // Cgroup SKB program for cgroup-based packet filtering"
369
- | _ -> " // eBPF program"
370
- in
371
-
372
- let return_values = match template.program_type with
373
- | "xdp" -> [" XDP_ABORTED" ; " XDP_DROP" ; " XDP_PASS" ; " XDP_TX" ; " XDP_REDIRECT" ]
374
- | "tc" -> [" TC_ACT_OK" ; " TC_ACT_SHOT" ; " TC_ACT_STOLEN" ; " TC_ACT_PIPE" ; " TC_ACT_REDIRECT" ]
375
- | _ -> [" 0" ; " -1" ]
361
+ (* Initialize context code generators to ensure they're available *)
362
+ Kernelscript_context.Xdp_codegen. register () ;
363
+ Kernelscript_context.Tc_codegen. register () ;
364
+ Kernelscript_context.Kprobe_codegen. register () ;
365
+ Kernelscript_context.Tracepoint_codegen. register () ;
366
+ Kernelscript_context.Fprobe_codegen. register () ;
367
+
368
+ (* Get program description from context codegen system *)
369
+ let context_comment = " // " ^ (Kernelscript_context.Context_codegen. get_context_program_description template.program_type) in
370
+
371
+ (* Get return values from context codegen system if available *)
372
+ let return_values =
373
+ let action_constants = Kernelscript_context.Context_codegen. get_context_action_constants template.program_type in
374
+ if action_constants <> [] then
375
+ List. map fst action_constants (* Extract constant names *)
376
+ else
377
+ (* Fallback for program types without action constants *)
378
+ [" 0" ; " -1" ]
376
379
in
377
380
378
381
(* Helper function to generate type definition string *)
@@ -421,7 +424,7 @@ let generate_kernelscript_source ?extra_param ?include_kfuncs template project_n
421
424
422
425
(* Generate function signature comments and actual function definition for specific program types *)
423
426
let (function_signatures_comment, target_function_name, function_definition, custom_attribute) =
424
- if template.program_type = " kprobe " && template.function_signatures <> [] then
427
+ if template.program_type = " probe " && template.function_signatures <> [] then
425
428
let signature_lines = List. map (fun (func_name , signature ) ->
426
429
sprintf " // Target function: %s -> %s" func_name signature
427
430
) template.function_signatures in
@@ -462,23 +465,23 @@ let generate_kernelscript_source ?extra_param ?include_kfuncs template project_n
462
465
| None -> " @" ^ template.program_type
463
466
in
464
467
465
- (* Customize attach call for kprobe /tracepoint *)
468
+ (* Customize attach call for probe /tracepoint *)
466
469
let attach_target =
467
- if template.program_type = " kprobe " then target_function_name
470
+ if template.program_type = " probe " then target_function_name
468
471
else if template.program_type = " tracepoint" then target_function_name
469
472
else " eth0"
470
473
in
471
474
let attach_comment =
472
- if template.program_type = " kprobe " then
473
- " // Attach kprobe to target kernel function"
475
+ if template.program_type = " probe " then
476
+ " // Attach probe to target kernel function"
474
477
else if template.program_type = " tracepoint" then
475
478
" // Attach tracepoint to target kernel event"
476
479
else
477
480
" // TODO: Update interface name and attachment parameters"
478
481
in
479
482
480
483
let function_name =
481
- if template.program_type = " kprobe " then target_function_name
484
+ if template.program_type = " probe " then target_function_name
482
485
else if template.program_type = " tracepoint" then
483
486
String. map (function '/' -> '_' | c -> c) target_function_name ^ " _handler"
484
487
else if template.program_type = " tc" && extra_param <> None then
0 commit comments