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>
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>
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>
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>
This commit moves the aya-log projects from the subtree and adds them to
the main cargo workspace. It also brings the BPF crates into the
workspace and moves the macro crates up a level since they aren't BPF
code.
Miri was disabled for aya-bpf as the previous config wasn't actually
checking anything.
CI, clippy, fmt and release configurations have all been adjusted
appropriately.
CI was not properly running for other supported arches which was also
ixed here.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Change 821ba0b243fd removed the `size > buf.len()` check, which was a
mistake, because we might write to a subslice of the whole buffer, so
then `buf` can be lower than `LOG_BUF_CAPACITY`.
This change compares `size` with `min::(buf.len(), LOG_BUF_CAPACITY)`
instead.
Fixes: 821ba0b243fd ("Ensure log buffer bounds")
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
This change adds checks in `TagLenValue.write()` to ensure that the size
of written data doesn't exceed the buffer size.
Verifier in recent kernel versions requires the bound to be a constant
value, so using `buf.len()` does not work.
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
This moves a large chunk of code from ebpf to shared so we can re-use
write_record_header and write_record_message and friends so that we
can write test cases to ensure that logs are properly formatted
given certain input.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
eBPF verifier rejects programs which are not checking the bounds of the
log buffer before writing any arguments. This change ensures that
written log arguments.
In practice, it means that doing this kind of checks is not going to be
needed in eBPF program code anymore:
33a1aee2ea/echo-ebpf/src/main.rs (L47)
Tested on:
876f8b4551
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
This change moves away argument formatting from eBPF to the userspace.
eBPF part of aya-log writes unformatted log message and all arguments to
the perf buffer and the userspace part of aya-log is formatting the
message after receiving all arguments.
Aya-based project to test this change:
https://github.com/vadorovsky/aya-log-exampleFixes: #4
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Signed-off-by: Tuetuopay <tuetuopay@me.com>
Co-authored-by: Tuetuopay <tuetuopay@me.com>