OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef NET_DNS_FUZZED_HOST_RESOLVER_ | 5 #ifndef NET_DNS_FUZZED_HOST_RESOLVER_ |
6 #define NET_DNS_FUZZED_HOST_RESOLVER_ | 6 #define NET_DNS_FUZZED_HOST_RESOLVER_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "net/base/address_family.h" | 14 #include "net/base/address_family.h" |
15 #include "net/dns/host_resolver.h" | 15 #include "net/dns/host_resolver.h" |
16 #include "net/dns/host_resolver_impl.h" | 16 #include "net/dns/host_resolver_impl.h" |
17 #include "net/socket/fuzzed_socket_factory.h" | 17 #include "net/socket/fuzzed_socket_factory.h" |
18 | 18 |
| 19 namespace base { |
| 20 class FuzzedDataProvider; |
| 21 } |
| 22 |
19 namespace net { | 23 namespace net { |
20 | 24 |
21 class AddressList; | 25 class AddressList; |
22 class ClientSocketFactory; | 26 class ClientSocketFactory; |
23 class DnsClient; | 27 class DnsClient; |
24 class NetLog; | 28 class NetLog; |
25 class ScopedDefaultHostResolverProc; | 29 class ScopedDefaultHostResolverProc; |
26 | 30 |
27 // HostResolver that uses a fuzzer to determine what results to return. It | 31 // HostResolver that uses a fuzzer to determine what results to return. It |
28 // inherits from HostResolverImpl, unlike MockHostResolver, so more closely | 32 // inherits from HostResolverImpl, unlike MockHostResolver, so more closely |
(...skipping 10 matching lines...) Expand all Loading... |
39 // Note that it does not attempt to sort the resulting AddressList when using | 43 // Note that it does not attempt to sort the resulting AddressList when using |
40 // the mock system resolver path. | 44 // the mock system resolver path. |
41 // | 45 // |
42 // The async DNS client can make system calls in AddressSorterPosix, but other | 46 // The async DNS client can make system calls in AddressSorterPosix, but other |
43 // methods that make system calls are stubbed out. | 47 // methods that make system calls are stubbed out. |
44 class FuzzedHostResolver : public HostResolverImpl { | 48 class FuzzedHostResolver : public HostResolverImpl { |
45 public: | 49 public: |
46 // |data_provider| and |net_log| must outlive the FuzzedHostResolver. | 50 // |data_provider| and |net_log| must outlive the FuzzedHostResolver. |
47 FuzzedHostResolver(const Options& options, | 51 FuzzedHostResolver(const Options& options, |
48 NetLog* net_log, | 52 NetLog* net_log, |
49 FuzzedDataProvider* data_provider); | 53 base::FuzzedDataProvider* data_provider); |
50 ~FuzzedHostResolver() override; | 54 ~FuzzedHostResolver() override; |
51 | 55 |
52 // Enable / disable the async resolver. When enabled, installs a | 56 // Enable / disable the async resolver. When enabled, installs a |
53 // DnsClient with fuzzed UDP and TCP sockets. Overrides | 57 // DnsClient with fuzzed UDP and TCP sockets. Overrides |
54 // HostResolverImpl method of the same name. | 58 // HostResolverImpl method of the same name. |
55 void SetDnsClientEnabled(bool enabled) override; | 59 void SetDnsClientEnabled(bool enabled) override; |
56 | 60 |
57 private: | 61 private: |
58 // HostResolverImpl implementation: | 62 // HostResolverImpl implementation: |
59 bool IsIPv6Reachable(const BoundNetLog& net_log) override; | 63 bool IsIPv6Reachable(const BoundNetLog& net_log) override; |
60 void RunLoopbackProbeJob() override; | 64 void RunLoopbackProbeJob() override; |
61 | 65 |
62 FuzzedDataProvider* data_provider_; | 66 base::FuzzedDataProvider* data_provider_; |
63 | 67 |
64 // Used for UDP and TCP sockets if the async resolver is enabled. | 68 // Used for UDP and TCP sockets if the async resolver is enabled. |
65 FuzzedSocketFactory socket_factory_; | 69 FuzzedSocketFactory socket_factory_; |
66 | 70 |
67 // Fixed value to be returned by IsIPv6Reachable. | 71 // Fixed value to be returned by IsIPv6Reachable. |
68 const bool is_ipv6_reachable_; | 72 const bool is_ipv6_reachable_; |
69 | 73 |
70 NetLog* net_log_; | 74 NetLog* net_log_; |
71 | 75 |
72 base::WeakPtrFactory<FuzzedDataProvider> data_provider_weak_factory_; | 76 base::WeakPtrFactory<base::FuzzedDataProvider> data_provider_weak_factory_; |
73 | 77 |
74 DISALLOW_COPY_AND_ASSIGN(FuzzedHostResolver); | 78 DISALLOW_COPY_AND_ASSIGN(FuzzedHostResolver); |
75 }; | 79 }; |
76 | 80 |
77 } // namespace net | 81 } // namespace net |
78 | 82 |
79 #endif // NET_DNS_FUZZED_HOST_RESOLVER_ | 83 #endif // NET_DNS_FUZZED_HOST_RESOLVER_ |
OLD | NEW |