this repo has no description
1(** See {!page-index} for example usage *)
2
3open Ctypes
4
5module C : module type of C
6(** Entry point for the underlying C primatives *)
7
8val major_version : int
9val minor_version : int
10val version_string : string
11val bpf_attach_type_str : C.Types.Bpf_attach_type.t -> string
12val bpf_link_type_str : C.Types.Bpf_link_type.t -> string
13val bpf_map_type_str : C.Types.Bpf_map_type.t -> string
14val bpf_prog_type_str : C.Types.Bpf_prog_type.t -> string
15
16type bpf_object = C.Types.bpf_object structure ptr
17
18type bpf_program = {
19 name : string;
20 fd : int;
21 ptr : C.Types.bpf_program structure ptr;
22}
23
24type bpf_map = { fd : int; ptr : C.Types.bpf_map structure ptr }
25type bpf_link = C.Types.bpf_link structure ptr
26
27val bpf_object_open : string -> bpf_object
28(** [bpf_object_open path] opens and tries to read the bpf_object
29 found at path [path] in the filesystem. Libbpf parses the BPF
30 object file and discovers BPF maps, BPF programs, and global
31 variables. After a BPF app is opened, user space apps can make
32 additional adjustments (setting BPF program types, if necessary;
33 pre-setting initial values for global variables, etc.) before all
34 the entities are created and loaded.
35
36 Fails if object file is in invalid format or path does not exist *)
37
38val bpf_object_load : bpf_object -> unit
39(** [bpf_object_load obj] tries to load [obj]. Libbpf parses
40 the BPF object file and discovers BPF maps, BPF programs, and
41 global variables. After a BPF app is opened, user space apps can
42 make additional adjustments (setting BPF program types, if
43 necessary; pre-setting initial values for global variables, etc.)
44 before all the entities are created and loaded. *)
45
46val bpf_object_find_program_by_name : bpf_object -> string -> bpf_program
47(** [bpf_object_find_program_by_name obj name] locates the
48 program identifier [name] within the [obj].
49
50 Fails if [name] is not found *)
51
52val bpf_program_attach : bpf_program -> bpf_link
53(** [bpf_program_attach prog] attaches the [prog] in the
54 kernel to start respond to events. Libbpf attaches BPF programs to
55 various BPF hook points (e.g., tracepoints, kprobes, cgroup hooks,
56 network packet processing pipeline, etc.). During this phase, BPF
57 programs perform useful work such as processing packets, or
58 updating BPF maps and global variables that can be read from user
59 space
60
61 Fails if link could not be attached *)
62
63val bpf_program_fd : bpf_program -> int
64(** [bpf_map_fd prog] returns the fd of the [prog] *)
65
66val bpf_object_find_map_by_name : bpf_object -> string -> bpf_map
67(** [bpf_object_find_map_by_name obj name] locates the bpf_map
68 identifier [name] within [obj].
69
70 Fails if map is not found *)
71
72val bpf_map_fd : bpf_map -> int
73(** [bpf_map_fd map] returns the fd of the [map] *)
74
75val bpf_link_destroy : bpf_link -> unit
76(** [bpf_link_destroy link] detaches and unloads the bpf program
77 associated to [link] from the kernel *)
78
79val bpf_object_close : bpf_object -> unit
80(** [bpf_object_close obj] tearsdown [obj]. BPF maps are destroyed,
81 and all the resources used by the BPF app are freed. *)
82
83val with_bpf_object_open_load_link :
84 obj_path:string ->
85 program_names:string list ->
86 ?before_link:(bpf_object -> unit) ->
87 (bpf_object -> bpf_link list -> unit) ->
88 unit
89(** [with_bpf_object_open_load_link obj_path program_names
90 ?before_link fn] performs opening and loading of the provided
91 filesystem path to the bpf_object [obj_path]. This helper runs
92 [before_link] before the program attaches the bpf programs
93 specified in [program_names]. Initialization code should go
94 here. [fn] is passed the bpf_object and the list of program links
95 if all steps were successful. Ensures all the proper shutdown and
96 cleanup of bpf_object resources and links *)
97
98val bpf_map_lookup_value :
99 key_ty:'a typ -> val_ty:'b typ -> val_zero:'b -> bpf_map -> 'a -> 'b
100(** [bpf_map_lookup_value key_ty val_ty val_zero map k flags] Looks
101 up the value associated with the key [k]. If key is invalid, no
102 value is found or the size of key/value is not in sync, it will
103 return an error. [bpf_map_lookup_value] expects [key_ty] and
104 [val_ty] to verify the types are coherent in your bpf map
105 declaration. [val_zero] is merely an initialization value that
106 will be overwritten. *)
107
108val bpf_map_update_elem :
109 key_ty:'a typ -> val_ty:'b typ -> bpf_map -> 'a -> 'b (* -> flags *) -> unit
110(** [bpf_map_update_elem key_ty val_ty map k v flags] updates the
111 value associated the key [k] to [v]. If key is invalid or the
112 size of key/value is not in sync, it will return an
113 error. [bpf_map_update_elem] expects [key_ty] and [val_ty] to
114 verify the types are coherent in your bpf map declaration. *)