summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authordroger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 00:27:50 +0000
committerdroger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 00:27:50 +0000
commitf79c5917f8dd23a6d05c19f57537d5eb0ca58ba2 (patch)
treef0bdd826ac8a047c158d4fd9f95910bfbde38510 /net
parent1e4fdc0ba8d4438bda54a986be156f3d00081f4f (diff)
downloadchromium_src-f79c5917f8dd23a6d05c19f57537d5eb0ca58ba2.zip
chromium_src-f79c5917f8dd23a6d05c19f57537d5eb0ca58ba2.tar.gz
chromium_src-f79c5917f8dd23a6d05c19f57537d5eb0ca58ba2.tar.bz2
Remove private system API calls in dns_config_service_posix on iOS
BUG=335000 Review URL: https://codereview.chromium.org/135043003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/dns/dns_config_service_posix.cc128
-rw-r--r--net/dns/dns_config_watcher_mac.cc106
-rw-r--r--net/dns/dns_config_watcher_mac.h26
-rw-r--r--net/net.gyp3
4 files changed, 162 insertions, 101 deletions
diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
index baf9172..b352d32 100644
--- a/net/dns/dns_config_service_posix.cc
+++ b/net/dns/dns_config_service_posix.cc
@@ -21,68 +21,9 @@
#include "net/dns/notify_watcher_mac.h"
#include "net/dns/serial_worker.h"
-#if defined(OS_MACOSX)
-#include <dlfcn.h>
-
-#include "third_party/apple_apsl/dnsinfo.h"
-
-namespace {
-
-// dnsinfo symbols are available via libSystem.dylib, but can also be present in
-// SystemConfiguration.framework. To avoid confusion, load them explicitly from
-// libSystem.dylib.
-class DnsInfoApi {
- public:
- typedef const char* (*dns_configuration_notify_key_t)();
- typedef dns_config_t* (*dns_configuration_copy_t)();
- typedef void (*dns_configuration_free_t)(dns_config_t*);
-
- DnsInfoApi()
- : dns_configuration_notify_key(NULL),
- dns_configuration_copy(NULL),
- dns_configuration_free(NULL) {
- handle_ = dlopen("/usr/lib/libSystem.dylib",
- RTLD_LAZY | RTLD_NOLOAD);
- if (!handle_)
- return;
- dns_configuration_notify_key =
- reinterpret_cast<dns_configuration_notify_key_t>(
- dlsym(handle_, "dns_configuration_notify_key"));
- dns_configuration_copy =
- reinterpret_cast<dns_configuration_copy_t>(
- dlsym(handle_, "dns_configuration_copy"));
- dns_configuration_free =
- reinterpret_cast<dns_configuration_free_t>(
- dlsym(handle_, "dns_configuration_free"));
- }
-
- ~DnsInfoApi() {
- if (handle_)
- dlclose(handle_);
- }
-
- dns_configuration_notify_key_t dns_configuration_notify_key;
- dns_configuration_copy_t dns_configuration_copy;
- dns_configuration_free_t dns_configuration_free;
-
- private:
- void* handle_;
-};
-
-const DnsInfoApi& GetDnsInfoApi() {
- static base::LazyInstance<DnsInfoApi>::Leaky api = LAZY_INSTANCE_INITIALIZER;
- return api.Get();
-}
-
-struct DnsConfigTDeleter {
- inline void operator()(dns_config_t* ptr) const {
- if (GetDnsInfoApi().dns_configuration_free)
- GetDnsInfoApi().dns_configuration_free(ptr);
- }
-};
-
-} // namespace
-#endif // defined(OS_MACOSX)
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+#include "net/dns/dns_config_watcher_mac.h"
+#endif
namespace net {
@@ -94,20 +35,20 @@ namespace {
const base::FilePath::CharType* kFilePathHosts =
FILE_PATH_LITERAL("/etc/hosts");
-#if defined(OS_MACOSX)
-class ConfigWatcher {
+#if defined(OS_IOS)
+
+// There is no plublic API to watch the DNS configuration on iOS.
+class DnsConfigWatcher {
public:
- bool Watch(const base::Callback<void(bool succeeded)>& callback) {
- if (!GetDnsInfoApi().dns_configuration_notify_key)
- return false;
- return watcher_.Watch(GetDnsInfoApi().dns_configuration_notify_key(),
- callback);
- }
+ typedef base::Callback<void(bool succeeded)> CallbackType;
- private:
- NotifyWatcherMac watcher_;
+ bool Watch(const CallbackType& callback) {
+ return false;
+ }
};
-#else
+
+#elif !defined(OS_MACOSX)
+// DnsConfigWatcher for OS_MACOSX is in dns_config_watcher_mac.{hh,cc}.
#ifndef _PATH_RESCONF // Normally defined in <resolv.h>
#define _PATH_RESCONF "/etc/resolv.conf"
@@ -116,14 +57,14 @@ class ConfigWatcher {
static const base::FilePath::CharType* kFilePathConfig =
FILE_PATH_LITERAL(_PATH_RESCONF);
-class ConfigWatcher {
+class DnsConfigWatcher {
public:
typedef base::Callback<void(bool succeeded)> CallbackType;
bool Watch(const CallbackType& callback) {
callback_ = callback;
return watcher_.Watch(base::FilePath(kFilePathConfig), false,
- base::Bind(&ConfigWatcher::OnCallback,
+ base::Bind(&DnsConfigWatcher::OnCallback,
base::Unretained(this)));
}
@@ -165,31 +106,18 @@ ConfigParsePosixResult ReadDnsConfig(DnsConfig* config) {
#endif
#endif
-#if defined(OS_MACOSX)
- if (!GetDnsInfoApi().dns_configuration_copy)
- return CONFIG_PARSE_POSIX_NO_DNSINFO;
- scoped_ptr<dns_config_t, DnsConfigTDeleter> dns_config(
- GetDnsInfoApi().dns_configuration_copy());
- if (!dns_config)
- return CONFIG_PARSE_POSIX_NO_DNSINFO;
-
- // TODO(szym): Parse dns_config_t for resolvers rather than res_state.
- // DnsClient can't handle domain-specific unscoped resolvers.
- unsigned num_resolvers = 0;
- for (int i = 0; i < dns_config->n_resolver; ++i) {
- dns_resolver_t* resolver = dns_config->resolver[i];
- if (!resolver->n_nameserver)
- continue;
- if (resolver->options && !strcmp(resolver->options, "mdns"))
- continue;
- ++num_resolvers;
- }
- if (num_resolvers > 1) {
- LOG(WARNING) << "dns_config has unhandled options!";
- config->unhandled_options = true;
- return CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS;
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+ ConfigParsePosixResult error = DnsConfigWatcher::CheckDnsConfig();
+ switch (error) {
+ case CONFIG_PARSE_POSIX_OK:
+ break;
+ case CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS:
+ LOG(WARNING) << "dns_config has unhandled options!";
+ config->unhandled_options = true;
+ default:
+ return error;
}
-#endif // defined(OS_MACOSX)
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
// Override timeout value to match default setting on Windows.
config->timeout = base::TimeDelta::FromSeconds(kDnsTimeoutSeconds);
return result;
@@ -246,7 +174,7 @@ class DnsConfigServicePosix::Watcher {
base::WeakPtrFactory<Watcher> weak_factory_;
DnsConfigServicePosix* service_;
- ConfigWatcher config_watcher_;
+ DnsConfigWatcher config_watcher_;
base::FilePathWatcher hosts_watcher_;
DISALLOW_COPY_AND_ASSIGN(Watcher);
diff --git a/net/dns/dns_config_watcher_mac.cc b/net/dns/dns_config_watcher_mac.cc
new file mode 100644
index 0000000..a92db0c
--- /dev/null
+++ b/net/dns/dns_config_watcher_mac.cc
@@ -0,0 +1,106 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/dns/dns_config_watcher_mac.h"
+
+#include <dlfcn.h>
+
+#include "base/lazy_instance.h"
+#include "third_party/apple_apsl/dnsinfo.h"
+
+namespace {
+
+// dnsinfo symbols are available via libSystem.dylib, but can also be present in
+// SystemConfiguration.framework. To avoid confusion, load them explicitly from
+// libSystem.dylib.
+class DnsInfoApi {
+ public:
+ typedef const char* (*dns_configuration_notify_key_t)();
+ typedef dns_config_t* (*dns_configuration_copy_t)();
+ typedef void (*dns_configuration_free_t)(dns_config_t*);
+
+ DnsInfoApi()
+ : dns_configuration_notify_key(NULL),
+ dns_configuration_copy(NULL),
+ dns_configuration_free(NULL) {
+ handle_ = dlopen("/usr/lib/libSystem.dylib",
+ RTLD_LAZY | RTLD_NOLOAD);
+ if (!handle_)
+ return;
+ dns_configuration_notify_key =
+ reinterpret_cast<dns_configuration_notify_key_t>(
+ dlsym(handle_, "dns_configuration_notify_key"));
+ dns_configuration_copy =
+ reinterpret_cast<dns_configuration_copy_t>(
+ dlsym(handle_, "dns_configuration_copy"));
+ dns_configuration_free =
+ reinterpret_cast<dns_configuration_free_t>(
+ dlsym(handle_, "dns_configuration_free"));
+ }
+
+ ~DnsInfoApi() {
+ if (handle_)
+ dlclose(handle_);
+ }
+
+ dns_configuration_notify_key_t dns_configuration_notify_key;
+ dns_configuration_copy_t dns_configuration_copy;
+ dns_configuration_free_t dns_configuration_free;
+
+ private:
+ void* handle_;
+};
+
+const DnsInfoApi& GetDnsInfoApi() {
+ static base::LazyInstance<DnsInfoApi>::Leaky api = LAZY_INSTANCE_INITIALIZER;
+ return api.Get();
+}
+
+struct DnsConfigTDeleter {
+ inline void operator()(dns_config_t* ptr) const {
+ if (GetDnsInfoApi().dns_configuration_free)
+ GetDnsInfoApi().dns_configuration_free(ptr);
+ }
+};
+
+} // namespace
+
+namespace net {
+namespace internal {
+
+bool DnsConfigWatcher::Watch(
+ const base::Callback<void(bool succeeded)>& callback) {
+ if (!GetDnsInfoApi().dns_configuration_notify_key)
+ return false;
+ return watcher_.Watch(GetDnsInfoApi().dns_configuration_notify_key(),
+ callback);
+}
+
+// static
+ConfigParsePosixResult DnsConfigWatcher::CheckDnsConfig() {
+ if (!GetDnsInfoApi().dns_configuration_copy)
+ return CONFIG_PARSE_POSIX_NO_DNSINFO;
+ scoped_ptr<dns_config_t, DnsConfigTDeleter> dns_config(
+ GetDnsInfoApi().dns_configuration_copy());
+ if (!dns_config)
+ return CONFIG_PARSE_POSIX_NO_DNSINFO;
+
+ // TODO(szym): Parse dns_config_t for resolvers rather than res_state.
+ // DnsClient can't handle domain-specific unscoped resolvers.
+ unsigned num_resolvers = 0;
+ for (int i = 0; i < dns_config->n_resolver; ++i) {
+ dns_resolver_t* resolver = dns_config->resolver[i];
+ if (!resolver->n_nameserver)
+ continue;
+ if (resolver->options && !strcmp(resolver->options, "mdns"))
+ continue;
+ ++num_resolvers;
+ }
+ if (num_resolvers > 1)
+ return CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS;
+ return CONFIG_PARSE_POSIX_OK;
+}
+
+} // naespace internal
+} // namespace net
diff --git a/net/dns/dns_config_watcher_mac.h b/net/dns/dns_config_watcher_mac.h
new file mode 100644
index 0000000..0c3fc6a
--- /dev/null
+++ b/net/dns/dns_config_watcher_mac.h
@@ -0,0 +1,26 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/callback_forward.h"
+#include "net/dns/dns_config_service_posix.h"
+#include "net/dns/notify_watcher_mac.h"
+
+namespace net {
+namespace internal {
+
+// Watches DNS configuration on Mac.
+class DnsConfigWatcher {
+ public:
+ bool Watch(const base::Callback<void(bool succeeded)>& callback);
+
+ // Returns an error if the DNS configuration is invalid.
+ // Returns CONFIG_PARSE_POSIX_OK otherwise.
+ static ConfigParsePosixResult CheckDnsConfig();
+
+ private:
+ NotifyWatcherMac watcher_;
+};
+
+} // naespace internal
+} // namespace net
diff --git a/net/net.gyp b/net/net.gyp
index 4e362539..a08947f 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -474,6 +474,8 @@
'dns/dns_config_service_posix.h',
'dns/dns_config_service_win.cc',
'dns/dns_config_service_win.h',
+ 'dns/dns_config_watcher_mac.cc',
+ 'dns/dns_config_watcher_mac.h',
'dns/dns_hosts.cc',
'dns/dns_hosts.h',
'dns/dns_protocol.h',
@@ -1579,7 +1581,6 @@
['include', '^cert/test_root_certs_nss\\.cc$'],
['include', '^cert/x509_util_nss\\.cc$'],
['include', '^cert/x509_util_nss\\.h$'],
- ['include', '^dns/notify_watcher_mac\\.cc$'],
['include', '^proxy/proxy_resolver_mac\\.cc$'],
['include', '^proxy/proxy_server_mac\\.cc$'],
['include', '^ocsp/nss_ocsp\\.cc$'],