Remove procfs dependency

reviewable/pr643/r1
Tamir Duberstein 1 year ago
parent b5ebcb7cc5
commit cc2bc0acc1
No known key found for this signature in database

@ -31,7 +31,6 @@ tokio = { version = "1.24.0", features = [
"rt-multi-thread", "rt-multi-thread",
"net", "net",
], optional = true } ], optional = true }
procfs = { version = "0.15.1", default-features = false }
[dev-dependencies] [dev-dependencies]
futures = { version = "0.3.12", default-features = false, features = ["std"] } futures = { version = "0.3.12", default-features = false, features = ["std"] }

@ -47,9 +47,9 @@ use std::{
ptr, ptr,
}; };
use crate::util::KernelVersion;
use libc::{getrlimit, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY}; use libc::{getrlimit, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY};
use log::warn; use log::warn;
use procfs::KernelVersion;
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{

@ -1,6 +1,6 @@
//! Cgroup device programs. //! Cgroup device programs.
use procfs::KernelVersion; use crate::util::KernelVersion;
use std::os::fd::{AsRawFd, RawFd}; use std::os::fd::{AsRawFd, RawFd};
use crate::{ use crate::{

@ -1,6 +1,6 @@
//! Cgroup skb programs. //! Cgroup skb programs.
use procfs::KernelVersion; use crate::util::KernelVersion;
use std::{ use std::{
hash::Hash, hash::Hash,
os::fd::{AsRawFd, RawFd}, os::fd::{AsRawFd, RawFd},

@ -2,7 +2,7 @@
pub use aya_obj::programs::CgroupSockAttachType; pub use aya_obj::programs::CgroupSockAttachType;
use procfs::KernelVersion; use crate::util::KernelVersion;
use std::{ use std::{
hash::Hash, hash::Hash,
os::fd::{AsRawFd, RawFd}, os::fd::{AsRawFd, RawFd},

@ -2,7 +2,7 @@
pub use aya_obj::programs::CgroupSockAddrAttachType; pub use aya_obj::programs::CgroupSockAddrAttachType;
use procfs::KernelVersion; use crate::util::KernelVersion;
use std::{ use std::{
hash::Hash, hash::Hash,
os::fd::{AsRawFd, RawFd}, os::fd::{AsRawFd, RawFd},

@ -2,7 +2,7 @@
pub use aya_obj::programs::CgroupSockoptAttachType; pub use aya_obj::programs::CgroupSockoptAttachType;
use procfs::KernelVersion; use crate::util::KernelVersion;
use std::{ use std::{
hash::Hash, hash::Hash,
os::fd::{AsRawFd, RawFd}, os::fd::{AsRawFd, RawFd},

@ -1,6 +1,6 @@
//! Cgroup sysctl programs. //! Cgroup sysctl programs.
use procfs::KernelVersion; use crate::util::KernelVersion;
use std::{ use std::{
hash::Hash, hash::Hash,
os::fd::{AsRawFd, RawFd}, os::fd::{AsRawFd, RawFd},

@ -64,8 +64,8 @@ pub mod uprobe;
mod utils; mod utils;
pub mod xdp; pub mod xdp;
use crate::util::KernelVersion;
use libc::ENOSPC; use libc::ENOSPC;
use procfs::KernelVersion;
use std::{ use std::{
ffi::CString, ffi::CString,
io, io,

@ -1,5 +1,5 @@
use crate::util::KernelVersion;
use libc::pid_t; use libc::pid_t;
use procfs::KernelVersion;
use std::{ use std::{
fs::{self, OpenOptions}, fs::{self, OpenOptions},
io::{self, Write}, io::{self, Write},

@ -1,8 +1,8 @@
//! eXpress Data Path (XDP) programs. //! eXpress Data Path (XDP) programs.
use crate::util::KernelVersion;
use bitflags; use bitflags;
use libc::if_nametoindex; use libc::if_nametoindex;
use procfs::KernelVersion;
use std::{convert::TryFrom, ffi::CString, hash::Hash, io, mem, os::unix::io::RawFd}; use std::{convert::TryFrom, ffi::CString, hash::Hash, io, mem, os::unix::io::RawFd};
use thiserror::Error; use thiserror::Error;

@ -7,12 +7,12 @@ use std::{
slice, slice,
}; };
use crate::util::KernelVersion;
use libc::{c_char, c_long, close, ENOENT, ENOSPC}; use libc::{c_char, c_long, close, ENOENT, ENOSPC};
use obj::{ use obj::{
maps::{bpf_map_def, LegacyMap}, maps::{bpf_map_def, LegacyMap},
BpfSectionKind, BpfSectionKind,
}; };
use procfs::KernelVersion;
use crate::{ use crate::{
generated::{ generated::{

@ -3,8 +3,10 @@ use std::{
collections::BTreeMap, collections::BTreeMap,
ffi::CString, ffi::CString,
fs::{self, File}, fs::{self, File},
io::{self, BufReader}, io::{self, BufRead, BufReader},
mem, slice, mem,
num::ParseIntError,
slice,
str::FromStr, str::FromStr,
}; };
@ -15,7 +17,65 @@ use crate::{
use libc::{if_nametoindex, sysconf, _SC_PAGESIZE}; use libc::{if_nametoindex, sysconf, _SC_PAGESIZE};
use io::BufRead; /// 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)]
pub struct KernelVersion {
pub(crate) major: u8,
pub(crate) minor: u8,
pub(crate) patch: u16,
}
impl KernelVersion {
/// Constructor.
pub fn new(major: u8, minor: u8, patch: u16) -> Self {
Self {
major,
minor,
patch,
}
}
/// Returns the kernel version of the currently running kernel.
///
/// This is taken from `/proc/sys/kernel/osrelease`;
pub fn current() -> Result<Self, String> {
let s =
fs::read_to_string("/proc/sys/kernel/osrelease").map_err(|err| format!("{err:?}"))?;
let s = s.as_str();
let pos = s.find(|c: char| c != '.' && !c.is_ascii_digit());
let kernel = if let Some(pos) = pos {
let (s, _) = s.split_at(pos);
s
} else {
s
};
let mut kernel_split = kernel.split('.');
let major = kernel_split
.next()
.ok_or("Missing major version component")?;
let minor = kernel_split
.next()
.ok_or("Missing minor version component")?;
let patch = kernel_split
.next()
.ok_or("Missing patch version component")?;
let major = major
.parse()
.map_err(|ParseIntError { .. }| "Failed to parse major version")?;
let minor = minor
.parse()
.map_err(|ParseIntError { .. }| "Failed to parse minor version")?;
let patch = patch
.parse()
.map_err(|ParseIntError { .. }| "Failed to parse patch version")?;
Ok(Self::new(major, minor, patch))
}
}
const ONLINE_CPUS: &str = "/sys/devices/system/cpu/online"; const ONLINE_CPUS: &str = "/sys/devices/system/cpu/online";
pub(crate) const POSSIBLE_CPUS: &str = "/sys/devices/system/cpu/possible"; pub(crate) const POSSIBLE_CPUS: &str = "/sys/devices/system/cpu/possible";

@ -12,7 +12,6 @@ aya-obj = { path = "../../aya-obj" }
libc = { version = "0.2.105" } libc = { version = "0.2.105" }
log = "0.4" log = "0.4"
object = { version = "0.31", default-features = false, features = ["std", "read_core", "elf"] } object = { version = "0.31", default-features = false, features = ["std", "read_core", "elf"] }
procfs = "0.15.1"
rbpf = "0.2.0" rbpf = "0.2.0"
tempfile = "3.3.0" tempfile = "3.3.0"
tokio = { version = "1.24", features = ["rt", "rt-multi-thread", "sync", "time"] } tokio = { version = "1.24", features = ["rt", "rt-multi-thread", "sync", "time"] }

@ -1,9 +1,8 @@
use anyhow::{bail, Context as _, Result}; use anyhow::{bail, Context as _, Result};
use procfs::KernelVersion;
use std::{path::PathBuf, process::Command, thread::sleep, time::Duration}; use std::{path::PathBuf, process::Command, thread::sleep, time::Duration};
use tempfile::TempDir; use tempfile::TempDir;
use aya::{maps::Array, programs::TracePoint, BpfLoader, Btf, Endianness}; use aya::{maps::Array, programs::TracePoint, util::KernelVersion, BpfLoader, Btf, Endianness};
// In the tests below we often use values like 0xAAAAAAAA or -0x7AAAAAAA. Those values have no // In the tests below we often use values like 0xAAAAAAAA or -0x7AAAAAAA. Those values have no
// special meaning, they just have "nice" bit patterns that can be helpful while debugging. // special meaning, they just have "nice" bit patterns that can be helpful while debugging.

@ -1,4 +1,3 @@
use procfs::KernelVersion;
use std::{convert::TryInto as _, thread, time}; use std::{convert::TryInto as _, thread, time};
use aya::{ use aya::{
@ -8,6 +7,7 @@ use aya::{
links::{FdLink, PinnedLink}, links::{FdLink, PinnedLink},
loaded_programs, KProbe, TracePoint, Xdp, XdpFlags, loaded_programs, KProbe, TracePoint, Xdp, XdpFlags,
}, },
util::KernelVersion,
Bpf, Bpf,
}; };

@ -1,8 +1,7 @@
use procfs::KernelVersion;
use aya::{ use aya::{
include_bytes_aligned, include_bytes_aligned,
programs::{Extension, Xdp, XdpFlags}, programs::{Extension, Xdp, XdpFlags},
util::KernelVersion,
Bpf, BpfLoader, Bpf, BpfLoader,
}; };

Loading…
Cancel
Save