From d9fda840d8851663fe85359a950e38120daaf289 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Thu, 2 Jan 2025 17:50:09 +0800 Subject: [PATCH] fix(dns): IP strategy option not respected for dns resolve method `resolv` (#1461) --- crates/trippy-dns/src/lazy_resolver.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/trippy-dns/src/lazy_resolver.rs b/crates/trippy-dns/src/lazy_resolver.rs index 4937e702..1ad4f301 100644 --- a/crates/trippy-dns/src/lazy_resolver.rs +++ b/crates/trippy-dns/src/lazy_resolver.rs @@ -98,6 +98,7 @@ mod inner { use hickory_resolver::error::{ResolveError, ResolveErrorKind}; use hickory_resolver::proto::error::ProtoError; use hickory_resolver::proto::rr::RecordType; + use hickory_resolver::system_conf::read_system_conf; use hickory_resolver::{Name, Resolver}; use itertools::{Either, Itertools}; use parking_lot::RwLock; @@ -166,15 +167,21 @@ mod inner { DnsProvider::DnsLookup } else { let mut options = ResolverOpts::default(); - options.timeout = config.timeout; - options.ip_strategy = match config.addr_family { + let ip_strategy = match config.addr_family { IpAddrFamily::Ipv4Only => LookupIpStrategy::Ipv4Only, IpAddrFamily::Ipv6Only => LookupIpStrategy::Ipv6Only, IpAddrFamily::Ipv6thenIpv4 => LookupIpStrategy::Ipv6thenIpv4, IpAddrFamily::Ipv4thenIpv6 => LookupIpStrategy::Ipv4thenIpv6, }; + options.timeout = config.timeout; + options.ip_strategy = ip_strategy; let res = match config.resolve_method { - ResolveMethod::Resolv => Resolver::from_system_conf(), + ResolveMethod::Resolv => { + let (resolver_cfg, mut options) = read_system_conf()?; + options.timeout = config.timeout; + options.ip_strategy = ip_strategy; + Resolver::new(resolver_cfg, options) + } ResolveMethod::Google => Resolver::new(ResolverConfig::google(), options), ResolveMethod::Cloudflare => { Resolver::new(ResolverConfig::cloudflare(), options)