message.c revision ecb6c5782ea248307e86c4bceac6c371d27576a6
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * Copyright (C) 1999, 2000 Internet Software Consortium.
19c7b1a0293498a3e36692c59646ed6e15ffc8d0Tinderbox User * Permission to use, copy, modify, and distribute this software for any
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews * purpose with or without fee is hereby granted, provided that the above
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define VALID_NAMED_SECTION(s) (((s) > DNS_SECTION_ANY) \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define VALID_SECTION(s) (((s) >= DNS_SECTION_ANY) \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * This is the size of each individual scratchpad buffer, and the numbers
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * of various block allocations used within the server.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * XXXMLG These should come from a config setting.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * "helper" type, which consists of a block of some type, and is linkable.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * For it to work, sizeof(dns_msgblock_t) must be a multiple of the pointer
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * size, or the allocated elements will not be alligned correctly.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int count;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int remaining;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}; /* dynamically sized */
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonmsgblock_allocate(isc_mem_t *, unsigned int, unsigned int);
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson ((type *)msgblock_internalget(block, sizeof(type)))
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinmsgblock_internalget(dns_msgblock_t *, unsigned int);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonmsgblock_free(isc_mem_t *, dns_msgblock_t *, unsigned int);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Allocate a new dns_msgblock_t, and return a pointer to it. If no memory
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * is free, return NULL.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonmsgblock_allocate(isc_mem_t *mctx, unsigned int sizeof_type,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int count)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int length;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein length = sizeof(dns_msgblock_t) + (sizeof_type * count);
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Return an element from the msgblock. If no more are available, return
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void *
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonmsgblock_internalget(dns_msgblock_t *block, unsigned int sizeof_type)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Release memory associated with a message block.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinmsgblock_free(isc_mem_t *mctx, dns_msgblock_t *block,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int length;
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson length = sizeof(dns_msgblock_t) + (sizeof_type * block->count);
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson * Allocate a new dynamic buffer, and attach it to this message as the
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * "current" buffer. (which is always the last on the list, for our
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonnewbuffer(dns_message_t *msg, unsigned int size)
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson result = isc_buffer_allocate(msg->mctx, &dynbuf, size,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline isc_buffer_t *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinreleaserdata(dns_message_t *msg, dns_rdata_t *rdata)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline dns_rdata_t *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein msgblock = msgblock_allocate(msg->mctx, sizeof(dns_rdata_t),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinstatic inline void
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinreleaserdatalist(dns_message_t *msg, dns_rdatalist_t *rdatalist)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ISC_LIST_PREPEND(msg->freerdatalist, rdatalist, link);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein rdatalist = msgblock_get(msgblock, dns_rdatalist_t);
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews rdatalist = msgblock_get(msgblock, dns_rdatalist_t);
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntstatic inline void
m->id = 0;
m->flags = 0;
m->rcode = 0;
m->opcode = 0;
m->rdclass = 0;
for (i = 0; i < DNS_SECTION_MAX; i++) {
m->counts[i] = 0;
m->opt_reserved = 0;
m->reserved = 0;
m->need_cctx_cleanup = 0;
msginitheader(m);
msginitprivate(m);
msginittsig(m);
m->header_ok = 0;
m->question_ok = 0;
m->tcp_continuation = 0;
m->verified_sig = 0;
m->verify_attempted = 0;
if (!everything) {
if (!everything) {
sizeof(dns_rdata_any_tsig_t));
sizeof(dns_rdata_any_tsig_t));
if (!everything)
dns_message_t *m;
if (m == NULL)
return (DNS_R_NOMEMORY);
msginit(m);
for (i = 0 ; i < DNS_SECTION_MAX ; i++)
goto cleanup;
&m->rdspool);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
*msgp = m;
return (DNS_R_SUCCESS);
m->magic = 0;
return (DNS_R_NOMEMORY);
static isc_result_t
return (DNS_R_SUCCESS);
return (DNS_R_NOTFOUND);
return (DNS_R_SUCCESS);
return (DNS_R_NOTFOUND);
static isc_result_t
unsigned int tries;
tries = 0;
scratch);
tries++;
return (result);
return (result);
return (DNS_R_UNEXPECTED);
static isc_result_t
unsigned int tries;
unsigned int trysize;
return (DNS_R_SUCCESS);
tries = 0;
trysize = 0;
scratch);
if (tries == 0) {
return (ISC_R_NOSPACE);
tries++;
return (result);
return (result);
static isc_result_t
isc_region_t r;
unsigned int count;
return (DNS_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
return (DNS_R_SUCCESS);
if (free_name)
return (result);
static isc_result_t
isc_region_t r;
return (DNS_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
attributes = 0;
goto cleanup;
else if (covers == 0) {
covers = 0;
&rdataset);
goto cleanup;
goto cleanup;
unsigned int ercode;
return (DNS_R_SUCCESS);
if (free_name)
if (free_rdataset)
return (result);
isc_region_t r;
return (DNS_R_UNEXPECTEDEND);
return (ret);
return (ret);
return (ret);
return (ret);
if (r.length != 0)
return (DNS_R_FORMERR);
return (ISC_R_NOMEMORY);
sizeof(isc_region_t));
return (ISC_R_NOMEMORY);
return (DNS_R_SUCCESS);
isc_region_t r;
return (result);
return (DNS_R_SUCCESS);
return (DNS_R_SUCCESS);
isc_region_t r;
return (DNS_R_NOSPACE);
return (DNS_R_SUCCESS);
static inline isc_boolean_t
int pass_needed;
return (ISC_FALSE);
case dns_rdatatype_a:
case dns_rdatatype_aaaa:
case dns_rdatatype_a6:
case dns_rdatatype_sig:
case dns_rdatatype_key:
return (ISC_FALSE);
return (ISC_TRUE);
unsigned int options)
int pass;
total = 0;
return (DNS_R_SUCCESS);
goto next;
goto next;
count = 0;
return (result);
next:
} while (--pass != 0);
return (DNS_R_SUCCESS);
isc_region_t r;
isc_region_t r;
int result;
unsigned int count;
return (DNS_R_FORMERR);
count = 0;
return (result);
return (result);
return (result);
return (result);
return (result);
return (DNS_R_SUCCESS);
for (i = 0; i < DNS_SECTION_MAX; i++) {
return (DNS_R_NOMORE);
return (DNS_R_SUCCESS);
return (DNS_R_NOMORE);
return (DNS_R_SUCCESS);
unsigned int attributes;
attributes = 0;
return (DNS_R_NXDOMAIN);
return (result);
return (DNS_R_SUCCESS);
return (DNS_R_NXRDATASET);
return (result);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
unsigned int *flagsp)
isc_region_t r;
unsigned int flags;
return (DNS_R_UNEXPECTEDEND);
return (DNS_R_SUCCESS);
unsigned int first_section;
return (DNS_R_FORMERR);
if (want_question_section) {
return (DNS_R_FORMERR);
return (DNS_R_SUCCESS);
return (result);
return (result);
return (DNS_R_SUCCESS);
isc_region_t r;
return (ISC_R_NOTFOUND);
return (result);
return (ISC_R_NOTFOUND);
&dataset);
return (result);
return (result);
return (result);
isc_buffer_t b;
return (ISC_R_SUCCESS);
return (DNS_R_EXPECTEDTSIG);