Changed default CIDR

This commit is contained in:
2026-06-29 06:12:21 -03:00
parent 75fb09e767
commit 9838e1b612
4 changed files with 46 additions and 27 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM rust:1.78-bookworm AS builder FROM rust:stable-bookworm AS builder
WORKDIR /app WORKDIR /app
COPY Cargo.toml Cargo.lock ./ COPY Cargo.toml Cargo.lock ./
+1 -1
View File
@@ -19,7 +19,7 @@ services:
command: ["coordinator"] command: ["coordinator"]
environment: environment:
DATABASE_URL: postgres://camfinder:camfinder@postgres:5432/camfinder DATABASE_URL: postgres://camfinder:camfinder@postgres:5432/camfinder
SCAN_CIDRS: 192.168.15.0/24 SCAN_CIDR_FILE: /app/cidrs.txt
SCAN_PORT: 554 SCAN_PORT: 554
SCAN_TIMEOUT_MS: 1200 SCAN_TIMEOUT_MS: 1200
SCAN_CONCURRENCY: 16 SCAN_CONCURRENCY: 16
+10 -10
View File
@@ -200,16 +200,6 @@ fn load_cidrs(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<String>>
return Err(anyhow!("arquivo de CIDRs vazio: {}", file.display())); return Err(anyhow!("arquivo de CIDRs vazio: {}", file.display()));
} }
if let Ok(value) = env::var("SCAN_CIDRS") {
let value = value.trim();
if !value.is_empty() {
let cidrs = parse_cidr_list(value);
if !cidrs.is_empty() {
return Ok(cidrs);
}
}
}
if let Ok(path) = env::var("SCAN_CIDR_FILE") { if let Ok(path) = env::var("SCAN_CIDR_FILE") {
let path = path.trim(); let path = path.trim();
if !path.is_empty() { if !path.is_empty() {
@@ -223,6 +213,16 @@ fn load_cidrs(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<String>>
} }
} }
if let Ok(value) = env::var("SCAN_CIDRS") {
let value = value.trim();
if !value.is_empty() {
let cidrs = parse_cidr_list(value);
if !cidrs.is_empty() {
return Ok(cidrs);
}
}
}
if let Ok(value) = env::var("SCAN_CIDR") { if let Ok(value) = env::var("SCAN_CIDR") {
let value = value.trim(); let value = value.trim();
if !value.is_empty() { if !value.is_empty() {
+28 -9
View File
@@ -84,7 +84,10 @@ fn validate_and_filter_cidrs(cidrs: &[String]) -> Result<Vec<String>> {
} }
if skipped_count > 0 { if skipped_count > 0 {
eprintln!("️ Total de {} CIDR(s) privados/não roteáveis ignorados", skipped_count); eprintln!(
"️ Total de {} CIDR(s) privados/não roteáveis ignorados",
skipped_count
);
} }
if valid_cidrs.is_empty() { if valid_cidrs.is_empty() {
@@ -113,7 +116,9 @@ fn validate_cidr(cidr: &str) -> Result<CidrType> {
.map_err(|_| anyhow::anyhow!("máscara de sub-rede inválida: {prefix}"))?; .map_err(|_| anyhow::anyhow!("máscara de sub-rede inválida: {prefix}"))?;
if prefix > 32 { if prefix > 32 {
return Err(anyhow::anyhow!("máscara de sub-rede deve ser <= 32: {prefix}")); return Err(anyhow::anyhow!(
"máscara de sub-rede deve ser <= 32: {prefix}"
));
} }
let ip: std::net::Ipv4Addr = network let ip: std::net::Ipv4Addr = network
@@ -249,17 +254,31 @@ mod tests {
#[test] #[test]
fn test_routable_ips() { fn test_routable_ips() {
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(1, 2, 3, 4)))); assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(8, 8, 8, 8)))); 1, 2, 3, 4
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(203, 0, 114, 1)))); ))));
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(
8, 8, 8, 8
))));
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(
203, 0, 114, 1
))));
} }
#[test] #[test]
fn test_private_ips() { fn test_private_ips() {
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(10, 0, 0, 1)))); assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(172, 16, 0, 1)))); 10, 0, 0, 1
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(192, 168, 1, 1)))); ))));
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(127, 0, 0, 1)))); assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(
172, 16, 0, 1
))));
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(
192, 168, 1, 1
))));
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(
127, 0, 0, 1
))));
} }
#[test] #[test]