1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #pragma once
13 
14 /***
15  ***	Imports
16  ***/
17 
18 #include <inttypes.h>
19 #include <stdbool.h>
20 
21 #include <isc/lang.h>
22 #include <isc/magic.h>
23 #include <isc/refcount.h>
24 
25 #include <dns/compress.h>
26 #include <dns/masterdump.h>
27 #include <dns/types.h>
28 
29 #include <dst/dst.h>
30 
31 /*! \file dns/message.h
32  * \brief Message Handling Module
33  *
34  * How this beast works:
35  *
36  * When a dns message is received in a buffer, dns_message_parse() is called
37  * on the memory region.  Various items are checked including the format
38  * of the message (if counts are right, if counts consume the entire sections,
39  * and if sections consume the entire message) and known pseudo-RRs in the
40  * additional data section are analyzed and removed.
41  *
42  * TSIG checking is also done at this layer, and any DNSSEC transaction
43  * signatures should also be checked here.
44  *
45  * Notes on using the gettemp*() and puttemp*() functions:
46  *
47  * These functions return items (names, rdatasets, etc) allocated from some
48  * internal state of the dns_message_t.
49  *
50  * Names and rdatasets must be put back into the dns_message_t in
51  * one of two ways.  Assume a name was allocated via
52  * dns_message_gettempname():
53  *
54  *\li	(1) insert it into a section, using dns_message_addname().
55  *
56  *\li	(2) return it to the message using dns_message_puttempname().
57  *
58  * The same applies to rdatasets.
59  *
60  * On the other hand, offsets, rdatalists and rdatas allocated using
61  * dns_message_gettemp*() will always be freed automatically
62  * when the message is reset or destroyed; calling dns_message_puttemp*()
63  * on rdatalists and rdatas is optional and serves only to enable the item
64  * to be reused multiple times during the lifetime of the message; offsets
65  * cannot be reused.
66  *
67  * Buffers allocated using isc_buffer_allocate() can be automatically freed
68  * as well by giving the buffer to the message using dns_message_takebuffer().
69  * Doing this will cause the buffer to be freed using isc_buffer_free()
70  * when the section lists are cleared, such as in a reset or in a destroy.
71  * Since the buffer itself exists until the message is destroyed, this sort
72  * of code can be written:
73  *
74  * \code
75  *	buffer = isc_buffer_allocate(mctx, 512);
76  *	name = NULL;
77  *	result = dns_message_gettempname(message, &name);
78  *	result = dns_name_fromtext(name, &source, dns_rootname, 0, buffer);
79  *	dns_message_takebuffer(message, &buffer);
80  * \endcode
81  *
82  *
83  * TODO:
84  *
85  * XXX Needed:  ways to set and retrieve EDNS information, add rdata to a
86  * section, move rdata from one section to another, remove rdata, etc.
87  */
88 
89 #define DNS_MESSAGEFLAG_QR 0x8000U
90 #define DNS_MESSAGEFLAG_AA 0x0400U
91 #define DNS_MESSAGEFLAG_TC 0x0200U
92 #define DNS_MESSAGEFLAG_RD 0x0100U
93 #define DNS_MESSAGEFLAG_RA 0x0080U
94 #define DNS_MESSAGEFLAG_AD 0x0020U
95 #define DNS_MESSAGEFLAG_CD 0x0010U
96 
97 /*%< EDNS0 extended message flags */
98 #define DNS_MESSAGEEXTFLAG_DO 0x8000U
99 
100 /*%< EDNS0 extended OPT codes */
101 #define DNS_OPT_LLQ	      1	 /*%< LLQ opt code */
102 #define DNS_OPT_NSID	      3	 /*%< NSID opt code */
103 #define DNS_OPT_CLIENT_SUBNET 8	 /*%< client subnet opt code */
104 #define DNS_OPT_EXPIRE	      9	 /*%< EXPIRE opt code */
105 #define DNS_OPT_COOKIE	      10 /*%< COOKIE opt code */
106 #define DNS_OPT_TCP_KEEPALIVE 11 /*%< TCP keepalive opt code */
107 #define DNS_OPT_PAD	      12 /*%< PAD opt code */
108 #define DNS_OPT_KEY_TAG	      14 /*%< Key tag opt code */
109 #define DNS_OPT_EDE	      15 /*%< Extended DNS Error opt code */
110 #define DNS_OPT_CLIENT_TAG    16 /*%< Client tag opt code */
111 #define DNS_OPT_SERVER_TAG    17 /*%< Server tag opt code */
112 
113 /*%< Experimental options [65001...65534] as per RFC6891 */
114 
115 /*%< The number of EDNS options we know about. */
116 #define DNS_EDNSOPTIONS 7
117 
118 #define DNS_MESSAGE_REPLYPRESERVE	 (DNS_MESSAGEFLAG_RD | DNS_MESSAGEFLAG_CD)
119 #define DNS_MESSAGEEXTFLAG_REPLYPRESERVE (DNS_MESSAGEEXTFLAG_DO)
120 
121 #define DNS_MESSAGE_HEADERLEN 12 /*%< 6 uint16_t's */
122 
123 #define DNS_MESSAGE_MAGIC      ISC_MAGIC('M', 'S', 'G', '@')
124 #define DNS_MESSAGE_VALID(msg) ISC_MAGIC_VALID(msg, DNS_MESSAGE_MAGIC)
125 
126 /*
127  * Ordering here matters.  DNS_SECTION_ANY must be the lowest and negative,
128  * and DNS_SECTION_MAX must be one greater than the last used section.
129  */
130 typedef int dns_section_t;
131 #define DNS_SECTION_ANY	       (-1)
132 #define DNS_SECTION_QUESTION   0
133 #define DNS_SECTION_ANSWER     1
134 #define DNS_SECTION_AUTHORITY  2
135 #define DNS_SECTION_ADDITIONAL 3
136 #define DNS_SECTION_MAX	       4
137 
138 typedef int dns_pseudosection_t;
139 #define DNS_PSEUDOSECTION_ANY  (-1)
140 #define DNS_PSEUDOSECTION_OPT  0
141 #define DNS_PSEUDOSECTION_TSIG 1
142 #define DNS_PSEUDOSECTION_SIG0 2
143 #define DNS_PSEUDOSECTION_MAX  3
144 
145 typedef int dns_messagetextflag_t;
146 #define DNS_MESSAGETEXTFLAG_NOCOMMENTS 0x0001
147 #define DNS_MESSAGETEXTFLAG_NOHEADERS  0x0002
148 #define DNS_MESSAGETEXTFLAG_ONESOA     0x0004
149 #define DNS_MESSAGETEXTFLAG_OMITSOA    0x0008
150 
151 /*
152  * Dynamic update names for these sections.
153  */
154 #define DNS_SECTION_ZONE	 DNS_SECTION_QUESTION
155 #define DNS_SECTION_PREREQUISITE DNS_SECTION_ANSWER
156 #define DNS_SECTION_UPDATE	 DNS_SECTION_AUTHORITY
157 
158 /*
159  * These tell the message library how the created dns_message_t will be used.
160  */
161 #define DNS_MESSAGE_INTENTUNKNOWN 0 /*%< internal use only */
162 #define DNS_MESSAGE_INTENTPARSE	  1 /*%< parsing messages */
163 #define DNS_MESSAGE_INTENTRENDER  2 /*%< rendering */
164 
165 /*
166  * Control behavior of parsing
167  */
168 #define DNS_MESSAGEPARSE_PRESERVEORDER 0x0001 /*%< preserve rdata order */
169 #define DNS_MESSAGEPARSE_BESTEFFORT       \
170 	0x0002 /*%< return a message if a \
171 		* recoverable parse error \
172 		* occurs */
173 #define DNS_MESSAGEPARSE_CLONEBUFFER   \
174 	0x0004 /*%< save a copy of the \
175 		* source buffer */
176 #define DNS_MESSAGEPARSE_IGNORETRUNCATION \
177 	0x0008 /*%< truncation errors are \
178 		* not fatal. */
179 
180 /*
181  * Control behavior of rendering
182  */
183 #define DNS_MESSAGERENDER_ORDERED    0x0001 /*%< don't change order */
184 #define DNS_MESSAGERENDER_PARTIAL    0x0002 /*%< allow a partial rdataset */
185 #define DNS_MESSAGERENDER_OMITDNSSEC 0x0004 /*%< omit DNSSEC records */
186 #define DNS_MESSAGERENDER_PREFER_A      \
187 	0x0008 /*%< prefer A records in \
188 		*   additional section. */
189 #define DNS_MESSAGERENDER_PREFER_AAAA      \
190 	0x0010 /*%< prefer AAAA records in \
191 		*   additional section. */
192 /* Obsolete: DNS_MESSAGERENDER_FILTER_AAAA	0x0020	*/
193 
194 typedef struct dns_msgblock dns_msgblock_t;
195 
196 struct dns_sortlist_arg {
197 	dns_aclenv_t *		env;
198 	const dns_acl_t *	acl;
199 	const dns_aclelement_t *element;
200 };
201 
202 struct dns_message {
203 	/* public from here down */
204 	unsigned int   magic;
205 	isc_refcount_t refcount;
206 
207 	dns_messageid_t	 id;
208 	unsigned int	 flags;
209 	dns_rcode_t	 rcode;
210 	dns_opcode_t	 opcode;
211 	dns_rdataclass_t rdclass;
212 
213 	/* 4 real, 1 pseudo */
214 	unsigned int counts[DNS_SECTION_MAX];
215 
216 	/* private from here down */
217 	dns_namelist_t	sections[DNS_SECTION_MAX];
218 	dns_name_t *	cursors[DNS_SECTION_MAX];
219 	dns_rdataset_t *opt;
220 	dns_rdataset_t *sig0;
221 	dns_rdataset_t *tsig;
222 
223 	int	     state;
224 	unsigned int from_to_wire     : 2;
225 	unsigned int header_ok	      : 1;
226 	unsigned int question_ok      : 1;
227 	unsigned int tcp_continuation : 1;
228 	unsigned int verified_sig     : 1;
229 	unsigned int verify_attempted : 1;
230 	unsigned int free_query	      : 1;
231 	unsigned int free_saved	      : 1;
232 	unsigned int cc_ok	      : 1;
233 	unsigned int cc_bad	      : 1;
234 	unsigned int tkey	      : 1;
235 	unsigned int rdclass_set      : 1;
236 
237 	unsigned int opt_reserved;
238 	unsigned int sig_reserved;
239 	unsigned int reserved; /* reserved space (render) */
240 
241 	uint16_t     padding;
242 	unsigned int padding_off;
243 
244 	isc_buffer_t *	buffer;
245 	dns_compress_t *cctx;
246 
247 	isc_mem_t *    mctx;
248 	isc_mempool_t *namepool;
249 	isc_mempool_t *rdspool;
250 
251 	isc_bufferlist_t scratchpad;
252 	isc_bufferlist_t cleanup;
253 
254 	ISC_LIST(dns_msgblock_t) rdatas;
255 	ISC_LIST(dns_msgblock_t) rdatalists;
256 	ISC_LIST(dns_msgblock_t) offsets;
257 
258 	ISC_LIST(dns_rdata_t) freerdata;
259 	ISC_LIST(dns_rdatalist_t) freerdatalist;
260 
261 	dns_rcode_t tsigstatus;
262 	dns_rcode_t querytsigstatus;
263 	dns_name_t *tsigname; /* Owner name of TSIG, if any
264 			       * */
265 	dns_rdataset_t *querytsig;
266 	dns_tsigkey_t * tsigkey;
267 	dst_context_t * tsigctx;
268 	int		sigstart;
269 	int		timeadjust;
270 
271 	dns_name_t *sig0name; /* Owner name of SIG0, if any
272 			       * */
273 	dst_key_t *  sig0key;
274 	dns_rcode_t  sig0status;
275 	isc_region_t query;
276 	isc_region_t saved;
277 
278 	dns_rdatasetorderfunc_t order;
279 	dns_sortlist_arg_t	order_arg;
280 
281 	dns_indent_t indent;
282 };
283 
284 struct dns_ednsopt {
285 	uint16_t       code;
286 	uint16_t       length;
287 	unsigned char *value;
288 };
289 
290 /***
291  *** Functions
292  ***/
293 
294 ISC_LANG_BEGINDECLS
295 
296 void
297 dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp);
298 
299 /*%<
300  * Create msg structure.
301  *
302  * This function will allocate some internal blocks of memory that are
303  * expected to be needed for parsing or rendering nearly any type of message.
304  *
305  * Requires:
306  *\li	'mctx' be a valid memory context.
307  *
308  *\li	'msgp' be non-null and '*msg' be NULL.
309  *
310  *\li	'intent' must be one of DNS_MESSAGE_INTENTPARSE or
311  *	#DNS_MESSAGE_INTENTRENDER.
312  *
313  * Ensures:
314  *\li	The data in "*msg" is set to indicate an unused and empty msg
315  *	structure.
316  *
317  * Returns:
318  *\li	#ISC_R_NOMEMORY		-- out of memory
319  *\li	#ISC_R_SUCCESS		-- success
320  */
321 
322 void
323 dns_message_reset(dns_message_t *msg, unsigned int intent);
324 /*%<
325  * Reset a message structure to default state.  All internal lists are freed
326  * or reset to a default state as well.  This is simply a more efficient
327  * way to call dns_message_detach() (assuming last reference is hold),
328  * followed by dns_message_create(), since it avoid many memory allocations.
329  *
330  * If any data loanouts (buffers, names, rdatas, etc) were requested,
331  * the caller must no longer use them after this call.
332  *
333  * The intended next use of the message will be 'intent'.
334  *
335  * Requires:
336  *
337  *\li	'msg' be valid.
338  *
339  *\li	'intent' is DNS_MESSAGE_INTENTPARSE or DNS_MESSAGE_INTENTRENDER
340  */
341 
342 void
343 dns_message_attach(dns_message_t *source, dns_message_t **target);
344 /*%<
345  * Attach to message 'source'.
346  *
347  * Requires:
348  *\li	'source' to be a valid message.
349  *\li	'target' to be non NULL and '*target' to be NULL.
350  */
351 
352 void
353 dns_message_detach(dns_message_t **messagep);
354 /*%<
355  * Detach *messagep from its message.
356  * list.
357  *
358  * Requires:
359  *\li	'*messagep' to be a valid message.
360  */
361 
362 isc_result_t
363 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
364 			  const dns_master_style_t *style,
365 			  dns_messagetextflag_t flags, isc_buffer_t *target);
366 
367 isc_result_t
368 dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section,
369 				const dns_master_style_t *style,
370 				dns_messagetextflag_t	  flags,
371 				isc_buffer_t *		  target);
372 /*%<
373  * Convert section 'section' or 'pseudosection' of message 'msg' to
374  * a cleartext representation
375  *
376  * Notes:
377  *     \li See dns_message_totext for meanings of flags.
378  *
379  * Requires:
380  *
381  *\li	'msg' is a valid message.
382  *
383  *\li	'style' is a valid master dump style.
384  *
385  *\li	'target' is a valid buffer.
386  *
387  *\li	'section' is a valid section label.
388  *
389  * Ensures:
390  *
391  *\li	If the result is success:
392  *		The used space in 'target' is updated.
393  *
394  * Returns:
395  *
396  *\li	#ISC_R_SUCCESS
397  *\li	#ISC_R_NOSPACE
398  *\li	#ISC_R_NOMORE
399  *
400  *\li	Note: On error return, *target may be partially filled with data.
401  */
402 
403 isc_result_t
404 dns_message_headertotext(dns_message_t *msg, const dns_master_style_t *style,
405 			 dns_messagetextflag_t flags, isc_buffer_t *target);
406 /*%<
407  * Convert the header section of message 'msg' to a cleartext
408  * representation. This is called from dns_message_totext().
409  *
410  * Notes on flags:
411  *\li	If #DNS_MESSAGETEXTFLAG_NOHEADERS is set, header lines will be
412  * 	suppressed and this function is a no-op.
413  *
414  * Requires:
415  *
416  *\li	'msg' is a valid message.
417  *
418  *\li	'target' is a valid buffer.
419  *
420  * Ensures:
421  *
422  *\li	If the result is success:
423  *		The used space in 'target' is updated.
424  *
425  * Returns:
426  *
427  *\li	#ISC_R_SUCCESS
428  *\li	#ISC_R_NOSPACE
429  *\li	#ISC_R_NOMORE
430  *
431  *\li	Note: On error return, *target may be partially filled with data.
432  */
433 
434 isc_result_t
435 dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
436 		   dns_messagetextflag_t flags, isc_buffer_t *target);
437 /*%<
438  * Convert all sections of message 'msg' to a cleartext representation
439  *
440  * Notes on flags:
441  *\li	If #DNS_MESSAGETEXTFLAG_NOCOMMENTS is cleared, lines beginning with
442  * 	";;" will be emitted indicating section name.
443  *\li	If #DNS_MESSAGETEXTFLAG_NOHEADERS is cleared, header lines will be
444  * 	emitted.
445  *\li   If #DNS_MESSAGETEXTFLAG_ONESOA is set then only print the first
446  *	SOA record in the answer section.
447  *\li	If *#DNS_MESSAGETEXTFLAG_OMITSOA is set don't print any SOA records
448  *	in the answer section.
449  *
450  * The SOA flags are useful for suppressing the display of the second
451  * SOA record in an AXFR by setting #DNS_MESSAGETEXTFLAG_ONESOA on the
452  * first message in an AXFR stream and #DNS_MESSAGETEXTFLAG_OMITSOA on
453  * subsequent messages.
454  *
455  * Requires:
456  *
457  *\li	'msg' is a valid message.
458  *
459  *\li	'style' is a valid master dump style.
460  *
461  *\li	'target' is a valid buffer.
462  *
463  * Ensures:
464  *
465  *\li	If the result is success:
466  *		The used space in 'target' is updated.
467  *
468  * Returns:
469  *
470  *\li	#ISC_R_SUCCESS
471  *\li	#ISC_R_NOSPACE
472  *\li	#ISC_R_NOMORE
473  *
474  *\li	Note: On error return, *target may be partially filled with data.
475  */
476 
477 isc_result_t
478 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
479 		  unsigned int options);
480 /*%<
481  * Parse raw wire data in 'source' as a DNS message.
482  *
483  * OPT records are detected and stored in the pseudo-section "opt".
484  * TSIGs are detected and stored in the pseudo-section "tsig".
485  *
486  * If #DNS_MESSAGEPARSE_PRESERVEORDER is set, or if the opcode of the message
487  * is UPDATE, a separate dns_name_t object will be created for each RR in the
488  * message.  Each such dns_name_t will have a single rdataset containing the
489  * single RR, and the order of the RRs in the message is preserved.
490  * Otherwise, only one dns_name_t object will be created for each unique
491  * owner name in the section, and each such dns_name_t will have a list
492  * of rdatasets.  To access the names and their data, use
493  * dns_message_firstname() and dns_message_nextname().
494  *
495  * If #DNS_MESSAGEPARSE_BESTEFFORT is set, errors in message content will
496  * not be considered FORMERRs.  If the entire message can be parsed, it
497  * will be returned and DNS_R_RECOVERABLE will be returned.
498  *
499  * If #DNS_MESSAGEPARSE_IGNORETRUNCATION is set then return as many complete
500  * RR's as possible, DNS_R_RECOVERABLE will be returned.
501  *
502  * OPT and TSIG records are always handled specially, regardless of the
503  * 'preserve_order' setting.
504  *
505  * Requires:
506  *\li	"msg" be valid.
507  *
508  *\li	"buffer" be a wire format buffer.
509  *
510  * Ensures:
511  *\li	The buffer's data format is correct.
512  *
513  *\li	The buffer's contents verify as correct regarding header bits, buffer
514  * 	and rdata sizes, etc.
515  *
516  * Returns:
517  *\li	#ISC_R_SUCCESS		-- all is well
518  *\li	#ISC_R_NOMEMORY		-- no memory
519  *\li	#DNS_R_RECOVERABLE	-- the message parsed properly, but contained
520  *				   errors.
521  *\li	Many other errors possible XXXMLG
522  */
523 
524 isc_result_t
525 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
526 			isc_buffer_t *buffer);
527 /*%<
528  * Begin rendering on a message.  Only one call can be made to this function
529  * per message.
530  *
531  * The compression context is "owned" by the message library until
532  * dns_message_renderend() is called.  It must be invalidated by the caller.
533  *
534  * The buffer is "owned" by the message library until dns_message_renderend()
535  * is called.
536  *
537  * Requires:
538  *
539  *\li	'msg' be valid.
540  *
541  *\li	'cctx' be valid.
542  *
543  *\li	'buffer' is a valid buffer.
544  *
545  * Side Effects:
546  *
547  *\li	The buffer is cleared before it is used.
548  *
549  * Returns:
550  *\li	#ISC_R_SUCCESS		-- all is well
551  *\li	#ISC_R_NOSPACE		-- output buffer is too small
552  */
553 
554 isc_result_t
555 dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer);
556 /*%<
557  * Reset the buffer.  This can be used after growing the old buffer
558  * on a ISC_R_NOSPACE return from most of the render functions.
559  *
560  * On successful completion, the old buffer is no longer used by the
561  * library.  The new buffer is owned by the library until
562  * dns_message_renderend() is called.
563  *
564  * Requires:
565  *
566  *\li	'msg' be valid.
567  *
568  *\li	dns_message_renderbegin() was called.
569  *
570  *\li	buffer != NULL.
571  *
572  * Returns:
573  *\li	#ISC_R_NOSPACE		-- new buffer is too small
574  *\li	#ISC_R_SUCCESS		-- all is well.
575  */
576 
577 isc_result_t
578 dns_message_renderreserve(dns_message_t *msg, unsigned int space);
579 /*%<
580  * XXXMLG should use size_t rather than unsigned int once the buffer
581  * API is cleaned up
582  *
583  * Reserve "space" bytes in the given buffer.
584  *
585  * Requires:
586  *
587  *\li	'msg' be valid.
588  *
589  *\li	dns_message_renderbegin() was called.
590  *
591  * Returns:
592  *\li	#ISC_R_SUCCESS		-- all is well.
593  *\li	#ISC_R_NOSPACE		-- not enough free space in the buffer.
594  */
595 
596 void
597 dns_message_renderrelease(dns_message_t *msg, unsigned int space);
598 /*%<
599  * XXXMLG should use size_t rather than unsigned int once the buffer
600  * API is cleaned up
601  *
602  * Release "space" bytes in the given buffer that was previously reserved.
603  *
604  * Requires:
605  *
606  *\li	'msg' be valid.
607  *
608  *\li	'space' is less than or equal to the total amount of space reserved
609  *	via prior calls to dns_message_renderreserve().
610  *
611  *\li	dns_message_renderbegin() was called.
612  */
613 
614 isc_result_t
615 dns_message_rendersection(dns_message_t *msg, dns_section_t section,
616 			  unsigned int options);
617 /*%<
618  * Render all names, rdatalists, etc from the given section at the
619  * specified priority or higher.
620  *
621  * Requires:
622  *\li	'msg' be valid.
623  *
624  *\li	'section' be a valid section.
625  *
626  *\li	dns_message_renderbegin() was called.
627  *
628  * Returns:
629  *\li	#ISC_R_SUCCESS		-- all records were written, and there are
630  *				   no more records for this section.
631  *\li	#ISC_R_NOSPACE		-- Not enough room in the buffer to write
632  *				   all records requested.
633  *\li	#DNS_R_MOREDATA		-- All requested records written, and there
634  *				   are records remaining for this section.
635  */
636 
637 void
638 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target);
639 /*%<
640  * Render the message header.  This is implicitly called by
641  * dns_message_renderend().
642  *
643  * Requires:
644  *
645  *\li	'msg' be a valid message.
646  *
647  *\li	dns_message_renderbegin() was called.
648  *
649  *\li	'target' is a valid buffer with enough space to hold a message header
650  */
651 
652 isc_result_t
653 dns_message_renderend(dns_message_t *msg);
654 /*%<
655  * Finish rendering to the buffer.  Note that more data can be in the
656  * 'msg' structure.  Destroying the structure will free this, or in a multi-
657  * part EDNS1 message this data can be rendered to another buffer later.
658  *
659  * Requires:
660  *
661  *\li	'msg' be a valid message.
662  *
663  *\li	dns_message_renderbegin() was called.
664  *
665  * Returns:
666  *\li	#ISC_R_SUCCESS		-- all is well.
667  */
668 
669 void
670 dns_message_renderreset(dns_message_t *msg);
671 /*%<
672  * Reset the message so that it may be rendered again.
673  *
674  * Notes:
675  *
676  *\li	If dns_message_renderbegin() has been called, dns_message_renderend()
677  *	must be called before calling this function.
678  *
679  * Requires:
680  *
681  *\li	'msg' be a valid message with rendering intent.
682  */
683 
684 isc_result_t
685 dns_message_firstname(dns_message_t *msg, dns_section_t section);
686 /*%<
687  * Set internal per-section name pointer to the beginning of the section.
688  *
689  * The functions dns_message_firstname() and dns_message_nextname() may
690  * be used for iterating over the owner names in a section.
691  *
692  * Requires:
693  *
694  *\li   	'msg' be valid.
695  *
696  *\li	'section' be a valid section.
697  *
698  * Returns:
699  *\li	#ISC_R_SUCCESS		-- All is well.
700  *\li	#ISC_R_NOMORE		-- No names on given section.
701  */
702 
703 isc_result_t
704 dns_message_nextname(dns_message_t *msg, dns_section_t section);
705 /*%<
706  * Sets the internal per-section name pointer to point to the next name
707  * in that section.
708  *
709  * Requires:
710  *
711  * \li  	'msg' be valid.
712  *
713  *\li	'section' be a valid section.
714  *
715  *\li	dns_message_firstname() must have been called on this section,
716  *	and the result was ISC_R_SUCCESS.
717  *
718  * Returns:
719  *\li	#ISC_R_SUCCESS		-- All is well.
720  *\li	#ISC_R_NOMORE		-- No more names in given section.
721  */
722 
723 void
724 dns_message_currentname(dns_message_t *msg, dns_section_t section,
725 			dns_name_t **name);
726 /*%<
727  * Sets 'name' to point to the name where the per-section internal name
728  * pointer is currently set.
729  *
730  * This function returns the name in the database, so any data associated
731  * with it (via the name's "list" member) contains the actual rdatasets.
732  *
733  * Requires:
734  *
735  *\li	'msg' be valid.
736  *
737  *\li	'name' be non-NULL, and *name be NULL.
738  *
739  *\li	'section' be a valid section.
740  *
741  *\li	dns_message_firstname() must have been called on this section,
742  *	and the result of it and any dns_message_nextname() calls was
743  *	#ISC_R_SUCCESS.
744  */
745 
746 isc_result_t
747 dns_message_findname(dns_message_t *msg, dns_section_t section,
748 		     const dns_name_t *target, dns_rdatatype_t type,
749 		     dns_rdatatype_t covers, dns_name_t **foundname,
750 		     dns_rdataset_t **rdataset);
751 /*%<
752  * Search for a name in the specified section.  If it is found, *name is
753  * set to point to the name, and *rdataset is set to point to the found
754  * rdataset (if type is specified as other than dns_rdatatype_any).
755  *
756  * Requires:
757  *\li	'msg' be valid.
758  *
759  *\li	'section' be a valid section.
760  *
761  *\li	If a pointer to the name is desired, 'foundname' should be non-NULL.
762  *	If it is non-NULL, '*foundname' MUST be NULL.
763  *
764  *\li	If a type other than dns_datatype_any is searched for, 'rdataset'
765  *	may be non-NULL, '*rdataset' be NULL, and will point at the found
766  *	rdataset.  If the type is dns_datatype_any, 'rdataset' must be NULL.
767  *
768  *\li	'target' be a valid name.
769  *
770  *\li	'type' be a valid type.
771  *
772  *\li	If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
773  *	Otherwise it should be 0.
774  *
775  * Returns:
776  *\li	#ISC_R_SUCCESS		-- all is well.
777  *\li	#DNS_R_NXDOMAIN		-- name does not exist in that section.
778  *\li	#DNS_R_NXRRSET		-- The name does exist, but the desired
779  *				   type does not.
780  */
781 
782 isc_result_t
783 dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type,
784 		     dns_rdatatype_t covers, dns_rdataset_t **rdataset);
785 /*%<
786  * Search the name for the specified type.  If it is found, *rdataset is
787  * filled in with a pointer to that rdataset.
788  *
789  * Requires:
790  *\li	if '**rdataset' is non-NULL, *rdataset needs to be NULL.
791  *
792  *\li	'type' be a valid type, and NOT dns_rdatatype_any.
793  *
794  *\li	If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
795  *	Otherwise it should be 0.
796  *
797  * Returns:
798  *\li	#ISC_R_SUCCESS		-- all is well.
799  *\li	#ISC_R_NOTFOUND		-- the desired type does not exist.
800  */
801 
802 isc_result_t
803 dns_message_find(const dns_name_t *name, dns_rdataclass_t rdclass,
804 		 dns_rdatatype_t type, dns_rdatatype_t covers,
805 		 dns_rdataset_t **rdataset);
806 /*%<
807  * Search the name for the specified rdclass and type.  If it is found,
808  * *rdataset is filled in with a pointer to that rdataset.
809  *
810  * Requires:
811  *\li	if '**rdataset' is non-NULL, *rdataset needs to be NULL.
812  *
813  *\li	'type' be a valid type, and NOT dns_rdatatype_any.
814  *
815  *\li	If 'type' is dns_rdatatype_rrsig, 'covers' must be a valid type.
816  *	Otherwise it should be 0.
817  *
818  * Returns:
819  *\li	#ISC_R_SUCCESS		-- all is well.
820  *\li	#ISC_R_NOTFOUND		-- the desired type does not exist.
821  */
822 
823 void
824 dns_message_movename(dns_message_t *msg, dns_name_t *name,
825 		     dns_section_t fromsection, dns_section_t tosection);
826 /*%<
827  * Move a name from one section to another.
828  *
829  * Requires:
830  *
831  *\li	'msg' be valid.
832  *
833  *\li	'name' must be a name already in 'fromsection'.
834  *
835  *\li	'fromsection' must be a valid section.
836  *
837  *\li	'tosection' must be a valid section.
838  */
839 
840 void
841 dns_message_addname(dns_message_t *msg, dns_name_t *name,
842 		    dns_section_t section);
843 /*%<
844  * Adds the name to the given section.
845  *
846  * It is the caller's responsibility to enforce any unique name requirements
847  * in a section.
848  *
849  * Requires:
850  *
851  *\li	'msg' be valid, and be a renderable message.
852  *
853  *\li	'name' be a valid absolute name.
854  *
855  *\li	'section' be a named section.
856  */
857 
858 void
859 dns_message_removename(dns_message_t *msg, dns_name_t *name,
860 		       dns_section_t section);
861 /*%<
862  * Remove a existing name from a given section.
863  *
864  * It is the caller's responsibility to ensure the name is part of the
865  * given section.
866  *
867  * Requires:
868  *
869  *\li	'msg' be valid, and be a renderable message.
870  *
871  *\li	'name' be a valid absolute name.
872  *
873  *\li	'section' be a named section.
874  */
875 
876 /*
877  * LOANOUT FUNCTIONS
878  *
879  * Each of these functions loan a particular type of data to the caller.
880  * The storage for these will vanish when the message is destroyed or
881  * reset, and must NOT be used after these operations.
882  */
883 
884 isc_result_t
885 dns_message_gettempname(dns_message_t *msg, dns_name_t **item);
886 /*%<
887  * Return a name that can be used for any temporary purpose, including
888  * inserting into the message's linked lists.  The name must be returned
889  * to the message code using dns_message_puttempname() or inserted into
890  * one of the message's sections before the message is destroyed.
891  *
892  * The name will be associated with a dns_fixedname object, and will
893  * be initialized.
894  *
895  * Requires:
896  *\li	msg be a valid message
897  *
898  *\li	item != NULL && *item == NULL
899  *
900  * Returns:
901  *\li	#ISC_R_SUCCESS		-- All is well.
902  */
903 
904 isc_result_t
905 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item);
906 /*%<
907  * Return a rdata that can be used for any temporary purpose, including
908  * inserting into the message's linked lists.  The rdata will be freed
909  * when the message is destroyed or reset.
910  *
911  * Requires:
912  *\li	msg be a valid message
913  *
914  *\li	item != NULL && *item == NULL
915  *
916  * Returns:
917  *\li	#ISC_R_SUCCESS		-- All is well.
918  */
919 
920 isc_result_t
921 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item);
922 /*%<
923  * Return a rdataset that can be used for any temporary purpose, including
924  * inserting into the message's linked lists. The name must be returned
925  * to the message code using dns_message_puttempname() or inserted into
926  * one of the message's sections before the message is destroyed.
927  *
928  * Requires:
929  *\li	msg be a valid message
930  *
931  *\li	item != NULL && *item == NULL
932  *
933  * Returns:
934  *\li	#ISC_R_SUCCESS		-- All is well.
935  */
936 
937 isc_result_t
938 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
939 /*%<
940  * Return a rdatalist that can be used for any temporary purpose, including
941  * inserting into the message's linked lists.  The rdatalist will be
942  * destroyed when the message is destroyed or reset.
943  *
944  * Requires:
945  *\li	msg be a valid message
946  *
947  *\li	item != NULL && *item == NULL
948  *
949  * Returns:
950  *\li	#ISC_R_SUCCESS		-- All is well.
951  */
952 
953 void
954 dns_message_puttempname(dns_message_t *msg, dns_name_t **item);
955 /*%<
956  * Return a borrowed name to the message's name free list.
957  *
958  * Requires:
959  *\li	msg be a valid message
960  *
961  *\li	item != NULL && *item point to a name returned by
962  *	dns_message_gettempname()
963  *
964  * Ensures:
965  *\li	*item == NULL
966  */
967 
968 void
969 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item);
970 /*%<
971  * Return a borrowed rdata to the message's rdata free list.
972  *
973  * Requires:
974  *\li	msg be a valid message
975  *
976  *\li	item != NULL && *item point to a rdata returned by
977  *	dns_message_gettemprdata()
978  *
979  * Ensures:
980  *\li	*item == NULL
981  */
982 
983 void
984 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item);
985 /*%<
986  * Return a borrowed rdataset to the message's rdataset free list.
987  *
988  * Requires:
989  *\li	msg be a valid message
990  *
991  *\li	item != NULL && *item point to a rdataset returned by
992  *	dns_message_gettemprdataset()
993  *
994  * Ensures:
995  *\li	*item == NULL
996  */
997 
998 void
999 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
1000 /*%<
1001  * Return a borrowed rdatalist to the message's rdatalist free list.
1002  *
1003  * Requires:
1004  *\li	msg be a valid message
1005  *
1006  *\li	item != NULL && *item point to a rdatalist returned by
1007  *	dns_message_gettemprdatalist()
1008  *
1009  * Ensures:
1010  *\li	*item == NULL
1011  */
1012 
1013 isc_result_t
1014 dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp,
1015 		       unsigned int *flagsp);
1016 /*%<
1017  * Assume the remaining region of "source" is a DNS message.  Peek into
1018  * it and fill in "*idp" with the message id, and "*flagsp" with the flags.
1019  *
1020  * Requires:
1021  *
1022  *\li	source != NULL
1023  *
1024  * Ensures:
1025  *
1026  *\li	if (idp != NULL) *idp == message id.
1027  *
1028  *\li	if (flagsp != NULL) *flagsp == message flags.
1029  *
1030  * Returns:
1031  *
1032  *\li	#ISC_R_SUCCESS		-- all is well.
1033  *
1034  *\li	#ISC_R_UNEXPECTEDEND	-- buffer doesn't contain enough for a header.
1035  */
1036 
1037 isc_result_t
1038 dns_message_reply(dns_message_t *msg, bool want_question_section);
1039 /*%<
1040  * Start formatting a reply to the query in 'msg'.
1041  *
1042  * Requires:
1043  *
1044  *\li	'msg' is a valid message with parsing intent, and contains a query.
1045  *
1046  * Ensures:
1047  *
1048  *\li	The message will have a rendering intent.  If 'want_question_section'
1049  *	is true, the message opcode is query or notify, and the question
1050  *	section is present and properly formatted, then the question section
1051  *	will be included in the reply.  All other sections will be cleared.
1052  *	The QR flag will be set, the RD flag will be preserved, and all other
1053  *	flags will be cleared.
1054  *
1055  * Returns:
1056  *
1057  *\li	#ISC_R_SUCCESS		-- all is well.
1058  *
1059  *\li	#DNS_R_FORMERR		-- the header or question section of the
1060  *				   message is invalid, replying is impossible.
1061  *				   If DNS_R_FORMERR is returned when
1062  *				   want_question_section is false, then
1063  *				   it's the header section that's bad;
1064  *				   otherwise either of the header or question
1065  *				   sections may be bad.
1066  */
1067 
1068 dns_rdataset_t *
1069 dns_message_getopt(dns_message_t *msg);
1070 /*%<
1071  * Get the OPT record for 'msg'.
1072  *
1073  * Requires:
1074  *
1075  *\li	'msg' is a valid message.
1076  *
1077  * Returns:
1078  *
1079  *\li	The OPT rdataset of 'msg', or NULL if there isn't one.
1080  */
1081 
1082 isc_result_t
1083 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt);
1084 /*%<
1085  * Set the OPT record for 'msg'.
1086  *
1087  * Requires:
1088  *
1089  *\li	'msg' is a valid message with rendering intent
1090  *	and no sections have been rendered.
1091  *
1092  *\li	'opt' is a valid OPT record.
1093  *
1094  * Ensures:
1095  *
1096  *\li	The OPT record has either been freed or ownership of it has
1097  *	been transferred to the message.
1098  *
1099  *\li	If ISC_R_SUCCESS was returned, the OPT record will be rendered
1100  *	when dns_message_renderend() is called.
1101  *
1102  * Returns:
1103  *
1104  *\li	#ISC_R_SUCCESS		-- all is well.
1105  *
1106  *\li	#ISC_R_NOSPACE		-- there is no space for the OPT record.
1107  */
1108 
1109 dns_rdataset_t *
1110 dns_message_gettsig(dns_message_t *msg, const dns_name_t **owner);
1111 /*%<
1112  * Get the TSIG record and owner for 'msg'.
1113  *
1114  * Requires:
1115  *
1116  *\li	'msg' is a valid message.
1117  *\li	'owner' is NULL or *owner is NULL.
1118  *
1119  * Returns:
1120  *
1121  *\li	The TSIG rdataset of 'msg', or NULL if there isn't one.
1122  *
1123  * Ensures:
1124  *
1125  * \li	If 'owner' is not NULL, it will point to the owner name.
1126  */
1127 
1128 isc_result_t
1129 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key);
1130 /*%<
1131  * Set the tsig key for 'msg'.  This is only necessary for when rendering a
1132  * query or parsing a response.  The key (if non-NULL) is attached to, and
1133  * will be detached when the message is destroyed.
1134  *
1135  * Requires:
1136  *
1137  *\li	'msg' is a valid message with rendering intent,
1138  *	dns_message_renderbegin() has been called, and no sections have been
1139  *	rendered.
1140  *\li	'key' is a valid tsig key or NULL.
1141  *
1142  * Returns:
1143  *
1144  *\li	#ISC_R_SUCCESS		-- all is well.
1145  *
1146  *\li	#ISC_R_NOSPACE		-- there is no space for the TSIG record.
1147  */
1148 
1149 dns_tsigkey_t *
1150 dns_message_gettsigkey(dns_message_t *msg);
1151 /*%<
1152  * Gets the tsig key for 'msg'.
1153  *
1154  * Requires:
1155  *
1156  *\li	'msg' is a valid message
1157  */
1158 
1159 isc_result_t
1160 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig);
1161 /*%<
1162  * Indicates that 'querytsig' is the TSIG from the signed query for which
1163  * 'msg' is the response.  This is also used for chained TSIGs in TCP
1164  * responses.
1165  *
1166  * Requires:
1167  *
1168  *\li	'querytsig' is a valid buffer as returned by dns_message_getquerytsig()
1169  *	or NULL
1170  *
1171  *\li	'msg' is a valid message
1172  *
1173  * Returns:
1174  *
1175  *\li	#ISC_R_SUCCESS
1176  *\li	#ISC_R_NOMEMORY
1177  */
1178 
1179 isc_result_t
1180 dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
1181 			 isc_buffer_t **querytsig);
1182 /*%<
1183  * Gets the tsig from the TSIG from the signed query 'msg'.  This is also used
1184  * for chained TSIGs in TCP responses.  Unlike dns_message_gettsig, this makes
1185  * a copy of the data, so can be used if the message is destroyed.
1186  *
1187  * Requires:
1188  *
1189  *\li	'msg' is a valid signed message
1190  *\li	'mctx' is a valid memory context
1191  *\li	querytsig != NULL && *querytsig == NULL
1192  *
1193  * Returns:
1194  *
1195  *\li	#ISC_R_SUCCESS
1196  *\li	#ISC_R_NOMEMORY
1197  *
1198  * Ensures:
1199  *\li 	'tsig' points to NULL or an allocated buffer which must be freed
1200  * 	by the caller.
1201  */
1202 
1203 dns_rdataset_t *
1204 dns_message_getsig0(dns_message_t *msg, const dns_name_t **owner);
1205 /*%<
1206  * Get the SIG(0) record and owner for 'msg'.
1207  *
1208  * Requires:
1209  *
1210  *\li	'msg' is a valid message.
1211  *\li	'owner' is NULL or *owner is NULL.
1212  *
1213  * Returns:
1214  *
1215  *\li	The SIG(0) rdataset of 'msg', or NULL if there isn't one.
1216  *
1217  * Ensures:
1218  *
1219  * \li	If 'owner' is not NULL, it will point to the owner name.
1220  */
1221 
1222 isc_result_t
1223 dns_message_setsig0key(dns_message_t *msg, dst_key_t *key);
1224 /*%<
1225  * Set the SIG(0) key for 'msg'.
1226  *
1227  * Requires:
1228  *
1229  *\li	'msg' is a valid message with rendering intent,
1230  *	dns_message_renderbegin() has been called, and no sections have been
1231  *	rendered.
1232  *\li	'key' is a valid sig key or NULL.
1233  *
1234  * Returns:
1235  *
1236  *\li	#ISC_R_SUCCESS		-- all is well.
1237  *
1238  *\li	#ISC_R_NOSPACE		-- there is no space for the SIG(0) record.
1239  */
1240 
1241 dst_key_t *
1242 dns_message_getsig0key(dns_message_t *msg);
1243 /*%<
1244  * Gets the SIG(0) key for 'msg'.
1245  *
1246  * Requires:
1247  *
1248  *\li	'msg' is a valid message
1249  */
1250 
1251 void
1252 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer);
1253 /*%<
1254  * Give the *buffer to the message code to clean up when it is no
1255  * longer needed.  This is usually when the message is reset or
1256  * destroyed.
1257  *
1258  * Requires:
1259  *
1260  *\li	msg be a valid message.
1261  *
1262  *\li	buffer != NULL && *buffer is a valid isc_buffer_t, which was
1263  *	dynamically allocated via isc_buffer_allocate().
1264  */
1265 
1266 isc_result_t
1267 dns_message_signer(dns_message_t *msg, dns_name_t *signer);
1268 /*%<
1269  * If this message was signed, return the identity of the signer.
1270  * Unless ISC_R_NOTFOUND is returned, signer will reflect the name of the
1271  * key that signed the message.
1272  *
1273  * Requires:
1274  *
1275  *\li	msg is a valid parsed message.
1276  *\li	signer is a valid name
1277  *
1278  * Returns:
1279  *
1280  *\li	#ISC_R_SUCCESS		- the message was signed, and *signer
1281  *				  contains the signing identity
1282  *
1283  *\li	#ISC_R_NOTFOUND		- no TSIG or SIG(0) record is present in the
1284  *				  message
1285  *
1286  *\li	#DNS_R_TSIGVERIFYFAILURE	- the message was signed by a TSIG, but
1287  * the signature failed to verify
1288  *
1289  *\li	#DNS_R_TSIGERRORSET	- the message was signed by a TSIG and
1290  *				  verified, but the query was rejected by
1291  *				  the server
1292  *
1293  *\li	#DNS_R_NOIDENTITY	- the message was signed by a TSIG and
1294  *				  verified, but the key has no identity since
1295  *				  it was generated by an unsigned TKEY process
1296  *
1297  *\li	#DNS_R_SIGINVALID	- the message was signed by a SIG(0), but
1298  *				  the signature failed to verify
1299  *
1300  *\li	#DNS_R_NOTVERIFIEDYET	- the message was signed by a TSIG or SIG(0),
1301  *				  but the signature has not been verified yet
1302  */
1303 
1304 isc_result_t
1305 dns_message_checksig(dns_message_t *msg, dns_view_t *view);
1306 /*%<
1307  * If this message was signed, verify the signature.
1308  *
1309  * Requires:
1310  *
1311  *\li	msg is a valid parsed message.
1312  *\li	view is a valid view or NULL
1313  *
1314  * Returns:
1315  *
1316  *\li	#ISC_R_SUCCESS		- the message was unsigned, or the message
1317  *				  was signed correctly.
1318  *
1319  *\li	#DNS_R_EXPECTEDTSIG	- A TSIG was expected, but not seen
1320  *\li	#DNS_R_UNEXPECTEDTSIG	- A TSIG was seen but not expected
1321  *\li	#DNS_R_TSIGVERIFYFAILURE - The TSIG failed to verify
1322  */
1323 
1324 isc_result_t
1325 dns_message_rechecksig(dns_message_t *msg, dns_view_t *view);
1326 /*%<
1327  * Reset the signature state and then if the message was signed,
1328  * verify the message.
1329  *
1330  * Requires:
1331  *
1332  *\li	msg is a valid parsed message.
1333  *\li	view is a valid view or NULL
1334  *
1335  * Returns:
1336  *
1337  *\li	#ISC_R_SUCCESS		- the message was unsigned, or the message
1338  *				  was signed correctly.
1339  *
1340  *\li	#DNS_R_EXPECTEDTSIG	- A TSIG was expected, but not seen
1341  *\li	#DNS_R_UNEXPECTEDTSIG	- A TSIG was seen but not expected
1342  *\li	#DNS_R_TSIGVERIFYFAILURE - The TSIG failed to verify
1343  */
1344 
1345 void
1346 dns_message_resetsig(dns_message_t *msg);
1347 /*%<
1348  * Reset the signature state.
1349  *
1350  * Requires:
1351  *\li	'msg' is a valid parsed message.
1352  */
1353 
1354 isc_region_t *
1355 dns_message_getrawmessage(dns_message_t *msg);
1356 /*%<
1357  * Retrieve the raw message in compressed wire format.  The message must
1358  * have been successfully parsed for it to have been saved.
1359  *
1360  * Requires:
1361  *\li	msg is a valid parsed message.
1362  *
1363  * Returns:
1364  *\li	NULL	if there is no saved message.
1365  *	a pointer to a region which refers the dns message.
1366  */
1367 
1368 void
1369 dns_message_setsortorder(dns_message_t *msg, dns_rdatasetorderfunc_t order,
1370 			 dns_aclenv_t *env, const dns_acl_t *acl,
1371 			 const dns_aclelement_t *element);
1372 /*%<
1373  * Define the order in which RR sets get rendered by
1374  * dns_message_rendersection() to be the ascending order
1375  * defined by the integer value returned by 'order' when
1376  * given each RR and a ns_sortlist_arg_t constructed from 'env',
1377  * 'acl', and 'element' as arguments.
1378  *
1379  * If 'order' is NULL, a default order is used.
1380  *
1381  * Requires:
1382  *\li	msg be a valid message.
1383  *\li	If 'env' is NULL, 'order' must be NULL.
1384  *\li	If 'env' is not NULL, 'order' must not be NULL and at least one of
1385  *	'acl' and 'element' must also not be NULL.
1386  */
1387 
1388 void
1389 dns_message_settimeadjust(dns_message_t *msg, int timeadjust);
1390 /*%<
1391  * Adjust the time used to sign/verify a message by timeadjust.
1392  * Currently only TSIG.
1393  *
1394  * Requires:
1395  *\li	msg be a valid message.
1396  */
1397 
1398 int
1399 dns_message_gettimeadjust(dns_message_t *msg);
1400 /*%<
1401  * Return the current time adjustment.
1402  *
1403  * Requires:
1404  *\li	msg be a valid message.
1405  */
1406 
1407 void
1408 dns_message_logpacket(dns_message_t *message, const char *description,
1409 		      const isc_sockaddr_t *address,
1410 		      isc_logcategory_t *category, isc_logmodule_t *module,
1411 		      int level, isc_mem_t *mctx);
1412 
1413 void
1414 dns_message_logfmtpacket(dns_message_t *message, const char *description,
1415 			 const isc_sockaddr_t *address,
1416 			 isc_logcategory_t *category, isc_logmodule_t *module,
1417 			 const dns_master_style_t *style, int level,
1418 			 isc_mem_t *mctx);
1419 /*%<
1420  * Log 'message' at the specified logging parameters.
1421  *
1422  * For dns_message_logpacket and dns_message_logfmtpacket expect the
1423  * 'description' to end in a newline.
1424  *
1425  * For dns_message_logpacket2 and dns_message_logfmtpacket2
1426  * 'description' will be emitted at the start of the message followed
1427  * by the formatted address and a newline.
1428  *
1429  * Requires:
1430  * \li   message be a valid.
1431  * \li   description to be non NULL.
1432  * \li   address to be non NULL.
1433  * \li   category to be valid.
1434  * \li   module to be valid.
1435  * \li   style to be valid.
1436  * \li   mctx to be a valid.
1437  */
1438 
1439 isc_result_t
1440 dns_message_buildopt(dns_message_t *msg, dns_rdataset_t **opt,
1441 		     unsigned int version, uint16_t udpsize, unsigned int flags,
1442 		     dns_ednsopt_t *ednsopts, size_t count);
1443 /*%<
1444  * Built a opt record.
1445  *
1446  * Requires:
1447  * \li   msg be a valid message.
1448  * \li   opt to be a non NULL and *opt to be NULL.
1449  *
1450  * Returns:
1451  * \li	 ISC_R_SUCCESS on success.
1452  * \li	 ISC_R_NOMEMORY
1453  * \li	 ISC_R_NOSPACE
1454  * \li	 other.
1455  */
1456 
1457 void
1458 dns_message_setclass(dns_message_t *msg, dns_rdataclass_t rdclass);
1459 /*%<
1460  * Set the expected class of records in the response.
1461  *
1462  * Requires:
1463  * \li   msg be a valid message with parsing intent.
1464  */
1465 
1466 void
1467 dns_message_setpadding(dns_message_t *msg, uint16_t padding);
1468 /*%<
1469  * Set the padding block size in the response.
1470  * 0 means no padding (default).
1471  *
1472  * Requires:
1473  * \li	msg be a valid message.
1474  */
1475 
1476 void
1477 dns_message_clonebuffer(dns_message_t *msg);
1478 /*%<
1479  * Clone the query or saved buffers if they where not cloned
1480  * when parsing.
1481  *
1482  * Requires:
1483  * \li   msg be a valid message.
1484  */
1485 
1486 ISC_LANG_ENDDECLS
1487