@@ -224,7 +224,7 @@ let get_kprobe_program_template target_function btf_path =
224224 in
225225
226226 {
227- program_type = " kprobe " ;
227+ program_type = " probe " ;
228228 context_type = context_type;
229229 return_type = return_type;
230230 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 =
358358
359359(* * Generate KernelScript source code from template *)
360360let 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" ]
376379 in
377380
378381 (* Helper function to generate type definition string *)
@@ -421,7 +424,7 @@ let generate_kernelscript_source ?extra_param ?include_kfuncs template project_n
421424
422425 (* Generate function signature comments and actual function definition for specific program types *)
423426 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
425428 let signature_lines = List. map (fun (func_name , signature ) ->
426429 sprintf " // Target function: %s -> %s" func_name signature
427430 ) template.function_signatures in
@@ -462,23 +465,23 @@ let generate_kernelscript_source ?extra_param ?include_kfuncs template project_n
462465 | None -> " @" ^ template.program_type
463466 in
464467
465- (* Customize attach call for kprobe /tracepoint *)
468+ (* Customize attach call for probe /tracepoint *)
466469 let attach_target =
467- if template.program_type = " kprobe " then target_function_name
470+ if template.program_type = " probe " then target_function_name
468471 else if template.program_type = " tracepoint" then target_function_name
469472 else " eth0"
470473 in
471474 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"
474477 else if template.program_type = " tracepoint" then
475478 " // Attach tracepoint to target kernel event"
476479 else
477480 " // TODO: Update interface name and attachment parameters"
478481 in
479482
480483 let function_name =
481- if template.program_type = " kprobe " then target_function_name
484+ if template.program_type = " probe " then target_function_name
482485 else if template.program_type = " tracepoint" then
483486 String. map (function '/' -> '_' | c -> c) target_function_name ^ " _handler"
484487 else if template.program_type = " tc" && extra_param <> None then
0 commit comments