blob: 6a2ccb13728e3154a7a67a8c1ccc4d3c7790079e [file] [log] [blame]
Paul Stewartbf667612012-06-29 14:49:54 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewartb6063942011-08-05 10:17:29 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_RESOLVER_
6#define SHILL_RESOLVER_
7
Hristo Stefanoved2c28c2011-11-29 15:37:30 -08008#include <string>
9#include <vector>
10
Paul Stewartb6063942011-08-05 10:17:29 -070011#include <base/file_path.h>
Paul Stewart0d2ada32011-08-09 17:01:57 -070012#include <base/lazy_instance.h>
Paul Stewartb6063942011-08-05 10:17:29 -070013#include <base/memory/ref_counted.h>
Paul Stewartb6063942011-08-05 10:17:29 -070014
15#include "shill/refptr_types.h"
16
17namespace shill {
18
19// This provides a static function for dumping the DNS information out
20// of an ipconfig into a "resolv.conf" formatted file.
21class Resolver {
22 public:
Paul Stewartbf667612012-06-29 14:49:54 -070023 enum TimeoutParameters {
24 kDefaultTimeout,
25 kShortTimeout
26 };
27
Paul Stewart4d5efb72012-09-17 12:24:34 -070028 // The default comma-separated list of search-list prefixes that
29 // should be ignored when writing out a DNS configuration. These
30 // are usually preconfigured by a DHCP server and are not of real
31 // value to the user. This will release DNS bandwidth for searches
32 // we expect will have a better chance of getting what the user is
33 // looking for.
34 static const char kDefaultIgnoredSearchList[];
35
Paul Stewartbf667612012-06-29 14:49:54 -070036 // The default comma-separated list of technologies for which short
37 // DNS timeouts should be enabled.
38 static const char kDefaultShortTimeoutTechnologies[];
39
Paul Stewart0d2ada32011-08-09 17:01:57 -070040 virtual ~Resolver();
41
Paul Stewartb6063942011-08-05 10:17:29 -070042 // Since this is a singleton, use Resolver::GetInstance()->Foo()
43 static Resolver *GetInstance();
44
Paul Stewartdd60e452011-08-08 11:38:36 -070045 virtual void set_path(const FilePath &path) { path_ = path; }
Paul Stewartb6063942011-08-05 10:17:29 -070046
Paul Stewart6f65c0b2012-09-11 14:57:32 -070047 // Install domain name service parameters, given a list of
48 // DNS servers in |dns_servers|, a list of DNS search suffixes in
49 // |domain_search| and a DNS timeout parameter in |timeout|.
Paul Stewartdd60e452011-08-08 11:38:36 -070050 virtual bool SetDNSFromLists(const std::vector<std::string> &dns_servers,
Paul Stewartbf667612012-06-29 14:49:54 -070051 const std::vector<std::string> &domain_search,
52 TimeoutParameters timeout);
Paul Stewartb6063942011-08-05 10:17:29 -070053
Paul Stewartbf667612012-06-29 14:49:54 -070054 // Remove any created domain name service file.
Paul Stewartdd60e452011-08-08 11:38:36 -070055 virtual bool ClearDNS();
Paul Stewartb6063942011-08-05 10:17:29 -070056
Paul Stewart4d5efb72012-09-17 12:24:34 -070057 // Sets the list of ignored DNS search suffixes. This list will be used
58 // to filter the domain_search parameter of later SetDNSFromLists() calls.
59 virtual void set_ignored_search_list(
60 const std::vector<std::string> &ignored_list) {
61 ignored_search_list_ = ignored_list;
62 }
63
Paul Stewart0d2ada32011-08-09 17:01:57 -070064 protected:
Paul Stewartb6063942011-08-05 10:17:29 -070065 Resolver();
Paul Stewart0d2ada32011-08-09 17:01:57 -070066
67 private:
68 friend struct base::DefaultLazyInstanceTraits<Resolver>;
69 friend class ResolverTest;
Paul Stewartb6063942011-08-05 10:17:29 -070070
Paul Stewartbf667612012-06-29 14:49:54 -070071 static const char kDefaultTimeoutOptions[];
72 static const char kShortTimeoutOptions[];
73
Paul Stewartb6063942011-08-05 10:17:29 -070074 FilePath path_;
Paul Stewart4d5efb72012-09-17 12:24:34 -070075 std::vector<std::string> ignored_search_list_;
Paul Stewartb6063942011-08-05 10:17:29 -070076
77 DISALLOW_COPY_AND_ASSIGN(Resolver);
78};
79
80} // namespace shill
81
82#endif // SHILL_RESOLVER_