Commit Graph

928 Commits (d2a999d27a6ca5f00f2bac2788f69bdca97e8054)
 

Author SHA1 Message Date
Andre Fredette af3de84b08 Use a struct for setting priority and handle in SchedClassfier attach
Use a struct called TcOptions for setting priority and handle in SchedClassifier attach

struct TcOptions implements the Default trait, so for the simple use
case in which the defaults are acceptable, we can call attach as
follows:
attach(“eth0”, TcAttachType::Ingress, TcOptions::default())

To specify all options:
attach(“eth0”, TcAttachType::Ingress, TcOptions { priority: (50), handle: (3) })

Or, some options:
attach(“eth0”, TcAttachType::Ingress, TcOptions { priority: (50), ..Default::default() })

Signed-off-by: Andre Fredette <afredette@redhat.com>
Andre Fredette ac07608b79 Support using handle in tc programs
Implements step 1 of https://github.com/aya-rs/aya/issues/414.

- Adds handle to the SchedClassifier attach API
- Saves handle in the TcLink sruct and uses it when detaching programs

NOTE: this changes the API, so it will require a bump in the Aya version.

Signed-off-by: Andre Fredette <afredette@redhat.com>
Alessandro Decina d6cb1a16ad
Merge pull request from astoycos/refactor-map-api2
Refactor map API
Andrew Stoycos 82edd681c3 Fix doc links, update rustdoc args
Fix some broken rust doc links.

Make sure rustdoc build fail on warnings
so we catch these broken links in CI.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos f3262e87bd Make map APIs return an option
switch map() and map_mut() from returning a
`Result` to an `Option` since it's just getting
a value from a Hashmap, and to stay in line with
the Programs API.

Remove `MapError::MapNotFound`

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos 4ddf2600b4 Fixups4
Remove From method and replace with internal
helper function.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos 440097d7bc Fixups 3
Remove MapError::UnexpectedMapType

Add Macro for converting from aya::Map to
u32 (map type) for use in
`MapError::InvalidMapType { map_type: x }`

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Michal Rostecki 89df8c36d3
Merge pull request from aya-rs/dependabot/cargo/bindgen-0.61
build(deps): update bindgen requirement from 0.60 to 0.61
Andrew Stoycos 939d16cce5 Fixups 2
Respond to more review comments:

Revert to try_from in doctests so we don't need
to explicitly specify type parameters.

Fixup some documentation

Remove explit types in `try_from` methods

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos 8009361694 Fixups
Respond to review comments, specifically:

- Remove Map::map_type()

- Update some comments

- remove `docs` from feature macros

- generalize check_bounds, check_kv_size,
and check_v_size functions to remove
duplicate code

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos 893f9f44a2 Implement Copy for MapData
Implement Copy for MapData so that
when `take_map` is used we create a
1 to 1 mapping of MapData to internal
FileDescriptor.  This will ensure
that when MapData is used in multiple
tasks that we don't drop the FD before
all tasks are done using it.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos 898a14d425 Use SockMapFd
Create a new type called `SockMapFd` which is
solely used when a program needs to attach
to a socket map. In the future this same
tatic could be used for other use cases
so we may make this more generic.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Andrew Stoycos 1aefa2e5e6 Core refactor of Map API
Build completing tests passing

Refactor the Map API to better align
with the aya programs API.  Specifically
remove all internal locking mechanisms
and custom Deref/DerefMut implementations.
They are replaced with a Map enum
and AsRef/AsMut implementations.

All Try_From implementations have been moved
to standardized enums, with a slightly
special one for PerfEventArray's.

Also cleanup/fix all associated tests and
documentation.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Alessandro Decina 0a9c9960e4 Add Documentation section to CONTRIBUTING.md
dependabot[bot] 5717f17367
build(deps): update bindgen requirement from 0.60 to 0.61
Updates the requirements on [bindgen](https://github.com/rust-lang/rust-bindgen) to permit the latest version.
- [Release notes](https://github.com/rust-lang/rust-bindgen/releases)
- [Changelog](https://github.com/rust-lang/rust-bindgen/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/rust-bindgen/compare/v0.60.0...v0.61.0)

---
updated-dependencies:
- dependency-name: bindgen
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Dave Tucker a0b0399dcd
Merge pull request from abhijeetbhagat/integration-tests-cli-options
add list, run cli flags to integration tests.
abhijeetbhagat c83d012c51 preserve existing behavior and avoid changes to gh workflows/xtask
abhi 4183c7a7d2
Merge branch 'aya-rs:main' into integration-tests-cli-options
Dave Tucker 77c5543993
Merge pull request from abhijeetbhagat/patch-1
add libelf as a pre-requisite for linux, libbpf repo link
Michal Rostecki 94bc93ea07
Merge pull request from abhijeetbhagat/fix-warnings
fix all clippy warnings
abhijeetbhagat 6c813b8c38 fix all clippy warnings
Michal Rostecki 57ab0d7978
Merge pull request from dave-tucker/unused-deps
cargo: Remove unused dependencies
abhijeetbhagat 7499661670 fix formatting
abhijeetbhagat 638cf514fb use macro to log, execute test and handle error
abhijeetbhagat 5b3e0ee856 add list, run cli flags to integration tests.
fixes: 
abhi 493a8db0ec
add libelf as a pre-requisite for linux, libbpf repo link
Dave Tucker ec2bd69053 cargo: Remove unused dependencies
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker 14ba644aa5
Merge pull request from dave-tucker/async-docs
docs: Add labels for optional features
Dave Tucker 95e8c78db8 docs: Add labels for optional features
Following the lead of crates like tokio and nix, we now annotate APIs
that require optional features. This helps in cases where a user wants
to have an `AsyncPerfEventArray` which is documented on crates.io, but
it's not obvious that you have to enable the `async` feature.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Michal Rostecki ae6fc95a8c
Merge pull request from vadorovsky/fix-integration-tests
integration-test: Change `assert_loaded` to a macro with timeouts
Michal Rostecki b15e1f8226 integration-test: Change `assert_loaded` to a macro with timeouts
We often need to wait a bit until the program or link gets unloaded
after dropping.

Also, using a macro makes it clear in which particular test the panic
happened.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Michal Rostecki 3f2f3a8be0
Merge pull request from vadorovsky/fix-miri
Fix CI errors
Michal Rostecki 325391892c integration-test: Remove multimap C test
libbpf 1.0 doesn't support multimaps defined in `maps` section, it
supports only BTF maps.

At the same time, we already test multimaps loading with the Rust
example (`integration-ebpf/src/bpf/map_test.rs`), so we can just remove
the failing C test.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Michal Rostecki 43aff57793 maps: Disable miri warnings about integer-to-pointer conversions
`override_syscall` performs integer-to-pointer conversion. This is
considered harmful on the newest Rust nightly which provides
`ptr::from_exposed_addr`, but there is no other way on Rust stable than
doing `as *const T`, which is what miri is unhappy about.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Michal Rostecki 2432677b2b Avoid integer to pointer casts
Instead, operate on byte slices if possible. That's the first step in
getting rid of miri warnings about Strict Provenance[0].

[0] https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Alessandro Decina a93a975cc6
Merge pull request from aztecher/impl-set_max_entries
aya: add BpfLoader::set_max_entries
aztecher 2eccf1d57d aya: add BpfLoader::set_max_entries
Add BpfLoader::set_max_entries, which sets the max_entries for the
specified map, as the load-time option.
The max_entries set at map initialization in the ebpf component can be
overwritten by this method called on the userspace component.
If you want to set max_entries for multiple maps in an ebpf component,
you can do so by calling set_max_entries in the form of a method chain.

Fixes: 
Refs: 
Michal Rostecki 6eca4f5709
Merge pull request from vadorovsky/clippy
Fix clippy warnings
Michal Rostecki 5a4b5ff8d8 Fix clippy warnings
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Dave Tucker e696389837
Merge pull request from dave-tucker/fix-387
Consistently name Pin APIs as from_pin
Dave Tucker 5693fb9941 aya: Rename from_pinned and from_path to from_pin
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker de6fa98963 aya: Fix review comments from
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker eb26a6b116
Merge pull request from astoycos/map-from-prog
Load static maps
Michal Rostecki 367ab20305
Merge pull request from dave-tucker/clippy-up
clippy: Fix latest nightly lints
Dave Tucker b2924a3a26 aya-log: Make miri happy
Miri took issue about using slice::from_raw_parts without checking for
alignment. Instead, we can simply convert to a [u8;16] into a [u16;8] by
iterating in chunks of 2 and bitshifting (remembering that these arrays
are in network-endian order).

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker a8eef00595 clippy: Fix latest nightly lints
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Andrew Stoycos 8a9cbf179f Add `from_pinned` and `from_fd` methods
Add `from_pinned` to allow loading BPF maps
from pinned points in the bpffs and
`from_fd` to allow loading BPF maps from
RawFds aquired via some other means eg
a unix socket.

These functions return an
aya::Map which has not been used previously
but will be the future abstraction once
all bpf maps are represented as an enum.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Dave Tucker 98e25ca5e6
Merge pull request from dave-tucker/pin-fixes-again
aya: More pinning fixes
Dave Tucker 7c244e1f65 tests: Add integration test for pinning lifecycle
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker 4ed587becc aya-tool: Fix clippy lints
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>