diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-06-02 11:03:12 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-06-02 11:03:12 +0200 |
| commit | bae528b847e13faf0ea745e29c8d119687241e5c (patch) | |
| tree | 69768eac1f8d27c0359cfa316365da371480bc99 /mullvad-cli/src | |
| parent | 3b59a0ae1ca0cd725b166a843364712956bf3335 (diff) | |
| parent | 9ae5ed301218c649b304e31327df2d687ffe6866 (diff) | |
| download | mullvadvpn-bae528b847e13faf0ea745e29c8d119687241e5c.tar.xz mullvadvpn-bae528b847e13faf0ea745e29c8d119687241e5c.zip | |
Merge branch 'split-tunnel-linux'
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/mod.rs | 7 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/split_tunnel.rs | 70 |
2 files changed, 77 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs index 699b62ba1d..9cdefd19c5 100644 --- a/mullvad-cli/src/cmds/mod.rs +++ b/mullvad-cli/src/cmds/mod.rs @@ -34,6 +34,11 @@ pub use self::relay::Relay; mod reset; pub use self::reset::Reset; +#[cfg(target_os = "linux")] +mod split_tunnel; +#[cfg(target_os = "linux")] +pub use self::split_tunnel::SplitTunnel; + mod status; pub use self::status::Status; @@ -57,6 +62,8 @@ pub fn get_commands() -> HashMap<&'static str, Box<dyn Command>> { Box::new(Lan), Box::new(Relay), Box::new(Reset), + #[cfg(target_os = "linux")] + Box::new(SplitTunnel), Box::new(Status), Box::new(Tunnel), Box::new(Version), diff --git a/mullvad-cli/src/cmds/split_tunnel.rs b/mullvad-cli/src/cmds/split_tunnel.rs new file mode 100644 index 0000000000..95b172eb6b --- /dev/null +++ b/mullvad-cli/src/cmds/split_tunnel.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"), + } + } +} |
