summaryrefslogtreecommitdiff
path: root/chromium/net/dns/dns_config_overrides.h
blob: e09a6ee82fd1c2cda4ecaf0dacf8eb5981d4f38d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2018 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_DNS_CONFIG_OVERRIDES_H_
#define NET_DNS_DNS_CONFIG_OVERRIDES_H_

#include <string>
#include <vector>

#include "base/optional.h"
#include "base/time/time.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_export.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_hosts.h"
#include "net/dns/public/dns_over_https_server_config.h"

namespace net {

// Overriding values to be applied over a DnsConfig struct.
struct NET_EXPORT DnsConfigOverrides {
  DnsConfigOverrides();
  DnsConfigOverrides(const DnsConfigOverrides& other);
  DnsConfigOverrides(DnsConfigOverrides&& other);
  ~DnsConfigOverrides();

  DnsConfigOverrides& operator=(const DnsConfigOverrides& other);
  DnsConfigOverrides& operator=(DnsConfigOverrides&& other);

  bool operator==(const DnsConfigOverrides& other) const;
  bool operator!=(const DnsConfigOverrides& other) const;

  // Creation method that initializes all values with the defaults from
  // DnsConfig. Guarantees the result of OverridesEverything() will be |true|.
  static DnsConfigOverrides CreateOverridingEverythingWithDefaults();

  // Creates a new DnsConfig where any field with an overriding value in |this|
  // is replaced with that overriding value. Any field without an overriding
  // value (|base::nullopt|) will be copied as-is from |config|.
  DnsConfig ApplyOverrides(const DnsConfig& config) const;

  // Returns |true| if the overriding configuration is comprehensive and would
  // override everything in a base DnsConfig. This is the case if all Optional
  // fields have a value.
  bool OverridesEverything() const;

  // Overriding values. See same-named fields in DnsConfig for explanations.
  base::Optional<std::vector<IPEndPoint>> nameservers;
  base::Optional<std::vector<std::string>> search;
  base::Optional<DnsHosts> hosts;
  base::Optional<bool> append_to_multi_label_name;
  base::Optional<bool> randomize_ports;
  base::Optional<int> ndots;
  base::Optional<base::TimeDelta> timeout;
  base::Optional<int> attempts;
  base::Optional<int> doh_attempts;
  base::Optional<bool> rotate;
  base::Optional<bool> use_local_ipv6;
  base::Optional<std::vector<DnsOverHttpsServerConfig>> dns_over_https_servers;
  base::Optional<DnsConfig::SecureDnsMode> secure_dns_mode;
  base::Optional<bool> allow_dns_over_https_upgrade;
  base::Optional<std::vector<std::string>> disabled_upgrade_providers;

  // Note no overriding value for |unhandled_options|. It is meta-configuration,
  // and there should be no reason to override it.
};

}  // namespace net

#endif  // NET_DNS_DNS_CONFIG_OVERRIDES_H_