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/dns_config_service.h" | 5 #include "net/dns/dns_config_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Check if particular nameserver address is rogue. See: | 16 // Check if particular nameserver address is rogue. See: |
17 // http://www.fbi.gov/news/stories/2011/november/malware_110911/DNS-changer-malw
are.pdf | 17 // http://www.fbi.gov/news/stories/2011/november/malware_110911/DNS-changer-malw
are.pdf |
18 bool CheckRogueDnsAddress(const IPAddressNumber& address) { | 18 bool CheckRogueDnsAddress(const IPAddressNumber& address) { |
| 19 #define U8(x) static_cast<unsigned char>(x) |
19 const struct Bounds { | 20 const struct Bounds { |
20 const unsigned char lower[4]; // inclusive | 21 const unsigned char lower[4]; // inclusive |
21 const unsigned char upper[4]; // exclusive | 22 const unsigned char upper[4]; // exclusive |
22 } cases[] = { | 23 } cases[] = { |
23 { { '\x55', '\xFF', '\x70', '\x00' }, // 85.255.112.0 | 24 { { U8('\x55'), U8('\xFF'), U8('\x70'), U8('\x00') }, // 85.255.112.0 |
24 { '\x55', '\xFF', '\x80', '\x00' } }, // 85.255.128.0 | 25 { U8('\x55'), U8('\xFF'), U8('\x80'), U8('\x00') } }, // 85.255.128.0 |
25 { { '\x43', '\xD2', '\x00', '\x00' }, // 67.210.0.0 | 26 { { U8('\x43'), U8('\xD2'), U8('\x00'), U8('\x00') }, // 67.210.0.0 |
26 { '\x43', '\xD2', '\x10', '\x00' } }, // 67.210.16.0 | 27 { U8('\x43'), U8('\xD2'), U8('\x10'), U8('\x00') } }, // 67.210.16.0 |
27 { { '\x5D', '\xBC', '\xA0', '\x00' }, // 93.188.160.0 | 28 { { U8('\x5D'), U8('\xBC'), U8('\xA0'), U8('\x00') }, // 93.188.160.0 |
28 { '\x5D', '\xBC', '\xA8', '\x00' } }, // 93.188.168.0 | 29 { U8('\x5D'), U8('\xBC'), U8('\xA8'), U8('\x00') } }, // 93.188.168.0 |
29 { { '\x4D', '\x43', '\x53', '\x00' }, // 77.67.83.0 | 30 { { U8('\x4D'), U8('\x43'), U8('\x53'), U8('\x00') }, // 77.67.83.0 |
30 { '\x4D', '\x43', '\x54', '\x00' } }, // 77.67.84.0 | 31 { U8('\x4D'), U8('\x43'), U8('\x54'), U8('\x00') } }, // 77.67.84.0 |
31 { { '\x40', '\x1C', '\xB2', '\x00' }, // 64.28.178.0 | 32 { { U8('\x40'), U8('\x1C'), U8('\xB2'), U8('\x00') }, // 64.28.178.0 |
32 { '\x40', '\x1C', '\xC0', '\x00' } }, // 64.28.192.0 | 33 { U8('\x40'), U8('\x1C'), U8('\xC0'), U8('\x00') } }, // 64.28.192.0 |
33 }; | 34 }; |
| 35 #undef U8 |
34 for (unsigned i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 36 for (unsigned i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
35 const Bounds& bounds = cases[i]; | 37 const Bounds& bounds = cases[i]; |
36 IPAddressNumber lower(bounds.lower, bounds.lower + 4); | 38 IPAddressNumber lower(bounds.lower, bounds.lower + 4); |
37 IPAddressNumber upper(bounds.upper, bounds.upper + 4); | 39 IPAddressNumber upper(bounds.upper, bounds.upper + 4); |
38 if (address.size() == kIPv6AddressSize) { | 40 if (address.size() == kIPv6AddressSize) { |
39 lower = ConvertIPv4NumberToIPv6Number(lower); | 41 lower = ConvertIPv4NumberToIPv6Number(lower); |
40 upper = ConvertIPv4NumberToIPv6Number(upper); | 42 upper = ConvertIPv4NumberToIPv6Number(upper); |
41 } | 43 } |
42 if ((lower <= address) && (address < upper)) | 44 if ((lower <= address) && (address < upper)) |
43 return true; | 45 return true; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 CheckRogueDnsConfig(dns_config_); | 266 CheckRogueDnsConfig(dns_config_); |
265 checked_rogue_dns_ = true; | 267 checked_rogue_dns_ = true; |
266 } | 268 } |
267 need_update_ = false; | 269 need_update_ = false; |
268 last_sent_empty_ = false; | 270 last_sent_empty_ = false; |
269 callback_.Run(dns_config_); | 271 callback_.Run(dns_config_); |
270 } | 272 } |
271 | 273 |
272 } // namespace net | 274 } // namespace net |
273 | 275 |
OLD | NEW |