Issue: https://github.com/aya-rs/aya/issues/1305
This change introduces a public constructor `HashMap::from_map_data`, enabling safe and ergonomic creation of HashMap<MapData, K, V> from a pinned BPF map. Previously, this required reloading the full BPF object or using unsafe/private APIs.
Motivation:
- Simplifies accessing pinned maps in multi-threaded user space
- Avoids full BPF reloads and potential deadlocks
- Matches existing ergonomic APIs like LruHashMap::try_from
- Keeps user code safe and idiomatic
Includes test coverage to validate the new API.
This change implements the `AsFd` trait for the `EbpfLogger` struct.
This allows obtaining a `BorrowedFd` from an `EbpfLogger` instance, which is safer than using `AsRawFd`.
This improves the ergonomics of using `EbpfLogger` with APIs that accept file descriptors.
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
The `Format` implementations for various types were using a wildcard `_`
to match the `None` case on `Option<DisplayHint>`.
This is incorrect as it would also match any `Some(...)` variants that
were not explicitly handled, leading to unexpected behavior.
This commit changes the wildcard `_` to an explicit `None` match to
ensure that only the `None` case is handled, making the matching more
explicit and correct.
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
We've recently added an xtask to bpf-linker (aya-rs/bpf-linker#282),
which resulted in multiple binary targets. Therefore, bpf-linker has
to be installed with the following command:
```
cargo install --git https://github.com/aya-rs/bpf-linker.git bpf-linker
```
The last argument (`bpf-linker`) specifies the binary target.
Rather than support N async runtimes, push this to the user. The
relevant types (`PerfEventArrayBuffer` and `RingBuffer`) implement
`As{,Raw}Fd` which is sufficient with integration with tokio, smol, and
other async runtimes.
`construct_debuglink_path()` returns a `Result`, but it doesn't actually
do anything that can fail. This means callers must do a useless
`unwrap()` to get at the return value.
This fixes the signature to reflect that the function is infallible.
This doesn't get us to zero copy because the reserve/submit APIs do not
support DSTs for reasons I don't remember.
Now that it is unused in userspace, move `LOG_BUF_CAPACITY` to
`aya-log-ebpf` by making its type `LogValueLength` which obviates the
need for `log_value_length_sufficient`.
Implements TryFrom for FdLink for CgroupSkb, CgroupSock, CgroupSockAddr
and SockOps program types. This allows support for link pinning for
these program types, aligning with the documentation for FdLink.
Fixes: #739
Co-authored-by: Benjamin Barzen <bbarzen@amazon.com>
Short-circuits `CACHE` to true if the field is non-zero.
This saves from executing the probing logic since the logic essentially
checks if the field can process (or doesn't error) non-zero value.
Cached probed for ProgramInfo fields instead of exposing it through
global FEATURE. Probing occurs on cache miss, which happens when first
accessing the field, *and* if the field is 0.
We have had loaded_links in the API as `#[doc(hidden)]` for a while.
I've been using it in bpfman and it's been fine. This commit does the
minimal work required to make the API stable.
We expose a `LinkInfo` type - similar to `ProgInfo` - which wraps the
generated type. In this case, `bpf_link_info`.
A few accessor functions have been added for `id`, `link_type` and
`program_id`. There are many more fields that could be (eventually)
made public.
As a convenience, `LinkInfo` can be retrieved from an existing FdLink
by using `FdLink::info()`.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>