OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_DNS_FUZZED_HOST_RESOLVER_ |
| 6 #define NET_DNS_FUZZED_HOST_RESOLVER_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "net/base/address_family.h" |
| 15 #include "net/dns/host_resolver.h" |
| 16 #include "net/dns/host_resolver_impl.h" |
| 17 #include "net/socket/fuzzed_socket_factory.h" |
| 18 |
| 19 namespace net { |
| 20 |
| 21 class AddressList; |
| 22 class ClientSocketFactory; |
| 23 class DnsClient; |
| 24 class NetLog; |
| 25 class ScopedDefaultHostResolverProc; |
| 26 |
| 27 // HostResolver that uses a fuzzer to determine what results to return. It |
| 28 // inherits from HostResolverImpl, unlike MockHostResolver, so more closely |
| 29 // matches real behavior. |
| 30 // |
| 31 // By default uses a mocked out system resolver, though can be configured to |
| 32 // use the built-in async resolver (Built in DNS stub resolver) with a fuzzed |
| 33 // set of UDP/TCP sockets. |
| 34 // |
| 35 // To make behavior most deterministic, does not use the WorkerPool to run its |
| 36 // simulated platform host resolver calls, instead runs them on the thread it is |
| 37 // created on. |
| 38 // |
| 39 // Note that it does not attempt to sort the resulting AddressList when using |
| 40 // the mock system resolver path. |
| 41 // |
| 42 // The async DNS client can make system calls in AddressSorterPosix, but other |
| 43 // methods that make system calls are stubbed out. |
| 44 class FuzzedHostResolver : public HostResolverImpl { |
| 45 public: |
| 46 // |data_provider| and |net_log| must outlive the FuzzedHostResolver. |
| 47 FuzzedHostResolver(const Options& options, |
| 48 NetLog* net_log, |
| 49 FuzzedDataProvider* data_provider); |
| 50 ~FuzzedHostResolver() override; |
| 51 |
| 52 // Enable / disable the async resolver. When enabled, installs a |
| 53 // DnsClient with fuzzed UDP and TCP sockets. Overrides |
| 54 // HostResolverImpl method of the same name. |
| 55 void SetDnsClientEnabled(bool enabled) override; |
| 56 |
| 57 private: |
| 58 // HostResolverImpl implementation: |
| 59 bool IsIPv6Reachable(const BoundNetLog& net_log) override; |
| 60 void RunLoopbackProbeJob() override; |
| 61 |
| 62 FuzzedDataProvider* data_provider_; |
| 63 |
| 64 // Used for UDP and TCP sockets if the async resolver is enabled. |
| 65 FuzzedSocketFactory socket_factory_; |
| 66 |
| 67 // Fixed value to be returned by IsIPv6Reachable. |
| 68 const bool is_ipv6_reachable_; |
| 69 |
| 70 NetLog* net_log_; |
| 71 |
| 72 base::WeakPtrFactory<FuzzedDataProvider> data_provider_weak_factory_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(FuzzedHostResolver); |
| 75 }; |
| 76 |
| 77 } // namespace net |
| 78 |
| 79 #endif // NET_DNS_FUZZED_HOST_RESOLVER_ |
OLD | NEW |