Skip to content

Commit 3e62eb1

Browse files
grantseltzerKernel Patches Daemon
authored andcommitted
Add documentation to API functions
This adds documentation for the following API functions: - bpf_program__set_expected_attach_type() - bpf_program__set_type() - bpf_program__set_attach_target() - bpf_program__attach() - bpf_program__pin() - bpf_program__unpin() Signed-off-by: Grant Seltzer <[email protected]>
1 parent f7744d6 commit 3e62eb1

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

tools/lib/bpf/libbpf.h

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,54 @@ struct bpf_link;
378378
LIBBPF_API struct bpf_link *bpf_link__open(const char *path);
379379
LIBBPF_API int bpf_link__fd(const struct bpf_link *link);
380380
LIBBPF_API const char *bpf_link__pin_path(const struct bpf_link *link);
381+
/**
382+
* @brief **bpf_link__pin()** pins the BPF link to a file
383+
* in the BPF FS specified by a path. This increments the links
384+
* reference count, allowing it to stay loaded after the process
385+
* which loaded it has exited.
386+
*
387+
* @param link BPF link to pin, must already be loaded
388+
* @param path file path in a BPF file system
389+
* @return 0, on success; negative error code, otherwise
390+
*/
391+
381392
LIBBPF_API int bpf_link__pin(struct bpf_link *link, const char *path);
393+
394+
/**
395+
* @brief **bpf_link__unpin()** unpins the BPF link from a file
396+
* in the BPFFS specified by a path. This decrements the links
397+
* reference count.
398+
*
399+
* The file pinning the BPF link can also be unlinked by a different
400+
* process in which case this function will return an error.
401+
*
402+
* @param prog BPF program to unpin
403+
* @param path file path to the pin in a BPF file system
404+
* @return 0, on success; negative error code, otherwise
405+
*/
382406
LIBBPF_API int bpf_link__unpin(struct bpf_link *link);
383407
LIBBPF_API int bpf_link__update_program(struct bpf_link *link,
384408
struct bpf_program *prog);
385409
LIBBPF_API void bpf_link__disconnect(struct bpf_link *link);
386410
LIBBPF_API int bpf_link__detach(struct bpf_link *link);
387411
LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
388412

413+
/**
414+
* @brief **bpf_program__attach()** is a generic function for attaching
415+
* a BPF program based on auto-detection of program type, attach type,
416+
* and extra paremeters, where applicable.
417+
*
418+
* @param prog BPF program to attach
419+
* @return Reference to the newly created BPF link; or NULL is returned on error,
420+
* error code is stored in errno
421+
*
422+
* This is supported for:
423+
* - kprobe/kretprobe (depends on SEC() definition)
424+
* - uprobe/uretprobe (depends on SEC() definition)
425+
* - tracepoint
426+
* - raw tracepoint
427+
* - tracing programs (typed raw TP/fentry/fexit/fmod_ret)
428+
*/
389429
LIBBPF_API struct bpf_link *
390430
bpf_program__attach(const struct bpf_program *prog);
391431

@@ -686,12 +726,37 @@ LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_program__set_type() instead")
686726
LIBBPF_API int bpf_program__set_sk_lookup(struct bpf_program *prog);
687727

688728
LIBBPF_API enum bpf_prog_type bpf_program__type(const struct bpf_program *prog);
689-
LIBBPF_API void bpf_program__set_type(struct bpf_program *prog,
729+
730+
/**
731+
* @brief **bpf_program__set_type()** sets the program
732+
* type of the passed BPF program.
733+
* @param prog BPF program to set the program type for
734+
* @param type program type to set the BPF map to have
735+
* @return error code; or 0 if no error. An error occurs
736+
* if the object is already loaded.
737+
*
738+
* This must be called before the BPF object is loaded,
739+
* otherwise it has no effect and an error is returned.
740+
*/
741+
LIBBPF_API int bpf_program__set_type(struct bpf_program *prog,
690742
enum bpf_prog_type type);
691743

692744
LIBBPF_API enum bpf_attach_type
693745
bpf_program__expected_attach_type(const struct bpf_program *prog);
694-
LIBBPF_API void
746+
747+
/**
748+
* @brief **bpf_program__set_expected_attach_type()** sets the
749+
* attach type of the passed BPF program. This is used for
750+
* auto-detection of attachment when programs are loaded.
751+
* @param prog BPF program to set the attach type for
752+
* @param type attach type to set the BPF map to have
753+
* @return error code; or 0 if no error. An error occurs
754+
* if the object is already loaded.
755+
*
756+
* This must be called before the BPF object is loaded,
757+
* otherwise it has no effect and an error is returned.
758+
*/
759+
LIBBPF_API int
695760
bpf_program__set_expected_attach_type(struct bpf_program *prog,
696761
enum bpf_attach_type type);
697762

@@ -707,6 +772,14 @@ LIBBPF_API int bpf_program__set_log_level(struct bpf_program *prog, __u32 log_le
707772
LIBBPF_API const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_size);
708773
LIBBPF_API int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size);
709774

775+
/**
776+
* @brief **bpf_program__set_attach_target()** sets BTF-based attach target
777+
* for supported BPF program types:
778+
* BTF-aware raw tracepoints, fentry/fexit/fmod_ret, lsm, freplace
779+
* @param prog BPF program to set the attach type for
780+
* @param type attach type to set the BPF map to have
781+
* @return error code; or 0 if no error occurred.
782+
*/
710783
LIBBPF_API int
711784
bpf_program__set_attach_target(struct bpf_program *prog, int attach_prog_fd,
712785
const char *attach_func_name);

0 commit comments

Comments
 (0)