From 88928604907aeba0d70a75ed2078b87bc0c78d66 Mon Sep 17 00:00:00 2001 From: artemws <59208085+artemws@users.noreply.github.com> Date: Fri, 20 Feb 2026 16:04:21 +0200 Subject: [PATCH] Change whitelist to use IpNetwork for IP filtering --- src/metrics.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/metrics.rs b/src/metrics.rs index fa6c680..5222295 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -1,5 +1,5 @@ use std::convert::Infallible; -use std::net::{IpAddr, SocketAddr}; +use std::net::SocketAddr; use std::sync::Arc; use http_body_util::Full; @@ -7,12 +7,13 @@ use hyper::body::Bytes; use hyper::server::conn::http1; use hyper::service::service_fn; use hyper::{Request, Response, StatusCode}; +use ipnetwork::IpNetwork; use tokio::net::TcpListener; use tracing::{info, warn, debug}; use crate::stats::Stats; -pub async fn serve(port: u16, stats: Arc, whitelist: Vec) { +pub async fn serve(port: u16, stats: Arc, whitelist: Vec) { let addr = SocketAddr::from(([0, 0, 0, 0], port)); let listener = match TcpListener::bind(addr).await { Ok(l) => l, @@ -32,7 +33,7 @@ pub async fn serve(port: u16, stats: Arc, whitelist: Vec) { } }; - if !whitelist.is_empty() && !whitelist.contains(&peer.ip()) { + if !whitelist.is_empty() && !whitelist.iter().any(|net| net.contains(peer.ip())) { debug!(peer = %peer, "Metrics request denied by whitelist"); continue; }