/build/ldns-NeVfgT/ldns-1.9.2/wire2host.c
Go to the documentation of this file.
/*
* wire2host.c
*
* conversion routines from the wire to the host
* format.
* This will usually just a re-ordering of the
* data (as we store it in network format)
*
* a Net::DNS like library for C
*
* (c) NLnet Labs, 2004-2006
*
* See the file LICENSE for the license
*/
#include <ldns/config.h>
#include <ldns/ldns.h>
/*#include <ldns/wire2host.h>*/
#include <strings.h>
#include <limits.h>
/*
* Set of macro's to deal with the dns message header as specified
* in RFC1035 in portable way.
*
*/
/*
*
* 1 1 1 1 1 1
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ID |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* |QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | QDCOUNT |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ANCOUNT |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | NSCOUNT |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ARCOUNT |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
/* allocates memory to *dname! */
ldns_status
ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
{
uint8_t label_size;
uint16_t pointer_target;
uint8_t pointer_target_buf[2];
size_t dname_pos = 0;
size_t compression_pos = 0;
uint8_t tmp_dname[LDNS_MAX_DOMAINLEN];
unsigned int pointer_count = 0;
if (pos == NULL) {
return LDNS_STATUS_WIRE_RDATA_ERR;
}
if (*pos >= max) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
label_size = wire[*pos];
while (label_size > 0) {
/* compression */
while (label_size >= 192) {
if (compression_pos == 0) {
compression_pos = *pos + 2;
}
pointer_count++;
/* remove first two bits */
if (*pos + 2 > max) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
pointer_target_buf[0] = wire[*pos] & 63;
pointer_target_buf[1] = wire[*pos + 1];
pointer_target = ldns_read_uint16(pointer_target_buf);
if (pointer_target == 0) {
return LDNS_STATUS_INVALID_POINTER;
} else if (pointer_target >= max) {
return LDNS_STATUS_INVALID_POINTER;
} else if (pointer_count > LDNS_MAX_POINTERS) {
return LDNS_STATUS_INVALID_POINTER;
}
*pos = pointer_target;
label_size = wire[*pos];
}
if(label_size == 0)
break; /* break from pointer to 0 byte */
if (label_size > LDNS_MAX_LABELLEN) {
return LDNS_STATUS_LABEL_OVERFLOW;
}
if (*pos + 1 + label_size > max) {
return LDNS_STATUS_LABEL_OVERFLOW;
}
/* check space for labelcount itself */
if (dname_pos + 1 > LDNS_MAX_DOMAINLEN) {
return LDNS_STATUS_DOMAINNAME_OVERFLOW;
}
tmp_dname[dname_pos] = label_size;
if (label_size > 0) {
dname_pos++;
}
*pos = *pos + 1;
if (dname_pos + label_size > LDNS_MAX_DOMAINLEN) {
return LDNS_STATUS_DOMAINNAME_OVERFLOW;
}
memcpy(&tmp_dname[dname_pos], &wire[*pos], label_size);
dname_pos += label_size;
*pos = *pos + label_size;
if (*pos < max) {
label_size = wire[*pos];
}
}
if (compression_pos > 0) {
*pos = compression_pos;
} else {
*pos = *pos + 1;
}
if (dname_pos >= LDNS_MAX_DOMAINLEN) {
return LDNS_STATUS_DOMAINNAME_OVERFLOW;
}
tmp_dname[dname_pos] = 0;
dname_pos++;
*dname = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_DNAME,
(uint16_t) dname_pos, tmp_dname);
if (!*dname) {
return LDNS_STATUS_MEM_ERR;
}
return LDNS_STATUS_OK;
}
/* maybe make this a goto error so data can be freed or something/ */
#define LDNS_STATUS_CHECK_RETURN(st) {if (st != LDNS_STATUS_OK) { return st; }}
#define LDNS_STATUS_CHECK_GOTO(st, label) {if (st != LDNS_STATUS_OK) { /*printf("STG %s:%d: status code %d\n", __FILE__, __LINE__, st);*/ goto label; }}
ldns_status
ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos)
{
size_t end;
size_t cur_rdf_length;
uint8_t rdf_index;
uint8_t *data;
uint16_t rd_length;
ldns_rdf *cur_rdf = NULL;
ldns_rdf_type cur_rdf_type;
const ldns_rr_descriptor *descriptor;
ldns_status status;
assert(rr != NULL);
descriptor = ldns_rr_descript(ldns_rr_get_type(rr));
if (*pos + 2 > max) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
rd_length = ldns_read_uint16(&wire[*pos]);
*pos = *pos + 2;
if (*pos + rd_length > max) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
end = *pos + (size_t) rd_length;
rdf_index = 0;
while (*pos < end &&
rdf_index < ldns_rr_descriptor_maximum(descriptor)) {
cur_rdf_length = 0;
cur_rdf_type = ldns_rr_descriptor_field_type(
descriptor, rdf_index);
/* handle special cases immediately, set length
for fixed length rdata and do them below */
switch (cur_rdf_type) {
case LDNS_RDF_TYPE_DNAME:
status = ldns_wire2dname(&cur_rdf, wire, max, pos);
LDNS_STATUS_CHECK_RETURN(status);
break;
case LDNS_RDF_TYPE_CLASS:
case LDNS_RDF_TYPE_ALG:
case LDNS_RDF_TYPE_CERTIFICATE_USAGE:
case LDNS_RDF_TYPE_SELECTOR:
case LDNS_RDF_TYPE_MATCHING_TYPE:
case LDNS_RDF_TYPE_INT8:
cur_rdf_length = LDNS_RDF_SIZE_BYTE;
break;
case LDNS_RDF_TYPE_TYPE:
case LDNS_RDF_TYPE_INT16:
case LDNS_RDF_TYPE_CERT_ALG:
cur_rdf_length = LDNS_RDF_SIZE_WORD;
break;
case LDNS_RDF_TYPE_TIME:
case LDNS_RDF_TYPE_INT32:
case LDNS_RDF_TYPE_A:
case LDNS_RDF_TYPE_PERIOD:
cur_rdf_length = LDNS_RDF_SIZE_DOUBLEWORD;
break;
case LDNS_RDF_TYPE_TSIGTIME:
case LDNS_RDF_TYPE_EUI48:
cur_rdf_length = LDNS_RDF_SIZE_6BYTES;
break;
case LDNS_RDF_TYPE_ILNP64:
case LDNS_RDF_TYPE_EUI64:
case LDNS_RDF_TYPE_IPN:
case LDNS_RDF_TYPE_INT64:
cur_rdf_length = LDNS_RDF_SIZE_8BYTES;
break;
case LDNS_RDF_TYPE_AAAA:
cur_rdf_length = LDNS_RDF_SIZE_16BYTES;
break;
case LDNS_RDF_TYPE_STR:
case LDNS_RDF_TYPE_NSEC3_SALT:
case LDNS_RDF_TYPE_UNQUOTED:
case LDNS_RDF_TYPE_TAG:
/* len is stored in first byte
* it should be in the rdf too, so just
* copy len+1 from this position
*/
cur_rdf_length = ((size_t) wire[*pos]) + 1;
break;
case LDNS_RDF_TYPE_INT16_DATA:
if (*pos + 2 > end) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
cur_rdf_length =
(size_t) ldns_read_uint16(&wire[*pos]) + 2;
break;
case LDNS_RDF_TYPE_HIP:
if (*pos + 4 > end) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
cur_rdf_length =
(size_t) wire[*pos] +
(size_t) ldns_read_uint16(&wire[*pos + 2]) + 4;
break;
case LDNS_RDF_TYPE_B32_EXT:
case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER:
/* length is stored in first byte */
cur_rdf_length = ((size_t) wire[*pos]) + 1;
break;
case LDNS_RDF_TYPE_APL:
case LDNS_RDF_TYPE_B64:
case LDNS_RDF_TYPE_HEX:
case LDNS_RDF_TYPE_NSEC:
case LDNS_RDF_TYPE_UNKNOWN:
case LDNS_RDF_TYPE_SERVICE:
case LDNS_RDF_TYPE_LOC:
case LDNS_RDF_TYPE_WKS:
case LDNS_RDF_TYPE_NSAP:
case LDNS_RDF_TYPE_ATMA:
case LDNS_RDF_TYPE_IPSECKEY:
case LDNS_RDF_TYPE_LONG_STR:
case LDNS_RDF_TYPE_AMTRELAY:
case LDNS_RDF_TYPE_SVCPARAMS:
case LDNS_RDF_TYPE_NONE:
/*
* Read to end of rr rdata
*/
cur_rdf_length = end - *pos;
break;
}
/* fixed length rdata */
if (cur_rdf_length > 0) {
if (cur_rdf_length + *pos > end) {
return LDNS_STATUS_PACKET_OVERFLOW;
}
data = LDNS_XMALLOC(uint8_t, rd_length);
if (!data) {
return LDNS_STATUS_MEM_ERR;
}
memcpy(data, &wire[*pos], cur_rdf_length);
cur_rdf = ldns_rdf_new(cur_rdf_type,
cur_rdf_length, data);
*pos = *pos + cur_rdf_length;
}
if (cur_rdf) {
ldns_rr_push_rdf(rr, cur_rdf);
cur_rdf = NULL;
}
rdf_index++;
} /* while (rdf_index < ldns_rr_descriptor_maximum(descriptor)) */
return LDNS_STATUS_OK;
}
/* TODO:
can *pos be incremented at READ_INT? or maybe use something like
RR_CLASS(wire)?
uhhm Jelte??
*/
ldns_status
ldns_wire2rr(ldns_rr **rr_p, const uint8_t *wire, size_t max,
size_t *pos, ldns_pkt_section section)
{
ldns_rdf *owner = NULL;
ldns_rr *rr = ldns_rr_new();
ldns_status status;
status = ldns_wire2dname(&owner, wire, max, pos);
LDNS_STATUS_CHECK_GOTO(status, status_error);
ldns_rr_set_owner(rr, owner);
if (*pos + 4 > max) {
status = LDNS_STATUS_PACKET_OVERFLOW;
goto status_error;
}
ldns_rr_set_type(rr, ldns_read_uint16(&wire[*pos]));
*pos = *pos + 2;
ldns_rr_set_class(rr, ldns_read_uint16(&wire[*pos]));
*pos = *pos + 2;
if (section != LDNS_SECTION_QUESTION) {
if (*pos + 4 > max) {
status = LDNS_STATUS_PACKET_OVERFLOW;
goto status_error;
}
ldns_rr_set_ttl(rr, ldns_read_uint32(&wire[*pos]));
*pos = *pos + 4;
status = ldns_wire2rdf(rr, wire, max, pos);
LDNS_STATUS_CHECK_GOTO(status, status_error);
ldns_rr_set_question(rr, false);
} else {
ldns_rr_set_question(rr, true);
}
*rr_p = rr;
return LDNS_STATUS_OK;
status_error:
ldns_rr_free(rr);
return status;
}
static ldns_status
ldns_wire2pkt_hdr(ldns_pkt *packet, const uint8_t *wire, size_t max, size_t *pos)
{
if (*pos + LDNS_HEADER_SIZE > max) {
return LDNS_STATUS_WIRE_INCOMPLETE_HEADER;
} else {
ldns_pkt_set_id(packet, LDNS_ID_WIRE(wire));
ldns_pkt_set_qr(packet, LDNS_QR_WIRE(wire));
ldns_pkt_set_opcode(packet, LDNS_OPCODE_WIRE(wire));
ldns_pkt_set_aa(packet, LDNS_AA_WIRE(wire));
ldns_pkt_set_tc(packet, LDNS_TC_WIRE(wire));
ldns_pkt_set_rd(packet, LDNS_RD_WIRE(wire));
ldns_pkt_set_ra(packet, LDNS_RA_WIRE(wire));
ldns_pkt_set_ad(packet, LDNS_AD_WIRE(wire));
ldns_pkt_set_cd(packet, LDNS_CD_WIRE(wire));
ldns_pkt_set_rcode(packet, LDNS_RCODE_WIRE(wire));
ldns_pkt_set_qdcount(packet, LDNS_QDCOUNT(wire));
ldns_pkt_set_ancount(packet, LDNS_ANCOUNT(wire));
ldns_pkt_set_nscount(packet, LDNS_NSCOUNT(wire));
ldns_pkt_set_arcount(packet, LDNS_ARCOUNT(wire));
*pos += LDNS_HEADER_SIZE;
return LDNS_STATUS_OK;
}
}
ldns_status
ldns_buffer2pkt_wire(ldns_pkt **packet, const ldns_buffer *buffer)
{
/* lazy */
return ldns_wire2pkt(packet, ldns_buffer_begin(buffer),
ldns_buffer_limit(buffer));
}
ldns_status
ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
{
size_t pos = 0;
uint16_t i;
ldns_rr *rr;
ldns_pkt *packet = ldns_pkt_new();
ldns_status status = LDNS_STATUS_OK;
uint8_t have_edns = 0;
uint8_t data[4];
if (!packet) {
return LDNS_STATUS_MEM_ERR;
}
status = ldns_wire2pkt_hdr(packet, wire, max, &pos);
LDNS_STATUS_CHECK_GOTO(status, status_error);
for (i = 0; i < ldns_pkt_qdcount(packet); i++) {
status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_QUESTION);
if (status == LDNS_STATUS_PACKET_OVERFLOW) {
status = LDNS_STATUS_WIRE_INCOMPLETE_QUESTION;
}
LDNS_STATUS_CHECK_GOTO(status, status_error);
if (!ldns_rr_list_push_rr(ldns_pkt_question(packet), rr)) {
ldns_pkt_free(packet);
return LDNS_STATUS_INTERNAL_ERR;
}
}
for (i = 0; i < ldns_pkt_ancount(packet); i++) {
status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_ANSWER);
if (status == LDNS_STATUS_PACKET_OVERFLOW) {
status = LDNS_STATUS_WIRE_INCOMPLETE_ANSWER;
}
LDNS_STATUS_CHECK_GOTO(status, status_error);
if (!ldns_rr_list_push_rr(ldns_pkt_answer(packet), rr)) {
ldns_pkt_free(packet);
return LDNS_STATUS_INTERNAL_ERR;
}
}
for (i = 0; i < ldns_pkt_nscount(packet); i++) {
status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_AUTHORITY);
if (status == LDNS_STATUS_PACKET_OVERFLOW) {
status = LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY;
}
LDNS_STATUS_CHECK_GOTO(status, status_error);
if (!ldns_rr_list_push_rr(ldns_pkt_authority(packet), rr)) {
ldns_pkt_free(packet);
return LDNS_STATUS_INTERNAL_ERR;
}
}
for (i = 0; i < ldns_pkt_arcount(packet); i++) {
status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_ADDITIONAL);
if (status == LDNS_STATUS_PACKET_OVERFLOW) {
status = LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL;
}
LDNS_STATUS_CHECK_GOTO(status, status_error);
if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_OPT) {
ldns_pkt_set_edns_udp_size(packet, ldns_rr_get_class(rr));
ldns_write_uint32(data, ldns_rr_ttl(rr));
ldns_pkt_set_edns_extended_rcode(packet, data[0]);
ldns_pkt_set_edns_version(packet, data[1]);
ldns_pkt_set_edns_z(packet, ldns_read_uint16(&data[2]));
/* edns might not have rdfs */
if (ldns_rr_rdf(rr, 0)) {
ldns_rdf_deep_free(ldns_pkt_edns_data(packet));
ldns_pkt_set_edns_data(packet, ldns_rdf_clone(ldns_rr_rdf(rr, 0)));
}
ldns_rr_free(rr);
have_edns += 1;
} else if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_TSIG) {
ldns_pkt_set_tsig(packet, rr);
ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet) - 1);
} else if (!ldns_rr_list_push_rr(ldns_pkt_additional(packet), rr)) {
ldns_pkt_free(packet);
return LDNS_STATUS_INTERNAL_ERR;
}
}
ldns_pkt_set_size(packet, max);
if(have_edns)
ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet)
- have_edns);
packet->_edns_present = have_edns;
*packet_p = packet;
return status;
status_error:
ldns_pkt_free(packet);
return status;
}
ldns_buffer
struct ldns_struct_buffer ldns_buffer
Definition buffer.h:72
config.h
LDNS_STATUS_WIRE_INCOMPLETE_QUESTION
@ LDNS_STATUS_WIRE_INCOMPLETE_QUESTION
Definition error.h:73
LDNS_STATUS_WIRE_RDATA_ERR
@ LDNS_STATUS_WIRE_RDATA_ERR
Definition error.h:125
LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL
@ LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL
Definition error.h:76
LDNS_STATUS_WIRE_INCOMPLETE_HEADER
@ LDNS_STATUS_WIRE_INCOMPLETE_HEADER
Definition error.h:72
LDNS_STATUS_LABEL_OVERFLOW
@ LDNS_STATUS_LABEL_OVERFLOW
Definition error.h:28
LDNS_STATUS_MEM_ERR
@ LDNS_STATUS_MEM_ERR
Definition error.h:34
LDNS_STATUS_INTERNAL_ERR
@ LDNS_STATUS_INTERNAL_ERR
Definition error.h:35
LDNS_STATUS_WIRE_INCOMPLETE_ANSWER
@ LDNS_STATUS_WIRE_INCOMPLETE_ANSWER
Definition error.h:74
LDNS_STATUS_INVALID_POINTER
@ LDNS_STATUS_INVALID_POINTER
Definition error.h:33
LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY
@ LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY
Definition error.h:75
LDNS_STATUS_OK
@ LDNS_STATUS_OK
Definition error.h:26
LDNS_STATUS_PACKET_OVERFLOW
@ LDNS_STATUS_PACKET_OVERFLOW
Definition error.h:32
LDNS_STATUS_DOMAINNAME_OVERFLOW
@ LDNS_STATUS_DOMAINNAME_OVERFLOW
Definition error.h:29
ldns_status
enum ldns_enum_status ldns_status
Definition error.h:152
ldns_pkt_free
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
Definition packet.c:917
ldns_pkt_set_ad
void ldns_pkt_set_ad(ldns_pkt *p, signed char b)
Set the packet's ad bit.
Definition packet.c:564
ldns_pkt_set_size
void ldns_pkt_set_size(ldns_pkt *p, size_t s)
Set the packet's size.
Definition packet.c:625
ldns_pkt_set_cd
void ldns_pkt_set_cd(ldns_pkt *p, signed char b)
Set the packet's cd bit.
Definition packet.c:552
ldns_pkt_set_edns_udp_size
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
Definition packet.c:631
ldns_pkt_additional
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *p)
Return the packet's additional section.
Definition packet.c:145
ldns_pkt_authority
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *p)
Return the packet's authority section.
Definition packet.c:139
ldns_pkt_question
ldns_rr_list * ldns_pkt_question(const ldns_pkt *p)
Return the packet's question section.
Definition packet.c:127
ldns_pkt_set_qr
void ldns_pkt_set_qr(ldns_pkt *p, signed char b)
Set the packet's qr bit.
Definition packet.c:504
ldns_pkt_ancount
uint16_t ldns_pkt_ancount(const ldns_pkt *p)
Return the packet's an count.
Definition packet.c:109
ldns_pkt_nscount
uint16_t ldns_pkt_nscount(const ldns_pkt *p)
Return the packet's ns count.
Definition packet.c:115
ldns_pkt_set_aa
void ldns_pkt_set_aa(ldns_pkt *p, signed char b)
Set the packet's aa bit.
Definition packet.c:510
ldns_pkt_answer
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *p)
Return the packet's answer section.
Definition packet.c:133
ldns_pkt
struct ldns_struct_pkt ldns_pkt
Definition packet.h:272
ldns_pkt_set_rd
void ldns_pkt_set_rd(ldns_pkt *p, signed char b)
Set the packet's rd bit.
Definition packet.c:522
ldns_pkt_new
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
Definition packet.c:863
ldns_pkt_set_tc
void ldns_pkt_set_tc(ldns_pkt *p, signed char b)
Set the packet's tc bit.
Definition packet.c:516
ldns_pkt_set_rcode
void ldns_pkt_set_rcode(ldns_pkt *p, uint8_t c)
Set the packet's response code.
Definition packet.c:576
ldns_pkt_set_edns_z
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet's edns z value.
Definition packet.c:649
ldns_pkt_section
enum ldns_enum_pkt_section ldns_pkt_section
Definition packet.h:287
ldns_pkt_edns_data
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's EDNS data
Definition packet.c:279
ldns_pkt_set_qdcount
void ldns_pkt_set_qdcount(ldns_pkt *p, uint16_t c)
Set the packet's qd count.
Definition packet.c:582
ldns_pkt_qdcount
uint16_t ldns_pkt_qdcount(const ldns_pkt *p)
Return the packet's qd count.
Definition packet.c:103
ldns_pkt_set_edns_data
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet's EDNS data.
Definition packet.c:655
ldns_pkt_set_arcount
void ldns_pkt_set_arcount(ldns_pkt *p, uint16_t c)
Set the packet's arcount.
Definition packet.c:600
ldns_pkt_set_opcode
void ldns_pkt_set_opcode(ldns_pkt *p, ldns_pkt_opcode c)
Set the packet's opcode.
Definition packet.c:570
ldns_pkt_arcount
uint16_t ldns_pkt_arcount(const ldns_pkt *p)
Return the packet's ar count.
Definition packet.c:121
ldns_pkt_set_id
void ldns_pkt_set_id(ldns_pkt *p, uint16_t id)
Set the packet's id.
Definition packet.c:490
ldns_pkt_set_ancount
void ldns_pkt_set_ancount(ldns_pkt *p, uint16_t c)
Set the packet's an count.
Definition packet.c:588
ldns_pkt_set_ra
void ldns_pkt_set_ra(ldns_pkt *p, signed char b)
Set the packet's ra bit.
Definition packet.c:558
ldns_pkt_set_tsig
void ldns_pkt_set_tsig(ldns_pkt *p, ldns_rr *t)
Set the packet's tsig rr.
Definition packet.c:691
ldns_pkt_set_edns_extended_rcode
void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
Set the packet's edns extended rcode.
Definition packet.c:637
LDNS_SECTION_QUESTION
@ LDNS_SECTION_QUESTION
Definition packet.h:278
LDNS_SECTION_ANSWER
@ LDNS_SECTION_ANSWER
Definition packet.h:279
LDNS_SECTION_ADDITIONAL
@ LDNS_SECTION_ADDITIONAL
Definition packet.h:281
LDNS_SECTION_AUTHORITY
@ LDNS_SECTION_AUTHORITY
Definition packet.h:280
ldns_pkt_set_nscount
void ldns_pkt_set_nscount(ldns_pkt *p, uint16_t c)
Set the packet's ns count.
Definition packet.c:594
ldns_pkt_set_edns_version
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet's edns version.
Definition packet.c:643
ldns_rdf_clone
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
Definition rdata.c:222
ldns_rdf_new_frm_data
ldns_rdf * ldns_rdf_new_frm_data(ldns_rdf_type type, size_t size, const void *data)
allocates a new rdf structure and fills it.
Definition rdata.c:193
LDNS_RDF_SIZE_WORD
#define LDNS_RDF_SIZE_WORD
Definition rdata.h:34
ldns_rdf_deep_free
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition rdata.c:230
LDNS_RDF_SIZE_BYTE
#define LDNS_RDF_SIZE_BYTE
Definition rdata.h:33
LDNS_RDF_SIZE_6BYTES
#define LDNS_RDF_SIZE_6BYTES
Definition rdata.h:36
LDNS_RDF_SIZE_16BYTES
#define LDNS_RDF_SIZE_16BYTES
Definition rdata.h:38
LDNS_RDF_SIZE_8BYTES
#define LDNS_RDF_SIZE_8BYTES
Definition rdata.h:37
LDNS_RDF_TYPE_INT32
@ LDNS_RDF_TYPE_INT32
32 bits
Definition rdata.h:56
LDNS_RDF_TYPE_TAG
@ LDNS_RDF_TYPE_TAG
A non-zero sequence of US-ASCII letters and numbers in lower case.
Definition rdata.h:132
LDNS_RDF_TYPE_NSAP
@ LDNS_RDF_TYPE_NSAP
NSAP.
Definition rdata.h:106
LDNS_RDF_TYPE_HIP
@ LDNS_RDF_TYPE_HIP
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
Definition rdata.h:95
LDNS_RDF_TYPE_IPN
@ LDNS_RDF_TYPE_IPN
draft-johnson-dns-ipn-cla-07
Definition rdata.h:155
LDNS_RDF_TYPE_B32_EXT
@ LDNS_RDF_TYPE_B32_EXT
b32 string
Definition rdata.h:68
LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
@ LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
nsec3 base32 string (with length byte on wire
Definition rdata.h:114
LDNS_RDF_TYPE_CERT_ALG
@ LDNS_RDF_TYPE_CERT_ALG
certificate algorithm
Definition rdata.h:81
LDNS_RDF_TYPE_EUI48
@ LDNS_RDF_TYPE_EUI48
6 * 8 bit hex numbers separated by dashes.
Definition rdata.h:122
LDNS_RDF_TYPE_SERVICE
@ LDNS_RDF_TYPE_SERVICE
protocol and port bitmaps
Definition rdata.h:100
LDNS_RDF_TYPE_EUI64
@ LDNS_RDF_TYPE_EUI64
8 * 8 bit hex numbers separated by dashes.
Definition rdata.h:124
LDNS_RDF_TYPE_PERIOD
@ LDNS_RDF_TYPE_PERIOD
period
Definition rdata.h:89
LDNS_RDF_TYPE_B64
@ LDNS_RDF_TYPE_B64
b64 string
Definition rdata.h:70
LDNS_RDF_TYPE_AAAA
@ LDNS_RDF_TYPE_AAAA
AAAA record.
Definition rdata.h:62
LDNS_RDF_TYPE_UNKNOWN
@ LDNS_RDF_TYPE_UNKNOWN
unknown types
Definition rdata.h:85
LDNS_RDF_TYPE_WKS
@ LDNS_RDF_TYPE_WKS
well known services
Definition rdata.h:104
LDNS_RDF_TYPE_DNAME
@ LDNS_RDF_TYPE_DNAME
domain name
Definition rdata.h:50
LDNS_RDF_TYPE_TIME
@ LDNS_RDF_TYPE_TIME
time (32 bits)
Definition rdata.h:87
LDNS_RDF_TYPE_SVCPARAMS
@ LDNS_RDF_TYPE_SVCPARAMS
draft-ietf-dnsop-svcb-https
Definition rdata.h:152
LDNS_RDF_TYPE_NSEC
@ LDNS_RDF_TYPE_NSEC
nsec type codes
Definition rdata.h:74
LDNS_RDF_TYPE_SELECTOR
@ LDNS_RDF_TYPE_SELECTOR
Definition rdata.h:145
LDNS_RDF_TYPE_NSEC3_SALT
@ LDNS_RDF_TYPE_NSEC3_SALT
nsec3 hash salt
Definition rdata.h:112
LDNS_RDF_TYPE_APL
@ LDNS_RDF_TYPE_APL
apl data
Definition rdata.h:66
LDNS_RDF_TYPE_A
@ LDNS_RDF_TYPE_A
A record.
Definition rdata.h:60
LDNS_RDF_TYPE_LONG_STR
@ LDNS_RDF_TYPE_LONG_STR
A <character-string> encoding of the value field as specified [RFC1035], Section 5....
Definition rdata.h:138
LDNS_RDF_TYPE_LOC
@ LDNS_RDF_TYPE_LOC
location data
Definition rdata.h:102
LDNS_RDF_TYPE_INT64
@ LDNS_RDF_TYPE_INT64
64 bits
Definition rdata.h:58
LDNS_RDF_TYPE_INT16_DATA
@ LDNS_RDF_TYPE_INT16_DATA
variable length any type rdata where the length is specified by the first 2 bytes
Definition rdata.h:98
LDNS_RDF_TYPE_ILNP64
@ LDNS_RDF_TYPE_ILNP64
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Definition rdata.h:119
LDNS_RDF_TYPE_ATMA
@ LDNS_RDF_TYPE_ATMA
ATMA.
Definition rdata.h:108
LDNS_RDF_TYPE_HEX
@ LDNS_RDF_TYPE_HEX
hex string
Definition rdata.h:72
LDNS_RDF_TYPE_NONE
@ LDNS_RDF_TYPE_NONE
none
Definition rdata.h:48
LDNS_RDF_TYPE_CLASS
@ LDNS_RDF_TYPE_CLASS
a class
Definition rdata.h:79
LDNS_RDF_TYPE_INT8
@ LDNS_RDF_TYPE_INT8
8 bits
Definition rdata.h:52
LDNS_RDF_TYPE_MATCHING_TYPE
@ LDNS_RDF_TYPE_MATCHING_TYPE
Definition rdata.h:146
LDNS_RDF_TYPE_IPSECKEY
@ LDNS_RDF_TYPE_IPSECKEY
IPSECKEY.
Definition rdata.h:110
LDNS_RDF_TYPE_CERTIFICATE_USAGE
@ LDNS_RDF_TYPE_CERTIFICATE_USAGE
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
Definition rdata.h:144
LDNS_RDF_TYPE_STR
@ LDNS_RDF_TYPE_STR
txt string
Definition rdata.h:64
LDNS_RDF_TYPE_INT16
@ LDNS_RDF_TYPE_INT16
16 bits
Definition rdata.h:54
LDNS_RDF_TYPE_ALG
@ LDNS_RDF_TYPE_ALG
a key algorithm
Definition rdata.h:83
LDNS_RDF_TYPE_AMTRELAY
@ LDNS_RDF_TYPE_AMTRELAY
draft-ietf-mboned-driad-amt-discovery
Definition rdata.h:149
LDNS_RDF_TYPE_UNQUOTED
@ LDNS_RDF_TYPE_UNQUOTED
Character string without quotes.
Definition rdata.h:127
LDNS_RDF_TYPE_TSIGTIME
@ LDNS_RDF_TYPE_TSIGTIME
tsig time 48 bits
Definition rdata.h:91
LDNS_RDF_TYPE_TYPE
@ LDNS_RDF_TYPE_TYPE
a RR type
Definition rdata.h:77
LDNS_RDF_SIZE_DOUBLEWORD
#define LDNS_RDF_SIZE_DOUBLEWORD
Definition rdata.h:35
ldns_rdf
struct ldns_struct_rdf ldns_rdf
Definition rdata.h:211
ldns_rdf_new
ldns_rdf * ldns_rdf_new(ldns_rdf_type type, size_t size, void *data)
allocates a new rdf structure and fills it.
Definition rdata.c:179
ldns_rdf_type
enum ldns_enum_rdf_type ldns_rdf_type
Definition rdata.h:157
ldns_rr_ttl
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
Definition rr.c:929
ldns_rr_free
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
Definition rr.c:81
ldns_rr_set_owner
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
Definition rr.c:802
ldns_rr
struct ldns_struct_rr ldns_rr
Definition rr.h:346
LDNS_MAX_LABELLEN
#define LDNS_MAX_LABELLEN
Maximum length of a dname label.
Definition rr.h:31
ldns_rr_new
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
Definition rr.c:30
ldns_rr_set_type
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
Definition rr.c:826
LDNS_RR_TYPE_OPT
@ LDNS_RR_TYPE_OPT
OPT record RFC 6891.
Definition rr.h:160
LDNS_RR_TYPE_TSIG
@ LDNS_RR_TYPE_TSIG
Definition rr.h:219
ldns_rr_list_push_rr
signed char ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
Definition rr.c:1130
ldns_rr_descriptor_field_type
ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field)
returns the rdf type for the given rdata field number of the rr type for the given descriptor.
Definition rr.c:2781
ldns_rr_rdf
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition rr.c:907
ldns_rr_get_type
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition rr.c:941
ldns_rr_set_ttl
void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
sets the ttl in the rr structure.
Definition rr.c:814
ldns_rr_set_question
void ldns_rr_set_question(ldns_rr *rr, signed char question)
sets the question flag in the rr structure.
Definition rr.c:808
ldns_rr_descriptor_maximum
size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor)
returns the maximum number of rdata fields of the rr type this descriptor describes.
Definition rr.c:2766
ldns_rr_get_class
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
Definition rr.c:947
LDNS_MAX_POINTERS
#define LDNS_MAX_POINTERS
Maximum number of pointers in 1 dname.
Definition rr.h:35
ldns_rr_set_class
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
Definition rr.c:832
ldns_rr_push_rdf
signed char ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
Definition rr.c:855
LDNS_MAX_DOMAINLEN
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
Definition rr.h:33
ldns_rr_descript
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
Definition rr.c:2737
ldns_rr_descriptor
struct ldns_struct_rr_descriptor ldns_rr_descriptor
Definition rr.h:386
ldns_struct_pkt::_edns_present
uint8_t _edns_present
Definition packet.h:256
LDNS_XMALLOC
#define LDNS_XMALLOC(type, count)
Definition util.h:51
ldns_wire2dname
ldns_status ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.
Definition wire2host.c:56
LDNS_STATUS_CHECK_RETURN
#define LDNS_STATUS_CHECK_RETURN(st)
Definition wire2host.c:152
ldns_wire2rr
ldns_status ldns_wire2rr(ldns_rr **rr_p, const uint8_t *wire, size_t max, size_t *pos, ldns_pkt_section section)
converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.
Definition wire2host.c:321
ldns_wire2rdf
ldns_status ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos)
converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the...
Definition wire2host.c:156
LDNS_STATUS_CHECK_GOTO
#define LDNS_STATUS_CHECK_GOTO(st, label)
Definition wire2host.c:153
ldns_buffer2pkt_wire
ldns_status ldns_buffer2pkt_wire(ldns_pkt **packet, const ldns_buffer *buffer)
converts the data in the ldns_buffer (in wire format) to a DNS packet.
Definition wire2host.c:397
ldns_wire2pkt
ldns_status ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
converts the data on the uint8_t bytearray (in wire format) to a DNS packet.
Definition wire2host.c:406
LDNS_OPCODE_WIRE
#define LDNS_OPCODE_WIRE(wirebuf)
Definition wire2host.h:55
LDNS_ID_WIRE
#define LDNS_ID_WIRE(wirebuf)
Definition wire2host.h:97
LDNS_CD_WIRE
#define LDNS_CD_WIRE(wirebuf)
Definition wire2host.h:74
LDNS_AD_WIRE
#define LDNS_AD_WIRE(wirebuf)
Definition wire2host.h:80
LDNS_AA_WIRE
#define LDNS_AA_WIRE(wirebuf)
Definition wire2host.h:49
LDNS_RCODE_WIRE
#define LDNS_RCODE_WIRE(wirebuf)
Definition wire2host.h:68
LDNS_QDCOUNT
#define LDNS_QDCOUNT(wirebuf)
Definition wire2host.h:102
LDNS_HEADER_SIZE
#define LDNS_HEADER_SIZE
Definition wire2host.h:32
LDNS_RD_WIRE
#define LDNS_RD_WIRE(wirebuf)
Definition wire2host.h:37
LDNS_RA_WIRE
#define LDNS_RA_WIRE(wirebuf)
Definition wire2host.h:92
LDNS_NSCOUNT
#define LDNS_NSCOUNT(wirebuf)
Definition wire2host.h:110
LDNS_ANCOUNT
#define LDNS_ANCOUNT(wirebuf)
Definition wire2host.h:106
LDNS_ARCOUNT
#define LDNS_ARCOUNT(wirebuf)
Definition wire2host.h:114
LDNS_QR_WIRE
#define LDNS_QR_WIRE(wirebuf)
Definition wire2host.h:61
LDNS_TC_WIRE
#define LDNS_TC_WIRE(wirebuf)
Definition wire2host.h:43