diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-06-04 14:50:33 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-06-04 14:50:33 +0200 |
| commit | 2d624ed34da8eedd9e967e6d3c3d095981ad49db (patch) | |
| tree | 214e7103b4d2250e4f8d66b65679a09df20d4f56 /mullvad-cli/src/cmds/split_tunnel | |
| parent | 76a75a268abb1ac8daeffd39087c96cc6fe688c0 (diff) | |
| parent | 48707812900cd46054a307225784f855fcc4b228 (diff) | |
| download | mullvadvpn-2d624ed34da8eedd9e967e6d3c3d095981ad49db.tar.xz mullvadvpn-2d624ed34da8eedd9e967e6d3c3d095981ad49db.zip | |
Merge branch 'split-tunnel-update-mods'
Diffstat (limited to 'mullvad-cli/src/cmds/split_tunnel')
| -rw-r--r-- | mullvad-cli/src/cmds/split_tunnel/linux.rs | 70 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/split_tunnel/mod.rs | 6 |
2 files changed, 76 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/split_tunnel/linux.rs b/mullvad-cli/src/cmds/split_tunnel/linux.rs new file mode 100644 index 0000000000..95b172eb6b --- /dev/null +++ b/mullvad-cli/src/cmds/split_tunnel/linux.rs @@ -0,0 +1,70 @@ +use crate::{new_rpc_client, Command, Result}; +use clap::value_t_or_exit; + +pub struct SplitTunnel; + +impl Command for SplitTunnel { + fn name(&self) -> &'static str { + "split-tunnel" + } + + fn clap_subcommand(&self) -> clap::App<'static, 'static> { + clap::SubCommand::with_name(self.name()) + .about("Manage split tunneling") + .setting(clap::AppSettings::SubcommandRequiredElseHelp) + .subcommand(create_pid_subcommand()) + } + + fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> { + match matches.subcommand() { + ("pid", Some(pid_matches)) => Self::handle_pid_cmd(pid_matches), + _ => unreachable!("unhandled comand"), + } + } +} + +fn create_pid_subcommand() -> clap::App<'static, 'static> { + clap::SubCommand::with_name("pid") + .about("Manage processes to exclude from the tunnel") + .setting(clap::AppSettings::SubcommandRequiredElseHelp) + .subcommand( + clap::SubCommand::with_name("add").arg(clap::Arg::with_name("pid").required(true)), + ) + .subcommand( + clap::SubCommand::with_name("delete").arg(clap::Arg::with_name("pid").required(true)), + ) + .subcommand(clap::SubCommand::with_name("clear")) + .subcommand(clap::SubCommand::with_name("list")) +} + +impl SplitTunnel { + fn handle_pid_cmd(matches: &clap::ArgMatches<'_>) -> Result<()> { + match matches.subcommand() { + ("add", Some(matches)) => { + let pid = value_t_or_exit!(matches.value_of("pid"), i32); + new_rpc_client()?.add_split_tunnel_process(pid)?; + Ok(()) + } + ("delete", Some(matches)) => { + let pid = value_t_or_exit!(matches.value_of("pid"), i32); + new_rpc_client()?.remove_split_tunnel_process(pid)?; + Ok(()) + } + ("clear", Some(_)) => { + new_rpc_client()?.clear_split_tunnel_processes()?; + Ok(()) + } + ("list", Some(_)) => { + let pids = new_rpc_client()?.get_split_tunnel_processes()?; + println!("Excluded PIDs:"); + + for pid in pids.iter() { + println!(" {}", pid); + } + + Ok(()) + } + _ => unreachable!("unhandled command"), + } + } +} diff --git a/mullvad-cli/src/cmds/split_tunnel/mod.rs b/mullvad-cli/src/cmds/split_tunnel/mod.rs new file mode 100644 index 0000000000..c7c366d6ea --- /dev/null +++ b/mullvad-cli/src/cmds/split_tunnel/mod.rs @@ -0,0 +1,6 @@ +#[cfg(target_os = "linux")] +#[path = "linux.rs"] +mod imp; + +#[cfg(target_os = "linux")] +pub use imp::*; |
