| OLD | NEW |
| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 const uint8_t kIcanNameCollisionIp[] = {127, 0, 53, 53}; |
| 185 | 185 |
| 186 bool ContainsIcannNameCollisionIp(const AddressList& addr_list) { |
| 187 for (const auto& endpoint : addr_list) { |
| 188 const IPAddress& addr = endpoint.address(); |
| 189 if (addr.IsIPv4() && IPAddressStartsWith(addr, kIcanNameCollisionIp)) { |
| 190 return true; |
| 191 } |
| 192 } |
| 193 return false; |
| 194 } |
| 195 |
| 186 void UmaAsyncDnsResolveStatus(DnsResolveStatus result) { | 196 void UmaAsyncDnsResolveStatus(DnsResolveStatus result) { |
| 187 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ResolveStatus", | 197 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ResolveStatus", |
| 188 result, | 198 result, |
| 189 RESOLVE_STATUS_MAX); | 199 RESOLVE_STATUS_MAX); |
| 190 } | 200 } |
| 191 | 201 |
| 192 bool ResemblesNetBIOSName(const std::string& hostname) { | 202 bool ResemblesNetBIOSName(const std::string& hostname) { |
| 193 return (hostname.size() < 16) && (hostname.find('.') == std::string::npos); | 203 return (hostname.size() < 16) && (hostname.find('.') == std::string::npos); |
| 194 } | 204 } |
| 195 | 205 |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 const uint32_t attempt_number) { | 742 const uint32_t attempt_number) { |
| 733 AddressList results; | 743 AddressList results; |
| 734 int os_error = 0; | 744 int os_error = 0; |
| 735 // Running on a worker task runner. | 745 // Running on a worker task runner. |
| 736 int error = params_.resolver_proc->Resolve(key_.hostname, | 746 int error = params_.resolver_proc->Resolve(key_.hostname, |
| 737 key_.address_family, | 747 key_.address_family, |
| 738 key_.host_resolver_flags, | 748 key_.host_resolver_flags, |
| 739 &results, | 749 &results, |
| 740 &os_error); | 750 &os_error); |
| 741 | 751 |
| 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( | 752 network_task_runner_->PostTask( |
| 753 FROM_HERE, base::Bind(&ProcTask::OnLookupComplete, this, results, | 753 FROM_HERE, base::Bind(&ProcTask::OnLookupComplete, this, results, |
| 754 start_time, attempt_number, error, os_error)); | 754 start_time, attempt_number, error, os_error)); |
| 755 } | 755 } |
| 756 | 756 |
| 757 // Makes next attempt if DoLookup() has not finished. | 757 // Makes next attempt if DoLookup() has not finished. |
| 758 void RetryIfNotComplete() { | 758 void RetryIfNotComplete() { |
| 759 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 759 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 760 | 760 |
| 761 if (was_completed() || was_canceled()) | 761 if (was_completed() || was_canceled()) |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 } | 1612 } |
| 1613 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.ResolveError", | 1613 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.ResolveError", |
| 1614 std::abs(dns_task_error_)); | 1614 std::abs(dns_task_error_)); |
| 1615 resolver_->OnDnsTaskResolve(dns_task_error_); | 1615 resolver_->OnDnsTaskResolve(dns_task_error_); |
| 1616 } else { | 1616 } else { |
| 1617 DNS_HISTOGRAM("AsyncDNS.FallbackFail", duration); | 1617 DNS_HISTOGRAM("AsyncDNS.FallbackFail", duration); |
| 1618 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_FAIL); | 1618 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_FAIL); |
| 1619 } | 1619 } |
| 1620 } | 1620 } |
| 1621 | 1621 |
| 1622 if (ContainsIcannNameCollisionIp(addr_list)) |
| 1623 net_error = ERR_ICANN_NAME_COLLISION; |
| 1624 |
| 1622 base::TimeDelta ttl = | 1625 base::TimeDelta ttl = |
| 1623 base::TimeDelta::FromSeconds(kNegativeCacheEntryTTLSeconds); | 1626 base::TimeDelta::FromSeconds(kNegativeCacheEntryTTLSeconds); |
| 1624 if (net_error == OK) | 1627 if (net_error == OK) |
| 1625 ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds); | 1628 ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds); |
| 1626 | 1629 |
| 1627 // Don't store the |ttl| in cache since it's not obtained from the server. | 1630 // Don't store the |ttl| in cache since it's not obtained from the server. |
| 1628 CompleteRequests( | 1631 CompleteRequests( |
| 1629 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list)), | 1632 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list)), |
| 1630 ttl); | 1633 ttl); |
| 1631 } | 1634 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 } | 1705 } |
| 1703 | 1706 |
| 1704 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_DNS_SUCCESS); | 1707 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_DNS_SUCCESS); |
| 1705 RecordTTL(ttl); | 1708 RecordTTL(ttl); |
| 1706 | 1709 |
| 1707 resolver_->OnDnsTaskResolve(OK); | 1710 resolver_->OnDnsTaskResolve(OK); |
| 1708 | 1711 |
| 1709 base::TimeDelta bounded_ttl = | 1712 base::TimeDelta bounded_ttl = |
| 1710 std::max(ttl, base::TimeDelta::FromSeconds(kMinimumTTLSeconds)); | 1713 std::max(ttl, base::TimeDelta::FromSeconds(kMinimumTTLSeconds)); |
| 1711 | 1714 |
| 1715 if (ContainsIcannNameCollisionIp(addr_list)) |
| 1716 net_error = ERR_ICANN_NAME_COLLISION; |
| 1717 |
| 1712 CompleteRequests( | 1718 CompleteRequests( |
| 1713 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list), ttl), | 1719 HostCache::Entry(net_error, MakeAddressListForRequest(addr_list), ttl), |
| 1714 bounded_ttl); | 1720 bounded_ttl); |
| 1715 } | 1721 } |
| 1716 | 1722 |
| 1717 void OnFirstDnsTransactionComplete() override { | 1723 void OnFirstDnsTransactionComplete() override { |
| 1718 DCHECK(dns_task_->needs_two_transactions()); | 1724 DCHECK(dns_task_->needs_two_transactions()); |
| 1719 DCHECK_EQ(dns_task_->needs_another_transaction(), is_queued()); | 1725 DCHECK_EQ(dns_task_->needs_another_transaction(), is_queued()); |
| 1720 // No longer need to occupy two dispatcher slots. | 1726 // No longer need to occupy two dispatcher slots. |
| 1721 ReduceToOneJobSlot(); | 1727 ReduceToOneJobSlot(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 return; | 1768 return; |
| 1763 } | 1769 } |
| 1764 | 1770 |
| 1765 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB, | 1771 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB, |
| 1766 entry.error()); | 1772 entry.error()); |
| 1767 | 1773 |
| 1768 resolver_->SchedulePersist(); | 1774 resolver_->SchedulePersist(); |
| 1769 | 1775 |
| 1770 DCHECK(!requests_.empty()); | 1776 DCHECK(!requests_.empty()); |
| 1771 | 1777 |
| 1772 if (entry.error() == OK) { | 1778 if (entry.error() == OK || entry.error() == ERR_ICANN_NAME_COLLISION) { |
| 1773 // Record this histogram here, when we know the system has a valid DNS | 1779 // Record this histogram here, when we know the system has a valid DNS |
| 1774 // configuration. | 1780 // configuration. |
| 1775 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", | 1781 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", |
| 1776 resolver_->received_dns_config_); | 1782 resolver_->received_dns_config_); |
| 1777 } | 1783 } |
| 1778 | 1784 |
| 1779 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) && | 1785 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) && |
| 1780 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); | 1786 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); |
| 1781 if (did_complete) { | 1787 if (did_complete) { |
| 1782 resolver_->CacheResult(key_, entry, ttl); | 1788 resolver_->CacheResult(key_, entry, ttl); |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2610 if (job_) | 2616 if (job_) |
| 2611 job_->CancelRequest(this); | 2617 job_->CancelRequest(this); |
| 2612 } | 2618 } |
| 2613 | 2619 |
| 2614 void HostResolverImpl::RequestImpl::ChangeRequestPriority( | 2620 void HostResolverImpl::RequestImpl::ChangeRequestPriority( |
| 2615 RequestPriority priority) { | 2621 RequestPriority priority) { |
| 2616 job_->ChangeRequestPriority(this, priority); | 2622 job_->ChangeRequestPriority(this, priority); |
| 2617 } | 2623 } |
| 2618 | 2624 |
| 2619 } // namespace net | 2625 } // namespace net |
| OLD | NEW |