Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: net/dns/host_resolver_impl.cc

Issue 2567623003: Make ERR_ICANN_NAME_COLLISION work for async DNS resolver. (Closed)
Patch Set: one more Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // ICANN uses this localhost address to indicate a name collision. 175 // ICANN uses this localhost address to indicate a name collision.
176 // 176 //
177 // The policy in Chromium is to fail host resolving if it resolves to 177 // The policy in Chromium is to fail host resolving if it resolves to
178 // this special address. 178 // this special address.
179 // 179 //
180 // Not however that IP literals are exempt from this policy, so it is still 180 // Not however that IP literals are exempt from this policy, so it is still
181 // possible to navigate to http://127.0.53.53/ directly. 181 // possible to navigate to http://127.0.53.53/ directly.
182 // 182 //
183 // For more details: https://www.icann.org/news/announcement-2-2014-08-01-en 183 // For more details: https://www.icann.org/news/announcement-2-2014-08-01-en
184 const uint8_t kIcanNameCollisionIp[] = {127, 0, 53, 53}; 184 bool ContainsIcannNameCollisionIp(const AddressList& addr_list) {
185 static const uint8_t kIcanNameCollisionIp[] = {127, 0, 53, 53};
mmenke 2016/12/13 19:24:15 I thought not using static was preferred, to ensur
eroman 2016/12/13 22:09:04 Done. Not sure (I have seen both instances in our
186 for (const auto& endpoint : addr_list) {
187 const IPAddress& addr = endpoint.address();
188 if (addr.IsIPv4() && IPAddressStartsWith(addr, kIcanNameCollisionIp)) {
189 return true;
190 }
191 }
192 return false;
193 }
185 194
186 void UmaAsyncDnsResolveStatus(DnsResolveStatus result) { 195 void UmaAsyncDnsResolveStatus(DnsResolveStatus result) {
187 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ResolveStatus", 196 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ResolveStatus",
188 result, 197 result,
189 RESOLVE_STATUS_MAX); 198 RESOLVE_STATUS_MAX);
190 } 199 }
191 200
192 bool ResemblesNetBIOSName(const std::string& hostname) { 201 bool ResemblesNetBIOSName(const std::string& hostname) {
193 return (hostname.size() < 16) && (hostname.find('.') == std::string::npos); 202 return (hostname.size() < 16) && (hostname.find('.') == std::string::npos);
194 } 203 }
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 const uint32_t attempt_number) { 741 const uint32_t attempt_number) {
733 AddressList results; 742 AddressList results;
734 int os_error = 0; 743 int os_error = 0;
735 // Running on a worker task runner. 744 // Running on a worker task runner.
736 int error = params_.resolver_proc->Resolve(key_.hostname, 745 int error = params_.resolver_proc->Resolve(key_.hostname,
737 key_.address_family, 746 key_.address_family,
738 key_.host_resolver_flags, 747 key_.host_resolver_flags,
739 &results, 748 &results,
740 &os_error); 749 &os_error);
741 750
742 // Fail the resolution if the result contains 127.0.53.53. See the comment
743 // block of kIcanNameCollisionIp for details on why.
744 for (const auto& it : results) {
745 const IPAddress& cur = it.address();
746 if (cur.IsIPv4() && IPAddressStartsWith(cur, kIcanNameCollisionIp)) {
747 error = ERR_ICANN_NAME_COLLISION;
748 break;
749 }
750 }
751
752 network_task_runner_->PostTask( 751 network_task_runner_->PostTask(
753 FROM_HERE, base::Bind(&ProcTask::OnLookupComplete, this, results, 752 FROM_HERE, base::Bind(&ProcTask::OnLookupComplete, this, results,
754 start_time, attempt_number, error, os_error)); 753 start_time, attempt_number, error, os_error));
755 } 754 }
756 755
757 // Makes next attempt if DoLookup() has not finished. 756 // Makes next attempt if DoLookup() has not finished.
758 void RetryIfNotComplete() { 757 void RetryIfNotComplete() {
759 DCHECK(network_task_runner_->BelongsToCurrentThread()); 758 DCHECK(network_task_runner_->BelongsToCurrentThread());
760 759
761 if (was_completed() || was_canceled()) 760 if (was_completed() || was_canceled())
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 } 1611 }
1613 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.ResolveError", 1612 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.ResolveError",
1614 std::abs(dns_task_error_)); 1613 std::abs(dns_task_error_));
1615 resolver_->OnDnsTaskResolve(dns_task_error_); 1614 resolver_->OnDnsTaskResolve(dns_task_error_);
1616 } else { 1615 } else {
1617 DNS_HISTOGRAM("AsyncDNS.FallbackFail", duration); 1616 DNS_HISTOGRAM("AsyncDNS.FallbackFail", duration);
1618 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_FAIL); 1617 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_FAIL);
1619 } 1618 }
1620 } 1619 }
1621 1620
1621 if (ContainsIcannNameCollisionIp(addr_list))
1622 net_error = ERR_ICANN_NAME_COLLISION;
1623
1622 base::TimeDelta ttl = 1624 base::TimeDelta ttl =
1623 base::TimeDelta::FromSeconds(kNegativeCacheEntryTTLSeconds); 1625 base::TimeDelta::FromSeconds(kNegativeCacheEntryTTLSeconds);
1624 if (net_error == OK) 1626 if (net_error == OK)
1625 ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds); 1627 ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds);
1626 1628
1627 // Don't store the |ttl| in cache since it's not obtained from the server. 1629 // Don't store the |ttl| in cache since it's not obtained from the server.
1628 CompleteRequests( 1630 CompleteRequests(
1629 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list)), 1631 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list)),
1630 ttl); 1632 ttl);
1631 } 1633 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 } 1704 }
1703 1705
1704 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_DNS_SUCCESS); 1706 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_DNS_SUCCESS);
1705 RecordTTL(ttl); 1707 RecordTTL(ttl);
1706 1708
1707 resolver_->OnDnsTaskResolve(OK); 1709 resolver_->OnDnsTaskResolve(OK);
1708 1710
1709 base::TimeDelta bounded_ttl = 1711 base::TimeDelta bounded_ttl =
1710 std::max(ttl, base::TimeDelta::FromSeconds(kMinimumTTLSeconds)); 1712 std::max(ttl, base::TimeDelta::FromSeconds(kMinimumTTLSeconds));
1711 1713
1714 if (ContainsIcannNameCollisionIp(addr_list))
1715 net_error = ERR_ICANN_NAME_COLLISION;
1716
1712 CompleteRequests( 1717 CompleteRequests(
1713 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list), ttl), 1718 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list), ttl),
1714 bounded_ttl); 1719 bounded_ttl);
mmenke 2016/12/13 19:24:16 I know this is old behavior, but can we not pass t
eroman 2016/12/13 22:09:04 Correct, I believe that addr_list shouldn't be use
mmenke 2016/12/13 22:14:59 I'm actually not at all concerned about perf here.
eroman 2016/12/13 22:50:18 That's a fair concern. I will address in a follow-
1715 } 1720 }
1716 1721
1717 void OnFirstDnsTransactionComplete() override { 1722 void OnFirstDnsTransactionComplete() override {
1718 DCHECK(dns_task_->needs_two_transactions()); 1723 DCHECK(dns_task_->needs_two_transactions());
1719 DCHECK_EQ(dns_task_->needs_another_transaction(), is_queued()); 1724 DCHECK_EQ(dns_task_->needs_another_transaction(), is_queued());
1720 // No longer need to occupy two dispatcher slots. 1725 // No longer need to occupy two dispatcher slots.
1721 ReduceToOneJobSlot(); 1726 ReduceToOneJobSlot();
1722 1727
1723 // We already have a job slot at the dispatcher, so if the second 1728 // We already have a job slot at the dispatcher, so if the second
1724 // transaction hasn't started, reuse it now instead of waiting in the queue 1729 // transaction hasn't started, reuse it now instead of waiting in the queue
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 return; 1767 return;
1763 } 1768 }
1764 1769
1765 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB, 1770 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB,
1766 entry.error()); 1771 entry.error());
1767 1772
1768 resolver_->SchedulePersist(); 1773 resolver_->SchedulePersist();
1769 1774
1770 DCHECK(!requests_.empty()); 1775 DCHECK(!requests_.empty());
1771 1776
1772 if (entry.error() == OK) { 1777 if (entry.error() == OK || entry.error() == ERR_ICANN_NAME_COLLISION) {
1773 // Record this histogram here, when we know the system has a valid DNS 1778 // Record this histogram here, when we know the system has a valid DNS
1774 // configuration. 1779 // configuration.
1775 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", 1780 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig",
1776 resolver_->received_dns_config_); 1781 resolver_->received_dns_config_);
1777 } 1782 }
1778 1783
1779 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) && 1784 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) &&
1780 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); 1785 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE);
1781 if (did_complete) { 1786 if (did_complete) {
1782 resolver_->CacheResult(key_, entry, ttl); 1787 resolver_->CacheResult(key_, entry, ttl);
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 if (job_) 2615 if (job_)
2611 job_->CancelRequest(this); 2616 job_->CancelRequest(this);
2612 } 2617 }
2613 2618
2614 void HostResolverImpl::RequestImpl::ChangeRequestPriority( 2619 void HostResolverImpl::RequestImpl::ChangeRequestPriority(
2615 RequestPriority priority) { 2620 RequestPriority priority) {
2616 job_->ChangeRequestPriority(this, priority); 2621 job_->ChangeRequestPriority(this, priority);
2617 } 2622 }
2618 2623
2619 } // namespace net 2624 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698