Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable first-line-heading -->

<!--
Thank you for your contribution to Aya! 🎉

Expand All @@ -13,22 +15,25 @@

-->

# Summary
<!---
Summarize the changes you're making here.
Detailed information belongs in the Git Commit messages.
Feel free to flag anything you thing needs a reviewer's attention.
Summarize the changes you're making here. Detailed information belongs in
the Git commit messages. If your pull request contains just one commit,
it's best to use its message as a summary. Otherwise, if there are multiple
atomic commits, write a summary for the entire PR. Feel free to flag
anything you think needs a reviewer's attention.
-->

# Related Issues
<!--
For example:
If your changes address an issue, link it with the *Fixes* tag so
the issue gets closed when the PR is merged, for example:

Fixes: #1234

- Closes: #1234
- Relates To: #1234
If you are only referencing an issue without fully addressing it, feel
free to link it anywhere in the summary.
-->

# Added/updated tests?
### Added/updated tests?

_We strongly encourage you to add a test for your changes._

Expand All @@ -37,7 +42,7 @@ _We strongly encourage you to add a test for your changes._
have not been included_
- [ ] I need help with writing tests

# Checklist
### Checklist

- [ ] Rust code has been formatted with `cargo +nightly fmt`.
- [ ] All clippy lints have been fixed.
Expand All @@ -48,4 +53,4 @@ _We strongly encourage you to add a test for your changes._

[Integration tests]: https://github.com/aya-rs/aya/blob/main/test/README.md

# (Optional) What GIF best describes this PR or how it makes you feel?
### (Optional) What GIF best describes this PR or how it makes you feel?
74 changes: 12 additions & 62 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror

- uses: DavidAnson/markdownlint-cli2-action@v22
- uses: DavidAnson/markdownlint-cli2-action@v23

- run: taplo fmt --check

Expand Down Expand Up @@ -177,9 +177,10 @@ jobs:

- uses: Swatinem/rust-cache@v2

- run: cargo install --git https://github.com/aya-rs/bpf-linker.git bpf-linker

- uses: taiki-e/install-action@cargo-hack
- uses: taiki-e/install-action@v2
with:
tool: cargo-binstall,cargo-hack
- run: cargo binstall --force bpf-linker

- name: Build & test for all BPF architectures
env:
Expand Down Expand Up @@ -288,11 +289,14 @@ jobs:
sudo apt update
# linux-libc-dev provides kernel UAPI headers for libbpf-sys cross-compilation.
#
# llvm provides llvm-objcopy for integration tests.
#
# See https://github.com/libbpf/libbpf-sys/issues/137.
sudo apt -y install \
autopoint \
linux-libc-dev \
liblzma-dev \
llvm \
lynx \
musl-tools \
qemu-system-{arm,x86}
Expand All @@ -305,10 +309,6 @@ jobs:
brew bundle
echo $(brew --prefix curl)/bin >> $GITHUB_PATH
echo $(brew --prefix llvm)/bin >> $GITHUB_PATH
# Point bpf-linker's build.rs to the brew prefixes with static
# libraries it needs.
echo "CXXSTDLIB_PATH=$(brew --prefix llvm)/lib/c++" >> $GITHUB_ENV
echo "ZLIB_PATH=$(brew --prefix zlib)/lib" >> $GITHUB_ENV

# https://github.com/actions/setup-python/issues/577
find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
Expand All @@ -325,60 +325,10 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: Install libLLVM
# Download libLLVM from Rust CI to ensure that the libLLVM version
# matches exactly with the version used by the current Rust nightly. A
# mismatch between libLLVM (used by bpf-linker) and Rust's LLVM version
# can lead to linking issues.
run: |
set -euxo pipefail
# Get the partial SHA from Rust nightly.
rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
# Get the full SHA from GitHub.
rustc_sha=$(curl -sfSL https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
| jq -r '.sha')
mkdir -p /tmp/rustc-llvm
case "${{ runner.arch }}" in
ARM64)
arch=aarch64
;;
X64)
arch=x86_64
;;
*)
echo "::error::Unsupported runner architecture: ${{ runner.arch }}"
exit 1
;;
esac
case "${{ runner.os }}" in
Linux)
target=${arch}-unknown-linux-gnu
;;
macOS)
target=${arch}-apple-darwin
echo "LLVM_LINK_FEATURE=llvm-link-static" >> $GITHUB_ENV
;;
*)
echo "::error::Unsupported runner OS: ${{ runner.os }}"
exit 1
;;
esac
curl -sfSL https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-${target}.tar.xz | \
tar -xJ --strip-components 2 -C /tmp/rustc-llvm
echo /tmp/rustc-llvm/bin >> $GITHUB_PATH

# NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
# --force so that bpf-linker gets always relinked against the latest LLVM downloaded above.
#
# Add the downloaded LLVM to PATH for this build step.
#
# Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so.
- run: |
cargo install \
--git https://github.com/aya-rs/bpf-linker.git bpf-linker \
--no-default-features --features "llvm-22,${LLVM_LINK_FEATURE}" --force
- uses: taiki-e/install-action@v2
with:
tool: cargo-binstall,cargo-hack
- run: cargo binstall --force bpf-linker

- uses: actions/cache@v5
with:
Expand Down
3 changes: 0 additions & 3 deletions Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ brew "autoconf"
brew "automake"
brew "gawk"

# macOS provides only dynamic zlib. Install the static one.
brew "zlib"

# We need a musl C toolchain to compile our `test-distro` since some of our
# dependencies have build scripts that compile C code (i.e xz2).
tap "filosottile/musl-cross"
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
# ebpf crates
"ebpf/aya-ebpf",
"ebpf/aya-ebpf-bindings",
"ebpf/aya-ebpf-cty",
"ebpf/aya-log-ebpf",
"test/integration-ebpf",
]
Expand Down Expand Up @@ -87,7 +88,7 @@ log = { version = "0.4", default-features = false }
network-types = { version = "0.1.0", default-features = false }
nix = { version = "0.31.1", default-features = false }
num_enum = { version = "0.7", default-features = false }
object = { version = "0.38", default-features = false }
object = { version = "0.39", default-features = false }
once_cell = { version = "1.20.1", default-features = false }
proc-macro2 = { version = "1", default-features = false }
proc-macro2-diagnostics = { version = "0.10.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion aya-obj/src/btf/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl Func {
}

pub(crate) fn linkage(&self) -> FuncLinkage {
(self.info & 0xFFF).into()
(self.info & 0xFFFF).into()
}

pub(crate) const fn set_linkage(&mut self, linkage: FuncLinkage) {
Expand Down
54 changes: 33 additions & 21 deletions aya-obj/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use crate::{
},
maps::{BtfMap, BtfMapDef, LegacyMap, MINIMUM_MAP_SIZE, Map, PinningType, bpf_map_def},
programs::{
CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType, XdpAttachType,
CgroupSkbAttachType, CgroupSockAddrAttachType, CgroupSockAttachType,
CgroupSockoptAttachType, SkSkbKind, XdpAttachType,
},
relocation::{INS_SIZE, Relocation, Symbol},
util::HashMap,
Expand Down Expand Up @@ -247,13 +248,14 @@ pub enum ProgramSection {
attach_type: XdpAttachType,
},
SkMsg,
SkSkbStreamParser,
SkSkbStreamVerdict,
SkSkbStream {
kind: SkSkbKind,
},
SockOps,
SchedClassifier,
CgroupSkb,
CgroupSkbIngress,
CgroupSkbEgress,
CgroupSkb {
attach_type: Option<CgroupSkbAttachType>,
},
CgroupSockAddr {
attach_type: CgroupSockAddrAttachType,
},
Expand Down Expand Up @@ -329,34 +331,36 @@ impl FromStr for ProgramSection {
"sk_msg" => Self::SkMsg,
"sk_skb" => {
let name = next()?;
match name {
"stream_parser" => Self::SkSkbStreamParser,
"stream_verdict" => Self::SkSkbStreamVerdict,
let kind = match name {
"stream_parser" => SkSkbKind::StreamParser,
"stream_verdict" => SkSkbKind::StreamVerdict,
_ => {
return Err(ParseError::InvalidProgramSection {
section: section.to_owned(),
});
}
}
};
Self::SkSkbStream { kind }
}
"sockops" => Self::SockOps,
"classifier" => Self::SchedClassifier,
"cgroup_skb" => {
let name = next()?;
match name {
"ingress" => Self::CgroupSkbIngress,
"egress" => Self::CgroupSkbEgress,
let attach_type = Some(match name {
"ingress" => CgroupSkbAttachType::Ingress,
"egress" => CgroupSkbAttachType::Egress,
_ => {
return Err(ParseError::InvalidProgramSection {
section: section.to_owned(),
});
}
}
});
Self::CgroupSkb { attach_type }
}
"cgroup" => {
let name = next()?;
match name {
"skb" => Self::CgroupSkb,
"skb" => Self::CgroupSkb { attach_type: None },
"sysctl" => Self::CgroupSysctl,
"dev" => Self::CgroupDevice,
"getsockopt" => Self::CgroupSockopt {
Expand Down Expand Up @@ -2291,7 +2295,9 @@ mod tests {
assert_matches!(
obj.programs.get("stream_parser"),
Some(Program {
section: ProgramSection::SkSkbStreamParser,
section: ProgramSection::SkSkbStream {
kind: SkSkbKind::StreamParser
},
..
})
);
Expand All @@ -2314,7 +2320,9 @@ mod tests {
assert_matches!(
obj.programs.get("my_parser"),
Some(Program {
section: ProgramSection::SkSkbStreamParser,
section: ProgramSection::SkSkbStream {
kind: SkSkbKind::StreamParser
},
..
})
);
Expand Down Expand Up @@ -2435,7 +2443,9 @@ mod tests {
assert_matches!(
obj.programs.get("ingress"),
Some(Program {
section: ProgramSection::CgroupSkbIngress,
section: ProgramSection::CgroupSkb {
attach_type: Some(CgroupSkbAttachType::Ingress),
},
..
})
);
Expand All @@ -2458,7 +2468,9 @@ mod tests {
assert_matches!(
obj.programs.get("foo"),
Some(Program {
section: ProgramSection::CgroupSkbIngress,
section: ProgramSection::CgroupSkb {
attach_type: Some(CgroupSkbAttachType::Ingress),
},
..
})
);
Expand All @@ -2481,7 +2493,7 @@ mod tests {
assert_matches!(
obj.programs.get("skb"),
Some(Program {
section: ProgramSection::CgroupSkb,
section: ProgramSection::CgroupSkb { attach_type: None },
..
})
);
Expand All @@ -2504,7 +2516,7 @@ mod tests {
assert_matches!(
obj.programs.get("foo"),
Some(Program {
section: ProgramSection::CgroupSkb,
section: ProgramSection::CgroupSkb { attach_type: None },
..
})
);
Expand Down
20 changes: 20 additions & 0 deletions aya-obj/src/programs/cgroup_skb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Cgroup skb programs.
use crate::generated::bpf_attach_type;

/// Defines where to attach a `CgroupSkb` program.
#[derive(Copy, Clone, Debug)]
pub enum CgroupSkbAttachType {
/// Attach to ingress.
Ingress,
/// Attach to egress.
Egress,
}

impl From<CgroupSkbAttachType> for bpf_attach_type {
fn from(s: CgroupSkbAttachType) -> Self {
match s {
CgroupSkbAttachType::Ingress => Self::BPF_CGROUP_INET_INGRESS,
CgroupSkbAttachType::Egress => Self::BPF_CGROUP_INET_EGRESS,
}
}
}
4 changes: 4 additions & 0 deletions aya-obj/src/programs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//! Program struct and type bindings.

pub mod cgroup_skb;
pub mod cgroup_sock;
pub mod cgroup_sock_addr;
pub mod cgroup_sockopt;
pub mod sk_skb;
mod types;
pub mod xdp;

pub use cgroup_skb::CgroupSkbAttachType;
pub use cgroup_sock::CgroupSockAttachType;
pub use cgroup_sock_addr::CgroupSockAddrAttachType;
pub use cgroup_sockopt::CgroupSockoptAttachType;
pub use sk_skb::SkSkbKind;
pub use xdp::XdpAttachType;
Loading
Loading