blob: d2ca587c5e7811ebb72ab8fce6db6f1c854acc90 [file] [log] [blame]
[email protected]4e09d242013-05-02 03:19:351// Copyright (c) 2013 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_RECORD_RDATA_H_
6#define NET_DNS_RECORD_RDATA_H_
7
Avi Drissman13fc8932015-12-20 04:40:468#include <stdint.h>
9
danakj22f90e72016-04-16 01:55:4010#include <memory>
[email protected]4e09d242013-05-02 03:19:3511#include <string>
12#include <vector>
13
[email protected]4e09d242013-05-02 03:19:3514#include "base/compiler_specific.h"
Avi Drissman13fc8932015-12-20 04:40:4615#include "base/macros.h"
[email protected]4e09d242013-05-02 03:19:3516#include "base/strings/string_piece.h"
martijna23c8962016-03-04 18:18:5117#include "net/base/ip_address.h"
[email protected]4e09d242013-05-02 03:19:3518#include "net/base/net_export.h"
[email protected]4e09d242013-05-02 03:19:3519#include "net/dns/dns_protocol.h"
20
21namespace net {
22
23class DnsRecordParser;
24
25// Parsed represenation of the extra data in a record. Does not include standard
26// DNS record data such as TTL, Name, Type and Class.
27class NET_EXPORT_PRIVATE RecordRdata {
28 public:
29 virtual ~RecordRdata() {}
30
[email protected]f6a9add2013-05-23 00:56:3631 virtual bool IsEqual(const RecordRdata* other) const = 0;
Avi Drissman13fc8932015-12-20 04:40:4632 virtual uint16_t Type() const = 0;
[email protected]f6a9add2013-05-23 00:56:3633
[email protected]4e09d242013-05-02 03:19:3534 protected:
35 RecordRdata();
36
37 DISALLOW_COPY_AND_ASSIGN(RecordRdata);
38};
39
40// SRV record format (http://www.ietf.org/rfc/rfc2782.txt):
41// 2 bytes network-order unsigned priority
42// 2 bytes network-order unsigned weight
43// 2 bytes network-order unsigned port
44// target: domain name (on-the-wire representation)
45class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata {
46 public:
Avi Drissman13fc8932015-12-20 04:40:4647 static const uint16_t kType = dns_protocol::kTypeSRV;
[email protected]4e09d242013-05-02 03:19:3548
dcheng67be2b1f2014-10-27 21:47:2949 ~SrvRecordRdata() override;
danakj22f90e72016-04-16 01:55:4050 static std::unique_ptr<SrvRecordRdata> Create(const base::StringPiece& data,
51 const DnsRecordParser& parser);
[email protected]4e09d242013-05-02 03:19:3552
dcheng67be2b1f2014-10-27 21:47:2953 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:4654 uint16_t Type() const override;
[email protected]f6a9add2013-05-23 00:56:3655
Avi Drissman13fc8932015-12-20 04:40:4656 uint16_t priority() const { return priority_; }
57 uint16_t weight() const { return weight_; }
58 uint16_t port() const { return port_; }
[email protected]4e09d242013-05-02 03:19:3559
60 const std::string& target() const { return target_; }
61
62 private:
63 SrvRecordRdata();
64
Avi Drissman13fc8932015-12-20 04:40:4665 uint16_t priority_;
66 uint16_t weight_;
67 uint16_t port_;
[email protected]4e09d242013-05-02 03:19:3568
69 std::string target_;
70
71 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata);
72};
73
74// A Record format (http://www.ietf.org/rfc/rfc1035.txt):
75// 4 bytes for IP address.
76class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata {
77 public:
Avi Drissman13fc8932015-12-20 04:40:4678 static const uint16_t kType = dns_protocol::kTypeA;
[email protected]4e09d242013-05-02 03:19:3579
dcheng67be2b1f2014-10-27 21:47:2980 ~ARecordRdata() override;
danakj22f90e72016-04-16 01:55:4081 static std::unique_ptr<ARecordRdata> Create(const base::StringPiece& data,
82 const DnsRecordParser& parser);
dcheng67be2b1f2014-10-27 21:47:2983 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:4684 uint16_t Type() const override;
[email protected]4e09d242013-05-02 03:19:3585
martijna23c8962016-03-04 18:18:5186 const IPAddress& address() const { return address_; }
[email protected]4e09d242013-05-02 03:19:3587
88 private:
89 ARecordRdata();
90
martijna23c8962016-03-04 18:18:5191 IPAddress address_;
[email protected]4e09d242013-05-02 03:19:3592
93 DISALLOW_COPY_AND_ASSIGN(ARecordRdata);
94};
95
[email protected]f6a9add2013-05-23 00:56:3696// AAAA Record format (http://www.ietf.org/rfc/rfc1035.txt):
97// 16 bytes for IP address.
98class NET_EXPORT_PRIVATE AAAARecordRdata : public RecordRdata {
99 public:
Avi Drissman13fc8932015-12-20 04:40:46100 static const uint16_t kType = dns_protocol::kTypeAAAA;
[email protected]f6a9add2013-05-23 00:56:36101
dcheng67be2b1f2014-10-27 21:47:29102 ~AAAARecordRdata() override;
danakj22f90e72016-04-16 01:55:40103 static std::unique_ptr<AAAARecordRdata> Create(const base::StringPiece& data,
104 const DnsRecordParser& parser);
dcheng67be2b1f2014-10-27 21:47:29105 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:46106 uint16_t Type() const override;
[email protected]f6a9add2013-05-23 00:56:36107
martijna23c8962016-03-04 18:18:51108 const IPAddress& address() const { return address_; }
[email protected]f6a9add2013-05-23 00:56:36109
110 private:
111 AAAARecordRdata();
112
martijna23c8962016-03-04 18:18:51113 IPAddress address_;
[email protected]f6a9add2013-05-23 00:56:36114
115 DISALLOW_COPY_AND_ASSIGN(AAAARecordRdata);
116};
117
[email protected]4e09d242013-05-02 03:19:35118// CNAME record format (http://www.ietf.org/rfc/rfc1035.txt):
119// cname: On the wire representation of domain name.
120class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata {
121 public:
Avi Drissman13fc8932015-12-20 04:40:46122 static const uint16_t kType = dns_protocol::kTypeCNAME;
[email protected]4e09d242013-05-02 03:19:35123
dcheng67be2b1f2014-10-27 21:47:29124 ~CnameRecordRdata() override;
danakj22f90e72016-04-16 01:55:40125 static std::unique_ptr<CnameRecordRdata> Create(
126 const base::StringPiece& data,
127 const DnsRecordParser& parser);
dcheng67be2b1f2014-10-27 21:47:29128 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:46129 uint16_t Type() const override;
[email protected]4e09d242013-05-02 03:19:35130
131 std::string cname() const { return cname_; }
132
133 private:
134 CnameRecordRdata();
135
136 std::string cname_;
137
138 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata);
139};
140
141// PTR record format (http://www.ietf.org/rfc/rfc1035.txt):
142// domain: On the wire representation of domain name.
143class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata {
144 public:
Avi Drissman13fc8932015-12-20 04:40:46145 static const uint16_t kType = dns_protocol::kTypePTR;
[email protected]4e09d242013-05-02 03:19:35146
dcheng67be2b1f2014-10-27 21:47:29147 ~PtrRecordRdata() override;
danakj22f90e72016-04-16 01:55:40148 static std::unique_ptr<PtrRecordRdata> Create(const base::StringPiece& data,
149 const DnsRecordParser& parser);
dcheng67be2b1f2014-10-27 21:47:29150 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:46151 uint16_t Type() const override;
[email protected]4e09d242013-05-02 03:19:35152
153 std::string ptrdomain() const { return ptrdomain_; }
154
155 private:
156 PtrRecordRdata();
157
158 std::string ptrdomain_;
159
160 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata);
161};
162
163// TXT record format (http://www.ietf.org/rfc/rfc1035.txt):
164// texts: One or more <character-string>s.
165// a <character-string> is a length octet followed by as many characters.
166class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata {
167 public:
Avi Drissman13fc8932015-12-20 04:40:46168 static const uint16_t kType = dns_protocol::kTypeTXT;
[email protected]4e09d242013-05-02 03:19:35169
dcheng67be2b1f2014-10-27 21:47:29170 ~TxtRecordRdata() override;
danakj22f90e72016-04-16 01:55:40171 static std::unique_ptr<TxtRecordRdata> Create(const base::StringPiece& data,
172 const DnsRecordParser& parser);
dcheng67be2b1f2014-10-27 21:47:29173 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:46174 uint16_t Type() const override;
[email protected]4e09d242013-05-02 03:19:35175
176 const std::vector<std::string>& texts() const { return texts_; }
177
178 private:
179 TxtRecordRdata();
180
181 std::vector<std::string> texts_;
182
183 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata);
184};
[email protected]f6a9add2013-05-23 00:56:36185
[email protected]7e09a302013-06-26 04:12:30186// Only the subset of the NSEC record format required by mDNS is supported.
187// Nsec record format is described in http://www.ietf.org/rfc/rfc3845.txt and
188// the limited version required for mDNS described in
189// http://www.rfc-editor.org/rfc/rfc6762.txt Section 6.1.
190class NET_EXPORT_PRIVATE NsecRecordRdata : public RecordRdata {
191 public:
Avi Drissman13fc8932015-12-20 04:40:46192 static const uint16_t kType = dns_protocol::kTypeNSEC;
[email protected]7e09a302013-06-26 04:12:30193
dcheng67be2b1f2014-10-27 21:47:29194 ~NsecRecordRdata() override;
danakj22f90e72016-04-16 01:55:40195 static std::unique_ptr<NsecRecordRdata> Create(const base::StringPiece& data,
196 const DnsRecordParser& parser);
dcheng67be2b1f2014-10-27 21:47:29197 bool IsEqual(const RecordRdata* other) const override;
Avi Drissman13fc8932015-12-20 04:40:46198 uint16_t Type() const override;
[email protected]7e09a302013-06-26 04:12:30199
200 // Length of the bitmap in bits.
201 unsigned bitmap_length() const { return bitmap_.size() * 8; }
202
203 // Returns bit i-th bit in the bitmap, where bits withing a byte are organized
204 // most to least significant. If it is set, a record with rrtype i exists for
205 // the domain name of this nsec record.
206 bool GetBit(unsigned i) const;
207
208 private:
209 NsecRecordRdata();
210
Avi Drissman13fc8932015-12-20 04:40:46211 std::vector<uint8_t> bitmap_;
[email protected]7e09a302013-06-26 04:12:30212
213 DISALLOW_COPY_AND_ASSIGN(NsecRecordRdata);
214};
215
216
[email protected]f6a9add2013-05-23 00:56:36217} // namespace net
[email protected]4e09d242013-05-02 03:19:35218
219#endif // NET_DNS_RECORD_RDATA_H_