diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2022-11-08 13:59:54 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2022-11-08 17:07:07 +0100 |
| commit | 24dd952ae0dbaa36c30884619f11e66db7c61cf2 (patch) | |
| tree | 1dcea28cdeaa86e2636514fcd5508e256b395fe0 /talpid-openvpn/src | |
| parent | 55d07cc2f6c600e8e5e49d34f05825eafa37c652 (diff) | |
| download | mullvadvpn-24dd952ae0dbaa36c30884619f11e66db7c61cf2.tar.xz mullvadvpn-24dd952ae0dbaa36c30884619f11e66db7c61cf2.zip | |
Use fwmark for routing in openvpn
Diffstat (limited to 'talpid-openvpn/src')
| -rw-r--r-- | talpid-openvpn/src/lib.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/talpid-openvpn/src/lib.rs b/talpid-openvpn/src/lib.rs index e49cbd121a..decff64b0c 100644 --- a/talpid-openvpn/src/lib.rs +++ b/talpid-openvpn/src/lib.rs @@ -316,6 +316,8 @@ impl OpenVpnMonitor<OpenVpnCommand> { proxy_auth_file, proxy_monitor, tunnel_close_rx, + #[cfg(target_os = "linux")] + fwmark: params.fwmark, }; Self::new_internal( cmd, @@ -380,6 +382,8 @@ struct OpenVpnTunnelInitArgs { proxy_auth_file: Option<mktemp::TempFile>, proxy_monitor: Option<Box<dyn ProxyMonitor>>, tunnel_close_rx: oneshot::Receiver<()>, + #[cfg(target_os = "linux")] + fwmark: u32, } impl<C: OpenVpnBuilder + Send + 'static> OpenVpnMonitor<C> { @@ -408,6 +412,9 @@ impl<C: OpenVpnBuilder + Send + 'static> OpenVpnMonitor<C> { #[cfg(windows)] let wintun = Arc::new(wintun); + #[cfg(target_os = "linux")] + cmd.fwmark(init_args.fwmark); + cmd.plugin(plugin_path, vec![ipc_path]) .log(log_path.as_deref()); let (spawn_task, abort_spawn) = futures::future::abortable(Self::prepare_process( @@ -769,6 +776,10 @@ pub trait OpenVpnBuilder { /// Spawn the subprocess and return a handle. fn start(&self) -> io::Result<Self::ProcessHandle>; + + /// Sets the firewall mark for the connection. + #[cfg(target_os = "linux")] + fn fwmark(&mut self, fwmark: u32) -> &mut Self; } /// Trait for types acting as handles to subprocesses for `OpenVpnMonitor` @@ -798,6 +809,12 @@ impl OpenVpnBuilder for OpenVpnCommand { fn start(&self) -> io::Result<OpenVpnProcHandle> { OpenVpnProcHandle::new(self.build()) } + + #[cfg(target_os = "linux")] + fn fwmark(&mut self, fwmark: u32) -> &mut Self { + self.fwmark(Some(fwmark)); + self + } } impl ProcessHandle for OpenVpnProcHandle { @@ -1196,6 +1213,11 @@ mod tests { self } + #[cfg(target_os = "linux")] + fn fwmark(&mut self, _fwmark: u32) -> &mut Self { + self + } + fn start(&self) -> io::Result<Self::ProcessHandle> { self.process_handle .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "failed to start")) @@ -1246,6 +1268,8 @@ mod tests { proxy_auth_file: None, proxy_monitor: None, tunnel_close_rx: close_rx, + #[cfg(target_os = "linux")] + fwmark: 0, } } |
