summaryrefslogtreecommitdiffstats
path: root/net/dns
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-12 19:18:56 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-12 19:18:56 +0000
commit3c4f7dfd3ecf4c5c69fc160be98a20b3b1b31c96 (patch)
tree8e4ede291d47295b4e73f18d44b9dff1a2c0a333 /net/dns
parentff762fbe1abebb014ef65596becbcd28900b44de (diff)
downloadchromium_src-3c4f7dfd3ecf4c5c69fc160be98a20b3b1b31c96.zip
chromium_src-3c4f7dfd3ecf4c5c69fc160be98a20b3b1b31c96.tar.gz
chromium_src-3c4f7dfd3ecf4c5c69fc160be98a20b3b1b31c96.tar.bz2
[net/dns] Make DnsResponse::ParseToAddressList less stroct.
Obsoletes DnsResponse::DNS_ADDRESS_TTL_MISMATCH. Ignores DNS_NAME_MISMATCH on resource records of ignored types. BUG=164696 TEST=net_unittests --gtest_filter=DnsResponse.ParseToAddressList Review URL: https://codereview.chromium.org/11537012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns')
-rw-r--r--net/dns/dns_response.cc23
-rw-r--r--net/dns/dns_response.h2
-rw-r--r--net/dns/dns_response_unittest.cc18
-rw-r--r--net/dns/dns_test_util.h24
4 files changed, 27 insertions, 40 deletions
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc
index 4ab7296..354622d 100644
--- a/net/dns/dns_response.cc
+++ b/net/dns/dns_response.cc
@@ -243,8 +243,7 @@ DnsResponse::Result DnsResponse::ParseToAddressList(
size_t expected_size = (expected_type == dns_protocol::kTypeAAAA)
? kIPv6AddressSize : kIPv4AddressSize;
- uint32 cname_ttl_sec = kuint32max;
- uint32 addr_ttl_sec = kuint32max;
+ uint32 ttl_sec = kuint32max;
IPAddressList ip_addresses;
DnsRecordParser parser = Parser();
DnsResourceRecord record;
@@ -253,27 +252,27 @@ DnsResponse::Result DnsResponse::ParseToAddressList(
if (!parser.ReadRecord(&record))
return DNS_MALFORMED_RESPONSE;
- if (base::strcasecmp(record.name.c_str(), expected_name.c_str()) != 0)
- return DNS_NAME_MISMATCH;
if (record.type == dns_protocol::kTypeCNAME) {
// Following the CNAME chain, only if no addresses seen.
if (!ip_addresses.empty())
return DNS_CNAME_AFTER_ADDRESS;
+ if (base::strcasecmp(record.name.c_str(), expected_name.c_str()) != 0)
+ return DNS_NAME_MISMATCH;
+
if (record.rdata.size() !=
parser.ReadName(record.rdata.begin(), &expected_name))
return DNS_MALFORMED_CNAME;
- cname_ttl_sec = std::min(cname_ttl_sec, record.ttl);
+ ttl_sec = std::min(ttl_sec, record.ttl);
} else if (record.type == expected_type) {
if (record.rdata.size() != expected_size)
return DNS_SIZE_MISMATCH;
- if (ip_addresses.empty()) {
- addr_ttl_sec = record.ttl;
- } else {
- if (addr_ttl_sec != record.ttl)
- return DNS_ADDRESS_TTL_MISMATCH;
- }
+
+ if (base::strcasecmp(record.name.c_str(), expected_name.c_str()) != 0)
+ return DNS_NAME_MISMATCH;
+
+ ttl_sec = std::min(ttl_sec, record.ttl);
ip_addresses.push_back(IPAddressNumber(record.rdata.begin(),
record.rdata.end()));
}
@@ -285,7 +284,7 @@ DnsResponse::Result DnsResponse::ParseToAddressList(
// If the response passed all the checks so far, then |expected_name| is it.
*addr_list = AddressList::CreateFromIPAddressList(ip_addresses,
expected_name);
- *ttl = base::TimeDelta::FromSeconds(std::min(cname_ttl_sec, addr_ttl_sec));
+ *ttl = base::TimeDelta::FromSeconds(ttl_sec);
return DNS_PARSE_OK;
}
diff --git a/net/dns/dns_response.h b/net/dns/dns_response.h
index fe80c30..cb61e1f 100644
--- a/net/dns/dns_response.h
+++ b/net/dns/dns_response.h
@@ -89,7 +89,7 @@ class NET_EXPORT_PRIVATE DnsResponse {
// leads there.
DNS_SIZE_MISMATCH, // Got an address but size does not match.
DNS_CNAME_AFTER_ADDRESS, // Found CNAME after an address record.
- DNS_ADDRESS_TTL_MISMATCH, // TTL of all address records are not identical.
+ DNS_ADDRESS_TTL_MISMATCH, // OBSOLETE. No longer used.
DNS_NO_ADDRESSES, // OBSOLETE. No longer used.
// Only add new values here.
DNS_PARSE_RESULT_MAX, // Bounding value for histograms.
diff --git a/net/dns/dns_response_unittest.cc b/net/dns/dns_response_unittest.cc
index 6ed6f06..760fe47 100644
--- a/net/dns/dns_response_unittest.cc
+++ b/net/dns/dns_response_unittest.cc
@@ -379,22 +379,6 @@ const uint8 kResponseCNAMEAfterAddress[] = {
0x00, 0x03, 0x01, 'b', 0x00,
};
-const uint8 kResponseTTLMismatch[] = {
- // Header: 1 question, 3 answer RR
- 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
- // Question: name = 'a', type = A (0x1)
- 0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01,
- // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = 'b'
- 0x01, 'a', 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
- 0x00, 0x03, 0x01, 'b', 0x00,
- // Answer: name = 'b', type = A, TTL = 0xFF, RDATA = 10.10.10.10
- 0x01, 'b', 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
- 0x00, 0x04, 0x0A, 0x0A, 0x0A, 0x0A,
- // Answer: name = 'b', type = A, TTL = 0xBB, RDATA = 10.10.10.11
- 0x01, 'b', 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0xBB,
- 0x00, 0x04, 0x0A, 0x0A, 0x0A, 0x0B,
-};
-
const uint8 kResponseNoAddresses[] = {
// Header: 1 question, 1 answer RR, 1 authority RR
0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
@@ -427,8 +411,6 @@ TEST(DnsResponseTest, ParseToAddressListFail) {
DnsResponse::DNS_SIZE_MISMATCH },
{ kResponseCNAMEAfterAddress, arraysize(kResponseCNAMEAfterAddress),
DnsResponse::DNS_CNAME_AFTER_ADDRESS },
- { kResponseTTLMismatch, arraysize(kResponseTTLMismatch),
- DnsResponse::DNS_ADDRESS_TTL_MISMATCH },
// Not actually a failure, just an empty result.
{ kResponseNoAddresses, arraysize(kResponseNoAddresses),
DnsResponse::DNS_PARSE_OK },
diff --git a/net/dns/dns_test_util.h b/net/dns/dns_test_util.h
index 5c5019a..7d11920 100644
--- a/net/dns/dns_test_util.h
+++ b/net/dns/dns_test_util.h
@@ -138,7 +138,10 @@ static const uint8 kT3ResponseDatagram[] = {
// response contains www.google.com as CNAME for www.google.az and
// www.l.google.com as CNAME for www.google.com and the following
// IP addresses: 74.125.226.{178,179,180,176,177}
- 0x00, 0x03, 0x81, 0x80, 0x00, 0x01, 0x00, 0x07,
+ // The TTLs on the records are: 0x00015099, 0x00025099, 0x00000415,
+ // 0x00003015, 0x00002015, 0x00000015, 0x00001015.
+ // The last record is an imaginary TXT record for t.google.com.
+ 0x00, 0x03, 0x81, 0x80, 0x00, 0x01, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x02,
0x61, 0x7a, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0,
@@ -146,18 +149,21 @@ static const uint8 kT3ResponseDatagram[] = {
0x99, 0x00, 0x10, 0x03, 0x77, 0x77, 0x77, 0x06,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
0x6f, 0x6d, 0x00, 0xc0, 0x2b, 0x00, 0x05, 0x00,
- 0x01, 0x00, 0x01, 0x50, 0x99, 0x00, 0x08, 0x03,
+ 0x01, 0x00, 0x02, 0x50, 0x99, 0x00, 0x08, 0x03,
0x77, 0x77, 0x77, 0x01, 0x6c, 0xc0, 0x2f, 0xc0,
- 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x04,
0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb2, 0xc0,
- 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x30,
0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb3, 0xc0,
- 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x20,
0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb4, 0xc0,
0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb0, 0xc0,
- 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1
+ 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10,
+ 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1, 0x01,
+ 0x74, 0xc0, 0x2f, 0x00, 0x10, 0x00, 0x01, 0x00,
+ 0x00, 0x00, 0x01, 0x00, 0x04, 0xde, 0xad, 0xfe,
+ 0xed
};
static const char* const kT3IpAddresses[] = {
"74.125.226.178", "74.125.226.179", "74.125.226.180",
@@ -165,8 +171,8 @@ static const char* const kT3IpAddresses[] = {
};
static const char kT3CanonName[] = "www.l.google.com";
static const int kT3TTL = 0x00000015;
-// +2 for the CNAME records.
-static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 2;
+// +2 for the CNAME records, +1 for TXT record.
+static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 3;
class DnsClient;