diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-08-15 17:28:12 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-08-18 10:51:45 +0200 |
| commit | 0abee355c21eb00a221842b39ab41bc26fa0b663 (patch) | |
| tree | 0922c26b9856baa51938d9cdf4f7fc2d9b0e47eb | |
| parent | 64a6f6540d0d81ad84c5a4bfef850d47ab5b5342 (diff) | |
| download | mullvadvpn-0abee355c21eb00a221842b39ab41bc26fa0b663.tar.xz mullvadvpn-0abee355c21eb00a221842b39ab41bc26fa0b663.zip | |
Filter on IP version for QUIC in desktop UI
3 files changed, 34 insertions, 4 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx index 89f9edaee5..59a48c4130 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx @@ -81,6 +81,7 @@ export function RelayListContextProvider(props: RelayListContextProviderProps) { const relaySettings = useNormalRelaySettings(); const tunnelProtocol = useTunnelProtocol(); const multihop = relaySettings?.wireguard.useMultihop ?? false; + const ipVersion = relaySettings?.wireguard.ipVersion ?? 'any'; // Filters the relays to only keep the ones of the desired endpoint type, e.g. "wireguard", // "openvpn" or "bridge" @@ -103,8 +104,15 @@ export function RelayListContextProvider(props: RelayListContextProviderProps) { // Only show relays that have QUIC endpoints when QUIC obfuscation is enabled. const relayListForQuic = useMemo(() => { - return filterLocationsByQuic(relayListForDaita, quic, tunnelProtocol, locationType, multihop); - }, [quic, relayListForDaita, locationType, tunnelProtocol, multihop]); + return filterLocationsByQuic( + relayListForDaita, + quic, + tunnelProtocol, + locationType, + multihop, + ipVersion, + ); + }, [quic, relayListForDaita, locationType, tunnelProtocol, multihop, ipVersion]); // Filters the relays to only keep the relays matching the currently selected filters, e.g. // ownership and providers diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts index d219bb099f..2c125cdb9a 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts +++ b/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts @@ -1,4 +1,6 @@ import { + IpVersion, + LiftedConstraint, Ownership, RelayEndpointType, RelayLocation, @@ -17,6 +19,7 @@ import { IRelayLocationCountryRedux, IRelayLocationRelayRedux, } from '../redux/settings/reducers'; +import { IpAddress, IPv4Address, IPv6Address } from './ip'; export enum EndpointType { any, @@ -38,8 +41,10 @@ export function filterLocationsByQuic( tunnelProtocol: TunnelProtocol, locationType: LocationType, multihop: boolean, + ipVersion: LiftedConstraint<IpVersion>, ): IRelayLocationCountryRedux[] { - const quickOnRelay = (relay: IRelayLocationRelayRedux) => relay.quic !== undefined; + const quickOnRelay = (relay: IRelayLocationRelayRedux) => + relay.quic !== undefined && containsIpVersionAddr(relay.quic.addrIn, ipVersion); return quicFilterActive(quic, locationType, tunnelProtocol, multihop) ? filterLocationsImpl(locations, quickOnRelay) : locations; @@ -95,6 +100,23 @@ export function filterLocations( : locations; } +function containsIpVersionAddr(addrs: string[], version: LiftedConstraint<IpVersion>): boolean { + if (version === 'any') { + return addrs.length > 0; + } + return addrs.some((strAddr) => { + try { + const addr = IpAddress.fromString(strAddr); + return ( + (addr instanceof IPv4Address && version === 'ipv4') || + (addr instanceof IPv6Address && version === 'ipv6') + ); + } catch { + return false; + } + }); +} + function getTunnelProtocolFilter( endpointType: EndpointType, tunnelProtocol: TunnelProtocol, diff --git a/desktop/packages/mullvad-vpn/test/e2e/mock-data.ts b/desktop/packages/mullvad-vpn/test/e2e/mock-data.ts index efbac88f83..4bd4436772 100644 --- a/desktop/packages/mullvad-vpn/test/e2e/mock-data.ts +++ b/desktop/packages/mullvad-vpn/test/e2e/mock-data.ts @@ -56,7 +56,7 @@ const relayList: IRelayList = { endpointType: 'wireguard', daita: true, quic: { - addrIn: [], + addrIn: ['10.0.0.4'], domain: '', token: '', }, |
