summaryrefslogtreecommitdiffstats
path: root/net/dns/mdns_cache.cc
diff options
context:
space:
mode:
authornoamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-11 19:59:03 +0000
committernoamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-11 19:59:03 +0000
commit35f3a6b7d6568956de88dd230a611d90e0666896 (patch)
tree9e10315d7e5f5be942dcda37f67e3595e98f9a3a /net/dns/mdns_cache.cc
parent3a585276f38d07d23f84d7664791c58d58c60b29 (diff)
downloadchromium_src-35f3a6b7d6568956de88dd230a611d90e0666896.zip
chromium_src-35f3a6b7d6568956de88dd230a611d90e0666896.tar.gz
chromium_src-35f3a6b7d6568956de88dd230a611d90e0666896.tar.bz2
Add correct handling of goodbye packets to MDnsCache
Handle goodbye packets separately -- a goodbye packet should never cause the cache to seem to change. Also, a goodbye packet for a record not in the cache should not add it to the cache. BUG=255084 Review URL: https://chromiumcodereview.appspot.com/18106002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211194 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/mdns_cache.cc')
-rw-r--r--net/dns/mdns_cache.cc22
1 files changed, 12 insertions, 10 deletions
diff --git a/net/dns/mdns_cache.cc b/net/dns/mdns_cache.cc
index b430f95..010a34f 100644
--- a/net/dns/mdns_cache.cc
+++ b/net/dns/mdns_cache.cc
@@ -4,6 +4,7 @@
#include "net/dns/mdns_cache.h"
+#include <algorithm>
#include <utility>
#include "base/stl_util.h"
@@ -89,31 +90,32 @@ const RecordParsed* MDnsCache::LookupKey(const Key& key) {
MDnsCache::UpdateType MDnsCache::UpdateDnsRecord(
scoped_ptr<const RecordParsed> record) {
- UpdateType type = NoChange;
-
Key cache_key = Key::CreateFor(record.get());
- base::Time expiration = GetEffectiveExpiration(record.get());
- if (next_expiration_ == base::Time() || expiration < next_expiration_) {
- next_expiration_ = expiration;
- }
+ // Ignore "goodbye" packets for records not in cache.
+ if (record->ttl() == 0 && mdns_cache_.find(cache_key) == mdns_cache_.end())
+ return NoChange;
+
+ base::Time new_expiration = GetEffectiveExpiration(record.get());
+ if (next_expiration_ != base::Time())
+ new_expiration = std::min(new_expiration, next_expiration_);
std::pair<RecordMap::iterator, bool> insert_result =
mdns_cache_.insert(std::make_pair(cache_key, (const RecordParsed*)NULL));
-
+ UpdateType type = NoChange;
if (insert_result.second) {
type = RecordAdded;
- insert_result.first->second = record.release();
} else {
const RecordParsed* other_record = insert_result.first->second;
- if (!record->IsEqual(other_record, true)) {
+ if (record->ttl() != 0 && !record->IsEqual(other_record, true)) {
type = RecordChanged;
}
delete other_record;
- insert_result.first->second = record.release();
}
+ insert_result.first->second = record.release();
+ next_expiration_ = new_expiration;
return type;
}