Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Bpf to Ebpf and BpfLoader to EbpfLoader #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ Aya supports a large chunk of the eBPF API. The following example shows how to u
```rust linenums="1"
use std::fs::File;
use std::convert::TryInto;
use aya::Bpf;
use aya::Ebpf;
use aya::programs::{CgroupSkb, CgroupSkbAttachType};

// load the BPF code
let mut bpf = Bpf::load_file("bpf.o")?;
// get the `ingress_filter` program compiled into `bpf.o`.
let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?;
let mut ebpf = Ebpf::load_file("ebpf.o")?;
// get the `ingress_filter` program compiled into `ebpf.o`.
let ingress: &mut CgroupSkb = ebpf.program_mut("ingress_filter")?.try_into()?;

// load the program into the kernel
ingress.load()?;
Expand Down
8 changes: 4 additions & 4 deletions examples/aya-gen/myapp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aya::{include_bytes_aligned, programs::Lsm, Bpf, Btf};
use aya::{include_bytes_aligned, programs::Lsm, Ebpf, Btf};
use std::{
sync::{
atomic::{AtomicBool, Ordering},
Expand All @@ -25,13 +25,13 @@ fn try_main() -> Result<(), anyhow::Error> {
// This will include your eBPF object file as raw bytes at compile-time and load it at
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
let mut bpf = Bpf::load(include_bytes_aligned!(
// reach for `Ebpf::load_file` instead.
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/myapp"
))?;
let btf = Btf::from_sys_fs()?;
let program: &mut Lsm =
bpf.program_mut("task_alloc").unwrap().try_into()?;
ebpf.program_mut("task_alloc").unwrap().try_into()?;
program.load("task_alloc", &btf)?;
program.attach()?;

Expand Down
8 changes: 4 additions & 4 deletions examples/lsm-nice/lsm-nice/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::process;

use aya::{include_bytes_aligned, programs::Lsm, BpfLoader, Btf};
use aya::{include_bytes_aligned, programs::Lsm, EbpfLoader, Btf};
use log::info;
use simplelog::{
ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode,
Expand All @@ -26,16 +26,16 @@ async fn main() -> Result<(), anyhow::Error> {
// This will include your eBPF object file as raw bytes at compile-time and load it at
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
// reach for `Ebpf::load_file` instead.
// (2)
let mut bpf = BpfLoader::new().set_global("PID", &pid).load(
let mut ebpf = EbpfLoader::new().set_global("PID", &pid).load(
include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/lsm-nice"
),
)?;
let btf = Btf::from_sys_fs()?;
let program: &mut Lsm =
bpf.program_mut("task_setnice").unwrap().try_into()?;
ebpf.program_mut("task_setnice").unwrap().try_into()?;
program.load("task_setnice", &btf)?;
program.attach()?;

Expand Down
12 changes: 6 additions & 6 deletions examples/myapp-01/myapp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aya::{include_bytes_aligned, Bpf};
use aya::{include_bytes_aligned, Ebpf};
use anyhow::Context;
use aya::programs::{Xdp, XdpFlags};
use aya_log::BpfLogger;
Expand Down Expand Up @@ -30,20 +30,20 @@ async fn main() -> Result<(), anyhow::Error> {
// This will include your eBPF object file as raw bytes at compile-time and load it at
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
// reach for `Ebpf::load_file` instead.
// (4)
// (5)
#[cfg(debug_assertions)]
let mut bpf = Bpf::load(include_bytes_aligned!(
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/myapp"
))?;
#[cfg(not(debug_assertions))]
let mut bpf = Bpf::load(include_bytes_aligned!(
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/myapp"
))?;
BpfLogger::init(&mut bpf)?;
BpfLogger::init(&mut ebpf)?;
// (6)
let program: &mut Xdp = bpf.program_mut("myapp").unwrap().try_into()?;
let program: &mut Xdp = ebpf.program_mut("myapp").unwrap().try_into()?;
program.load()?; // (7)
// (8)
program.attach(&opt.iface, XdpFlags::default())
Expand Down
12 changes: 6 additions & 6 deletions examples/myapp-02/myapp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aya::{include_bytes_aligned, Bpf};
use aya::{include_bytes_aligned, Ebpf};
use anyhow::Context;
use aya::programs::{Xdp, XdpFlags};
use aya::maps::perf::AsyncPerfEventArray;
Expand All @@ -23,23 +23,23 @@ async fn main() -> Result<(), anyhow::Error> {
// This will include your eBPF object file as raw bytes at compile-time and load it at
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
// reach for `Ebpf::load_file` instead.
#[cfg(debug_assertions)]
let mut bpf = Bpf::load(include_bytes_aligned!(
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/myapp"
))?;
#[cfg(not(debug_assertions))]
let mut bpf = Bpf::load(include_bytes_aligned!(
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/myapp"
))?;
// (1)
let program: &mut Xdp = bpf.program_mut("xdp").unwrap().try_into()?;
let program: &mut Xdp = ebpf.program_mut("xdp").unwrap().try_into()?;
program.load()?;
program.attach(&opt.iface, XdpFlags::default())
.context("failed to attach the XDP program with default flags - try changing XdpFlags::default() to XdpFlags::SKB_MODE")?;

// (2)
let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("EVENTS")?)?;
let mut perf_array = AsyncPerfEventArray::try_from(ebpf.map_mut("EVENTS")?)?;

for cpu_id in online_cpus()? {
// (3)
Expand Down
19 changes: 10 additions & 9 deletions examples/myapp-03/myapp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use aya::{include_bytes_aligned, Bpf};
use anyhow::Context;
use aya::programs::{Xdp, XdpFlags};
use aya::maps::{perf::AsyncPerfEventArray, HashMap};
use aya::programs::{Xdp, XdpFlags};
use aya::util::online_cpus;
use aya::{include_bytes_aligned, Ebpf};
use bytes::BytesMut;
use std::net::{self, Ipv4Addr};
use clap::Parser;
use std::net::{self, Ipv4Addr};
use tokio::{signal, task};

use myapp_common::PacketLog;
Expand All @@ -23,31 +23,32 @@ async fn main() -> Result<(), anyhow::Error> {
// This will include your eBPF object file as raw bytes at compile-time and load it at
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
// reach for `Ebpf::load_file` instead.
#[cfg(debug_assertions)]
let mut bpf = Bpf::load(include_bytes_aligned!(
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/myapp"
))?;
#[cfg(not(debug_assertions))]
let mut bpf = Bpf::load(include_bytes_aligned!(
let mut ebpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/myapp"
))?;
let program: &mut Xdp = bpf.program_mut("xdp").unwrap().try_into()?;
let program: &mut Xdp = ebpf.program_mut("xdp").unwrap().try_into()?;
program.load()?;
program.attach(&opt.iface, XdpFlags::default())
.context("failed to attach the XDP program with default flags - try changing XdpFlags::default() to XdpFlags::SKB_MODE")?;

// (1)
let mut blocklist: HashMap<_, u32, u32> =
HashMap::try_from(bpf.map_mut("BLOCKLIST")?)?;
HashMap::try_from(ebpf.map_mut("BLOCKLIST")?)?;

// (2)
let block_addr: u32 = Ipv4Addr::new(1, 1, 1, 1).try_into()?;

// (3)
blocklist.insert(block_addr, 0, 0)?;

let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("EVENTS")?)?;
let mut perf_array =
AsyncPerfEventArray::try_from(ebpf.map_mut("EVENTS")?)?;

for cpu_id in online_cpus()? {
let mut buf = perf_array.open(cpu_id, None)?;
Expand Down