#include "net/dns/dns_response.h"
#include <algorithm>
#include <cstdint>
#include <limits>
#include <numeric>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include "base/big_endian.h"
#include "base/containers/span.h"
#include "base/containers/span_reader.h"
#include "base/containers/span_writer.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h"
#include "base/sys_byteorder.h"
#include "base/types/optional_util.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/dns/dns_names_util.h"
#include "net/dns/dns_query.h"
#include "net/dns/dns_response_result_extractor.h"
#include "net/dns/dns_util.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/record_rdata.h"
namespace net {
namespace {
const size_t kHeaderSize = …;
const uint8_t kRcodeMask = …;
}
DnsResourceRecord::DnsResourceRecord() = default;
DnsResourceRecord::DnsResourceRecord(const DnsResourceRecord& other)
: … { … }
DnsResourceRecord::DnsResourceRecord(DnsResourceRecord&& other)
: … { … }
DnsResourceRecord::~DnsResourceRecord() = default;
DnsResourceRecord& DnsResourceRecord::operator=(
const DnsResourceRecord& other) { … }
DnsResourceRecord& DnsResourceRecord::operator=(DnsResourceRecord&& other) { … }
void DnsResourceRecord::SetOwnedRdata(std::string value) { … }
size_t DnsResourceRecord::CalculateRecordSize() const { … }
DnsRecordParser::DnsRecordParser() = default;
DnsRecordParser::~DnsRecordParser() = default;
DnsRecordParser::DnsRecordParser(const DnsRecordParser&) = default;
DnsRecordParser::DnsRecordParser(DnsRecordParser&&) = default;
DnsRecordParser& DnsRecordParser::operator=(const DnsRecordParser&) = default;
DnsRecordParser& DnsRecordParser::operator=(DnsRecordParser&&) = default;
DnsRecordParser::DnsRecordParser(base::span<const uint8_t> packet,
size_t offset,
size_t num_records)
: … { … }
unsigned DnsRecordParser::ReadName(const void* const vpos,
std::string* out) const { … }
bool DnsRecordParser::ReadRecord(DnsResourceRecord* out) { … }
bool DnsRecordParser::ReadQuestion(std::string& out_dotted_qname,
uint16_t& out_qtype) { … }
DnsResponse::DnsResponse(
uint16_t id,
bool is_authoritative,
const std::vector<DnsResourceRecord>& answers,
const std::vector<DnsResourceRecord>& authority_records,
const std::vector<DnsResourceRecord>& additional_records,
const std::optional<DnsQuery>& query,
uint8_t rcode,
bool validate_records,
bool validate_names_as_internet_hostnames) { … }
DnsResponse::DnsResponse()
: … { … }
DnsResponse::DnsResponse(scoped_refptr<IOBuffer> buffer, size_t size)
: … { … }
DnsResponse::DnsResponse(size_t length)
: … { … }
DnsResponse::DnsResponse(base::span<const uint8_t> data, size_t answer_offset)
: … { … }
DnsResponse DnsResponse::CreateEmptyNoDataResponse(
uint16_t id,
bool is_authoritative,
base::span<const uint8_t> qname,
uint16_t qtype) { … }
DnsResponse::DnsResponse(DnsResponse&& other) = default;
DnsResponse& DnsResponse::operator=(DnsResponse&& other) = default;
DnsResponse::~DnsResponse() = default;
bool DnsResponse::InitParse(size_t nbytes, const DnsQuery& query) { … }
bool DnsResponse::InitParseWithoutQuery(size_t nbytes) { … }
std::optional<uint16_t> DnsResponse::id() const { … }
bool DnsResponse::IsValid() const { … }
uint16_t DnsResponse::flags() const { … }
uint8_t DnsResponse::rcode() const { … }
unsigned DnsResponse::question_count() const { … }
unsigned DnsResponse::answer_count() const { … }
unsigned DnsResponse::authority_count() const { … }
unsigned DnsResponse::additional_answer_count() const { … }
uint16_t DnsResponse::GetSingleQType() const { … }
std::string_view DnsResponse::GetSingleDottedName() const { … }
DnsRecordParser DnsResponse::Parser() const { … }
const dns_protocol::Header* DnsResponse::header() const { … }
bool DnsResponse::WriteHeader(base::SpanWriter<uint8_t>* writer,
const dns_protocol::Header& header) { … }
bool DnsResponse::WriteQuestion(base::SpanWriter<uint8_t>* writer,
const DnsQuery& query) { … }
bool DnsResponse::WriteRecord(base::SpanWriter<uint8_t>* writer,
const DnsResourceRecord& record,
bool validate_record,
bool validate_name_as_internet_hostname) { … }
bool DnsResponse::WriteAnswer(base::SpanWriter<uint8_t>* writer,
const DnsResourceRecord& answer,
const std::optional<DnsQuery>& query,
bool validate_record,
bool validate_name_as_internet_hostname) { … }
}