xref: /dragonfly/contrib/ldns/ldns/rr.h (revision a4da4a90)
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 	/**  Pseudo OPT record... */
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-wessels-dns-zone-digest */
195 
196 	LDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
197 
198 	LDNS_RR_TYPE_UINFO = 100,
199 	LDNS_RR_TYPE_UID = 101,
200 	LDNS_RR_TYPE_GID = 102,
201 	LDNS_RR_TYPE_UNSPEC = 103,
202 
203 	LDNS_RR_TYPE_NID = 104, /* RFC 6742 */
204 	LDNS_RR_TYPE_L32 = 105, /* RFC 6742 */
205 	LDNS_RR_TYPE_L64 = 106, /* RFC 6742 */
206 	LDNS_RR_TYPE_LP = 107, /* RFC 6742 */
207 
208 	LDNS_RR_TYPE_EUI48 = 108, /* RFC 7043 */
209 	LDNS_RR_TYPE_EUI64 = 109, /* RFC 7043 */
210 
211 	LDNS_RR_TYPE_TKEY = 249, /* RFC 2930 */
212 	LDNS_RR_TYPE_TSIG = 250,
213 	LDNS_RR_TYPE_IXFR = 251,
214 	LDNS_RR_TYPE_AXFR = 252,
215 	/**  A request for mailbox-related records (MB, MG or MR) */
216 	LDNS_RR_TYPE_MAILB = 253,
217 	/**  A request for mail agent RRs (Obsolete - see MX) */
218 	LDNS_RR_TYPE_MAILA = 254,
219 	/**  any type (wildcard) */
220 	LDNS_RR_TYPE_ANY = 255,
221 	LDNS_RR_TYPE_URI = 256, /* RFC 7553 */
222 	LDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
223 	LDNS_RR_TYPE_AVC = 258, /* Cisco's DNS-AS RR, see www.dns-as.org */
224 	LDNS_RR_TYPE_DOA = 259, /* draft-durand-doa-over-dns */
225 
226 	/** draft-ietf-mboned-driad-amt-discovery **/
227 	LDNS_RR_TYPE_AMTRELAY = 260,
228 
229 	/** DNSSEC Trust Authorities */
230 	LDNS_RR_TYPE_TA = 32768,
231 	/* RFC 4431, 5074, DNSSEC Lookaside Validation */
232 	LDNS_RR_TYPE_DLV = 32769,
233 
234 	/* type codes from nsec3 experimental phase
235 	LDNS_RR_TYPE_NSEC3 = 65324,
236 	LDNS_RR_TYPE_NSEC3PARAMS = 65325, */
237 	LDNS_RR_TYPE_FIRST = 0,
238 	LDNS_RR_TYPE_LAST  = 65535,
239 	LDNS_RR_TYPE_COUNT = LDNS_RR_TYPE_LAST - LDNS_RR_TYPE_FIRST + 1
240 };
241 typedef enum ldns_enum_rr_type ldns_rr_type;
242 
243 /* The first fields are contiguous and can be referenced instantly */
244 #define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON (LDNS_RR_TYPE_AMTRELAY + 1)
245 
246 /**
247  * Resource Record
248  *
249  * This is the basic DNS element that contains actual data
250  *
251  * From RFC1035:
252  * <pre>
253 3.2.1. Format
254 
255 All RRs have the same top level format shown below:
256 
257                                     1  1  1  1  1  1
258       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
259     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
260     |                                               |
261     /                                               /
262     /                      NAME                     /
263     |                                               |
264     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
265     |                      TYPE                     |
266     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
267     |                     CLASS                     |
268     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
269     |                      TTL                      |
270     |                                               |
271     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
272     |                   RDLENGTH                    |
273     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
274     /                     RDATA                     /
275     /                                               /
276     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
277 
278 where:
279 
280 NAME            an owner name, i.e., the name of the node to which this
281                 resource record pertains.
282 
283 TYPE            two octets containing one of the RR TYPE codes.
284 
285 CLASS           two octets containing one of the RR CLASS codes.
286 
287 TTL             a 32 bit signed integer that specifies the time interval
288                 that the resource record may be cached before the source
289                 of the information should again be consulted.  Zero
290                 values are interpreted to mean that the RR can only be
291                 used for the transaction in progress, and should not be
292                 cached.  For example, SOA records are always distributed
293                 with a zero TTL to prohibit caching.  Zero values can
294                 also be used for extremely volatile data.
295 
296 RDLENGTH        an unsigned 16 bit integer that specifies the length in
297                 octets of the RDATA field.
298 
299 RDATA           a variable length string of octets that describes the
300                 resource.  The format of this information varies
301                 according to the TYPE and CLASS of the resource record.
302  * </pre>
303  *
304  * The actual amount and type of rdata fields depend on the RR type of the
305  * RR, and can be found by using \ref ldns_rr_descriptor functions.
306  */
307 struct ldns_struct_rr
308 {
309 	/**  Owner name, uncompressed */
310 	ldns_rdf	*_owner;
311 	/**  Time to live  */
312 	uint32_t	_ttl;
313 	/**  Number of data fields */
314 	size_t	        _rd_count;
315 	/**  the type of the RR. A, MX etc. */
316 	ldns_rr_type	_rr_type;
317 	/**  Class of the resource record.  */
318 	ldns_rr_class	_rr_class;
319 	/* everything in the rdata is in network order */
320 	/**  The array of rdata's */
321 	ldns_rdf	 **_rdata_fields;
322 	/**  question rr [it would be nicer if thous is after _rd_count]
323 		 ABI change: Fix this in next major release
324 	 */
325 	bool		_rr_question;
326 };
327 typedef struct ldns_struct_rr ldns_rr;
328 
329 /**
330  * List or Set of Resource Records
331  *
332  * Contains a list of rr's <br>
333  * No official RFC-like checks are made
334  */
335 struct ldns_struct_rr_list
336 {
337 	size_t _rr_count;
338 	size_t _rr_capacity;
339 	ldns_rr **_rrs;
340 };
341 typedef struct ldns_struct_rr_list ldns_rr_list;
342 
343 /**
344  * Contains all information about resource record types.
345  *
346  * This structure contains, for all rr types, the rdata fields that are defined.
347  */
348 struct ldns_struct_rr_descriptor
349 {
350 	/** Type of the RR that is described here */
351 	ldns_rr_type    _type;
352 	/** Textual name of the RR type.  */
353 	const char *_name;
354 	/** Minimum number of rdata fields in the RRs of this type.  */
355 	uint8_t     _minimum;
356 	/** Maximum number of rdata fields in the RRs of this type.  */
357 	uint8_t     _maximum;
358 	/** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
359 	const ldns_rdf_type *_wireformat;
360 	/** Special rdf types */
361 	ldns_rdf_type _variable;
362 	/** Specifies whether compression can be used for dnames in this RR type. */
363 	ldns_rr_compress _compress;
364 	/** The number of DNAMEs in the _wireformat string, for parsing. */
365 	uint8_t _dname_count;
366 };
367 typedef struct ldns_struct_rr_descriptor ldns_rr_descriptor;
368 
369 
370 /**
371  * Create a rr type bitmap rdf providing enough space to set all
372  * known (to ldns) rr types.
373  * \param[out] rdf the constructed rdf
374  * \return LDNS_STATUS_OK if all went well.
375  */
376 ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf** rdf);
377 
378 /**
379  * Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
380  * \param[out] rdf the constructed rdf
381  * \return LDNS_STATUS_OK if all went well.
382  */
383 ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf** rdf);
384 
385 
386 /**
387  * creates a new rr structure.
388  * \return ldns_rr *
389  */
390 ldns_rr* ldns_rr_new(void);
391 
392 /**
393  * creates a new rr structure, based on the given type.
394  * alloc enough space to hold all the rdf's
395  */
396 ldns_rr* ldns_rr_new_frm_type(ldns_rr_type t);
397 
398 /**
399  * frees an RR structure
400  * \param[in] *rr the RR to be freed
401  * \return void
402  */
403 void ldns_rr_free(ldns_rr *rr);
404 
405 /**
406  * creates an rr from a string.
407  * The string should be a fully filled-in rr, like
408  * ownername &lt;space&gt; TTL &lt;space&gt; CLASS &lt;space&gt;
409  * TYPE &lt;space&gt; RDATA.
410  * \param[out] n the rr to return
411  * \param[in] str the string to convert
412  * \param[in] default_ttl default ttl value for the rr.
413  *            If 0 DEF_TTL will be used
414  * \param[in] origin when the owner is relative add this.
415  *	The caller must ldns_rdf_deep_free it.
416  * \param[out] prev the previous ownername. if this value is not NULL,
417  * the function overwrites this with the ownername found in this
418  * string. The caller must then ldns_rdf_deep_free it.
419  * \return a status msg describing an error or LDNS_STATUS_OK
420  */
421 ldns_status ldns_rr_new_frm_str(ldns_rr **n, const char *str,
422                                 uint32_t default_ttl, const ldns_rdf *origin,
423                                 ldns_rdf **prev);
424 
425 /**
426  * creates an rr for the question section from a string, i.e.
427  * without RDATA fields
428  * Origin and previous RR functionality are the same as in
429  * ldns_rr_new_frm_str()
430  * \param[out] n the rr to return
431  * \param[in] str the string to convert
432  * \param[in] origin when the owner is relative add this.
433  *	The caller must ldns_rdf_deep_free it.
434  * \param prev the previous ownername. the function overwrite this with
435  * the current found ownername. The caller must ldns_rdf_deep_free it.
436  * \return a status msg describing an error or LDNS_STATUS_OK
437  */
438 ldns_status ldns_rr_new_question_frm_str(ldns_rr **n, const char *str,
439                                 const ldns_rdf *origin, ldns_rdf **prev);
440 
441 /**
442  * creates a new rr from a file containing a string.
443  * \param[out] rr the new rr
444  * \param[in] fp the file pointer to use
445  * \param[in] default_ttl pointer to a default ttl for the rr. If NULL DEF_TTL will be used
446  *            the pointer will be updated if the file contains a $TTL directive
447  * \param[in] origin when the owner is relative add this
448  * 	      the pointer will be updated if the file contains a $ORIGIN directive
449  *	      The caller must ldns_rdf_deep_free it.
450  * \param[in] prev when the owner is whitespaces use this as the * ownername
451  *            the pointer will be updated after the call
452  *	      The caller must ldns_rdf_deep_free it.
453  * \return a ldns_status with an error or LDNS_STATUS_OK
454  */
455 ldns_status ldns_rr_new_frm_fp(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev);
456 
457 /**
458  * creates a new rr from a file containing a string.
459  * \param[out] rr the new rr
460  * \param[in] fp the file pointer to use
461  * \param[in] default_ttl a default ttl for the rr. If NULL DEF_TTL will be used
462  *            the pointer will be updated if the file contains a $TTL directive
463  * \param[in] origin when the owner is relative add this
464  * 	      the pointer will be updated if the file contains a $ORIGIN directive
465  *	      The caller must ldns_rdf_deep_free it.
466  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
467  * \param[in] prev when the owner is whitespaces use this as the * ownername
468  *            the pointer will be updated after the call
469  *	      The caller must ldns_rdf_deep_free it.
470  * \return a ldns_status with an error or LDNS_STATUS_OK
471  */
472 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);
473 
474 /**
475  * sets the owner in the rr structure.
476  * \param[in] *rr rr to operate on
477  * \param[in] *owner set to this owner
478  * \return void
479  */
480 void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner);
481 
482 /**
483  * sets the question flag in the rr structure.
484  * \param[in] *rr rr to operate on
485  * \param[in] question question flag
486  * \return void
487  */
488 void ldns_rr_set_question(ldns_rr *rr, bool question);
489 
490 /**
491  * sets the ttl in the rr structure.
492  * \param[in] *rr rr to operate on
493  * \param[in] ttl set to this ttl
494  * \return void
495  */
496 void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl);
497 
498 /**
499  * sets the rd_count in the rr.
500  * \param[in] *rr rr to operate on
501  * \param[in] count set to this count
502  * \return void
503  */
504 void ldns_rr_set_rd_count(ldns_rr *rr, size_t count);
505 
506 /**
507  * sets the type in the rr.
508  * \param[in] *rr rr to operate on
509  * \param[in] rr_type set to this type
510  * \return void
511  */
512 void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type);
513 
514 /**
515  * sets the class in the rr.
516  * \param[in] *rr rr to operate on
517  * \param[in] rr_class set to this class
518  * \return void
519  */
520 void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class);
521 
522 /**
523  * sets a rdf member, it will be set on the
524  * position given. The old value is returned, like pop.
525  * \param[in] *rr the rr to operate on
526  * \param[in] *f the rdf to set
527  * \param[in] position the position the set the rdf
528  * \return  the old value in the rr, NULL on failyre
529  */
530 ldns_rdf* ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position);
531 
532 /**
533  * sets rd_field member, it will be
534  * placed in the next available spot.
535  * \param[in] *rr rr to operate on
536  * \param[in] *f the data field member to set
537  * \return bool
538  */
539 bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f);
540 
541 /**
542  * removes a rd_field member, it will be
543  * popped from the last position.
544  * \param[in] *rr rr to operate on
545  * \return rdf which was popped (null if nothing)
546  */
547 ldns_rdf* ldns_rr_pop_rdf(ldns_rr *rr);
548 
549 /**
550  * returns the rdata field member counter.
551  * \param[in] *rr rr to operate on
552  * \param[in] nr the number of the rdf to return
553  * \return ldns_rdf *
554  */
555 ldns_rdf* ldns_rr_rdf(const ldns_rr *rr, size_t nr);
556 
557 /**
558  * returns the owner name of an rr structure.
559  * \param[in] *rr rr to operate on
560  * \return ldns_rdf *
561  */
562 ldns_rdf* ldns_rr_owner(const ldns_rr *rr);
563 
564 /**
565  * returns the question flag of an rr structure.
566  * \param[in] *rr rr to operate on
567  * \return bool true if question
568  */
569 bool ldns_rr_is_question(const ldns_rr *rr);
570 
571 /**
572  * returns the ttl of an rr structure.
573  * \param[in] *rr the rr to read from
574  * \return the ttl of the rr
575  */
576 uint32_t ldns_rr_ttl(const ldns_rr *rr);
577 
578 /**
579  * returns the rd_count of an rr structure.
580  * \param[in] *rr the rr to read from
581  * \return the rd count of the rr
582  */
583 size_t ldns_rr_rd_count(const ldns_rr *rr);
584 
585 /**
586  * returns the type of the rr.
587  * \param[in] *rr the rr to read from
588  * \return the type of the rr
589  */
590 ldns_rr_type ldns_rr_get_type(const ldns_rr *rr);
591 
592 /**
593  * returns the class of the rr.
594  * \param[in] *rr the rr to read from
595  * \return the class of the rr
596  */
597 ldns_rr_class ldns_rr_get_class(const ldns_rr *rr);
598 
599 /* rr_lists */
600 
601 /**
602  * returns the number of rr's in an rr_list.
603  * \param[in] rr_list  the rr_list to read from
604  * \return the number of rr's
605  */
606 size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list);
607 
608 /**
609  * sets the number of rr's in an rr_list.
610  * \param[in] rr_list the rr_list to set the count on
611  * \param[in] count the number of rr in this list
612  * \return void
613  */
614 void ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count);
615 
616 /**
617  * set a rr on a specific index in a ldns_rr_list
618  * \param[in] rr_list the rr_list to use
619  * \param[in] r the rr to set
620  * \param[in] count index into the rr_list
621  * \return the old rr which was stored in the rr_list, or
622  * NULL is the index was too large
623  * set a specific rr */
624 ldns_rr * ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count);
625 
626 /**
627  * returns a specific rr of an rrlist.
628  * \param[in] rr_list the rr_list to read from
629  * \param[in] nr return this rr
630  * \return the rr at position nr
631  */
632 ldns_rr* ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr);
633 
634 /**
635  * creates a new rr_list structure.
636  * \return a new rr_list structure
637  */
638 ldns_rr_list* ldns_rr_list_new(void);
639 
640 /**
641  * frees an rr_list structure.
642  * \param[in] rr_list the list to free
643  */
644 void ldns_rr_list_free(ldns_rr_list *rr_list);
645 
646 /**
647  * frees an rr_list structure and all rrs contained therein.
648  * \param[in] rr_list the list to free
649  */
650 void ldns_rr_list_deep_free(ldns_rr_list *rr_list);
651 
652 /**
653  * concatenates two ldns_rr_lists together. This modifies
654  * *left (to extend it and add the pointers from *right).
655  * \param[in] left the leftside
656  * \param[in] right the rightside
657  * \return a left with right concatenated to it
658  */
659 bool ldns_rr_list_cat(ldns_rr_list *left, const ldns_rr_list *right);
660 
661 /**
662  * concatenates two ldns_rr_lists together, but makes clones of the rr's
663  * (instead of pointer copying).
664  * \param[in] left the leftside
665  * \param[in] right the rightside
666  * \return a new rr_list with leftside/rightside concatenated
667  */
668 ldns_rr_list* ldns_rr_list_cat_clone(const ldns_rr_list *left, const ldns_rr_list *right);
669 
670 /**
671  * pushes an rr to an rrlist.
672  * \param[in] rr_list the rr_list to push to
673  * \param[in] rr the rr to push
674  * \return false on error, otherwise true
675  */
676 bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr);
677 
678 /**
679  * pushes an rr_list to an rrlist.
680  * \param[in] rr_list the rr_list to push to
681  * \param[in] push_list the rr_list to push
682  * \return false on error, otherwise true
683  */
684 bool ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list);
685 
686 /**
687  * pops the last rr from an rrlist.
688  * \param[in] rr_list the rr_list to pop from
689  * \return NULL if nothing to pop. Otherwise the popped RR
690  */
691 ldns_rr* ldns_rr_list_pop_rr(ldns_rr_list *rr_list);
692 
693 /**
694  * pops an  rr_list of size s from an rrlist.
695  * \param[in] rr_list the rr_list to pop from
696  * \param[in] size the number of rr's to pop
697  * \return NULL if nothing to pop. Otherwise the popped rr_list
698  */
699 ldns_rr_list* ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t size);
700 
701 /**
702  * returns true if the given rr is one of the rrs in the
703  * list, or if it is equal to one
704  * \param[in] rr_list the rr_list to check
705  * \param[in] rr the rr to check
706  * \return true if rr_list contains rr, false otherwise
707  */
708 bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr);
709 
710 /**
711  * checks if an rr_list is a rrset.
712  * \param[in] rr_list the rr_list to check
713  * \return true if it is an rrset otherwise false
714  */
715 bool ldns_is_rrset(const ldns_rr_list *rr_list);
716 
717 /**
718  * pushes an rr to an rrset (which really are rr_list's).
719  * \param[in] *rr_list the rrset to push the rr to
720  * \param[in] *rr the rr to push
721  * \return true if the push succeeded otherwise false
722  */
723 bool ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr);
724 
725 /**
726  * pops the last rr from an rrset. This function is there only
727  * for the symmetry.
728  * \param[in] rr_list the rr_list to pop from
729  * \return NULL if nothing to pop. Otherwise the popped RR
730  *
731  */
732 ldns_rr* ldns_rr_set_pop_rr(ldns_rr_list *rr_list);
733 
734 /**
735  * pops the first rrset from the list,
736  * the list must be sorted, so that all rr's from each rrset
737  * are next to each other
738  */
739 ldns_rr_list *ldns_rr_list_pop_rrset(ldns_rr_list *rr_list);
740 
741 
742 /**
743  * retrieves a rrtype by looking up its name.
744  * \param[in] name a string with the name
745  * \return the type which corresponds with the name
746  */
747 ldns_rr_type ldns_get_rr_type_by_name(const char *name);
748 
749 /**
750  * retrieves a class by looking up its name.
751  * \param[in] name string with the name
752  * \return the cass which corresponds with the name
753  */
754 ldns_rr_class ldns_get_rr_class_by_name(const char *name);
755 
756 /**
757  * clones a rr and all its data
758  * \param[in] rr the rr to clone
759  * \return the new rr or NULL on failure
760  */
761 ldns_rr* ldns_rr_clone(const ldns_rr *rr);
762 
763 /**
764  * clones an rrlist.
765  * \param[in] rrlist the rrlist to clone
766  * \return the cloned rr list
767  */
768 ldns_rr_list* ldns_rr_list_clone(const ldns_rr_list *rrlist);
769 
770 /**
771  * sorts an rr_list (canonical wire format). the sorting is done inband.
772  * \param[in] unsorted the rr_list to be sorted
773  * \return void
774  */
775 void ldns_rr_list_sort(ldns_rr_list *unsorted);
776 
777 /**
778  * compares two rrs. The TTL is not looked at.
779  * \param[in] rr1 the first one
780  * \param[in] rr2 the second one
781  * \return 0 if equal
782  *         -1 if rr1 comes before rr2
783  *         +1 if rr2 comes before rr1
784  */
785 int ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2);
786 
787 /**
788  * compares two rrs, up to the rdata.
789  * \param[in] rr1 the first one
790  * \param[in] rr2 the second one
791  * \return 0 if equal
792  *         -1 if rr1 comes before rr2
793  *         +1 if rr2 comes before rr1
794  */
795 int ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2);
796 
797 /**
798  * compares the wireformat of two rrs, contained in the given buffers.
799  * \param[in] rr1_buf the first one
800  * \param[in] rr2_buf the second one
801  * \return 0 if equal
802  *         -1 if rr1_buf comes before rr2_buf
803  *         +1 if rr2_buf comes before rr1_buf
804  */
805 int ldns_rr_compare_wire(const ldns_buffer *rr1_buf, const ldns_buffer *rr2_buf);
806 
807 /**
808  * returns true of the given rr's are equal.
809  * Also returns true if one record is a DS that represents the
810  * same DNSKEY record as the other record
811  * \param[in] rr1 the first rr
812  * \param[in] rr2 the second rr
813  * \return true if equal otherwise false
814  */
815 bool ldns_rr_compare_ds(const ldns_rr *rr1, const ldns_rr *rr2);
816 
817 /**
818  * compares two rr listss.
819  * \param[in] rrl1 the first one
820  * \param[in] rrl2 the second one
821  * \return 0 if equal
822  *         -1 if rrl1 comes before rrl2
823  *         +1 if rrl2 comes before rrl1
824  */
825 int ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2);
826 
827 /**
828  * calculates the uncompressed size of an RR.
829  * \param[in] r the rr to operate on
830  * \return size of the rr
831  */
832 size_t ldns_rr_uncompressed_size(const ldns_rr *r);
833 
834 /**
835  * converts each dname in a rr to its canonical form.
836  * \param[in] rr the rr to work on
837  * \return void
838  */
839 void ldns_rr2canonical(ldns_rr *rr);
840 
841 /**
842  * converts each dname in each rr in a rr_list to its canonical form.
843  * \param[in] rr_list the rr_list to work on
844  * \return void
845  */
846 void ldns_rr_list2canonical(const ldns_rr_list *rr_list);
847 
848 /**
849  * counts the number of labels of the ownername.
850  * \param[in] rr count the labels of this rr
851  * \return the number of labels
852  */
853 uint8_t ldns_rr_label_count(const ldns_rr *rr);
854 
855 /**
856  * returns the resource record descriptor for the given rr type.
857  *
858  * \param[in] type the type value of the rr type
859  *\return the ldns_rr_descriptor for this type
860  */
861 const ldns_rr_descriptor *ldns_rr_descript(uint16_t type);
862 
863 /**
864  * returns the minimum number of rdata fields of the rr type this descriptor describes.
865  *
866  * \param[in]  descriptor for an rr type
867  * \return the minimum number of rdata fields
868  */
869 size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor);
870 
871 /**
872  * returns the maximum number of rdata fields of the rr type this descriptor describes.
873  *
874  * \param[in]  descriptor for an rr type
875  * \return the maximum number of rdata fields
876  */
877 size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor);
878 
879 /**
880  * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
881  *
882  * \param[in] descriptor for an rr type
883  * \param[in] field the field number
884  * \return the rdf type for the field
885  */
886 ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field);
887 
888 /**
889  * Return the rr_list which matches the rdf at position field. Think
890  * type-covered stuff for RRSIG
891  *
892  * \param[in] l the rr_list to look in
893  * \param[in] r the rdf to use for the comparison
894  * \param[in] pos at which position can we find the rdf
895  *
896  * \return a new rr list with only the RRs that match
897  *
898  */
899 ldns_rr_list *ldns_rr_list_subtype_by_rdf(const ldns_rr_list *l, const ldns_rdf *r, size_t pos);
900 
901 /**
902  * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
903  * LDNS_RR_TYPE. This is useful in the case when inspecting
904  * the rrtype covered field of an RRSIG.
905  * \param[in] rd the rdf to look at
906  * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
907  *
908  */
909 ldns_rr_type    ldns_rdf2rr_type(const ldns_rdf *rd);
910 
911 /**
912  * Returns the type of the first element of the RR
913  * If there are no elements present, 0 is returned
914  *
915  * \param[in] rr_list The rr list
916  * \return rr_type of the first element, or 0 if the list is empty
917  */
918 ldns_rr_type
919 ldns_rr_list_type(const ldns_rr_list *rr_list);
920 
921 /**
922  * Returns the owner domain name rdf of the first element of the RR
923  * If there are no elements present, NULL is returned
924  *
925  * \param[in] rr_list The rr list
926  * \return dname of the first element, or NULL if the list is empty
927  */
928 ldns_rdf *
929 ldns_rr_list_owner(const ldns_rr_list *rr_list);
930 
931 #ifdef __cplusplus
932 }
933 #endif
934 
935 #endif /* LDNS_RR_H */
936