2 * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
18 /* $Id: message.h,v 1.114.18.6 2006/03/02 23:19:20 marka Exp $ */
21 #define DNS_MESSAGE_H 1
28 #include <isc/magic.h>
30 #include <dns/compress.h>
31 #include <dns/masterdump.h>
32 #include <dns/types.h>
37 * \brief Message Handling Module
39 * How this beast works:
41 * When a dns message is received in a buffer, dns_message_fromwire() is called
42 * on the memory region. Various items are checked including the format
43 * of the message (if counts are right, if counts consume the entire sections,
44 * and if sections consume the entire message) and known pseudo-RRs in the
45 * additional data section are analyzed and removed.
47 * TSIG checking is also done at this layer, and any DNSSEC transaction
48 * signatures should also be checked here.
50 * Notes on using the gettemp*() and puttemp*() functions:
52 * These functions return items (names, rdatasets, etc) allocated from some
53 * internal state of the dns_message_t.
55 * Names and rdatasets must be put back into the dns_message_t in
56 * one of two ways. Assume a name was allocated via
57 * dns_message_gettempname():
59 *\li (1) insert it into a section, using dns_message_addname().
61 *\li (2) return it to the message using dns_message_puttempname().
63 * The same applies to rdatasets.
65 * On the other hand, offsets, rdatalists and rdatas allocated using
66 * dns_message_gettemp*() will always be freed automatically
67 * when the message is reset or destroyed; calling dns_message_puttemp*()
68 * on rdatalists and rdatas is optional and serves only to enable the item
69 * to be reused multiple times during the lifetime of the message; offsets
72 * Buffers allocated using isc_buffer_allocate() can be automatically freed
73 * as well by giving the buffer to the message using dns_message_takebuffer().
74 * Doing this will cause the buffer to be freed using isc_buffer_free()
75 * when the section lists are cleared, such as in a reset or in a destroy.
76 * Since the buffer itself exists until the message is destroyed, this sort
77 * of code can be written:
80 * buffer = isc_buffer_allocate(mctx, 512);
82 * name = dns_message_gettempname(message, &name);
83 * dns_name_init(name, NULL);
84 * result = dns_name_fromtext(name, &source, dns_rootname, ISC_FALSE,
86 * dns_message_takebuffer(message, &buffer);
92 * XXX Needed: ways to set and retrieve EDNS information, add rdata to a
93 * section, move rdata from one section to another, remove rdata, etc.
96 #define DNS_MESSAGEFLAG_QR 0x8000U
97 #define DNS_MESSAGEFLAG_AA 0x0400U
98 #define DNS_MESSAGEFLAG_TC 0x0200U
99 #define DNS_MESSAGEFLAG_RD 0x0100U
100 #define DNS_MESSAGEFLAG_RA 0x0080U
101 #define DNS_MESSAGEFLAG_AD 0x0020U
102 #define DNS_MESSAGEFLAG_CD 0x0010U
104 #define DNS_MESSAGEEXTFLAG_DO 0x8000U
106 #define DNS_MESSAGE_REPLYPRESERVE (DNS_MESSAGEFLAG_RD|DNS_MESSAGEFLAG_CD)
107 #define DNS_MESSAGEEXTFLAG_REPLYPRESERVE (DNS_MESSAGEEXTFLAG_DO)
109 #define DNS_MESSAGE_HEADERLEN 12 /*%< 6 isc_uint16_t's */
111 #define DNS_MESSAGE_MAGIC ISC_MAGIC('M','S','G','@')
112 #define DNS_MESSAGE_VALID(msg) ISC_MAGIC_VALID(msg, DNS_MESSAGE_MAGIC)
115 * Ordering here matters. DNS_SECTION_ANY must be the lowest and negative,
116 * and DNS_SECTION_MAX must be one greater than the last used section.
118 typedef int dns_section_t;
119 #define DNS_SECTION_ANY (-1)
120 #define DNS_SECTION_QUESTION 0
121 #define DNS_SECTION_ANSWER 1
122 #define DNS_SECTION_AUTHORITY 2
123 #define DNS_SECTION_ADDITIONAL 3
124 #define DNS_SECTION_MAX 4
126 typedef int dns_pseudosection_t;
127 #define DNS_PSEUDOSECTION_ANY (-1)
128 #define DNS_PSEUDOSECTION_OPT 0
129 #define DNS_PSEUDOSECTION_TSIG 1
130 #define DNS_PSEUDOSECTION_SIG0 2
131 #define DNS_PSEUDOSECTION_MAX 3
133 typedef int dns_messagetextflag_t;
134 #define DNS_MESSAGETEXTFLAG_NOCOMMENTS 0x0001
135 #define DNS_MESSAGETEXTFLAG_NOHEADERS 0x0002
138 * Dynamic update names for these sections.
140 #define DNS_SECTION_ZONE DNS_SECTION_QUESTION
141 #define DNS_SECTION_PREREQUISITE DNS_SECTION_ANSWER
142 #define DNS_SECTION_UPDATE DNS_SECTION_AUTHORITY
145 * These tell the message library how the created dns_message_t will be used.
147 #define DNS_MESSAGE_INTENTUNKNOWN 0 /*%< internal use only */
148 #define DNS_MESSAGE_INTENTPARSE 1 /*%< parsing messages */
149 #define DNS_MESSAGE_INTENTRENDER 2 /*%< rendering */
152 * Control behavior of parsing
154 #define DNS_MESSAGEPARSE_PRESERVEORDER 0x0001 /*%< preserve rdata order */
155 #define DNS_MESSAGEPARSE_BESTEFFORT 0x0002 /*%< return a message if a
156 recoverable parse error
158 #define DNS_MESSAGEPARSE_CLONEBUFFER 0x0004 /*%< save a copy of the
160 #define DNS_MESSAGEPARSE_IGNORETRUNCATION 0x0008 /*%< trucation errors are
164 * Control behavior of rendering
166 #define DNS_MESSAGERENDER_ORDERED 0x0001 /*%< don't change order */
167 #define DNS_MESSAGERENDER_PARTIAL 0x0002 /*%< allow a partial rdataset */
168 #define DNS_MESSAGERENDER_OMITDNSSEC 0x0004 /*%< omit DNSSEC records */
169 #define DNS_MESSAGERENDER_PREFER_A 0x0008 /*%< prefer A records in
170 additional section. */
171 #define DNS_MESSAGERENDER_PREFER_AAAA 0x0010 /*%< prefer AAAA records in
172 additional section. */
174 typedef struct dns_msgblock dns_msgblock_t;
177 /* public from here down */
184 dns_rdataclass_t rdclass;
186 /* 4 real, 1 pseudo */
187 unsigned int counts[DNS_SECTION_MAX];
189 /* private from here down */
190 dns_namelist_t sections[DNS_SECTION_MAX];
191 dns_name_t *cursors[DNS_SECTION_MAX];
193 dns_rdataset_t *sig0;
194 dns_rdataset_t *tsig;
197 unsigned int from_to_wire : 2;
198 unsigned int header_ok : 1;
199 unsigned int question_ok : 1;
200 unsigned int tcp_continuation : 1;
201 unsigned int verified_sig : 1;
202 unsigned int verify_attempted : 1;
203 unsigned int free_query : 1;
204 unsigned int free_saved : 1;
206 unsigned int opt_reserved;
207 unsigned int sig_reserved;
208 unsigned int reserved; /* reserved space (render) */
210 isc_buffer_t *buffer;
211 dns_compress_t *cctx;
214 isc_mempool_t *namepool;
215 isc_mempool_t *rdspool;
217 isc_bufferlist_t scratchpad;
218 isc_bufferlist_t cleanup;
220 ISC_LIST(dns_msgblock_t) rdatas;
221 ISC_LIST(dns_msgblock_t) rdatalists;
222 ISC_LIST(dns_msgblock_t) offsets;
224 ISC_LIST(dns_rdata_t) freerdata;
225 ISC_LIST(dns_rdatalist_t) freerdatalist;
227 dns_rcode_t tsigstatus;
228 dns_rcode_t querytsigstatus;
229 dns_name_t *tsigname; /* Owner name of TSIG, if any */
230 dns_rdataset_t *querytsig;
231 dns_tsigkey_t *tsigkey;
232 dst_context_t *tsigctx;
236 dns_name_t *sig0name; /* Owner name of SIG0, if any */
238 dns_rcode_t sig0status;
242 dns_rdatasetorderfunc_t order;
243 const void * order_arg;
253 dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp);
256 * Create msg structure.
258 * This function will allocate some internal blocks of memory that are
259 * expected to be needed for parsing or rendering nearly any type of message.
262 *\li 'mctx' be a valid memory context.
264 *\li 'msgp' be non-null and '*msg' be NULL.
266 *\li 'intent' must be one of DNS_MESSAGE_INTENTPARSE or
267 * #DNS_MESSAGE_INTENTRENDER.
270 *\li The data in "*msg" is set to indicate an unused and empty msg
274 *\li #ISC_R_NOMEMORY -- out of memory
275 *\li #ISC_R_SUCCESS -- success
279 dns_message_reset(dns_message_t *msg, unsigned int intent);
281 * Reset a message structure to default state. All internal lists are freed
282 * or reset to a default state as well. This is simply a more efficient
283 * way to call dns_message_destroy() followed by dns_message_allocate(),
284 * since it avoid many memory allocations.
286 * If any data loanouts (buffers, names, rdatas, etc) were requested,
287 * the caller must no longer use them after this call.
289 * The intended next use of the message will be 'intent'.
295 *\li 'intent' is DNS_MESSAGE_INTENTPARSE or DNS_MESSAGE_INTENTRENDER
299 dns_message_destroy(dns_message_t **msgp);
301 * Destroy all state in the message.
305 *\li 'msgp' be valid.
312 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
313 const dns_master_style_t *style,
314 dns_messagetextflag_t flags,
315 isc_buffer_t *target);
318 dns_message_pseudosectiontotext(dns_message_t *msg,
319 dns_pseudosection_t section,
320 const dns_master_style_t *style,
321 dns_messagetextflag_t flags,
322 isc_buffer_t *target);
324 * Convert section 'section' or 'pseudosection' of message 'msg' to
325 * a cleartext representation
328 * \li See dns_message_totext for meanings of flags.
332 *\li 'msg' is a valid message.
334 *\li 'style' is a valid master dump style.
336 *\li 'target' is a valid buffer.
338 *\li 'section' is a valid section label.
342 *\li If the result is success:
343 * The used space in 'target' is updated.
351 *\li Note: On error return, *target may be partially filled with data.
355 dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
356 dns_messagetextflag_t flags, isc_buffer_t *target);
358 * Convert all sections of message 'msg' to a cleartext representation
361 * \li In flags, If #DNS_MESSAGETEXTFLAG_OMITDOT is set, then the
362 * final '.' in absolute names will not be emitted. If
363 * #DNS_MESSAGETEXTFLAG_NOCOMMENTS is cleared, lines beginning
364 * with ";;" will be emitted indicating section name. If
365 * #DNS_MESSAGETEXTFLAG_NOHEADERS is cleared, header lines will
370 *\li 'msg' is a valid message.
372 *\li 'style' is a valid master dump style.
374 *\li 'target' is a valid buffer.
378 *\li If the result is success:
379 * The used space in 'target' is updated.
387 *\li Note: On error return, *target may be partially filled with data.
391 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
392 unsigned int options);
394 * Parse raw wire data in 'source' as a DNS message.
396 * OPT records are detected and stored in the pseudo-section "opt".
397 * TSIGs are detected and stored in the pseudo-section "tsig".
399 * If #DNS_MESSAGEPARSE_PRESERVEORDER is set, or if the opcode of the message
400 * is UPDATE, a separate dns_name_t object will be created for each RR in the
401 * message. Each such dns_name_t will have a single rdataset containing the
402 * single RR, and the order of the RRs in the message is preserved.
403 * Otherwise, only one dns_name_t object will be created for each unique
404 * owner name in the section, and each such dns_name_t will have a list
405 * of rdatasets. To access the names and their data, use
406 * dns_message_firstname() and dns_message_nextname().
408 * If #DNS_MESSAGEPARSE_BESTEFFORT is set, errors in message content will
409 * not be considered FORMERRs. If the entire message can be parsed, it
410 * will be returned and DNS_R_RECOVERABLE will be returned.
412 * If #DNS_MESSAGEPARSE_IGNORETRUNCATION is set then return as many complete
413 * RR's as possible, DNS_R_RECOVERABLE will be returned.
415 * OPT and TSIG records are always handled specially, regardless of the
416 * 'preserve_order' setting.
421 *\li "buffer" be a wire format buffer.
424 *\li The buffer's data format is correct.
426 *\li The buffer's contents verify as correct regarding header bits, buffer
427 * and rdata sizes, etc.
430 *\li #ISC_R_SUCCESS -- all is well
431 *\li #ISC_R_NOMEMORY -- no memory
432 *\li #DNS_R_RECOVERABLE -- the message parsed properly, but contained
434 *\li Many other errors possible XXXMLG
438 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
439 isc_buffer_t *buffer);
441 * Begin rendering on a message. Only one call can be made to this function
444 * The compression context is "owned" by the message library until
445 * dns_message_renderend() is called. It must be invalidated by the caller.
447 * The buffer is "owned" by the message library until dns_message_renderend()
454 *\li 'cctx' be valid.
456 *\li 'buffer' is a valid buffer.
460 *\li The buffer is cleared before it is used.
463 *\li #ISC_R_SUCCESS -- all is well
464 *\li #ISC_R_NOSPACE -- output buffer is too small
468 dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer);
470 * Reset the buffer. This can be used after growing the old buffer
471 * on a ISC_R_NOSPACE return from most of the render functions.
473 * On successful completion, the old buffer is no longer used by the
474 * library. The new buffer is owned by the library until
475 * dns_message_renderend() is called.
481 *\li dns_message_renderbegin() was called.
486 *\li #ISC_R_NOSPACE -- new buffer is too small
487 *\li #ISC_R_SUCCESS -- all is well.
491 dns_message_renderreserve(dns_message_t *msg, unsigned int space);
493 * XXXMLG should use size_t rather than unsigned int once the buffer
496 * Reserve "space" bytes in the given buffer.
502 *\li dns_message_renderbegin() was called.
505 *\li #ISC_R_SUCCESS -- all is well.
506 *\li #ISC_R_NOSPACE -- not enough free space in the buffer.
510 dns_message_renderrelease(dns_message_t *msg, unsigned int space);
512 * XXXMLG should use size_t rather than unsigned int once the buffer
515 * Release "space" bytes in the given buffer that was previously reserved.
521 *\li 'space' is less than or equal to the total amount of space reserved
522 * via prior calls to dns_message_renderreserve().
524 *\li dns_message_renderbegin() was called.
528 dns_message_rendersection(dns_message_t *msg, dns_section_t section,
529 unsigned int options);
531 * Render all names, rdatalists, etc from the given section at the
532 * specified priority or higher.
537 *\li 'section' be a valid section.
539 *\li dns_message_renderbegin() was called.
542 *\li #ISC_R_SUCCESS -- all records were written, and there are
543 * no more records for this section.
544 *\li #ISC_R_NOSPACE -- Not enough room in the buffer to write
545 * all records requested.
546 *\li #DNS_R_MOREDATA -- All requested records written, and there
547 * are records remaining for this section.
551 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target);
553 * Render the message header. This is implicitly called by
554 * dns_message_renderend().
558 *\li 'msg' be a valid message.
560 *\li dns_message_renderbegin() was called.
562 *\li 'target' is a valid buffer with enough space to hold a message header
566 dns_message_renderend(dns_message_t *msg);
568 * Finish rendering to the buffer. Note that more data can be in the
569 * 'msg' structure. Destroying the structure will free this, or in a multi-
570 * part EDNS1 message this data can be rendered to another buffer later.
574 *\li 'msg' be a valid message.
576 *\li dns_message_renderbegin() was called.
579 *\li #ISC_R_SUCCESS -- all is well.
583 dns_message_renderreset(dns_message_t *msg);
585 * Reset the message so that it may be rendered again.
589 *\li If dns_message_renderbegin() has been called, dns_message_renderend()
590 * must be called before calling this function.
594 *\li 'msg' be a valid message with rendering intent.
598 dns_message_firstname(dns_message_t *msg, dns_section_t section);
600 * Set internal per-section name pointer to the beginning of the section.
602 * The functions dns_message_firstname() and dns_message_nextname() may
603 * be used for iterating over the owner names in a section.
609 *\li 'section' be a valid section.
612 *\li #ISC_R_SUCCESS -- All is well.
613 *\li #ISC_R_NOMORE -- No names on given section.
617 dns_message_nextname(dns_message_t *msg, dns_section_t section);
619 * Sets the internal per-section name pointer to point to the next name
624 * \li 'msg' be valid.
626 *\li 'section' be a valid section.
628 *\li dns_message_firstname() must have been called on this section,
629 * and the result was ISC_R_SUCCESS.
632 *\li #ISC_R_SUCCESS -- All is well.
633 *\li #ISC_R_NOMORE -- No more names in given section.
637 dns_message_currentname(dns_message_t *msg, dns_section_t section,
640 * Sets 'name' to point to the name where the per-section internal name
641 * pointer is currently set.
643 * This function returns the name in the database, so any data associated
644 * with it (via the name's "list" member) contains the actual rdatasets.
650 *\li 'name' be non-NULL, and *name be NULL.
652 *\li 'section' be a valid section.
654 *\li dns_message_firstname() must have been called on this section,
655 * and the result of it and any dns_message_nextname() calls was
660 dns_message_findname(dns_message_t *msg, dns_section_t section,
661 dns_name_t *target, dns_rdatatype_t type,
662 dns_rdatatype_t covers, dns_name_t **foundname,
663 dns_rdataset_t **rdataset);
665 * Search for a name in the specified section. If it is found, *name is
666 * set to point to the name, and *rdataset is set to point to the found
667 * rdataset (if type is specified as other than dns_rdatatype_any).
672 *\li 'section' be a valid section.
674 *\li If a pointer to the name is desired, 'foundname' should be non-NULL.
675 * If it is non-NULL, '*foundname' MUST be NULL.
677 *\li If a type other than dns_datatype_any is searched for, 'rdataset'
678 * may be non-NULL, '*rdataset' be NULL, and will point at the found
679 * rdataset. If the type is dns_datatype_any, 'rdataset' must be NULL.
681 *\li 'target' be a valid name.
683 *\li 'type' be a valid type.
685 *\li If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
686 * Otherwise it should be 0.
689 *\li #ISC_R_SUCCESS -- all is well.
690 *\li #DNS_R_NXDOMAIN -- name does not exist in that section.
691 *\li #DNS_R_NXRRSET -- The name does exist, but the desired
696 dns_message_findtype(dns_name_t *name, dns_rdatatype_t type,
697 dns_rdatatype_t covers, dns_rdataset_t **rdataset);
699 * Search the name for the specified type. If it is found, *rdataset is
700 * filled in with a pointer to that rdataset.
703 *\li if '**rdataset' is non-NULL, *rdataset needs to be NULL.
705 *\li 'type' be a valid type, and NOT dns_rdatatype_any.
707 *\li If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
708 * Otherwise it should be 0.
711 *\li #ISC_R_SUCCESS -- all is well.
712 *\li #ISC_R_NOTFOUND -- the desired type does not exist.
716 dns_message_find(dns_name_t *name, dns_rdataclass_t rdclass,
717 dns_rdatatype_t type, dns_rdatatype_t covers,
718 dns_rdataset_t **rdataset);
720 * Search the name for the specified rdclass and type. If it is found,
721 * *rdataset is filled in with a pointer to that rdataset.
724 *\li if '**rdataset' is non-NULL, *rdataset needs to be NULL.
726 *\li 'type' be a valid type, and NOT dns_rdatatype_any.
728 *\li If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
729 * Otherwise it should be 0.
732 *\li #ISC_R_SUCCESS -- all is well.
733 *\li #ISC_R_NOTFOUND -- the desired type does not exist.
737 dns_message_movename(dns_message_t *msg, dns_name_t *name,
738 dns_section_t fromsection,
739 dns_section_t tosection);
741 * Move a name from one section to another.
747 *\li 'name' must be a name already in 'fromsection'.
749 *\li 'fromsection' must be a valid section.
751 *\li 'tosection' must be a valid section.
755 dns_message_addname(dns_message_t *msg, dns_name_t *name,
756 dns_section_t section);
758 * Adds the name to the given section.
760 * It is the caller's responsibility to enforce any unique name requirements
765 *\li 'msg' be valid, and be a renderable message.
767 *\li 'name' be a valid absolute name.
769 *\li 'section' be a named section.
773 dns_message_removename(dns_message_t *msg, dns_name_t *name,
774 dns_section_t section);
776 * Remove a existing name from a given section.
778 * It is the caller's responsibility to ensure the name is part of the
783 *\li 'msg' be valid, and be a renderable message.
785 *\li 'name' be a valid absolute name.
787 *\li 'section' be a named section.
794 * Each of these functions loan a particular type of data to the caller.
795 * The storage for these will vanish when the message is destroyed or
796 * reset, and must NOT be used after these operations.
800 dns_message_gettempname(dns_message_t *msg, dns_name_t **item);
802 * Return a name that can be used for any temporary purpose, including
803 * inserting into the message's linked lists. The name must be returned
804 * to the message code using dns_message_puttempname() or inserted into
805 * one of the message's sections before the message is destroyed.
807 * It is the caller's responsibility to initialize this name.
810 *\li msg be a valid message
812 *\li item != NULL && *item == NULL
815 *\li #ISC_R_SUCCESS -- All is well.
816 *\li #ISC_R_NOMEMORY -- No item can be allocated.
820 dns_message_gettempoffsets(dns_message_t *msg, dns_offsets_t **item);
822 * Return an offsets array that can be used for any temporary purpose,
823 * such as attaching to a temporary name. The offsets will be freed
824 * when the message is destroyed or reset.
827 *\li msg be a valid message
829 *\li item != NULL && *item == NULL
832 *\li #ISC_R_SUCCESS -- All is well.
833 *\li #ISC_R_NOMEMORY -- No item can be allocated.
837 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item);
839 * Return a rdata that can be used for any temporary purpose, including
840 * inserting into the message's linked lists. The rdata will be freed
841 * when the message is destroyed or reset.
844 *\li msg be a valid message
846 *\li item != NULL && *item == NULL
849 *\li #ISC_R_SUCCESS -- All is well.
850 *\li #ISC_R_NOMEMORY -- No item can be allocated.
854 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item);
856 * Return a rdataset that can be used for any temporary purpose, including
857 * inserting into the message's linked lists. The name must be returned
858 * to the message code using dns_message_puttempname() or inserted into
859 * one of the message's sections before the message is destroyed.
862 *\li msg be a valid message
864 *\li item != NULL && *item == NULL
867 *\li #ISC_R_SUCCESS -- All is well.
868 *\li #ISC_R_NOMEMORY -- No item can be allocated.
872 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
874 * Return a rdatalist that can be used for any temporary purpose, including
875 * inserting into the message's linked lists. The rdatalist will be
876 * destroyed when the message is destroyed or reset.
879 *\li msg be a valid message
881 *\li item != NULL && *item == NULL
884 *\li #ISC_R_SUCCESS -- All is well.
885 *\li #ISC_R_NOMEMORY -- No item can be allocated.
889 dns_message_puttempname(dns_message_t *msg, dns_name_t **item);
891 * Return a borrowed name to the message's name free list.
894 *\li msg be a valid message
896 *\li item != NULL && *item point to a name returned by
897 * dns_message_gettempname()
904 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item);
906 * Return a borrowed rdata to the message's rdata free list.
909 *\li msg be a valid message
911 *\li item != NULL && *item point to a rdata returned by
912 * dns_message_gettemprdata()
919 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item);
921 * Return a borrowed rdataset to the message's rdataset free list.
924 *\li msg be a valid message
926 *\li item != NULL && *item point to a rdataset returned by
927 * dns_message_gettemprdataset()
934 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
936 * Return a borrowed rdatalist to the message's rdatalist free list.
939 *\li msg be a valid message
941 *\li item != NULL && *item point to a rdatalist returned by
942 * dns_message_gettemprdatalist()
949 dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp,
950 unsigned int *flagsp);
952 * Assume the remaining region of "source" is a DNS message. Peek into
953 * it and fill in "*idp" with the message id, and "*flagsp" with the flags.
961 *\li if (idp != NULL) *idp == message id.
963 *\li if (flagsp != NULL) *flagsp == message flags.
967 *\li #ISC_R_SUCCESS -- all is well.
969 *\li #ISC_R_UNEXPECTEDEND -- buffer doesn't contain enough for a header.
973 dns_message_reply(dns_message_t *msg, isc_boolean_t want_question_section);
975 * Start formatting a reply to the query in 'msg'.
979 *\li 'msg' is a valid message with parsing intent, and contains a query.
983 *\li The message will have a rendering intent. If 'want_question_section'
984 * is true, the message opcode is query or notify, and the question
985 * section is present and properly formatted, then the question section
986 * will be included in the reply. All other sections will be cleared.
987 * The QR flag will be set, the RD flag will be preserved, and all other
988 * flags will be cleared.
992 *\li #ISC_R_SUCCESS -- all is well.
994 *\li #DNS_R_FORMERR -- the header or question section of the
995 * message is invalid, replying is impossible.
996 * If DNS_R_FORMERR is returned when
997 * want_question_section is ISC_FALSE, then
998 * it's the header section that's bad;
999 * otherwise either of the header or question
1000 * sections may be bad.
1004 dns_message_getopt(dns_message_t *msg);
1006 * Get the OPT record for 'msg'.
1010 *\li 'msg' is a valid message.
1014 *\li The OPT rdataset of 'msg', or NULL if there isn't one.
1018 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt);
1020 * Set the OPT record for 'msg'.
1024 *\li 'msg' is a valid message with rendering intent
1025 * and no sections have been rendered.
1027 *\li 'opt' is a valid OPT record.
1031 *\li The OPT record has either been freed or ownership of it has
1032 * been transferred to the message.
1034 *\li If ISC_R_SUCCESS was returned, the OPT record will be rendered
1035 * when dns_message_renderend() is called.
1039 *\li #ISC_R_SUCCESS -- all is well.
1041 *\li #ISC_R_NOSPACE -- there is no space for the OPT record.
1045 dns_message_gettsig(dns_message_t *msg, dns_name_t **owner);
1047 * Get the TSIG record and owner for 'msg'.
1051 *\li 'msg' is a valid message.
1052 *\li 'owner' is NULL or *owner is NULL.
1056 *\li The TSIG rdataset of 'msg', or NULL if there isn't one.
1060 * \li If 'owner' is not NULL, it will point to the owner name.
1064 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key);
1066 * Set the tsig key for 'msg'. This is only necessary for when rendering a
1067 * query or parsing a response. The key (if non-NULL) is attached to, and
1068 * will be detached when the message is destroyed.
1072 *\li 'msg' is a valid message with rendering intent,
1073 * dns_message_renderbegin() has been called, and no sections have been
1075 *\li 'key' is a valid tsig key or NULL.
1079 *\li #ISC_R_SUCCESS -- all is well.
1081 *\li #ISC_R_NOSPACE -- there is no space for the TSIG record.
1085 dns_message_gettsigkey(dns_message_t *msg);
1087 * Gets the tsig key for 'msg'.
1091 *\li 'msg' is a valid message
1095 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig);
1097 * Indicates that 'querytsig' is the TSIG from the signed query for which
1098 * 'msg' is the response. This is also used for chained TSIGs in TCP
1103 *\li 'querytsig' is a valid buffer as returned by dns_message_getquerytsig()
1106 *\li 'msg' is a valid message
1111 *\li #ISC_R_NOMEMORY
1115 dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
1116 isc_buffer_t **querytsig);
1118 * Gets the tsig from the TSIG from the signed query 'msg'. This is also used
1119 * for chained TSIGs in TCP responses. Unlike dns_message_gettsig, this makes
1120 * a copy of the data, so can be used if the message is destroyed.
1124 *\li 'msg' is a valid signed message
1125 *\li 'mctx' is a valid memory context
1126 *\li querytsig != NULL && *querytsig == NULL
1131 *\li #ISC_R_NOMEMORY
1134 *\li 'tsig' points to NULL or an allocated buffer which must be freed
1139 dns_message_getsig0(dns_message_t *msg, dns_name_t **owner);
1141 * Get the SIG(0) record and owner for 'msg'.
1145 *\li 'msg' is a valid message.
1146 *\li 'owner' is NULL or *owner is NULL.
1150 *\li The SIG(0) rdataset of 'msg', or NULL if there isn't one.
1154 * \li If 'owner' is not NULL, it will point to the owner name.
1158 dns_message_setsig0key(dns_message_t *msg, dst_key_t *key);
1160 * Set the SIG(0) key for 'msg'.
1164 *\li 'msg' is a valid message with rendering intent,
1165 * dns_message_renderbegin() has been called, and no sections have been
1167 *\li 'key' is a valid sig key or NULL.
1171 *\li #ISC_R_SUCCESS -- all is well.
1173 *\li #ISC_R_NOSPACE -- there is no space for the SIG(0) record.
1177 dns_message_getsig0key(dns_message_t *msg);
1179 * Gets the SIG(0) key for 'msg'.
1183 *\li 'msg' is a valid message
1187 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer);
1189 * Give the *buffer to the message code to clean up when it is no
1190 * longer needed. This is usually when the message is reset or
1195 *\li msg be a valid message.
1197 *\li buffer != NULL && *buffer is a valid isc_buffer_t, which was
1198 * dynamincally allocated via isc_buffer_allocate().
1202 dns_message_signer(dns_message_t *msg, dns_name_t *signer);
1204 * If this message was signed, return the identity of the signer.
1205 * Unless ISC_R_NOTFOUND is returned, signer will reflect the name of the
1206 * key that signed the message.
1210 *\li msg is a valid parsed message.
1211 *\li signer is a valid name
1215 *\li #ISC_R_SUCCESS - the message was signed, and *signer
1216 * contains the signing identity
1218 *\li #ISC_R_NOTFOUND - no TSIG or SIG(0) record is present in the
1221 *\li #DNS_R_TSIGVERIFYFAILURE - the message was signed by a TSIG, but the
1222 * signature failed to verify
1224 *\li #DNS_R_TSIGERRORSET - the message was signed by a TSIG and
1225 * verified, but the query was rejected by
1228 *\li #DNS_R_NOIDENTITY - the message was signed by a TSIG and
1229 * verified, but the key has no identity since
1230 * it was generated by an unsigned TKEY process
1232 *\li #DNS_R_SIGINVALID - the message was signed by a SIG(0), but
1233 * the signature failed to verify
1235 *\li #DNS_R_NOTVERIFIEDYET - the message was signed by a TSIG or SIG(0),
1236 * but the signature has not been verified yet
1240 dns_message_checksig(dns_message_t *msg, dns_view_t *view);
1242 * If this message was signed, verify the signature.
1246 *\li msg is a valid parsed message.
1247 *\li view is a valid view or NULL
1251 *\li #ISC_R_SUCCESS - the message was unsigned, or the message
1252 * was signed correctly.
1254 *\li #DNS_R_EXPECTEDTSIG - A TSIG was expected, but not seen
1255 *\li #DNS_R_UNEXPECTEDTSIG - A TSIG was seen but not expected
1256 *\li #DNS_R_TSIGVERIFYFAILURE - The TSIG failed to verify
1260 dns_message_rechecksig(dns_message_t *msg, dns_view_t *view);
1262 * Reset the signature state and then if the message was signed,
1263 * verify the message.
1267 *\li msg is a valid parsed message.
1268 *\li view is a valid view or NULL
1272 *\li #ISC_R_SUCCESS - the message was unsigned, or the message
1273 * was signed correctly.
1275 *\li #DNS_R_EXPECTEDTSIG - A TSIG was expected, but not seen
1276 *\li #DNS_R_UNEXPECTEDTSIG - A TSIG was seen but not expected
1277 *\li #DNS_R_TSIGVERIFYFAILURE - The TSIG failed to verify
1281 dns_message_resetsig(dns_message_t *msg);
1283 * Reset the signature state.
1286 *\li 'msg' is a valid parsed message.
1290 dns_message_getrawmessage(dns_message_t *msg);
1292 * Retrieve the raw message in compressed wire format. The message must
1293 * have been successfully parsed for it to have been saved.
1296 *\li msg is a valid parsed message.
1299 *\li NULL if there is no saved message.
1300 * a pointer to a region which refers the dns message.
1304 dns_message_setsortorder(dns_message_t *msg, dns_rdatasetorderfunc_t order,
1305 const void *order_arg);
1307 * Define the order in which RR sets get rendered by
1308 * dns_message_rendersection() to be the ascending order
1309 * defined by the integer value returned by 'order' when
1310 * given each RR and 'arg' as arguments. If 'order' and
1311 * 'order_arg' are NULL, a default order is used.
1314 *\li msg be a valid message.
1315 *\li order_arg is NULL if and only if order is NULL.
1319 dns_message_settimeadjust(dns_message_t *msg, int timeadjust);
1321 * Adjust the time used to sign/verify a message by timeadjust.
1322 * Currently only TSIG.
1325 *\li msg be a valid message.
1329 dns_message_gettimeadjust(dns_message_t *msg);
1331 * Return the current time adjustment.
1334 *\li msg be a valid message.
1339 #endif /* DNS_MESSAGE_H */