Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Ignore bond as well as tun for network activity #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/widgets/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::colorscheme::Colorscheme;
use crate::update::UpdatableWidget;
use crate::widgets::block;

const VPN_INTERFACE: &str = "tun0";
const BOND_INTERFACE_PREFIX: &str = "bond";
const TUN_INTERFACE_PREFIX: &str = "tun";

pub struct NetWidget<'a, 'b> {
title: String,
Expand Down Expand Up @@ -62,9 +63,14 @@ impl UpdatableWidget for NetWidget<'_, '_> {
.unwrap()
.into_iter()
.filter(|(name, _counters)| {
// Filter out the VPN interface unless specified directly since it gets double
// Filter out tunnels and bonds unless specified directly since it gets double
// counted along with the hardware interfaces it is operating on.
(self.interface == "all" && name != VPN_INTERFACE) || name == self.interface
// TODO: Ideally it would be good to detect if the interface is virtual instead of
// hardcoding these cases
(self.interface == "all"
&& !name.starts_with(TUN_INTERFACE_PREFIX)
&& !name.starts_with(BOND_INTERFACE_PREFIX))
|| name == self.interface
})
.map(|(_name, counters)| counters)
.sum();
Expand Down