1 // 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.
5 #ifndef NET_DNS_RECORD_RDATA_H_
6 #define NET_DNS_RECORD_RDATA_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_piece.h"
15 #include "net/base/big_endian.h"
16 #include "net/base/net_export.h"
17 #include "net/base/net_util.h"
18 #include "net/dns/dns_protocol.h"
22 class DnsRecordParser;
24 // Parsed represenation of the extra data in a record. Does not include standard
25 // DNS record data such as TTL, Name, Type and Class.
26 class NET_EXPORT_PRIVATE RecordRdata {
28 virtual ~RecordRdata() {}
30 virtual bool IsEqual(const RecordRdata* other) const = 0;
31 virtual uint16 Type() const = 0;
36 DISALLOW_COPY_AND_ASSIGN(RecordRdata);
39 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt):
40 // 2 bytes network-order unsigned priority
41 // 2 bytes network-order unsigned weight
42 // 2 bytes network-order unsigned port
43 // target: domain name (on-the-wire representation)
44 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata {
46 static const uint16 kType = dns_protocol::kTypeSRV;
48 virtual ~SrvRecordRdata();
49 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data,
50 const DnsRecordParser& parser);
52 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
53 virtual uint16 Type() const OVERRIDE;
55 uint16 priority() const { return priority_; }
56 uint16 weight() const { return weight_; }
57 uint16 port() const { return port_; }
59 const std::string& target() const { return target_; }
70 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata);
73 // A Record format (http://www.ietf.org/rfc/rfc1035.txt):
74 // 4 bytes for IP address.
75 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata {
77 static const uint16 kType = dns_protocol::kTypeA;
79 virtual ~ARecordRdata();
80 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data,
81 const DnsRecordParser& parser);
82 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
83 virtual uint16 Type() const OVERRIDE;
85 const IPAddressNumber& address() const { return address_; }
90 IPAddressNumber address_;
92 DISALLOW_COPY_AND_ASSIGN(ARecordRdata);
95 // AAAA Record format (http://www.ietf.org/rfc/rfc1035.txt):
96 // 16 bytes for IP address.
97 class NET_EXPORT_PRIVATE AAAARecordRdata : public RecordRdata {
99 static const uint16 kType = dns_protocol::kTypeAAAA;
101 virtual ~AAAARecordRdata();
102 static scoped_ptr<AAAARecordRdata> Create(const base::StringPiece& data,
103 const DnsRecordParser& parser);
104 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
105 virtual uint16 Type() const OVERRIDE;
107 const IPAddressNumber& address() const { return address_; }
112 IPAddressNumber address_;
114 DISALLOW_COPY_AND_ASSIGN(AAAARecordRdata);
117 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt):
118 // cname: On the wire representation of domain name.
119 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata {
121 static const uint16 kType = dns_protocol::kTypeCNAME;
123 virtual ~CnameRecordRdata();
124 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data,
125 const DnsRecordParser& parser);
126 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
127 virtual uint16 Type() const OVERRIDE;
129 std::string cname() const { return cname_; }
136 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata);
139 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt):
140 // domain: On the wire representation of domain name.
141 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata {
143 static const uint16 kType = dns_protocol::kTypePTR;
145 virtual ~PtrRecordRdata();
146 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data,
147 const DnsRecordParser& parser);
148 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
149 virtual uint16 Type() const OVERRIDE;
151 std::string ptrdomain() const { return ptrdomain_; }
156 std::string ptrdomain_;
158 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata);
161 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt):
162 // texts: One or more <character-string>s.
163 // a <character-string> is a length octet followed by as many characters.
164 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata {
166 static const uint16 kType = dns_protocol::kTypeTXT;
168 virtual ~TxtRecordRdata();
169 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data,
170 const DnsRecordParser& parser);
171 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
172 virtual uint16 Type() const OVERRIDE;
174 const std::vector<std::string>& texts() const { return texts_; }
179 std::vector<std::string> texts_;
181 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata);
184 // Only the subset of the NSEC record format required by mDNS is supported.
185 // Nsec record format is described in http://www.ietf.org/rfc/rfc3845.txt and
186 // the limited version required for mDNS described in
187 // http://www.rfc-editor.org/rfc/rfc6762.txt Section 6.1.
188 class NET_EXPORT_PRIVATE NsecRecordRdata : public RecordRdata {
190 static const uint16 kType = dns_protocol::kTypeNSEC;
192 virtual ~NsecRecordRdata();
193 static scoped_ptr<NsecRecordRdata> Create(const base::StringPiece& data,
194 const DnsRecordParser& parser);
195 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE;
196 virtual uint16 Type() const OVERRIDE;
198 // Length of the bitmap in bits.
199 unsigned bitmap_length() const { return bitmap_.size() * 8; }
201 // Returns bit i-th bit in the bitmap, where bits withing a byte are organized
202 // most to least significant. If it is set, a record with rrtype i exists for
203 // the domain name of this nsec record.
204 bool GetBit(unsigned i) const;
209 std::vector<uint8> bitmap_;
211 DISALLOW_COPY_AND_ASSIGN(NsecRecordRdata);
217 #endif // NET_DNS_RECORD_RDATA_H_