-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2353 from zmrow/dns-settings
Add configurable DNS settings
- Loading branch information
Showing
35 changed files
with
587 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{#if settings.dns.name-servers}} | ||
name-servers = [{{join_array ", " settings.dns.name-servers }}] | ||
{{/if}} | ||
{{#if settings.dns.search-list}} | ||
search-list = [{{join_array ", " settings.dns.search-list }}] | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
sources/api/migration/migrations/v1.10.0/dns-settings-metadata/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "dns-settings-metadata" | ||
version = "0.1.0" | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers", version = "0.1.0"} |
23 changes: 23 additions & 0 deletions
23
sources/api/migration/migrations/v1.10.0/dns-settings-metadata/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![deny(rust_2018_idioms)] | ||
|
||
use migration_helpers::common_migrations::{AddMetadataMigration, SettingMetadata}; | ||
use migration_helpers::{migrate, Result}; | ||
use std::process; | ||
|
||
/// We added a new setting and `affected-services` metadata for `settings.dns` | ||
fn run() -> Result<()> { | ||
migrate(AddMetadataMigration(&[SettingMetadata { | ||
metadata: &["affected-services"], | ||
setting: "settings.dns", | ||
}])) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
sources/api/migration/migrations/v1.10.0/dns-settings/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "dns-settings" | ||
version = "0.1.0" | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers", version = "0.1.0"} |
24 changes: 24 additions & 0 deletions
24
sources/api/migration/migrations/v1.10.0/dns-settings/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![deny(rust_2018_idioms)] | ||
|
||
use migration_helpers::common_migrations::AddPrefixesMigration; | ||
use migration_helpers::{migrate, Result}; | ||
use std::process; | ||
|
||
/// We added new settings under `settings.dns` for configuring /etc/resolv.conf | ||
fn run() -> Result<()> { | ||
migrate(AddPrefixesMigration(vec![ | ||
"settings.dns", | ||
"services.dns", | ||
"configuration-files.netdog-toml", | ||
])) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use super::{error, Result}; | ||
use crate::dns::DnsSettings; | ||
use crate::lease::{lease_path, LeaseInfo}; | ||
use crate::PRIMARY_INTERFACE; | ||
use argh::FromArgs; | ||
use snafu::ResultExt; | ||
use std::fs; | ||
|
||
#[derive(FromArgs, PartialEq, Debug)] | ||
#[argh(subcommand, name = "write-resolv-conf")] | ||
/// Writes /etc/resolv.conf, using DNS API settings if they exist | ||
pub(crate) struct WriteResolvConfArgs {} | ||
|
||
pub(crate) fn run() -> Result<()> { | ||
// Use DNS API settings if they exist, supplementing any missing settings with settings | ||
// derived from the primary interface's DHCP lease if it exists | ||
let primary_interface = fs::read_to_string(PRIMARY_INTERFACE) | ||
.context(error::PrimaryInterfaceReadSnafu { | ||
path: PRIMARY_INTERFACE, | ||
})? | ||
.trim() | ||
.to_lowercase(); | ||
|
||
let primary_lease_path = lease_path(&primary_interface); | ||
let dns_settings = if let Some(primary_lease_path) = primary_lease_path { | ||
let lease = | ||
LeaseInfo::from_lease(&primary_lease_path).context(error::LeaseParseFailedSnafu)?; | ||
DnsSettings::from_config_or_lease(Some(&lease)).context(error::GetDnsSettingsSnafu)? | ||
} else { | ||
DnsSettings::from_config_or_lease(None).context(error::GetDnsSettingsSnafu)? | ||
}; | ||
|
||
dns_settings | ||
.write_resolv_conf() | ||
.context(error::ResolvConfWriteFailedSnafu)?; | ||
Ok(()) | ||
} |
Oops, something went wrong.