message.h 16.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 1999  Internet Software Consortium.
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

18 19
#ifndef DNS_MESSAGE_H
#define DNS_MESSAGE_H 1
20 21 22 23 24 25

/***
 ***	Imports
 ***/

#include <isc/mem.h>
Michael Graff's avatar
Michael Graff committed
26
#include <isc/buffer.h>
27 28 29 30 31

#include <dns/types.h>
#include <dns/result.h>
#include <dns/name.h>
#include <dns/rdataset.h>
Michael Graff's avatar
Michael Graff committed
32
#include <dns/compress.h>
33 34 35 36

/*
 * How this beast works:
 *
37
 * When a dns message is received in a buffer, dns_message_fromwire() is called
38 39 40 41 42 43 44 45
 * on the memory region.  Various items are checked including the format
 * of the message (if counts are right, if counts consume the entire sections,
 * and if sections consume the entire message) and known pseudo-RRs in the
 * additional data section are analyzed and removed.
 *
 * TSIG checking is also done at this layer, and any DNSSEC information should
 * also be performed at this time.
 *
46
 * If dns_message_fromwire() returns DNS_R_MOREDATA additional
47 48
 * message packets are required.  This implies an EDNS message.
 *
49
 * When going from structure to wire, dns_message_towire() will return
Michael Graff's avatar
typo  
Michael Graff committed
50
 * DNS_R_MOREDATA if there is more data left in the output buffer that
51 52 53 54 55 56 57 58 59
 * could not be rendered into the exisiting buffer.
 *
 * XXX Needed:  ways to handle TSIG and DNSSEC, supply TSIG and DNSSEC
 * keys, set and retrieve EDNS information, add rdata to a section,
 * move rdata from one section to another, remove rdata, etc.
 */

ISC_LANG_BEGINDECLS

60 61 62 63 64
#define DNS_MESSAGEFLAG_QR		0x8000U
#define DNS_MESSAGEFLAG_AA		0x0400U
#define DNS_MESSAGEFLAG_TC		0x0200U
#define DNS_MESSAGEFLAG_RD		0x0100U
#define DNS_MESSAGEFLAG_RA		0x0080U
65

Michael Graff's avatar
Michael Graff committed
66
#define DNS_MESSAGE_HEADERLEN		    12 /* 6 u_int16_t's */
67

Michael Graff's avatar
Michael Graff committed
68 69
#define MESSAGE_MAGIC		0x4d534740U	/* MSG@ */
#define VALID_MESSAGE(msg)	(((msg)->magic) == MESSAGE_MAGIC)
Michael Graff's avatar
Michael Graff committed
70

Michael Graff's avatar
Michael Graff committed
71 72 73 74
/*
 * Ordering here matters.  DNS_SECTION_ANY must be the lowest and negative,
 * and DNS_SECTION_MAX must be one greater than the last used section.
 */
Michael Graff's avatar
Michael Graff committed
75
typedef int dns_section_t;
Michael Graff's avatar
Michael Graff committed
76
#define DNS_SECTION_ANY			(-1)
Michael Graff's avatar
Michael Graff committed
77 78 79 80
#define DNS_SECTION_QUESTION		0
#define DNS_SECTION_ANSWER		1
#define DNS_SECTION_AUTHORITY		2
#define DNS_SECTION_ADDITIONAL		3
81 82 83 84 85 86 87 88 89
#define DNS_SECTION_TSIG		4 /* pseudo-section */
#define DNS_SECTION_MAX			5

/*
 * Dynamic update named for these sections.
 */
#define DNS_SECTION_ZONE		DNS_SECTION_QUESTION
#define DNS_SECTION_PREREQUISITE	DNS_SECTION_ANSWER
#define DNS_SECTION_UPDATE		DNS_SECTION_AUTHORITY
Michael Graff's avatar
Michael Graff committed
90 91

/*
Michael Graff's avatar
Michael Graff committed
92
 * These tell the message library how the created dns_message_t will be used.
Michael Graff's avatar
Michael Graff committed
93
 */
Michael Graff's avatar
Michael Graff committed
94 95 96
#define DNS_MESSAGE_INTENTUNKNOWN	0 /* internal use only */
#define DNS_MESSAGE_INTENTPARSE		1 /* parsing messages */
#define DNS_MESSAGE_INTENTRENDER	2 /* rendering */
Michael Graff's avatar
Michael Graff committed
97

Michael Graff's avatar
Michael Graff committed
98 99
typedef struct dns_msgblock dns_msgblock_t;

100
typedef struct {
Michael Graff's avatar
Michael Graff committed
101
	/* public from here down */
Michael Graff's avatar
Michael Graff committed
102
	unsigned int			magic;
103

Michael Graff's avatar
Michael Graff committed
104
	unsigned int			id;
Michael Graff's avatar
Michael Graff committed
105 106 107
	unsigned int			flags;
	unsigned int			rcode;
	unsigned int			opcode;
Michael Graff's avatar
Michael Graff committed
108
	dns_rdataclass_t		rdclass;
Michael Graff's avatar
Michael Graff committed
109

110
	/* 4 real, 1 pseudo */
Michael Graff's avatar
Michael Graff committed
111
	unsigned int			counts[DNS_SECTION_MAX];
Michael Graff's avatar
Michael Graff committed
112 113

	/* private from here down */
Michael Graff's avatar
Michael Graff committed
114 115
	dns_namelist_t			sections[DNS_SECTION_MAX];
	dns_name_t		       *cursors[DNS_SECTION_MAX];
116
	dns_rdata_t		       *opt;
117

Michael Graff's avatar
Michael Graff committed
118
	int				state;
Michael Graff's avatar
Michael Graff committed
119
	unsigned int			from_to_wire : 2;
Michael Graff's avatar
Michael Graff committed
120
	unsigned int			reserved;
121

122
	isc_buffer_t		       *buffer;
Michael Graff's avatar
Michael Graff committed
123 124
	dns_compress_t			cctx;
	isc_boolean_t			need_cctx_cleanup;
125

Michael Graff's avatar
Michael Graff committed
126
	isc_mem_t		       *mctx;
Michael Graff's avatar
Michael Graff committed
127
	ISC_LIST(isc_dynbuffer_t)	scratchpad;
Michael Graff's avatar
Michael Graff committed
128 129
	ISC_LIST(dns_msgblock_t)	names;
	ISC_LIST(dns_msgblock_t)	rdatas;
Michael Graff's avatar
Michael Graff committed
130
	ISC_LIST(dns_msgblock_t)	rdatasets;
Michael Graff's avatar
Michael Graff committed
131
	ISC_LIST(dns_msgblock_t)	rdatalists;
Michael Graff's avatar
Michael Graff committed
132 133 134 135
	dns_name_t		       *nextname;
	dns_rdata_t		       *nextrdata;
	dns_rdataset_t		       *nextrdataset;
	dns_rdatalist_t		       *nextrdatalist;
Michael Graff's avatar
Michael Graff committed
136
} dns_message_t;
137

Michael Graff's avatar
Michael Graff committed
138
dns_result_t
Michael Graff's avatar
Michael Graff committed
139 140
dns_message_create(isc_mem_t *mctx, dns_message_t **msgp,
		   unsigned int intent);
141
/*
Michael Graff's avatar
Michael Graff committed
142
 * Create msg structure.
143
 *
Michael Graff's avatar
Michael Graff committed
144
 * This function will allocate some internal blocks of memory that are
Michael Graff's avatar
Michael Graff committed
145
 * expected to be needed for parsing or rendering nearly any type of message.
Michael Graff's avatar
Michael Graff committed
146 147 148
 *
 * Requires:
 *	'mctx' be a valid memory context.
149
 *
Michael Graff's avatar
Michael Graff committed
150
 *	'msgp' be non-null and '*msg' be NULL.
Michael Graff's avatar
Michael Graff committed
151 152 153
 *
 *	'intent' must be one of DNS_MESSAGE_INTENT_PARSE or
 *	DNS_MESSAGE_INTENT_RENDER.
Michael Graff's avatar
Michael Graff committed
154 155
 *
 * Ensures:
Michael Graff's avatar
Michael Graff committed
156
 *	The data in "*msg" is set to indicate an unused and empty msg
Michael Graff's avatar
Michael Graff committed
157 158 159
 *	structure.
 *
 * Returns:
160 161
 *	DNS_R_NOMEMORY		-- out of memory
 *	DNS_R_SUCCESS		-- success
162 163
 */

Michael Graff's avatar
Michael Graff committed
164 165 166 167 168 169 170 171
void
dns_message_reset(dns_message_t *msg);
/*
 * Reset a message structure to default state.  All internal lists are freed
 * or reset to a default state as well.  This is simply a more efficient
 * way to call dns_message_destroy() followed by dns_message_allocate(),
 * since it avoid many memory allocations.
 *
Michael Graff's avatar
Michael Graff committed
172 173 174
 * If any data loanouts (buffers, names, rdatas, etc) were requested,
 * the caller must no longer use them after this call.
 *
Michael Graff's avatar
Michael Graff committed
175 176 177 178
 * Requires:
 *
 *	'msg' be valid.
 */
Michael Graff's avatar
Michael Graff committed
179

Michael Graff's avatar
Michael Graff committed
180
void
Michael Graff's avatar
Michael Graff committed
181
dns_message_destroy(dns_message_t **msgp);
Michael Graff's avatar
Michael Graff committed
182
/*
Michael Graff's avatar
Michael Graff committed
183 184 185 186
 * Destroy all state in the message.
 *
 * Requires:
 *
Michael Graff's avatar
Michael Graff committed
187
 *	'msgp' be valid.
Michael Graff's avatar
Michael Graff committed
188 189
 *
 * Ensures:
Michael Graff's avatar
Michael Graff committed
190
 *	'*msgp' == NULL
Michael Graff's avatar
Michael Graff committed
191 192
 */

Michael Graff's avatar
Michael Graff committed
193
dns_result_t
Michael Graff's avatar
Michael Graff committed
194
dns_message_parse(dns_message_t *msg, isc_buffer_t *source);
Michael Graff's avatar
Michael Graff committed
195
/*
Michael Graff's avatar
Michael Graff committed
196 197 198 199 200 201 202
 * Parse raw wire data pointed to by "buffer" and bounded by "buflen" as a
 * DNS message.
 *
 * OPT records are detected and stored in the pseudo-section "opt".
 * TSIGs are detected and stored in the pseudo-section "tsig".  At detection
 * time, the TSIG is verified (XXX) and the message fails if the TSIG fails
 * to verify.
Michael Graff's avatar
Michael Graff committed
203 204 205 206 207 208 209 210 211
 *
 * If this is a multi-packet message (edns) and more data is required to
 * build the full message state, DNS_R_MOREDATA is returned.  In this case,
 * this function should be repeated with all input buffers until DNS_R_SUCCESS
 * (or an error) is returned.
 *
 * Requires:
 *	"msg" be valid.
 *
Michael Graff's avatar
Michael Graff committed
212
 *	"buffer" be a wire format binary buffer.
Michael Graff's avatar
Michael Graff committed
213 214 215 216
 *
 * Ensures:
 *	The buffer's data format is correct.
 *
Michael Graff's avatar
Michael Graff committed
217 218
 *	The buffer's contents verify as correct regarding header bits, buffer
 * 	and rdata sizes, etc.
Michael Graff's avatar
Michael Graff committed
219 220 221
 *
 * Returns:
 *	DNS_R_SUCCESS		-- all is well
Michael Graff's avatar
Michael Graff committed
222
 *	DNS_R_NOMEMORY		-- no memory
Michael Graff's avatar
Michael Graff committed
223
 *	DNS_R_MOREDATA		-- more packets needed for complete message
Michael Graff's avatar
Michael Graff committed
224 225
 *	DNS_R_???		-- bad signature (XXXMLG need more of these)
 *	Many other errors possible XXXMLG
Michael Graff's avatar
Michael Graff committed
226 227
 */

Michael Graff's avatar
Michael Graff committed
228 229
dns_result_t
dns_message_renderbegin(dns_message_t *msg, isc_buffer_t *buffer);
Michael Graff's avatar
Michael Graff committed
230
/*
Michael Graff's avatar
Michael Graff committed
231 232
 * Begin rendering on a message.  Only one call can be made to this function
 * per message.
Michael Graff's avatar
Michael Graff committed
233
 *
Michael Graff's avatar
Michael Graff committed
234 235 236
 * The buffer is "owned" buy the message library until dns_message_renderend()
 * is called.
 *
Michael Graff's avatar
Michael Graff committed
237
 * Requires:
Michael Graff's avatar
Michael Graff committed
238 239
 *
 *	'msg' be valid.
240
 *
Michael Graff's avatar
Michael Graff committed
241 242 243 244 245
 *	buffer is a valid binary buffer.
 *
 * Side Effects:
 *
 *	The buffer is cleared before it is used.
246
 *
Michael Graff's avatar
Michael Graff committed
247 248 249 250
 * Returns:
 *	DNS_R_SUCCESS		-- all is well
 *	DNS_R_NOSPACE		-- output buffer is too small
 *	Anything that dns_compress_init() can return.
Michael Graff's avatar
Michael Graff committed
251 252 253
 */

dns_result_t
254 255 256 257 258
dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer);
/*
 * Reset the buffer.  This can be used after growing the old buffer
 * on a DNS_R_NOSPACE return from most of the render functions.
 *
Michael Graff's avatar
Michael Graff committed
259 260 261 262
 * On successful completion, the old buffer is no longer used by the
 * library.  The new buffer is owned by the library until
 * dns_message_renderend() is called.
 *
263 264 265 266 267 268 269 270 271
 * Requires:
 *
 *	'msg' be valid.
 *
 *	dns_message_renderbegin() was called.
 *
 *	buffer != NULL.
 *
 * Returns:
272 273
 *	DNS_R_NOSPACE		-- new buffer is too small
 *	DNS_R_SUCCESS		-- all is well.
274 275 276 277
 */

dns_result_t
dns_message_renderreserve(dns_message_t *msg, unsigned int space);
Michael Graff's avatar
Michael Graff committed
278
/*
Michael Graff's avatar
Michael Graff committed
279 280 281
 * XXXMLG should use size_t rather than unsigned int once the buffer
 * API is cleaned up
 *
Michael Graff's avatar
Michael Graff committed
282 283 284 285 286
 * Reserve "space" bytes in the given buffer.
 *
 * Requires:
 *
 *	'msg' be valid.
Michael Graff's avatar
Michael Graff committed
287
 *
288 289
 *	dns_message_renderbegin() was called.
 *
Michael Graff's avatar
Michael Graff committed
290
 * Returns:
Michael Graff's avatar
Michael Graff committed
291 292
 *	DNS_R_SUCCESS		-- all is well.
 *	DNS_R_NOSPACE		-- not enough free space in the buffer.
Michael Graff's avatar
Michael Graff committed
293 294
 */

Michael Graff's avatar
Michael Graff committed
295 296 297
dns_result_t
dns_message_renderrelease(dns_message_t *msg, unsigned int space);
/*
Michael Graff's avatar
Michael Graff committed
298 299 300
 * XXXMLG should use size_t rather than unsigned int once the buffer
 * API is cleaned up
 *
Michael Graff's avatar
Michael Graff committed
301 302 303 304 305 306
 * Release "space" bytes in the given buffer that was previously reserved.
 *
 * Requires:
 *
 *	'msg' be valid.
 *
307 308
 *	dns_message_renderbegin() was called.
 *
Michael Graff's avatar
Michael Graff committed
309 310 311 312 313
 * Returns:
 *	DNS_R_SUCCESS		-- all is well.
 *	DNS_R_NOSPACE		-- trying to release more than was reserved.
 */

Michael Graff's avatar
Michael Graff committed
314
dns_result_t
315
dns_message_rendersection(dns_message_t *msg, dns_section_t section,
Michael Graff's avatar
Michael Graff committed
316
			  unsigned int priority, unsigned int options);
Michael Graff's avatar
Michael Graff committed
317
/*
Michael Graff's avatar
Michael Graff committed
318 319
 * Render all names, rdatalists, etc from the given section at the
 * specified priority or higher.
Michael Graff's avatar
Michael Graff committed
320 321
 *
 * Requires:
Michael Graff's avatar
Michael Graff committed
322 323 324
 *	'msg' be valid.
 *
 *	'section' be a valid section.
Michael Graff's avatar
Michael Graff committed
325
 *
326 327
 *	dns_message_renderbegin() was called.
 *
Michael Graff's avatar
Michael Graff committed
328
 * Returns:
Michael Graff's avatar
Michael Graff committed
329 330 331 332 333 334
 *	DNS_R_SUCCESS		-- all records were written, and there are
 *				   no more records for this section.
 *	DNS_R_NOSPACE		-- Not enough room in the buffer to write
 *				   all records requested.
 *	DNS_R_MOREDATA		-- All requested records written, and there
 *				   are records remaining for this section.
Michael Graff's avatar
Michael Graff committed
335 336
 */

Michael Graff's avatar
Michael Graff committed
337
dns_result_t
338
dns_message_renderend(dns_message_t *msg);
Michael Graff's avatar
Michael Graff committed
339
/*
Michael Graff's avatar
Michael Graff committed
340 341 342 343 344 345 346 347
 * Finish rendering to the buffer.  Note that more data can be in the
 * 'msg' structure.  Destroying the structure will free this, or in a multi-
 * part EDNS1 message this data can be rendered to another buffer later.
 *
 * Requires:
 *
 *	'msg' be a valid message.
 *
348 349
 *	dns_message_renderbegin() was called.
 *
Michael Graff's avatar
Michael Graff committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
 * Returns:
 *	DNS_R_SUCCESS		-- all is well.
 */
		      

dns_result_t
dns_message_firstname(dns_message_t *msg, dns_section_t section);
/*
 * Set internal per-section name pointer to the beginning of the section.
 *
 * Requires:
 *
 *   	'msg' be valid.
 *
 *	'section' be a valid section.
 *
 * Returns:
 *	DNS_R_SUCCESS		-- All is well.
 *	DNS_R_NOMORE		-- No names on given section.
 */

dns_result_t
dns_message_nextname(dns_message_t *msg, dns_section_t section);
/*
 * Sets the internal per-section name pointer to point to the next name
 * in that section.
 *
 * Requires:
 *
 *   	'msg' be valid.
 *
 *	'section' be a valid section.
 *
Michael Graff's avatar
Michael Graff committed
383 384 385
 *	dns_message_firstname() must have been called on this section,
 *	and the result was DNS_R_SUCCESS.
 *
Michael Graff's avatar
Michael Graff committed
386 387 388 389 390
 * Returns:
 *	DNS_R_SUCCESS		-- All is well.
 *	DNS_R_NOMORE		-- No names in given section.
 */

Michael Graff's avatar
Michael Graff committed
391
void
Michael Graff's avatar
Michael Graff committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405
dns_message_currentname(dns_message_t *msg, dns_section_t section,
			dns_name_t **name);
/*
 * Sets 'name' to point to the name where the per-section internal name
 * pointer is currently set.
 *
 * Requires:
 *
 *	'msg' be valid.
 *
 *	'name' be non-NULL, and *name be NULL.
 *
 *	'section' be a valid section.
 *
Michael Graff's avatar
Michael Graff committed
406 407 408
 *	dns_message_firstname() must have been called on this section,
 *	and the result of it and any dns_message_nextname() calls was
 *	DNS_R_SUCCESS.
Michael Graff's avatar
Michael Graff committed
409 410
 */

Michael Graff's avatar
Michael Graff committed
411 412 413
dns_result_t
dns_message_findname(dns_message_t *msg, dns_section_t section,
		     dns_name_t *target, dns_rdatatype_t type,
Michael Graff's avatar
Michael Graff committed
414
		     dns_name_t **foundname, dns_rdataset_t **rdataset);
Michael Graff's avatar
Michael Graff committed
415
/*
Michael Graff's avatar
Michael Graff committed
416 417 418 419 420 421 422 423 424
 * Search for a name in the specified section.  If it is found, *name is
 * set to point to the name, and *rdataset is set to point to the found
 * rdataset (if type is specified as other than dns_rdatatype_any.)
 *
 * Requires:
 *	'msg' be valid.
 *
 *	'section' be a valid section.
 *
Michael Graff's avatar
Michael Graff committed
425 426
 *	If a pointer to the name is desired, 'foundname' should be non-NULL.
 *	If it is non-NULL, '*foundname' MUST be NULL.
Michael Graff's avatar
Michael Graff committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440
 *
 *	If a type other than dns_datatype_any is searched for, 'rdataset'
 *	may be non-NULL, '*rdataset' be NULL, and will point at the found
 *	rdataset.
 *
 *	'target' be a valid name.
 *
 *	'type' be a valid type.
 *
 * Returns:
 *	DNS_R_SUCCESS		-- all is well.
 *	DNS_R_NXDOMAIN		-- name does not exist in that section.
 *	DNS_R_NXRDATASET	-- The name does exist, but the desired
 *				   type does not.
Michael Graff's avatar
Michael Graff committed
441 442
 */

Michael Graff's avatar
Michael Graff committed
443 444 445 446
void
dns_message_movename(dns_message_t *msg, dns_name_t *name,
		     dns_section_t fromsection,
		     dns_section_t tosection);
Michael Graff's avatar
Michael Graff committed
447 448
/*
 * Move a name from one section to another.
Michael Graff's avatar
Michael Graff committed
449 450 451 452 453
 *
 * Requires:
 *
 *	'msg' be valid.
 *
Michael Graff's avatar
Michael Graff committed
454
 *	'name' must be a name already in 'fromsection'.
Michael Graff's avatar
Michael Graff committed
455 456 457
 *
 *	'fromsection' must be a valid section.
 *
Michael Graff's avatar
Michael Graff committed
458
 *	'tosection' must be a valid section.
Michael Graff's avatar
Michael Graff committed
459 460
 */

Michael Graff's avatar
Michael Graff committed
461 462 463
void
dns_message_addname(dns_message_t *msg, dns_name_t *name,
		    dns_section_t section);
Michael Graff's avatar
Michael Graff committed
464 465 466
/*
 * Adds the name to the given section.
 *
Michael Graff's avatar
Michael Graff committed
467 468
 * It is the caller's responsibility to enforce any unique name requirements
 * in a section.
Michael Graff's avatar
Michael Graff committed
469 470 471 472 473 474 475 476
 *
 * Requires:
 *
 *	'msg' be valid, and be a renderable message.
 *
 *	'name' be a valid name.
 *
 *	'section' be a named section.
Michael Graff's avatar
Michael Graff committed
477
 */
478

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
/*
 * LOANOUT FUNCTIONS
 *
 * Each of these functions loan a particular type of data to the caller.
 * The storage for these will vanish when the message is destroyed or
 * reset, and must NOT be used after these operations.
 */

dns_result_t
dns_message_gettempname(dns_message_t *msg, dns_name_t **item);
/*
 * Return a name that can be used for any temporary purpose, including
 * inserting into the message's linked lists.  The storage associated with
 * this name will be destroyed when the message is destroyed or reset.
 *
 * It is the caller's responsibility to initialize this name.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item == NULL
 *
 * Returns:
 *	DNS_R_SUCCESS		-- All is well.
 *	DNS_R_NOMEMORY		-- No item can be allocated.
 */

dns_result_t
dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item);
/*
 * Return a rdata that can be used for any temporary purpose, including
 * inserting into the message's linked lists.  The storage associated with
 * this rdata will be destroyed when the message is destroyed or reset.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item == NULL
 *
 * Returns:
 *	DNS_R_SUCCESS		-- All is well.
 *	DNS_R_NOMEMORY		-- No item can be allocated.
 */

dns_result_t
dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item);
/*
 * Return a rdataset that can be used for any temporary purpose, including
 * inserting into the message's linked lists.  The storage associated with
 * this rdataset will be destroyed when the message is destroyed or reset.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item == NULL
 *
 * Returns:
 *	DNS_R_SUCCESS		-- All is well.
 *	DNS_R_NOMEMORY		-- No item can be allocated.
 */

dns_result_t
dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
/*
 * Return a rdatalist that can be used for any temporary purpose, including
 * inserting into the message's linked lists.  The storage associated with
 * this rdatalist will be destroyed when the message is destroyed or reset.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item == NULL
 *
 * Returns:
 *	DNS_R_SUCCESS		-- All is well.
 *	DNS_R_NOMEMORY		-- No item can be allocated.
 */

void
dns_message_puttempname(dns_message_t *msg, dns_name_t **item);
/*
 * Return a borrowed name to the message's name free list.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item point to a name returned by
 *	dns_message_gettempname()
 *
 * Ensures:
 *	*item == NULL
 */

void
dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item);
/*
 * Return a borrowed rdata to the message's rdata free list.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item point to a rdata returned by
 *	dns_message_gettemprdata()
 *
 * Ensures:
 *	*item == NULL
 */

void
dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item);
/*
 * Return a borrowed rdataset to the message's rdataset free list.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item point to a rdataset returned by
 *	dns_message_gettemprdataset()
 *
 * Ensures:
 *	*item == NULL
 */

void
dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
/*
 * Return a borrowed rdatalist to the message's rdatalist free list.
 *
 * Requires:
 *	msg be a valid message
 *
 *	item != NULL && *item point to a rdatalist returned by
 *	dns_message_gettemprdatalist()
 *
 * Ensures:
 *	*item == NULL
 */

617 618 619
ISC_LANG_ENDDECLS

#endif	/* DNS_DNS_H */