Merge pull request #797 from aya-rs/rustfmt-group-imports

rustfmt: group_imports = "StdExternalCrate"
reviewable/pr629/r67
Tamir Duberstein 1 year ago committed by GitHub
commit 373fb7bf06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,8 +1,8 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use alloc::{string::ToString, vec, vec::Vec};
use core::{fmt::Display, mem, ptr}; use core::{fmt::Display, mem, ptr};
use alloc::{string::ToString, vec, vec::Vec};
use object::Endianness; use object::Endianness;
use crate::btf::{Btf, BtfError, MAX_RESOLVE_DEPTH}; use crate::btf::{Btf, BtfError, MAX_RESOLVE_DEPTH};
@ -1570,9 +1570,10 @@ fn bytes_of<T>(val: &T) -> &[u8] {
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use assert_matches::assert_matches; use assert_matches::assert_matches;
use super::*;
#[test] #[test]
fn test_read_btf_type_int() { fn test_read_btf_type_int() {
let endianness = Endianness::default(); 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 // don't re-export __u8 __u16 etc which are already exported by the
// linux_bindings_* module // linux_bindings_* module
pub use btf_internal_bindings::{bpf_core_relo, bpf_core_relo_kind, btf_ext_header}; 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")] #[cfg(target_arch = "aarch64")]
pub use linux_bindings_aarch64::*; pub use linux_bindings_aarch64::*;
#[cfg(target_arch = "arm")]
pub use linux_bindings_armv7::*;
#[cfg(target_arch = "riscv64")] #[cfg(target_arch = "riscv64")]
pub use linux_bindings_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. //! Map struct and type bindings.
use core::mem;
use crate::BpfSectionKind;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::mem;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use crate::std; use crate::std;
use crate::BpfSectionKind;
/// Invalid map type encontered /// Invalid map type encontered
pub struct InvalidMapTypeError { pub struct InvalidMapTypeError {

@ -7,7 +7,8 @@ use alloc::{
string::{String, ToString}, string::{String, ToString},
vec::Vec, 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 log::debug;
use object::{ use object::{
read::{Object as ElfObject, ObjectSection, Section as ObjSection}, read::{Object as ElfObject, ObjectSection, Section as ObjSection},
@ -15,27 +16,23 @@ use object::{
SymbolKind, 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"))] #[cfg(not(feature = "std"))]
use crate::std; use crate::std;
use crate::{ use crate::{
btf::{Btf, BtfError, BtfExt, BtfType}, btf::{
generated::{bpf_insn, bpf_map_info, bpf_map_type::BPF_MAP_TYPE_ARRAY, BPF_F_RDONLY_PROG}, Array, Btf, BtfError, BtfExt, BtfFeatures, BtfType, DataSecEntry, FuncSecInfo, LineSecInfo,
maps::{bpf_map_def, BtfMapDef, PinningType}, },
programs::{CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType}, 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; const KERNEL_VERSION_ANY: u32 = 0xFFFF_FFFE;
@ -1395,6 +1392,7 @@ fn get_func_and_line_info(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use alloc::vec; use alloc::vec;
use assert_matches::assert_matches; use assert_matches::assert_matches;
use object::Endianness; use object::Endianness;

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

@ -1,14 +1,13 @@
use core::{mem, slice}; use core::{mem, slice};
#[cfg(not(feature = "std"))]
pub(crate) use hashbrown::HashMap;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub(crate) use std::collections::HashMap; 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"))] #[cfg(not(feature = "std"))]
pub(crate) use hashbrown::HashSet; pub(crate) use hashbrown::HashSet;
#[cfg(feature = "std")]
pub(crate) use std::collections::HashSet;
/// bytes_of converts a <T> to a byte slice /// bytes_of converts a <T> to a byte slice
pub(crate) unsafe fn bytes_of<T>(val: &T) -> &[u8] { 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 std::{path::PathBuf, process::exit};
use aya_tool::generate::{generate, InputFile};
use clap::Parser; use clap::Parser;
#[derive(Parser)] #[derive(Parser)]

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

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

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

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

@ -150,13 +150,12 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<K, PerCpuValues<V>>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{super::test_utils, *};
use crate::{ use crate::{
generated::bpf_map_type::{BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH}, generated::bpf_map_type::{BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH},
maps::Map, maps::Map,
}; };
use super::{super::test_utils, *};
#[test] #[test]
fn test_try_from_ok() { fn test_try_from_ok() {
let map = Map::PerCpuHashMap(test_utils::new_map(test_utils::new_obj_map( 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)] #[cfg(test)]
mod tests { mod tests {
use std::{ffi::c_long, io, mem, net::Ipv4Addr};
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use super::*; use super::*;
use crate::{ use crate::{
bpf_map_def, bpf_map_def,
@ -207,9 +212,6 @@ mod tests {
obj::{self, maps::LegacyMap, BpfSectionKind}, obj::{self, maps::LegacyMap, BpfSectionKind},
sys::{override_syscall, SysResult, Syscall}, 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 { fn new_obj_map() -> obj::Map {
obj::Map::Legacy(LegacyMap { obj::Map::Legacy(LegacyMap {

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

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

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

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

@ -8,6 +8,7 @@ use std::{
use aya_obj::generated::bpf_cpumap_val; use aya_obj::generated::bpf_cpumap_val;
use super::XdpMapError;
use crate::{ use crate::{
maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError}, maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError},
programs::ProgramFd, programs::ProgramFd,
@ -15,8 +16,6 @@ use crate::{
Pod, FEATURES, Pod, FEATURES,
}; };
use super::XdpMapError;
/// An array of available CPUs. /// An array of available CPUs.
/// ///
/// XDP programs can use this map to redirect packets to a target /// 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 aya_obj::generated::bpf_devmap_val;
use super::XdpMapError;
use crate::{ use crate::{
maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError}, maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError},
programs::ProgramFd, programs::ProgramFd,
@ -15,8 +16,6 @@ use crate::{
Pod, FEATURES, Pod, FEATURES,
}; };
use super::XdpMapError;
/// An array of network devices. /// An array of network devices.
/// ///
/// XDP programs can use this map to redirect to other network /// 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 aya_obj::generated::bpf_devmap_val;
use super::{dev_map::DevMapValue, XdpMapError};
use crate::{ use crate::{
maps::{check_kv_size, hash_map, IterableMap, MapData, MapError, MapIter, MapKeys}, maps::{check_kv_size, hash_map, IterableMap, MapData, MapError, MapIter, MapKeys},
programs::ProgramFd, programs::ProgramFd,
@ -15,8 +16,6 @@ use crate::{
FEATURES, FEATURES,
}; };
use super::{dev_map::DevMapValue, XdpMapError};
/// An hashmap of network devices. /// An hashmap of network devices.
/// ///
/// XDP programs can use this map to redirect to other network /// 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 cpu_map::CpuMap;
pub use dev_map::DevMap; pub use dev_map::DevMap;
pub use dev_map_hash::DevMapHash; pub use dev_map_hash::DevMapHash;
use thiserror::Error;
pub use xsk_map::XskMap; pub use xsk_map::XskMap;
use super::MapError; use super::MapError;
use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
/// Errors occuring from working with XDP maps. /// Errors occuring from working with XDP maps.

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

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

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

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

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

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

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

@ -5,7 +5,6 @@ use std::os::fd::AsFd as _;
pub use crate::generated::{ 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, perf_hw_cache_id, perf_hw_cache_op_id, perf_hw_cache_op_result_id, perf_hw_id, perf_sw_ids,
}; };
use crate::{ use crate::{
generated::{ generated::{
bpf_link_type, bpf_link_type,

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

@ -1,13 +1,12 @@
use std::os::fd::AsFd; use std::os::fd::AsFd;
use super::links::FdLink;
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP}, generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP},
programs::{define_link_wrapper, load_program, FdLinkId, ProgramData, ProgramError}, programs::{define_link_wrapper, load_program, FdLinkId, ProgramData, ProgramError},
sys::{bpf_link_create, LinkTarget, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
}; };
use super::links::FdLink;
/// A program used to redirect incoming packets to a local socket. /// A program used to redirect incoming packets to a local socket.
/// ///
/// [`SkLookup`] programs are attached to network namespaces to provide programmable /// [`SkLookup`] programs are attached to network namespaces to provide programmable

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

@ -1,6 +1,4 @@
//! Network traffic control programs. //! Network traffic control programs.
use thiserror::Error;
use std::{ use std::{
ffi::{CStr, CString}, ffi::{CStr, CString},
io, io,
@ -8,6 +6,8 @@ use std::{
path::Path, path::Path,
}; };
use thiserror::Error;
use crate::{ use crate::{
generated::{ generated::{
bpf_prog_type::BPF_PROG_TYPE_SCHED_CLS, TC_H_CLSACT, TC_H_MIN_EGRESS, TC_H_MIN_INGRESS, 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. //! Tracepoint programs.
use std::{fs, io, os::fd::AsFd as _, path::Path}; use std::{fs, io, os::fd::AsFd as _, path::Path};
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{

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

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

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

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

@ -5,7 +5,6 @@ use std::{
os::fd::{AsRawFd as _, BorrowedFd, FromRawFd as _, OwnedFd}, os::fd::{AsRawFd as _, BorrowedFd, FromRawFd as _, OwnedFd},
ptr, slice, ptr, slice,
}; };
use thiserror::Error;
use libc::{ use libc::{
getsockname, nlattr, nlmsgerr, nlmsghdr, recv, send, setsockopt, sockaddr_nl, socket, 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, 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, RTM_NEWQDISC, RTM_NEWTFILTER, RTM_SETLINK, SOCK_RAW, SOL_NETLINK,
}; };
use thiserror::Error;
use crate::{ use crate::{
generated::{ generated::{

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

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

@ -14,17 +14,14 @@ mod aarch64;
mod riscv64; mod riscv64;
mod gen { 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")] #[cfg(bpf_target_arch = "aarch64")]
pub use super::aarch64::*; pub use super::aarch64::*;
#[cfg(bpf_target_arch = "arm")]
pub use super::armv7::*;
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
pub use super::riscv64::*; pub use super::riscv64::*;
#[cfg(bpf_target_arch = "x86_64")]
pub use super::x86_64::*;
} }
pub use gen::helpers; 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 // aarch64 uses user_pt_regs instead of pt_regs
#[cfg(not(any(bpf_target_arch = "aarch64", bpf_target_arch = "riscv64")))] #[cfg(not(any(bpf_target_arch = "aarch64", bpf_target_arch = "riscv64")))]
use crate::bindings::pt_regs; use crate::bindings::pt_regs;
#[cfg(bpf_target_arch = "aarch64")] #[cfg(bpf_target_arch = "aarch64")]
use crate::bindings::user_pt_regs as pt_regs; use crate::bindings::user_pt_regs as pt_regs;
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
use crate::bindings::user_regs_struct as pt_regs; 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 /// A trait that indicates a valid type for an argument which can be coerced from a BTF
/// context. /// context.

@ -22,13 +22,12 @@ pub mod helpers;
pub mod maps; pub mod maps;
pub mod programs; pub mod programs;
pub use aya_bpf_cty as cty;
use core::ffi::c_void; 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; 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; 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 aya_bpf_bindings::bindings::bpf_cpumap_val;
use super::try_redirect_map;
use crate::{ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_CPUMAP}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_CPUMAP},
maps::PinningType, maps::PinningType,
}; };
use super::try_redirect_map;
/// An array of available CPUs. /// An array of available CPUs.
/// ///
/// XDP programs can use this map to redirect packets to a target CPU for processing. /// 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_bindings::bindings::bpf_devmap_val;
use aya_bpf_cty::c_void; use aya_bpf_cty::c_void;
use super::try_redirect_map;
use crate::{ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP},
helpers::bpf_map_lookup_elem, helpers::bpf_map_lookup_elem,
maps::PinningType, maps::PinningType,
}; };
use super::try_redirect_map;
/// An array of network devices. /// An array of network devices.
/// ///
/// XDP programs can use this map to redirect packets to other network deviecs. /// 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_bindings::bindings::bpf_devmap_val;
use aya_bpf_cty::c_void; use aya_bpf_cty::c_void;
use super::{dev_map::DevMapValue, try_redirect_map};
use crate::{ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP_HASH}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP_HASH},
helpers::bpf_map_lookup_elem, helpers::bpf_map_lookup_elem,
maps::PinningType, maps::PinningType,
}; };
use super::{dev_map::DevMapValue, try_redirect_map};
/// A map of network devices. /// A map of network devices.
/// ///
/// XDP programs can use this map to redirect packets to other network devices. It is similar to /// 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_bindings::bindings::bpf_xdp_sock;
use aya_bpf_cty::c_void; use aya_bpf_cty::c_void;
use super::try_redirect_map;
use crate::{ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_XSKMAP}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_XSKMAP},
helpers::bpf_map_lookup_elem, helpers::bpf_map_lookup_elem,
maps::PinningType, maps::PinningType,
}; };
use super::try_redirect_map;
/// An array of AF_XDP sockets. /// An array of AF_XDP sockets.
/// ///
/// XDP programs can use this map to redirect packets to a target AF_XDP socket using the /// 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 core::ffi::c_void;
use crate::BpfContext;
pub struct PerfEventContext { pub struct PerfEventContext {
ctx: *mut c_void, ctx: *mut c_void,
} }

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

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

@ -1,3 +1,4 @@
unstable_features = true group_imports = "StdExternalCrate"
reorder_imports = true
imports_granularity = "Crate" 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 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", 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)] #[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 std::path::{Path, PathBuf};
use anyhow::anyhow;
use aya_tool::{bindgen, write_to_file}; use aya_tool::{bindgen, write_to_file};
use crate::codegen::{Architecture, SysrootOptions}; 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 std::path::{Path, PathBuf};
use anyhow::anyhow;
use aya_tool::{bindgen, write_to_file_fmt}; use aya_tool::{bindgen, write_to_file_fmt};
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{parse_str, Item}; use syn::{parse_str, Item};
use crate::codegen::{ use crate::codegen::{

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

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

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

Loading…
Cancel
Save