diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-02-27 10:22:54 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-06-02 10:05:01 +0200 |
| commit | 5bb52620f9b7bbbc0bd24bfe03e4cfcfb5a0b16a (patch) | |
| tree | 2038f1c4a0d8c9e71622907c0944e92749fa381c /mullvad-daemon/src | |
| parent | 39c1a12c5c7f234fe32f397d93d60eb49234cfa1 (diff) | |
| download | mullvadvpn-5bb52620f9b7bbbc0bd24bfe03e4cfcfb5a0b16a.tar.xz mullvadvpn-5bb52620f9b7bbbc0bd24bfe03e4cfcfb5a0b16a.zip | |
Add IPC functions for managing split tunneling
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 40 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 60 |
2 files changed, 100 insertions, 0 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index cd9ddd39a1..783954a3b2 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -57,6 +57,7 @@ use std::{ }; use talpid_core::{ mpsc::Sender, + split, tunnel_state_machine::{self, TunnelCommand, TunnelParametersGenerator}, }; #[cfg(target_os = "android")] @@ -212,6 +213,15 @@ pub enum DaemonCommand { /// Remove settings and clear the cache #[cfg(not(target_os = "android"))] FactoryReset(oneshot::Sender<()>), + /// Request list of processes excluded from the tunnel + #[cfg(unix)] + GetSplitTunnelProcesses(oneshot::Sender<Vec<i32>>), + /// Exclude traffic of a process (PID) from the tunnel + #[cfg(unix)] + AddSplitTunnelProcess(oneshot::Sender<()>, i32), + /// Remove process (PID) from list of processes excluded from the tunnel + #[cfg(unix)] + RemoveSplitTunnelProcess(oneshot::Sender<()>, i32), /// Makes the daemon exit the main loop and quit. Shutdown, /// Saves the target tunnel state and enters a blocking state. The state is restored @@ -992,6 +1002,12 @@ where GetCurrentVersion(tx) => self.on_get_current_version(tx), #[cfg(not(target_os = "android"))] FactoryReset(tx) => self.on_factory_reset(tx), + #[cfg(unix)] + GetSplitTunnelProcesses(tx) => self.on_get_split_tunnel_processes(tx), + #[cfg(unix)] + AddSplitTunnelProcess(tx, pid) => self.on_add_split_tunnel_process(tx, pid), + #[cfg(unix)] + RemoveSplitTunnelProcess(tx, pid) => self.on_remove_split_tunnel_process(tx, pid), Shutdown => self.trigger_shutdown_event(), PrepareRestart => self.on_prepare_restart(), } @@ -1355,6 +1371,30 @@ where })); } + #[cfg(unix)] + fn on_get_split_tunnel_processes(&mut self, tx: oneshot::Sender<Vec<i32>>) { + match split::list_pids() { + Ok(pids) => Self::oneshot_send(tx, pids, "get_split_tunnel_processes response"), + Err(e) => error!("{}", e.display_chain_with_msg("Unable to obtain PIDs")), + } + } + + #[cfg(unix)] + fn on_add_split_tunnel_process(&mut self, tx: oneshot::Sender<()>, pid: i32) { + match split::add_pid(pid) { + Ok(()) => Self::oneshot_send(tx, (), "add_split_tunnel_process response"), + Err(e) => error!("{}", e.display_chain_with_msg("Unable to add PID")), + } + } + + #[cfg(unix)] + fn on_remove_split_tunnel_process(&mut self, tx: oneshot::Sender<()>, pid: i32) { + match split::remove_pid(pid) { + Ok(()) => Self::oneshot_send(tx, (), "remove_split_tunnel_process response"), + Err(e) => error!("{}", e.display_chain_with_msg("Unable to remove PID")), + } + } + fn on_update_relay_settings(&mut self, tx: oneshot::Sender<()>, update: RelaySettingsUpdate) { let save_result = self.settings.update_relay_settings(update); match save_result { diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 84c5db8570..2839fc3d57 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -178,6 +178,18 @@ build_rpc_trait! { #[rpc(meta, name = "factory_reset")] fn factory_reset(&self, Self::Metadata) -> BoxFuture<(), Error>; + /// Retrieve PIDs to exclude from the tunnel + #[rpc(meta, name = "get_split_tunnel_processes")] + fn get_split_tunnel_processes(&self, Self::Metadata) -> BoxFuture<Vec<i32>, Error>; + + /// Add a process to exclude from the tunnel + #[rpc(meta, name = "add_split_tunnel_process")] + fn add_split_tunnel_process(&self, Self::Metadata, i32) -> BoxFuture<(), Error>; + + /// Remove a process excluded from the tunnel + #[rpc(meta, name = "remove_split_tunnel_process")] + fn remove_split_tunnel_process(&self, Self::Metadata, i32) -> BoxFuture<(), Error>; + #[pubsub(name = "daemon_event")] { /// Subscribes to events from the daemon. #[rpc(name = "daemon_event_subscribe")] @@ -739,6 +751,54 @@ impl ManagementInterfaceApi for ManagementInterface { } } + fn get_split_tunnel_processes(&self, _: Self::Metadata) -> BoxFuture<Vec<i32>, Error> { + #[cfg(unix)] + { + log::debug!("get_split_tunnel_processes"); + let (tx, rx) = sync::oneshot::channel(); + let future = self + .send_command_to_daemon(DaemonCommand::GetSplitTunnelProcesses(tx)) + .and_then(|_| rx.map_err(|_| Error::internal_error())); + Box::new(future) + } + #[cfg(not(unix))] + { + Box::new(future::ok(Vec::with_capacity(0))) + } + } + + fn add_split_tunnel_process(&self, _: Self::Metadata, pid: i32) -> BoxFuture<(), Error> { + #[cfg(unix)] + { + log::debug!("add_split_tunnel_process"); + let (tx, rx) = sync::oneshot::channel(); + let future = self + .send_command_to_daemon(DaemonCommand::AddSplitTunnelProcess(tx, pid)) + .and_then(|_| rx.map_err(|_| Error::internal_error())); + Box::new(future) + } + #[cfg(not(unix))] + { + Box::new(future::ok(())) + } + } + + fn remove_split_tunnel_process(&self, _: Self::Metadata, pid: i32) -> BoxFuture<(), Error> { + #[cfg(unix)] + { + log::debug!("remove_split_tunnel_process"); + let (tx, rx) = sync::oneshot::channel(); + let future = self + .send_command_to_daemon(DaemonCommand::RemoveSplitTunnelProcess(tx, pid)) + .and_then(|_| rx.map_err(|_| Error::internal_error())); + Box::new(future) + } + #[cfg(not(unix))] + { + Box::new(future::ok(())) + } + } + fn daemon_event_subscribe( &self, |
