1 /*
2  * rrdef.h
3  *
4  * RR definitions
5  *
6  * a Net::DNS like library for C
7  *
8  * (c) NLnet Labs, 2005-2006
9  *
10  * See the file LICENSE for the license
11  */
12 
13 /**
14  * \file
15  *
16  * Defines resource record types and constants.
17  */
18 
19 #ifndef GLDNS_RRDEF_H
20 #define GLDNS_RRDEF_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /** Maximum length of a dname label */
27 #define GLDNS_MAX_LABELLEN     63
28 /** Maximum length of a complete dname */
29 #define GLDNS_MAX_DOMAINLEN    255
30 /** Maximum number of pointers in 1 dname */
31 #define GLDNS_MAX_POINTERS	65535
32 /** The bytes TTL, CLASS and length use up in an rr */
33 #define GLDNS_RR_OVERHEAD	10
34 
35 #define GLDNS_DNSSEC_KEYPROTO    3
36 #define GLDNS_KEY_ZONE_KEY   0x0100 /* set for ZSK&KSK, rfc 4034 */
37 #define GLDNS_KEY_SEP_KEY    0x0001 /* set for KSK, rfc 4034 */
38 #define GLDNS_KEY_REVOKE_KEY 0x0080 /* used to revoke KSK, rfc 5011 */
39 
40 /* The first fields are contiguous and can be referenced instantly */
41 #define GLDNS_RDATA_FIELD_DESCRIPTORS_COMMON 260
42 
43 /** lookuptable for rr classes  */
44 extern struct gldns_struct_lookup_table* gldns_rr_classes;
45 
46 /**
47  *  The different RR classes.
48  */
49 enum gldns_enum_rr_class
50 {
51 	/** the Internet */
52 	GLDNS_RR_CLASS_IN 	= 1,
53 	/** Chaos class */
54 	GLDNS_RR_CLASS_CH	= 3,
55 	/** Hesiod (Dyer 87) */
56 	GLDNS_RR_CLASS_HS	= 4,
57 	/** None class, dynamic update */
58 	GLDNS_RR_CLASS_NONE      = 254,
59 	/** Any class */
60 	GLDNS_RR_CLASS_ANY	= 255,
61 
62 	GLDNS_RR_CLASS_FIRST     = 0,
63 	GLDNS_RR_CLASS_LAST      = 65535,
64 	GLDNS_RR_CLASS_COUNT     = GLDNS_RR_CLASS_LAST - GLDNS_RR_CLASS_FIRST + 1
65 };
66 typedef enum gldns_enum_rr_class gldns_rr_class;
67 
68 /**
69  *  Used to specify whether compression is allowed.
70  */
71 enum gldns_enum_rr_compress
72 {
73 	/** compression is allowed */
74 	GLDNS_RR_COMPRESS,
75 	GLDNS_RR_NO_COMPRESS
76 };
77 typedef enum gldns_enum_rr_compress gldns_rr_compress;
78 
79 /**
80  * The different RR types.
81  */
82 enum gldns_enum_rr_type
83 {
84 	/**  a host address */
85 	GLDNS_RR_TYPE_A = 1,
86 	/**  an authoritative name server */
87 	GLDNS_RR_TYPE_NS = 2,
88 	/**  a mail destination (Obsolete - use MX) */
89 	GLDNS_RR_TYPE_MD = 3,
90 	/**  a mail forwarder (Obsolete - use MX) */
91 	GLDNS_RR_TYPE_MF = 4,
92 	/**  the canonical name for an alias */
93 	GLDNS_RR_TYPE_CNAME = 5,
94 	/**  marks the start of a zone of authority */
95 	GLDNS_RR_TYPE_SOA = 6,
96 	/**  a mailbox domain name (EXPERIMENTAL) */
97 	GLDNS_RR_TYPE_MB = 7,
98 	/**  a mail group member (EXPERIMENTAL) */
99 	GLDNS_RR_TYPE_MG = 8,
100 	/**  a mail rename domain name (EXPERIMENTAL) */
101 	GLDNS_RR_TYPE_MR = 9,
102 	/**  a null RR (EXPERIMENTAL) */
103 	GLDNS_RR_TYPE_NULL = 10,
104 	/**  a well known service description */
105 	GLDNS_RR_TYPE_WKS = 11,
106 	/**  a domain name pointer */
107 	GLDNS_RR_TYPE_PTR = 12,
108 	/**  host information */
109 	GLDNS_RR_TYPE_HINFO = 13,
110 	/**  mailbox or mail list information */
111 	GLDNS_RR_TYPE_MINFO = 14,
112 	/**  mail exchange */
113 	GLDNS_RR_TYPE_MX = 15,
114 	/**  text strings */
115 	GLDNS_RR_TYPE_TXT = 16,
116 	/**  RFC1183 */
117 	GLDNS_RR_TYPE_RP = 17,
118 	/**  RFC1183 */
119 	GLDNS_RR_TYPE_AFSDB = 18,
120 	/**  RFC1183 */
121 	GLDNS_RR_TYPE_X25 = 19,
122 	/**  RFC1183 */
123 	GLDNS_RR_TYPE_ISDN = 20,
124 	/**  RFC1183 */
125 	GLDNS_RR_TYPE_RT = 21,
126 	/**  RFC1706 */
127 	GLDNS_RR_TYPE_NSAP = 22,
128 	/**  RFC1348 */
129 	GLDNS_RR_TYPE_NSAP_PTR = 23,
130 	/**  2535typecode */
131 	GLDNS_RR_TYPE_SIG = 24,
132 	/**  2535typecode */
133 	GLDNS_RR_TYPE_KEY = 25,
134 	/**  RFC2163 */
135 	GLDNS_RR_TYPE_PX = 26,
136 	/**  RFC1712 */
137 	GLDNS_RR_TYPE_GPOS = 27,
138 	/**  ipv6 address */
139 	GLDNS_RR_TYPE_AAAA = 28,
140 	/**  LOC record  RFC1876 */
141 	GLDNS_RR_TYPE_LOC = 29,
142 	/**  2535typecode */
143 	GLDNS_RR_TYPE_NXT = 30,
144 	/**  draft-ietf-nimrod-dns-01.txt */
145 	GLDNS_RR_TYPE_EID = 31,
146 	/**  draft-ietf-nimrod-dns-01.txt */
147 	GLDNS_RR_TYPE_NIMLOC = 32,
148 	/**  SRV record RFC2782 */
149 	GLDNS_RR_TYPE_SRV = 33,
150 	/**  http://www.jhsoft.com/rfc/af-saa-0069.000.rtf */
151 	GLDNS_RR_TYPE_ATMA = 34,
152 	/**  RFC2915 */
153 	GLDNS_RR_TYPE_NAPTR = 35,
154 	/**  RFC2230 */
155 	GLDNS_RR_TYPE_KX = 36,
156 	/**  RFC2538 */
157 	GLDNS_RR_TYPE_CERT = 37,
158 	/**  RFC2874 */
159 	GLDNS_RR_TYPE_A6 = 38,
160 	/**  RFC2672 */
161 	GLDNS_RR_TYPE_DNAME = 39,
162 	/**  dnsind-kitchen-sink-02.txt */
163 	GLDNS_RR_TYPE_SINK = 40,
164 	/**  Pseudo OPT record... */
165 	GLDNS_RR_TYPE_OPT = 41,
166 	/**  RFC3123 */
167 	GLDNS_RR_TYPE_APL = 42,
168 	/**  RFC4034, RFC3658 */
169 	GLDNS_RR_TYPE_DS = 43,
170 	/**  SSH Key Fingerprint */
171 	GLDNS_RR_TYPE_SSHFP = 44, /* RFC 4255 */
172 	/**  IPsec Key */
173 	GLDNS_RR_TYPE_IPSECKEY = 45, /* RFC 4025 */
174 	/**  DNSSEC */
175 	GLDNS_RR_TYPE_RRSIG = 46, /* RFC 4034 */
176 	GLDNS_RR_TYPE_NSEC = 47, /* RFC 4034 */
177 	GLDNS_RR_TYPE_DNSKEY = 48, /* RFC 4034 */
178 
179 	GLDNS_RR_TYPE_DHCID = 49, /* RFC 4701 */
180 	/* NSEC3 */
181 	GLDNS_RR_TYPE_NSEC3 = 50, /* RFC 5155 */
182 	GLDNS_RR_TYPE_NSEC3PARAM = 51, /* RFC 5155 */
183 	GLDNS_RR_TYPE_NSEC3PARAMS = 51,
184 	GLDNS_RR_TYPE_TLSA = 52, /* RFC 6698 */
185 	GLDNS_RR_TYPE_SMIMEA = 53, /* RFC 8162 */
186 	GLDNS_RR_TYPE_HIP = 55, /* RFC 5205 */
187 
188 	/** draft-reid-dnsext-zs */
189 	GLDNS_RR_TYPE_NINFO = 56,
190 	/** draft-reid-dnsext-rkey */
191 	GLDNS_RR_TYPE_RKEY = 57,
192         /** draft-ietf-dnsop-trust-history */
193         GLDNS_RR_TYPE_TALINK = 58,
194 	GLDNS_RR_TYPE_CDS = 59, /** RFC 7344 */
195 	GLDNS_RR_TYPE_CDNSKEY = 60, /** RFC 7344 */
196 	GLDNS_RR_TYPE_OPENPGPKEY = 61, /* RFC 7929 */
197 	GLDNS_RR_TYPE_CSYNC = 62, /* RFC 7477 */
198 	GLDNS_RR_TYPE_ZONEMD = 63, /* draft-wessels-dns-zone-digest */
199 
200 	GLDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
201 
202 	GLDNS_RR_TYPE_UINFO = 100,
203 	GLDNS_RR_TYPE_UID = 101,
204 	GLDNS_RR_TYPE_GID = 102,
205 	GLDNS_RR_TYPE_UNSPEC = 103,
206 
207 	GLDNS_RR_TYPE_NID = 104, /* RFC 6742 */
208 	GLDNS_RR_TYPE_L32 = 105, /* RFC 6742 */
209 	GLDNS_RR_TYPE_L64 = 106, /* RFC 6742 */
210 	GLDNS_RR_TYPE_LP = 107, /* RFC 6742 */
211 
212 	/** draft-jabley-dnsext-eui48-eui64-rrtypes */
213 	GLDNS_RR_TYPE_EUI48 = 108,
214 	GLDNS_RR_TYPE_EUI64 = 109,
215 
216 	GLDNS_RR_TYPE_TKEY = 249, /* RFC 2930 */
217 	GLDNS_RR_TYPE_TSIG = 250,
218 	GLDNS_RR_TYPE_IXFR = 251,
219 	GLDNS_RR_TYPE_AXFR = 252,
220 	/**  A request for mailbox-related records (MB, MG or MR) */
221 	GLDNS_RR_TYPE_MAILB = 253,
222 	/**  A request for mail agent RRs (Obsolete - see MX) */
223 	GLDNS_RR_TYPE_MAILA = 254,
224 	/**  any type (wildcard) */
225 	GLDNS_RR_TYPE_ANY = 255,
226 	GLDNS_RR_TYPE_URI = 256, /* RFC 7553 */
227 	GLDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
228 	GLDNS_RR_TYPE_AVC = 258,
229 	GLDNS_RR_TYPE_DOA = 259, /* draft-durand-doa-over-dns */
230 	GLDNS_RR_TYPE_AMTRELAY = 260, /* draft-ietf-mboned-driad-amt-discovery */
231 
232 	/** DNSSEC Trust Authorities */
233 	GLDNS_RR_TYPE_TA = 32768,
234 	/* RFC 4431, 5074, DNSSEC Lookaside Validation */
235 	GLDNS_RR_TYPE_DLV = 32769,
236 
237 	/* type codes from nsec3 experimental phase
238 	GLDNS_RR_TYPE_NSEC3 = 65324,
239 	GLDNS_RR_TYPE_NSEC3PARAMS = 65325, */
240 	GLDNS_RR_TYPE_FIRST = 0,
241 	GLDNS_RR_TYPE_LAST  = 65535,
242 	GLDNS_RR_TYPE_COUNT = GLDNS_RR_TYPE_LAST - GLDNS_RR_TYPE_FIRST + 1
243 };
244 typedef enum gldns_enum_rr_type gldns_rr_type;
245 
246 /* RDATA */
247 #define GLDNS_MAX_RDFLEN	65535
248 
249 #define GLDNS_RDF_SIZE_BYTE              1
250 #define GLDNS_RDF_SIZE_WORD              2
251 #define GLDNS_RDF_SIZE_DOUBLEWORD        4
252 #define GLDNS_RDF_SIZE_6BYTES            6
253 #define GLDNS_RDF_SIZE_8BYTES            8
254 #define GLDNS_RDF_SIZE_16BYTES           16
255 
256 #define GLDNS_NSEC3_VARS_OPTOUT_MASK 0x01
257 
258 #define GLDNS_APL_IP4            1
259 #define GLDNS_APL_IP6            2
260 #define GLDNS_APL_MASK           0x7f
261 #define GLDNS_APL_NEGATION       0x80
262 
263 /**
264  * The different types of RDATA fields.
265  */
266 enum gldns_enum_rdf_type
267 {
268 	/** none */
269 	GLDNS_RDF_TYPE_NONE,
270 	/** domain name */
271 	GLDNS_RDF_TYPE_DNAME,
272 	/** 8 bits */
273 	GLDNS_RDF_TYPE_INT8,
274 	/** 16 bits */
275 	GLDNS_RDF_TYPE_INT16,
276 	/** 32 bits */
277 	GLDNS_RDF_TYPE_INT32,
278 	/** A record */
279 	GLDNS_RDF_TYPE_A,
280 	/** AAAA record */
281 	GLDNS_RDF_TYPE_AAAA,
282 	/** txt string */
283 	GLDNS_RDF_TYPE_STR,
284 	/** apl data */
285 	GLDNS_RDF_TYPE_APL,
286 	/** b32 string */
287 	GLDNS_RDF_TYPE_B32_EXT,
288 	/** b64 string */
289 	GLDNS_RDF_TYPE_B64,
290 	/** hex string */
291 	GLDNS_RDF_TYPE_HEX,
292 	/** nsec type codes */
293 	GLDNS_RDF_TYPE_NSEC,
294 	/** a RR type */
295 	GLDNS_RDF_TYPE_TYPE,
296 	/** a class */
297 	GLDNS_RDF_TYPE_CLASS,
298 	/** certificate algorithm */
299 	GLDNS_RDF_TYPE_CERT_ALG,
300 	/** a key algorithm */
301         GLDNS_RDF_TYPE_ALG,
302         /** unknown types */
303         GLDNS_RDF_TYPE_UNKNOWN,
304         /** time (32 bits) */
305         GLDNS_RDF_TYPE_TIME,
306         /** period */
307         GLDNS_RDF_TYPE_PERIOD,
308         /** tsig time 48 bits */
309         GLDNS_RDF_TYPE_TSIGTIME,
310 	/** Represents the Public Key Algorithm, HIT and Public Key fields
311 	    for the HIP RR types.  A HIP specific rdf type is used because of
312 	    the unusual layout in wireformat (see RFC 5205 Section 5) */
313 	GLDNS_RDF_TYPE_HIP,
314         /** variable length any type rdata where the length
315             is specified by the first 2 bytes */
316         GLDNS_RDF_TYPE_INT16_DATA,
317         /** protocol and port bitmaps */
318         GLDNS_RDF_TYPE_SERVICE,
319         /** location data */
320         GLDNS_RDF_TYPE_LOC,
321         /** well known services */
322         GLDNS_RDF_TYPE_WKS,
323         /** NSAP */
324         GLDNS_RDF_TYPE_NSAP,
325         /** ATMA */
326         GLDNS_RDF_TYPE_ATMA,
327         /** IPSECKEY */
328         GLDNS_RDF_TYPE_IPSECKEY,
329         /** nsec3 hash salt */
330         GLDNS_RDF_TYPE_NSEC3_SALT,
331         /** nsec3 base32 string (with length byte on wire */
332         GLDNS_RDF_TYPE_NSEC3_NEXT_OWNER,
333 
334         /** 4 shorts represented as 4 * 16 bit hex numbers
335          *  separated by colons. For NID and L64.
336          */
337         GLDNS_RDF_TYPE_ILNP64,
338 
339         /** 6 * 8 bit hex numbers separated by dashes. For EUI48. */
340         GLDNS_RDF_TYPE_EUI48,
341         /** 8 * 8 bit hex numbers separated by dashes. For EUI64. */
342         GLDNS_RDF_TYPE_EUI64,
343 
344         /** A non-zero sequence of US-ASCII letters and numbers in lower case.
345          *  For CAA.
346          */
347         GLDNS_RDF_TYPE_TAG,
348 
349         /** A <character-string> encoding of the value field as specified
350          * [RFC1035], Section 5.1., encoded as remaining rdata.
351          * For CAA, URI.
352          */
353         GLDNS_RDF_TYPE_LONG_STR,
354 
355 	/* draft-ietf-mboned-driad-amt-discovery */
356 	GLDNS_RDF_TYPE_AMTRELAY,
357 
358 	/** TSIG extended 16bit error value */
359 	GLDNS_RDF_TYPE_TSIGERROR,
360 
361         /* Aliases */
362         GLDNS_RDF_TYPE_BITMAP = GLDNS_RDF_TYPE_NSEC
363 };
364 typedef enum gldns_enum_rdf_type gldns_rdf_type;
365 
366 /**
367  * Algorithms used in dns
368  */
369 enum gldns_enum_algorithm
370 {
371         GLDNS_RSAMD5             = 1,   /* RFC 4034,4035 */
372         GLDNS_DH                 = 2,
373         GLDNS_DSA                = 3,
374         GLDNS_ECC                = 4,
375         GLDNS_RSASHA1            = 5,
376         GLDNS_DSA_NSEC3          = 6,
377         GLDNS_RSASHA1_NSEC3      = 7,
378         GLDNS_RSASHA256          = 8,   /* RFC 5702 */
379         GLDNS_RSASHA512          = 10,  /* RFC 5702 */
380         GLDNS_ECC_GOST           = 12,  /* RFC 5933 */
381         GLDNS_ECDSAP256SHA256    = 13,  /* RFC 6605 */
382         GLDNS_ECDSAP384SHA384    = 14,  /* RFC 6605 */
383 	GLDNS_ED25519		= 15,  /* RFC 8080 */
384 	GLDNS_ED448		= 16,  /* RFC 8080 */
385         GLDNS_INDIRECT           = 252,
386         GLDNS_PRIVATEDNS         = 253,
387         GLDNS_PRIVATEOID         = 254
388 };
389 typedef enum gldns_enum_algorithm gldns_algorithm;
390 
391 /**
392  * Hashing algorithms used in the DS record
393  */
394 enum gldns_enum_hash
395 {
396         GLDNS_SHA1               = 1,  /* RFC 4034 */
397         GLDNS_SHA256             = 2,  /* RFC 4509 */
398         GLDNS_HASH_GOST          = 3,  /* RFC 5933 */
399         GLDNS_SHA384             = 4   /* RFC 6605 */
400 };
401 typedef enum gldns_enum_hash gldns_hash;
402 
403 /**
404  * algorithms used in CERT rrs
405  */
406 enum gldns_enum_cert_algorithm
407 {
408         GLDNS_CERT_PKIX          = 1,
409         GLDNS_CERT_SPKI          = 2,
410         GLDNS_CERT_PGP           = 3,
411         GLDNS_CERT_IPKIX         = 4,
412         GLDNS_CERT_ISPKI         = 5,
413         GLDNS_CERT_IPGP          = 6,
414         GLDNS_CERT_ACPKIX        = 7,
415         GLDNS_CERT_IACPKIX       = 8,
416         GLDNS_CERT_URI           = 253,
417         GLDNS_CERT_OID           = 254
418 };
419 typedef enum gldns_enum_cert_algorithm gldns_cert_algorithm;
420 
421 /**
422  * EDNS option codes
423  */
424 enum gldns_enum_edns_option
425 {
426 	GLDNS_EDNS_LLQ = 1, /* http://files.dns-sd.org/draft-sekar-dns-llq.txt */
427 	GLDNS_EDNS_UL = 2, /* http://files.dns-sd.org/draft-sekar-dns-ul.txt */
428 	GLDNS_EDNS_NSID = 3, /* RFC5001 */
429 	/* 4 draft-cheshire-edns0-owner-option */
430 	GLDNS_EDNS_DAU = 5, /* RFC6975 */
431 	GLDNS_EDNS_DHU = 6, /* RFC6975 */
432 	GLDNS_EDNS_N3U = 7, /* RFC6975 */
433 	GLDNS_EDNS_CLIENT_SUBNET = 8, /* RFC7871 */
434 	GLDNS_EDNS_KEEPALIVE = 11, /* draft-ietf-dnsop-edns-tcp-keepalive*/
435 	GLDNS_EDNS_PADDING = 12 /* RFC7830 */
436 };
437 typedef enum gldns_enum_edns_option gldns_edns_option;
438 
439 #define GLDNS_EDNS_MASK_DO_BIT 0x8000
440 
441 /** TSIG and TKEY extended rcodes (16bit), 0-15 are the normal rcodes. */
442 #define GLDNS_TSIG_ERROR_NOERROR  0
443 #define GLDNS_TSIG_ERROR_BADSIG   16
444 #define GLDNS_TSIG_ERROR_BADKEY   17
445 #define GLDNS_TSIG_ERROR_BADTIME  18
446 #define GLDNS_TSIG_ERROR_BADMODE  19
447 #define GLDNS_TSIG_ERROR_BADNAME  20
448 #define GLDNS_TSIG_ERROR_BADALG   21
449 
450 /**
451  * Contains all information about resource record types.
452  *
453  * This structure contains, for all rr types, the rdata fields that are defined.
454  */
455 struct gldns_struct_rr_descriptor
456 {
457 	/** Type of the RR that is described here */
458 	gldns_rr_type    _type;
459 	/** Textual name of the RR type.  */
460 	const char *_name;
461 	/** Minimum number of rdata fields in the RRs of this type.  */
462 	uint8_t     _minimum;
463 	/** Maximum number of rdata fields in the RRs of this type.  */
464 	uint8_t     _maximum;
465 	/** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
466 	const gldns_rdf_type *_wireformat;
467 	/** Special rdf types */
468 	gldns_rdf_type _variable;
469 	/** Specifies whether compression can be used for dnames in this RR type. */
470 	gldns_rr_compress _compress;
471 	/** The number of DNAMEs in the _wireformat string, for parsing. */
472 	uint8_t _dname_count;
473 };
474 typedef struct gldns_struct_rr_descriptor gldns_rr_descriptor;
475 
476 /**
477  * returns the resource record descriptor for the given rr type.
478  *
479  * \param[in] type the type value of the rr type
480  *\return the gldns_rr_descriptor for this type
481  */
482 const gldns_rr_descriptor *gldns_rr_descript(uint16_t type);
483 
484 /**
485  * returns the minimum number of rdata fields of the rr type this descriptor describes.
486  *
487  * \param[in]  descriptor for an rr type
488  * \return the minimum number of rdata fields
489  */
490 size_t gldns_rr_descriptor_minimum(const gldns_rr_descriptor *descriptor);
491 
492 /**
493  * returns the maximum number of rdata fields of the rr type this descriptor describes.
494  *
495  * \param[in]  descriptor for an rr type
496  * \return the maximum number of rdata fields
497  */
498 size_t gldns_rr_descriptor_maximum(const gldns_rr_descriptor *descriptor);
499 
500 /**
501  * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
502  *
503  * \param[in] descriptor for an rr type
504  * \param[in] field the field number
505  * \return the rdf type for the field
506  */
507 gldns_rdf_type gldns_rr_descriptor_field_type(const gldns_rr_descriptor *descriptor, size_t field);
508 
509 /**
510  * retrieves a rrtype by looking up its name.
511  * \param[in] name a string with the name
512  * \return the type which corresponds with the name
513  */
514 gldns_rr_type gldns_get_rr_type_by_name(const char *name);
515 
516 /**
517  * retrieves a class by looking up its name.
518  * \param[in] name string with the name
519  * \return the cass which corresponds with the name
520  */
521 gldns_rr_class gldns_get_rr_class_by_name(const char *name);
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 
527 #endif /* GLDNS_RRDEF_H */
528