From fda52601721643b2b3a9065c2f69709dbfeea6fc Mon Sep 17 00:00:00 2001 From: Kensuke Kubo Date: Tue, 5 Jul 2022 15:45:31 +0900 Subject: [PATCH 1/2] fix: Bpf -> Ebpf, BpfLoader -> EbpfLoader --- docs/index.md | 8 ++++---- examples/aya-gen/myapp/src/main.rs | 6 +++--- examples/lsm-nice/lsm-nice/src/main.rs | 6 +++--- examples/myapp-01/myapp/src/main.rs | 8 ++++---- examples/myapp-02/myapp/src/main.rs | 8 ++++---- examples/myapp-03/myapp/src/main.rs | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/index.md b/docs/index.md index a53f651..a08004b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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()?; diff --git a/examples/aya-gen/myapp/src/main.rs b/examples/aya-gen/myapp/src/main.rs index 1d8967a..932bd07 100644 --- a/examples/aya-gen/myapp/src/main.rs +++ b/examples/aya-gen/myapp/src/main.rs @@ -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}, @@ -25,8 +25,8 @@ 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 bpf = Ebpf::load(include_bytes_aligned!( "../../target/bpfel-unknown-none/release/myapp" ))?; let btf = Btf::from_sys_fs()?; diff --git a/examples/lsm-nice/lsm-nice/src/main.rs b/examples/lsm-nice/lsm-nice/src/main.rs index 01ffcec..b171e27 100644 --- a/examples/lsm-nice/lsm-nice/src/main.rs +++ b/examples/lsm-nice/lsm-nice/src/main.rs @@ -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, @@ -26,9 +26,9 @@ 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 bpf = EbpfLoader::new().set_global("PID", &pid).load( include_bytes_aligned!( "../../target/bpfel-unknown-none/release/lsm-nice" ), diff --git a/examples/myapp-01/myapp/src/main.rs b/examples/myapp-01/myapp/src/main.rs index 0ce1d2d..f040845 100644 --- a/examples/myapp-01/myapp/src/main.rs +++ b/examples/myapp-01/myapp/src/main.rs @@ -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; @@ -30,15 +30,15 @@ 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 bpf = 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 bpf = Ebpf::load(include_bytes_aligned!( "../../target/bpfel-unknown-none/release/myapp" ))?; BpfLogger::init(&mut bpf)?; diff --git a/examples/myapp-02/myapp/src/main.rs b/examples/myapp-02/myapp/src/main.rs index f1ec04c..e36a6c9 100644 --- a/examples/myapp-02/myapp/src/main.rs +++ b/examples/myapp-02/myapp/src/main.rs @@ -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; @@ -23,13 +23,13 @@ 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 bpf = 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 bpf = Ebpf::load(include_bytes_aligned!( "../../target/bpfel-unknown-none/release/myapp" ))?; // (1) diff --git a/examples/myapp-03/myapp/src/main.rs b/examples/myapp-03/myapp/src/main.rs index 11563d7..e9361bf 100644 --- a/examples/myapp-03/myapp/src/main.rs +++ b/examples/myapp-03/myapp/src/main.rs @@ -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, HashMap}; @@ -23,13 +23,13 @@ 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 bpf = 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 bpf = Ebpf::load(include_bytes_aligned!( "../../target/bpfel-unknown-none/release/myapp" ))?; let program: &mut Xdp = bpf.program_mut("xdp").unwrap().try_into()?; From 2da9b35704fa55ab0f3b3d6ae49ff18563f42e0c Mon Sep 17 00:00:00 2001 From: Kensuke Kubo Date: Tue, 5 Jul 2022 15:56:37 +0900 Subject: [PATCH 2/2] fix: variables name: bpf -> ebpf --- examples/aya-gen/myapp/src/main.rs | 4 ++-- examples/lsm-nice/lsm-nice/src/main.rs | 4 ++-- examples/myapp-01/myapp/src/main.rs | 8 ++++---- examples/myapp-02/myapp/src/main.rs | 8 ++++---- examples/myapp-03/myapp/src/main.rs | 17 +++++++++-------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/aya-gen/myapp/src/main.rs b/examples/aya-gen/myapp/src/main.rs index 932bd07..5a81230 100644 --- a/examples/aya-gen/myapp/src/main.rs +++ b/examples/aya-gen/myapp/src/main.rs @@ -26,12 +26,12 @@ fn try_main() -> Result<(), anyhow::Error> { // 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 `Ebpf::load_file` instead. - let mut bpf = Ebpf::load(include_bytes_aligned!( + 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()?; diff --git a/examples/lsm-nice/lsm-nice/src/main.rs b/examples/lsm-nice/lsm-nice/src/main.rs index b171e27..2be0a3c 100644 --- a/examples/lsm-nice/lsm-nice/src/main.rs +++ b/examples/lsm-nice/lsm-nice/src/main.rs @@ -28,14 +28,14 @@ async fn main() -> Result<(), anyhow::Error> { // like to specify the eBPF program at runtime rather than at compile-time, you can // reach for `Ebpf::load_file` instead. // (2) - let mut bpf = EbpfLoader::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()?; diff --git a/examples/myapp-01/myapp/src/main.rs b/examples/myapp-01/myapp/src/main.rs index f040845..d95fe8c 100644 --- a/examples/myapp-01/myapp/src/main.rs +++ b/examples/myapp-01/myapp/src/main.rs @@ -34,16 +34,16 @@ async fn main() -> Result<(), anyhow::Error> { // (4) // (5) #[cfg(debug_assertions)] - let mut bpf = Ebpf::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 = Ebpf::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()) diff --git a/examples/myapp-02/myapp/src/main.rs b/examples/myapp-02/myapp/src/main.rs index e36a6c9..b5c9fd7 100644 --- a/examples/myapp-02/myapp/src/main.rs +++ b/examples/myapp-02/myapp/src/main.rs @@ -25,21 +25,21 @@ async fn main() -> Result<(), anyhow::Error> { // like to specify the eBPF program at runtime rather than at compile-time, you can // reach for `Ebpf::load_file` instead. #[cfg(debug_assertions)] - let mut bpf = Ebpf::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 = Ebpf::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) diff --git a/examples/myapp-03/myapp/src/main.rs b/examples/myapp-03/myapp/src/main.rs index e9361bf..49faa62 100644 --- a/examples/myapp-03/myapp/src/main.rs +++ b/examples/myapp-03/myapp/src/main.rs @@ -1,11 +1,11 @@ -use aya::{include_bytes_aligned, Ebpf}; 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; @@ -25,21 +25,21 @@ async fn main() -> Result<(), anyhow::Error> { // like to specify the eBPF program at runtime rather than at compile-time, you can // reach for `Ebpf::load_file` instead. #[cfg(debug_assertions)] - let mut bpf = Ebpf::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 = Ebpf::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()?; @@ -47,7 +47,8 @@ async fn main() -> Result<(), anyhow::Error> { // (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)?;