Commit 1556c38f authored by Eric Orth's avatar Eric Orth Committed by Commit Bot

Cleanup/whitelist remaining //net/dns usage

Removed a bunch of whitelist entries that were no longer needed, mostly
due to completed servicification migrations.  Some usage was
no-longer-needed includes that I removed, and all of UrlInfo appeared
to be no longer used or present in build files so I removed the whole
class and tests.

Some usage of MDnsClient was just accessing the Get...Endpoint()
methods that could easily be moved to net/dns/public and thus no longer
require whitelisting.

Ensured all remaining whitelist entries were commented with why usage
is appropriate or with a TODO and bug for anything still requiring
servicification migration.

Bug: 846454
Change-Id: I39aeeaa437bd8fe2899e78189ca7ef0adbffd1f6
Reviewed-on: https://chromium-review.googlesource.com/c/1320511
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606365}
parent cd52a866
......@@ -18,7 +18,6 @@
#include "content/public/browser/browser_task_traits.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "net/base/net_errors.h"
#include "net/dns/host_resolver.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/tcp_client_socket.h"
......
......@@ -21,7 +21,6 @@
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "net/dns/mdns_client.h"
#include "net/socket/datagram_server_socket.h"
namespace net {
......
......@@ -56,6 +56,7 @@
#include "services/network/public/cpp/cross_thread_shared_url_loader_factory_info.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
#include "url/gurl.h"
......
// Copyright (c) 2012 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 "chrome/browser/net/url_info.h"
#include <ctype.h>
#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <string>
#include "base/format_macros.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
using base::TimeDelta;
using base::TimeTicks;
namespace chrome_browser_net {
namespace {
// The number of OS cache entries we can guarantee(?) before cache eviction
// might likely take place.
const int kMaxGuaranteedDnsCacheSize = 50;
// Common low end TTL for sites is 5 minutes. However, DNS servers give us the
// remaining time, not the original 5 minutes. Hence it doesn't much matter
// whether we found something in the local cache, or an ISP cache, it will on
// average be 2.5 minutes before it expires. We could try to model this with
// 180 seconds, but simpler is just to do the lookups all the time (wasting OS
// calls(?)), and let that OS cache decide what to do (with TTL in hand). We
// use a small time to help get some duplicate suppression, in case a page has
// a TON of copies of the same domain name, so that we don't thrash the OS to
// death. Hopefully it is small enough that we're not hurting our cache hit
// rate (i.e., we could always ask the OS).
const int kDefaultCacheExpirationDuration = 5;
TimeDelta MaxNonNetworkDnsLookupDuration() {
return TimeDelta::FromMilliseconds(15);
}
bool detailed_logging_enabled = false;
struct GlobalState {
GlobalState() {
cache_expiration_duration =
TimeDelta::FromSeconds(kDefaultCacheExpirationDuration);
}
TimeDelta cache_expiration_duration;
};
base::LazyInstance<GlobalState>::Leaky global_state;
} // anonymous namespace
// Use command line switch to enable detailed logging.
void EnablePredictorDetailedLog(bool enable) {
detailed_logging_enabled = enable;
}
// static
int UrlInfo::sequence_counter = 1;
UrlInfo::UrlInfo()
: state_(PENDING),
old_prequeue_state_(state_),
resolve_duration_(NullDuration()),
queue_duration_(NullDuration()),
sequence_number_(0),
motivation_(NO_PREFETCH_MOTIVATION),
was_linked_(false) {
}
UrlInfo::UrlInfo(UrlInfo&& other) = default;
UrlInfo& UrlInfo::operator=(UrlInfo&& other) = default;
UrlInfo::~UrlInfo() {}
bool UrlInfo::NeedsDnsUpdate() {
switch (state_) {
case PENDING: // Just now created info.
return true;
case QUEUED: // In queue.
case ASSIGNED: // It's being resolved.
case ASSIGNED_BUT_MARKED: // It's being resolved.
return false; // We're already working on it
case NO_SUCH_NAME: // Lookup failed.
case FOUND: // Lookup succeeded.
return !IsStillCached(); // See if DNS cache expired.
default:
NOTREACHED();
return false;
}
}
// Used by test ONLY. The value is otherwise constant.
// static
void UrlInfo::set_cache_expiration(TimeDelta time) {
global_state.Pointer()->cache_expiration_duration = time;
}
// static
TimeDelta UrlInfo::get_cache_expiration() {
return global_state.Get().cache_expiration_duration;
}
void UrlInfo::SetQueuedState(ResolutionMotivation motivation) {
DCHECK(PENDING == state_ || FOUND == state_ || NO_SUCH_NAME == state_);
old_prequeue_state_ = state_;
state_ = QUEUED;
queue_duration_ = resolve_duration_ = NullDuration();
SetMotivation(motivation);
GetDuration(); // Set time_
DLogResultsStats("DNS Prefetch in queue");
}
void UrlInfo::SetAssignedState() {
DCHECK(QUEUED == state_);
state_ = ASSIGNED;
queue_duration_ = GetDuration();
DLogResultsStats("DNS Prefetch assigned");
}
void UrlInfo::RemoveFromQueue() {
DCHECK(ASSIGNED == state_);
state_ = old_prequeue_state_;
DLogResultsStats("DNS Prefetch reset to prequeue");
}
void UrlInfo::SetPendingDeleteState() {
DCHECK(ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_);
state_ = ASSIGNED_BUT_MARKED;
}
void UrlInfo::SetFoundState() {
DCHECK(ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_);
state_ = FOUND;
resolve_duration_ = GetDuration();
const TimeDelta max_duration = MaxNonNetworkDnsLookupDuration();
if (max_duration <= resolve_duration_) {
UMA_HISTOGRAM_CUSTOM_TIMES("DNS.PrefetchResolution", resolve_duration_,
max_duration, TimeDelta::FromMinutes(15), 100);
}
sequence_number_ = sequence_counter++;
DLogResultsStats("DNS PrefetchFound");
}
void UrlInfo::SetNoSuchNameState() {
DCHECK(ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_);
state_ = NO_SUCH_NAME;
resolve_duration_ = GetDuration();
#ifndef NDEBUG
if (MaxNonNetworkDnsLookupDuration() <= resolve_duration_) {
LOCAL_HISTOGRAM_TIMES("DNS.PrefetchNotFoundName", resolve_duration_);
}
#endif
sequence_number_ = sequence_counter++;
DLogResultsStats("DNS PrefetchNotFound");
}
void UrlInfo::SetUrl(const GURL& url) {
if (url_.is_empty()) // Not yet initialized.
url_ = url;
else
DCHECK_EQ(url_, url);
}
// IsStillCached() guesses if the DNS cache still has IP data,
// or at least remembers results about "not finding host."
bool UrlInfo::IsStillCached() const {
DCHECK(FOUND == state_ || NO_SUCH_NAME == state_);
// Default MS OS does not cache failures. Hence we could return false almost
// all the time for that case. However, we'd never try again to prefetch
// the value if we returned false that way. Hence we'll just let the lookup
// time out the same way as FOUND case.
if (sequence_counter - sequence_number_ > kMaxGuaranteedDnsCacheSize)
return false;
TimeDelta time_since_resolution = TimeTicks::Now() - time_;
return time_since_resolution < global_state.Get().cache_expiration_duration;
}
void UrlInfo::DLogResultsStats(const char* message) const {
if (!detailed_logging_enabled)
return;
DVLOG(1) << "\t" << message << "\tq=" << queue_duration().InMilliseconds()
<< "ms,\tr=" << resolve_duration().InMilliseconds()
<< "ms,\tp=" << sequence_number_ << "\t" << url_.spec();
}
void UrlInfo::SetMotivation(ResolutionMotivation motivation) {
motivation_ = motivation;
if (motivation < LINKED_MAX_MOTIVATED)
was_linked_ = true;
}
} // namespace chrome_browser_net
// Copyright (c) 2012 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.
// A UrlInfo object is used to store prediction related information about a host
// port and scheme triplet. When performing DNS pre-resolution of the host/port
// pair, its state is monitored as it is resolved.
// It includes progress, from placement in the Predictor's queue, to resolution
// by the DNS service as either FOUND or NO_SUCH_NAME. Each instance may also
// hold records of previous resolution times, which might later be shown to be
// savings relative to resolution time during a navigation.
// UrlInfo objects are also used to describe frames, and additional instances
// may describe associated subresources, for future speculative connections to
// those expected subresources.
#ifndef CHROME_BROWSER_NET_URL_INFO_H_
#define CHROME_BROWSER_NET_URL_INFO_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/time/time.h"
#include "net/base/host_port_pair.h"
#include "net/dns/host_resolver.h"
#include "url/gurl.h"
namespace chrome_browser_net {
// Use command line switch to enable detailed logging.
void EnablePredictorDetailedLog(bool enable);
class UrlInfo {
public:
// Reasons for a domain to be resolved.
enum ResolutionMotivation {
MOUSE_OVER_MOTIVATED, // Mouse-over link induced resolution.
PAGE_SCAN_MOTIVATED, // Scan of rendered page induced resolution.
UNIT_TEST_MOTIVATED,
LINKED_MAX_MOTIVATED, // enum demarkation above motivation from links.
OMNIBOX_MOTIVATED, // Omni-box suggested resolving this.
STARTUP_LIST_MOTIVATED, // Startup list caused this resolution.
EARLY_LOAD_MOTIVATED, // In some cases we use the prefetcher to warm up
// the connection in advance of issuing the real
// request.
NO_PREFETCH_MOTIVATION, // Browser navigation info (not prefetch related).
// The following involve predictive prefetching, triggered by a navigation.
// TODO(jar): Support STATIC_REFERAL_MOTIVATED API and integration.
STATIC_REFERAL_MOTIVATED, // External database suggested this resolution.
LEARNED_REFERAL_MOTIVATED, // Prior navigation taught us this resolution.
SELF_REFERAL_MOTIVATED, // Guess about need for a second connection.
MAX_MOTIVATED // Beyond all enums, for use in histogram bounding.
};
enum DnsProcessingState {
// When processed by our prefetching system, the states are:
PENDING, // Constructor has completed.
QUEUED, // In name queue but not yet being resolved.
ASSIGNED, // Being resolved (or being reset to earlier state)
ASSIGNED_BUT_MARKED, // Needs to be deleted as soon as it's resolved.
FOUND, // DNS resolution completed.
NO_SUCH_NAME, // DNS resolution completed.
};
static base::TimeDelta NullDuration() {
return base::TimeDelta::FromMilliseconds(-1);
}
// UrlInfo are usually made by the default constructor during
// initializing of the Predictor's map (of info for Hostnames).
UrlInfo();
UrlInfo(UrlInfo&& other);
UrlInfo& operator=(UrlInfo&& other);
~UrlInfo();
// NeedDnsUpdate decides, based on our internal info,
// if it would be valuable to attempt to update (prefectch)
// DNS data for hostname. This decision is based
// on how recently we've done DNS prefetching for hostname.
bool NeedsDnsUpdate();
// FOR TEST ONLY: The following access the otherwise constant values.
static void set_cache_expiration(base::TimeDelta time);
static base::TimeDelta get_cache_expiration();
// The prefetching lifecycle.
void SetQueuedState(ResolutionMotivation motivation);
void SetAssignedState();
void RemoveFromQueue();
void SetPendingDeleteState();
void SetFoundState();
void SetNoSuchNameState();
// Finish initialization. Must only be called once.
void SetUrl(const GURL& url);
bool was_linked() const { return was_linked_; }
bool was_found() const { return FOUND == state_; }
bool was_nonexistent() const { return NO_SUCH_NAME == state_; }
bool is_assigned() const {
return ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_;
}
bool is_marked_to_delete() const { return ASSIGNED_BUT_MARKED == state_; }
bool HasUrl(const GURL& url) const {
return url_ == url;
}
base::TimeDelta resolve_duration() const { return resolve_duration_;}
base::TimeDelta queue_duration() const { return queue_duration_;}
void DLogResultsStats(const char* message) const;
// For testing, and use in printing tables of info, we sometimes need to
// adjust the time manually. Usually, this value is maintained by state
// transition, and this call is not made.
void set_time(const base::TimeTicks& time) { time_ = time; }
void set_request(std::unique_ptr<net::HostResolver::Request> request) {
request_ = std::move(request);
}
private:
base::TimeDelta GetDuration() {
base::TimeTicks old_time = time_;
time_ = base::TimeTicks::Now();
return time_ - old_time;
}
// IsStillCached() guesses if the DNS cache still has IP data.
bool IsStillCached() const;
// Record why we created, or have updated (reqested pre-resolution) of this
// instance.
void SetMotivation(ResolutionMotivation motivation);
// The current state of this instance.
DnsProcessingState state_;
// Record the state prior to going to a queued state, in case we have to back
// out of the queue.
DnsProcessingState old_prequeue_state_;
GURL url_; // Host, port and scheme for this info.
// When was last state changed (usually lookup completed).
base::TimeTicks time_;
// Time needed for DNS to resolve.
base::TimeDelta resolve_duration_;
// Time spent in queue.
base::TimeDelta queue_duration_;
int sequence_number_; // Used to calculate potential of cache eviction.
static int sequence_counter; // Used to allocate sequence_number_'s.
// Motivation for creation of this instance.
ResolutionMotivation motivation_;
// Record if the motivation for prefetching was ever a page-link-scan.
bool was_linked_;
// Request object cancels the request to the host resolver on deletion.
std::unique_ptr<net::HostResolver::Request> request_;
DISALLOW_COPY_AND_ASSIGN(UrlInfo);
};
} // namespace chrome_browser_net
#endif // CHROME_BROWSER_NET_URL_INFO_H_
// Copyright (c) 2012 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.
// Single threaded tests of UrlInfo functionality.
#include <time.h>
#include <string>
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "chrome/browser/net/url_info.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeDelta;
using base::TimeTicks;
namespace {
class UrlHostInfoTest : public testing::Test {
};
typedef chrome_browser_net::UrlInfo UrlInfo;
// Cycle throught the states held by a UrlInfo instance, and check to see that
// states look reasonable as time ticks away. If the test bots are too slow,
// we'll just give up on this test and exit from it.
TEST(UrlHostInfoTest, StateChangeTest) {
UrlInfo info_practice, info;
GURL url1("http://domain1.com:80"), url2("https://domain2.com:443");
// First load DLL, so that their load time won't interfere with tests.
// Some tests involve timing function performance, and DLL time can overwhelm
// test durations (which are considering network vs cache response times).
info_practice.SetUrl(url2);
info_practice.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info_practice.SetAssignedState();
info_practice.SetFoundState();
// Start test with actual (long/default) expiration time intact.
// Complete the construction of real test object.
info.SetUrl(url1);
EXPECT_TRUE(info.NeedsDnsUpdate()) << "error in construction state";
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
EXPECT_FALSE(info.NeedsDnsUpdate()) << "update needed after being queued";
info.SetAssignedState();
EXPECT_FALSE(info.NeedsDnsUpdate()) << "update needed during resolution";
base::TimeTicks before_resolution_complete = TimeTicks::Now();
info.SetFoundState();
// "Immediately" check to see if we need an update yet (we shouldn't).
if (info.NeedsDnsUpdate()) {
// The test bot must be really slow, so we can verify that.
EXPECT_GT((TimeTicks::Now() - before_resolution_complete).InMilliseconds(),
UrlInfo::get_cache_expiration().InMilliseconds());
return; // Lets punt here, the test bot is too slow.
}
// Run similar test with a shortened expiration, so we can trigger it.
const TimeDelta kMockExpirationTime = TimeDelta::FromMilliseconds(300);
info.set_cache_expiration(kMockExpirationTime);
// That was a nice life when the object was found.... but next time it won't
// be found. We'll sleep for a while, and then come back with not-found.
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
EXPECT_FALSE(info.NeedsDnsUpdate());
info.SetAssignedState();
EXPECT_FALSE(info.NeedsDnsUpdate());
// Greater than minimal expected network latency on DNS lookup.
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(25));
before_resolution_complete = TimeTicks::Now();
info.SetNoSuchNameState();
// "Immediately" check to see if we need an update yet (we shouldn't).
if (info.NeedsDnsUpdate()) {
// The test bot must be really slow, so we can verify that.
EXPECT_GT((TimeTicks::Now() - before_resolution_complete),
kMockExpirationTime);
return;
}
// Wait over 300ms, so it should definately be considered out of cache.
base::PlatformThread::Sleep(kMockExpirationTime +
TimeDelta::FromMilliseconds(20));
EXPECT_TRUE(info.NeedsDnsUpdate()) << "expiration time not honored";
}
// When a system gets "congested" relative to DNS, it means it is doing too many
// DNS resolutions, and bogging down the system. When we detect such a
// situation, we divert the sequence of states a UrlInfo instance moves
// through. Rather than proceeding from QUEUED (waiting in a name queue for a
// worker thread that can resolve the name) to ASSIGNED (where a worker thread
// actively resolves the name), we enter the ASSIGNED state (without actually
// getting sent to a resolver thread) and reset our state to what it was before
// the corresponding name was put in the work_queue_. This test drives through
// the state transitions used in such congestion handling.
TEST(UrlHostInfoTest, CongestionResetStateTest) {
UrlInfo info;
GURL url("http://domain1.com:80");
info.SetUrl(url);
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info.SetAssignedState();
EXPECT_TRUE(info.is_assigned());
info.RemoveFromQueue(); // Do the reset.
EXPECT_FALSE(info.is_assigned());
// Since this was a new info instance, and it never got resolved, we land back
// in a PENDING state rather than FOUND or NO_SUCH_NAME.
EXPECT_FALSE(info.was_found());
EXPECT_FALSE(info.was_nonexistent());
// Make sure we're completely re-usable, by going throug a normal flow.
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info.SetAssignedState();
info.SetFoundState();
EXPECT_TRUE(info.was_found());
// Use the congestion flow, and check that we end up in the found state.
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info.SetAssignedState();
info.RemoveFromQueue(); // Do the reset.
EXPECT_FALSE(info.is_assigned());
EXPECT_TRUE(info.was_found()); // Back to what it was before being queued.
}
// TODO(jar): Add death test for illegal state changes, and also for setting
// hostname when already set.
} // namespace
......@@ -19,13 +19,6 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache.h"
#include "net/dns/host_cache.h"
#include "net/dns/host_resolver.h"
#include "net/http/http_cache.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/public/mojom/network_context.mojom.h"
using content::BrowserThread;
......
......@@ -19,8 +19,8 @@
#include "net/base/address_family.h"
#include "net/base/ip_address.h"
#include "net/base/network_interfaces.h"
#include "net/dns/mdns_client.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/util.h"
#include "services/network/public/mojom/network_service.mojom.h"
namespace {
......@@ -169,10 +169,11 @@ void PrivetTrafficDetector::Helper::Bind() {
socket_options->multicast_loopback_mode = false;
socket_->Bind(
net::GetMDnsReceiveEndPoint(net::ADDRESS_FAMILY_IPV4),
net::dns_util::GetMdnsReceiveEndPoint(net::ADDRESS_FAMILY_IPV4),
std::move(socket_options),
base::BindOnce(&Helper::OnBindComplete, weak_ptr_factory_.GetWeakPtr(),
net::GetMDnsGroupEndPoint(net::ADDRESS_FAMILY_IPV4)));
base::BindOnce(
&Helper::OnBindComplete, weak_ptr_factory_.GetWeakPtr(),
net::dns_util::GetMdnsGroupEndPoint(net::ADDRESS_FAMILY_IPV4)));
}
void PrivetTrafficDetector::Helper::OnBindComplete(
......
......@@ -135,41 +135,17 @@ source_set("host_resolver") {
# Whitelist-only access so we can keep track of all usage external to the
# network stack and network service.
friend = [
# chrome/browser/devtools/device/tcp_device_provider.cc
# TODO(crbug.com/874653): Remove once migrated to network service IPC.
#
# chrome/browser/devtools/device/port_forwarding_controller.cc
# TODO(crbug.com/874651): Remove once migrated to network service IPC.
"//chrome/browser/devtools",
# chrome/browser/io_thread.cc
# Used to build in-process HostResolver when network service disabled.
#
# chrome/browser/net/dns_probe_service.cc
# TODO(crbug.com/874660): Remove once migrated to network service IPC.
#
# chrome/browser/net/url_info.h
# chrome/browser/net_benchmarking.cc
# HostResolver only used for deprecated net::Predictor.
# TODO(crbug.com/875238): Remove once deprecated code is removed.
"//chrome/browser",
# chrome/browser/ui/webui/net_internals/net_internals_ui.cc
# TODO(crbug.com/876110): Remove once migrated to network service IPC.
"//chrome/browser/ui",
# chromecast/browser/url_request_context_factory.cc
# URLRequestContext creation for chromecast.
"//chromecast/browser",
# components/network_hints/browser/network_hints_message_filter.cc
# TODO(crbug.com/874654): Remove once migrated to network service IPC.
"//components/network_hints/browser",
# headless/lib/browser/headless_url_request_context_getter.cc
# URLRequestContext creation for headless.
"//headless",
# URLRequestContext and HttpNetworkSession::Context creation for iOS.
"//ios/components/io_thread",
"//ios/web/shell",
......@@ -178,6 +154,7 @@ source_set("host_resolver") {
# Tests and test support.
"//chrome/browser:test_support",
"//chrome/test:browser_tests",
"//chrome/test:unit_tests",
"//components/grpc_support/test:unit_tests",
"//content/shell:content_shell_lib",
......@@ -218,7 +195,6 @@ source_set("host_resolver") {
}
# Overridable implementation details of HostResolver.
# TODO(crbug.com/846423): Servicify or remove external usage.
source_set("host_resolver_impl") {
# Due to circular dependencies, should only be depended on through //net.
# Limit visibility to //net and other source_sets with the same access
......@@ -231,7 +207,16 @@ source_set("host_resolver_impl") {
# Whitelist-only access so we can keep track of all usage external to the
# network stack.
friend = [
# chromeos/network/network_change_notifier_chromeos.cc
# ChromeOS-specific change notifier with some overrides for DnsConfigService
# TODO(crbug.com/882610): Remove/cleanup once we figure out servicification.
#
# chromeos/network/host_resolver_impl_chromeos.h
# ChromeOS-specific overriding implementation of HostResolverImpl.
# TODO(crbug.com/827533): Remove once converted to use network service.
"//chromeos/network",
# Network stack/service
"//components/cronet/*",
"//net/*",
"//services/network:tests",
......@@ -257,11 +242,9 @@ source_set("host_resolver_impl") {
]
}
# DnsClient interfaces. Primarily intended as part of the impelementation of the
# DnsClient interfaces. Primarily intended as part of the implementation of the
# standard HostResolver interface, but can be used as an alternative external
# interface for advanced usage.
# TODO(crbug.com/846423): Figure out what we want to do with these for
# servicification.
source_set("dns_client") {
# Due to circular dependencies, should only be depended on through //net.
# Limit visibility to //net and other source_sets with the same access
......@@ -275,10 +258,26 @@ source_set("dns_client") {
# Whitelist-only access so we can keep track of all usage external to the
# network stack.
friend = [
# chrome/browser/local_discovery/service_discovery_client_impl.cc
# Result parsing utilities for parsing results read through MdnsClient.
# TODO(crbug.com/874662): Remove once migrated to network service.
#
# chrome/browser/net/dns_probe_runner.cc
# chrome/browser/net/dns_probe_service.cc
# DNS lookups using DnsClient.
# TODO(crbug.com/874660): Remove once migrated to network service.
"//chrome/browser",
"//chrome/browser:test_support",
# chrome/browser/chromeos/smb_client/discovery/mdns_host_locator.cc
# Result parsing for results read through MdnsClient.
# TODO(crbug.com/902531): Remove once migrated to network service.
"//chrome/browser/chromeos",
# Tests and test support
"//chrome/browser:test_support",
"//chrome/test/*",
# Network stack/service
"//components/certificate_transparency/*",
"//net/*",
"//services/network/*",
......@@ -307,8 +306,6 @@ source_set("dns_client") {
}
# MdnsClient interfaces.
# TODO(crbug.com/846423): Figure out what we want to do with these for
# servicification.
source_set("mdns_client") {
# Due to circular dependencies, should only be depended on through //net.
# Limit visibility to //net and other source_sets with the same access
......@@ -321,10 +318,27 @@ source_set("mdns_client") {
# Whitelist-only access so we can keep track of all usage external to the
# network stack.
friend = [
# chrome/browser/local_discovery/service_discovery_client_mdns.h
# chrome/browser/local_discovery/service_discovery_client_impl.h
# Makes MDNS queries using MDnsClient.
# TODO(crbug.com/874662): Remove once migrated to network service.
"//chrome/browser",
"//chrome/browser:test_support",
"//chrome/browser/chromeos",
# chrome/tools/service_discovery_sniffer/service_discovery_sniffer.cc
# Creates MDnsClient instance and passes to ServiceDiscoveryClientImpl.
# TODO(crbug.com/874662): Remove once discovery client migrated.
"//chrome/tools/service_discovery_sniffer",
# chrome/browser/chromeos/smb_client/discovery/mdns_host_locator.h
# chrome/browser/chromeos/smb_client/discovery/mdns_host_locator.cc
# Makes MDNS queries using MDnsClient.
# TODO(crbug.com/902531): Remove once migrated to network service.
"//chrome/browser/chromeos",
# Tests and test support
"//chrome/browser:test_support",
# Network stack/service
"//net/*",
"//services/network/*",
]
......
......@@ -8,7 +8,6 @@
#include <limits.h>
#include <cstring>
#include <set>
#include <unordered_map>
#include <vector>
......@@ -22,7 +21,6 @@
#include "net/base/url_util.h"
#include "net/dns/public/dns_protocol.h"
#include "net/third_party/uri_template/uri_template.h"
#include "url/gurl.h"
#include "url/url_canon.h"
namespace {
......@@ -148,35 +146,6 @@ std::string GetURLFromTemplateWithoutParameters(const string& server_template) {
return url_string;
}
bool IsValidDoHTemplate(const string& server_template,
const string& server_method) {
std::string url_string;
std::string test_query = "this_is_a_test_query";
std::unordered_map<std::string, std::string> template_params(
{{"dns", test_query}});
std::set<std::string> vars_found;
bool valid_template = uri_template::Expand(server_template, template_params,
&url_string, &vars_found);
if (!valid_template) {
// The URI template is malformed.
return false;
}
if (server_method != "POST" && vars_found.find("dns") == vars_found.end()) {
// GET requests require the template to have a dns variable.
return false;
}
GURL url(url_string);
if (!url.is_valid() || !url.SchemeIs("https")) {
// The expanded template must be a valid HTTPS URL.
return false;
}
if (url.host().find(test_query) != std::string::npos) {
// The dns variable may not be part of the hostname.
return false;
}
return true;
}
#if !defined(OS_NACL)
namespace {
......
......@@ -50,13 +50,6 @@ NET_EXPORT std::string DNSDomainToString(const base::StringPiece& domain);
NET_EXPORT_PRIVATE std::string GetURLFromTemplateWithoutParameters(
const std::string& server_template);
// Returns true if the URI template is acceptable for sending requests via the
// given method. The template must be properly formatted, GET requests require
// the template to contain a "dns" variable, an expanded template must parse
// to a valid HTTPS URL, and the "dns" variable may not be part of the hostname.
NET_EXPORT_PRIVATE bool IsValidDoHTemplate(const std::string& server_template,
const std::string& server_method);
#if !defined(OS_NACL)
NET_EXPORT_PRIVATE
base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault(
......
......@@ -4,12 +4,11 @@
#include "net/dns/mdns_client.h"
#include "build/build_config.h"
#include "net/base/ip_address.h"
#include "net/base/address_family.h"
#include "net/base/net_errors.h"
#include "net/base/network_interfaces.h"
#include "net/dns/mdns_client_impl.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/util.h"
#include "net/log/net_log.h"
#include "net/log/net_log_source.h"
......@@ -17,28 +16,18 @@ namespace net {
namespace {
const char kMDnsMulticastGroupIPv4[] = "224.0.0.251";
const char kMDnsMulticastGroupIPv6[] = "FF02::FB";
IPEndPoint GetMDnsIPEndPoint(const char* address) {
IPAddress multicast_group_number;
bool success = multicast_group_number.AssignFromIPLiteral(address);
DCHECK(success);
return IPEndPoint(multicast_group_number,
dns_protocol::kDefaultPortMulticast);
}
int Bind(AddressFamily address_family,
uint32_t interface_index,
DatagramServerSocket* socket) {
socket->AllowAddressSharingForMulticast();
socket->SetMulticastInterface(interface_index);
int rv = socket->Listen(GetMDnsReceiveEndPoint(address_family));
int rv = socket->Listen(dns_util::GetMdnsReceiveEndPoint(address_family));
if (rv < OK)
return rv;
return socket->JoinGroup(GetMDnsGroupEndPoint(address_family).address());
return socket->JoinGroup(
dns_util::GetMdnsGroupEndPoint(address_family).address());
}
} // namespace
......@@ -56,43 +45,6 @@ std::unique_ptr<MDnsClient> MDnsClient::CreateDefault() {
return std::unique_ptr<MDnsClient>(new MDnsClientImpl());
}
IPEndPoint GetMDnsGroupEndPoint(AddressFamily address_family) {
switch (address_family) {
case ADDRESS_FAMILY_IPV4:
return GetMDnsIPEndPoint(kMDnsMulticastGroupIPv4);
case ADDRESS_FAMILY_IPV6:
return GetMDnsIPEndPoint(kMDnsMulticastGroupIPv6);
default:
NOTREACHED();
return IPEndPoint();
}
}
IPEndPoint GetMDnsReceiveEndPoint(AddressFamily address_family) {
#if defined(OS_WIN) || defined(OS_FUCHSIA)
// With Windows, binding to a mulitcast group address is not allowed.
// Multicast messages will be received appropriate to the multicast groups the
// socket has joined. Sockets intending to receive multicast messages should
// bind to a wildcard address (e.g. 0.0.0.0).
switch (address_family) {
case ADDRESS_FAMILY_IPV4:
return IPEndPoint(IPAddress::IPv4AllZeros(),
dns_protocol::kDefaultPortMulticast);
case ADDRESS_FAMILY_IPV6:
return IPEndPoint(IPAddress::IPv6AllZeros(),
dns_protocol::kDefaultPortMulticast);
default:
NOTREACHED();
return IPEndPoint();
}
#else // !(defined(OS_WIN) || defined(OS_FUCHSIA))
// With POSIX, any socket can receive messages for multicast groups joined by
// any socket on the system. Sockets intending to receive messages for a
// specific multicast group should bind to that group address.
return GetMDnsGroupEndPoint(address_family);
#endif // !(defined(OS_WIN) || defined(OS_FUCHSIA))
}
InterfaceIndexFamilyList GetMDnsInterfacesToBind() {
NetworkInterfaceList network_list;
InterfaceIndexFamilyList interfaces;
......
......@@ -19,6 +19,7 @@
#include "net/base/rand_callback.h"
#include "net/dns/dns_util.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/util.h"
#include "net/dns/record_rdata.h"
#include "net/socket/datagram_socket.h"
......@@ -70,7 +71,7 @@ int MDnsConnection::SocketHandler::Start() {
return rv;
DCHECK(end_point.GetFamily() == ADDRESS_FAMILY_IPV4 ||
end_point.GetFamily() == ADDRESS_FAMILY_IPV6);
multicast_addr_ = GetMDnsGroupEndPoint(end_point.GetFamily());
multicast_addr_ = dns_util::GetMdnsGroupEndPoint(end_point.GetFamily());
return DoLoop(0);
}
......
......@@ -12,6 +12,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/base/net_errors.h"
#include "net/dns/public/util.h"
using testing::_;
using testing::Invoke;
......@@ -20,7 +21,7 @@ namespace net {
MockMDnsDatagramServerSocket::MockMDnsDatagramServerSocket(
AddressFamily address_family) {
local_address_ = GetMDnsReceiveEndPoint(address_family);
local_address_ = dns_util::GetMdnsReceiveEndPoint(address_family);
}
MockMDnsDatagramServerSocket::~MockMDnsDatagramServerSocket() = default;
......
......@@ -21,8 +21,14 @@ namespace net {
namespace dns_protocol {
static const uint16_t kDefaultPort = 53;
// RFC 5353.
static const uint16_t kDefaultPortMulticast = 5353;
// https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml#multicast-addresses-1
static const char kMdnsMulticastGroupIPv4[] = "224.0.0.251";
// https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml#link-local
static const char kMdnsMulticastGroupIPv6[] = "FF02::FB";
// DNS packet consists of a header followed by questions and/or answers.
// For the meaning of specific fields, please see RFC 1035 and 2535
......
......@@ -7,10 +7,25 @@
#include <set>
#include <unordered_map>
#include "base/logging.h"
#include "build/build_config.h"
#include "net/base/ip_address.h"
#include "net/dns/public/dns_protocol.h"
#include "net/third_party/uri_template/uri_template.h"
#include "url/gurl.h"
namespace net {
namespace {
IPEndPoint GetMdnsIPEndPoint(const char* address) {
IPAddress multicast_group_number;
bool success = multicast_group_number.AssignFromIPLiteral(address);
DCHECK(success);
return IPEndPoint(multicast_group_number,
dns_protocol::kDefaultPortMulticast);
}
} // namespace
namespace dns_util {
bool IsValidDoHTemplate(const string& server_template,
......@@ -42,5 +57,42 @@ bool IsValidDoHTemplate(const string& server_template,
return true;
}
IPEndPoint GetMdnsGroupEndPoint(AddressFamily address_family) {
switch (address_family) {
case ADDRESS_FAMILY_IPV4:
return GetMdnsIPEndPoint(dns_protocol::kMdnsMulticastGroupIPv4);
case ADDRESS_FAMILY_IPV6:
return GetMdnsIPEndPoint(dns_protocol::kMdnsMulticastGroupIPv6);
default:
NOTREACHED();
return IPEndPoint();
}
}
IPEndPoint GetMdnsReceiveEndPoint(AddressFamily address_family) {
#if defined(OS_WIN) || defined(OS_FUCHSIA)
// With Windows, binding to a mulitcast group address is not allowed.
// Multicast messages will be received appropriate to the multicast groups the
// socket has joined. Sockets intending to receive multicast messages should
// bind to a wildcard address (e.g. 0.0.0.0).
switch (address_family) {
case ADDRESS_FAMILY_IPV4:
return IPEndPoint(IPAddress::IPv4AllZeros(),
dns_protocol::kDefaultPortMulticast);
case ADDRESS_FAMILY_IPV6:
return IPEndPoint(IPAddress::IPv6AllZeros(),
dns_protocol::kDefaultPortMulticast);
default:
NOTREACHED();
return IPEndPoint();
}
#else // !(defined(OS_WIN) || defined(OS_FUCHSIA))
// With POSIX, any socket can receive messages for multicast groups joined by
// any socket on the system. Sockets intending to receive messages for a
// specific multicast group should bind to that group address.
return GetMdnsGroupEndPoint(address_family);
#endif // !(defined(OS_WIN) || defined(OS_FUCHSIA))
}
} // namespace dns_util
} // namespace net
......@@ -7,6 +7,8 @@
#include <string>
#include "net/base/address_family.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_export.h"
namespace net {
......@@ -21,6 +23,17 @@ namespace dns_util {
NET_EXPORT bool IsValidDoHTemplate(const std::string& server_template,
const std::string& server_method);
// Gets the endpoint for the multicast group a socket should join to receive
// MDNS messages. Such sockets should also bind to the endpoint from
// GetMDnsReceiveEndPoint().
//
// This is also the endpoint messages should be sent to to send MDNS messages.
NET_EXPORT IPEndPoint GetMdnsGroupEndPoint(AddressFamily address_family);
// Gets the endpoint sockets should be bound to to receive MDNS messages. Such
// sockets should also join the multicast group from GetMDnsGroupEndPoint().
NET_EXPORT IPEndPoint GetMdnsReceiveEndPoint(AddressFamily address_family);
} // namespace dns_util
} // namespace net
......
......@@ -26,6 +26,7 @@
#include "net/dns/dns_util.h"
#include "net/dns/mdns_client.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/util.h"
#include "net/dns/record_parsed.h"
#include "net/dns/record_rdata.h"
#include "net/socket/datagram_server_socket.h"
......@@ -267,7 +268,8 @@ class MdnsResponderManager::SocketHandler {
}
DCHECK(end_point.GetFamily() == net::ADDRESS_FAMILY_IPV4 ||
end_point.GetFamily() == net::ADDRESS_FAMILY_IPV6);
multicast_addr_ = GetMDnsGroupEndPoint(end_point.GetFamily());
multicast_addr_ =
net::dns_util::GetMdnsGroupEndPoint(end_point.GetFamily());
int result = DoReadLoop();
if (result == net::ERR_IO_PENDING) {
// An in-progress read loop is considered a completed start.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment