|
| 1 | +// TODO: enable #![warn(missing_docs)] |
| 2 | +// TODO: enable #![warn(missing_doc_code_examples)] |
1 | 3 | //! `bpf-rs` is a safe, lean library for inspecting and querying eBPF objects. A lot of the
|
2 | 4 | //! design & inspiration stems from [bpftool](https://github.com/libbpf/bpftool) internals and
|
3 | 5 | //! [libbpf-rs](https://docs.rs/libbpf-rs).
|
@@ -175,6 +177,8 @@ impl Iterator for ProgramTypeIter {
|
175 | 177 | }
|
176 | 178 | }
|
177 | 179 |
|
| 180 | +/// eBPF program object info. Similar to (but not the same) kernel header's |
| 181 | +/// [struct bpf_prog_info](https://github.com/torvalds/linux/blob/672c0c5173427e6b3e2a9bbb7be51ceeec78093a/include/uapi/linux/bpf.h#L5840) |
178 | 182 | #[derive(Debug)]
|
179 | 183 | #[repr(C)]
|
180 | 184 | pub struct ProgramInfo {
|
@@ -359,10 +363,25 @@ impl Iterator for MapTypeIter {
|
359 | 363 | }
|
360 | 364 | }
|
361 | 365 |
|
| 366 | +/// eBPF helper function wrapper. See [`bpf-helpers(7)`](https://man7.org/linux/man-pages/man7/bpf-helpers.7.html) |
| 367 | +/// |
| 368 | +/// Tuple field [`BpfHelper::0`] represents the unique id reserved by the kernel to represent the helper function. This |
| 369 | +/// unique id works almost as a counter with a max value: |
| 370 | +/// [`__BPF_FUNC_MAX_ID`](https://github.com/torvalds/linux/blob/672c0c5173427e6b3e2a9bbb7be51ceeec78093a/include/uapi/linux/bpf.h#L5350). |
| 371 | +/// This max limit changes between kernel versions due to the addition of eBPF helper functions. |
| 372 | +/// |
| 373 | +/// For more information on eBPF helper functions, check out (although slightly outdated) |
| 374 | +/// [Marsden's Oracle blog post](https://blogs.oracle.com/linux/post/bpf-in-depth-bpf-helper-functions). |
362 | 375 | #[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
363 | 376 | pub struct BpfHelper(pub u32);
|
364 | 377 |
|
365 | 378 | impl BpfHelper {
|
| 379 | + /// Human-readable name for an eBPF helper function |
| 380 | + /// |
| 381 | + /// In the kernel, eBPF helper functions are usually represented as an int. This tries to create |
| 382 | + /// a digestable name for the helper functions but will return `<unknown>` or `<utf8err>` if not |
| 383 | + /// possible. For example, in the case that [`BpfHelper::0`] is outside the |
| 384 | + /// `__BPF_FUNC_MAX_ID` limit. |
366 | 385 | pub fn name(&self) -> &'static str {
|
367 | 386 | match usize::try_from(self.0) {
|
368 | 387 | Ok(func_idx) => {
|
@@ -393,10 +412,17 @@ impl Debug for BpfHelper {
|
393 | 412 | }
|
394 | 413 | }
|
395 | 414 |
|
| 415 | +/// Iterator for the eBPF helper functions |
396 | 416 | pub struct BpfHelperIter(u32);
|
397 | 417 |
|
398 | 418 | impl BpfHelperIter {
|
399 |
| - // Skips unspec helper |
| 419 | + /// Creates an ordered iterator |
| 420 | + /// |
| 421 | + /// Order here is based on the ascending int ids used to represent the helper |
| 422 | + /// functions within the kernel. For most cases, this ordering property isn't |
| 423 | + /// needed. |
| 424 | + /// |
| 425 | + /// **Note**: Skips `unspec` helper since it's an invalid function |
400 | 426 | pub fn new() -> Self {
|
401 | 427 | Self(1)
|
402 | 428 | }
|
|
0 commit comments