summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-10-16 13:33:48 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-10-22 09:33:58 +0200
commit63f7862295dc9a765f29e771d4222ba8457f8b8a (patch)
tree8bc2cc6eb48b3ebf6874db7a8f03b6b2e7b26b4a
parentcb4a5587cac2ed3e051ec9b787230a02bf477990 (diff)
downloadmullvadvpn-63f7862295dc9a765f29e771d4222ba8457f8b8a.tar.xz
mullvadvpn-63f7862295dc9a765f29e771d4222ba8457f8b8a.zip
Add CLI interface for custom DNS
-rw-r--r--mullvad-cli/src/cmds/custom_dns.rs74
-rw-r--r--mullvad-cli/src/cmds/mod.rs4
2 files changed, 78 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/custom_dns.rs b/mullvad-cli/src/cmds/custom_dns.rs
new file mode 100644
index 0000000000..1ae196f47c
--- /dev/null
+++ b/mullvad-cli/src/cmds/custom_dns.rs
@@ -0,0 +1,74 @@
+use crate::{new_rpc_client, Command, Result};
+use mullvad_management_interface::types;
+
+pub struct CustomDns;
+
+#[mullvad_management_interface::async_trait]
+impl Command for CustomDns {
+ fn name(&self) -> &'static str {
+ "custom-dns"
+ }
+
+ fn clap_subcommand(&self) -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name(self.name())
+ .about("Configure custom DNS servers to use when connected")
+ .setting(clap::AppSettings::SubcommandRequiredElseHelp)
+ .subcommand(
+ clap::SubCommand::with_name("set")
+ .about("Change custom DNS setting")
+ .arg(
+ clap::Arg::with_name("servers")
+ .multiple(true)
+ .required(false),
+ ),
+ )
+ .subcommand(
+ clap::SubCommand::with_name("get").about("Display the current custom DNS setting"),
+ )
+ }
+
+ async fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
+ if let Some(set_matches) = matches.subcommand_matches("set") {
+ self.set(set_matches.values_of_lossy("servers")).await
+ } else if let Some(_matches) = matches.subcommand_matches("get") {
+ self.get().await
+ } else {
+ unreachable!("No custom-dns command given");
+ }
+ }
+}
+
+impl CustomDns {
+ async fn set(&self, servers: Option<Vec<String>>) -> Result<()> {
+ let mut rpc = new_rpc_client().await?;
+ rpc.set_custom_dns(types::CustomDns {
+ addresses: servers.unwrap_or_default(),
+ })
+ .await?;
+ println!("Updated custom DNS settings");
+ Ok(())
+ }
+
+ async fn get(&self) -> Result<()> {
+ let mut rpc = new_rpc_client().await?;
+ let custom_dns = rpc
+ .get_settings(())
+ .await?
+ .into_inner()
+ .tunnel_options
+ .unwrap()
+ .generic
+ .unwrap()
+ .custom_dns;
+ match custom_dns {
+ None => println!("No DNS servers are configured"),
+ Some(types::CustomDns { addresses }) => {
+ println!("Custom DNS servers:");
+ for server in &addresses {
+ println!("\t{}", server);
+ }
+ }
+ }
+ Ok(())
+ }
+}
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs
index 9cdefd19c5..ae3739289e 100644
--- a/mullvad-cli/src/cmds/mod.rs
+++ b/mullvad-cli/src/cmds/mod.rs
@@ -25,6 +25,9 @@ pub use self::disconnect::Disconnect;
mod lan;
pub use self::lan::Lan;
+mod custom_dns;
+pub use self::custom_dns::CustomDns;
+
mod reconnect;
pub use self::reconnect::Reconnect;
@@ -60,6 +63,7 @@ pub fn get_commands() -> HashMap<&'static str, Box<dyn Command>> {
Box::new(Disconnect),
Box::new(Reconnect),
Box::new(Lan),
+ Box::new(CustomDns),
Box::new(Relay),
Box::new(Reset),
#[cfg(target_os = "linux")]