2 * rr.h - resource record definitions
4 * a Net::DNS like library for C
6 * (c) NLnet Labs, 2005-2006
8 * See the file LICENSE for the license
14 * Contains the definition of ldns_rr and functions to manipulate those.
21 #include <ldns/common.h>
22 #include <ldns/rdata.h>
23 #include <ldns/buffer.h>
24 #include <ldns/error.h>
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
39 /* The first fields are contiguous and can be referenced instantly */
40 #define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON 259
45 * The different RR classes.
47 enum ldns_enum_rr_class
53 /** Hesiod (Dyer 87) */
55 /** None class, dynamic update */
56 LDNS_RR_CLASS_NONE = 254,
58 LDNS_RR_CLASS_ANY = 255,
60 LDNS_RR_CLASS_FIRST = 0,
61 LDNS_RR_CLASS_LAST = 65535,
62 LDNS_RR_CLASS_COUNT = LDNS_RR_CLASS_LAST - LDNS_RR_CLASS_FIRST + 1
64 typedef enum ldns_enum_rr_class ldns_rr_class;
67 * Used to specify whether compression is allowed.
69 enum ldns_enum_rr_compress
71 /** compression is allowed */
75 typedef enum ldns_enum_rr_compress ldns_rr_compress;
78 * The different RR types.
80 enum ldns_enum_rr_type
84 /** an authoritative name server */
86 /** a mail destination (Obsolete - use MX) */
88 /** a mail forwarder (Obsolete - use MX) */
90 /** the canonical name for an alias */
91 LDNS_RR_TYPE_CNAME = 5,
92 /** marks the start of a zone of authority */
94 /** a mailbox domain name (EXPERIMENTAL) */
96 /** a mail group member (EXPERIMENTAL) */
98 /** a mail rename domain name (EXPERIMENTAL) */
100 /** a null RR (EXPERIMENTAL) */
101 LDNS_RR_TYPE_NULL = 10,
102 /** a well known service description */
103 LDNS_RR_TYPE_WKS = 11,
104 /** a domain name pointer */
105 LDNS_RR_TYPE_PTR = 12,
106 /** host information */
107 LDNS_RR_TYPE_HINFO = 13,
108 /** mailbox or mail list information */
109 LDNS_RR_TYPE_MINFO = 14,
111 LDNS_RR_TYPE_MX = 15,
113 LDNS_RR_TYPE_TXT = 16,
115 LDNS_RR_TYPE_RP = 17,
117 LDNS_RR_TYPE_AFSDB = 18,
119 LDNS_RR_TYPE_X25 = 19,
121 LDNS_RR_TYPE_ISDN = 20,
123 LDNS_RR_TYPE_RT = 21,
125 LDNS_RR_TYPE_NSAP = 22,
127 LDNS_RR_TYPE_NSAP_PTR = 23,
129 LDNS_RR_TYPE_SIG = 24,
131 LDNS_RR_TYPE_KEY = 25,
133 LDNS_RR_TYPE_PX = 26,
135 LDNS_RR_TYPE_GPOS = 27,
137 LDNS_RR_TYPE_AAAA = 28,
138 /** LOC record RFC1876 */
139 LDNS_RR_TYPE_LOC = 29,
141 LDNS_RR_TYPE_NXT = 30,
142 /** draft-ietf-nimrod-dns-01.txt */
143 LDNS_RR_TYPE_EID = 31,
144 /** draft-ietf-nimrod-dns-01.txt */
145 LDNS_RR_TYPE_NIMLOC = 32,
146 /** SRV record RFC2782 */
147 LDNS_RR_TYPE_SRV = 33,
148 /** http://www.jhsoft.com/rfc/af-saa-0069.000.rtf */
149 LDNS_RR_TYPE_ATMA = 34,
151 LDNS_RR_TYPE_NAPTR = 35,
153 LDNS_RR_TYPE_KX = 36,
155 LDNS_RR_TYPE_CERT = 37,
157 LDNS_RR_TYPE_A6 = 38,
159 LDNS_RR_TYPE_DNAME = 39,
160 /** dnsind-kitchen-sink-02.txt */
161 LDNS_RR_TYPE_SINK = 40,
162 /** Pseudo OPT record... */
163 LDNS_RR_TYPE_OPT = 41,
165 LDNS_RR_TYPE_APL = 42,
166 /** RFC4034, RFC3658 */
167 LDNS_RR_TYPE_DS = 43,
168 /** SSH Key Fingerprint */
169 LDNS_RR_TYPE_SSHFP = 44, /* RFC 4255 */
171 LDNS_RR_TYPE_IPSECKEY = 45, /* RFC 4025 */
173 LDNS_RR_TYPE_RRSIG = 46, /* RFC 4034 */
174 LDNS_RR_TYPE_NSEC = 47, /* RFC 4034 */
175 LDNS_RR_TYPE_DNSKEY = 48, /* RFC 4034 */
177 LDNS_RR_TYPE_DHCID = 49, /* RFC 4701 */
179 LDNS_RR_TYPE_NSEC3 = 50, /* RFC 5155 */
180 LDNS_RR_TYPE_NSEC3PARAM = 51, /* RFC 5155 */
181 LDNS_RR_TYPE_NSEC3PARAMS = 51,
182 LDNS_RR_TYPE_TLSA = 52, /* RFC 6698 */
183 LDNS_RR_TYPE_SMIMEA = 53, /* draft-ietf-dane-smime */
185 LDNS_RR_TYPE_HIP = 55, /* RFC 5205 */
187 /** draft-reid-dnsext-zs */
188 LDNS_RR_TYPE_NINFO = 56,
189 /** draft-reid-dnsext-rkey */
190 LDNS_RR_TYPE_RKEY = 57,
191 /** draft-ietf-dnsop-trust-history */
192 LDNS_RR_TYPE_TALINK = 58,
193 LDNS_RR_TYPE_CDS = 59, /* RFC 7344 */
194 LDNS_RR_TYPE_CDNSKEY = 60, /* RFC 7344 */
195 LDNS_RR_TYPE_OPENPGPKEY = 61, /* RFC 7929 */
196 LDNS_RR_TYPE_CSYNC = 62, /* RFC 7477 */
198 LDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
200 LDNS_RR_TYPE_UINFO = 100,
201 LDNS_RR_TYPE_UID = 101,
202 LDNS_RR_TYPE_GID = 102,
203 LDNS_RR_TYPE_UNSPEC = 103,
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 */
210 LDNS_RR_TYPE_EUI48 = 108, /* RFC 7043 */
211 LDNS_RR_TYPE_EUI64 = 109, /* RFC 7043 */
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 */
227 /** DNSSEC Trust Authorities */
228 LDNS_RR_TYPE_TA = 32768,
229 /* RFC 4431, 5074, DNSSEC Lookaside Validation */
230 LDNS_RR_TYPE_DLV = 32769,
232 /* type codes from nsec3 experimental phase
233 LDNS_RR_TYPE_NSEC3 = 65324,
234 LDNS_RR_TYPE_NSEC3PARAMS = 65325, */
235 LDNS_RR_TYPE_FIRST = 0,
236 LDNS_RR_TYPE_LAST = 65535,
237 LDNS_RR_TYPE_COUNT = LDNS_RR_TYPE_LAST - LDNS_RR_TYPE_FIRST + 1
239 typedef enum ldns_enum_rr_type ldns_rr_type;
244 * This is the basic DNS element that contains actual data
250 All RRs have the same top level format shown below:
253 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
254 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
259 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
261 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
263 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
266 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
268 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
271 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
275 NAME an owner name, i.e., the name of the node to which this
276 resource record pertains.
278 TYPE two octets containing one of the RR TYPE codes.
280 CLASS two octets containing one of the RR CLASS codes.
282 TTL a 32 bit signed integer that specifies the time interval
283 that the resource record may be cached before the source
284 of the information should again be consulted. Zero
285 values are interpreted to mean that the RR can only be
286 used for the transaction in progress, and should not be
287 cached. For example, SOA records are always distributed
288 with a zero TTL to prohibit caching. Zero values can
289 also be used for extremely volatile data.
291 RDLENGTH an unsigned 16 bit integer that specifies the length in
292 octets of the RDATA field.
294 RDATA a variable length string of octets that describes the
295 resource. The format of this information varies
296 according to the TYPE and CLASS of the resource record.
299 * The actual amount and type of rdata fields depend on the RR type of the
300 * RR, and can be found by using \ref ldns_rr_descriptor functions.
302 struct ldns_struct_rr
304 /** Owner name, uncompressed */
308 /** Number of data fields */
310 /** the type of the RR. A, MX etc. */
311 ldns_rr_type _rr_type;
312 /** Class of the resource record. */
313 ldns_rr_class _rr_class;
314 /* everything in the rdata is in network order */
315 /** The array of rdata's */
316 ldns_rdf **_rdata_fields;
317 /** question rr [it would be nicer if thous is after _rd_count]
318 ABI change: Fix this in next major release
322 typedef struct ldns_struct_rr ldns_rr;
325 * List or Set of Resource Records
327 * Contains a list of rr's <br>
328 * No official RFC-like checks are made
330 struct ldns_struct_rr_list
336 typedef struct ldns_struct_rr_list ldns_rr_list;
339 * Contains all information about resource record types.
341 * This structure contains, for all rr types, the rdata fields that are defined.
343 struct ldns_struct_rr_descriptor
345 /** Type of the RR that is described here */
347 /** Textual name of the RR type. */
349 /** Minimum number of rdata fields in the RRs of this type. */
351 /** Maximum number of rdata fields in the RRs of this type. */
353 /** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
354 const ldns_rdf_type *_wireformat;
355 /** Special rdf types */
356 ldns_rdf_type _variable;
357 /** Specifies whether compression can be used for dnames in this RR type. */
358 ldns_rr_compress _compress;
359 /** The number of DNAMEs in the _wireformat string, for parsing. */
360 uint8_t _dname_count;
362 typedef struct ldns_struct_rr_descriptor ldns_rr_descriptor;
366 * Create a rr type bitmap rdf providing enough space to set all
367 * known (to ldns) rr types.
368 * \param[out] rdf the constructed rdf
369 * \return LDNS_STATUS_OK if all went well.
371 ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf** rdf);
374 * Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
375 * \param[out] rdf the constructed rdf
376 * \return LDNS_STATUS_OK if all went well.
378 ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf** rdf);
382 * creates a new rr structure.
385 ldns_rr* ldns_rr_new(void);
388 * creates a new rr structure, based on the given type.
389 * alloc enough space to hold all the rdf's
391 ldns_rr* ldns_rr_new_frm_type(ldns_rr_type t);
394 * frees an RR structure
395 * \param[in] *rr the RR to be freed
398 void ldns_rr_free(ldns_rr *rr);
401 * creates an rr from a string.
402 * The string should be a fully filled-in rr, like
403 * ownername <space> TTL <space> CLASS <space>
404 * TYPE <space> RDATA.
405 * \param[out] n the rr to return
406 * \param[in] str the string to convert
407 * \param[in] default_ttl default ttl value for the rr.
408 * If 0 DEF_TTL will be used
409 * \param[in] origin when the owner is relative add this.
410 * The caller must ldns_rdf_deep_free it.
411 * \param[out] prev the previous ownername. if this value is not NULL,
412 * the function overwrites this with the ownername found in this
413 * string. The caller must then ldns_rdf_deep_free it.
414 * \return a status msg describing an error or LDNS_STATUS_OK
416 ldns_status ldns_rr_new_frm_str(ldns_rr **n, const char *str,
417 uint32_t default_ttl, const ldns_rdf *origin,
421 * creates an rr for the question section from a string, i.e.
422 * without RDATA fields
423 * Origin and previous RR functionality are the same as in
424 * ldns_rr_new_frm_str()
425 * \param[out] n the rr to return
426 * \param[in] str the string to convert
427 * \param[in] origin when the owner is relative add this.
428 * The caller must ldns_rdf_deep_free it.
429 * \param prev the previous ownername. the function overwrite this with
430 * the current found ownername. The caller must ldns_rdf_deep_free it.
431 * \return a status msg describing an error or LDNS_STATUS_OK
433 ldns_status ldns_rr_new_question_frm_str(ldns_rr **n, const char *str,
434 const ldns_rdf *origin, ldns_rdf **prev);
437 * creates a new rr from a file containing a string.
438 * \param[out] rr the new rr
439 * \param[in] fp the file pointer to use
440 * \param[in] default_ttl pointer to a default ttl for the rr. If NULL DEF_TTL will be used
441 * the pointer will be updated if the file contains a $TTL directive
442 * \param[in] origin when the owner is relative add this
443 * the pointer will be updated if the file contains a $ORIGIN directive
444 * The caller must ldns_rdf_deep_free it.
445 * \param[in] prev when the owner is whitespaces use this as the * ownername
446 * the pointer will be updated after the call
447 * The caller must ldns_rdf_deep_free it.
448 * \return a ldns_status with an error or LDNS_STATUS_OK
450 ldns_status ldns_rr_new_frm_fp(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev);
453 * creates a new rr from a file containing a string.
454 * \param[out] rr the new rr
455 * \param[in] fp the file pointer to use
456 * \param[in] default_ttl a default ttl for the rr. If NULL DEF_TTL will be used
457 * the pointer will be updated if the file contains a $TTL directive
458 * \param[in] origin when the owner is relative add this
459 * the pointer will be updated if the file contains a $ORIGIN directive
460 * The caller must ldns_rdf_deep_free it.
461 * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
462 * \param[in] prev when the owner is whitespaces use this as the * ownername
463 * the pointer will be updated after the call
464 * The caller must ldns_rdf_deep_free it.
465 * \return a ldns_status with an error or LDNS_STATUS_OK
467 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);
470 * sets the owner in the rr structure.
471 * \param[in] *rr rr to operate on
472 * \param[in] *owner set to this owner
475 void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner);
478 * sets the question flag in the rr structure.
479 * \param[in] *rr rr to operate on
480 * \param[in] question question flag
483 void ldns_rr_set_question(ldns_rr *rr, bool question);
486 * sets the ttl in the rr structure.
487 * \param[in] *rr rr to operate on
488 * \param[in] ttl set to this ttl
491 void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl);
494 * sets the rd_count in the rr.
495 * \param[in] *rr rr to operate on
496 * \param[in] count set to this count
499 void ldns_rr_set_rd_count(ldns_rr *rr, size_t count);
502 * sets the type in the rr.
503 * \param[in] *rr rr to operate on
504 * \param[in] rr_type set to this type
507 void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type);
510 * sets the class in the rr.
511 * \param[in] *rr rr to operate on
512 * \param[in] rr_class set to this class
515 void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class);
518 * sets a rdf member, it will be set on the
519 * position given. The old value is returned, like pop.
520 * \param[in] *rr the rr to operate on
521 * \param[in] *f the rdf to set
522 * \param[in] position the position the set the rdf
523 * \return the old value in the rr, NULL on failyre
525 ldns_rdf* ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position);
528 * sets rd_field member, it will be
529 * placed in the next available spot.
530 * \param[in] *rr rr to operate on
531 * \param[in] *f the data field member to set
534 bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f);
537 * removes a rd_field member, it will be
538 * popped from the last position.
539 * \param[in] *rr rr to operate on
540 * \return rdf which was popped (null if nothing)
542 ldns_rdf* ldns_rr_pop_rdf(ldns_rr *rr);
545 * returns the rdata field member counter.
546 * \param[in] *rr rr to operate on
547 * \param[in] nr the number of the rdf to return
550 ldns_rdf* ldns_rr_rdf(const ldns_rr *rr, size_t nr);
553 * returns the owner name of an rr structure.
554 * \param[in] *rr rr to operate on
557 ldns_rdf* ldns_rr_owner(const ldns_rr *rr);
560 * returns the question flag of an rr structure.
561 * \param[in] *rr rr to operate on
562 * \return bool true if question
564 bool ldns_rr_is_question(const ldns_rr *rr);
567 * returns the ttl of an rr structure.
568 * \param[in] *rr the rr to read from
569 * \return the ttl of the rr
571 uint32_t ldns_rr_ttl(const ldns_rr *rr);
574 * returns the rd_count of an rr structure.
575 * \param[in] *rr the rr to read from
576 * \return the rd count of the rr
578 size_t ldns_rr_rd_count(const ldns_rr *rr);
581 * returns the type of the rr.
582 * \param[in] *rr the rr to read from
583 * \return the type of the rr
585 ldns_rr_type ldns_rr_get_type(const ldns_rr *rr);
588 * returns the class of the rr.
589 * \param[in] *rr the rr to read from
590 * \return the class of the rr
592 ldns_rr_class ldns_rr_get_class(const ldns_rr *rr);
597 * returns the number of rr's in an rr_list.
598 * \param[in] rr_list the rr_list to read from
599 * \return the number of rr's
601 size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list);
604 * sets the number of rr's in an rr_list.
605 * \param[in] rr_list the rr_list to set the count on
606 * \param[in] count the number of rr in this list
609 void ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count);
612 * set a rr on a specific index in a ldns_rr_list
613 * \param[in] rr_list the rr_list to use
614 * \param[in] r the rr to set
615 * \param[in] count index into the rr_list
616 * \return the old rr which was stored in the rr_list, or
617 * NULL is the index was too large
618 * set a specific rr */
619 ldns_rr * ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count);
622 * returns a specific rr of an rrlist.
623 * \param[in] rr_list the rr_list to read from
624 * \param[in] nr return this rr
625 * \return the rr at position nr
627 ldns_rr* ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr);
630 * creates a new rr_list structure.
631 * \return a new rr_list structure
633 ldns_rr_list* ldns_rr_list_new(void);
636 * frees an rr_list structure.
637 * \param[in] rr_list the list to free
639 void ldns_rr_list_free(ldns_rr_list *rr_list);
642 * frees an rr_list structure and all rrs contained therein.
643 * \param[in] rr_list the list to free
645 void ldns_rr_list_deep_free(ldns_rr_list *rr_list);
648 * concatenates two ldns_rr_lists together. This modifies
649 * *left (to extend it and add the pointers from *right).
650 * \param[in] left the leftside
651 * \param[in] right the rightside
652 * \return a left with right concatenated to it
654 bool ldns_rr_list_cat(ldns_rr_list *left, const ldns_rr_list *right);
657 * concatenates two ldns_rr_lists together, but makes clones of the rr's
658 * (instead of pointer copying).
659 * \param[in] left the leftside
660 * \param[in] right the rightside
661 * \return a new rr_list with leftside/rightside concatenated
663 ldns_rr_list* ldns_rr_list_cat_clone(const ldns_rr_list *left, const ldns_rr_list *right);
666 * pushes an rr to an rrlist.
667 * \param[in] rr_list the rr_list to push to
668 * \param[in] rr the rr to push
669 * \return false on error, otherwise true
671 bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr);
674 * pushes an rr_list to an rrlist.
675 * \param[in] rr_list the rr_list to push to
676 * \param[in] push_list the rr_list to push
677 * \return false on error, otherwise true
679 bool ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list);
682 * pops the last rr from an rrlist.
683 * \param[in] rr_list the rr_list to pop from
684 * \return NULL if nothing to pop. Otherwise the popped RR
686 ldns_rr* ldns_rr_list_pop_rr(ldns_rr_list *rr_list);
689 * pops an rr_list of size s from an rrlist.
690 * \param[in] rr_list the rr_list to pop from
691 * \param[in] size the number of rr's to pop
692 * \return NULL if nothing to pop. Otherwise the popped rr_list
694 ldns_rr_list* ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t size);
697 * returns true if the given rr is one of the rrs in the
698 * list, or if it is equal to one
699 * \param[in] rr_list the rr_list to check
700 * \param[in] rr the rr to check
701 * \return true if rr_list contains rr, false otherwise
703 bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr);
706 * checks if an rr_list is a rrset.
707 * \param[in] rr_list the rr_list to check
708 * \return true if it is an rrset otherwise false
710 bool ldns_is_rrset(const ldns_rr_list *rr_list);
713 * pushes an rr to an rrset (which really are rr_list's).
714 * \param[in] *rr_list the rrset to push the rr to
715 * \param[in] *rr the rr to push
716 * \return true if the push succeeded otherwise false
718 bool ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr);
721 * pops the last rr from an rrset. This function is there only
723 * \param[in] rr_list the rr_list to pop from
724 * \return NULL if nothing to pop. Otherwise the popped RR
727 ldns_rr* ldns_rr_set_pop_rr(ldns_rr_list *rr_list);
730 * pops the first rrset from the list,
731 * the list must be sorted, so that all rr's from each rrset
732 * are next to each other
734 ldns_rr_list *ldns_rr_list_pop_rrset(ldns_rr_list *rr_list);
738 * retrieves a rrtype by looking up its name.
739 * \param[in] name a string with the name
740 * \return the type which corresponds with the name
742 ldns_rr_type ldns_get_rr_type_by_name(const char *name);
745 * retrieves a class by looking up its name.
746 * \param[in] name string with the name
747 * \return the cass which corresponds with the name
749 ldns_rr_class ldns_get_rr_class_by_name(const char *name);
752 * clones a rr and all its data
753 * \param[in] rr the rr to clone
754 * \return the new rr or NULL on failure
756 ldns_rr* ldns_rr_clone(const ldns_rr *rr);
760 * \param[in] rrlist the rrlist to clone
761 * \return the cloned rr list
763 ldns_rr_list* ldns_rr_list_clone(const ldns_rr_list *rrlist);
766 * sorts an rr_list (canonical wire format). the sorting is done inband.
767 * \param[in] unsorted the rr_list to be sorted
770 void ldns_rr_list_sort(ldns_rr_list *unsorted);
773 * compares two rrs. The TTL is not looked at.
774 * \param[in] rr1 the first one
775 * \param[in] rr2 the second one
777 * -1 if rr1 comes before rr2
778 * +1 if rr2 comes before rr1
780 int ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2);
783 * compares two rrs, up to the rdata.
784 * \param[in] rr1 the first one
785 * \param[in] rr2 the second one
787 * -1 if rr1 comes before rr2
788 * +1 if rr2 comes before rr1
790 int ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2);
793 * compares the wireformat of two rrs, contained in the given buffers.
794 * \param[in] rr1_buf the first one
795 * \param[in] rr2_buf the second one
797 * -1 if rr1_buf comes before rr2_buf
798 * +1 if rr2_buf comes before rr1_buf
800 int ldns_rr_compare_wire(const ldns_buffer *rr1_buf, const ldns_buffer *rr2_buf);
803 * returns true of the given rr's are equal.
804 * Also returns true if one record is a DS that represents the
805 * same DNSKEY record as the other record
806 * \param[in] rr1 the first rr
807 * \param[in] rr2 the second rr
808 * \return true if equal otherwise false
810 bool ldns_rr_compare_ds(const ldns_rr *rr1, const ldns_rr *rr2);
813 * compares two rr listss.
814 * \param[in] rrl1 the first one
815 * \param[in] rrl2 the second one
817 * -1 if rrl1 comes before rrl2
818 * +1 if rrl2 comes before rrl1
820 int ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2);
823 * calculates the uncompressed size of an RR.
824 * \param[in] r the rr to operate on
825 * \return size of the rr
827 size_t ldns_rr_uncompressed_size(const ldns_rr *r);
830 * converts each dname in a rr to its canonical form.
831 * \param[in] rr the rr to work on
834 void ldns_rr2canonical(ldns_rr *rr);
837 * converts each dname in each rr in a rr_list to its canonical form.
838 * \param[in] rr_list the rr_list to work on
841 void ldns_rr_list2canonical(const ldns_rr_list *rr_list);
844 * counts the number of labels of the ownername.
845 * \param[in] rr count the labels of this rr
846 * \return the number of labels
848 uint8_t ldns_rr_label_count(const ldns_rr *rr);
851 * returns the resource record descriptor for the given rr type.
853 * \param[in] type the type value of the rr type
854 *\return the ldns_rr_descriptor for this type
856 const ldns_rr_descriptor *ldns_rr_descript(uint16_t type);
859 * returns the minimum number of rdata fields of the rr type this descriptor describes.
861 * \param[in] descriptor for an rr type
862 * \return the minimum number of rdata fields
864 size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor);
867 * returns the maximum number of rdata fields of the rr type this descriptor describes.
869 * \param[in] descriptor for an rr type
870 * \return the maximum number of rdata fields
872 size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor);
875 * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
877 * \param[in] descriptor for an rr type
878 * \param[in] field the field number
879 * \return the rdf type for the field
881 ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field);
884 * Return the rr_list which matches the rdf at position field. Think
885 * type-covered stuff for RRSIG
887 * \param[in] l the rr_list to look in
888 * \param[in] r the rdf to use for the comparison
889 * \param[in] pos at which position can we find the rdf
891 * \return a new rr list with only the RRs that match
894 ldns_rr_list *ldns_rr_list_subtype_by_rdf(const ldns_rr_list *l, const ldns_rdf *r, size_t pos);
897 * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
898 * LDNS_RR_TYPE. This is useful in the case when inspecting
899 * the rrtype covered field of an RRSIG.
900 * \param[in] rd the rdf to look at
901 * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
904 ldns_rr_type ldns_rdf2rr_type(const ldns_rdf *rd);
907 * Returns the type of the first element of the RR
908 * If there are no elements present, 0 is returned
910 * \param[in] rr_list The rr list
911 * \return rr_type of the first element, or 0 if the list is empty
914 ldns_rr_list_type(const ldns_rr_list *rr_list);
917 * Returns the owner domain name rdf of the first element of the RR
918 * If there are no elements present, NULL is returned
920 * \param[in] rr_list The rr list
921 * \return dname of the first element, or NULL if the list is empty
924 ldns_rr_list_owner(const ldns_rr_list *rr_list);
930 #endif /* LDNS_RR_H */