xref: /dragonfly/contrib/ldns/ldns/rr.h (revision f9993810)
1 /*
2  * rr.h -  resource record definitions
3  *
4  * a Net::DNS like library for C
5  *
6  * (c) NLnet Labs, 2005-2006
7  *
8  * See the file LICENSE for the license
9  */
10 
11 /**
12  * \file
13  *
14  * Contains the definition of ldns_rr and functions to manipulate those.
15  */
16 
17 
18 #ifndef LDNS_RR_H
19 #define LDNS_RR_H
20 
21 #include <ldns/common.h>
22 #include <ldns/rdata.h>
23 #include <ldns/buffer.h>
24 #include <ldns/error.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /** Maximum length of a dname label */
31 #define LDNS_MAX_LABELLEN     63
32 /** Maximum length of a complete dname */
33 #define LDNS_MAX_DOMAINLEN    255
34 /** Maximum number of pointers in 1 dname */
35 #define LDNS_MAX_POINTERS	65535
36 /** The bytes TTL, CLASS and length use up in an rr */
37 #define LDNS_RR_OVERHEAD	10
38 
39 
40 
41 /**
42  *  The different RR classes.
43  */
44 enum ldns_enum_rr_class
45 {
46 	/** the Internet */
47 	LDNS_RR_CLASS_IN 	= 1,
48 	/** Chaos class */
49 	LDNS_RR_CLASS_CH	= 3,
50 	/** Hesiod (Dyer 87) */
51 	LDNS_RR_CLASS_HS	= 4,
52     /** None class, dynamic update */
53     LDNS_RR_CLASS_NONE      = 254,
54 	/** Any class */
55 	LDNS_RR_CLASS_ANY	= 255,
56 
57 	LDNS_RR_CLASS_FIRST     = 0,
58 	LDNS_RR_CLASS_LAST      = 65535,
59 	LDNS_RR_CLASS_COUNT     = LDNS_RR_CLASS_LAST - LDNS_RR_CLASS_FIRST + 1
60 };
61 typedef enum ldns_enum_rr_class ldns_rr_class;
62 
63 /**
64  *  Used to specify whether compression is allowed.
65  */
66 enum ldns_enum_rr_compress
67 {
68 	/** compression is allowed */
69 	LDNS_RR_COMPRESS,
70 	LDNS_RR_NO_COMPRESS
71 };
72 typedef enum ldns_enum_rr_compress ldns_rr_compress;
73 
74 /**
75  * The different RR types.
76  */
77 enum ldns_enum_rr_type
78 {
79 	/**  a host address */
80 	LDNS_RR_TYPE_A = 1,
81 	/**  an authoritative name server */
82 	LDNS_RR_TYPE_NS = 2,
83 	/**  a mail destination (Obsolete - use MX) */
84 	LDNS_RR_TYPE_MD = 3,
85 	/**  a mail forwarder (Obsolete - use MX) */
86 	LDNS_RR_TYPE_MF = 4,
87 	/**  the canonical name for an alias */
88 	LDNS_RR_TYPE_CNAME = 5,
89 	/**  marks the start of a zone of authority */
90 	LDNS_RR_TYPE_SOA = 6,
91 	/**  a mailbox domain name (EXPERIMENTAL) */
92 	LDNS_RR_TYPE_MB = 7,
93 	/**  a mail group member (EXPERIMENTAL) */
94 	LDNS_RR_TYPE_MG = 8,
95 	/**  a mail rename domain name (EXPERIMENTAL) */
96 	LDNS_RR_TYPE_MR = 9,
97 	/**  a null RR (EXPERIMENTAL) */
98 	LDNS_RR_TYPE_NULL = 10,
99 	/**  a well known service description */
100 	LDNS_RR_TYPE_WKS = 11,
101 	/**  a domain name pointer */
102 	LDNS_RR_TYPE_PTR = 12,
103 	/**  host information */
104 	LDNS_RR_TYPE_HINFO = 13,
105 	/**  mailbox or mail list information */
106 	LDNS_RR_TYPE_MINFO = 14,
107 	/**  mail exchange */
108 	LDNS_RR_TYPE_MX = 15,
109 	/**  text strings */
110 	LDNS_RR_TYPE_TXT = 16,
111 	/**  RFC1183 */
112 	LDNS_RR_TYPE_RP = 17,
113 	/**  RFC1183 */
114 	LDNS_RR_TYPE_AFSDB = 18,
115 	/**  RFC1183 */
116 	LDNS_RR_TYPE_X25 = 19,
117 	/**  RFC1183 */
118 	LDNS_RR_TYPE_ISDN = 20,
119 	/**  RFC1183 */
120 	LDNS_RR_TYPE_RT = 21,
121 	/**  RFC1706 */
122 	LDNS_RR_TYPE_NSAP = 22,
123 	/**  RFC1348 */
124 	LDNS_RR_TYPE_NSAP_PTR = 23,
125 	/**  2535typecode */
126 	LDNS_RR_TYPE_SIG = 24,
127 	/**  2535typecode */
128 	LDNS_RR_TYPE_KEY = 25,
129 	/**  RFC2163 */
130 	LDNS_RR_TYPE_PX = 26,
131 	/**  RFC1712 */
132 	LDNS_RR_TYPE_GPOS = 27,
133 	/**  ipv6 address */
134 	LDNS_RR_TYPE_AAAA = 28,
135 	/**  LOC record  RFC1876 */
136 	LDNS_RR_TYPE_LOC = 29,
137 	/**  2535typecode */
138 	LDNS_RR_TYPE_NXT = 30,
139 	/**  draft-ietf-nimrod-dns-01.txt */
140 	LDNS_RR_TYPE_EID = 31,
141 	/**  draft-ietf-nimrod-dns-01.txt */
142 	LDNS_RR_TYPE_NIMLOC = 32,
143 	/**  SRV record RFC2782 */
144 	LDNS_RR_TYPE_SRV = 33,
145 	/**  http://www.jhsoft.com/rfc/af-saa-0069.000.rtf */
146 	LDNS_RR_TYPE_ATMA = 34,
147 	/**  RFC2915 */
148 	LDNS_RR_TYPE_NAPTR = 35,
149 	/**  RFC2230 */
150 	LDNS_RR_TYPE_KX = 36,
151 	/**  RFC2538 */
152 	LDNS_RR_TYPE_CERT = 37,
153 	/**  RFC2874 */
154 	LDNS_RR_TYPE_A6 = 38,
155 	/**  RFC2672 */
156 	LDNS_RR_TYPE_DNAME = 39,
157 	/**  dnsind-kitchen-sink-02.txt */
158 	LDNS_RR_TYPE_SINK = 40,
159 	/**  OPT record RFC 6891 */
160 	LDNS_RR_TYPE_OPT = 41,
161 	/**  RFC3123 */
162 	LDNS_RR_TYPE_APL = 42,
163 	/**  RFC4034, RFC3658 */
164 	LDNS_RR_TYPE_DS = 43,
165 	/**  SSH Key Fingerprint */
166 	LDNS_RR_TYPE_SSHFP = 44, /* RFC 4255 */
167 	/**  IPsec Key */
168 	LDNS_RR_TYPE_IPSECKEY = 45, /* RFC 4025 */
169 	/**  DNSSEC */
170 	LDNS_RR_TYPE_RRSIG = 46, /* RFC 4034 */
171 	LDNS_RR_TYPE_NSEC = 47, /* RFC 4034 */
172 	LDNS_RR_TYPE_DNSKEY = 48, /* RFC 4034 */
173 
174 	LDNS_RR_TYPE_DHCID = 49, /* RFC 4701 */
175 	/* NSEC3 */
176 	LDNS_RR_TYPE_NSEC3 = 50, /* RFC 5155 */
177 	LDNS_RR_TYPE_NSEC3PARAM = 51, /* RFC 5155 */
178 	LDNS_RR_TYPE_NSEC3PARAMS = 51,
179 	LDNS_RR_TYPE_TLSA = 52, /* RFC 6698 */
180 	LDNS_RR_TYPE_SMIMEA = 53, /* RFC 8162 */
181 
182 	LDNS_RR_TYPE_HIP = 55, /* RFC 5205 */
183 
184 	/** draft-reid-dnsext-zs */
185 	LDNS_RR_TYPE_NINFO = 56,
186 	/** draft-reid-dnsext-rkey */
187 	LDNS_RR_TYPE_RKEY = 57,
188         /** draft-ietf-dnsop-trust-history */
189         LDNS_RR_TYPE_TALINK = 58,
190 	LDNS_RR_TYPE_CDS = 59, /* RFC 7344 */
191 	LDNS_RR_TYPE_CDNSKEY = 60, /* RFC 7344 */
192 	LDNS_RR_TYPE_OPENPGPKEY = 61, /* RFC 7929 */
193 	LDNS_RR_TYPE_CSYNC = 62, /* RFC 7477 */
194 	LDNS_RR_TYPE_ZONEMD = 63, /* draft-ietf-dnsop-dns-zone-digest */
195 	LDNS_RR_TYPE_SVCB = 64, /* draft-ietf-dnsop-svcb-https */
196 	LDNS_RR_TYPE_HTTPS = 65, /* draft-ietf-dnsop-svcb-https */
197 
198 	LDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
199 
200 	LDNS_RR_TYPE_UINFO = 100,
201 	LDNS_RR_TYPE_UID = 101,
202 	LDNS_RR_TYPE_GID = 102,
203 	LDNS_RR_TYPE_UNSPEC = 103,
204 
205 	LDNS_RR_TYPE_NID = 104, /* RFC 6742 */
206 	LDNS_RR_TYPE_L32 = 105, /* RFC 6742 */
207 	LDNS_RR_TYPE_L64 = 106, /* RFC 6742 */
208 	LDNS_RR_TYPE_LP = 107, /* RFC 6742 */
209 
210 	LDNS_RR_TYPE_EUI48 = 108, /* RFC 7043 */
211 	LDNS_RR_TYPE_EUI64 = 109, /* RFC 7043 */
212 
213 	LDNS_RR_TYPE_TKEY = 249, /* RFC 2930 */
214 	LDNS_RR_TYPE_TSIG = 250,
215 	LDNS_RR_TYPE_IXFR = 251,
216 	LDNS_RR_TYPE_AXFR = 252,
217 	/**  A request for mailbox-related records (MB, MG or MR) */
218 	LDNS_RR_TYPE_MAILB = 253,
219 	/**  A request for mail agent RRs (Obsolete - see MX) */
220 	LDNS_RR_TYPE_MAILA = 254,
221 	/**  any type (wildcard) */
222 	LDNS_RR_TYPE_ANY = 255,
223 	LDNS_RR_TYPE_URI = 256, /* RFC 7553 */
224 	LDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
225 	LDNS_RR_TYPE_AVC = 258, /* Cisco's DNS-AS RR, see www.dns-as.org */
226 	LDNS_RR_TYPE_DOA = 259, /* draft-durand-doa-over-dns */
227 
228 	/** draft-ietf-mboned-driad-amt-discovery **/
229 	LDNS_RR_TYPE_AMTRELAY = 260,
230 
231 	/** DNSSEC Trust Authorities */
232 	LDNS_RR_TYPE_TA = 32768,
233 	/* RFC 4431, 5074, DNSSEC Lookaside Validation */
234 	LDNS_RR_TYPE_DLV = 32769,
235 
236 	/* type codes from nsec3 experimental phase
237 	LDNS_RR_TYPE_NSEC3 = 65324,
238 	LDNS_RR_TYPE_NSEC3PARAMS = 65325, */
239 	LDNS_RR_TYPE_FIRST = 0,
240 	LDNS_RR_TYPE_LAST  = 65535,
241 	LDNS_RR_TYPE_COUNT = LDNS_RR_TYPE_LAST - LDNS_RR_TYPE_FIRST + 1
242 };
243 typedef enum ldns_enum_rr_type ldns_rr_type;
244 
245 /* The first fields are contiguous and can be referenced instantly */
246 #define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON (LDNS_RR_TYPE_AMTRELAY + 1)
247 
248 /**
249  * Resource Record
250  *
251  * This is the basic DNS element that contains actual data
252  *
253  * From RFC1035:
254  * <pre>
255 3.2.1. Format
256 
257 All RRs have the same top level format shown below:
258 
259                                     1  1  1  1  1  1
260       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
261     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
262     |                                               |
263     /                                               /
264     /                      NAME                     /
265     |                                               |
266     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
267     |                      TYPE                     |
268     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
269     |                     CLASS                     |
270     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
271     |                      TTL                      |
272     |                                               |
273     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
274     |                   RDLENGTH                    |
275     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
276     /                     RDATA                     /
277     /                                               /
278     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
279 
280 where:
281 
282 NAME            an owner name, i.e., the name of the node to which this
283                 resource record pertains.
284 
285 TYPE            two octets containing one of the RR TYPE codes.
286 
287 CLASS           two octets containing one of the RR CLASS codes.
288 
289 TTL             a 32 bit signed integer that specifies the time interval
290                 that the resource record may be cached before the source
291                 of the information should again be consulted.  Zero
292                 values are interpreted to mean that the RR can only be
293                 used for the transaction in progress, and should not be
294                 cached.  For example, SOA records are always distributed
295                 with a zero TTL to prohibit caching.  Zero values can
296                 also be used for extremely volatile data.
297 
298 RDLENGTH        an unsigned 16 bit integer that specifies the length in
299                 octets of the RDATA field.
300 
301 RDATA           a variable length string of octets that describes the
302                 resource.  The format of this information varies
303                 according to the TYPE and CLASS of the resource record.
304  * </pre>
305  *
306  * The actual amount and type of rdata fields depend on the RR type of the
307  * RR, and can be found by using \ref ldns_rr_descriptor functions.
308  */
309 struct ldns_struct_rr
310 {
311 	/**  Owner name, uncompressed */
312 	ldns_rdf	*_owner;
313 	/**  Time to live  */
314 	uint32_t	_ttl;
315 	/**  Number of data fields */
316 	size_t	        _rd_count;
317 	/**  the type of the RR. A, MX etc. */
318 	ldns_rr_type	_rr_type;
319 	/**  Class of the resource record.  */
320 	ldns_rr_class	_rr_class;
321 	/* everything in the rdata is in network order */
322 	/**  The array of rdata's */
323 	ldns_rdf	 **_rdata_fields;
324 	/**  question rr [it would be nicer if thous is after _rd_count]
325 		 ABI change: Fix this in next major release
326 	 */
327 	bool		_rr_question;
328 };
329 typedef struct ldns_struct_rr ldns_rr;
330 
331 /**
332  * List or Set of Resource Records
333  *
334  * Contains a list of rr's <br>
335  * No official RFC-like checks are made
336  */
337 struct ldns_struct_rr_list
338 {
339 	size_t _rr_count;
340 	size_t _rr_capacity;
341 	ldns_rr **_rrs;
342 };
343 typedef struct ldns_struct_rr_list ldns_rr_list;
344 
345 /**
346  * Contains all information about resource record types.
347  *
348  * This structure contains, for all rr types, the rdata fields that are defined.
349  */
350 struct ldns_struct_rr_descriptor
351 {
352 	/** Type of the RR that is described here */
353 	ldns_rr_type    _type;
354 	/** Textual name of the RR type.  */
355 	const char *_name;
356 	/** Minimum number of rdata fields in the RRs of this type.  */
357 	uint8_t     _minimum;
358 	/** Maximum number of rdata fields in the RRs of this type.  */
359 	uint8_t     _maximum;
360 	/** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
361 	const ldns_rdf_type *_wireformat;
362 	/** Special rdf types */
363 	ldns_rdf_type _variable;
364 	/** Specifies whether compression can be used for dnames in this RR type. */
365 	ldns_rr_compress _compress;
366 	/** The number of DNAMEs in the _wireformat string, for parsing. */
367 	uint8_t _dname_count;
368 };
369 typedef struct ldns_struct_rr_descriptor ldns_rr_descriptor;
370 
371 
372 /**
373  * Create a rr type bitmap rdf providing enough space to set all
374  * known (to ldns) rr types.
375  * \param[out] rdf the constructed rdf
376  * \return LDNS_STATUS_OK if all went well.
377  */
378 ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf** rdf);
379 
380 /**
381  * Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
382  * \param[out] rdf the constructed rdf
383  * \return LDNS_STATUS_OK if all went well.
384  */
385 ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf** rdf);
386 
387 
388 /**
389  * creates a new rr structure.
390  * \return ldns_rr *
391  */
392 ldns_rr* ldns_rr_new(void);
393 
394 /**
395  * creates a new rr structure, based on the given type.
396  * alloc enough space to hold all the rdf's
397  */
398 ldns_rr* ldns_rr_new_frm_type(ldns_rr_type t);
399 
400 /**
401  * frees an RR structure
402  * \param[in] *rr the RR to be freed
403  * \return void
404  */
405 void ldns_rr_free(ldns_rr *rr);
406 
407 /**
408  * creates an rr from a string.
409  * The string should be a fully filled-in rr, like
410  * ownername &lt;space&gt; TTL &lt;space&gt; CLASS &lt;space&gt;
411  * TYPE &lt;space&gt; RDATA.
412  * \param[out] n the rr to return
413  * \param[in] str the string to convert
414  * \param[in] default_ttl default ttl value for the rr.
415  *            If 0 DEF_TTL will be used
416  * \param[in] origin when the owner is relative add this.
417  *	The caller must ldns_rdf_deep_free it.
418  * \param[out] prev the previous ownername. if this value is not NULL,
419  * the function overwrites this with the ownername found in this
420  * string. The caller must then ldns_rdf_deep_free it.
421  * \return a status msg describing an error or LDNS_STATUS_OK
422  */
423 ldns_status ldns_rr_new_frm_str(ldns_rr **n, const char *str,
424                                 uint32_t default_ttl, const ldns_rdf *origin,
425                                 ldns_rdf **prev);
426 
427 /**
428  * creates an rr for the question section from a string, i.e.
429  * without RDATA fields
430  * Origin and previous RR functionality are the same as in
431  * ldns_rr_new_frm_str()
432  * \param[out] n the rr to return
433  * \param[in] str the string to convert
434  * \param[in] origin when the owner is relative add this.
435  *	The caller must ldns_rdf_deep_free it.
436  * \param prev the previous ownername. the function overwrite this with
437  * the current found ownername. The caller must ldns_rdf_deep_free it.
438  * \return a status msg describing an error or LDNS_STATUS_OK
439  */
440 ldns_status ldns_rr_new_question_frm_str(ldns_rr **n, const char *str,
441                                 const ldns_rdf *origin, ldns_rdf **prev);
442 
443 /**
444  * creates a new rr from a file containing a string.
445  * \param[out] rr the new rr
446  * \param[in] fp the file pointer to use
447  * \param[in] default_ttl pointer to a default ttl for the rr. If NULL DEF_TTL will be used
448  *            the pointer will be updated if the file contains a $TTL directive
449  * \param[in] origin when the owner is relative add this
450  * 	      the pointer will be updated if the file contains a $ORIGIN directive
451  *	      The caller must ldns_rdf_deep_free it.
452  * \param[in] prev when the owner is whitespaces use this as the * ownername
453  *            the pointer will be updated after the call
454  *	      The caller must ldns_rdf_deep_free it.
455  * \return a ldns_status with an error or LDNS_STATUS_OK
456  */
457 ldns_status ldns_rr_new_frm_fp(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev);
458 
459 /**
460  * creates a new rr from a file containing a string.
461  * \param[out] rr the new rr
462  * \param[in] fp the file pointer to use
463  * \param[in] default_ttl a default ttl for the rr. If NULL DEF_TTL will be used
464  *            the pointer will be updated if the file contains a $TTL directive
465  * \param[in] origin when the owner is relative add this
466  * 	      the pointer will be updated if the file contains a $ORIGIN directive
467  *	      The caller must ldns_rdf_deep_free it.
468  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
469  * \param[in] prev when the owner is whitespaces use this as the * ownername
470  *            the pointer will be updated after the call
471  *	      The caller must ldns_rdf_deep_free it.
472  * \return a ldns_status with an error or LDNS_STATUS_OK
473  */
474 ldns_status ldns_rr_new_frm_fp_l(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr);
475 
476 /**
477  * sets the owner in the rr structure.
478  * \param[in] *rr rr to operate on
479  * \param[in] *owner set to this owner
480  * \return void
481  */
482 void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner);
483 
484 /**
485  * sets the question flag in the rr structure.
486  * \param[in] *rr rr to operate on
487  * \param[in] question question flag
488  * \return void
489  */
490 void ldns_rr_set_question(ldns_rr *rr, bool question);
491 
492 /**
493  * sets the ttl in the rr structure.
494  * \param[in] *rr rr to operate on
495  * \param[in] ttl set to this ttl
496  * \return void
497  */
498 void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl);
499 
500 /**
501  * sets the rd_count in the rr.
502  * \param[in] *rr rr to operate on
503  * \param[in] count set to this count
504  * \return void
505  */
506 void ldns_rr_set_rd_count(ldns_rr *rr, size_t count);
507 
508 /**
509  * sets the type in the rr.
510  * \param[in] *rr rr to operate on
511  * \param[in] rr_type set to this type
512  * \return void
513  */
514 void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type);
515 
516 /**
517  * sets the class in the rr.
518  * \param[in] *rr rr to operate on
519  * \param[in] rr_class set to this class
520  * \return void
521  */
522 void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class);
523 
524 /**
525  * sets a rdf member, it will be set on the
526  * position given. The old value is returned, like pop.
527  * \param[in] *rr the rr to operate on
528  * \param[in] *f the rdf to set
529  * \param[in] position the position the set the rdf
530  * \return  the old value in the rr, NULL on failure
531  */
532 ldns_rdf* ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position);
533 
534 /**
535  * sets rd_field member, it will be
536  * placed in the next available spot.
537  * \param[in] *rr rr to operate on
538  * \param[in] *f the data field member to set
539  * \return bool
540  */
541 bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f);
542 
543 /**
544  * removes a rd_field member, it will be
545  * popped from the last position.
546  * \param[in] *rr rr to operate on
547  * \return rdf which was popped (null if nothing)
548  */
549 ldns_rdf* ldns_rr_pop_rdf(ldns_rr *rr);
550 
551 /**
552  * returns the rdata field member counter.
553  * \param[in] *rr rr to operate on
554  * \param[in] nr the number of the rdf to return
555  * \return ldns_rdf *
556  */
557 ldns_rdf* ldns_rr_rdf(const ldns_rr *rr, size_t nr);
558 
559 /**
560  * returns the owner name of an rr structure.
561  * \param[in] *rr rr to operate on
562  * \return ldns_rdf *
563  */
564 ldns_rdf* ldns_rr_owner(const ldns_rr *rr);
565 
566 /**
567  * returns the question flag of an rr structure.
568  * \param[in] *rr rr to operate on
569  * \return bool true if question
570  */
571 bool ldns_rr_is_question(const ldns_rr *rr);
572 
573 /**
574  * returns the ttl of an rr structure.
575  * \param[in] *rr the rr to read from
576  * \return the ttl of the rr
577  */
578 uint32_t ldns_rr_ttl(const ldns_rr *rr);
579 
580 /**
581  * returns the rd_count of an rr structure.
582  * \param[in] *rr the rr to read from
583  * \return the rd count of the rr
584  */
585 size_t ldns_rr_rd_count(const ldns_rr *rr);
586 
587 /**
588  * returns the type of the rr.
589  * \param[in] *rr the rr to read from
590  * \return the type of the rr
591  */
592 ldns_rr_type ldns_rr_get_type(const ldns_rr *rr);
593 
594 /**
595  * returns the class of the rr.
596  * \param[in] *rr the rr to read from
597  * \return the class of the rr
598  */
599 ldns_rr_class ldns_rr_get_class(const ldns_rr *rr);
600 
601 /* rr_lists */
602 
603 /**
604  * returns the number of rr's in an rr_list.
605  * \param[in] rr_list  the rr_list to read from
606  * \return the number of rr's
607  */
608 size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list);
609 
610 /**
611  * sets the number of rr's in an rr_list.
612  * \param[in] rr_list the rr_list to set the count on
613  * \param[in] count the number of rr in this list
614  * \return void
615  */
616 void ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count);
617 
618 /**
619  * set a rr on a specific index in a ldns_rr_list
620  * \param[in] rr_list the rr_list to use
621  * \param[in] r the rr to set
622  * \param[in] count index into the rr_list
623  * \return the old rr which was stored in the rr_list, or
624  * NULL is the index was too large
625  * set a specific rr */
626 ldns_rr * ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count);
627 
628 /**
629  * returns a specific rr of an rrlist.
630  * \param[in] rr_list the rr_list to read from
631  * \param[in] nr return this rr
632  * \return the rr at position nr
633  */
634 ldns_rr* ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr);
635 
636 /**
637  * creates a new rr_list structure.
638  * \return a new rr_list structure
639  */
640 ldns_rr_list* ldns_rr_list_new(void);
641 
642 /**
643  * frees an rr_list structure.
644  * \param[in] rr_list the list to free
645  */
646 void ldns_rr_list_free(ldns_rr_list *rr_list);
647 
648 /**
649  * frees an rr_list structure and all rrs contained therein.
650  * \param[in] rr_list the list to free
651  */
652 void ldns_rr_list_deep_free(ldns_rr_list *rr_list);
653 
654 /**
655  * concatenates two ldns_rr_lists together. This modifies
656  * *left (to extend it and add the pointers from *right).
657  * \param[in] left the leftside
658  * \param[in] right the rightside
659  * \return a left with right concatenated to it
660  */
661 bool ldns_rr_list_cat(ldns_rr_list *left, const ldns_rr_list *right);
662 
663 /**
664  * concatenates two ldns_rr_lists together, but makes clones of the rr's
665  * (instead of pointer copying).
666  * \param[in] left the leftside
667  * \param[in] right the rightside
668  * \return a new rr_list with leftside/rightside concatenated
669  */
670 ldns_rr_list* ldns_rr_list_cat_clone(const ldns_rr_list *left, const ldns_rr_list *right);
671 
672 /**
673  * pushes an rr to an rrlist.
674  * \param[in] rr_list the rr_list to push to
675  * \param[in] rr the rr to push
676  * \return false on error, otherwise true
677  */
678 bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr);
679 
680 /**
681  * pushes an rr_list to an rrlist.
682  * \param[in] rr_list the rr_list to push to
683  * \param[in] push_list the rr_list to push
684  * \return false on error, otherwise true
685  */
686 bool ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list);
687 
688 /**
689  * pops the last rr from an rrlist.
690  * \param[in] rr_list the rr_list to pop from
691  * \return NULL if nothing to pop. Otherwise the popped RR
692  */
693 ldns_rr* ldns_rr_list_pop_rr(ldns_rr_list *rr_list);
694 
695 /**
696  * pops an  rr_list of size s from an rrlist.
697  * \param[in] rr_list the rr_list to pop from
698  * \param[in] size the number of rr's to pop
699  * \return NULL if nothing to pop. Otherwise the popped rr_list
700  */
701 ldns_rr_list* ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t size);
702 
703 /**
704  * returns true if the given rr is one of the rrs in the
705  * list, or if it is equal to one
706  * \param[in] rr_list the rr_list to check
707  * \param[in] rr the rr to check
708  * \return true if rr_list contains rr, false otherwise
709  */
710 bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr);
711 
712 /**
713  * checks if an rr_list is a rrset.
714  * \param[in] rr_list the rr_list to check
715  * \return true if it is an rrset otherwise false
716  */
717 bool ldns_is_rrset(const ldns_rr_list *rr_list);
718 
719 /**
720  * pushes an rr to an rrset (which really are rr_list's).
721  * \param[in] *rr_list the rrset to push the rr to
722  * \param[in] *rr the rr to push
723  * \return true if the push succeeded otherwise false
724  */
725 bool ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr);
726 
727 /**
728  * pops the last rr from an rrset. This function is there only
729  * for the symmetry.
730  * \param[in] rr_list the rr_list to pop from
731  * \return NULL if nothing to pop. Otherwise the popped RR
732  *
733  */
734 ldns_rr* ldns_rr_set_pop_rr(ldns_rr_list *rr_list);
735 
736 /**
737  * pops the first rrset from the list,
738  * the list must be sorted, so that all rr's from each rrset
739  * are next to each other
740  */
741 ldns_rr_list *ldns_rr_list_pop_rrset(ldns_rr_list *rr_list);
742 
743 
744 /**
745  * retrieves a rrtype by looking up its name.
746  * \param[in] name a string with the name
747  * \return the type which corresponds with the name
748  */
749 ldns_rr_type ldns_get_rr_type_by_name(const char *name);
750 
751 /**
752  * retrieves a class by looking up its name.
753  * \param[in] name string with the name
754  * \return the cass which corresponds with the name
755  */
756 ldns_rr_class ldns_get_rr_class_by_name(const char *name);
757 
758 /**
759  * clones a rr and all its data
760  * \param[in] rr the rr to clone
761  * \return the new rr or NULL on failure
762  */
763 ldns_rr* ldns_rr_clone(const ldns_rr *rr);
764 
765 /**
766  * clones an rrlist.
767  * \param[in] rrlist the rrlist to clone
768  * \return the cloned rr list
769  */
770 ldns_rr_list* ldns_rr_list_clone(const ldns_rr_list *rrlist);
771 
772 /**
773  * sorts an rr_list (canonical wire format). the sorting is done inband.
774  * \param[in] unsorted the rr_list to be sorted
775  * \return void
776  */
777 void ldns_rr_list_sort(ldns_rr_list *unsorted);
778 
779 /**
780  * compares two rrs. The TTL is not looked at.
781  * \param[in] rr1 the first one
782  * \param[in] rr2 the second one
783  * \return 0 if equal
784  *         -1 if rr1 comes before rr2
785  *         +1 if rr2 comes before rr1
786  */
787 int ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2);
788 
789 /**
790  * compares two rrs, up to the rdata.
791  * \param[in] rr1 the first one
792  * \param[in] rr2 the second one
793  * \return 0 if equal
794  *         -1 if rr1 comes before rr2
795  *         +1 if rr2 comes before rr1
796  */
797 int ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2);
798 
799 /**
800  * compares the wireformat of two rrs, contained in the given buffers.
801  * \param[in] rr1_buf the first one
802  * \param[in] rr2_buf the second one
803  * \return 0 if equal
804  *         -1 if rr1_buf comes before rr2_buf
805  *         +1 if rr2_buf comes before rr1_buf
806  */
807 int ldns_rr_compare_wire(const ldns_buffer *rr1_buf, const ldns_buffer *rr2_buf);
808 
809 /**
810  * returns true of the given rr's are equal.
811  * Also returns true if one record is a DS that represents the
812  * same DNSKEY record as the other record
813  * \param[in] rr1 the first rr
814  * \param[in] rr2 the second rr
815  * \return true if equal otherwise false
816  */
817 bool ldns_rr_compare_ds(const ldns_rr *rr1, const ldns_rr *rr2);
818 
819 /**
820  * compares two rr lists.
821  * \param[in] rrl1 the first one
822  * \param[in] rrl2 the second one
823  * \return 0 if equal
824  *         -1 if rrl1 comes before rrl2
825  *         +1 if rrl2 comes before rrl1
826  */
827 int ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2);
828 
829 /**
830  * calculates the uncompressed size of an RR.
831  * \param[in] r the rr to operate on
832  * \return size of the rr
833  */
834 size_t ldns_rr_uncompressed_size(const ldns_rr *r);
835 
836 /**
837  * converts each dname in a rr to its canonical form.
838  * \param[in] rr the rr to work on
839  * \return void
840  */
841 void ldns_rr2canonical(ldns_rr *rr);
842 
843 /**
844  * converts each dname in each rr in a rr_list to its canonical form.
845  * \param[in] rr_list the rr_list to work on
846  * \return void
847  */
848 void ldns_rr_list2canonical(const ldns_rr_list *rr_list);
849 
850 /**
851  * counts the number of labels of the ownername.
852  * \param[in] rr count the labels of this rr
853  * \return the number of labels
854  */
855 uint8_t ldns_rr_label_count(const ldns_rr *rr);
856 
857 /**
858  * returns the resource record descriptor for the given rr type.
859  *
860  * \param[in] type the type value of the rr type
861  *\return the ldns_rr_descriptor for this type
862  */
863 const ldns_rr_descriptor *ldns_rr_descript(uint16_t type);
864 
865 /**
866  * returns the minimum number of rdata fields of the rr type this descriptor describes.
867  *
868  * \param[in]  descriptor for an rr type
869  * \return the minimum number of rdata fields
870  */
871 size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor);
872 
873 /**
874  * returns the maximum number of rdata fields of the rr type this descriptor describes.
875  *
876  * \param[in]  descriptor for an rr type
877  * \return the maximum number of rdata fields
878  */
879 size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor);
880 
881 /**
882  * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
883  *
884  * \param[in] descriptor for an rr type
885  * \param[in] field the field number
886  * \return the rdf type for the field
887  */
888 ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field);
889 
890 /**
891  * Return the rr_list which matches the rdf at position field. Think
892  * type-covered stuff for RRSIG
893  *
894  * \param[in] l the rr_list to look in
895  * \param[in] r the rdf to use for the comparison
896  * \param[in] pos at which position can we find the rdf
897  *
898  * \return a new rr list with only the RRs that match
899  *
900  */
901 ldns_rr_list *ldns_rr_list_subtype_by_rdf(const ldns_rr_list *l, const ldns_rdf *r, size_t pos);
902 
903 /**
904  * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
905  * LDNS_RR_TYPE. This is useful in the case when inspecting
906  * the rrtype covered field of an RRSIG.
907  * \param[in] rd the rdf to look at
908  * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
909  *
910  */
911 ldns_rr_type    ldns_rdf2rr_type(const ldns_rdf *rd);
912 
913 /**
914  * Returns the type of the first element of the RR
915  * If there are no elements present, 0 is returned
916  *
917  * \param[in] rr_list The rr list
918  * \return rr_type of the first element, or 0 if the list is empty
919  */
920 ldns_rr_type
921 ldns_rr_list_type(const ldns_rr_list *rr_list);
922 
923 /**
924  * Returns the owner domain name rdf of the first element of the RR
925  * If there are no elements present, NULL is returned
926  *
927  * \param[in] rr_list The rr list
928  * \return dname of the first element, or NULL if the list is empty
929  */
930 ldns_rdf *
931 ldns_rr_list_owner(const ldns_rr_list *rr_list);
932 
933 #ifdef __cplusplus
934 }
935 #endif
936 
937 #endif /* LDNS_RR_H */
938