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

fix(apple client): sign in crash, closes #4350 #4353

Merged
merged 1 commit into from
Mar 27, 2024
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
5 changes: 5 additions & 0 deletions rust/connlib/clients/android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ pub unsafe extern "system" fn Java_dev_firezone_android_tunnel_ConnlibSession_di
});
}

/// Set system DNS resolvers
///
/// `dns_list` must not have any IPv6 scopes
/// <https://github.com/firezone/firezone/issues/4350>
///
/// # Safety
/// Pointers must be valid
#[allow(non_snake_case)]
Expand Down
5 changes: 5 additions & 0 deletions rust/connlib/clients/apple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ mod ffi {
) -> Result<WrappedSession, String>;

fn reconnect(&mut self);

// Set system DNS resolvers
//
// `dns_servers` must not have any IPv6 scopes
// <https://github.com/firezone/firezone/issues/4350>
#[swift_bridge(swift_name = "setDns")]
fn set_dns(&mut self, dns_servers: String);
fn disconnect(self);
Expand Down
8 changes: 1 addition & 7 deletions swift/apple/FirezoneNetworkExtension/Adapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ class Adapter {
logFilter,
callbackHandler
)
// Attempt to set DNS right away
if let jsonResolvers = try? String(
decoding: JSONEncoder().encode(getSystemDefaultResolvers()), as: UTF8.self
).intoRustString() {
session.setDns(jsonResolvers)
}
// Update our internal state
self.state = .tunnelStarted(session: session)

Expand Down Expand Up @@ -416,7 +410,7 @@ extension Adapter: CallbackHandlerDelegate {
}
}

private func getSystemDefaultResolvers(interfaceName: String? = nil) -> [String] {
private func getSystemDefaultResolvers(interfaceName: String?) -> [String] {
#if os(macOS)
let resolvers = SystemConfigurationResolvers(logger: logger).getDefaultDNSServers(
interfaceName: interfaceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ class SystemConfigurationResolvers {
self.dynamicStore = dynamicStore
}

func getDefaultDNSServers(interfaceName: String?) -> [String] {
if let interfaceName = interfaceName {
return getDefaultDNSServersForInterface(interfaceName)
} else {
return getGlobalDefaultDNSServers()
}
}


/// 1. First, find the service ID that corresponds to the interface we're interested in.
/// We do this by searching the configuration store at "Setup:/Network/Service/<service-id>/Interface"
/// for a matching "InterfaceName".
Expand All @@ -48,8 +39,9 @@ class SystemConfigurationResolvers {
/// State:/Network/Service/<service-id>/DNS
/// 4. We assume manually-set DNS servers take precedence over DHCP ones,
/// so return those if found. Otherwise, return the DHCP ones.
private func getDefaultDNSServersForInterface(_ interfaceName: String) -> [String] {
guard let dynamicStore = dynamicStore
public func getDefaultDNSServers(interfaceName: String?) -> [String] {
guard let dynamicStore = dynamicStore,
let interfaceName = interfaceName
else {
return []
}
Expand Down Expand Up @@ -95,30 +87,4 @@ class SystemConfigurationResolvers {

return value
}

private func getGlobalDefaultDNSServers() -> [String] {
guard let dynamicStore = dynamicStore
else {
return []
}

var dnsServers: [String] = []

// Specify the DNS key to fetch the current DNS servers
let dnsKey = "State:/Network/Global/DNS" as CFString

// Retrieve the current DNS server configuration from the dynamic store
guard let dnsInfo = SCDynamicStoreCopyValue(dynamicStore, dnsKey) as? [String: Any],
let servers = dnsInfo[kSCPropNetDNSServerAddresses as String] as? [String]
else {
self.logger.error("\(#function): Failed to retrieve DNS server information")
return []
}

// Append the retrieved DNS servers to the result array
dnsServers.append(contentsOf: servers)

return dnsServers

}
}
Loading