Commit Graph

585 Commits (ae612a0a1061ea65237b62a7d9fa1f2f583dff36)

Author SHA1 Message Date
Tamir Duberstein ae612a0a10
Merge pull request #813 from tamird/sort-variants
maps: sort variants
11 months ago
Tamir Duberstein 5cdd1baf29
aya: import types from std::ffi rather than libc 11 months ago
Tamir Duberstein 5e637071c1
maps: sort variants 11 months ago
astoycos 7b71c7e1cd aya/maps: add pin() api
- Adds new `maps_mut()` API to the BpfManager to allow us to iterate though
and pin all of maps at the same time.

- Adds new pin(Path)/unpin(Path) api to Maps so they
can be generically pinned AFTER load.

- Adds macro for pinning explicit map types in aya.
Convert all explicit map types "inner" field to be
pub crate in order to facilitate this.

Signed-off-by: astoycos <astoycos@redhat.com>
12 months ago
astoycos 0bf97eba64 aya/maps: fix libbpf_pin_by_name
Aligns with libbpf for the special LIBBPF_PIN_BY_NAME
map flag. Specifically if the flag is provided without a pin path
default to "/sys/fs/bpf".

Signed-off-by: astoycos <astoycos@redhat.com>
12 months ago
Mike Rostecki bd6ba3ad8b util: Deprecate `syscall_prefix`
Using the prefix only for the host architecture is often not enough,
kernels usually provide symbols for more architectures, which are
used by multilib applications. Handling them might or might not be
necessary depending on the use case. Due to that complexity, we
decided to let the callers to handle prefixes the way they prefer.
12 months ago
Tamir Duberstein d16e607fd4
rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
12 months ago
Andrés Medina 0a6a2674fa aya: Fix program loading on kernels with a patch > 255 12 months ago
Alessandro Decina 7f9ce062f4
Merge pull request #527 from Tuetuopay/xdpmaps
Implement XDP map types
1 year ago
Tuetuopay 579e3cee22 aya, bpf: misc fixes following review comments 1 year ago
astoycos dffff1ce6b integration-test: fix load time and add test
Time since boot is defined as the UNIX_EPOCH plus the duration
since boot. which is realtime - boottime NOT boottime - realtime.

Add a integration test to ensure this doesn't happen again.

Signed-off-by: astoycos <astoycos@redhat.com>
1 year ago
Tuetuopay 00dc7a5bd4 maps/xdp: make maps work on kernels not supporting ProgIds
On startup, the kernel is probed for support of chained program ids for
CpuMap, DevMap and DevMapHash, and will patch maps at load time to have
the proper size. Then, at runtime, the support is checked and will error
out if a program id is passed when the kernel does not support it.
1 year ago
Tuetuopay c6754c614e maps/xdp: use ProgramFd instead of impl AsRawFd
Not having a generic here allows to pass `None` without specifying the
actual type you don't care about.
1 year ago
Tuetuopay 9ed1d3d281 bpf: add documentation for XDP maps 1 year ago
Tuetuopay f7fbbcd0e5 aya: fix docstring missing trailing period 1 year ago
Tuetuopay 0647927e32 xdp: add support for chained xdp programs in {cpu,dev}map
set/insert functions can now take an optional bpf program fd to run once
the packet has been redirected from the main probe
1 year ago
Tuetuopay 139f382638 aya: add support for map-bound XDP programs
Such programs are to be bound to cpumap or devmap instead of the usual
network interfaces.
1 year ago
Tuetuopay ede3e91014 aya: Update XDP maps implementations
Map impls changed since this was first written.

Fixes: 2b726c8 ("aya: Implement XDP Map Types")
1 year ago
Dave Tucker ec8293ab86 aya: Implement XDP Map Types
This commit adds implementations for:
- xskmap
- devmap
- devmap_hash
- cpumap

Which can all be used to redirect XDP packets to various different
locations

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker 42fd82e32b
Merge pull request #790 from dave-tucker/no-map-pinned 1 year ago
Dave Tucker 938f979fe7 aya: Make MapData::pin pub
This is to solve a use-case where a user (in this case bpfd) may want
to:

- MapData::from_pin to open a pinned map from bpffs
- MapData::pin to pin that object into another bpffs

Both operations should be easily accomplished without needing to cast
a MapData into a concrete Map type - e.g aya::maps::HashMap.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker 0f4021ec89 aya: Remove MapData::pinned
BPF objects can be pinned multiple times, to multiple different places.
Tracking whether or not a map is pinned in a bool is therefore not sufficient.
We could track this in a HashSet<PathBuf>, but there is really no reason
to track it at all.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Andrew Stoycos 0b6ea313de
Merge pull request #782 from astoycos/prog-info
aya: add program_info() api to `Program`
1 year ago
Tamir Duberstein 0dacb34d44
maps: fix typos, avoid fallible conversions 1 year ago
Tamir Duberstein b4d5a1e8db
maps: MapData::{obj, fd} are private 1 year ago
Tamir Duberstein f41592663c
maps: `MapFd` and `SockMapFd` are owned
`MapData::fd` is now a `MapFd`. This means that `MapData` now closes the
file descriptor on drop. In the future we might consider making `MapFd`
hold a `BorrowedFd` but this requires API design work due to overlapping
borrows.

Since `SockMapFd` is no longer `Copy`, attach methods to take it by
reference to allow callers to use it multiple times as they are
accustomed to doing.

`SockMapFd` implements `try_clone`. `MapFd` and `SockMapFd` are now
returned by reference to allow callers to avoid file descriptor cloning
when desired.

This is an API breaking change.

Updates #612.
1 year ago
astoycos 6ab7475fa6 aya: add program_info() api to program
Add a new api to the outer level `Program` structure which
allows users to get the program's kernel info before casting
it to an explicit program variant.

Signed-off-by: astoycos <astoycos@redhat.com>
1 year ago
Tamir Duberstein 92d3056db3
Merge pull request #775 from aya-rs/perf-as-raw-fd
async_perf_event_array: access inner through async
1 year ago
Andrew Werner 172859c66b aya/maps: support TryFrom for LRU hash maps
The macro to implement TryFrom for MapData didn't have the ability to
specify that more than one variant of MapData can be valid for a single
map implementation. Support for new syntax was added to the macro so that
the implementation can succeed for both valid variants in the HashMap
and PerCpuHashMap impl.

Fixes #636
1 year ago
Andrew Werner 2a1bf609b2 aya/maps: rework TryFrom macros
The old macros were repetitive and inflexible. This unifies the various
macros used to generate TryFrom implementations for map implementations
from the relevant map enum variants.

Cleanup in anticipation of fixing #636.

The API changes are just about renaming the return to Self and
Self::Error; they are not real changes.
1 year ago
Tamir Duberstein 8b0c7f1204
async_perf_event_array: access inner through async
Avoid holding onto raw file descriptors.

Remove some implied bounds (BorrowMut implies Borrow).
1 year ago
Tamir Duberstein 8668436787
Merge pull request #772 from aya-rs/link-owned
programs: ProgAttachLink and LircLink hold owned FDs
1 year ago
Tamir Duberstein 204d02022a
programs: ProgAttachLink and LircLink hold owned FDs
Updates #612.
1 year ago
Tamir Duberstein cee0265b52
netlink: use OwnedFd
Updates #612.
1 year ago
Andrés Medina 6895b1e2ed
aya: Use AsFd when attaching fds to programs
This is a breaking change but adds another level of safety to ensure
the file descriptor we receive is valid. Additionally, this allows
aya to internally easily duplicate this file descriptor using std
library methods instead of manually calling `dup` which doesn't
duplicate with the CLOSE_ON_EXEC flag that is standard pratice to
avoid leaking the file descriptor when exec'ing.
1 year ago
Andrés Medina d2e74e562d
aya: Use BorrowedFd when using the program fd in sys/bpf.rs
This commit reveals but does not address a file descriptor leak in
LircLink2::query. This function returns a list of `LircLink`s where
each of them have a program file descriptor that is not going to be
closed. This commit does not add this leak; it merely makes it louder
in the code.
1 year ago
Tamir Duberstein 1ccfdbc175
aya: support non-UTF8 probing
Fixes #751.
1 year ago
Tamir Duberstein 0bba9b14b0
maps,programs: avoid path UTF-8 assumptions 1 year ago
Tamir Duberstein 572d047e37
test: avoid lossy string conversions
We can be strict in tests.
1 year ago
Tamir Duberstein abda239d63
aya: deny various allow-by-default lints
Notably:
- clippy::use_self: replaced many T with Self.
- single_use_lifetimes: removed some single use lifetimes.
- unreachable_pub: removed some unreachable pub items.
- unused_crate_dependencies: removed unused futures,parking_lot deps.
- unused_qualifications: found a potential `crate` vs `$crate` bug.
- let_underscore_drop: not enabled, seems to trigger false positives.
- missing_copy_implementations: not enabled, unclear if we want this.
- unsafe_op_in_unsafe_fn: not enabled, unclear if we want this.
- unused_results: not enabled, needs many fixes (but I think wanted).
1 year ago
Tamir Duberstein 9ff1bf3d3b
aya: fix docs build
Appease the new lint rustdoc::redundant_explicit_links that was added in
https://github.com/rust-lang/rust/pull/113167.
1 year ago
Tamir Duberstein a31544b6e7
maps: BloomFilter::insert takes &mut self
This is consistent with all the other maps.
1 year ago
Tamir Duberstein 89bc255f1d
aya: MapData::fd is non-optional
The primary driver of change here is that `MapData::create` is now a
factory function that returns `Result<Self, _>` rather than mutating
`&mut self`. The remaining changes are consequences of that change, the
most notable of which is the removal of several errors which are no
longer possible.
1 year ago
Tamir Duberstein 3d68fa32cb
aya: use RAII to close FDs 1 year ago
Tamir Duberstein ae6526e59b
programs: `ProgramData::attach_prog_fd` is owned
This prevents a file descriptor leak when extensions are used.

This is an API breaking change.

Updates #612.
1 year ago
Tamir Duberstein 504fd1df0a
programs: `ProgramFd` is owned
`ProgramData::fd` is now a `ProgramFd`. This means that `ProgramData`
now closes the file descriptor on drop. In the future we might consider
making `ProgramFd` hold a `BorrowedFd` but this requires API design work
due to overlapping borrows.

Since `ProgramFd` is no longer `Copy`, update methods to take it by
reference to allow callers to use it multiple times as they are
accustomed to doing.

`ProgramFd` is now returned by reference and implements `try_clone` to
allow callers to avoid file descriptor cloning when desired.

This is an API breaking change.

Updates #612.
1 year ago
Andrew Stoycos bcc9743254
Merge pull request #637 from astoycos/helpers
Add more helpful methods to `ProgramInfo`
1 year ago
Andrew Stoycos e1a556894c
aya: add helper methods for ProgramInfo
- Add helper methods to get useful information from the ProgramInfo
object which is returned by the `loaded_programs()` API.  Specifically
this code mirrors the `bpftool prog` command in terms of useful fields.
- Add a new API macro to each aya `Program` type to allow us to fetch
its accompanying `ProgramInfo` metadata after its been loaded.
- Add a new ProgramInfo constructor that builds a new instance using
a raw fd.
- Add a smoke test for the loaded_programs() API as well as
all the relevant methods on the ProgramInfo type.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Dave Tucker 03c5012db2
Merge pull request #702 from dave-tucker/mapdata-btffd
aya: Don't store btf_fd in MapData
1 year ago
Tamir Duberstein d88ca62aaa
programs: Plug attach_btf_obj_fd leak
`ProgramData::attach_btf_obj_fd` is now owned.  This means that
`ProgramData` now closes the file descriptor on drop.

Updates #612.
1 year ago