-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecords.h
365 lines (329 loc) · 11.5 KB
/
records.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//
// Created by Miroslav Karpíšek on 01/11/2018.
//
#ifndef ISA_RECORDS_H
#define ISA_RECORDS_H
#include <string>
typedef struct _a_record a_record;
typedef struct _aaaa_record aaaa_record;
typedef struct _cname_record cname_record;
typedef struct _mx_record mx_record;
typedef struct _ns_record ns_record;
typedef struct _soa_record soa_record;
typedef struct _txt_record txt_record;
typedef struct _dnskey_record dnskey_record;
typedef struct _rsig_record rsig_record;
typedef struct _nsec_record nsec_record;
typedef struct _ds_record ds_record;
typedef union _rr_data rr_data;
typedef struct _rr_answer rr_answer;
/*
* A RDATA
*
* +---------------------------------------------------------------+
* | 0 | 1 | 2 | 3 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ADDRESS |
* +-------------------------------+-------------------------------+
*
* ADDRESS - 32 bit Internet IPv4 address
*
*/
#define DNS_TYPE_A 1
struct _a_record{
std::string ip4;
};
/*
* AAAA RDATA
*
* +---------------------------------------------------------------+
* | 0 ... 18 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ADDRESS |
* +-------------------------------+-------------------------------+
*
* ADDRESS - 128 bit Internet IPv6 address
*
*/
#define DNS_TYPE_AAAA 28
struct _aaaa_record{
std::string ip6;
};
/*
* CNAME RDATA
*
* +---------------------------------------------------------------+
* | ~ |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | CNAME |
* +-------------------------------+-------------------------------+
*
* CNAME - again name in labels
*
*/
#define DNS_TYPE_CNAME 5
struct _cname_record{
std::string cname;
};
/*
* MX RDATA
*
* +-------------------------------+
* | 0 | 1 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | PREF |
* +-------------------------------+
* ~ ~ ~ ~ ~ ~ ~EXCHANGE ~ ~ ~ ~ ~ ~
* +-------------------------------+
*
* PREFERENCE - integer specifies the preference in compare to other RR. Lowest value is higher
* EXCHANGE - labels specifies a host willing to act as a mail exchange for the owner
*
*/
#define DNS_TYPE_MX 15
struct _mx_record{
int preference;
std::string exchange;
};
/*
* NSNAME RDATA
*
* +---------------------------------------------------------------+
* | ~ |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | NSNAME |
* +-------------------------------+-------------------------------+
*
* NSNAME - name in labels specifies a host which should be authoritative
*
*/
#define DNS_TYPE_NS 2
struct _ns_record{
std::string nsname;
};
/*
* SOA RDATA
*
* +---------------------------------------------------------------+
* | 0 | 1 | 2 | 3 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ MNNAME~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
* +---------------------------------------------------------------+
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ RNAME ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
* +---------------------------------------------------------------+
* | SERIAL |
* +---------------+---------------+---------------+---------------+
* | REFRESH |
* +---------------+---------------+---------------+---------------+
* | RETRY |
* +---------------+---------------+---------------+---------------+
* | EXPIRE |
* +---------------+---------------+---------------+---------------+
* | MINIMUM |
* +---------------+---------------+---------------+---------------+
*
* MNNAME - domain name of the name server that was the original or primary source of data for this zone.
* RNAME - domain name which specifies the mailbox of the person responsible for this zone.
* SERIAL - version number of the original copy of the zone
* REFRESH - time interval before the zone should be refreshed.
* RETRY - time interval that should elapse before a failed refresh should be retried.
* EXPIRE - time value that specifies the upper limit on
* the time interval that can elapse before the zone is no
* longer authoritative.
* MINIMUM - minimum TTL field that should be exported with any RR from this zone.
*
*/
#define DNS_TYPE_SOA 6
struct _soa_record{
std::string mnname;
std::string rname;
unsigned int serial;
unsigned int refresh;
unsigned int retry;
unsigned int expire;
unsigned int minimum;
};
/*
* TXT RDATA
*
* +---------------------------------------------------------------+
* | 0 | ~ |
* +---------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | LEN | TXT |
* +---------------+---------------+---------------+---------------+
*
* LEN - length of the TXT
* TXT - characters
*
*/
#define DNS_TYPE_TXT 16
struct _txt_record{
int length;
std::string text;
};
/*
* DNSKEY RDATA
*
* +---------------------------------------------------------------+
* | 0 | 1 | 2 | 3 |
* +---------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | FLAGS | PROTOCOL | ALG |
* +---------------+---------------+---------------+---------------+
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~PUBLIC_KEY ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
* +---------------------------------------------------------------+
*
* FLAGS - flags
* PROTOCOL - must be 3
* ALG - used algorithm
* 0 = RESERVED
* 1 = RSAMD5
* 2 = DH
* 3 = DSA
* 4 = ECC
* 5 = RSASHA1
* 252 = INDIRECT
* 253 = PRIVATEDNS
* 254 = PRIVATEOID
* 255 = RESERVED
*
* PUBLIC_KEY =
*/
#define DNS_TYPE_DNSKEY 48
#define DNSKEY_HASH_LEN(len) (len - 4)
struct _dnskey_record {
int flags;
int protocol;
int algorithm;
std::string public_key;
};
/*
* RSIG RDATA
*
* +---------------------------------------------------------------+
* | 0 | 1 | 2 | 3 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Type Covered | Algorithm | Labels |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Original TTL |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Signature Expiration |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Signature Inception |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Key Tag | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Signer's Name /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Signature /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*
*/
#define DNS_TYPE_RRSIG 46
#define DNSRSIG_HASH_LEN(len, signers_name_len) (len - signers_name_len - 18)
struct _rsig_record {
int type;
int algorithm;
int labels;
int ttl;
std::string expiration;
std::string inception;
int key_tag;
std::string signers_name;
std::string signature;
};
/*
* NSEC RDATA
*
* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / Next Domain Name /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / Type Bit Maps /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#define DNS_TYPE_NSEC 47
#define NSEC_BITMAP_LEN(len, domain_len) (len - domain_len)
struct _nsec_record {
std::string next_domain_name;
std::string bit_maps;
};
/*
* DS RDATA
* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Key Tag | Algorithm | Digest Type |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Digest /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
#define DNS_TYPE_DS 43
#define DS_DIGEST_LEN(len) (len - 4)
struct _ds_record {
int key_tag;
int algorithm;
int digest_type;
std::string digest;
};
union _rr_data {
a_record* A;
aaaa_record* AAAA;
cname_record* CNAME;
mx_record* MX;
ns_record* NS;
soa_record* SOA;
txt_record* TXT;
dnskey_record* DNSKEY;
rsig_record* RSIG;
nsec_record* NSEC;
ds_record* DS;
};
/*
* Resource Record
*
* +-----------+-----------+-----------------------+
* | 0 | 1 |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | 1| 1| NAME_OFFSET |
* +-----------------------------------------------+
* | TYPE |
* +-----------------------------------------------+
* | CLASS |
* +-----------------------------------------------+
* | TTL |
* + - - - - - - - - - - - +
* | TTL |
* +-----------------------------------------------+
* | LEN |
* +-----------------------------------------------+
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ DATA~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
* +-----------------------------------------------+
*
* NAME_OFFSET - points to first occurance of NAME in DNS datagram
* TYPE - type of DNS record
* CLASS - class of DNS record
* TTL - time to live
* LEN - length of data
* DATA - received record data
*
*/
#define RESOURCE_RECORD_NAME_OFFSET 2
#define DNS_CLASS_IN 1
struct _rr_answer {
std::string qname;
int type;
int qclass;
int ttl;
int len;
rr_data record;
int count;
};
bool operator ==(rr_answer answer1, rr_answer answer2);
#endif //ISA_RECORDS_H