-
-
Notifications
You must be signed in to change notification settings - Fork 335
Add option to exclude IPs #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
af43365
148fae0
2aa6de4
f4cad33
798c662
b37571a
3ba1f9c
b2dde6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,13 @@ where | |
| move || { | ||
| while running.load(Ordering::Acquire) { | ||
| let render_start_time = Instant::now(); | ||
| let utilization = { network_utilization.lock().unwrap().clone_and_reset() }; | ||
| let mut utilization = { network_utilization.lock().unwrap().clone_and_reset() }; | ||
| if let Some(ref ex) = opts.excluded_ipv4 { | ||
| utilization.remove_ip(ex) | ||
| } | ||
| if let Some(ref ex) = opts.excluded_ipv4_port { | ||
| utilization.remove_ip_port(ex) | ||
| } | ||
|
||
| let OpenSockets { sockets_to_procs } = get_open_sockets(); | ||
| let mut ip_to_host = IpTable::new(); | ||
| if let Some(dns_client) = dns_client.as_mut() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| use std::collections::HashMap; | ||
| use std::{ | ||
| collections::HashMap, | ||
| net::{Ipv4Addr, SocketAddrV4}, | ||
| }; | ||
|
|
||
| use crate::network::{Connection, Direction, Segment}; | ||
|
|
||
|
|
@@ -42,4 +45,36 @@ impl Utilization { | |
| } | ||
| } | ||
| } | ||
| pub fn remove_ip(&mut self, ips: &[Ipv4Addr]) { | ||
| // might be possible to refactor this part better | ||
| // i still don't understand the whole borrow/own system very well yet | ||
| let placeholder = self.connections.clone(); | ||
|
||
| for util in placeholder { | ||
| match util.0.remote_socket.ip { | ||
| std::net::IpAddr::V4(ip) => { | ||
| if ips.contains(&ip) { | ||
| self.connections.remove_entry(&util.0); | ||
| } | ||
| } | ||
| std::net::IpAddr::V6(..) => { /* nothing here yet (maybe implement it for ipV6 too) */ | ||
| } | ||
| } | ||
| } | ||
| } | ||
| pub fn remove_ip_port(&mut self, ips: &[SocketAddrV4]) { | ||
| // might be possible to refactor this part better | ||
| // i still don't understand the whole borrow/own system very well yet | ||
| let placeholder = self.connections.clone(); | ||
| for util in placeholder { | ||
| match util.0.remote_socket.ip { | ||
| std::net::IpAddr::V4(ip) => { | ||
| if ips.contains(&SocketAddrV4::new(ip, util.0.remote_socket.port)) { | ||
| self.connections.remove_entry(&util.0); | ||
| } | ||
| } | ||
| std::net::IpAddr::V6(..) => { /* nothing here yet (maybe implement it for ipV6 too) */ | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty rigid and non-extensible. For example, it's pretty reasonable for a user to want to exclude by hostname. Or by CIDR. Do we need an option for each? And then double that if we want to support IPv6 (which we definitely do; it's not 2003).
Much better would be to declare a struct/enum
HostFilter(or something like that) and implementFromStrandDisplayfor it so that it can be used as a clap option parameter. Then all these different kinds of possible filters can be united under a single option.