diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 19:18:21 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 19:18:21 +0000 |
commit | 3dc5d7efacf57481c6a48464c002164c74d0a9ce (patch) | |
tree | 255985f7d375c48e36b7e5dbb8805e964200c023 /net | |
parent | 3cfe937422ac6bb8f8be1a8d95d15ddb3469736f (diff) | |
download | chromium_src-3dc5d7efacf57481c6a48464c002164c74d0a9ce.zip chromium_src-3dc5d7efacf57481c6a48464c002164c74d0a9ce.tar.gz chromium_src-3dc5d7efacf57481c6a48464c002164c74d0a9ce.tar.bz2 |
Revert "Support replacement of IP address resolutions via command line flag"
Original CL: http://crrev.com/156963003
Preserved ip_pattern* which is now being used by the DnsConfigService.
BUG=347382
Review URL: https://codereview.chromium.org/215623003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/ip_mapping_rules.cc | 120 | ||||
-rw-r--r-- | net/base/ip_mapping_rules.h | 90 | ||||
-rw-r--r-- | net/base/ip_mapping_rules_unittest.cc | 307 | ||||
-rw-r--r-- | net/dns/mapped_ip_resolver.cc | 69 | ||||
-rw-r--r-- | net/dns/mapped_ip_resolver.h | 76 | ||||
-rw-r--r-- | net/net.gyp | 5 |
6 files changed, 0 insertions, 667 deletions
diff --git a/net/base/ip_mapping_rules.cc b/net/base/ip_mapping_rules.cc deleted file mode 100644 index fbc887d..0000000 --- a/net/base/ip_mapping_rules.cc +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2014 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 "net/base/ip_mapping_rules.h" - -#include <vector> - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/stl_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" -#include "base/strings/string_tokenizer.h" -#include "base/strings/string_util.h" -#include "net/base/address_list.h" -#include "net/base/ip_pattern.h" - -namespace net { - -class IPMappingRules::Rule { - public: - Rule(const IPAddressNumber& address, IPPattern* pattern) - : pattern_(pattern), - replacement_address_(address) { - } - - bool Match(const IPAddressNumber& address) const { - return pattern_->Match(address); - } - - const IPAddressNumber& replacement_address() const { - return replacement_address_; - } - - private: - scoped_ptr<IPPattern> pattern_; // The pattern we can match. - IPAddressNumber replacement_address_; // The replacement address we provide. - DISALLOW_COPY_AND_ASSIGN(Rule); -}; - -IPMappingRules::IPMappingRules() {} - -IPMappingRules::~IPMappingRules() { - STLDeleteElements(&rules_); -} - -bool IPMappingRules::RewriteAddresses(AddressList* addresses) const { - // Last rule pushed into the list has the highest priority, and is tested - // first. - for (RuleList::const_reverse_iterator rule_it = rules_.rbegin(); - rule_it != rules_.rend(); ++rule_it) { - for (AddressList::iterator address_it = addresses->begin(); - address_it != addresses->end(); ++address_it) { - if (!(*rule_it)->Match(address_it->address())) - continue; - // We have a match. - int port = address_it->port(); - addresses->insert(addresses->begin(), - IPEndPoint((*rule_it)->replacement_address(), port)); - return true; - } - } - return false; -} - -bool IPMappingRules::AddRuleFromString(const std::string& rule_string) { - std::string trimmed; - base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL, &trimmed); - if (trimmed.empty()) - return true; // Allow empty rules. - - std::vector<std::string> parts; - base::SplitString(trimmed, ' ', &parts); - - if (parts.size() != 3) { - DVLOG(1) << "Rule has wrong number of parts: " << rule_string; - return false; - } - - if (!LowerCaseEqualsASCII(parts[0], "preface")) { - DVLOG(1) << "Unknown directive: " << rule_string; - return false; - } - - scoped_ptr<IPPattern> pattern(new IPPattern); - if (!pattern->ParsePattern(parts[1])) { - DVLOG(1) << "Unacceptable pattern: " << rule_string; - return false; - } - - IPAddressNumber address; - if (!ParseIPLiteralToNumber(parts[2], &address)) { - DVLOG(1) << "Invalid replacement address: " << rule_string; - return false; - } - - if (pattern->is_ipv4() != (address.size() == kIPv4AddressSize)) { - DVLOG(1) << "Mixture of IPv4 and IPv6: " << rule_string; - return false; - } - rules_.push_back(new Rule(address, pattern.release())); - return true; -} - -bool IPMappingRules::SetRulesFromString(const std::string& rules_string) { - STLDeleteElements(&rules_); - - base::StringTokenizer rules(rules_string, ";"); - while (rules.GetNext()) { - if (!AddRuleFromString(rules.token())) { - DVLOG(1) << "Failed parsing rule: " << rules.token(); - STLDeleteElements(&rules_); - return false; - } - } - return true; -} - -} // namespace net diff --git a/net/base/ip_mapping_rules.h b/net/base/ip_mapping_rules.h deleted file mode 100644 index 7291abf..0000000 --- a/net/base/ip_mapping_rules.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 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. - -#ifndef NET_BASE_IP_MAPPING_RULES_H_ -#define NET_BASE_IP_MAPPING_RULES_H_ - -#include <string> -#include <vector> - -#include "base/macros.h" -#include "net/base/net_export.h" - -namespace net { - -class AddressList; - -// This class contains a list of rules, that can be used to process (Rewrite) a -// set of DNS resolutions (IP addresses) in accordance with those rules. -// Currently the only rules supported use a pattern match against some given IP -// addresses, and may, if there is a match, place one new IP address at the -// start of the rewritten address list (re: the "PREFACE" directive). This -// supports a common use case where the matching detects an address in a given -// edge network server group, and the inserted address points to a server that -// is expected to handle all requests that would otherwise have gone to the -// given group of servers. -class NET_EXPORT_PRIVATE IPMappingRules { - public: - IPMappingRules(); - ~IPMappingRules(); - - // Modifies |*addresses| based on the current rules. Returns true if - // |addresses| was modified, false otherwise. - bool RewriteAddresses(AddressList* addresses) const; - - // Adds a rule to this mapper. - // Rules are evaluated against an address list until a first matching rule is - // found that applies, causing a modification of the address list. - // Each rule consists of one or more of the following pattern and action - // directives. - // - // RULE: CHANGE_DIRECTIVE | EMPTY - // CHANGE_DIRECTIVE: "PREFACE" SPACE IP_PATTERN SPACE IP_LITERAL - // SPACE: " " - // EMPTY: - // - // IP_LITERAL: IP_V6_LITERAL | IP_V4_LITERAL - // - // IP_V4_LITERAL: OCTET "." OCTET "." OCTET "." OCTET - // OCTET: decimal number in range 0 ... 255 - // - // IP_V6_LITERAL: HEX_COMPONENT | IP_V6_LITERAL ":" HEX_COMPONENT - // HEX_COMPONENT: hexadecimal values with no more than 4 hex digits - // - // IP_PATTERN: IP_V6_PATTERN | IP_V4_PATTERN - // - // IP_V6_PATTERN: HEX_PATTERN | IP_V6_PATTERN ":" HEX_PATTERN - // HEX_PATTERN: HEX_COMPONENT | "[" HEX_GROUP_PATTERN "]" | "*" - // HEX_GROUP_PATTERN: HEX_RANGE | HEX_GROUP_PATTERN "," HEX_RANGE - // HEX_RANGE: HEX_COMPONENT | HEX_COMPONENT "-" HEX_COMPONENT - // - // IP_V4_PATTERN: OCTET_PATTERN "." OCTET_PATTERN "." OCTET_PATTERN - // "." OCTET_PATTERN - // OCTET_PATTERN: OCTET | "[" OCTET_GROUP_PATTERN "]" | "*" - // OCTET_GROUP_PATTERN: OCTET_RANGE | OCTET_GROUP_PATTERN "," OCTET_RANGE - // OCTET_RANGE: OCTET | OCTET "-" OCTET - // - // All literals are required to have all their components specified (4 - // components for IPv4, and 8 for IPv6). Specifically, there is currently no - // support for elided compenents in an IPv6 address (e.g., "::"). - // Returns true if the rule was successfully parsed and added. - bool AddRuleFromString(const std::string& rule_string); - - // Sets the rules from a semicolon separated list of rules. - // Returns true if all the rules were successfully parsed and added. - bool SetRulesFromString(const std::string& rules_string); - - private: - class Rule; - typedef std::vector<Rule*> RuleList; - - // We own all rules in this list, and are responsible for their destruction. - RuleList rules_; - - DISALLOW_COPY_AND_ASSIGN(IPMappingRules); -}; - -} // namespace net - -#endif // NET_BASE_IP_MAPPING_RULES_H_ diff --git a/net/base/ip_mapping_rules_unittest.cc b/net/base/ip_mapping_rules_unittest.cc deleted file mode 100644 index 7fd599f..0000000 --- a/net/base/ip_mapping_rules_unittest.cc +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright 2014 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 "net/base/ip_mapping_rules.h" - -#include "net/base/address_list.h" -#include "net/base/ip_endpoint.h" -#include "net/base/net_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace net { - -namespace { - -TEST(IPMappingRulesTest, EmptyRules) { - AddressList addresses; - // Null rule does nothing to null list. - EXPECT_EQ(0u, addresses.size()); - IPMappingRules rules; - EXPECT_FALSE(rules.RewriteAddresses(&addresses)); - EXPECT_EQ(0u, addresses.size()); - - IPAddressNumber address; - EXPECT_TRUE(ParseIPLiteralToNumber("1.2.3.4", &address)); - int port = 80; - IPEndPoint endpoint(address, port); - addresses.push_back(endpoint); - // Null rule does nothing to a simple list. - ASSERT_EQ(1u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - EXPECT_FALSE(rules.RewriteAddresses(&addresses)); - ASSERT_EQ(1u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - - EXPECT_TRUE(ParseIPLiteralToNumber("1:2:3:4:a:b:c:def", &address)); - IPEndPoint endpoint2(address, port); - addresses.push_back(endpoint2); - // Null rule does nothing to a simple list. - ASSERT_EQ(2u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - EXPECT_EQ(addresses[1], endpoint2); - EXPECT_FALSE(rules.RewriteAddresses(&addresses)); - ASSERT_EQ(2u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - EXPECT_EQ(addresses[1], endpoint2); -} - -// The |inserted_ip| must have a short final component, so that we can just -// append a digit, and still be a valid (but different) ip address. -void MatchingInsertionHelper(const std::string& matchable_ip, - const std::string& matching_ip_pattern, - const std::string& inserted_ip, - bool should_match) { - AddressList addresses; - - IPAddressNumber address; - EXPECT_TRUE(ParseIPLiteralToNumber(matchable_ip, &address)); - int port = 80; - IPEndPoint endpoint(address, port); - addresses.push_back(endpoint); - // Match the string with a precisely crafted pattern. - std::string rule_text("Preface "); - rule_text += matching_ip_pattern; - rule_text += " "; - rule_text += inserted_ip; - IPMappingRules rules; - EXPECT_TRUE(rules.AddRuleFromString(rule_text)); - - ASSERT_EQ(1u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - EXPECT_EQ(should_match, rules.RewriteAddresses(&addresses)); - if (!should_match) { - ASSERT_EQ(1u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - return; // Don't bother with the rest of the test. - } - - ASSERT_EQ(2u, addresses.size()); - EXPECT_EQ(addresses[1], endpoint); - IPAddressNumber inserted_ip_adress_number; - EXPECT_TRUE(ParseIPLiteralToNumber(inserted_ip, &inserted_ip_adress_number)); - EXPECT_EQ(inserted_ip_adress_number, addresses[0].address()); - - // Now we have two addresses. We'll use new rules, to match the second - // address (the original address shifted over) in the list of addresses. - rule_text = "Preface "; // Build up a new rule. - rule_text += matching_ip_pattern; - rule_text += " "; - // Change the inserted IP mildly. - std::string different_inserted_ip = inserted_ip + "3"; - rule_text += different_inserted_ip; - // If we don't overwrite the old rule, it will fire first! - EXPECT_TRUE(rules.SetRulesFromString(rule_text)); // Overwrite old rules. - - ASSERT_EQ(2u, addresses.size()); - EXPECT_EQ(addresses[1], endpoint); - EXPECT_TRUE(rules.RewriteAddresses(&addresses)); - ASSERT_EQ(3u, addresses.size()); - EXPECT_EQ(addresses[2], endpoint); - EXPECT_TRUE(ParseIPLiteralToNumber(different_inserted_ip, - &inserted_ip_adress_number)); - EXPECT_EQ(inserted_ip_adress_number, addresses[0].address()); -} - -TEST(IPMappingRulesTest, SimpleMatchingInsertionIPV4) { - std::string matchable_ip("1.2.3.4"); - std::string matching_ip_pattern(matchable_ip); - std::string new_preface_ip("7.8.9.24"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, SimpleMatchingInsertionIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:8"); - std::string matching_ip_pattern(matchable_ip); - std::string new_preface_ip("A:B:C:D:1:2:3:4"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, SimpleMissatchingInsertionIPV4) { - std::string matchable_ip("1.2.3.4"); - std::string matching_ip_pattern(matchable_ip + "7"); - std::string new_preface_ip("7.8.9.24"); - bool should_match = false; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, SimpleMisatchingInsertionIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:8"); - std::string matching_ip_pattern(matchable_ip + "e"); - std::string new_preface_ip("A:B:C:D:1:2:3:4"); - bool should_match = false; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, AlternativeMatchingInsertionIPV4) { - std::string matchable_ip("1.2.3.4"); - std::string matching_ip_pattern("1.2.3.[2,4,6]"); - std::string new_preface_ip("7.8.9.24"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, AlternativeMatchingInsertionIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:abcd"); - std::string matching_ip_pattern("1:2:3:4:5:6:7:[abc2,abc9,abcd,cdef]"); - std::string new_preface_ip("A:B:C:D:1:2:3:4"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, RangeMatchingInsertionIPV4) { - std::string matchable_ip("1.2.3.4"); - std::string matching_ip_pattern("1.2.3.[2-6,22]"); - std::string new_preface_ip("7.8.9.24"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, RandgeMatchingInsertionIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:abcd"); - // Note: This test can detect confusion over high vs low-order bytes in an - // IPv6 component. If the code confused them, then this range would not - // include the matchable_ip. - std::string matching_ip_pattern("1:2:3:4:5:6:7:[abc2-cdc2]"); - std::string new_preface_ip("A:B:C:D:1:2:3:4"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, WildMatchingInsertionIPV4) { - std::string matchable_ip("1.2.3.4"); - std::string matching_ip_pattern("1.2.3.*"); - std::string new_preface_ip("7.8.9.24"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, WildMatchingInsertionIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:abcd"); - // Note: This test can detect confusion over high vs low-order bytes in an - // IPv6 component. If the code confused them, then this range would not - // include the matchable_ip. - std::string matching_ip_pattern("1:2:3:4:5:6:7:*"); - std::string new_preface_ip("A:B:C:D:1:2:3:4"); - bool should_match = true; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, WildNotMatchingInsertionIPV4) { - std::string matchable_ip("1.2.3.4"); - std::string matching_ip_pattern("*.200.*.*"); - std::string new_preface_ip("7.8.9.24"); - bool should_match = false; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, WildNotMatchingInsertionIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:8"); - // Note: This test can detect confusion over high vs low-order bytes in an - // IPv6 component. If the code confused them, then this range would not - // include the matchable_ip. - std::string matching_ip_pattern("*:*:37af:*:*:*:*:*"); - std::string new_preface_ip("A:B:C:D:1:2:3:4"); - bool should_match = false; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -TEST(IPMappingRulesTest, IPv4NotMatchForIPV6) { - std::string matchable_ip("1:2:3:4:5:6:7:abcd"); - // Note: This test can detect confusion over high vs low-order bytes in an - // IPv6 component. If the code confused them, then this range would not - // include the matchable_ip. - std::string matching_ip_pattern("1.2.3.4"); - std::string new_preface_ip("10.20.30.40"); // Compatible with pattern. - bool should_match = false; - MatchingInsertionHelper(matchable_ip, matching_ip_pattern, new_preface_ip, - should_match); -} - -// Parsing bad rules should silently discard the rule (and never crash). -TEST(IPMappingRulesTest, ParseInvalidRules) { - IPMappingRules rules; - - EXPECT_FALSE(rules.AddRuleFromString("Too short")); - EXPECT_FALSE(rules.AddRuleFromString("Preface much too long")); - EXPECT_FALSE(rules.AddRuleFromString("PrefaceNotSpelled 1.2.3.4 1.2.3.4")); - - // Ipv4 problems - EXPECT_FALSE(rules.AddRuleFromString("Preface 1.2.a.4 1.2.3.4")); - EXPECT_FALSE(rules.AddRuleFromString("Preface 1.2.3.4.5 1.2.3.4")); - EXPECT_FALSE(rules.AddRuleFromString("Preface 1.2.3.4 1.2.3.4.5")); - EXPECT_FALSE(rules.AddRuleFromString("Preface 1.2.3.4 1.2.3.4-5")); - EXPECT_FALSE(rules.AddRuleFromString("Preface 1.2.3.4-5-6 1.2.3.4")); - - // IPv6 problems - EXPECT_FALSE(rules.AddRuleFromString( - "Preface 1:2:3:4:5:6:7:g 1:2:3:4:5:6:7:8")); - EXPECT_FALSE(rules.AddRuleFromString( - "Preface 1:2:3:4:5:6:7:8 1:g:3:4:5:6:7:8")); - EXPECT_FALSE(rules.AddRuleFromString( - "Preface 1:2:3:4:5:6:7:8:9 1:2:3:4:5:6:7:8")); - EXPECT_FALSE(rules.AddRuleFromString( - "Preface 1:2:3:4:5:6:7:8 1:2:3:4:5:6:7:8:0")); - EXPECT_FALSE(rules.AddRuleFromString( - "Preface 1:2:3:4:5:6:7:8 1:2:3:4:5:6:7:8-A")); - EXPECT_FALSE(rules.AddRuleFromString( - "Preface 1:2:3:4:5:6:7:8-A-B 1:2:3:4:5:6:7:8")); - - // Don't mix ipv4 and ipv6. - EXPECT_FALSE(rules.AddRuleFromString("Preface 1.2.3.4 1:2:3:4:5:6:7:8")); - - EXPECT_FALSE(rules.SetRulesFromString("Preface 1.2.3.4 5.6.7.8; bad")); -} - - -TEST(IPMappingRulesTest, FirstRuleToMatch) { - std::string first_replacement("1.1.1.1"); - IPAddressNumber first_replacement_address; - EXPECT_TRUE(ParseIPLiteralToNumber(first_replacement, - &first_replacement_address)); - - std::string second_replacement("2.2.2.2"); - IPAddressNumber second_replacement_address; - EXPECT_TRUE(ParseIPLiteralToNumber(second_replacement, - &second_replacement_address)); - - IPMappingRules rules; - EXPECT_TRUE( - rules.SetRulesFromString("Preface *.*.*.* " + first_replacement + - ";Preface *.*.*.* " + second_replacement)); - - IPAddressNumber address; - EXPECT_TRUE(ParseIPLiteralToNumber("7.7.7.7", &address)); - int port = 80; - IPEndPoint endpoint(address, port); - AddressList addresses; - addresses.push_back(endpoint); - - ASSERT_EQ(1u, addresses.size()); - EXPECT_EQ(addresses[0], endpoint); - EXPECT_TRUE(rules.RewriteAddresses(&addresses)); - ASSERT_EQ(2u, addresses.size()); - EXPECT_EQ(addresses[1], endpoint); - // The last rule added to the list has the highest priority (overriding - // previous rules, and matching first). - EXPECT_NE(addresses[0].address(), first_replacement_address); - EXPECT_EQ(addresses[0].address(), second_replacement_address); -} - -} // namespace - -} // namespace net diff --git a/net/dns/mapped_ip_resolver.cc b/net/dns/mapped_ip_resolver.cc deleted file mode 100644 index 58d01a3..0000000 --- a/net/dns/mapped_ip_resolver.cc +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2014 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 "net/dns/mapped_ip_resolver.h" - -#include "base/strings/string_util.h" -#include "net/base/net_errors.h" -#include "net/base/net_util.h" - -namespace net { - -MappedIPResolver::MappedIPResolver(scoped_ptr<HostResolver> impl) - : impl_(impl.Pass()), - weak_factory_(this) { -} - -MappedIPResolver::~MappedIPResolver() {} - -int MappedIPResolver::Resolve(const RequestInfo& info, - RequestPriority priority, - AddressList* addresses, - const CompletionCallback& callback, - RequestHandle* out_req, - const BoundNetLog& net_log) { - CompletionCallback new_callback = base::Bind(&MappedIPResolver::ApplyRules, - weak_factory_.GetWeakPtr(), - callback, addresses); - int rv = impl_->Resolve(info, priority, addresses, new_callback, out_req, - net_log); - if (rv == OK) - rules_.RewriteAddresses(addresses); - return rv; -} - -int MappedIPResolver::ResolveFromCache(const RequestInfo& info, - AddressList* addresses, - const BoundNetLog& net_log) { - int rv = impl_->ResolveFromCache(info, addresses, net_log); - if (rv == OK) - rules_.RewriteAddresses(addresses); - return rv; -} - -void MappedIPResolver::CancelRequest(RequestHandle req) { - impl_->CancelRequest(req); -} - -void MappedIPResolver::SetDnsClientEnabled(bool enabled) { - impl_->SetDnsClientEnabled(enabled); -} - -HostCache* MappedIPResolver::GetHostCache() { - return impl_->GetHostCache(); -} - -base::Value* MappedIPResolver::GetDnsConfigAsValue() const { - return impl_->GetDnsConfigAsValue(); -} - -void MappedIPResolver::ApplyRules(const CompletionCallback& original_callback, - AddressList* addresses, - int rv) const { - if (rv == OK) - rules_.RewriteAddresses(addresses); - original_callback.Run(rv); -} - -} // namespace net diff --git a/net/dns/mapped_ip_resolver.h b/net/dns/mapped_ip_resolver.h deleted file mode 100644 index a3c7aa8..0000000 --- a/net/dns/mapped_ip_resolver.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2014 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. - -#ifndef NET_DNS_MAPPED_IP_RESOLVER_H_ -#define NET_DNS_MAPPED_IP_RESOLVER_H_ - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "net/base/ip_mapping_rules.h" -#include "net/base/net_export.h" -#include "net/dns/host_resolver.h" - -namespace net { - -// This class wraps an existing HostResolver instance, but modifies the -// resolution response by inserting or replacing IP addresses before returning -// it. Currently, the only directive suported is a "PREFACE" directive which -// (when a match exists) inserts a single IP address at the start of a list. -class NET_EXPORT MappedIPResolver : public HostResolver { - public: - // Creates a MappedIPResolver that forwards all of its requests through - // |impl|. - explicit MappedIPResolver(scoped_ptr<HostResolver> impl); - virtual ~MappedIPResolver(); - - // Adds a rule to our IP mapper rules_. - // The most recently added rule "has priority" and will be used first (in - // preference to) any previous rules. Once one rule is found that matches, - // no other rules will be considered. - // See ip_mapping_rules.h for syntax and semantics. - // Returns true if the rule was successfully parsed and added. - bool AddRuleFromString(const std::string& rule_string) { - return rules_.AddRuleFromString(rule_string); - } - - // Takes a semicolon separated list of rules, and assigns them to this - // resolver, discarding any previously added or set rules. - void SetRulesFromString(const std::string& rules_string) { - rules_.SetRulesFromString(rules_string); - } - - // HostResolver methods: - virtual int Resolve(const RequestInfo& info, - RequestPriority priority, - AddressList* addresses, - const CompletionCallback& callback, - RequestHandle* out_req, - const BoundNetLog& net_log) OVERRIDE; - virtual int ResolveFromCache(const RequestInfo& info, - AddressList* addresses, - const BoundNetLog& net_log) OVERRIDE; - virtual void CancelRequest(RequestHandle req) OVERRIDE; - virtual void SetDnsClientEnabled(bool enabled) OVERRIDE; - virtual HostCache* GetHostCache() OVERRIDE; - virtual base::Value* GetDnsConfigAsValue() const OVERRIDE; - - private: - // Modify the list of resolution |addresses| according to |rules_|, and then - // calls the |original_callback| with network error code |rv|. - void ApplyRules(const CompletionCallback& original_callback, - AddressList* addresses, - int rv) const; - - scoped_ptr<HostResolver> impl_; - IPMappingRules rules_; - - base::WeakPtrFactory<MappedIPResolver> weak_factory_; - DISALLOW_COPY_AND_ASSIGN(MappedIPResolver); -}; - -} // namespace net - -#endif // NET_DNS_MAPPED_IP_RESOLVER_H_ diff --git a/net/net.gyp b/net/net.gyp index 69631063..28dcd4d 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -136,8 +136,6 @@ 'base/iovec.h', 'base/ip_endpoint.cc', 'base/ip_endpoint.h', - 'base/ip_mapping_rules.cc', - 'base/ip_mapping_rules.h', 'base/ip_pattern.cc', 'base/ip_pattern.h', 'base/keygen_handler.cc', @@ -490,8 +488,6 @@ 'dns/host_resolver_proc.h', 'dns/mapped_host_resolver.cc', 'dns/mapped_host_resolver.h', - 'dns/mapped_ip_resolver.cc', - 'dns/mapped_ip_resolver.h', 'dns/mdns_cache.cc', 'dns/mdns_cache.h', 'dns/mdns_client.cc', @@ -1706,7 +1702,6 @@ 'base/host_mapping_rules_unittest.cc', 'base/host_port_pair_unittest.cc', 'base/ip_endpoint_unittest.cc', - 'base/ip_mapping_rules_unittest.cc', 'base/ip_pattern_unittest.cc', 'base/keygen_handler_unittest.cc', 'base/mime_sniffer_unittest.cc', |