diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-08-11 10:23:34 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-08-19 12:32:59 +0200 |
| commit | d347af2894817e3613be7e6c9ee7b02c96c70155 (patch) | |
| tree | cbf7f3d5ddfd60382561a37bc4492f481e17a80e | |
| parent | 12f77e401e6a3c2c4dab404d419176b6c373aed9 (diff) | |
| download | mullvadvpn-d347af2894817e3613be7e6c9ee7b02c96c70155.tar.xz mullvadvpn-d347af2894817e3613be7e6c9ee7b02c96c70155.zip | |
Remove hardcoded ports from mullvad-types
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 16 | ||||
| -rw-r--r-- | mullvad-types/src/relay_constraints.rs | 15 |
2 files changed, 19 insertions, 12 deletions
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index 3ff0e5ee17..019c6ac2c1 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -16,7 +16,6 @@ use mullvad_types::{ relay_constraints::{ BridgeState, Constraint, InternalBridgeConstraints, LocationConstraint, Match, OpenVpnConstraints, Providers, RelayConstraints, Set, WireguardConstraints, - WIREGUARD_TCP_PORTS, }, relay_list::{OpenVpnEndpointData, Relay, RelayList, RelayTunnels, WireguardEndpointData}, }; @@ -59,6 +58,7 @@ const WIREGUARD_EXIT_CONSTRAINTS: WireguardConstraints = WireguardConstraints { ip_version: Constraint::Only(IpVersion::V4), entry_location: None, }; +const WIREGUARD_TCP_PORTS: [(u16, u16); 3] = [(80, 80), (443, 443), (5001, 5001)]; #[derive(err_derive::Error, Debug)] @@ -757,6 +757,20 @@ impl RelaySelector { tunnels: &RelayTunnels, constraints: &WireguardConstraints, ) -> Vec<WireguardEndpointData> { + if constraints.protocol == Constraint::Only(TransportProtocol::Tcp) { + match constraints.port { + Constraint::Only(port) => { + if !WIREGUARD_TCP_PORTS + .iter() + .any(|range| port >= range.0 && port <= range.1) + { + return vec![]; + } + } + _ => (), + } + return tunnels.wireguard.clone(); + } tunnels .wireguard .iter() diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index df94de7c05..100daa2088 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -12,8 +12,6 @@ use serde::{Deserialize, Serialize}; use std::{collections::HashSet, fmt}; use talpid_types::net::{openvpn::ProxySettings, IpVersion, TransportProtocol, TunnelType}; -pub const WIREGUARD_TCP_PORTS: [(u16, u16); 3] = [(80, 80), (443, 443), (5001, 5001)]; - pub trait Match<T> { fn matches(&self, other: &T) -> bool; @@ -512,15 +510,10 @@ impl Match<WireguardEndpointData> for WireguardConstraints { fn matches(&self, endpoint: &WireguardEndpointData) -> bool { match self.port { Constraint::Any => true, - Constraint::Only(port) => match self.protocol { - Constraint::Only(TransportProtocol::Tcp) => WIREGUARD_TCP_PORTS - .iter() - .any(|range| (port >= range.0 && port <= range.1)), - _ => endpoint - .port_ranges - .iter() - .any(|range| (port >= range.0 && port <= range.1)), - }, + Constraint::Only(port) => endpoint + .port_ranges + .iter() + .any(|range| (port >= range.0 && port <= range.1)), } } } |
