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