The loader should fill bss maps with zeros according to the size of the
ELF section.
Failure to do so yields weird verifier messages as follows:
```
cannot access ptr member ops with moff 0 in struct bpf_map with off 0 size 4
```
Reference to this in the cilium/ebpf code is here [1].
I could not find a reference in libbpf.
1: d0c8fc1937/elf_reader.go (L1159-L1165)
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Update libbpf to 80b16457cb23db4d633b17ba0305f29daa2eb307
Files changed:
M aya-obj/src/generated/btf_internal_bindings.rs
M aya-obj/src/generated/linux_bindings_aarch64.rs
M aya-obj/src/generated/linux_bindings_armv7.rs
M aya-obj/src/generated/linux_bindings_powerpc64.rs
M aya-obj/src/generated/linux_bindings_riscv64.rs
M aya-obj/src/generated/linux_bindings_s390x.rs
M aya-obj/src/generated/linux_bindings_x86_64.rs
Adds the following to codegen:
- `bpf_cgroup_iter_order`: used in `bpf_link_info.iter.group.order`
- `NFPROTO_*`: used in `bpf_link_info.netfilter.pf`
- `nf_inet_hooks`: used in `bpf_link_info.netfilter.hooknum`
Include `linux/netfilter.h` in `linux_wrapper.h` for `NFPROTO_*` and
`nf_inet_hooks` to generate.
```
error: the following explicit lifetimes could be elided: 'data, 'file
--> aya-obj/src/obj.rs:1083:6
|
1083 | impl<'data, 'file, 'a> TryFrom<&'a ObjSection<'data, 'file>> for Section<'a> {
| ^^^^^ ^^^^^ ^^^^^ ^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
```
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.
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`.
Add conversion from u32 to program type, link type, and attach type.
Additionally, remove duplicate match statement for u32 conversion to
`BPF_MAP_TYPE_BLOOM_FILTER` & `BPF_MAP_TYPE_CGRP_STORAGE`.
New error `InvalidTypeBinding<T>` is created to represent when a
parsed/received value binding to a type is invalid.
This is used in the new conversions added here, and also replaces
`InvalidMapTypeError` in `TryFrom` for `bpf_map_type`.
Where possible, replace the hardcoded byte arrays in the tests with the
structs they represent, then convert the structs to byte arrays.
Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
bpfman, a project using aya, has a requirement to support powerpc64 and
s390x architectures. Adding these two architectures to aya.
Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
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>
Update libbpf to 686f600bca59e107af4040d0838ca2b02c14ff50
Files changed:
M aya-obj/src/generated/linux_bindings_aarch64.rs
M aya-obj/src/generated/linux_bindings_armv7.rs
M aya-obj/src/generated/linux_bindings_powerpc64.rs
M aya-obj/src/generated/linux_bindings_riscv64.rs
M aya-obj/src/generated/linux_bindings_s390x.rs
M aya-obj/src/generated/linux_bindings_x86_64.rs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Update libbpf to c1a6c770c46c6e78ad6755bf596c23a4e6f6b216
Files changed:
M aya-obj/src/generated/linux_bindings_aarch64.rs
M aya-obj/src/generated/linux_bindings_armv7.rs
A aya-obj/src/generated/linux_bindings_powerpc64.rs
M aya-obj/src/generated/linux_bindings_riscv64.rs
A aya-obj/src/generated/linux_bindings_s390x.rs
M aya-obj/src/generated/linux_bindings_x86_64.rs
M ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs
M ebpf/aya-ebpf-bindings/src/armv7/bindings.rs
A ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs
A ebpf/aya-ebpf-bindings/src/powerpc64/helpers.rs
M ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs
A ebpf/aya-ebpf-bindings/src/s390x/bindings.rs
A ebpf/aya-ebpf-bindings/src/s390x/helpers.rs
M ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
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>
```
error: unnecessary use of `get("foo").is_some()`
--> aya-obj/src/obj.rs:1690:26
|
1690 | assert!(obj.maps.get("foo").is_some());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("foo")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
note: the lint level is defined here
--> aya-obj/src/lib.rs:68:9
|
68 | #![deny(clippy::all, missing_docs)]
| ^^^^^^^^^^^
= note: `#[deny(clippy::unnecessary_get_then_check)]` implied by `#[deny(clippy::all)]`
error: unnecessary use of `get("foo").is_some()`
--> aya-obj/src/obj.rs:1777:26
|
1777 | assert!(obj.maps.get("foo").is_some());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("foo")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get("bar").is_some()`
--> aya-obj/src/obj.rs:1778:26
|
1778 | assert!(obj.maps.get("bar").is_some());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("bar")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get("baz").is_some()`
--> aya-obj/src/obj.rs:1779:26
|
1779 | assert!(obj.maps.get("baz").is_some());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("baz")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get(".bss").is_some()`
--> aya-obj/src/obj.rs:1799:26
|
1799 | assert!(obj.maps.get(".bss").is_some());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(".bss")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get(".rodata").is_some()`
--> aya-obj/src/obj.rs:1810:26
|
1810 | assert!(obj.maps.get(".rodata").is_some());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(".rodata")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get(".rodata.boo").is_some()`
--> aya-obj/src/obj.rs:1821:26
|
1821 | assert!(obj.maps.get(".rodata.boo").is_some());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(".rodata.boo")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get(".data").is_some()`
--> aya-obj/src/obj.rs:1832:26
|
1832 | assert!(obj.maps.get(".data").is_some());
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(".data")`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
error: unnecessary use of `get(".data.boo").is_some()`
--> aya-obj/src/obj.rs:1843:26
|
1843 | assert!(obj.maps.get(".data.boo").is_some());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(".data.boo")`
```
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>
When comparing `local_spec` with `target_spec` for enum relocations,
we can encounter a situation when a matchinng variant in a candidate
spec doesn't exist.
Before this change, such case wasn't handled explicitly, therefore
resulted in returning currently constructed `target_spec` at the
end. The problem is that such `target_spec` was, due to lack of
match, incomplete. It didn't contain any `accessors` nor `parts`.
Later usage of such incomplete `target_spec` was leading to panics,
since the code operating on enums' `target_spec` expects at least
one `accessor` to be available.
Fixes#868
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.
`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.
Remove repetition of permitted cgroup attach types. Make optionality of
name more explicit rather than pretending both kind and name are equal
to section.
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.
This commit adds:
- A probe to see if the ENUM64 feature is supported
- Fixups for the use of signed enums, or enum64 types
on systems where enum64 is not supported
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
The BTF we're working on is Cow anyway so modifying in-place is fine.
All we need to do is store some information before we start our
mutable iteration to avoid concurrently borrowing types both mutably and
immutably.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Rather than creating an empty vector and iteratively appending - which
might induce intermediate allocations - create an ExactSizeIterator and
collect it into a vector, which should produce exactly one allocation.
This commit fixes the (func|line)_info when we have multiple programs in
the same section. The integration test reloc.bpf.c serves as our test
case here. This required filtering down the (func|line)_info to only
that in scope of the current symbol + then adjusting the offets to
appease the kernel.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
This makes a few changes to the way that Aya reads the ELF object
files.
1. To find programs in a section, we use the symbols table. This allows
for cases where multiple programs could appear in the same section.
2. When parsing our ELF file we build symbols_by_section_index as an
optimization as we use it for legacy maps, BTF maps and now programs.
As a result of theses changes the "NAME" used in `bpf.prog_mut("NAME")`
is now ALWAYS the same as the function name in the eBPF code, making the
user experience more consistent.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Wrap verifier logs in a newtype whose `Debug` impl emits unescaped
newlines. This improves ergonomics in tests where we `Result::unwrap()`
those load errors; when these fail today they emit the errors with
newlines escaped, making them incredibly difficult to read.