message.c revision 3f42cf2f3e4dc7e740b4609ba7d7430292348f2b
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC")
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * purpose with or without fee is hereby granted, provided that the above
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * copyright notice and this permission notice appear in all copies.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * PERFORMANCE OF THIS SOFTWARE.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews/* $Id: message.c,v 1.241 2008/04/02 02:37:42 marka Exp $ */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <isc/string.h> /* Required for HP/UX (and others?) */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewshexdump(const char *msg, const char *msg2, void *base, size_t len) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews unsigned char *p;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews unsigned int cnt;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews printf("*** %s [%s] (%u bytes @ %p)\n", msg, msg2, len, base);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews printf(" %02x %c", *p, (isprint(*p) ? *p : ' '));
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define DNS_MESSAGE_EDNSVERSION_MASK 0x00ff0000U
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define VALID_NAMED_SECTION(s) (((s) > DNS_SECTION_ANY) \
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define VALID_SECTION(s) (((s) >= DNS_SECTION_ANY) \
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews return(ISC_R_NOSPACE); else \
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define VALID_PSEUDOSECTION(s) (((s) >= DNS_PSEUDOSECTION_ANY) \
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * This is the size of each individual scratchpad buffer, and the numbers
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * of various block allocations used within the server.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * XXXMLG These should come from a config setting.
static const char *sectiontext[] = {
static const char *updsectiontext[] = {
static const char *opcodetext[] = {
static const char *rcodetext[] = {
struct dns_msgblock {
unsigned int count;
unsigned int remaining;
static inline dns_msgblock_t *
static inline dns_msgblock_t *
unsigned int count)
unsigned int length;
return (NULL);
return (block);
void *ptr;
return (NULL);
+ sizeof(dns_msgblock_t)
return (ptr);
unsigned int length;
static inline isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static inline isc_buffer_t *
return (dynbuf);
static inline dns_rdata_t *
return (rdata);
return (NULL);
return (rdata);
static inline dns_rdatalist_t *
return (rdatalist);
sizeof(dns_rdatalist_t),
return (NULL);
return (rdatalist);
static inline dns_offsets_t *
sizeof(dns_offsets_t),
return (NULL);
return (offsets);
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->sig_reserved = 0;
m->reserved = 0;
m->timeadjust = 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;
m->free_query = 0;
m->free_saved = 0;
if (replying) {
if (!everything) {
if (!everything)
dns_message_t *m;
if (m == NULL)
return (ISC_R_NOMEMORY);
msginit(m);
for (i = 0; i < DNS_SECTION_MAX; i++)
goto cleanup;
&m->rdspool);
goto cleanup;
goto cleanup;
*msgp = m;
return (ISC_R_SUCCESS);
m->magic = 0;
return (ISC_R_NOMEMORY);
static isc_result_t
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
static isc_result_t
unsigned int tries;
tries = 0;
scratch);
tries++;
return (result);
return (result);
return (ISC_R_UNEXPECTED);
static isc_result_t
unsigned int tries;
unsigned int trysize;
tries = 0;
trysize = 0;
scratch);
if (tries == 0) {
return (ISC_R_NOSPACE);
tries++;
return (result);
return (result);
#define DO_FORMERR \
if (best_effort) \
goto cleanup; \
static isc_result_t
unsigned int options)
isc_region_t r;
unsigned int count;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
if (seen_problem)
return (DNS_R_RECOVERABLE);
return (ISC_R_SUCCESS);
if (free_name)
return (result);
static isc_boolean_t
return (ISC_FALSE);
static isc_result_t
isc_region_t r;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
if (rdatalen != 0) {
goto cleanup;
goto cleanup;
if (covers == 0)
if (covers == 0) {
covers = 0;
goto cleanup;
goto cleanup;
== ISC_R_SUCCESS);
if (seen_problem) {
if (free_name)
if (free_rdataset)
if (seen_problem)
return (DNS_R_RECOVERABLE);
return (ISC_R_SUCCESS);
if (free_name)
if (free_rdataset)
return (result);
unsigned int options)
isc_region_t r;
return (ISC_R_UNEXPECTEDEND);
goto truncated;
return (ret);
goto truncated;
return (ret);
goto truncated;
return (ret);
goto truncated;
return (ret);
if (r.length != 0) {
r.length);
return (ISC_R_NOMEMORY);
return (DNS_R_RECOVERABLE);
return (DNS_R_RECOVERABLE);
return (ISC_R_SUCCESS);
isc_region_t r;
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
isc_region_t r;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
static inline isc_boolean_t
int pass_needed;
return (ISC_FALSE);
case dns_rdatatype_a:
case dns_rdatatype_aaaa:
case dns_rdatatype_rrsig:
case dns_rdatatype_dnskey:
return (ISC_FALSE);
return (ISC_TRUE);
unsigned int options)
int pass;
unsigned int rd_options;
rd_options = 0;
total = 0;
count = 0;
if (partial)
name,
&count,
NULL);
name,
&count);
return (result);
return (result);
return (ISC_R_SUCCESS);
DNS_RDATASETATTR_RENDERED) != 0)
goto next;
goto next;
count = 0;
if (partial)
name,
&count,
NULL);
name,
&count);
return (result);
return (result);
next:
} while (--pass != 0);
return (ISC_R_SUCCESS);
isc_region_t r;
isc_region_t r;
int result;
unsigned int count;
return (DNS_R_FORMERR);
count = 0;
&count);
return (result);
return (result);
return (result);
count = 0;
&count);
return (result);
return (result);
count = 0;
&count);
return (result);
return (ISC_R_SUCCESS);
for (i = 0; i < DNS_SECTION_MAX; i++) {
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
return (DNS_R_NXDOMAIN);
return (result);
return (ISC_R_SUCCESS);
return (DNS_R_NXRRSET);
return (result);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
unsigned int *flagsp)
isc_region_t r;
unsigned int flags;
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_SUCCESS);
unsigned int first_section;
return (DNS_R_FORMERR);
if (want_question_section) {
return (DNS_R_FORMERR);
unsigned int otherlen = 0;
return (result);
return (ISC_R_SUCCESS);
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
return (result);
return (ISC_R_SUCCESS);
isc_region_t r;
return (ISC_R_SUCCESS);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
return (ISC_R_NOMEMORY);
isc_region_t r;
return (ISC_R_SUCCESS);
return (result);
return (result);
return (ISC_R_SUCCESS);
isc_region_t r;
return (result);
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (DNS_R_NOTVERIFIEDYET);
return (result);
return (result);
return (result);
#ifdef SKAN_MSG_DEBUG
return (ISC_R_SUCCESS);
#ifdef SKAN_MSG_DEBUG
return (ISC_R_UNEXPECTEDEND);
return (result);
return (DNS_R_KEYUNAUTHORIZED);
goto freesig;
goto freesig;
return (result);
return (ISC_R_SUCCESS);
return (result);
target);
target);
return (result);
return (result);
switch (section) {
case DNS_PSEUDOSECTION_OPT:
return (ISC_R_SUCCESS);
if (mbz != 0) {
return (ISC_R_SUCCESS);
case DNS_PSEUDOSECTION_TSIG:
return (ISC_R_SUCCESS);
return (result);
case DNS_PSEUDOSECTION_SIG0:
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_UNEXPECTED);
return (result);
return (result);
return (result);
return (result);
return (result);
return (result);
return (result);
return (ISC_R_SUCCESS);
const void *order_arg)
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);