@@ -378,14 +378,54 @@ struct bpf_link;
378378LIBBPF_API struct bpf_link * bpf_link__open (const char * path );
379379LIBBPF_API int bpf_link__fd (const struct bpf_link * link );
380380LIBBPF_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+
381392LIBBPF_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+ */
382406LIBBPF_API int bpf_link__unpin (struct bpf_link * link );
383407LIBBPF_API int bpf_link__update_program (struct bpf_link * link ,
384408 struct bpf_program * prog );
385409LIBBPF_API void bpf_link__disconnect (struct bpf_link * link );
386410LIBBPF_API int bpf_link__detach (struct bpf_link * link );
387411LIBBPF_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+ */
389429LIBBPF_API struct bpf_link *
390430bpf_program__attach (const struct bpf_program * prog );
391431
@@ -686,12 +726,37 @@ LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_program__set_type() instead")
686726LIBBPF_API int bpf_program__set_sk_lookup (struct bpf_program * prog );
687727
688728LIBBPF_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
692744LIBBPF_API enum bpf_attach_type
693745bpf_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
695760bpf_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
707772LIBBPF_API const char * bpf_program__log_buf (const struct bpf_program * prog , size_t * log_size );
708773LIBBPF_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+ */
710783LIBBPF_API int
711784bpf_program__set_attach_target (struct bpf_program * prog , int attach_prog_fd ,
712785 const char * attach_func_name );
0 commit comments