tdns
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
record-types.hh
Go to the documentation of this file.
1 #pragma once
2 #include <memory>
3 #include "dns-storage.hh"
4 #include "dnsmessages.hh"
5 #include "comboaddress.hh"
6 
7 class DNSMessageReader;
8 class DNSStringWriter;
9 
12 {
13  DNSStringReader(const std::string& str);
14  void skipSpaces();
15 
16  void xfrName(DNSName& name);
17  void xfrType(DNSType& name);
18  void xfrUInt8(uint8_t& v);
19  void xfrUInt16(uint16_t& v);
20  void xfrUInt32(uint32_t& v);
21  void xfrTxt(std::string& txt);
22  std::string d_string;
23  std::string::const_iterator d_iter;
24 };
25 
68 struct AGen : RRGen
70 {
71  AGen(uint32_t ip) : d_ip(ip) {}
72  AGen(DNSMessageReader& dmr);
73 
74  static std::unique_ptr<RRGen> make(const ComboAddress&);
75  static std::unique_ptr<RRGen> make(const std::string& s)
76  {
77  return make(ComboAddress(s));
78  }
79  void toMessage(DNSMessageWriter& dpw) override;
80  std::string toString() const override;
81  DNSType getType() const override { return DNSType::A; }
82  ComboAddress getIP() const;
83  uint32_t d_ip;
84 };
86 struct AAAAGen : RRGen
87 {
89  AAAAGen(unsigned char ip[16])
90  {
91  memcpy(d_ip, ip, 16);
92  }
93  static std::unique_ptr<RRGen> make(const ComboAddress&);
94  static std::unique_ptr<RRGen> make(const std::string& s)
95  {
96  return make(ComboAddress(s));
97  }
98  void toMessage(DNSMessageWriter& dpw) override;
99  std::string toString() const override;
100  DNSType getType() const override { return DNSType::AAAA; }
101 
102  ComboAddress getIP() const;
103 
104  unsigned char d_ip[16];
105 };
106 
108 struct SOAGen : RRGen
109 {
110  SOAGen(const DNSName& mname, const DNSName& rname, uint32_t serial, uint32_t refresh=10800, uint32_t retry=3600, uint32_t expire=604800, uint32_t minimum=3600) :
111  d_mname(mname), d_rname(rname), d_serial(serial), d_refresh(refresh), d_retry(retry), d_expire(expire), d_minimum(minimum)
112  {}
113 
114  SOAGen(DNSMessageReader& dmr);
115  SOAGen(DNSStringReader dsr);
116  static std::unique_ptr<RRGen> make(const DNSName& mname, const DNSName& rname, uint32_t serial, uint32_t refresh=10800, uint32_t retry=3600, uint32_t expire=604800, uint32_t minimum=3600)
117  {
118  return std::make_unique<SOAGen>(mname, rname, serial, refresh, retry, expire, minimum);
119  }
120 
121  void toMessage(DNSMessageWriter& dpw) override;
122  DNSType getType() const override { return DNSType::SOA; }
123  std::string toString() const override;
124  template<typename X> void doConv(X& x);
127 };
128 
130 struct SRVGen : RRGen
131 {
132  SRVGen(uint16_t preference, uint16_t weight, uint16_t port, const DNSName& target) :
133  d_preference(preference), d_weight(weight), d_port(port), d_target(target)
134  {}
135 
136  SRVGen(DNSMessageReader& dmr);
137  SRVGen(DNSStringReader dsr);
138  void toMessage(DNSMessageWriter& dpw) override;
139  DNSType getType() const override { return DNSType::SRV; }
140  std::string toString() const override;
141 
142  template<typename X> void doConv(X& x);
143 
146 };
147 
149 struct NAPTRGen : RRGen
150 {
151  NAPTRGen(uint16_t order, uint16_t pref, const std::string& flags,
152  const std::string& services, const std::string& regexp,
153  const DNSName& replacement) :
154  d_order(order), d_pref(pref), d_flags(flags), d_services(services), d_regexp(regexp), d_replacement(replacement)
155  {}
156 
159  void toMessage(DNSMessageWriter& dpw) override;
160  DNSType getType() const override { return DNSType::NAPTR; }
161  std::string toString() const override;
162  template<typename X> void doConv(X& x);
163 
164  uint16_t d_order, d_pref;
165  std::string d_flags, d_services, d_regexp;
167 };
168 
169 
171 struct CNAMEGen : RRGen
172 {
173  CNAMEGen(const DNSName& name) : d_name(name) {}
175  static std::unique_ptr<RRGen> make(const DNSName& mname)
176  {
177  return std::make_unique<CNAMEGen>(mname);
178  }
179  void toMessage(DNSMessageWriter& dpw) override;
180  std::string toString() const override;
181  DNSType getType() const override { return DNSType::CNAME; }
182 
184 };
185 
187 struct PTRGen : RRGen
188 {
189  PTRGen(const DNSName& name) : d_name(name) {}
190  PTRGen(DNSMessageReader& dmr);
191  static std::unique_ptr<RRGen> make(const DNSName& mname)
192  {
193  return std::make_unique<PTRGen>(mname);
194  }
195  void toMessage(DNSMessageWriter& dpw) override;
196  std::string toString() const override;
197  DNSType getType() const override { return DNSType::PTR; }
199 };
200 
202 struct NSGen : RRGen
203 {
204  NSGen(const DNSName& name) : d_name(name) {}
205  NSGen(DNSMessageReader& dmr);
206  static std::unique_ptr<RRGen> make(const DNSName& mname)
207  {
208  return std::make_unique<NSGen>(mname);
209  }
210  void toMessage(DNSMessageWriter& dpw) override;
211  std::string toString() const override;
212  DNSType getType() const override { return DNSType::NS; }
214 };
215 
217 struct MXGen : RRGen
218 {
219  MXGen(uint16_t prio, const DNSName& name) : d_prio(prio), d_name(name) {}
220  MXGen(DNSMessageReader& dmr);
221 
222  static std::unique_ptr<RRGen> make(uint16_t prio, const DNSName& name)
223  {
224  return std::make_unique<MXGen>(prio, name);
225  }
226  void toMessage(DNSMessageWriter& dpw) override;
227  std::string toString() const override;
228  DNSType getType() const override { return DNSType::MX; }
229  uint16_t d_prio;
231 };
232 
234 struct RRSIGGen : RRGen
235 {
236  RRSIGGen(DNSType type, uint16_t tag, const DNSName& signer, const std::string& signature,
237  uint32_t origttl, uint32_t expire, uint32_t inception, uint8_t algo, uint8_t labels) :
238  d_type(type), d_tag(tag), d_signer(signer), d_signature(signature), d_origttl(origttl),
239  d_expire(expire), d_inception(inception), d_algo(algo), d_labels(labels)
240  {}
243  void toMessage(DNSMessageWriter& dpw) override;
244  std::string toString() const override;
245  DNSType getType() const override { return DNSType::RRSIG; }
246  template<typename X> void doConv(X& x);
248  uint16_t d_tag;
250  std::string d_signature;
252  uint8_t d_algo, d_labels;
253 
254  void xfrSignature(DNSMessageReader& dr);
255  void xfrSignature(DNSMessageWriter& dmw);
256  void xfrSignature(DNSStringWriter& dmw);
257  void xfrSignature(DNSStringReader& dmw);
258 };
259 
260 
262 struct TXTGen : RRGen
263 {
264  TXTGen(const std::vector<std::string>& txts) : d_txts(txts) {}
266  static std::unique_ptr<RRGen> make(const std::vector<std::string>& txts)
267  {
268  return std::make_unique<TXTGen>(txts);
269  }
270  void toMessage(DNSMessageWriter& dpw) override;
271  std::string toString() const override;
272  DNSType getType() const override { return DNSType::TXT; }
273  std::vector<std::string> d_txts;
274 };
275 
278 {
279  UnknownGen(DNSType type, const std::string& rr) : d_type(type), d_rr(rr) {}
281  std::string d_rr;
282  void toMessage(DNSMessageWriter& dpw) override;
283  std::string toString() const override;
284  DNSType getType() const override { return d_type; }
285 };
286 
289 {
290  ClockTXTGen(const std::string& format) : d_format(format) {}
291  static std::unique_ptr<RRGen> make(const std::string& format)
292  {
293  return std::make_unique<ClockTXTGen>(format);
294  }
295  void toMessage(DNSMessageWriter& dpw) override;
296  std::string toString() const override { return d_format; }
297  DNSType getType() const override { return DNSType::TXT; }
298  std::string d_format;
299 };
void toMessage(DNSMessageWriter &dpw) override
This implements 'unknown record types'.
Definition: record-types.hh:277
std::string d_services
Definition: record-types.hh:165
std::string toString() const override
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:336
std::string d_flags
Definition: record-types.hh:165
MXGen(uint16_t prio, const DNSName &name)
Definition: record-types.hh:219
DNSName d_name
Definition: record-types.hh:183
Generates a PTR Resource Record.
Definition: record-types.hh:187
DNSType d_type
Definition: record-types.hh:247
uint16_t d_tag
Definition: record-types.hh:248
uint32_t d_ip
the actual IP
Definition: record-types.hh:83
IP address, A record generator.
Definition: record-types.hh:69
uint16_t d_port
Definition: record-types.hh:144
This implements a fun dynamic TXT record type.
Definition: record-types.hh:288
CNAMEGen(const DNSName &name)
Definition: record-types.hh:173
void xfrType(DNSType &name)
Definition: record-types.cc:78
std::string toString() const override
Definition: record-types.cc:326
void doConv(X &x)
Definition: record-types.cc:241
AAAAGen(unsigned char ip[16])
Definition: record-types.hh:89
uint32_t d_minimum
Definition: record-types.hh:126
Generates a SOA Resource Record.
Definition: record-types.hh:108
DNSType d_type
Definition: record-types.hh:280
std::string toString() const override
DNSType getType() const override
Definition: record-types.hh:228
static std::unique_ptr< RRGen > make(const std::string &format)
Definition: record-types.hh:291
DNSType getType() const override
Definition: record-types.hh:272
void doConv(X &x)
Definition: record-types.cc:376
void toMessage(DNSMessageWriter &dpw) override
ComboAddress getIP() const
Definition: record-types.cc:184
DNSType getType() const override
Definition: record-types.hh:160
void toMessage(DNSMessageWriter &dpw) override
to packet/message
Definition: record-types.cc:137
DNSName d_name
Definition: record-types.hh:213
Defines DNSLabel, DNSType, DNSClass and DNSNode, which together store DNS details.
void xfrName(DNSName &name)
Definition: record-types.cc:65
Generates an AAAA (IPv6 address) record.
Definition: record-types.hh:86
std::string toString() const override
static std::unique_ptr< RRGen > make(const std::vector< std::string > &txts)
Definition: record-types.hh:266
DNSName d_replacement
Definition: record-types.hh:166
A class that parses a DNS Message.
Definition: dnsmessages.hh:13
Generates an TXT Resource Record.
Definition: record-types.hh:262
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:283
DNSType getType() const override
Definition: record-types.hh:81
uint32_t d_refresh
Definition: record-types.hh:126
void skipSpaces()
Definition: record-types.cc:57
static std::unique_ptr< RRGen > make(const DNSName &mname)
Definition: record-types.hh:175
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:320
DNSName d_mname
Definition: record-types.hh:125
static std::unique_ptr< RRGen > make(const std::string &s)
Definition: record-types.hh:75
Generates a SRV Resource Record.
Definition: record-types.hh:130
Generates an RRSIG Resource Record.
Definition: record-types.hh:234
uint16_t d_weight
Definition: record-types.hh:144
uint32_t d_expire
Definition: record-types.hh:251
void xfrUInt32(uint32_t &v)
Definition: record-types.cc:109
std::string d_regexp
Definition: record-types.hh:165
Generates a NAPTR Resource Record.
Definition: record-types.hh:149
TXTGen(const std::vector< std::string > &txts)
Definition: record-types.hh:264
Represents the contents of a resource record.
Definition: dns-storage.hh:180
DNSName d_name
Definition: record-types.hh:230
A DNS Message writer.
Definition: dnsmessages.hh:111
std::string toString() const override
Definition: record-types.hh:296
SOAGen(const DNSName &mname, const DNSName &rname, uint32_t serial, uint32_t refresh=10800, uint32_t retry=3600, uint32_t expire=604800, uint32_t minimum=3600)
Definition: record-types.hh:110
void xfrTxt(std::string &txt)
Definition: record-types.cc:118
PTRGen(const DNSName &name)
Definition: record-types.hh:189
Used by an RRGen to output record content to 'zone text' format.
Definition: record-types.cc:12
std::string toString() const override
to master zone format
Definition: record-types.cc:149
Class that reads a string in 'zonefile format' on behalf of an RRGen.
Definition: record-types.hh:11
std::string toString() const override
Definition: record-types.cc:258
void xfrUInt8(uint8_t &v)
Definition: record-types.cc:92
AGen(uint32_t ip)
Definition: record-types.hh:71
DNSName d_target
Definition: record-types.hh:145
uint32_t d_retry
Definition: record-types.hh:126
static std::unique_ptr< RRGen > make(const std::string &s)
Definition: record-types.hh:94
DNSType getType() const override
Definition: record-types.hh:297
Generates an MX Resource Record.
Definition: record-types.hh:217
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:254
uint8_t d_labels
Definition: record-types.hh:252
Generates a CNAME Resource Record.
Definition: record-types.hh:171
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:269
uint16_t d_preference
Definition: record-types.hh:144
static std::unique_ptr< RRGen > make(const DNSName &mname)
Definition: record-types.hh:191
DNSType getType() const override
Definition: record-types.hh:100
NAPTRGen(uint16_t order, uint16_t pref, const std::string &flags, const std::string &services, const std::string &regexp, const DNSName &replacement)
Definition: record-types.hh:151
DNSName d_rname
Definition: record-types.hh:125
static std::unique_ptr< RRGen > make(const DNSName &mname)
Definition: record-types.hh:206
void toMessage(DNSMessageWriter &dpw) override
uint16_t d_prio
Definition: record-types.hh:229
DNSType getType() const override
Definition: record-types.hh:139
uint16_t d_pref
Definition: record-types.hh:164
void doConv(X &x)
Definition: record-types.cc:232
std::string toString() const override
std::string toString() const override
Definition: record-types.cc:273
std::string d_format
Definition: record-types.hh:298
DNSType getType() const override
Definition: record-types.hh:284
static std::unique_ptr< RRGen > make(const DNSName &mname, const DNSName &rname, uint32_t serial, uint32_t refresh=10800, uint32_t retry=3600, uint32_t expire=604800, uint32_t minimum=3600)
Definition: record-types.hh:116
void doConv(X &x)
Definition: record-types.cc:221
A DNS Name with helpful methods. Inherits case insensitivity from DNSLabel.
Definition: dns-storage.hh:133
DNSType getType() const override
Definition: record-types.hh:197
static std::unique_ptr< RRGen > make(const ComboAddress &)
Definition: record-types.cc:154
uint16_t d_order
Definition: record-types.hh:164
void toMessage(DNSMessageWriter &dpw) override
static std::unique_ptr< RRGen > make(uint16_t prio, const DNSName &name)
Definition: record-types.hh:222
std::string toString() const override
Definition: record-types.cc:192
void xfrUInt16(uint16_t &v)
Definition: record-types.cc:101
AAAAGen(DNSMessageReader &dmr)
Definition: record-types.cc:172
void xfrSignature(DNSMessageReader &dr)
Definition: record-types.cc:386
std::string d_signature
Definition: record-types.hh:250
std::string toString() const override
Definition: record-types.cc:287
RRSIGGen(DNSType type, uint16_t tag, const DNSName &signer, const std::string &signature, uint32_t origttl, uint32_t expire, uint32_t inception, uint8_t algo, uint8_t labels)
Definition: record-types.hh:236
SRVGen(uint16_t preference, uint16_t weight, uint16_t port, const DNSName &target)
Definition: record-types.hh:132
DNSType getType() const override
Definition: record-types.hh:181
DNSType getType() const override
Definition: record-types.hh:122
uint32_t d_serial
Definition: record-types.hh:126
NSGen(const DNSName &name)
Definition: record-types.hh:204
std::vector< std::string > d_txts
Definition: record-types.hh:273
std::string::const_iterator d_iter
Definition: record-types.hh:23
std::string d_string
Definition: record-types.hh:22
static std::unique_ptr< RRGen > make(const ComboAddress &)
Definition: record-types.cc:161
std::string toString() const override
Definition: record-types.cc:304
uint32_t d_origttl
Definition: record-types.hh:251
DNSName d_name
Definition: record-types.hh:198
unsigned char d_ip[16]
Definition: record-types.hh:104
ClockTXTGen(const std::string &format)
Definition: record-types.hh:290
DNSType
Stores the type of a DNS query or resource record.
Definition: dns-storage.hh:73
uint32_t d_expire
Definition: record-types.hh:126
DNSName d_signer
Definition: record-types.hh:249
DNSStringReader(const std::string &str)
Definition: record-types.cc:54
Defines DNSMessageReader and DNSMessageWriter.
std::string d_rr
Definition: record-types.hh:281
std::string toString() const override
Definition: record-types.cc:341
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:358
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:299
DNSType getType() const override
Definition: record-types.hh:212
DNSType getType() const override
Definition: record-types.hh:245
UnknownGen(DNSType type, const std::string &rr)
Definition: record-types.hh:279
uint8_t d_algo
Definition: record-types.hh:252
void toMessage(DNSMessageWriter &dpw) override
Definition: record-types.cc:179
ComboAddress getIP() const
Get IP address in ready to use form.
Definition: record-types.cc:142
uint32_t d_inception
Definition: record-types.hh:251
Generates an NS Resource Record.
Definition: record-types.hh:202