Skip to content

Commit

Permalink
Log if Same IP is used when starting a tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Oct 5, 2023
1 parent 66059dd commit 6ef69e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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 the tests are 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")!
// swiftlint enable:force_cast
}

0 comments on commit 6ef69e6

Please sign in to comment.