Commit Graph

89 Commits (main)

Author SHA1 Message Date
tyrone-wu 02d1db5fc0 aya: remove unwrap and NonZero* in info
Addresses the feedback from #1007:
- remove panic from `unwrap` and `expect`
- Option<NonZero*> => Option<int> with `0` mapping to `None`

Refs: #1007
2 weeks ago
tyrone-wu fbb09304a2
aya,int-test: revamp MapInfo be more friendly with older kernels
Adds detection for whether a field is available in `MapInfo`:
- For `map_type()`, we treturn new enum `MapType` instead of the integer
  representation.
- For fields that can't be zero, we return `Option<NonZero*>` type.
- For `name_as_str()`, it now uses the feature probe `bpf_name()` to
  detect if field is available.
  Although the feature probe checks for program name, it can also be
  used for map name since they were both introduced in the same commit.
2 weeks ago
tyrone-wu 88f5ac3114
aya,obj,int-test: revamp ProgramInfo be more friendly with older kernels
Purpose of this commit is to add detections for whether a field is
available in `ProgramInfo`.
- For `program_type()`, we return the new enum `ProgramType` instead of
  the integer representation.
- For fields that we know cannot be zero, we return `Option<NonZero*>`
  type.
- For `name_as_str()`, it now also uses the feature probe `bpf_name()`
  to detect if field is available or not.
- Two additional feature probes are added for the fields:
  - `prog_info_map_ids()` probe -> `map_ids()` field
  - `prog_info_gpl_compatible()` probe -> `gpl_compatible()` field

With the `prog_info_map_ids()` probe, the previous implementation that
I had for `bpf_prog_get_info_by_fd()` is shortened to use the probe
instead of having to make 2 potential syscalls.

The `test_loaded_at()` test is also moved into info tests since it is
better related to the info tests.

`aya::programs::Programs::prog_type(&self)` now returns `ProgramType`
instead of the generated FFI from aya-obj.

Also previously, `loaded_programs()` could be accessed either through
`aya` or `aya::programs`. To avoid confusion and duplicate export of
the item, the function should now only be exposed through
`aya::programs`.
2 weeks ago
Billy McFall eef7346fb2 test: adjust test byte arrays for big endian
Adding support for s390x (big endian architecture) and found that some
of the unit tests have structures and files implemented as byte arrays.
They are all coded as little endian and need a bug endian version to
work properly.

Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
3 weeks ago
Tamir Duberstein 41619933d6 Revert "Remove unused `allow(dead_code)`"
This reverts commit 5397c1ca4b.
1 month ago
Tamir Duberstein 5397c1ca4b Remove unused `allow(dead_code)`
See 31fe9628cf.
2 months ago
Michal Rostecki a75fc2f769 aya-log: Allow logging `core::net::Ipv4Addr` and `core::net::Ipv6Addr`
IP address types are available in `core`, so they can be used also in
eBPF programs. This change adds support of these types in aya-log.

* Add implementation of `WriteTuBuf` to these types.
* Support these types in `Ipv4Formatter` and `Ipv6Formatter`.
* Support them with `DisplayHint::Ip`.
* Add support for formatting `[u8; 4]`, to be able to handle
  `Ipv4Addr::octets`.
2 months ago
Alessandro Decina 8830c0bc20 docs(aya-log): reword rustdocs a bit 5 months ago
Catalin Horghidan e66f9540c9 aya-log: allow re-attach and read previously created logs
This feature is useful if someone wants to view the log contents
of a program that is already running. For e.g. a pinned program
or an XDP program attached to a net interface.
5 months ago
Dave Tucker 8c79b71bd5 feat(aya): Rename Bpf to Ebpf
And BpfLoader to EbpfLoader.
This also adds type aliases to preserve the use of the old names, making
updating to a new Aya release less of a burden. These aliases are marked
as deprecated since we'll likely remove them in a later release.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker a93e354620 feat(aya-log): Rename BpfLogger to EbpfLogger
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker 41c61560ea chore(aya-ebpf): Rename bpf -> ebpf
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker b6a84b658a Release aya-log-common v0.1.14, aya-log v0.2.0 7 months ago
Dave Tucker 9abb7160e5 docs(aya-log): Add CHANGELOG
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker c22a6963d4 Release aya-log-common v0.1.14, aya-log v0.2.0 7 months ago
Dave Tucker 0e99fa0f34 Release aya-obj v0.1.0, aya v0.12.0, safety bump aya-log v0.2.0 7 months ago
Dave Tucker 13b1fc63ef chore: Don't use path deps in workspace
This moves the path dependencies back into the per-crate Cargo.toml.
It is required such that the release tooling can correctly calculate
which version constraints require changing when we perform a release.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker b3e7ef741c chore: Use the cargo workspace package table
This allows for inheritance of common fields from the workspace root.
The following fields have been made common:

- authors
- license
- repository
- homepage
- edition

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Tamir Duberstein 963dd13219 Appease rustc dead_code lint
Some of these are legit, others are false positives. I've filed
https://github.com/rust-lang/rust/issues/120770 for the latter.
7 months ago
Tamir Duberstein d16e607fd4
rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
12 months ago
Tamir Duberstein 45df2519b6
Merge pull request #736 from aya-rs/logging-better
Remove pointless DefaultLogger
1 year ago
Tamir Duberstein ca3f70b16a
aya-log: s/Result<usize, ()>/Option<NonZeroUsize>/
`Option<NonZeroUsize>` is guaranteed to have the same size as `usize`,
which is not guarnateed for `Result`. This is a minor optimization, but
also results in simpler code.
1 year ago
Tamir Duberstein 00d265c51b
Remove pointless DefaultLogger
This avoids an atomic load on every log.
1 year ago
Mike Rostecki 96fa08bd82 cargo: Define dependencies on the workspace level
This way we will avoid version mismatches and make differences in
features across our crates clearer.
1 year ago
Tamir Duberstein c8bf646ef0
toml: add formatter and check in CI 1 year ago
Tamir Duberstein fa91fb4f59
Remove "async" feature
This feature is equivalent to async_tokio || async_std; removing it
avoids warnings emitted during `cargo hack check --feature-powerset`
where async is selected without either of the other features.

Use cargo hack to ensure clippy runs on the powerset of features.
1 year ago
Michal Rostecki 84e5e2894f aya-log: Unify IP format hints into one, repsesent it by `:i` token
Having separate format hints and tokens per IP address family is
unnecessary, since they are represented by different types and we handle
format hints for each type separately. So we can just have one format
hint.

Also, we should be consistent with the format strings grammar in
Rust[0]. The `type` token, which is mapped to formatting traits, usually
consists of one letter[1] (and optional `?` for `Debug` trait, but that
doesn't matter for us). It shouldn't consist of multiple letters. Our
`:ipv4` and `:ipv6` tokens were clearly breaking that convention, so we
should rather switch to something with one letter - hence `:i`.

[0] https://doc.rust-lang.org/std/fmt/#syntax
[1] https://doc.rust-lang.org/std/fmt/#formatting-traits
1 year ago
Tamir Duberstein d9f966ec9e
aya-log-common: support logging byte slices
These only support LowerHex and UpperHex hints for now.
1 year ago
Tamir Duberstein a4a69a6bcf
aya-log, aya-log-common: economize bytes
- Replace all `#[repr(usize)]` with `#[repr(u8)]`; this saves
  3*(sizeof(word)-1) bytes per log message.
- Encode payload length as u16 rather than usize; this saves
  sizeof(word)-1 bytes per log message. This is safe because the maximum
  size of a log message is less than (1 << 16 - 1).

This changes `level` to a require field in every log message. It was
already always present, but was treated as optional when reading.
1 year ago
Tamir Duberstein e4537e389a
aya-log: check errors in tests 1 year ago
Tamir Duberstein 490d7d587a
aya-log, aya-log-common: Remove duplicate struct
Previously `struct TagLenValue` was defined in both aya-log and
aya-log-common where the former implemented reading and the latter
writing; the reading logic doesn't need the struct, so remove it.
1 year ago
Michal Rostecki 5603d7248a aya-log: Move the `Pod` implementations from aya-log-common to aya-log
Keeping the `Pod` implementations and optional dependency on aya in
aya-log-common breaks the clippy checks (which are made on the entire
workspace).

The reason is that when different crates inside the workspace have the
same dependency with different features, that dependency is built only
once with the sum of features needed by all crates. It's **not** being
built separately with different feature sets.

That's why, before this change, aya-log-common was built once for the
entire workspace with `userspace` feature enabled. That made importing
aya-log-ebpf inside integration-ebpf impossible. The aya-log-common
build, with `userspace` feature enabled, was pulling std as a
dependency. Therefore, importing aya-log-ebpf inside integration-ebpf
resulted in including std and errors like:

```
error[E0152]: found duplicate lang item `panic_impl`
  --> test/integration-ebpf/src/log.rs:23:1
   |
23 | fn panic(_info: &core::panic::PanicInfo) -> ! {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: the lang item is first defined in crate `std` (which `aya` depends on)
```

This change fixes the problem by removing the `userspace` feature from
aya-log-common and moving the `Pod` implementations to aya-log.
1 year ago
Michal Rostecki dad75f45ac Update Tokio and inventory
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
ajwerner 12927cf699 Don't panic in init when bpf programs don't log
This was broken in d6cb1a16ad.
2 years ago
Dmitry Savintsev 055d94f58b fix uninlined_format_args clippy issues 2 years ago
dependabot[bot] 1c8088b16c
build(deps): update env_logger requirement from 0.9 to 0.10
Updates the requirements on [env_logger](https://github.com/rust-cli/env_logger) to permit the latest version.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.9.0...v0.10.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Alessandro Decina 0b41018ee2 Revert "aya-log, aya-log-common: temporarily revert to old map API so we can release"
This reverts commit 0d040d2290.
2 years ago
Alessandro Decina 832bdd280c {{crate_name}}: release version 0.1.13 2 years ago
Alessandro Decina 0d040d2290 aya-log, aya-log-common: temporarily revert to old map API so we can release 2 years ago
Michal Rostecki 2223ab828d aya-log: Add format hints for MAC addresses
Add `{:mac}` (for lower-case hex representation) and `{:MAC}` (for
upper-case hex representation) format hints for the `[u8; 6]` type,
which is the standard one in Linux to store physical addresses in.

Tested with: https://github.com/vadorovsky/aya-examples/tree/main/xdp-mac

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
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>
2 years ago
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>
2 years ago
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>
2 years ago
Dave Tucker 6f0637a6c8 aya-log, aya-log-common: start next development iteration 0.1.12-dev.0
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker ba927ac204 aya-log, aya-log-common: release version 0.1.11
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Michal Rostecki 83ec27f06b lib: Add display hints
This change adds optional display hints:

* `{:x}`, `{:X}` - for hex representation of numbers
* `{:ipv4}`, `{:IPv4}` - for IPv4 addresses
* `{:ipv6}`, `{:IPv6}` - for IPv6 addresses

It also gets rid of dyn-fmt and instead comes with our own parser
implementation.

Tested on: https://github.com/vadorovsky/aya-examples/tree/main/tc

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Michal Rostecki 944d6b8a16 Change from Rust edition 2018 to 2021
Rust 2021 adds more core prelude imports, including `TryFrom` and
`TryInto`.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Hengqi Chen b8b291c51b aya-log/README: Fix links to aya-log repo
The aya-log repo ([0]) has been archived, use the link to
aya repo instead.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
2 years ago
Michal Rostecki 3664e1ea0d aya-log, test: Switch from simplelog to env_logger
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Michal Rostecki 611f967cd1 aya-log: Remove i128 and u128 types
They are not supported by eBPF VM and we are going to use arrays for
IPv6.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago