Code cleanup

This commit is contained in:
Ilia Zhirov
2026-02-19 16:11:13 +05:00
parent d8329217cf
commit ab0597f558

View File

@@ -406,23 +406,19 @@ fn main() {
/// Returns the domain part of an address string if it is a domain (not an IP).
/// Returns `None` for IP addresses (both IPv4 and IPv6).
fn extract_domain_for_warning(addr: &str) -> Option<&str> {
// If the whole string parses as a SocketAddr (covers IPv4, [IPv6]:port), it's an IP.
if SocketAddr::from_str(addr).is_ok() {
return None;
}
// If the whole string parses as an IpAddr (bare IPv4 or bare IPv6 like ::1), it's an IP.
if addr.parse::<std::net::IpAddr>().is_ok() {
return None;
}
let domain = addr.rsplit_once(':').map(|(d, _)| d).unwrap_or(addr);
// After splitting on ':', check the domain part is not an IP.
if domain.parse::<std::net::IpAddr>().is_ok() {
return None;
}
Some(domain)
}
/// Returns `true` if `domain` matches any hostname or allowed SNI in the TLS hosts settings.
fn domain_matches_tls_hosts(domain: &str, tls_hosts_settings: &settings::TlsHostsSettings) -> bool {
tls_hosts_settings
.get_main_hosts()
@@ -437,11 +433,6 @@ fn domain_matches_tls_hosts(domain: &str, tls_hosts_settings: &settings::TlsHost
/// - `IP` without port (e.g. `1.2.3.4`, `::1`) — `default_port` is appended
/// - `domain:port` (e.g. `vpn.example.com:443`)
/// - `domain` without port (e.g. `vpn.example.com`) — `default_port` is appended
///
/// **Note:** IPv6 addresses with a port **must** use bracket notation: `[::1]:443`.
/// A bare IPv6 address without brackets (e.g. `::1`) is accepted only when no port
/// is specified — `default_port` is then appended. The ambiguous form `2001:db8::1:443`
/// (IPv6 with port, no brackets) is not supported and will be misinterpreted.
fn parse_endpoint_address(input: &str, default_port: u16) -> String {
if let Ok(addr) = SocketAddr::from_str(input) {
return addr.to_string();
@@ -449,7 +440,6 @@ fn parse_endpoint_address(input: &str, default_port: u16) -> String {
if let Ok(addr) = SocketAddr::from_str(&format!("{input}:{default_port}")) {
return addr.to_string();
}
// Bare IPv6 without brackets, e.g. "::1"
if let Ok(ip) = input.parse::<std::net::IpAddr>() {
return SocketAddr::new(ip, default_port).to_string();
}