Changed default CIDR
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM rust:1.78-bookworm AS builder
|
||||
FROM rust:stable-bookworm AS builder
|
||||
WORKDIR /app
|
||||
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ services:
|
||||
command: ["coordinator"]
|
||||
environment:
|
||||
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_TIMEOUT_MS: 1200
|
||||
SCAN_CONCURRENCY: 16
|
||||
|
||||
+10
-10
@@ -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()));
|
||||
}
|
||||
|
||||
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") {
|
||||
let path = path.trim();
|
||||
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") {
|
||||
let value = value.trim();
|
||||
if !value.is_empty() {
|
||||
|
||||
+28
-9
@@ -84,7 +84,10 @@ fn validate_and_filter_cidrs(cidrs: &[String]) -> Result<Vec<String>> {
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -113,7 +116,9 @@ fn validate_cidr(cidr: &str) -> Result<CidrType> {
|
||||
.map_err(|_| anyhow::anyhow!("máscara de sub-rede inválida: {prefix}"))?;
|
||||
|
||||
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
|
||||
@@ -249,17 +254,31 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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(8, 8, 8, 8))));
|
||||
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(203, 0, 114, 1))));
|
||||
assert!(is_routable_ip(u32::from(std::net::Ipv4Addr::new(
|
||||
1, 2, 3, 4
|
||||
))));
|
||||
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]
|
||||
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(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))));
|
||||
assert!(!is_routable_ip(u32::from(std::net::Ipv4Addr::new(
|
||||
10, 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]
|
||||
|
||||
Reference in New Issue
Block a user