Skip to content

Commit

Permalink
Do not touch DNS config if localhost is used
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Pettersson <markus.pettersson@mullvad.net>
  • Loading branch information
dlon and MarkusPettersson98 committed Sep 25, 2024
1 parent 7b54ec3 commit b668c86
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions talpid-core/src/dns/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl State {
match settings {
// Do nothing if the state is already what we want
Some(settings) if settings.address_set() == desired_set => (),
// Ignore loopback addresses
Some(settings) if settings.ips().any(|ip| ip.is_loopback()) => {
log::trace!("Not updating DNS config: localhost is used");
}
// Apply desired state to service
_ => {
let path_cf = CFString::new(path);
Expand Down Expand Up @@ -280,6 +284,12 @@ impl DnsSettings {
BTreeSet::from_iter(self.server_addresses())
}

pub fn ips(&self) -> impl Iterator<Item = IpAddr> {
self.server_addresses()
.into_iter()
.filter_map(|addr| addr.parse::<IpAddr>().ok())
}

/// Parses a CFArray into a Rust vector of Rust strings, if the array contains CFString
/// instances only, otherwise `None` is returned.
fn parse_cf_array_to_strings(array: CFArray) -> Option<Vec<String>> {
Expand Down

0 comments on commit b668c86

Please sign in to comment.