blob: 2b1123b49fb9d6881b47cc8724ebac9802a5e0b0 [file] [log] [blame]
// Copyright 2020 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.
#include <stdint.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/optional.h"
#include "base/strings/string_piece.h"
#include "net/base/ip_address.h"
#include "net/base/net_export.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/record_rdata.h"
namespace net {
class AliasFormHttpsRecordRdata;
class ServiceFormHttpsRecordRdata;
class NET_EXPORT_PRIVATE HttpsRecordRdata : public RecordRdata {
static const uint16_t kType = dns_protocol::kTypeHttps;
static std::unique_ptr<HttpsRecordRdata> Parse(base::StringPiece data);
HttpsRecordRdata(const HttpsRecordRdata& rdata) = delete;
HttpsRecordRdata& operator=(const HttpsRecordRdata& rdata) = delete;
~HttpsRecordRdata() override;
bool IsEqual(const RecordRdata* other) const override;
virtual bool IsEqual(const HttpsRecordRdata* other) const = 0;
uint16_t Type() const override;
virtual bool IsAlias() const = 0;
AliasFormHttpsRecordRdata* AsAliasForm();
const AliasFormHttpsRecordRdata* AsAliasForm() const;
ServiceFormHttpsRecordRdata* AsServiceForm();
const ServiceFormHttpsRecordRdata* AsServiceForm() const;
// For experimental query metrics.
// TODO( Remove as HTTPS use becomes non-experimental.
virtual bool IsMalformed() const;
HttpsRecordRdata() = default;
// For experimental query metrics.
// TODO( Remove as HTTPS use becomes non-experimental.
class NET_EXPORT_PRIVATE MalformedHttpsRecordRdata : public HttpsRecordRdata {
bool IsEqual(const HttpsRecordRdata* other) const override;
bool IsAlias() const override;
bool IsMalformed() const override;
class NET_EXPORT_PRIVATE AliasFormHttpsRecordRdata : public HttpsRecordRdata {
explicit AliasFormHttpsRecordRdata(std::string alias_name);
static std::unique_ptr<AliasFormHttpsRecordRdata> Parse(
base::StringPiece data);
bool IsEqual(const HttpsRecordRdata* other) const override;
bool IsAlias() const override;
base::StringPiece alias_name() const { return alias_name_; }
AliasFormHttpsRecordRdata() = default;
const std::string alias_name_;
class NET_EXPORT_PRIVATE ServiceFormHttpsRecordRdata : public HttpsRecordRdata {
static constexpr uint16_t kSupportedKeys[] = {
ServiceFormHttpsRecordRdata(uint16_t priority,
std::string service_name,
std::set<uint16_t> mandatory_keys,
std::vector<std::string> alpn_ids,
bool default_alpn,
base::Optional<uint16_t> port,
std::vector<IPAddress> ipv4_hint,
std::string ech_config,
std::vector<IPAddress> ipv6_hint,
std::map<uint16_t, std::string> unparsed_params);
static std::unique_ptr<ServiceFormHttpsRecordRdata> Parse(
base::StringPiece data);
~ServiceFormHttpsRecordRdata() override;
bool IsEqual(const HttpsRecordRdata* other) const override;
bool IsAlias() const override;
uint16_t priority() const { return priority_; }
base::StringPiece service_name() const { return service_name_; }
const std::set<uint16_t>& mandatory_keys() const { return mandatory_keys_; }
const std::vector<std::string>& alpn_ids() const { return alpn_ids_; }
bool default_alpn() const { return default_alpn_; }
base::Optional<uint16_t> port() const { return port_; }
const std::vector<IPAddress>& ipv4_hint() const { return ipv4_hint_; }
base::StringPiece ech_config() const { return ech_config_; }
const std::vector<IPAddress>& ipv6_hint() const { return ipv6_hint_; }
const std::map<uint16_t, std::string>& unparsed_params() const {
return unparsed_params_;
// Returns whether or not this rdata parser is considered "compatible" with
// the parsed rdata. That is that all keys listed by mandatory_keys() (and all
// keys considered default mandatory for HTTPS records) are parsable by this
// parser.
bool IsCompatible() const;
static bool IsSupportedKey(uint16_t key);
const uint16_t priority_;
const std::string service_name_;
// Supported service parameters.
const std::set<uint16_t> mandatory_keys_;
const std::vector<std::string> alpn_ids_;
const bool default_alpn_;
const base::Optional<uint16_t> port_;
const std::vector<IPAddress> ipv4_hint_;
const std::string ech_config_;
const std::vector<IPAddress> ipv6_hint_;
const std::map<uint16_t, std::string> unparsed_params_;
} // namespace net