Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log if Same IP is used when starting a tunnel #5228

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ios/PacketTunnel/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
let selectorResult = tunnelConfiguration.selectorResult
self.selectorResult = selectorResult
self.providerLogger.debug("Set tunnel relay to \(selectorResult.relay.hostname).")
self.logIfDeviceHasSameIP(than: tunnelConfiguration.wgTunnelConfig.interface.addresses)

// Start tunnel.
self.adapter.start(tunnelConfiguration: tunnelConfiguration.wgTunnelConfig) { error in
Expand Down Expand Up @@ -238,6 +239,16 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
}

private func logIfDeviceHasSameIP(than addresses: [IPAddressRange]) {
let hasIPv4SameAddress = addresses.compactMap { $0.address as? IPv4Address }
.contains { $0 == ApplicationConfiguration.sameIPv4 }
let hasIPv6SameAddress = addresses.compactMap { $0.address as? IPv6Address }
.contains { $0 == ApplicationConfiguration.sameIPv6 }

let isUsingSameIP = (hasIPv4SameAddress || hasIPv6SameAddress) ? "" : "NOT "
providerLogger.debug("Same IP is \(isUsingSameIP)being used")
}

override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
dispatchQueue.async {
self.providerLogger.debug("Stop the tunnel: \(reason)")
Expand Down
8 changes: 7 additions & 1 deletion ios/Shared/ApplicationConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import struct Network.IPv4Address
import Network

enum ApplicationConfiguration {
/// Shared container security group identifier.
Expand Down Expand Up @@ -37,4 +37,10 @@ enum ApplicationConfiguration {

/// Maximum number of devices per account.
static let maxAllowedDevices = 5

// FIXME: Used for debugging purposes during the migration to same IP. Remove when the migration is over.
// swiftlint disable:force_cast
static let sameIPv4 = IPv4Address("10.127.255.254")!
static let sameIPv6 = IPv6Address("fc00:bbbb:bbbb:bb01:ffff:ffff:ffff:ffff")!
faern marked this conversation as resolved.
Show resolved Hide resolved
// swiftlint enable:force_cast
}