2 * Copyright (C) 2004-2010, 2012-2015 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
19 #define DNS_MESSAGE_H 1
26 #include <isc/magic.h>
28 #include <dns/compress.h>
29 #include <dns/masterdump.h>
30 #include <dns/types.h>
34 /*! \file dns/message.h
35 * \brief Message Handling Module
37 * How this beast works:
39 * When a dns message is received in a buffer, dns_message_fromwire() is called
40 * on the memory region. Various items are checked including the format
41 * of the message (if counts are right, if counts consume the entire sections,
42 * and if sections consume the entire message) and known pseudo-RRs in the
43 * additional data section are analyzed and removed.
45 * TSIG checking is also done at this layer, and any DNSSEC transaction
46 * signatures should also be checked here.
48 * Notes on using the gettemp*() and puttemp*() functions:
50 * These functions return items (names, rdatasets, etc) allocated from some
51 * internal state of the dns_message_t.
53 * Names and rdatasets must be put back into the dns_message_t in
54 * one of two ways. Assume a name was allocated via
55 * dns_message_gettempname():
57 *\li (1) insert it into a section, using dns_message_addname().
59 *\li (2) return it to the message using dns_message_puttempname().
61 * The same applies to rdatasets.
63 * On the other hand, offsets, rdatalists and rdatas allocated using
64 * dns_message_gettemp*() will always be freed automatically
65 * when the message is reset or destroyed; calling dns_message_puttemp*()
66 * on rdatalists and rdatas is optional and serves only to enable the item
67 * to be reused multiple times during the lifetime of the message; offsets
70 * Buffers allocated using isc_buffer_allocate() can be automatically freed
71 * as well by giving the buffer to the message using dns_message_takebuffer().
72 * Doing this will cause the buffer to be freed using isc_buffer_free()
73 * when the section lists are cleared, such as in a reset or in a destroy.
74 * Since the buffer itself exists until the message is destroyed, this sort
75 * of code can be written:
78 * buffer = isc_buffer_allocate(mctx, 512);
80 * name = dns_message_gettempname(message, &name);
81 * dns_name_init(name, NULL);
82 * result = dns_name_fromtext(name, &source, dns_rootname, 0, buffer);
83 * dns_message_takebuffer(message, &buffer);
89 * XXX Needed: ways to set and retrieve EDNS information, add rdata to a
90 * section, move rdata from one section to another, remove rdata, etc.
93 #define DNS_MESSAGEFLAG_QR 0x8000U
94 #define DNS_MESSAGEFLAG_AA 0x0400U
95 #define DNS_MESSAGEFLAG_TC 0x0200U
96 #define DNS_MESSAGEFLAG_RD 0x0100U
97 #define DNS_MESSAGEFLAG_RA 0x0080U
98 #define DNS_MESSAGEFLAG_AD 0x0020U
99 #define DNS_MESSAGEFLAG_CD 0x0010U
101 /*%< EDNS0 extended message flags */
102 #define DNS_MESSAGEEXTFLAG_DO 0x8000U
104 /*%< EDNS0 extended OPT codes */
105 #define DNS_OPT_NSID 0x0003 /*%< NSID opt code */
106 #define DNS_OPT_CLIENT_SUBNET 0x0008 /*%< client subnet opt code */
107 #define DNS_OPT_EXPIRE 0x0009 /*%< EXPIRE opt code */
108 #define DNS_OPT_COOKIE 0x000a /*%< COOKIE opt code */
110 /*%< The number of EDNS options we know about. */
111 #define DNS_EDNSOPTIONS 4
113 #define DNS_MESSAGE_REPLYPRESERVE (DNS_MESSAGEFLAG_RD|DNS_MESSAGEFLAG_CD)
114 #define DNS_MESSAGEEXTFLAG_REPLYPRESERVE (DNS_MESSAGEEXTFLAG_DO)
116 #define DNS_MESSAGE_HEADERLEN 12 /*%< 6 isc_uint16_t's */
118 #define DNS_MESSAGE_MAGIC ISC_MAGIC('M','S','G','@')
119 #define DNS_MESSAGE_VALID(msg) ISC_MAGIC_VALID(msg, DNS_MESSAGE_MAGIC)
122 * Ordering here matters. DNS_SECTION_ANY must be the lowest and negative,
123 * and DNS_SECTION_MAX must be one greater than the last used section.
125 typedef int dns_section_t;
126 #define DNS_SECTION_ANY (-1)
127 #define DNS_SECTION_QUESTION 0
128 #define DNS_SECTION_ANSWER 1
129 #define DNS_SECTION_AUTHORITY 2
130 #define DNS_SECTION_ADDITIONAL 3
131 #define DNS_SECTION_MAX 4
133 typedef int dns_pseudosection_t;
134 #define DNS_PSEUDOSECTION_ANY (-1)
135 #define DNS_PSEUDOSECTION_OPT 0
136 #define DNS_PSEUDOSECTION_TSIG 1
137 #define DNS_PSEUDOSECTION_SIG0 2
138 #define DNS_PSEUDOSECTION_MAX 3
140 typedef int dns_messagetextflag_t;
141 #define DNS_MESSAGETEXTFLAG_NOCOMMENTS 0x0001
142 #define DNS_MESSAGETEXTFLAG_NOHEADERS 0x0002
143 #define DNS_MESSAGETEXTFLAG_ONESOA 0x0004
144 #define DNS_MESSAGETEXTFLAG_OMITSOA 0x0008
147 * Dynamic update names for these sections.
149 #define DNS_SECTION_ZONE DNS_SECTION_QUESTION
150 #define DNS_SECTION_PREREQUISITE DNS_SECTION_ANSWER
151 #define DNS_SECTION_UPDATE DNS_SECTION_AUTHORITY
154 * These tell the message library how the created dns_message_t will be used.
156 #define DNS_MESSAGE_INTENTUNKNOWN 0 /*%< internal use only */
157 #define DNS_MESSAGE_INTENTPARSE 1 /*%< parsing messages */
158 #define DNS_MESSAGE_INTENTRENDER 2 /*%< rendering */
161 * Control behavior of parsing
163 #define DNS_MESSAGEPARSE_PRESERVEORDER 0x0001 /*%< preserve rdata order */
164 #define DNS_MESSAGEPARSE_BESTEFFORT 0x0002 /*%< return a message if a
165 recoverable parse error
167 #define DNS_MESSAGEPARSE_CLONEBUFFER 0x0004 /*%< save a copy of the
169 #define DNS_MESSAGEPARSE_IGNORETRUNCATION 0x0008 /*%< truncation errors are
173 * Control behavior of rendering
175 #define DNS_MESSAGERENDER_ORDERED 0x0001 /*%< don't change order */
176 #define DNS_MESSAGERENDER_PARTIAL 0x0002 /*%< allow a partial rdataset */
177 #define DNS_MESSAGERENDER_OMITDNSSEC 0x0004 /*%< omit DNSSEC records */
178 #define DNS_MESSAGERENDER_PREFER_A 0x0008 /*%< prefer A records in
179 additional section. */
180 #define DNS_MESSAGERENDER_PREFER_AAAA 0x0010 /*%< prefer AAAA records in
181 additional section. */
182 #ifdef ALLOW_FILTER_AAAA_ON_V4
183 #define DNS_MESSAGERENDER_FILTER_AAAA 0x0020 /*%< filter AAAA records */
186 typedef struct dns_msgblock dns_msgblock_t;
189 /* public from here down */
196 dns_rdataclass_t rdclass;
198 /* 4 real, 1 pseudo */
199 unsigned int counts[DNS_SECTION_MAX];
201 /* private from here down */
202 dns_namelist_t sections[DNS_SECTION_MAX];
203 dns_name_t *cursors[DNS_SECTION_MAX];
205 dns_rdataset_t *sig0;
206 dns_rdataset_t *tsig;
209 unsigned int from_to_wire : 2;
210 unsigned int header_ok : 1;
211 unsigned int question_ok : 1;
212 unsigned int tcp_continuation : 1;
213 unsigned int verified_sig : 1;
214 unsigned int verify_attempted : 1;
215 unsigned int free_query : 1;
216 unsigned int free_saved : 1;
217 unsigned int tkey : 1;
218 unsigned int rdclass_set : 1;
220 unsigned int opt_reserved;
221 unsigned int sig_reserved;
222 unsigned int reserved; /* reserved space (render) */
224 isc_buffer_t *buffer;
225 dns_compress_t *cctx;
228 isc_mempool_t *namepool;
229 isc_mempool_t *rdspool;
231 isc_bufferlist_t scratchpad;
232 isc_bufferlist_t cleanup;
234 ISC_LIST(dns_msgblock_t) rdatas;
235 ISC_LIST(dns_msgblock_t) rdatalists;
236 ISC_LIST(dns_msgblock_t) offsets;
238 ISC_LIST(dns_rdata_t) freerdata;
239 ISC_LIST(dns_rdatalist_t) freerdatalist;
241 dns_rcode_t tsigstatus;
242 dns_rcode_t querytsigstatus;
243 dns_name_t *tsigname; /* Owner name of TSIG, if any */
244 dns_rdataset_t *querytsig;
245 dns_tsigkey_t *tsigkey;
246 dst_context_t *tsigctx;
250 dns_name_t *sig0name; /* Owner name of SIG0, if any */
252 dns_rcode_t sig0status;
256 dns_rdatasetorderfunc_t order;
257 const void * order_arg;
263 unsigned char *value;
273 dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp);
276 * Create msg structure.
278 * This function will allocate some internal blocks of memory that are
279 * expected to be needed for parsing or rendering nearly any type of message.
282 *\li 'mctx' be a valid memory context.
284 *\li 'msgp' be non-null and '*msg' be NULL.
286 *\li 'intent' must be one of DNS_MESSAGE_INTENTPARSE or
287 * #DNS_MESSAGE_INTENTRENDER.
290 *\li The data in "*msg" is set to indicate an unused and empty msg
294 *\li #ISC_R_NOMEMORY -- out of memory
295 *\li #ISC_R_SUCCESS -- success
299 dns_message_reset(dns_message_t *msg, unsigned int intent);
301 * Reset a message structure to default state. All internal lists are freed
302 * or reset to a default state as well. This is simply a more efficient
303 * way to call dns_message_destroy() followed by dns_message_allocate(),
304 * since it avoid many memory allocations.
306 * If any data loanouts (buffers, names, rdatas, etc) were requested,
307 * the caller must no longer use them after this call.
309 * The intended next use of the message will be 'intent'.
315 *\li 'intent' is DNS_MESSAGE_INTENTPARSE or DNS_MESSAGE_INTENTRENDER
319 dns_message_destroy(dns_message_t **msgp);
321 * Destroy all state in the message.
325 *\li 'msgp' be valid.
332 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
333 const dns_master_style_t *style,
334 dns_messagetextflag_t flags,
335 isc_buffer_t *target);
338 dns_message_pseudosectiontotext(dns_message_t *msg,
339 dns_pseudosection_t section,
340 const dns_master_style_t *style,
341 dns_messagetextflag_t flags,
342 isc_buffer_t *target);
344 * Convert section 'section' or 'pseudosection' of message 'msg' to
345 * a cleartext representation
348 * \li See dns_message_totext for meanings of flags.
352 *\li 'msg' is a valid message.
354 *\li 'style' is a valid master dump style.
356 *\li 'target' is a valid buffer.
358 *\li 'section' is a valid section label.
362 *\li If the result is success:
363 * The used space in 'target' is updated.
371 *\li Note: On error return, *target may be partially filled with data.
375 dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
376 dns_messagetextflag_t flags, isc_buffer_t *target);
378 * Convert all sections of message 'msg' to a cleartext representation
381 * \li In flags, If #DNS_MESSAGETEXTFLAG_OMITDOT is set, then the
382 * final '.' in absolute names will not be emitted. If
383 * #DNS_MESSAGETEXTFLAG_NOCOMMENTS is cleared, lines beginning
384 * with ";;" will be emitted indicating section name. If
385 * #DNS_MESSAGETEXTFLAG_NOHEADERS is cleared, header lines will
388 * If #DNS_MESSAGETEXTFLAG_ONESOA is set then only print the
389 * first SOA record in the answer section. If
390 * #DNS_MESSAGETEXTFLAG_OMITSOA is set don't print any SOA records
391 * in the answer section. These are useful for suppressing the
392 * display of the second SOA record in a AXFR by setting
393 * #DNS_MESSAGETEXTFLAG_ONESOA on the first message in a AXFR stream
394 * and #DNS_MESSAGETEXTFLAG_OMITSOA on subsequent messages.
398 *\li 'msg' is a valid message.
400 *\li 'style' is a valid master dump style.
402 *\li 'target' is a valid buffer.
406 *\li If the result is success:
407 * The used space in 'target' is updated.
415 *\li Note: On error return, *target may be partially filled with data.
419 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
420 unsigned int options);
422 * Parse raw wire data in 'source' as a DNS message.
424 * OPT records are detected and stored in the pseudo-section "opt".
425 * TSIGs are detected and stored in the pseudo-section "tsig".
427 * If #DNS_MESSAGEPARSE_PRESERVEORDER is set, or if the opcode of the message
428 * is UPDATE, a separate dns_name_t object will be created for each RR in the
429 * message. Each such dns_name_t will have a single rdataset containing the
430 * single RR, and the order of the RRs in the message is preserved.
431 * Otherwise, only one dns_name_t object will be created for each unique
432 * owner name in the section, and each such dns_name_t will have a list
433 * of rdatasets. To access the names and their data, use
434 * dns_message_firstname() and dns_message_nextname().
436 * If #DNS_MESSAGEPARSE_BESTEFFORT is set, errors in message content will
437 * not be considered FORMERRs. If the entire message can be parsed, it
438 * will be returned and DNS_R_RECOVERABLE will be returned.
440 * If #DNS_MESSAGEPARSE_IGNORETRUNCATION is set then return as many complete
441 * RR's as possible, DNS_R_RECOVERABLE will be returned.
443 * OPT and TSIG records are always handled specially, regardless of the
444 * 'preserve_order' setting.
449 *\li "buffer" be a wire format buffer.
452 *\li The buffer's data format is correct.
454 *\li The buffer's contents verify as correct regarding header bits, buffer
455 * and rdata sizes, etc.
458 *\li #ISC_R_SUCCESS -- all is well
459 *\li #ISC_R_NOMEMORY -- no memory
460 *\li #DNS_R_RECOVERABLE -- the message parsed properly, but contained
462 *\li Many other errors possible XXXMLG
466 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
467 isc_buffer_t *buffer);
469 * Begin rendering on a message. Only one call can be made to this function
472 * The compression context is "owned" by the message library until
473 * dns_message_renderend() is called. It must be invalidated by the caller.
475 * The buffer is "owned" by the message library until dns_message_renderend()
482 *\li 'cctx' be valid.
484 *\li 'buffer' is a valid buffer.
488 *\li The buffer is cleared before it is used.
491 *\li #ISC_R_SUCCESS -- all is well
492 *\li #ISC_R_NOSPACE -- output buffer is too small
496 dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer);
498 * Reset the buffer. This can be used after growing the old buffer
499 * on a ISC_R_NOSPACE return from most of the render functions.
501 * On successful completion, the old buffer is no longer used by the
502 * library. The new buffer is owned by the library until
503 * dns_message_renderend() is called.
509 *\li dns_message_renderbegin() was called.
514 *\li #ISC_R_NOSPACE -- new buffer is too small
515 *\li #ISC_R_SUCCESS -- all is well.
519 dns_message_renderreserve(dns_message_t *msg, unsigned int space);
521 * XXXMLG should use size_t rather than unsigned int once the buffer
524 * Reserve "space" bytes in the given buffer.
530 *\li dns_message_renderbegin() was called.
533 *\li #ISC_R_SUCCESS -- all is well.
534 *\li #ISC_R_NOSPACE -- not enough free space in the buffer.
538 dns_message_renderrelease(dns_message_t *msg, unsigned int space);
540 * XXXMLG should use size_t rather than unsigned int once the buffer
543 * Release "space" bytes in the given buffer that was previously reserved.
549 *\li 'space' is less than or equal to the total amount of space reserved
550 * via prior calls to dns_message_renderreserve().
552 *\li dns_message_renderbegin() was called.
556 dns_message_rendersection(dns_message_t *msg, dns_section_t section,
557 unsigned int options);
559 * Render all names, rdatalists, etc from the given section at the
560 * specified priority or higher.
565 *\li 'section' be a valid section.
567 *\li dns_message_renderbegin() was called.
570 *\li #ISC_R_SUCCESS -- all records were written, and there are
571 * no more records for this section.
572 *\li #ISC_R_NOSPACE -- Not enough room in the buffer to write
573 * all records requested.
574 *\li #DNS_R_MOREDATA -- All requested records written, and there
575 * are records remaining for this section.
579 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target);
581 * Render the message header. This is implicitly called by
582 * dns_message_renderend().
586 *\li 'msg' be a valid message.
588 *\li dns_message_renderbegin() was called.
590 *\li 'target' is a valid buffer with enough space to hold a message header
594 dns_message_renderend(dns_message_t *msg);
596 * Finish rendering to the buffer. Note that more data can be in the
597 * 'msg' structure. Destroying the structure will free this, or in a multi-
598 * part EDNS1 message this data can be rendered to another buffer later.
602 *\li 'msg' be a valid message.
604 *\li dns_message_renderbegin() was called.
607 *\li #ISC_R_SUCCESS -- all is well.
611 dns_message_renderreset(dns_message_t *msg);
613 * Reset the message so that it may be rendered again.
617 *\li If dns_message_renderbegin() has been called, dns_message_renderend()
618 * must be called before calling this function.
622 *\li 'msg' be a valid message with rendering intent.
626 dns_message_firstname(dns_message_t *msg, dns_section_t section);
628 * Set internal per-section name pointer to the beginning of the section.
630 * The functions dns_message_firstname() and dns_message_nextname() may
631 * be used for iterating over the owner names in a section.
637 *\li 'section' be a valid section.
640 *\li #ISC_R_SUCCESS -- All is well.
641 *\li #ISC_R_NOMORE -- No names on given section.
645 dns_message_nextname(dns_message_t *msg, dns_section_t section);
647 * Sets the internal per-section name pointer to point to the next name
652 * \li 'msg' be valid.
654 *\li 'section' be a valid section.
656 *\li dns_message_firstname() must have been called on this section,
657 * and the result was ISC_R_SUCCESS.
660 *\li #ISC_R_SUCCESS -- All is well.
661 *\li #ISC_R_NOMORE -- No more names in given section.
665 dns_message_currentname(dns_message_t *msg, dns_section_t section,
668 * Sets 'name' to point to the name where the per-section internal name
669 * pointer is currently set.
671 * This function returns the name in the database, so any data associated
672 * with it (via the name's "list" member) contains the actual rdatasets.
678 *\li 'name' be non-NULL, and *name be NULL.
680 *\li 'section' be a valid section.
682 *\li dns_message_firstname() must have been called on this section,
683 * and the result of it and any dns_message_nextname() calls was
688 dns_message_findname(dns_message_t *msg, dns_section_t section,
689 dns_name_t *target, dns_rdatatype_t type,
690 dns_rdatatype_t covers, dns_name_t **foundname,
691 dns_rdataset_t **rdataset);
693 * Search for a name in the specified section. If it is found, *name is
694 * set to point to the name, and *rdataset is set to point to the found
695 * rdataset (if type is specified as other than dns_rdatatype_any).
700 *\li 'section' be a valid section.
702 *\li If a pointer to the name is desired, 'foundname' should be non-NULL.
703 * If it is non-NULL, '*foundname' MUST be NULL.
705 *\li If a type other than dns_datatype_any is searched for, 'rdataset'
706 * may be non-NULL, '*rdataset' be NULL, and will point at the found
707 * rdataset. If the type is dns_datatype_any, 'rdataset' must be NULL.
709 *\li 'target' be a valid name.
711 *\li 'type' be a valid type.
713 *\li If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
714 * Otherwise it should be 0.
717 *\li #ISC_R_SUCCESS -- all is well.
718 *\li #DNS_R_NXDOMAIN -- name does not exist in that section.
719 *\li #DNS_R_NXRRSET -- The name does exist, but the desired
724 dns_message_findtype(dns_name_t *name, dns_rdatatype_t type,
725 dns_rdatatype_t covers, dns_rdataset_t **rdataset);
727 * Search the name for the specified type. If it is found, *rdataset is
728 * filled in with a pointer to that rdataset.
731 *\li if '**rdataset' is non-NULL, *rdataset needs to be NULL.
733 *\li 'type' be a valid type, and NOT dns_rdatatype_any.
735 *\li If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
736 * Otherwise it should be 0.
739 *\li #ISC_R_SUCCESS -- all is well.
740 *\li #ISC_R_NOTFOUND -- the desired type does not exist.
744 dns_message_find(dns_name_t *name, dns_rdataclass_t rdclass,
745 dns_rdatatype_t type, dns_rdatatype_t covers,
746 dns_rdataset_t **rdataset);
748 * Search the name for the specified rdclass and type. If it is found,
749 * *rdataset is filled in with a pointer to that rdataset.
752 *\li if '**rdataset' is non-NULL, *rdataset needs to be NULL.
754 *\li 'type' be a valid type, and NOT dns_rdatatype_any.
756 *\li If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
757 * Otherwise it should be 0.
760 *\li #ISC_R_SUCCESS -- all is well.
761 *\li #ISC_R_NOTFOUND -- the desired type does not exist.
765 dns_message_movename(dns_message_t *msg, dns_name_t *name,
766 dns_section_t fromsection,
767 dns_section_t tosection);
769 * Move a name from one section to another.
775 *\li 'name' must be a name already in 'fromsection'.
777 *\li 'fromsection' must be a valid section.
779 *\li 'tosection' must be a valid section.
783 dns_message_addname(dns_message_t *msg, dns_name_t *name,
784 dns_section_t section);
786 * Adds the name to the given section.
788 * It is the caller's responsibility to enforce any unique name requirements
793 *\li 'msg' be valid, and be a renderable message.
795 *\li 'name' be a valid absolute name.
797 *\li 'section' be a named section.
801 dns_message_removename(dns_message_t *msg, dns_name_t *name,
802 dns_section_t section);
804 * Remove a existing name from a given section.
806 * It is the caller's responsibility to ensure the name is part of the
811 *\li 'msg' be valid, and be a renderable message.
813 *\li 'name' be a valid absolute name.
815 *\li 'section' be a named section.
822 * Each of these functions loan a particular type of data to the caller.
823 * The storage for these will vanish when the message is destroyed or
824 * reset, and must NOT be used after these operations.
828 dns_message_gettempname(dns_message_t *msg, dns_name_t **item);
830 * Return a name that can be used for any temporary purpose, including
831 * inserting into the message's linked lists. The name must be returned
832 * to the message code using dns_message_puttempname() or inserted into
833 * one of the message's sections before the message is destroyed.
835 * It is the caller's responsibility to initialize this name.
838 *\li msg be a valid message
840 *\li item != NULL && *item == NULL
843 *\li #ISC_R_SUCCESS -- All is well.
844 *\li #ISC_R_NOMEMORY -- No item can be allocated.
848 dns_message_gettempoffsets(dns_message_t *msg, dns_offsets_t **item);
850 * Return an offsets array that can be used for any temporary purpose,
851 * such as attaching to a temporary name. The offsets will be freed
852 * when the message is destroyed or reset.
855 *\li msg be a valid message
857 *\li item != NULL && *item == NULL
860 *\li #ISC_R_SUCCESS -- All is well.
861 *\li #ISC_R_NOMEMORY -- No item can be allocated.
865 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item);
867 * Return a rdata that can be used for any temporary purpose, including
868 * inserting into the message's linked lists. The rdata will be freed
869 * when the message is destroyed or reset.
872 *\li msg be a valid message
874 *\li item != NULL && *item == NULL
877 *\li #ISC_R_SUCCESS -- All is well.
878 *\li #ISC_R_NOMEMORY -- No item can be allocated.
882 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item);
884 * Return a rdataset that can be used for any temporary purpose, including
885 * inserting into the message's linked lists. The name must be returned
886 * to the message code using dns_message_puttempname() or inserted into
887 * one of the message's sections before the message is destroyed.
890 *\li msg be a valid message
892 *\li item != NULL && *item == NULL
895 *\li #ISC_R_SUCCESS -- All is well.
896 *\li #ISC_R_NOMEMORY -- No item can be allocated.
900 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
902 * Return a rdatalist that can be used for any temporary purpose, including
903 * inserting into the message's linked lists. The rdatalist will be
904 * destroyed when the message is destroyed or reset.
907 *\li msg be a valid message
909 *\li item != NULL && *item == NULL
912 *\li #ISC_R_SUCCESS -- All is well.
913 *\li #ISC_R_NOMEMORY -- No item can be allocated.
917 dns_message_puttempname(dns_message_t *msg, dns_name_t **item);
919 * Return a borrowed name to the message's name free list.
922 *\li msg be a valid message
924 *\li item != NULL && *item point to a name returned by
925 * dns_message_gettempname()
932 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item);
934 * Return a borrowed rdata to the message's rdata free list.
937 *\li msg be a valid message
939 *\li item != NULL && *item point to a rdata returned by
940 * dns_message_gettemprdata()
947 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item);
949 * Return a borrowed rdataset to the message's rdataset free list.
952 *\li msg be a valid message
954 *\li item != NULL && *item point to a rdataset returned by
955 * dns_message_gettemprdataset()
962 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
964 * Return a borrowed rdatalist to the message's rdatalist free list.
967 *\li msg be a valid message
969 *\li item != NULL && *item point to a rdatalist returned by
970 * dns_message_gettemprdatalist()
977 dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp,
978 unsigned int *flagsp);
980 * Assume the remaining region of "source" is a DNS message. Peek into
981 * it and fill in "*idp" with the message id, and "*flagsp" with the flags.
989 *\li if (idp != NULL) *idp == message id.
991 *\li if (flagsp != NULL) *flagsp == message flags.
995 *\li #ISC_R_SUCCESS -- all is well.
997 *\li #ISC_R_UNEXPECTEDEND -- buffer doesn't contain enough for a header.
1001 dns_message_reply(dns_message_t *msg, isc_boolean_t want_question_section);
1003 * Start formatting a reply to the query in 'msg'.
1007 *\li 'msg' is a valid message with parsing intent, and contains a query.
1011 *\li The message will have a rendering intent. If 'want_question_section'
1012 * is true, the message opcode is query or notify, and the question
1013 * section is present and properly formatted, then the question section
1014 * will be included in the reply. All other sections will be cleared.
1015 * The QR flag will be set, the RD flag will be preserved, and all other
1016 * flags will be cleared.
1020 *\li #ISC_R_SUCCESS -- all is well.
1022 *\li #DNS_R_FORMERR -- the header or question section of the
1023 * message is invalid, replying is impossible.
1024 * If DNS_R_FORMERR is returned when
1025 * want_question_section is ISC_FALSE, then
1026 * it's the header section that's bad;
1027 * otherwise either of the header or question
1028 * sections may be bad.
1032 dns_message_getopt(dns_message_t *msg);
1034 * Get the OPT record for 'msg'.
1038 *\li 'msg' is a valid message.
1042 *\li The OPT rdataset of 'msg', or NULL if there isn't one.
1046 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt);
1048 * Set the OPT record for 'msg'.
1052 *\li 'msg' is a valid message with rendering intent
1053 * and no sections have been rendered.
1055 *\li 'opt' is a valid OPT record.
1059 *\li The OPT record has either been freed or ownership of it has
1060 * been transferred to the message.
1062 *\li If ISC_R_SUCCESS was returned, the OPT record will be rendered
1063 * when dns_message_renderend() is called.
1067 *\li #ISC_R_SUCCESS -- all is well.
1069 *\li #ISC_R_NOSPACE -- there is no space for the OPT record.
1073 dns_message_gettsig(dns_message_t *msg, dns_name_t **owner);
1075 * Get the TSIG record and owner for 'msg'.
1079 *\li 'msg' is a valid message.
1080 *\li 'owner' is NULL or *owner is NULL.
1084 *\li The TSIG rdataset of 'msg', or NULL if there isn't one.
1088 * \li If 'owner' is not NULL, it will point to the owner name.
1092 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key);
1094 * Set the tsig key for 'msg'. This is only necessary for when rendering a
1095 * query or parsing a response. The key (if non-NULL) is attached to, and
1096 * will be detached when the message is destroyed.
1100 *\li 'msg' is a valid message with rendering intent,
1101 * dns_message_renderbegin() has been called, and no sections have been
1103 *\li 'key' is a valid tsig key or NULL.
1107 *\li #ISC_R_SUCCESS -- all is well.
1109 *\li #ISC_R_NOSPACE -- there is no space for the TSIG record.
1113 dns_message_gettsigkey(dns_message_t *msg);
1115 * Gets the tsig key for 'msg'.
1119 *\li 'msg' is a valid message
1123 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig);
1125 * Indicates that 'querytsig' is the TSIG from the signed query for which
1126 * 'msg' is the response. This is also used for chained TSIGs in TCP
1131 *\li 'querytsig' is a valid buffer as returned by dns_message_getquerytsig()
1134 *\li 'msg' is a valid message
1139 *\li #ISC_R_NOMEMORY
1143 dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
1144 isc_buffer_t **querytsig);
1146 * Gets the tsig from the TSIG from the signed query 'msg'. This is also used
1147 * for chained TSIGs in TCP responses. Unlike dns_message_gettsig, this makes
1148 * a copy of the data, so can be used if the message is destroyed.
1152 *\li 'msg' is a valid signed message
1153 *\li 'mctx' is a valid memory context
1154 *\li querytsig != NULL && *querytsig == NULL
1159 *\li #ISC_R_NOMEMORY
1162 *\li 'tsig' points to NULL or an allocated buffer which must be freed
1167 dns_message_getsig0(dns_message_t *msg, dns_name_t **owner);
1169 * Get the SIG(0) record and owner for 'msg'.
1173 *\li 'msg' is a valid message.
1174 *\li 'owner' is NULL or *owner is NULL.
1178 *\li The SIG(0) rdataset of 'msg', or NULL if there isn't one.
1182 * \li If 'owner' is not NULL, it will point to the owner name.
1186 dns_message_setsig0key(dns_message_t *msg, dst_key_t *key);
1188 * Set the SIG(0) key for 'msg'.
1192 *\li 'msg' is a valid message with rendering intent,
1193 * dns_message_renderbegin() has been called, and no sections have been
1195 *\li 'key' is a valid sig key or NULL.
1199 *\li #ISC_R_SUCCESS -- all is well.
1201 *\li #ISC_R_NOSPACE -- there is no space for the SIG(0) record.
1205 dns_message_getsig0key(dns_message_t *msg);
1207 * Gets the SIG(0) key for 'msg'.
1211 *\li 'msg' is a valid message
1215 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer);
1217 * Give the *buffer to the message code to clean up when it is no
1218 * longer needed. This is usually when the message is reset or
1223 *\li msg be a valid message.
1225 *\li buffer != NULL && *buffer is a valid isc_buffer_t, which was
1226 * dynamically allocated via isc_buffer_allocate().
1230 dns_message_signer(dns_message_t *msg, dns_name_t *signer);
1232 * If this message was signed, return the identity of the signer.
1233 * Unless ISC_R_NOTFOUND is returned, signer will reflect the name of the
1234 * key that signed the message.
1238 *\li msg is a valid parsed message.
1239 *\li signer is a valid name
1243 *\li #ISC_R_SUCCESS - the message was signed, and *signer
1244 * contains the signing identity
1246 *\li #ISC_R_NOTFOUND - no TSIG or SIG(0) record is present in the
1249 *\li #DNS_R_TSIGVERIFYFAILURE - the message was signed by a TSIG, but the
1250 * signature failed to verify
1252 *\li #DNS_R_TSIGERRORSET - the message was signed by a TSIG and
1253 * verified, but the query was rejected by
1256 *\li #DNS_R_NOIDENTITY - the message was signed by a TSIG and
1257 * verified, but the key has no identity since
1258 * it was generated by an unsigned TKEY process
1260 *\li #DNS_R_SIGINVALID - the message was signed by a SIG(0), but
1261 * the signature failed to verify
1263 *\li #DNS_R_NOTVERIFIEDYET - the message was signed by a TSIG or SIG(0),
1264 * but the signature has not been verified yet
1268 dns_message_checksig(dns_message_t *msg, dns_view_t *view);
1270 * If this message was signed, verify the signature.
1274 *\li msg is a valid parsed message.
1275 *\li view is a valid view or NULL
1279 *\li #ISC_R_SUCCESS - the message was unsigned, or the message
1280 * was signed correctly.
1282 *\li #DNS_R_EXPECTEDTSIG - A TSIG was expected, but not seen
1283 *\li #DNS_R_UNEXPECTEDTSIG - A TSIG was seen but not expected
1284 *\li #DNS_R_TSIGVERIFYFAILURE - The TSIG failed to verify
1288 dns_message_rechecksig(dns_message_t *msg, dns_view_t *view);
1290 * Reset the signature state and then if the message was signed,
1291 * verify the message.
1295 *\li msg is a valid parsed message.
1296 *\li view is a valid view or NULL
1300 *\li #ISC_R_SUCCESS - the message was unsigned, or the message
1301 * was signed correctly.
1303 *\li #DNS_R_EXPECTEDTSIG - A TSIG was expected, but not seen
1304 *\li #DNS_R_UNEXPECTEDTSIG - A TSIG was seen but not expected
1305 *\li #DNS_R_TSIGVERIFYFAILURE - The TSIG failed to verify
1309 dns_message_resetsig(dns_message_t *msg);
1311 * Reset the signature state.
1314 *\li 'msg' is a valid parsed message.
1318 dns_message_getrawmessage(dns_message_t *msg);
1320 * Retrieve the raw message in compressed wire format. The message must
1321 * have been successfully parsed for it to have been saved.
1324 *\li msg is a valid parsed message.
1327 *\li NULL if there is no saved message.
1328 * a pointer to a region which refers the dns message.
1332 dns_message_setsortorder(dns_message_t *msg, dns_rdatasetorderfunc_t order,
1333 const void *order_arg);
1335 * Define the order in which RR sets get rendered by
1336 * dns_message_rendersection() to be the ascending order
1337 * defined by the integer value returned by 'order' when
1338 * given each RR and 'arg' as arguments. If 'order' and
1339 * 'order_arg' are NULL, a default order is used.
1342 *\li msg be a valid message.
1343 *\li order_arg is NULL if and only if order is NULL.
1347 dns_message_settimeadjust(dns_message_t *msg, int timeadjust);
1349 * Adjust the time used to sign/verify a message by timeadjust.
1350 * Currently only TSIG.
1353 *\li msg be a valid message.
1357 dns_message_gettimeadjust(dns_message_t *msg);
1359 * Return the current time adjustment.
1362 *\li msg be a valid message.
1366 dns_message_buildopt(dns_message_t *msg, dns_rdataset_t **opt,
1367 unsigned int version, isc_uint16_t udpsize,
1368 unsigned int flags, dns_ednsopt_t *ednsopts, size_t count);
1370 * Built a opt record.
1373 * \li msg be a valid message.
1374 * \li opt to be a non NULL and *opt to be NULL.
1377 * \li ISC_R_SUCCESS on success.
1378 * \li ISC_R_NOMEMORY
1384 dns_message_setclass(dns_message_t *msg, dns_rdataclass_t rdclass);
1386 * Set the expected class of records in the response.
1389 * \li msg be a valid message with parsing intent.
1394 #endif /* DNS_MESSAGE_H */