chore: remove aya_obj -> obj alias

When `aya::obj` was migrated to be its own crate `aya-obj`, the `obj`
alias was created to preserve existing imports that relied on
`crate::obj`.

This resulted in 3 ways to import `aya-obj` objects:
- `use aya_obj::*`
- `use obj::*`
- `use crate::obj::*`

The `obj` alias is now removed to avoid confusion, and all `obj` imports
should now refer to `aya_obj`.
pull/1063/head
Tyrone Wu 4 months ago
parent f9b34fe76f
commit 6c3b2a6b9c
No known key found for this signature in database
GPG Key ID: 978B1A1B79210AD6

@ -11,24 +11,20 @@ use std::{
};
use aya_obj::{
btf::{BtfFeatures, BtfRelocationError},
generated::{BPF_F_SLEEPABLE, BPF_F_XDP_HAS_FRAGS},
btf::{Btf, BtfError, BtfFeatures, BtfRelocationError},
generated::{
bpf_map_type::{self, *},
AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE, AYA_PERF_EVENT_IOC_SET_BPF,
BPF_F_SLEEPABLE, BPF_F_XDP_HAS_FRAGS,
},
relocation::EbpfRelocationError,
EbpfSectionKind, Features,
EbpfSectionKind, Features, Object, ParseError, ProgramSection,
};
use log::{debug, warn};
use thiserror::Error;
use crate::{
generated::{
bpf_map_type::{self, *},
AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE, AYA_PERF_EVENT_IOC_SET_BPF,
},
maps::{Map, MapData, MapError},
obj::{
btf::{Btf, BtfError},
Object, ParseError, ProgramSection,
},
programs::{
BtfTracePoint, CgroupDevice, CgroupSkb, CgroupSkbAttachType, CgroupSock, CgroupSockAddr,
CgroupSockopt, CgroupSysctl, Extension, FEntry, FExit, KProbe, LircMode2, Lsm, PerfEvent,
@ -790,7 +786,7 @@ fn adjust_to_page_size(byte_size: u32, page_size: u32) -> u32 {
#[cfg(test)]
mod tests {
use crate::generated::bpf_map_type::*;
use aya_obj::generated::bpf_map_type::*;
const PAGE_SIZE: u32 = 4096;
const NUM_CPUS: u32 = 4;

@ -86,10 +86,8 @@ pub mod util;
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
use aya_obj as obj;
use aya_obj::generated;
pub use aya_obj::btf::{Btf, BtfError};
pub use bpf::*;
pub use obj::btf::{Btf, BtfError};
pub use object::Endianness;
#[doc(hidden)]
pub use sys::netlink_set_link_up;

@ -81,23 +81,22 @@ mod tests {
use std::io;
use assert_matches::assert_matches;
use aya_obj::generated::{
bpf_cmd,
bpf_map_type::{BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_BLOOM_FILTER},
};
use libc::{EFAULT, ENOENT};
use super::*;
use crate::{
generated::{
bpf_cmd,
bpf_map_type::{BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_BLOOM_FILTER},
},
maps::{
test_utils::{self, new_map},
Map,
},
obj,
sys::{override_syscall, SysResult, Syscall},
};
fn new_obj_map() -> obj::Map {
fn new_obj_map() -> aya_obj::Map {
test_utils::new_obj_map::<u32>(BPF_MAP_TYPE_BLOOM_FILTER)
}

@ -106,23 +106,22 @@ mod tests {
use std::io;
use assert_matches::assert_matches;
use aya_obj::generated::{
bpf_attr, bpf_cmd,
bpf_map_type::{BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_LRU_HASH},
};
use libc::{EFAULT, ENOENT};
use super::*;
use crate::{
generated::{
bpf_attr, bpf_cmd,
bpf_map_type::{BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_LRU_HASH},
},
maps::{
test_utils::{self, new_map},
Map,
},
obj,
sys::{override_syscall, SysResult, Syscall},
};
fn new_obj_map() -> obj::Map {
fn new_obj_map() -> aya_obj::Map {
test_utils::new_obj_map::<u32>(BPF_MAP_TYPE_HASH)
}

@ -151,12 +151,13 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<K, PerCpuValues<V>>
#[cfg(test)]
mod tests {
use super::*;
use crate::{
generated::bpf_map_type::{BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH},
maps::{test_utils, Map},
use aya_obj::generated::bpf_map_type::{
BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH,
};
use super::*;
use crate::maps::{test_utils, Map};
#[test]
fn test_try_from_ok() {
let map = Map::PerCpuHashMap(test_utils::new_map(test_utils::new_obj_map::<u32>(

@ -198,23 +198,22 @@ mod tests {
use std::{io, net::Ipv4Addr};
use assert_matches::assert_matches;
use aya_obj::generated::{
bpf_cmd,
bpf_map_type::{BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_LPM_TRIE},
};
use libc::{EFAULT, ENOENT};
use super::*;
use crate::{
generated::{
bpf_cmd,
bpf_map_type::{BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_LPM_TRIE},
},
maps::{
test_utils::{self, new_map},
Map,
},
obj,
sys::{override_syscall, SysResult, Syscall},
};
fn new_obj_map() -> obj::Map {
fn new_obj_map() -> aya_obj::Map {
test_utils::new_obj_map::<Key<u32>>(BPF_MAP_TYPE_LPM_TRIE)
}

@ -59,13 +59,12 @@ use std::{
ptr,
};
use aya_obj::{generated::bpf_map_type, InvalidTypeBinding};
use aya_obj::{generated::bpf_map_type, parse_map_info, EbpfSectionKind, InvalidTypeBinding};
use libc::{getrlimit, rlim_t, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY};
use log::warn;
use thiserror::Error;
use crate::{
obj::{self, parse_map_info, EbpfSectionKind},
pin::PinError,
sys::{
bpf_create_map, bpf_get_object, bpf_map_freeze, bpf_map_get_fd_by_id, bpf_map_get_next_key,
@ -544,14 +543,14 @@ pub(crate) fn check_v_size<V>(map: &MapData) -> Result<(), MapError> {
/// You should never need to use this unless you're implementing a new map type.
#[derive(Debug)]
pub struct MapData {
obj: obj::Map,
obj: aya_obj::Map,
fd: MapFd,
}
impl MapData {
/// Creates a new map with the provided `name`
pub fn create(
mut obj: obj::Map,
mut obj: aya_obj::Map,
name: &str,
btf_fd: Option<BorrowedFd<'_>>,
) -> Result<Self, MapError> {
@ -599,7 +598,7 @@ impl MapData {
pub(crate) fn create_pinned_by_name<P: AsRef<Path>>(
path: P,
obj: obj::Map,
obj: aya_obj::Map,
name: &str,
btf_fd: Option<BorrowedFd<'_>>,
) -> Result<Self, MapError> {
@ -750,7 +749,7 @@ impl MapData {
fd
}
pub(crate) fn obj(&self) -> &obj::Map {
pub(crate) fn obj(&self) -> &aya_obj::Map {
let Self { obj, fd: _ } = self;
obj
}
@ -951,15 +950,19 @@ impl<T: Pod> Deref for PerCpuValues<T> {
#[cfg(test)]
mod test_utils {
use aya_obj::{
generated::{bpf_cmd, bpf_map_type},
maps::LegacyMap,
EbpfSectionKind,
};
use crate::{
bpf_map_def,
generated::{bpf_cmd, bpf_map_type},
maps::MapData,
obj::{self, maps::LegacyMap, EbpfSectionKind},
sys::{override_syscall, Syscall},
};
pub(super) fn new_map(obj: obj::Map) -> MapData {
pub(super) fn new_map(obj: aya_obj::Map) -> MapData {
override_syscall(|call| match call {
Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_CREATE,
@ -970,8 +973,8 @@ mod test_utils {
MapData::create(obj, "foo", None).unwrap()
}
pub(super) fn new_obj_map<K>(map_type: bpf_map_type) -> obj::Map {
obj::Map::Legacy(LegacyMap {
pub(super) fn new_obj_map<K>(map_type: bpf_map_type) -> aya_obj::Map {
aya_obj::Map::Legacy(LegacyMap {
def: bpf_map_def {
map_type: map_type as u32,
key_size: std::mem::size_of::<K>() as u32,
@ -989,8 +992,8 @@ mod test_utils {
pub(super) fn new_obj_map_with_max_entries<K>(
map_type: bpf_map_type,
max_entries: u32,
) -> obj::Map {
obj::Map::Legacy(LegacyMap {
) -> aya_obj::Map {
aya_obj::Map::Legacy(LegacyMap {
def: bpf_map_def {
map_type: map_type as u32,
key_size: std::mem::size_of::<K>() as u32,
@ -1011,17 +1014,15 @@ mod tests {
use std::os::fd::AsRawFd as _;
use assert_matches::assert_matches;
use aya_obj::generated::{bpf_cmd, bpf_map_info, bpf_map_type};
use libc::{c_char, EFAULT};
fn new_obj_map() -> obj::Map {
test_utils::new_obj_map::<u32>(crate::generated::bpf_map_type::BPF_MAP_TYPE_HASH)
}
use super::*;
use crate::{
generated::bpf_cmd,
sys::{override_syscall, Syscall},
};
use crate::sys::{override_syscall, Syscall};
fn new_obj_map() -> aya_obj::Map {
test_utils::new_obj_map::<u32>(bpf_map_type::BPF_MAP_TYPE_HASH)
}
#[test]
fn test_from_map_id() {
@ -1093,7 +1094,7 @@ mod tests {
// Create with max_entries > nr_cpus is clamped to nr_cpus
assert_matches!(
MapData::create(test_utils::new_obj_map_with_max_entries::<u32>(
crate::generated::bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY,
bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY,
65535,
), "foo", None),
Ok(MapData {
@ -1108,7 +1109,7 @@ mod tests {
// Create with max_entries = 0 is set to nr_cpus
assert_matches!(
MapData::create(test_utils::new_obj_map_with_max_entries::<u32>(
crate::generated::bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY,
bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY,
0,
), "foo", None),
Ok(MapData {
@ -1123,7 +1124,7 @@ mod tests {
// Create with max_entries < nr_cpus is unchanged
assert_matches!(
MapData::create(test_utils::new_obj_map_with_max_entries::<u32>(
crate::generated::bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY,
bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY,
1,
), "foo", None),
Ok(MapData {
@ -1142,8 +1143,6 @@ mod tests {
ignore = "`let map_info = unsafe { &mut *(attr.info.info as *mut bpf_map_info) }` is trying to retag from <wildcard> for Unique permission, but no exposed tags have suitable permission in the borrow stack for this location"
)]
fn test_name() {
use crate::generated::bpf_map_info;
const TEST_NAME: &str = "foo";
override_syscall(|call| match call {
@ -1178,8 +1177,6 @@ mod tests {
ignore = "`let map_info = unsafe { &mut *(attr.info.info as *mut bpf_map_info) }` is trying to retag from <wildcard> for Unique permission, but no exposed tags have suitable permission in the borrow stack for this location"
)]
fn test_loaded_maps() {
use crate::generated::bpf_map_info;
override_syscall(|call| match call {
Syscall::Ebpf {
cmd: bpf_cmd::BPF_MAP_GET_NEXT_ID,

@ -6,15 +6,15 @@ use std::{
sync::atomic::{self, AtomicPtr, Ordering},
};
use aya_obj::generated::{
perf_event_header, perf_event_mmap_page,
perf_event_type::{PERF_RECORD_LOST, PERF_RECORD_SAMPLE},
};
use bytes::BytesMut;
use libc::{munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use thiserror::Error;
use crate::{
generated::{
perf_event_header, perf_event_mmap_page,
perf_event_type::{PERF_RECORD_LOST, PERF_RECORD_SAMPLE},
},
sys::{mmap, perf_event_ioctl, perf_event_open_bpf, SysResult},
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
};

@ -17,10 +17,10 @@ use std::{
sync::atomic::{AtomicU32, AtomicUsize, Ordering},
};
use aya_obj::generated::{BPF_RINGBUF_BUSY_BIT, BPF_RINGBUF_DISCARD_BIT, BPF_RINGBUF_HDR_SZ};
use libc::{munmap, off_t, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use crate::{
generated::{BPF_RINGBUF_BUSY_BIT, BPF_RINGBUF_DISCARD_BIT, BPF_RINGBUF_HDR_SZ},
maps::{MapData, MapError},
sys::{mmap, SyscallError},
util::page_size,

@ -2,8 +2,11 @@
use std::os::fd::AsFd;
use aya_obj::generated::{
bpf_attach_type::BPF_CGROUP_DEVICE, bpf_prog_type::BPF_PROG_TYPE_CGROUP_DEVICE,
};
use crate::{
generated::{bpf_attach_type::BPF_CGROUP_DEVICE, bpf_prog_type::BPF_PROG_TYPE_CGROUP_DEVICE},
programs::{
bpf_prog_get_fd_by_id, define_link_wrapper, load_program, query, CgroupAttachMode, FdLink,
Link, ProgAttachLink, ProgramData, ProgramError, ProgramFd,

@ -2,11 +2,12 @@
use std::{hash::Hash, os::fd::AsFd, path::Path};
use crate::{
generated::{
use aya_obj::generated::{
bpf_attach_type::{BPF_CGROUP_INET_EGRESS, BPF_CGROUP_INET_INGRESS},
bpf_prog_type::BPF_PROG_TYPE_CGROUP_SKB,
},
};
use crate::{
programs::{
define_link_wrapper, load_program, CgroupAttachMode, FdLink, Link, ProgAttachLink,
ProgramData, ProgramError,

@ -2,10 +2,10 @@
use std::{hash::Hash, os::fd::AsFd, path::Path};
use aya_obj::generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK;
pub use aya_obj::programs::CgroupSockAttachType;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK,
programs::{
define_link_wrapper, load_program, CgroupAttachMode, FdLink, Link, ProgAttachLink,
ProgramData, ProgramError,

@ -2,10 +2,10 @@
use std::{hash::Hash, os::fd::AsFd, path::Path};
use aya_obj::generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK_ADDR;
pub use aya_obj::programs::CgroupSockAddrAttachType;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
programs::{
define_link_wrapper, load_program, CgroupAttachMode, FdLink, Link, ProgAttachLink,
ProgramData, ProgramError,

@ -2,10 +2,10 @@
use std::{hash::Hash, os::fd::AsFd, path::Path};
use aya_obj::generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCKOPT;
pub use aya_obj::programs::CgroupSockoptAttachType;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCKOPT,
programs::{
define_link_wrapper, load_program, CgroupAttachMode, FdLink, Link, ProgAttachLink,
ProgramData, ProgramError,

@ -2,8 +2,11 @@
use std::{hash::Hash, os::fd::AsFd};
use aya_obj::generated::{
bpf_attach_type::BPF_CGROUP_SYSCTL, bpf_prog_type::BPF_PROG_TYPE_CGROUP_SYSCTL,
};
use crate::{
generated::{bpf_attach_type::BPF_CGROUP_SYSCTL, bpf_prog_type::BPF_PROG_TYPE_CGROUP_SYSCTL},
programs::{
define_link_wrapper, load_program, CgroupAttachMode, FdLink, Link, ProgAttachLink,
ProgramData, ProgramError,

@ -2,12 +2,14 @@
use std::os::fd::{AsFd as _, BorrowedFd};
use aya_obj::{
btf::BtfKind,
generated::{bpf_attach_type::BPF_CGROUP_INET_INGRESS, bpf_prog_type::BPF_PROG_TYPE_EXT},
};
use object::Endianness;
use thiserror::Error;
use crate::{
generated::{bpf_attach_type::BPF_CGROUP_INET_INGRESS, bpf_prog_type::BPF_PROG_TYPE_EXT},
obj::btf::BtfKind,
programs::{
define_link_wrapper, load_program, FdLink, FdLinkId, ProgramData, ProgramError, ProgramFd,
},

@ -1,12 +1,13 @@
//! Fentry programs.
use crate::{
use aya_obj::{
btf::{Btf, BtfKind},
generated::{bpf_attach_type::BPF_TRACE_FENTRY, bpf_prog_type::BPF_PROG_TYPE_TRACING},
obj::btf::{Btf, BtfKind},
programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
ProgramData, ProgramError,
},
};
use crate::programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId, ProgramData,
ProgramError,
};
/// A program that can be attached to the entry point of (almost) any kernel

@ -1,12 +1,13 @@
//! Fexit programs.
use crate::{
use aya_obj::{
btf::{Btf, BtfKind},
generated::{bpf_attach_type::BPF_TRACE_FEXIT, bpf_prog_type::BPF_PROG_TYPE_TRACING},
obj::btf::{Btf, BtfKind},
programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
ProgramData, ProgramError,
},
};
use crate::programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId, ProgramData,
ProgramError,
};
/// A program that can be attached to the exit point of (almost) anny kernel

@ -6,10 +6,10 @@ use std::{
path::{Path, PathBuf},
};
use aya_obj::generated::{bpf_link_type, bpf_prog_type::BPF_PROG_TYPE_KPROBE};
use thiserror::Error;
use crate::{
generated::{bpf_link_type, bpf_prog_type::BPF_PROG_TYPE_KPROBE},
programs::{
define_link_wrapper, load_program,
perf_attach::{PerfLinkIdInner, PerfLinkInner},

@ -7,13 +7,13 @@ use std::{
path::{Path, PathBuf},
};
use aya_obj::generated::{
bpf_attach_type, BPF_F_AFTER, BPF_F_ALLOW_MULTI, BPF_F_ALLOW_OVERRIDE, BPF_F_BEFORE, BPF_F_ID,
BPF_F_LINK, BPF_F_REPLACE,
};
use thiserror::Error;
use crate::{
generated::{
bpf_attach_type, BPF_F_AFTER, BPF_F_ALLOW_MULTI, BPF_F_ALLOW_OVERRIDE, BPF_F_BEFORE,
BPF_F_ID, BPF_F_LINK, BPF_F_REPLACE,
},
pin::PinError,
programs::{MultiProgLink, MultiProgram, ProgramError, ProgramFd, ProgramId},
sys::{bpf_get_object, bpf_pin_object, bpf_prog_attach, bpf_prog_detach, SyscallError},
@ -521,11 +521,11 @@ mod tests {
use std::{cell::RefCell, fs::File, rc::Rc};
use assert_matches::assert_matches;
use aya_obj::generated::{BPF_F_ALLOW_MULTI, BPF_F_ALLOW_OVERRIDE};
use tempfile::tempdir;
use super::{FdLink, Link, LinkMap};
use crate::{
generated::{BPF_F_ALLOW_MULTI, BPF_F_ALLOW_OVERRIDE},
programs::{CgroupAttachMode, ProgramError},
sys::override_syscall,
};

@ -1,8 +1,11 @@
//! Lirc programs.
use std::os::fd::{AsFd, AsRawFd as _, RawFd};
use aya_obj::generated::{
bpf_attach_type::BPF_LIRC_MODE2, bpf_prog_type::BPF_PROG_TYPE_LIRC_MODE2,
};
use crate::{
generated::{bpf_attach_type::BPF_LIRC_MODE2, bpf_prog_type::BPF_PROG_TYPE_LIRC_MODE2},
programs::{
load_program, query, CgroupAttachMode, Link, ProgramData, ProgramError, ProgramFd,
ProgramInfo,

@ -1,12 +1,13 @@
//! LSM probes.
use crate::{
use aya_obj::{
btf::{Btf, BtfKind},
generated::{bpf_attach_type::BPF_LSM_MAC, bpf_prog_type::BPF_PROG_TYPE_LSM},
obj::btf::{Btf, BtfKind},
programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
ProgramData, ProgramError,
},
};
use crate::programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId, ProgramData,
ProgramError,
};
/// A program that attaches to Linux LSM hooks. Used to implement security policy and

@ -77,6 +77,11 @@ use std::{
sync::Arc,
};
use aya_obj::{
btf::BtfError,
generated::{bpf_attach_type, bpf_link_info, bpf_prog_info, bpf_prog_type},
VerifierLog,
};
use info::impl_info;
pub use info::{loaded_programs, ProgramInfo, ProgramType};
use libc::ENOSPC;
@ -113,9 +118,7 @@ pub use crate::programs::{
xdp::{Xdp, XdpError, XdpFlags},
};
use crate::{
generated::{bpf_attach_type, bpf_link_info, bpf_prog_info, bpf_prog_type},
maps::MapError,
obj::{self, btf::BtfError, VerifierLog},
pin::PinError,
programs::{links::*, perf_attach::*},
sys::{
@ -462,7 +465,7 @@ impl Program {
#[derive(Debug)]
pub(crate) struct ProgramData<T: Link> {
pub(crate) name: Option<String>,
pub(crate) obj: Option<(obj::Program, obj::Function)>,
pub(crate) obj: Option<(aya_obj::Program, aya_obj::Function)>,
pub(crate) fd: Option<ProgramFd>,
pub(crate) links: LinkMap<T>,
pub(crate) expected_attach_type: Option<bpf_attach_type>,
@ -478,7 +481,7 @@ pub(crate) struct ProgramData<T: Link> {
impl<T: Link> ProgramData<T> {
pub(crate) fn new(
name: Option<String>,
obj: (obj::Program, obj::Function),
obj: (aya_obj::Program, aya_obj::Function),
btf_fd: Option<Arc<crate::MockableFd>>,
verifier_log_level: VerifierLogLevel,
) -> Self {
@ -617,12 +620,12 @@ fn load_program<T: Link>(
}
let obj = obj.as_ref().unwrap();
let (
obj::Program {
aya_obj::Program {
license,
kernel_version,
..
},
obj::Function {
aya_obj::Function {
instructions,
func_info,
line_info,

@ -1,8 +1,9 @@
//! Perf attach links.
use std::os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, RawFd};
use aya_obj::generated::bpf_attach_type::BPF_PERF_EVENT;
use crate::{
generated::bpf_attach_type::BPF_PERF_EVENT,
programs::{
probe::{detach_debug_fs, ProbeEvent},
FdLink, Link, ProgramError,

@ -2,18 +2,19 @@
use std::os::fd::AsFd as _;
pub use crate::generated::{
perf_hw_cache_id, perf_hw_cache_op_id, perf_hw_cache_op_result_id, perf_hw_id, perf_sw_ids,
};
use crate::{
generated::{
use aya_obj::generated::{
bpf_link_type,
bpf_prog_type::BPF_PROG_TYPE_PERF_EVENT,
perf_type_id::{
PERF_TYPE_BREAKPOINT, PERF_TYPE_HARDWARE, PERF_TYPE_HW_CACHE, PERF_TYPE_RAW,
PERF_TYPE_SOFTWARE, PERF_TYPE_TRACEPOINT,
},
},
};
pub use aya_obj::generated::{
perf_hw_cache_id, perf_hw_cache_op_id, perf_hw_cache_op_result_id, perf_hw_id, perf_sw_ids,
};
use crate::{
programs::{
links::define_link_wrapper,
load_program, perf_attach,

@ -1,12 +1,11 @@
//! Raw tracepoints.
use std::ffi::CString;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_RAW_TRACEPOINT,
programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
ProgramData, ProgramError,
},
use aya_obj::generated::bpf_prog_type::BPF_PROG_TYPE_RAW_TRACEPOINT;
use crate::programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId, ProgramData,
ProgramError,
};
/// A program that can be attached at a pre-defined kernel trace point.

@ -1,9 +1,10 @@
//! Programmable socket lookup.
use std::os::fd::AsFd;
use aya_obj::generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP};
use super::links::FdLink;
use crate::{
generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP},
programs::{define_link_wrapper, load_program, FdLinkId, ProgramData, ProgramError},
sys::{bpf_link_create, LinkTarget, SyscallError},
};

@ -2,8 +2,11 @@
use std::os::fd::AsFd as _;
use aya_obj::generated::{
bpf_attach_type::BPF_SK_MSG_VERDICT, bpf_prog_type::BPF_PROG_TYPE_SK_MSG,
};
use crate::{
generated::{bpf_attach_type::BPF_SK_MSG_VERDICT, bpf_prog_type::BPF_PROG_TYPE_SK_MSG},
maps::sock::SockMapFd,
programs::{
define_link_wrapper, load_program, CgroupAttachMode, ProgAttachLink, ProgAttachLinkId,

@ -2,11 +2,12 @@
use std::{os::fd::AsFd as _, path::Path};
use crate::{
generated::{
use aya_obj::generated::{
bpf_attach_type::{BPF_SK_SKB_STREAM_PARSER, BPF_SK_SKB_STREAM_VERDICT},
bpf_prog_type::BPF_PROG_TYPE_SK_SKB,
},
};
use crate::{
maps::sock::SockMapFd,
programs::{
define_link_wrapper, load_program, CgroupAttachMode, ProgAttachLink, ProgAttachLinkId,

@ -1,8 +1,11 @@
//! Socket option programs.
use std::os::fd::AsFd;
use aya_obj::generated::{
bpf_attach_type::BPF_CGROUP_SOCK_OPS, bpf_prog_type::BPF_PROG_TYPE_SOCK_OPS,
};
use crate::{
generated::{bpf_attach_type::BPF_CGROUP_SOCK_OPS, bpf_prog_type::BPF_PROG_TYPE_SOCK_OPS},
programs::{
define_link_wrapper, load_program, CgroupAttachMode, FdLink, Link, ProgAttachLink,
ProgramData, ProgramError,

@ -4,13 +4,13 @@ use std::{
os::fd::{AsFd, AsRawFd, RawFd},
};
use aya_obj::generated::{
bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER, SO_ATTACH_BPF, SO_DETACH_BPF,
};
use libc::{setsockopt, SOL_SOCKET};
use thiserror::Error;
use crate::{
generated::{bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER, SO_ATTACH_BPF, SO_DETACH_BPF},
programs::{load_program, Link, ProgramData, ProgramError},
};
use crate::programs::{load_program, Link, ProgramData, ProgramError};
/// The type returned when attaching a [`SocketFilter`] fails.
#[derive(Debug, Error)]

@ -6,16 +6,16 @@ use std::{
path::Path,
};
use thiserror::Error;
use super::{FdLink, ProgramInfo};
use crate::{
generated::{
use aya_obj::generated::{
bpf_attach_type::{self, BPF_TCX_EGRESS, BPF_TCX_INGRESS},
bpf_link_type,
bpf_prog_type::BPF_PROG_TYPE_SCHED_CLS,
TC_H_CLSACT, TC_H_MIN_EGRESS, TC_H_MIN_INGRESS,
},
};
use thiserror::Error;
use super::{FdLink, ProgramInfo};
use crate::{
programs::{
define_link_wrapper, load_program, query, Link, LinkError, LinkOrder, ProgramData,
ProgramError,

@ -1,12 +1,13 @@
//! BTF-enabled raw tracepoints.
use crate::{
use aya_obj::{
btf::{Btf, BtfKind},
generated::{bpf_attach_type::BPF_TRACE_RAW_TP, bpf_prog_type::BPF_PROG_TYPE_TRACING},
obj::btf::{Btf, BtfKind},
programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
ProgramData, ProgramError,
},
};
use crate::programs::{
define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId, ProgramData,
ProgramError,
};
/// Marks a function as a [BTF-enabled raw tracepoint][1] eBPF program that can be attached at

@ -1,10 +1,10 @@
//! Tracepoint programs.
use std::{fs, io, os::fd::AsFd as _, path::Path};
use aya_obj::generated::{bpf_link_type, bpf_prog_type::BPF_PROG_TYPE_TRACEPOINT};
use thiserror::Error;
use crate::{
generated::{bpf_link_type, bpf_prog_type::BPF_PROG_TYPE_TRACEPOINT},
programs::{
define_link_wrapper, load_program,
perf_attach::{perf_attach, PerfLinkIdInner, PerfLinkInner},

@ -11,12 +11,12 @@ use std::{
sync::LazyLock,
};
use aya_obj::generated::{bpf_link_type, bpf_prog_type::BPF_PROG_TYPE_KPROBE};
use libc::pid_t;
use object::{Object, ObjectSection, ObjectSymbol, Symbol};
use thiserror::Error;
use crate::{
generated::{bpf_link_type, bpf_prog_type::BPF_PROG_TYPE_KPROBE},
programs::{
define_link_wrapper, load_program,
perf_attach::{PerfLinkIdInner, PerfLinkInner},

@ -8,15 +8,17 @@ use std::{
path::Path,
};
use libc::if_nametoindex;
use thiserror::Error;
use crate::{
use aya_obj::{
generated::{
bpf_link_type, bpf_prog_type, XDP_FLAGS_DRV_MODE, XDP_FLAGS_HW_MODE, XDP_FLAGS_REPLACE,
XDP_FLAGS_SKB_MODE, XDP_FLAGS_UPDATE_IF_NOEXIST,
},
obj::programs::XdpAttachType,
programs::XdpAttachType,
};
use libc::if_nametoindex;
use thiserror::Error;
use crate::{
programs::{
define_link_wrapper, load_program, FdLink, Link, LinkError, ProgramData, ProgramError,
},

@ -8,28 +8,24 @@ use std::{
};
use assert_matches::assert_matches;
use libc::{ENOENT, ENOSPC};
use obj::{
btf::{BtfEnum64, Enum64},
generated::bpf_stats_type,
use aya_obj::{
btf::{
BtfEnum64, BtfParam, BtfType, DataSec, DataSecEntry, DeclTag, Enum64, Float, Func,
FuncLinkage, FuncProto, FuncSecInfo, Int, IntEncoding, LineSecInfo, Ptr, TypeTag, Var,
VarLinkage,
},
copy_instructions,
generated::{
bpf_attach_type, bpf_attr, bpf_btf_info, bpf_cmd, bpf_insn, bpf_link_info, bpf_map_info,
bpf_map_type, bpf_prog_info, bpf_prog_type, bpf_stats_type, BPF_F_REPLACE,
},
maps::{bpf_map_def, LegacyMap},
EbpfSectionKind, VerifierLog,
};
use libc::{ENOENT, ENOSPC};
use crate::{
generated::{
bpf_attach_type, bpf_attr, bpf_btf_info, bpf_cmd, bpf_insn, bpf_link_info, bpf_map_info,
bpf_map_type, bpf_prog_info, bpf_prog_type, BPF_F_REPLACE,
},
maps::{MapData, PerCpuValues},
obj::{
self,
btf::{
BtfParam, BtfType, DataSec, DataSecEntry, DeclTag, Float, Func, FuncLinkage, FuncProto,
FuncSecInfo, Int, IntEncoding, LineSecInfo, Ptr, TypeTag, Var, VarLinkage,
},
copy_instructions,
},
programs::links::LinkRef,
sys::{syscall, SysResult, Syscall, SyscallError},
util::KernelVersion,
@ -38,7 +34,7 @@ use crate::{
pub(crate) fn bpf_create_map(
name: &CStr,
def: &obj::Map,
def: &aya_obj::Map,
btf_fd: Option<BorrowedFd<'_>>,
kernel_version: KernelVersion,
) -> SysResult<crate::MockableFd> {
@ -51,7 +47,7 @@ pub(crate) fn bpf_create_map(
u.max_entries = def.max_entries();
u.map_flags = def.map_flags();
if let obj::Map::Btf(m) = def {
if let aya_obj::Map::Btf(m) = def {
use bpf_map_type::*;
// Mimic https://github.com/libbpf/libbpf/issues/355
@ -901,7 +897,7 @@ pub(crate) fn is_bpf_global_data_supported() -> bool {
let mut insns = copy_instructions(prog).unwrap();
let map = MapData::create(
obj::Map::Legacy(LegacyMap {
aya_obj::Map::Legacy(LegacyMap {
def: bpf_map_def {
map_type: bpf_map_type::BPF_MAP_TYPE_ARRAY as u32,
key_size: 4,

@ -13,6 +13,7 @@ use std::{
os::fd::{AsRawFd as _, BorrowedFd, OwnedFd},
};
use aya_obj::generated::{bpf_attr, bpf_cmd, perf_event_attr};
pub(crate) use bpf::*;
#[cfg(test)]
pub(crate) use fake::*;
@ -23,8 +24,6 @@ pub(crate) use netlink::*;
pub(crate) use perf_event::*;
use thiserror::Error;
use crate::generated::{bpf_attr, bpf_cmd, perf_event_attr};
pub(crate) type SysResult<T> = Result<T, (i64, io::Error)>;
pub(crate) enum Syscall<'a> {
@ -152,9 +151,9 @@ pub enum Stats {
RunTime,
}
impl From<Stats> for crate::generated::bpf_stats_type {
impl From<Stats> for aya_obj::generated::bpf_stats_type {
fn from(value: Stats) -> Self {
use crate::generated::bpf_stats_type::*;
use aya_obj::generated::bpf_stats_type::*;
match value {
Stats::RunTime => BPF_STATS_RUN_TIME,

@ -6,6 +6,11 @@ use std::{
ptr, slice,
};
use aya_obj::generated::{
ifinfomsg, tcmsg, IFLA_XDP_EXPECTED_FD, IFLA_XDP_FD, IFLA_XDP_FLAGS, NLMSG_ALIGNTO, TCA_BPF_FD,
TCA_BPF_FLAGS, TCA_BPF_FLAG_ACT_DIRECT, TCA_BPF_NAME, TCA_KIND, TCA_OPTIONS, TC_H_CLSACT,
TC_H_INGRESS, TC_H_MAJ_MASK, TC_H_UNSPEC, XDP_FLAGS_REPLACE,
};
use libc::{
getsockname, nlattr, nlmsgerr, nlmsghdr, recv, send, setsockopt, sockaddr_nl, socket,
AF_NETLINK, AF_UNSPEC, ETH_P_ALL, IFF_UP, IFLA_XDP, NETLINK_EXT_ACK, NETLINK_ROUTE,
@ -15,15 +20,7 @@ use libc::{
};
use thiserror::Error;
use crate::{
generated::{
ifinfomsg, tcmsg, IFLA_XDP_EXPECTED_FD, IFLA_XDP_FD, IFLA_XDP_FLAGS, NLMSG_ALIGNTO,
TCA_BPF_FD, TCA_BPF_FLAGS, TCA_BPF_FLAG_ACT_DIRECT, TCA_BPF_NAME, TCA_KIND, TCA_OPTIONS,
TC_H_CLSACT, TC_H_INGRESS, TC_H_MAJ_MASK, TC_H_UNSPEC, XDP_FLAGS_REPLACE,
},
programs::TcAttachType,
util::tc_handler_make,
};
use crate::{programs::TcAttachType, util::tc_handler_make};
const NLA_HDR_LEN: usize = align_to(mem::size_of::<nlattr>(), NLA_ALIGNTO as usize);

@ -4,16 +4,16 @@ use std::{
os::fd::{BorrowedFd, FromRawFd as _},
};
use libc::pid_t;
use super::{syscall, SysResult, Syscall};
use crate::generated::{
use aya_obj::generated::{
perf_event_attr,
perf_event_sample_format::PERF_SAMPLE_RAW,
perf_sw_ids::PERF_COUNT_SW_BPF_OUTPUT,
perf_type_id::{PERF_TYPE_SOFTWARE, PERF_TYPE_TRACEPOINT},
PERF_FLAG_FD_CLOEXEC,
};
use libc::pid_t;
use super::{syscall, SysResult, Syscall};
#[allow(clippy::too_many_arguments)]
pub(crate) fn perf_event_open(

@ -12,12 +12,10 @@ use std::{
str::{FromStr, Utf8Error},
};
use aya_obj::generated::{TC_H_MAJ_MASK, TC_H_MIN_MASK};
use libc::{if_nametoindex, sysconf, uname, utsname, _SC_PAGESIZE};
use crate::{
generated::{TC_H_MAJ_MASK, TC_H_MIN_MASK},
Pod,
};
use crate::Pod;
/// Represents a kernel version, in major.minor.release version.
// Adapted from https://docs.rs/procfs/latest/procfs/sys/kernel/struct.Version.html.

Loading…
Cancel
Save