@@ -378,14 +378,54 @@ struct bpf_link;
378
378
LIBBPF_API struct bpf_link * bpf_link__open (const char * path );
379
379
LIBBPF_API int bpf_link__fd (const struct bpf_link * link );
380
380
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
+
381
392
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
+ */
382
406
LIBBPF_API int bpf_link__unpin (struct bpf_link * link );
383
407
LIBBPF_API int bpf_link__update_program (struct bpf_link * link ,
384
408
struct bpf_program * prog );
385
409
LIBBPF_API void bpf_link__disconnect (struct bpf_link * link );
386
410
LIBBPF_API int bpf_link__detach (struct bpf_link * link );
387
411
LIBBPF_API int bpf_link__destroy (struct bpf_link * link );
388
412
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
+ */
389
429
LIBBPF_API struct bpf_link *
390
430
bpf_program__attach (const struct bpf_program * prog );
391
431
@@ -686,11 +726,36 @@ LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_program__set_type() instead")
686
726
LIBBPF_API int bpf_program__set_sk_lookup (struct bpf_program * prog );
687
727
688
728
LIBBPF_API enum bpf_prog_type bpf_program__type (const 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
+ */
689
741
LIBBPF_API int bpf_program__set_type (struct bpf_program * prog ,
690
742
enum bpf_prog_type type );
691
743
692
744
LIBBPF_API enum bpf_attach_type
693
745
bpf_program__expected_attach_type (const struct bpf_program * prog );
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
+ */
694
759
LIBBPF_API int
695
760
bpf_program__set_expected_attach_type (struct bpf_program * prog ,
696
761
enum bpf_attach_type type );
@@ -707,6 +772,17 @@ LIBBPF_API int bpf_program__set_log_level(struct bpf_program *prog, __u32 log_le
707
772
LIBBPF_API const char * bpf_program__log_buf (const struct bpf_program * prog , size_t * log_size );
708
773
LIBBPF_API int bpf_program__set_log_buf (struct bpf_program * prog , char * log_buf , size_t log_size );
709
774
775
+ /**
776
+ * @brief **bpf_program__set_attach_target()** sets BTF-based attach target
777
+ * for supported BPF program types:
778
+ * - BTF-aware raw tracepoints (tp_btf);
779
+ * - fentry/fexit/fmod_ret;
780
+ * - lsm;
781
+ * - freplace.
782
+ * @param prog BPF program to set the attach type for
783
+ * @param type attach type to set the BPF map to have
784
+ * @return error code; or 0 if no error occurred.
785
+ */
710
786
LIBBPF_API int
711
787
bpf_program__set_attach_target (struct bpf_program * prog , int attach_prog_fd ,
712
788
const char * attach_func_name );
0 commit comments