summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2020-08-04 16:52:29 +0100
committerEmīls <emils@mullvad.net>2020-08-05 15:30:06 +0100
commit9b64aadc2e610fafb19b2118af9f03e9a4d3fdb7 (patch)
tree7fda6d67a4bbbeb2b1222e9f23242695d3ac1007
parent54757f71320830c3e37904851847da0ad205737e (diff)
downloadmullvadvpn-9b64aadc2e610fafb19b2118af9f03e9a4d3fdb7.tar.xz
mullvadvpn-9b64aadc2e610fafb19b2118af9f03e9a4d3fdb7.zip
Use systemd-resolved only with the stub resolvconf
-rw-r--r--talpid-core/src/dns/linux/systemd_resolved.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/talpid-core/src/dns/linux/systemd_resolved.rs b/talpid-core/src/dns/linux/systemd_resolved.rs
index 4aa9cd50e9..ee0ad7e793 100644
--- a/talpid-core/src/dns/linux/systemd_resolved.rs
+++ b/talpid-core/src/dns/linux/systemd_resolved.rs
@@ -49,12 +49,13 @@ pub enum Error {
}
lazy_static! {
- static ref RESOLVED_PATHS: Vec<&'static Path> = vec![
+ static ref RESOLVED_STUB_PATHS: Vec<&'static Path> = vec![
Path::new("/run/systemd/resolve/stub-resolv.conf"),
- Path::new("/run/systemd/resolve/resolv.conf"),
+ Path::new("/var/run/systemd/resolve/stub-resolv.conf"),
];
}
+
const RESOLVED_BUS: &str = "org.freedesktop.resolve1";
const RPC_TIMEOUT_MS: i32 = 1000;
@@ -99,21 +100,26 @@ impl SystemdResolved {
}
fn ensure_resolv_conf_is_resolved_symlink() -> Result<()> {
- let is_correct_symlink = fs::read_link(RESOLV_CONF_PATH)
- .map(|resolv_conf_target| Self::compare_resolvconf_symlink(&resolv_conf_target))
- .unwrap_or_else(|_| false);
- if is_correct_symlink {
+ let link_target =
+ fs::read_link(RESOLV_CONF_PATH).map_err(|_| Error::NotSymlinkedToResolvConf)?;
+
+ // if /etc/resolv.conf is not symlinked to the stub resolve.conf file , managing DNS
+ // through systemd-resolved will not ensure that our resolver is given priority - sometimes
+ // this will mean adding 1 and 2 seconds of latency to DNS queries, other times our
+ // resolver won't be considered at all. In this case, it's better to fall back to cruder
+ // management methods.
+ if Self::path_is_resolvconf_stub(&link_target) {
Ok(())
} else {
Err(Error::NotSymlinkedToResolvConf)
}
}
- fn compare_resolvconf_symlink(link_path: &Path) -> bool {
+ fn path_is_resolvconf_stub(link_path: &Path) -> bool {
// if link path is relative to /etc/resolv.conf, resolve the path and compare it.
if link_path.is_relative() {
match Path::new("/etc/").join(link_path).canonicalize() {
- Ok(link_destination) => RESOLVED_PATHS.contains(&link_destination.as_ref()),
+ Ok(link_destination) => RESOLVED_STUB_PATHS.contains(&link_destination.as_ref()),
Err(e) => {
log::error!(
"Failed to canonicalize resolv conf path {} - {}",
@@ -124,7 +130,7 @@ impl SystemdResolved {
}
}
} else {
- RESOLVED_PATHS.contains(&link_path)
+ RESOLVED_STUB_PATHS.contains(&link_path)
}
}