rustfmt: group_imports = "StdExternalCrate"

High time we stop debating this; let the robots do the work.
pull/797/head
Tamir Duberstein 12 months ago
parent 67863833ca
commit d16e607fd4
No known key found for this signature in database

@ -45,9 +45,10 @@ impl BtfTracePoint {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_btf_tracepoint() {
let prog = BtfTracePoint::parse(

@ -34,9 +34,10 @@ impl CgroupDevice {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_cgroup_device() {
let prog = CgroupDevice::parse(

@ -48,9 +48,10 @@ impl CgroupSkb {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn cgroup_skb() {
let prog = CgroupSkb::parse(

@ -46,9 +46,10 @@ impl CgroupSock {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn cgroup_sock_post_bind4() {
let prog = CgroupSock::parse(

@ -48,9 +48,10 @@ impl CgroupSockAddr {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn cgroup_sock_addr_connect4() {
let prog = CgroupSockAddr::parse(

@ -46,9 +46,10 @@ impl CgroupSockopt {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn cgroup_sockopt_getsockopt() {
let prog = CgroupSockopt::parse(

@ -34,9 +34,10 @@ impl CgroupSysctl {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_cgroup_sysctl() {
let prog = CgroupSysctl::parse(

@ -51,9 +51,10 @@ impl FEntry {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_fentry() {
let prog = FEntry::parse(

@ -51,9 +51,10 @@ impl FExit {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_fexit() {
let prog = FExit::parse(

@ -1,7 +1,6 @@
use std::borrow::Cow;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{ItemFn, Result};
@ -79,9 +78,10 @@ impl KProbe {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_kprobe() {
let kprobe = KProbe::parse(

@ -44,10 +44,9 @@ use sk_msg::SkMsg;
use sk_skb::{SkSkb, SkSkbKind};
use sock_ops::SockOps;
use socket_filter::SocketFilter;
use uprobe::{UProbe, UProbeKind};
use tc::SchedClassifier;
use tracepoint::TracePoint;
use uprobe::{UProbe, UProbeKind};
use xdp::Xdp;
#[proc_macro_error]
#[proc_macro_attribute]

@ -53,9 +53,10 @@ impl Lsm {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_lsm_sleepable() {
let prog = Lsm::parse(

@ -2,11 +2,9 @@ use std::borrow::Cow;
use proc_macro2::TokenStream;
use quote::quote;
use syn::Result;
use syn::{ItemStatic, Result};
use crate::args::name_arg;
use syn::ItemStatic;
pub(crate) struct Map {
item: ItemStatic,
name: String,
@ -34,9 +32,10 @@ impl Map {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_map_with_name() {
let map = Map::parse(

@ -35,9 +35,10 @@ impl PerfEvent {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_perf_event() {
let prog = PerfEvent::parse(

@ -1,7 +1,6 @@
use std::borrow::Cow;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{ItemFn, Result};
@ -45,9 +44,10 @@ impl RawTracePoint {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_raw_tracepoint() {
let prog = RawTracePoint::parse(

@ -34,9 +34,10 @@ impl SkLookup {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_sk_lookup() {
let prog = SkLookup::parse(

@ -34,9 +34,10 @@ impl SkMsg {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_sk_msg() {
let prog = SkMsg::parse(

@ -56,9 +56,10 @@ impl SkSkb {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_stream_parser() {
let prog = SkSkb::parse(

@ -34,9 +34,10 @@ impl SockOps {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_sock_ops() {
let prog = SockOps::parse(

@ -34,9 +34,10 @@ impl SocketFilter {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_socket_filter() {
let prog = SocketFilter::parse(

@ -34,9 +34,10 @@ impl SchedClassifier {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_sched_classifier() {
let prog = SchedClassifier::parse(

@ -52,9 +52,10 @@ impl TracePoint {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_tracepoint() {
let prog = TracePoint::parse(

@ -104,9 +104,10 @@ impl UProbe {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn uprobe() {
let uprobe = UProbe::parse(

@ -64,9 +64,10 @@ impl Xdp {
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
use super::*;
#[test]
fn test_xdp() {
let prog = Xdp::parse(

@ -1,3 +1,5 @@
use aya_log_common::DisplayHint;
use aya_log_parser::{parse, Fragment};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{
@ -6,9 +8,6 @@ use syn::{
Error, Expr, LitStr, Result, Token,
};
use aya_log_common::DisplayHint;
use aya_log_parser::{parse, Fragment};
pub(crate) struct LogArgs {
pub(crate) ctx: Expr,
pub(crate) target: Option<Expr>,

@ -59,13 +59,6 @@ use std::{
const MAP_NAME: &str = "AYA_LOGS";
use aya_log_common::{
Argument, DisplayHint, Level, LogValueLength, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS,
};
use bytes::BytesMut;
use log::{error, Log, Record};
use thiserror::Error;
use aya::{
maps::{
perf::{AsyncPerfEventArray, Events, PerfBufferError},
@ -74,6 +67,12 @@ use aya::{
util::online_cpus,
Bpf, Pod,
};
use aya_log_common::{
Argument, DisplayHint, Level, LogValueLength, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS,
};
use bytes::BytesMut;
use log::{error, Log, Record};
use thiserror::Error;
#[derive(Copy, Clone)]
#[repr(transparent)]
@ -563,10 +562,11 @@ fn try_read<T: Pod>(mut buf: &[u8]) -> Result<(T, &[u8], &[u8]), ()> {
#[cfg(test)]
mod test {
use super::*;
use aya_log_common::{write_record_header, WriteToBuf};
use log::{logger, Level};
use super::*;
fn new_log(args: usize) -> Option<(usize, Vec<u8>)> {
let mut buf = vec![0; 8192];
let len = write_record_header(

@ -1,5 +1,3 @@
use core::{ffi::CStr, mem, ptr};
use alloc::{
borrow::{Cow, ToOwned as _},
format,
@ -7,11 +5,14 @@ use alloc::{
vec,
vec::Vec,
};
use bytes::BufMut;
use core::{ffi::CStr, mem, ptr};
use bytes::BufMut;
use log::debug;
use object::{Endianness, SectionIndex};
#[cfg(not(feature = "std"))]
use crate::std;
use crate::{
btf::{
info::{FuncSecInfo, LineSecInfo},
@ -24,9 +25,6 @@ use crate::{
Object,
};
#[cfg(not(feature = "std"))]
use crate::std;
pub(crate) const MAX_RESOLVE_DEPTH: u8 = 32;
pub(crate) const MAX_SPEC_LEN: usize = 64;
@ -1102,12 +1100,13 @@ pub(crate) struct SecInfo<'a> {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use super::*;
use crate::btf::{
BtfEnum64, BtfParam, DataSec, DataSecEntry, DeclTag, Enum64, Float, Func, FuncProto, Ptr,
TypeTag, Var,
};
use assert_matches::assert_matches;
#[test]
fn test_parse_header() {

@ -1,4 +1,5 @@
use alloc::{string::String, vec, vec::Vec};
use bytes::BufMut;
use object::Endianness;

@ -1,5 +1,3 @@
use core::{mem, ops::Bound::Included, ptr};
use alloc::{
borrow::{Cow, ToOwned as _},
collections::BTreeMap,
@ -8,8 +6,12 @@ use alloc::{
vec,
vec::Vec,
};
use core::{mem, ops::Bound::Included, ptr};
use object::SectionIndex;
#[cfg(not(feature = "std"))]
use crate::std;
use crate::{
btf::{
fields_are_compatible, types_are_compatible, Array, Btf, BtfError, BtfMember, BtfType,
@ -23,9 +25,6 @@ use crate::{
Function, Object,
};
#[cfg(not(feature = "std"))]
use crate::std;
/// The error type returned by [`Object::relocate_btf`].
#[derive(thiserror::Error, Debug)]
#[error("error relocating `{section}`")]

@ -1,8 +1,8 @@
#![allow(missing_docs)]
use alloc::{string::ToString, vec, vec::Vec};
use core::{fmt::Display, mem, ptr};
use alloc::{string::ToString, vec, vec::Vec};
use object::Endianness;
use crate::btf::{Btf, BtfError, MAX_RESOLVE_DEPTH};
@ -1570,9 +1570,10 @@ fn bytes_of<T>(val: &T) -> &[u8] {
}
#[cfg(test)]
mod tests {
use super::*;
use assert_matches::assert_matches;
use super::*;
#[test]
fn test_read_btf_type_int() {
let endianness = Endianness::default();

@ -21,15 +21,11 @@ mod linux_bindings_x86_64;
// don't re-export __u8 __u16 etc which are already exported by the
// linux_bindings_* module
pub use btf_internal_bindings::{bpf_core_relo, bpf_core_relo_kind, btf_ext_header};
#[cfg(target_arch = "x86_64")]
pub use linux_bindings_x86_64::*;
#[cfg(target_arch = "arm")]
pub use linux_bindings_armv7::*;
#[cfg(target_arch = "aarch64")]
pub use linux_bindings_aarch64::*;
#[cfg(target_arch = "arm")]
pub use linux_bindings_armv7::*;
#[cfg(target_arch = "riscv64")]
pub use linux_bindings_riscv64::*;
#[cfg(target_arch = "x86_64")]
pub use linux_bindings_x86_64::*;

@ -1,12 +1,11 @@
//! Map struct and type bindings.
use core::mem;
use crate::BpfSectionKind;
use alloc::vec::Vec;
use core::mem;
#[cfg(not(feature = "std"))]
use crate::std;
use crate::BpfSectionKind;
/// Invalid map type encontered
pub struct InvalidMapTypeError {

@ -7,7 +7,8 @@ use alloc::{
string::{String, ToString},
vec::Vec,
};
use core::{ffi::CStr, mem, ptr, str::FromStr};
use core::{ffi::CStr, mem, ptr, slice::from_raw_parts_mut, str::FromStr};
use log::debug;
use object::{
read::{Object as ElfObject, ObjectSection, Section as ObjSection},
@ -15,27 +16,23 @@ use object::{
SymbolKind,
};
use crate::{
btf::BtfFeatures,
generated::{BPF_CALL, BPF_JMP, BPF_K},
maps::{BtfMap, LegacyMap, Map, MINIMUM_MAP_SIZE},
programs::XdpAttachType,
relocation::*,
util::HashMap,
};
#[cfg(not(feature = "std"))]
use crate::std;
use crate::{
btf::{Btf, BtfError, BtfExt, BtfType},
generated::{bpf_insn, bpf_map_info, bpf_map_type::BPF_MAP_TYPE_ARRAY, BPF_F_RDONLY_PROG},
maps::{bpf_map_def, BtfMapDef, PinningType},
programs::{CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType},
btf::{
Array, Btf, BtfError, BtfExt, BtfFeatures, BtfType, DataSecEntry, FuncSecInfo, LineSecInfo,
},
generated::{
bpf_insn, bpf_map_info, bpf_map_type::BPF_MAP_TYPE_ARRAY, BPF_CALL, BPF_F_RDONLY_PROG,
BPF_JMP, BPF_K,
},
maps::{bpf_map_def, BtfMap, BtfMapDef, LegacyMap, Map, PinningType, MINIMUM_MAP_SIZE},
programs::{
CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType, XdpAttachType,
},
relocation::*,
util::HashMap,
};
use core::slice::from_raw_parts_mut;
use crate::btf::{Array, DataSecEntry, FuncSecInfo, LineSecInfo};
const KERNEL_VERSION_ANY: u32 = 0xFFFF_FFFE;
@ -1395,6 +1392,7 @@ fn get_func_and_line_info(
#[cfg(test)]
mod tests {
use alloc::vec;
use assert_matches::assert_matches;
use object::Endianness;

@ -1,11 +1,13 @@
//! Program relocation handling.
use alloc::{borrow::ToOwned, collections::BTreeMap, string::String};
use core::mem;
use alloc::{borrow::ToOwned, collections::BTreeMap, string::String};
use log::debug;
use object::{SectionIndex, SymbolKind};
#[cfg(not(feature = "std"))]
use crate::std;
use crate::{
generated::{
bpf_insn, BPF_CALL, BPF_JMP, BPF_K, BPF_PSEUDO_CALL, BPF_PSEUDO_FUNC, BPF_PSEUDO_MAP_FD,
@ -17,9 +19,6 @@ use crate::{
BpfSectionKind,
};
#[cfg(not(feature = "std"))]
use crate::std;
pub(crate) const INS_SIZE: usize = mem::size_of::<bpf_insn>();
/// The error type returned by [`Object::relocate_maps`] and [`Object::relocate_calls`]
@ -498,13 +497,12 @@ fn insn_is_call(ins: &bpf_insn) -> bool {
mod test {
use alloc::{string::ToString, vec, vec::Vec};
use super::*;
use crate::{
maps::{BtfMap, LegacyMap, Map},
BpfSectionKind,
};
use super::*;
fn fake_sym(index: usize, section_index: usize, address: u64, name: &str, size: u64) -> Symbol {
Symbol {
index,

@ -1,14 +1,13 @@
use core::{mem, slice};
#[cfg(not(feature = "std"))]
pub(crate) use hashbrown::HashMap;
#[cfg(feature = "std")]
pub(crate) use std::collections::HashMap;
#[cfg(feature = "std")]
pub(crate) use std::collections::HashSet;
#[cfg(not(feature = "std"))]
pub(crate) use hashbrown::HashMap;
#[cfg(not(feature = "std"))]
pub(crate) use hashbrown::HashSet;
#[cfg(feature = "std")]
pub(crate) use std::collections::HashSet;
/// bytes_of converts a <T> to a byte slice
pub(crate) unsafe fn bytes_of<T>(val: &T) -> &[u8] {

@ -1,7 +1,6 @@
use aya_tool::generate::{generate, InputFile};
use std::{path::PathBuf, process::exit};
use aya_tool::generate::{generate, InputFile};
use clap::Parser;
#[derive(Parser)]

@ -7,7 +7,6 @@ use std::{
};
use tempfile::tempdir;
use thiserror::Error;
use crate::bindgen;

@ -79,6 +79,11 @@ impl<T: BorrowMut<MapData>, V: Pod> BloomFilter<T, V> {
#[cfg(test)]
mod tests {
use std::{ffi::c_long, io};
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use super::*;
use crate::{
bpf_map_def,
@ -90,9 +95,6 @@ mod tests {
obj::{self, maps::LegacyMap, BpfSectionKind},
sys::{override_syscall, SysResult, Syscall},
};
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use std::{ffi::c_long, io};
fn new_obj_map() -> obj::Map {
obj::Map::Legacy(LegacyMap {

@ -108,6 +108,10 @@ mod tests {
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use super::{
super::test_utils::{self, new_map},
*,
};
use crate::{
generated::{
bpf_attr, bpf_cmd,
@ -118,11 +122,6 @@ mod tests {
sys::{override_syscall, SysResult, Syscall},
};
use super::{
super::test_utils::{self, new_map},
*,
};
fn new_obj_map() -> obj::Map {
test_utils::new_obj_map(BPF_MAP_TYPE_HASH)
}

@ -1,10 +1,11 @@
//! Hash map types.
use std::os::fd::AsFd as _;
use crate::{
maps::MapError,
sys::{bpf_map_delete_elem, bpf_map_update_elem, SyscallError},
Pod,
};
use std::os::fd::AsFd as _;
#[allow(clippy::module_inception)]
mod hash_map;

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

@ -196,6 +196,11 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<Key<K>, V> for LpmTrie<T, K
#[cfg(test)]
mod tests {
use std::{ffi::c_long, io, mem, net::Ipv4Addr};
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use super::*;
use crate::{
bpf_map_def,
@ -207,9 +212,6 @@ mod tests {
obj::{self, maps::LegacyMap, BpfSectionKind},
sys::{override_syscall, SysResult, Syscall},
};
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use std::{ffi::c_long, io, mem, net::Ipv4Addr};
fn new_obj_map() -> obj::Map {
obj::Map::Legacy(LegacyMap {

@ -58,7 +58,6 @@ use std::{
ptr,
};
use crate::util::KernelVersion;
use libc::{getrlimit, rlim_t, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY};
use log::warn;
use thiserror::Error;
@ -70,7 +69,7 @@ use crate::{
bpf_create_map, bpf_get_object, bpf_map_freeze, bpf_map_get_info_by_fd,
bpf_map_get_next_key, bpf_map_update_elem_ptr, bpf_pin_object, SyscallError,
},
util::nr_cpus,
util::{nr_cpus, KernelVersion},
PinningType, Pod,
};
@ -807,10 +806,12 @@ impl<T: Pod> Deref for PerCpuValues<T> {
#[cfg(test)]
mod tests {
use std::os::fd::AsRawFd as _;
use assert_matches::assert_matches;
use libc::EFAULT;
use std::os::fd::AsRawFd as _;
use super::*;
use crate::{
bpf_map_def,
generated::{bpf_cmd, bpf_map_type::BPF_MAP_TYPE_HASH},
@ -819,8 +820,6 @@ mod tests {
sys::{override_syscall, Syscall},
};
use super::*;
fn new_obj_map() -> obj::Map {
obj::Map::Legacy(LegacyMap {
def: bpf_map_def {

@ -1,4 +1,3 @@
use bytes::BytesMut;
use std::borrow::{Borrow, BorrowMut};
// See https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features.
@ -7,7 +6,7 @@ use std::borrow::{Borrow, BorrowMut};
// "async-async-std". Presently we arbitrarily choose tokio over async-std when both are requested.
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
use async_io::Async;
use bytes::BytesMut;
#[cfg(feature = "async_tokio")]
use tokio::io::unix::AsyncFd;

@ -318,13 +318,15 @@ struct LostSamples {
#[cfg(test)]
mod tests {
use std::{fmt::Debug, mem};
use assert_matches::assert_matches;
use super::*;
use crate::{
generated::perf_event_mmap_page,
sys::{override_syscall, Syscall, TEST_MMAP_RET},
};
use assert_matches::assert_matches;
use std::{fmt::Debug, mem};
const PAGE_SIZE: usize = 4096;
union MMappedBuf {

@ -2,14 +2,14 @@
mod sock_hash;
mod sock_map;
pub use sock_hash::SockHash;
pub use sock_map::SockMap;
use std::{
io,
os::fd::{AsFd, BorrowedFd},
};
pub use sock_hash::SockHash;
pub use sock_map::SockMap;
/// A socket map file descriptor.
#[repr(transparent)]
pub struct SockMapFd(super::MapFd);

@ -8,6 +8,7 @@ use std::{
use aya_obj::generated::bpf_cpumap_val;
use super::XdpMapError;
use crate::{
maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError},
programs::ProgramFd,
@ -15,8 +16,6 @@ use crate::{
Pod, FEATURES,
};
use super::XdpMapError;
/// An array of available CPUs.
///
/// XDP programs can use this map to redirect packets to a target

@ -8,6 +8,7 @@ use std::{
use aya_obj::generated::bpf_devmap_val;
use super::XdpMapError;
use crate::{
maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError},
programs::ProgramFd,
@ -15,8 +16,6 @@ use crate::{
Pod, FEATURES,
};
use super::XdpMapError;
/// An array of network devices.
///
/// XDP programs can use this map to redirect to other network

@ -8,6 +8,7 @@ use std::{
use aya_obj::generated::bpf_devmap_val;
use super::{dev_map::DevMapValue, XdpMapError};
use crate::{
maps::{check_kv_size, hash_map, IterableMap, MapData, MapError, MapIter, MapKeys},
programs::ProgramFd,
@ -15,8 +16,6 @@ use crate::{
FEATURES,
};
use super::{dev_map::DevMapValue, XdpMapError};
/// An hashmap of network devices.
///
/// XDP programs can use this map to redirect to other network

@ -7,10 +7,10 @@ mod xsk_map;
pub use cpu_map::CpuMap;
pub use dev_map::DevMap;
pub use dev_map_hash::DevMapHash;
use thiserror::Error;
pub use xsk_map::XskMap;
use super::MapError;
use thiserror::Error;
#[derive(Error, Debug)]
/// Errors occuring from working with XDP maps.

@ -1,8 +1,9 @@
//! Pinning BPF objects to the BPF filesystem.
use crate::sys::SyscallError;
use thiserror::Error;
use crate::sys::SyscallError;
/// An error ocurred working with a pinned BPF object.
#[derive(Error, Debug)]
pub enum PinError {

@ -1,9 +1,9 @@
//! Cgroup socket programs.
pub use aya_obj::programs::CgroupSockAttachType;
use std::{hash::Hash, os::fd::AsFd, path::Path};
pub use aya_obj::programs::CgroupSockAttachType;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK,
programs::{

@ -1,9 +1,9 @@
//! Cgroup socket address programs.
pub use aya_obj::programs::CgroupSockAddrAttachType;
use std::{hash::Hash, os::fd::AsFd, path::Path};
pub use aya_obj::programs::CgroupSockAddrAttachType;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
programs::{

@ -1,9 +1,9 @@
//! Cgroup socket option programs.
pub use aya_obj::programs::CgroupSockoptAttachType;
use std::{hash::Hash, os::fd::AsFd, path::Path};
pub use aya_obj::programs::CgroupSockoptAttachType;
use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCKOPT,
programs::{

@ -5,6 +5,7 @@ use std::{
os::fd::AsFd as _,
path::{Path, PathBuf},
};
use thiserror::Error;
use crate::{

@ -1,6 +1,4 @@
//! Program links.
use thiserror::Error;
use std::{
collections::{hash_map::Entry, HashMap},
ffi::CString,
@ -9,6 +7,8 @@ use std::{
path::{Path, PathBuf},
};
use thiserror::Error;
use crate::{
generated::bpf_attach_type,
pin::PinError,
@ -357,13 +357,13 @@ pub enum LinkError {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use std::{cell::RefCell, fs::File, rc::Rc};
use tempfile::tempdir;
use crate::{programs::ProgramError, sys::override_syscall};
use assert_matches::assert_matches;
use tempfile::tempdir;
use super::{FdLink, Link, LinkMap};
use crate::{programs::ProgramError, sys::override_syscall};
#[derive(Debug, Hash, Eq, PartialEq)]
struct TestLinkId(u8, u8);

@ -64,7 +64,6 @@ pub mod uprobe;
mod utils;
pub mod xdp;
use libc::ENOSPC;
use std::{
ffi::CString,
io,
@ -74,7 +73,6 @@ use std::{
sync::Arc,
time::{Duration, SystemTime},
};
use thiserror::Error;
pub use cgroup_device::CgroupDevice;
pub use cgroup_skb::{CgroupSkb, CgroupSkbAttachType};
@ -86,6 +84,7 @@ pub use extension::{Extension, ExtensionError};
pub use fentry::FEntry;
pub use fexit::FExit;
pub use kprobe::{KProbe, KProbeError};
use libc::ENOSPC;
pub use links::Link;
use links::*;
pub use lirc_mode2::LircMode2;
@ -100,6 +99,7 @@ pub use sk_skb::{SkSkb, SkSkbKind};
pub use sock_ops::SockOps;
pub use socket_filter::{SocketFilter, SocketFilterError};
pub use tc::{SchedClassifier, TcAttachType, TcError};
use thiserror::Error;
pub use tp_btf::BtfTracePoint;
pub use trace_point::{TracePoint, TracePointError};
pub use uprobe::{UProbe, UProbeError};

@ -5,7 +5,6 @@ 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::{
bpf_link_type,

@ -1,5 +1,3 @@
use crate::util::KernelVersion;
use libc::pid_t;
use std::{
ffi::{OsStr, OsString},
fmt::Write as _,
@ -11,6 +9,8 @@ use std::{
sync::atomic::{AtomicUsize, Ordering},
};
use libc::pid_t;
use crate::{
programs::{
kprobe::KProbeError, perf_attach, perf_attach::PerfLinkInner, perf_attach_debugfs,
@ -18,6 +18,7 @@ use crate::{
Link, ProgramData, ProgramError,
},
sys::{perf_event_open_probe, perf_event_open_trace_point, SyscallError},
util::KernelVersion,
};
static PROBE_NAME_INDEX: AtomicUsize = AtomicUsize::new(0);
@ -213,6 +214,7 @@ fn create_probe_event(
offset: u64,
) -> Result<OsString, (PathBuf, io::Error)> {
use std::os::unix::ffi::OsStrExt as _;
use ProbeKind::*;
let events_file_name = tracefs.join(format!("{}_events", kind.pmu()));

@ -1,13 +1,12 @@
use std::os::fd::AsFd;
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},
};
use super::links::FdLink;
/// A program used to redirect incoming packets to a local socket.
///
/// [`SkLookup`] programs are attached to network namespaces to provide programmable

@ -1,9 +1,10 @@
//! Socket filter programs.
use libc::{setsockopt, SOL_SOCKET};
use std::{
io, mem,
os::fd::{AsFd, AsRawFd, RawFd},
};
use libc::{setsockopt, SOL_SOCKET};
use thiserror::Error;
use crate::{

@ -1,6 +1,4 @@
//! Network traffic control programs.
use thiserror::Error;
use std::{
ffi::{CStr, CString},
io,
@ -8,6 +6,8 @@ use std::{
path::Path,
};
use thiserror::Error;
use crate::{
generated::{
bpf_prog_type::BPF_PROG_TYPE_SCHED_CLS, TC_H_CLSACT, TC_H_MIN_EGRESS, TC_H_MIN_INGRESS,

@ -1,5 +1,6 @@
//! Tracepoint programs.
use std::{fs, io, os::fd::AsFd as _, path::Path};
use thiserror::Error;
use crate::{

@ -1,6 +1,4 @@
//! User space probes.
use libc::pid_t;
use object::{Object, ObjectSection, ObjectSymbol};
use std::{
borrow::Cow,
error::Error,
@ -12,6 +10,9 @@ use std::{
path::{Path, PathBuf},
sync::Arc,
};
use libc::pid_t;
use object::{Object, ObjectSection, ObjectSymbol};
use thiserror::Error;
use crate::{

@ -1,11 +1,5 @@
//! eXpress Data Path (XDP) programs.
use crate::{
sys::{LinkTarget, SyscallError},
util::KernelVersion,
};
use bitflags;
use libc::if_nametoindex;
use std::{
convert::TryFrom,
ffi::CString,
@ -14,6 +8,9 @@ use std::{
os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, RawFd},
path::Path,
};
use bitflags;
use libc::if_nametoindex;
use thiserror::Error;
use crate::{
@ -25,7 +22,11 @@ use crate::{
programs::{
define_link_wrapper, load_program, FdLink, Link, LinkError, ProgramData, ProgramError,
},
sys::{bpf_link_create, bpf_link_get_info_by_fd, bpf_link_update, netlink_set_xdp_fd},
sys::{
bpf_link_create, bpf_link_get_info_by_fd, bpf_link_update, netlink_set_xdp_fd, LinkTarget,
SyscallError,
},
util::KernelVersion,
VerifierLogLevel,
};

@ -7,7 +7,6 @@ use std::{
slice,
};
use crate::util::KernelVersion;
use assert_matches::assert_matches;
use libc::{c_char, c_long, ENOENT, ENOSPC};
use obj::{
@ -31,6 +30,7 @@ use crate::{
copy_instructions,
},
sys::{syscall, SysResult, Syscall, SyscallError},
util::KernelVersion,
Btf, Pod, VerifierLogLevel, BPF_OBJ_NAME_LEN,
};
@ -1069,9 +1069,10 @@ pub(crate) fn retry_with_verifier_logs<T>(
#[cfg(test)]
mod tests {
use libc::{EBADF, EINVAL};
use super::*;
use crate::sys::override_syscall;
use libc::{EBADF, EINVAL};
#[test]
fn test_perf_link_supported() {

@ -5,20 +5,20 @@ mod perf_event;
#[cfg(test)]
mod fake;
use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open};
use std::{
io, mem,
os::fd::{AsRawFd as _, BorrowedFd},
};
use thiserror::Error;
pub(crate) use bpf::*;
#[cfg(test)]
pub(crate) use fake::*;
use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open};
#[doc(hidden)]
pub use netlink::netlink_set_link_up;
pub(crate) use netlink::*;
pub(crate) use perf_event::*;
use thiserror::Error;
use crate::generated::{bpf_attr, bpf_cmd, perf_event_attr};

@ -5,7 +5,6 @@ use std::{
os::fd::{AsRawFd as _, BorrowedFd, FromRawFd as _, OwnedFd},
ptr, slice,
};
use thiserror::Error;
use libc::{
getsockname, nlattr, nlmsgerr, nlmsghdr, recv, send, setsockopt, sockaddr_nl, socket,
@ -14,6 +13,7 @@ use libc::{
NLM_F_DUMP, NLM_F_ECHO, NLM_F_EXCL, NLM_F_MULTI, NLM_F_REQUEST, RTM_DELTFILTER, RTM_GETTFILTER,
RTM_NEWQDISC, RTM_NEWTFILTER, RTM_SETLINK, SOCK_RAW, SOL_NETLINK,
};
use thiserror::Error;
use crate::{
generated::{

@ -6,6 +6,7 @@ use std::{
use libc::{c_int, pid_t};
use super::{syscall, SysResult, Syscall};
use crate::generated::{
perf_event_attr,
perf_event_sample_format::PERF_SAMPLE_RAW,
@ -14,8 +15,6 @@ use crate::generated::{
PERF_FLAG_FD_CLOEXEC,
};
use super::{syscall, SysResult, Syscall};
#[allow(clippy::too_many_arguments)]
pub(crate) fn perf_event_open(
perf_type: u32,

@ -11,13 +11,13 @@ use std::{
str::{FromStr, Utf8Error},
};
use libc::{if_nametoindex, sysconf, uname, utsname, _SC_PAGESIZE};
use crate::{
generated::{TC_H_MAJ_MASK, TC_H_MIN_MASK},
Pod,
};
use libc::{if_nametoindex, sysconf, uname, utsname, _SC_PAGESIZE};
/// Represents a kernel version, in major.minor.release version.
// Adapted from https://docs.rs/procfs/latest/procfs/sys/kernel/struct.Version.html.
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd)]
@ -359,9 +359,10 @@ pub(crate) fn bytes_of_slice<T: Pod>(val: &[T]) -> &[u8] {
#[cfg(test)]
mod tests {
use super::*;
use assert_matches::assert_matches;
use super::*;
#[test]
fn test_parse_kernel_version_string() {
// WSL.

@ -14,17 +14,14 @@ mod aarch64;
mod riscv64;
mod gen {
#[cfg(bpf_target_arch = "x86_64")]
pub use super::x86_64::*;
#[cfg(bpf_target_arch = "arm")]
pub use super::armv7::*;
#[cfg(bpf_target_arch = "aarch64")]
pub use super::aarch64::*;
#[cfg(bpf_target_arch = "arm")]
pub use super::armv7::*;
#[cfg(bpf_target_arch = "riscv64")]
pub use super::riscv64::*;
#[cfg(bpf_target_arch = "x86_64")]
pub use super::x86_64::*;
}
pub use gen::helpers;

@ -1,14 +1,11 @@
use crate::{cty::c_void, helpers::bpf_probe_read};
// aarch64 uses user_pt_regs instead of pt_regs
#[cfg(not(any(bpf_target_arch = "aarch64", bpf_target_arch = "riscv64")))]
use crate::bindings::pt_regs;
#[cfg(bpf_target_arch = "aarch64")]
use crate::bindings::user_pt_regs as pt_regs;
#[cfg(bpf_target_arch = "riscv64")]
use crate::bindings::user_regs_struct as pt_regs;
use crate::{cty::c_void, helpers::bpf_probe_read};
/// A trait that indicates a valid type for an argument which can be coerced from a BTF
/// context.

@ -22,13 +22,12 @@ pub mod helpers;
pub mod maps;
pub mod programs;
pub use aya_bpf_cty as cty;
use core::ffi::c_void;
use cty::{c_int, c_long};
use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid, bpf_get_current_uid_gid};
pub use aya_bpf_cty as cty;
pub use aya_bpf_macros as macros;
use cty::{c_int, c_long};
use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid, bpf_get_current_uid_gid};
pub const TASK_COMM_LEN: usize = 16;

@ -2,13 +2,12 @@ use core::{cell::UnsafeCell, mem};
use aya_bpf_bindings::bindings::bpf_cpumap_val;
use super::try_redirect_map;
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_CPUMAP},
maps::PinningType,
};
use super::try_redirect_map;
/// An array of available CPUs.
///
/// XDP programs can use this map to redirect packets to a target CPU for processing.

@ -3,14 +3,13 @@ use core::{cell::UnsafeCell, mem, num::NonZeroU32, ptr::NonNull};
use aya_bpf_bindings::bindings::bpf_devmap_val;
use aya_bpf_cty::c_void;
use super::try_redirect_map;
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP},
helpers::bpf_map_lookup_elem,
maps::PinningType,
};
use super::try_redirect_map;
/// An array of network devices.
///
/// XDP programs can use this map to redirect packets to other network deviecs.

@ -3,14 +3,13 @@ use core::{cell::UnsafeCell, mem, num::NonZeroU32, ptr::NonNull};
use aya_bpf_bindings::bindings::bpf_devmap_val;
use aya_bpf_cty::c_void;
use super::{dev_map::DevMapValue, try_redirect_map};
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP_HASH},
helpers::bpf_map_lookup_elem,
maps::PinningType,
};
use super::{dev_map::DevMapValue, try_redirect_map};
/// A map of network devices.
///
/// XDP programs can use this map to redirect packets to other network devices. It is similar to

@ -3,14 +3,13 @@ use core::{cell::UnsafeCell, mem, ptr::NonNull};
use aya_bpf_bindings::bindings::bpf_xdp_sock;
use aya_bpf_cty::c_void;
use super::try_redirect_map;
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_XSKMAP},
helpers::bpf_map_lookup_elem,
maps::PinningType,
};
use super::try_redirect_map;
/// An array of AF_XDP sockets.
///
/// XDP programs can use this map to redirect packets to a target AF_XDP socket using the

@ -1,6 +1,7 @@
use crate::BpfContext;
use core::ffi::c_void;
use crate::BpfContext;
pub struct PerfEventContext {
ctx: *mut c_void,
}

@ -1,15 +1,12 @@
use core::ffi::c_void;
use crate::{args::FromPtRegs, BpfContext};
#[cfg(not(any(bpf_target_arch = "aarch64", bpf_target_arch = "riscv64")))]
use crate::bindings::pt_regs;
#[cfg(bpf_target_arch = "aarch64")]
use crate::bindings::user_pt_regs as pt_regs;
#[cfg(bpf_target_arch = "riscv64")]
use crate::bindings::user_regs_struct as pt_regs;
use crate::{args::FromPtRegs, BpfContext};
pub struct ProbeContext {
pub regs: *mut pt_regs,

@ -1,6 +1,7 @@
use crate::{helpers::bpf_probe_read, BpfContext};
use core::ffi::c_void;
use crate::{helpers::bpf_probe_read, BpfContext};
pub struct TracePointContext {
ctx: *mut c_void,
}

@ -1,3 +1,4 @@
unstable_features = true
reorder_imports = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
reorder_imports = true
unstable_features = true

@ -1,6 +1,5 @@
use test_case::test_case;
use aya::{maps::Array, programs::UProbe, util::KernelVersion, BpfLoader, Btf, Endianness};
use test_case::test_case;
#[test_case("enum_signed_32", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
#[test_case("enum_signed_32", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7BBBBBBBi32 as u64)]

@ -1,6 +1,6 @@
use anyhow::anyhow;
use std::path::{Path, PathBuf};
use anyhow::anyhow;
use aya_tool::{bindgen, write_to_file};
use crate::codegen::{Architecture, SysrootOptions};

@ -1,9 +1,9 @@
use anyhow::anyhow;
use proc_macro2::TokenStream;
use quote::ToTokens;
use std::path::{Path, PathBuf};
use anyhow::anyhow;
use aya_tool::{bindgen, write_to_file_fmt};
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{parse_str, Item};
use crate::codegen::{

@ -1,7 +1,8 @@
use std::{ffi::OsString, fs, io::Write as _, process::Command};
use anyhow::{Context as _, Result};
use cargo_metadata::Metadata;
use indoc::{indoc, writedoc};
use std::{ffi::OsString, fs, io::Write as _, process::Command};
use xtask::exec;
pub fn docs(metadata: Metadata) -> Result<()> {

@ -1,6 +1,7 @@
use anyhow::{bail, Context as _, Result};
use std::process::Command;
use anyhow::{bail, Context as _, Result};
pub const AYA_BUILD_INTEGRATION_BPF: &str = "AYA_BUILD_INTEGRATION_BPF";
pub const LIBBPF_DIR: &str = "xtask/libbpf";

@ -3,10 +3,11 @@ mod docs;
mod public_api;
mod run;
use std::process::Command;
use anyhow::{Context as _, Result};
use cargo_metadata::{Metadata, MetadataCommand};
use clap::Parser;
use std::process::Command;
use xtask::{exec, LIBBPF_DIR};
#[derive(Parser)]

Loading…
Cancel
Save