Skip to content

Commit

Permalink
Refactor Cargo.toml and linux_monitor.rs to use the 'bpf' feature for…
Browse files Browse the repository at this point in the history
… the rust_http_proxy task
  • Loading branch information
arloor committed Oct 14, 2024
1 parent f88e7a2 commit 84e0a76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rust_http_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ serde_yaml = "0.9"
serde = { version = "1.0", features = ["derive"] }

[target.'cfg(target_os = "linux")'.dependencies]
socket_filter = { version = "0.1", optional = true }
cgroup_traffic = { version = "0.1", optional = true }
socket_filter = { git = "https://github.com/arloor/bpf_rs_hub", optional = true }
cgroup_traffic = { git = "https://github.com/arloor/bpf_rs_hub", optional = true }
libbpf-sys = { version = "1", optional = true }
pnet = { version = "0.35", optional = true }

Expand Down
18 changes: 14 additions & 4 deletions rust_http_proxy/src/linux_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,24 @@ const INTERVAL_SECONDS: u64 = 5;
const SIZE: usize = TOTAL_SECONDS as usize / INTERVAL_SECONDS as usize;
impl NetMonitor {
pub fn new() -> Result<NetMonitor, crate::DynError> {
#[cfg(all(target_os = "linux", feature = "bpf"))]
use std::mem::MaybeUninit;
#[cfg(all(target_os = "linux", feature = "bpf"))]
let (cgroup_traffic_counter, links) = cgroup_traffic::init_cgroup_skb_monitor(
Box::leak(Box::new(MaybeUninit::uninit())),
cgroup_traffic::SELF,
)?;
#[cfg(all(target_os = "linux", feature = "bpf"))]
Box::leak(Box::new(links));
Ok(NetMonitor {
buffer: Arc::new(RwLock::new(VecDeque::<TimeValue>::new())),
#[cfg(all(target_os = "linux", feature = "bpf"))]
cgroup_transmit_counter: Arc::new(cgroup_traffic::init_cgroup_skb_monitor(
cgroup_traffic::SELF,
)?),
cgroup_transmit_counter: Arc::new(cgroup_traffic_counter),
#[cfg(all(target_os = "linux", feature = "bpf"))]
transmit_counter: Arc::new(socket_filter::TransmitCounter::new(IGNORED_INTERFACES)?),
transmit_counter: Arc::new(socket_filter::TransmitCounter::new(
Box::leak(Box::new(MaybeUninit::uninit())),
IGNORED_INTERFACES,
)?),
})
}

Expand Down

0 comments on commit 84e0a76

Please sign in to comment.