buffer.c
Go to the documentation of this file.
/*
* Copyright (c) 2011 NLNet Labs. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "config.h"
#include "log.h"
#include "wire/buffer.h"
#include <string.h>
static const char* buffer_str = "buffer";
ods_lookup_table ods_rcode_str[] = {
{ LDNS_RCODE_NOERROR, "NOERROR" },
{ LDNS_RCODE_FORMERR, "FORMERR" },
{ LDNS_RCODE_SERVFAIL, "SERVFAIL" },
{ LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
{ LDNS_RCODE_NOTIMPL, "NOTIMPL" },
{ LDNS_RCODE_REFUSED, "REFUSED" },
{ LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
{ LDNS_RCODE_YXRRSET, "YXRRSET" },
{ LDNS_RCODE_NXRRSET, "NXRRSET" },
{ LDNS_RCODE_NOTAUTH, "NOTAUTH" },
{ LDNS_RCODE_NOTZONE, "NOTZONE" },
{ 0, NULL }
};
buffer_type*
buffer_create(size_t capacity)
{
buffer_type* buffer = NULL;
if (!capacity) {
return NULL;
}
CHECKALLOC(buffer = (buffer_type *) malloc(sizeof(buffer_type)));
buffer->data = (uint8_t*) calloc(capacity, sizeof(uint8_t));
buffer->position = 0;
buffer->limit = capacity;
buffer->capacity = capacity;
buffer->fixed = 0;
return buffer;
}
void
buffer_clear(buffer_type* buffer)
{
ods_log_assert(buffer);
buffer->position = 0;
buffer->limit = buffer->capacity;
}
void
buffer_flip(buffer_type* buffer)
{
ods_log_assert(buffer);
buffer->limit = buffer->position;
buffer->position = 0;
}
size_t
buffer_position(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer->position;
}
void
buffer_set_position(buffer_type* buffer, size_t pos)
{
ods_log_assert(buffer);
ods_log_assert(pos <= buffer->limit);
buffer->position = pos;
}
void
buffer_skip(buffer_type* buffer, ssize_t count)
{
ods_log_assert(buffer);
ods_log_assert(buffer->position + count <= buffer->limit);
buffer->position += count;
}
static int
get_bit(uint8_t bits[], size_t index)
{
return bits[index / 8] & (1 << (7 - index % 8));
}
static void
set_bit(uint8_t bits[], size_t index)
{
bits[index / 8] |= (1 << (7 - index % 8));
}
static int
label_is_pointer(const uint8_t* label)
{
ods_log_assert(label);
return (label[0] & 0xc0) == 0xc0;
}
static uint16_t
label_pointer_location(const uint8_t* label)
{
ods_log_assert(label);
ods_log_assert(label_is_pointer(label));
return ((uint16_t) (label[0] & ~0xc0) << 8) | (uint16_t) label[1];
}
static int
label_is_normal(const uint8_t* label)
{
ods_log_assert(label);
return (label[0] & 0xc0) == 0;
}
/*
* Is root label?
*
*/
static inline int
label_is_root(const uint8_t* label)
{
ods_log_assert(label);
return label[0] == 0;
}
/*
* Label length.
*
*/
static uint8_t
label_length(const uint8_t* label)
{
ods_log_assert(label);
ods_log_assert(label_is_normal(label));
return label[0];
}
size_t
buffer_read_dname(buffer_type* buffer, uint8_t* dname, unsigned allow_pointers)
{
int done = 0;
uint8_t visited[(MAX_PACKET_SIZE+7)/8];
size_t dname_length = 0;
const uint8_t *label = NULL;
ssize_t mark = -1;
ods_log_assert(buffer);
memset(visited, 0, (buffer_limit(buffer)+7)/8);
while (!done) {
if (!buffer_available(buffer, 1)) {
return 0;
}
if (get_bit(visited, buffer_position(buffer))) {
ods_log_error("[%s] dname loop!", buffer_str);
return 0;
}
set_bit(visited, buffer_position(buffer));
label = buffer_current(buffer);
if (label_is_pointer(label)) {
size_t pointer = 0;
if (!allow_pointers) {
return 0;
}
if (!buffer_available(buffer, 2)) {
return 0;
}
pointer = label_pointer_location(label);
if (pointer >= buffer_limit(buffer)) {
return 0;
}
buffer_skip(buffer, 2);
if (mark == -1) {
mark = buffer_position(buffer);
}
buffer_set_position(buffer, pointer);
} else if (label_is_normal(label)) {
size_t length = label_length(label) + 1;
done = label_is_root(label);
if (!buffer_available(buffer, length)) {
return 0;
}
if (dname_length + length >= MAXDOMAINLEN+1) {
return 0;
}
buffer_read(buffer, dname + dname_length, length);
dname_length += length;
} else {
return 0;
}
}
if (mark != -1) {
buffer_set_position(buffer, mark);
}
return dname_length;
}
int
buffer_skip_dname(buffer_type* buffer)
{
ods_log_assert(buffer);
while (1) {
uint8_t label_size = 0;
if (!buffer_available(buffer, 1)) {
return 0;
}
label_size = buffer_read_u8(buffer);
if (label_size == 0) {
break;
} else if ((label_size & 0xc0) != 0) {
if (!buffer_available(buffer, 1)) {
return 0;
}
buffer_skip(buffer, 1);
break;
} else if (!buffer_available(buffer, label_size)) {
return 0;
} else {
buffer_skip(buffer, label_size);
}
}
return 1;
}
int
buffer_skip_rr(buffer_type* buffer, unsigned qrr)
{
if (!buffer_skip_dname(buffer)) {
return 0;
}
if (qrr) {
if (!buffer_available(buffer, 4)) {
return 0;
}
buffer_skip(buffer, 4);
} else {
uint16_t rdata_size;
if (!buffer_available(buffer, 10)) {
return 0;
}
buffer_skip(buffer, 8);
rdata_size = buffer_read_u16(buffer);
if (!buffer_available(buffer, rdata_size)) {
return 0;
}
buffer_skip(buffer, rdata_size);
}
return 1;
}
size_t
buffer_limit(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer->limit;
}
void
buffer_set_limit(buffer_type* buffer, size_t limit)
{
ods_log_assert(buffer);
ods_log_assert(limit <= buffer->capacity);
buffer->limit = limit;
if (buffer->position > buffer->limit) {
buffer->position = buffer->limit;
}
}
size_t
buffer_capacity(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer->capacity;
}
uint8_t*
buffer_at(buffer_type* buffer, size_t at)
{
ods_log_assert(buffer);
ods_log_assert(at <= buffer->limit);
return buffer->data + at;
}
uint8_t*
buffer_begin(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_at(buffer, 0);
}
uint8_t*
buffer_current(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_at(buffer, buffer->position);
}
static size_t
buffer_remaining_at(buffer_type* buffer, size_t at)
{
ods_log_assert(buffer);
ods_log_assert(at <= buffer->limit);
return buffer->limit - at;
}
size_t
buffer_remaining(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_remaining_at(buffer, buffer->position);
}
static int
buffer_available_at(buffer_type *buffer, size_t at, size_t count)
{
ods_log_assert(buffer);
return count <= buffer_remaining_at(buffer, at);
}
int
buffer_available(buffer_type *buffer, size_t count)
{
ods_log_assert(buffer);
return buffer_available_at(buffer, buffer->position, count);
}
static void
buffer_write_u8_at(buffer_type* buffer, size_t at, uint8_t data)
{
ods_log_assert(buffer);
ods_log_assert(buffer_available_at(buffer, at, sizeof(data)));
buffer->data[at] = data;
}
void
buffer_write_u16_at(buffer_type* buffer, size_t at, uint16_t data)
{
ods_log_assert(buffer);
ods_log_assert(buffer_available_at(buffer, at, sizeof(data)));
write_uint16(buffer->data + at, data);
}
static void
buffer_write_u32_at(buffer_type* buffer, size_t at, uint32_t data)
{
ods_log_assert(buffer);
ods_log_assert(buffer_available_at(buffer, at, sizeof(data)));
write_uint32(buffer->data + at, data);
}
void
buffer_write(buffer_type* buffer, const void* data, size_t count)
{
ods_log_assert(buffer);
ods_log_assert(buffer_available(buffer, count));
memcpy(buffer->data + buffer->position, data, count);
buffer->position += count;
}
void
buffer_write_u8(buffer_type* buffer, uint8_t data)
{
ods_log_assert(buffer);
buffer_write_u8_at(buffer, buffer->position, data);
buffer->position += sizeof(data);
}
void
buffer_write_u16(buffer_type* buffer, uint16_t data)
{
ods_log_assert(buffer);
buffer_write_u16_at(buffer, buffer->position, data);
buffer->position += sizeof(data);
}
void
buffer_write_u32(buffer_type* buffer, uint32_t data)
{
ods_log_assert(buffer);
buffer_write_u32_at(buffer, buffer->position, data);
buffer->position += sizeof(data);
}
void
buffer_write_rdf(buffer_type* buffer, ldns_rdf* rdf)
{
ods_log_assert(buffer);
ods_log_assert(rdf);
buffer_write(buffer, ldns_rdf_data(rdf), ldns_rdf_size(rdf));
/* position updated by buffer_write() */
}
int
buffer_write_rr(buffer_type* buffer, ldns_rr* rr)
{
size_t i = 0;
size_t tc_mark = 0;
size_t rdlength_pos = 0;
uint16_t rdlength = 0;
ods_log_assert(buffer);
ods_log_assert(rr);
/* set truncation mark, in case rr does not fit */
tc_mark = buffer_position(buffer);
/* owner type class ttl */
if (!buffer_available(buffer, ldns_rdf_size(ldns_rr_owner(rr)))) {
goto buffer_tc;
}
buffer_write_rdf(buffer, ldns_rr_owner(rr));
if (!buffer_available(buffer, sizeof(uint16_t) + sizeof(uint16_t) +
sizeof(uint32_t) + sizeof(rdlength))) {
goto buffer_tc;
}
buffer_write_u16(buffer, (uint16_t) ldns_rr_get_type(rr));
buffer_write_u16(buffer, (uint16_t) ldns_rr_get_class(rr));
buffer_write_u32(buffer, (uint32_t) ldns_rr_ttl(rr));
/* skip rdlength */
rdlength_pos = buffer_position(buffer);
buffer_skip(buffer, sizeof(rdlength));
/* write rdata */
for (i=0; i < ldns_rr_rd_count(rr); i++) {
if (!buffer_available(buffer, ldns_rdf_size(ldns_rr_rdf(rr, i)))) {
goto buffer_tc;
}
buffer_write_rdf(buffer, ldns_rr_rdf(rr, i));
}
/* write rdlength */
rdlength = buffer_position(buffer) - rdlength_pos - sizeof(rdlength);
buffer_write_u16_at(buffer, rdlength_pos, rdlength);
/* position updated by buffer_write() */
return 1;
buffer_tc:
buffer_set_position(buffer, tc_mark);
return 0;
}
static uint8_t
buffer_read_u8_at(buffer_type* buffer, size_t at)
{
ods_log_assert(buffer);
ods_log_assert(at < buffer->capacity);
return buffer->data[at];
}
static uint16_t
buffer_read_u16_at(buffer_type* buffer, size_t at)
{
ods_log_assert(buffer);
return read_uint16(buffer->data + at);
}
static uint32_t
buffer_read_u32_at(buffer_type* buffer, size_t at)
{
ods_log_assert(buffer);
return read_uint32(buffer->data + at);
}
void
buffer_read(buffer_type* buffer, void* data, size_t count)
{
ods_log_assert(buffer);
ods_log_assert(buffer_available(buffer, count));
memcpy(data, buffer->data + buffer->position, count);
buffer->position += count;
}
uint8_t
buffer_read_u8(buffer_type* buffer)
{
uint16_t result = 0;
ods_log_assert(buffer);
result = buffer_read_u8_at(buffer, buffer->position);
buffer->position += sizeof(uint8_t);
return result;
}
uint16_t
buffer_read_u16(buffer_type* buffer)
{
uint16_t result = 0;
ods_log_assert(buffer);
result = buffer_read_u16_at(buffer, buffer->position);
buffer->position += sizeof(uint16_t);
return result;
}
uint32_t
buffer_read_u32(buffer_type* buffer)
{
uint32_t result = 0;
ods_log_assert(buffer);
result = buffer_read_u32_at(buffer, buffer->position);
buffer->position += sizeof(uint32_t);
return result;
}
uint16_t
buffer_pkt_id(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_read_u16_at(buffer, 0);
}
static uint16_t
random_id(void)
{
return ldns_get_random();
}
void
buffer_pkt_set_random_id(buffer_type* buffer)
{
uint16_t qid = 0;
ods_log_assert(buffer);
qid = random_id();
buffer_write_u16_at(buffer, 0, qid);
}
uint16_t
buffer_pkt_flags(buffer_type* buffer)
{
ods_log_assert(buffer);
return (uint16_t) buffer_read_u16_at(buffer, 2);
}
void
buffer_pkt_set_flags(buffer_type* buffer, uint16_t flags)
{
ods_log_assert(buffer);
buffer_write_u16_at(buffer, 2, flags);
}
int
buffer_pkt_qr(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) QR(buffer);
}
void
buffer_pkt_set_qr(buffer_type* buffer)
{
ods_log_assert(buffer);
QR_SET(buffer);
}
void
buffer_pkt_clear_qr(buffer_type* buffer)
{
ods_log_assert(buffer);
QR_CLR(buffer);
}
ldns_pkt_opcode
buffer_pkt_opcode(buffer_type* buffer)
{
ods_log_assert(buffer);
return (ldns_pkt_opcode) OPCODE(buffer);
}
void
buffer_pkt_set_opcode(buffer_type* buffer, ldns_pkt_opcode opcode)
{
ods_log_assert(buffer);
OPCODE_SET(buffer, opcode);
}
int
buffer_pkt_aa(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) AA(buffer);
}
void
buffer_pkt_set_aa(buffer_type* buffer)
{
ods_log_assert(buffer);
AA_SET(buffer);
}
int
buffer_pkt_tc(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) TC(buffer);
}
int
buffer_pkt_rd(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) RD(buffer);
}
int
buffer_pkt_ra(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) RA(buffer);
}
int
buffer_pkt_ad(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) AD(buffer);
}
int
buffer_pkt_cd(buffer_type* buffer)
{
ods_log_assert(buffer);
return (int) CD(buffer);
}
ldns_pkt_rcode
buffer_pkt_rcode(buffer_type* buffer)
{
ods_log_assert(buffer);
return (ldns_pkt_rcode) RCODE(buffer);
}
void
buffer_pkt_set_rcode(buffer_type* buffer, ldns_pkt_rcode rcode)
{
ods_log_assert(buffer);
RCODE_SET(buffer, rcode);
}
const char*
buffer_rcode2str(ldns_pkt_rcode rcode)
{
ods_lookup_table *lt;
lt = ods_lookup_by_id(ods_rcode_str, rcode);
if (lt) {
return lt->name;
}
return NULL;
}
uint16_t
buffer_pkt_qdcount(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_read_u16_at(buffer, 4);
}
void
buffer_pkt_set_qdcount(buffer_type* buffer, uint16_t count)
{
ods_log_assert(buffer);
buffer_write_u16_at(buffer, 4, count);
}
uint16_t
buffer_pkt_ancount(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_read_u16_at(buffer, 6);
}
void
buffer_pkt_set_ancount(buffer_type* buffer, uint16_t count)
{
ods_log_assert(buffer);
buffer_write_u16_at(buffer, 6, count);
}
uint16_t
buffer_pkt_nscount(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_read_u16_at(buffer, 8);
}
void
buffer_pkt_set_nscount(buffer_type* buffer, uint16_t count)
{
ods_log_assert(buffer);
buffer_write_u16_at(buffer, 8, count);
}
uint16_t
buffer_pkt_arcount(buffer_type* buffer)
{
ods_log_assert(buffer);
return buffer_read_u16_at(buffer, 10);
}
void
buffer_pkt_set_arcount(buffer_type* buffer, uint16_t count)
{
ods_log_assert(buffer);
buffer_write_u16_at(buffer, 10, count);
}
static void
buffer_pkt_new(buffer_type* buffer, ldns_rdf* qname, ldns_rr_type qtype,
ldns_rr_class qclass, ldns_pkt_opcode opcode)
{
ods_log_assert(buffer);
ods_log_assert(qname);
ods_log_assert(qtype);
ods_log_assert(qclass);
/* The header */
buffer_clear(buffer);
buffer_pkt_set_random_id(buffer);
buffer_pkt_set_opcode(buffer, opcode);
buffer_pkt_clear_qr(buffer);
buffer_pkt_set_rcode(buffer, LDNS_RCODE_NOERROR);
buffer_pkt_set_qdcount(buffer, 1);
buffer_pkt_set_ancount(buffer, 0);
buffer_pkt_set_nscount(buffer, 0);
buffer_pkt_set_arcount(buffer, 0);
buffer_skip(buffer, BUFFER_PKT_HEADER_SIZE);
/* The question record */
buffer_write_rdf(buffer, qname);
buffer_write_u16(buffer, qtype);
buffer_write_u16(buffer, qclass);
}
void
buffer_pkt_query(buffer_type* buffer, ldns_rdf* qname, ldns_rr_type qtype,
ldns_rr_class qclass)
{
buffer_pkt_new(buffer, qname, qtype, qclass, LDNS_PACKET_QUERY);
buffer_pkt_set_flags(buffer, 0);
}
void
buffer_pkt_notify(buffer_type* buffer, ldns_rdf* qname, ldns_rr_class qclass)
{
buffer_pkt_new(buffer, qname, LDNS_RR_TYPE_SOA, qclass,
LDNS_PACKET_NOTIFY);
}
void
buffer_cleanup(buffer_type* buffer)
{
if (!buffer) {
return;
}
free(buffer->data);
free(buffer);
}
buffer_pkt_opcode
ldns_pkt_opcode buffer_pkt_opcode(buffer_type *buffer)
Definition: buffer.c:846
OPCODE
#define OPCODE(packet)
Definition: buffer.h:60
buffer_pkt_rd
int buffer_pkt_rd(buffer_type *buffer)
Definition: buffer.c:906
buffer_pkt_set_random_id
void buffer_pkt_set_random_id(buffer_type *buffer)
Definition: buffer.c:772
buffer_at
uint8_t * buffer_at(buffer_type *buffer, size_t at)
Definition: buffer.c:413
buffer_pkt_arcount
uint16_t buffer_pkt_arcount(buffer_type *buffer)
Definition: buffer.c:1066
BUFFER_PKT_HEADER_SIZE
#define BUFFER_PKT_HEADER_SIZE
Definition: buffer.h:43
buffer_pkt_qdcount
uint16_t buffer_pkt_qdcount(buffer_type *buffer)
Definition: buffer.c:994
QR
#define QR(packet)
Definition: buffer.h:54
buffer_skip
void buffer_skip(buffer_type *buffer, ssize_t count)
Definition: buffer.c:150
buffer_pkt_set_flags
void buffer_pkt_set_flags(buffer_type *buffer, uint16_t flags)
Definition: buffer.c:798
buffer_read_u16
uint16_t buffer_read_u16(buffer_type *buffer)
Definition: buffer.c:721
buffer_skip_rr
int buffer_skip_rr(buffer_type *buffer, unsigned qrr)
Definition: buffer.c:342
buffer_flip
void buffer_flip(buffer_type *buffer)
Definition: buffer.c:112
buffer_pkt_set_qdcount
void buffer_pkt_set_qdcount(buffer_type *buffer, uint16_t count)
Definition: buffer.c:1006
buffer_clear
void buffer_clear(buffer_type *buffer)
Definition: buffer.c:99
OPCODE_SET
#define OPCODE_SET(packet, opcode)
Definition: buffer.h:61
buffer_read_u8
uint8_t buffer_read_u8(buffer_type *buffer)
Definition: buffer.c:706
buffer_write_u8
void buffer_write_u8(buffer_type *buffer, uint8_t data)
Definition: buffer.c:552
AA
#define AA(packet)
Definition: buffer.h:66
buffer_pkt_qr
int buffer_pkt_qr(buffer_type *buffer)
Definition: buffer.c:810
buffer_write
void buffer_write(buffer_type *buffer, const void *data, size_t count)
Definition: buffer.c:538
buffer_pkt_id
uint16_t buffer_pkt_id(buffer_type *buffer)
Definition: buffer.c:751
buffer_current
uint8_t * buffer_current(buffer_type *buffer)
Definition: buffer.c:438
buffer_pkt_ancount
uint16_t buffer_pkt_ancount(buffer_type *buffer)
Definition: buffer.c:1018
buffer_limit
size_t buffer_limit(buffer_type *buffer)
Definition: buffer.c:373
CD
#define CD(packet)
Definition: buffer.h:96
buffer_struct::capacity
size_t capacity
Definition: buffer.h:115
buffer_pkt_set_ancount
void buffer_pkt_set_ancount(buffer_type *buffer, uint16_t count)
Definition: buffer.c:1030
buffer_pkt_set_nscount
void buffer_pkt_set_nscount(buffer_type *buffer, uint16_t count)
Definition: buffer.c:1054
buffer_set_limit
void buffer_set_limit(buffer_type *buffer, size_t limit)
Definition: buffer.c:385
QR_SET
#define QR_SET(packet)
Definition: buffer.h:55
buffer_cleanup
void buffer_cleanup(buffer_type *buffer)
Definition: buffer.c:1145
buffer_struct::fixed
unsigned fixed
Definition: buffer.h:117
buffer_pkt_flags
uint16_t buffer_pkt_flags(buffer_type *buffer)
Definition: buffer.c:786
buffer_struct
Definition: buffer.h:112
RA
#define RA(packet)
Definition: buffer.h:84
buffer_capacity
size_t buffer_capacity(buffer_type *buffer)
Definition: buffer.c:401
buffer_skip_dname
int buffer_skip_dname(buffer_type *buffer)
Definition: buffer.c:310
buffer_read_u32
uint32_t buffer_read_u32(buffer_type *buffer)
Definition: buffer.c:736
buffer_struct::position
size_t position
Definition: buffer.h:113
buffer_pkt_set_opcode
void buffer_pkt_set_opcode(buffer_type *buffer, ldns_pkt_opcode opcode)
Definition: buffer.c:858
MAX_PACKET_SIZE
#define MAX_PACKET_SIZE
Definition: buffer.h:49
buffer_pkt_query
void buffer_pkt_query(buffer_type *buffer, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass)
Definition: buffer.c:1120
buffer_write_u16
void buffer_write_u16(buffer_type *buffer, uint16_t data)
Definition: buffer.c:565
buffer_read_dname
size_t buffer_read_dname(buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
Definition: buffer.c:246
buffer_write_u32
void buffer_write_u32(buffer_type *buffer, uint32_t data)
Definition: buffer.c:578
buffer_pkt_set_aa
void buffer_pkt_set_aa(buffer_type *buffer)
Definition: buffer.c:882
buffer_read
void buffer_read(buffer_type *buffer, void *data, size_t count)
Definition: buffer.c:692
TC
#define TC(packet)
Definition: buffer.h:72
buffer_rcode2str
const char * buffer_rcode2str(ldns_pkt_rcode rcode)
Definition: buffer.c:978
buffer_pkt_aa
int buffer_pkt_aa(buffer_type *buffer)
Definition: buffer.c:870
buffer_struct::data
uint8_t * data
Definition: buffer.h:116
buffer_pkt_nscount
uint16_t buffer_pkt_nscount(buffer_type *buffer)
Definition: buffer.c:1042
ods_rcode_str
ods_lookup_table ods_rcode_str[]
Definition: buffer.c:57
RD
#define RD(packet)
Definition: buffer.h:78
buffer_write_u16_at
void buffer_write_u16_at(buffer_type *buffer, size_t at, uint16_t data)
Definition: buffer.c:512
buffer_set_position
void buffer_set_position(buffer_type *buffer, size_t pos)
Definition: buffer.c:137
buffer_struct::limit
size_t limit
Definition: buffer.h:114
AA_SET
#define AA_SET(packet)
Definition: buffer.h:67
buffer.h
buffer_pkt_notify
void buffer_pkt_notify(buffer_type *buffer, ldns_rdf *qname, ldns_rr_class qclass)
Definition: buffer.c:1133
buffer_available
int buffer_available(buffer_type *buffer, size_t count)
Definition: buffer.c:487
buffer_pkt_ad
int buffer_pkt_ad(buffer_type *buffer)
Definition: buffer.c:930
MAXDOMAINLEN
#define MAXDOMAINLEN
Definition: buffer.h:44
RCODE_SET
#define RCODE_SET(packet, rcode)
Definition: buffer.h:103
buffer_pkt_clear_qr
void buffer_pkt_clear_qr(buffer_type *buffer)
Definition: buffer.c:834
AD
#define AD(packet)
Definition: buffer.h:90
buffer_remaining
size_t buffer_remaining(buffer_type *buffer)
Definition: buffer.c:463
buffer_pkt_set_rcode
void buffer_pkt_set_rcode(buffer_type *buffer, ldns_pkt_rcode rcode)
Definition: buffer.c:966
buffer_write_rdf
void buffer_write_rdf(buffer_type *buffer, ldns_rdf *rdf)
Definition: buffer.c:591
buffer_write_rr
int buffer_write_rr(buffer_type *buffer, ldns_rr *rr)
Definition: buffer.c:605
buffer_pkt_ra
int buffer_pkt_ra(buffer_type *buffer)
Definition: buffer.c:918
RCODE
#define RCODE(packet)
Definition: buffer.h:102
buffer_position
size_t buffer_position(buffer_type *buffer)
Definition: buffer.c:125
buffer_pkt_set_arcount
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
Definition: buffer.c:1078
buffer_pkt_cd
int buffer_pkt_cd(buffer_type *buffer)
Definition: buffer.c:942
QR_CLR
#define QR_CLR(packet)
Definition: buffer.h:56
buffer_pkt_set_qr
void buffer_pkt_set_qr(buffer_type *buffer)
Definition: buffer.c:822
buffer_begin
uint8_t * buffer_begin(buffer_type *buffer)
Definition: buffer.c:426
buffer_pkt_rcode
ldns_pkt_rcode buffer_pkt_rcode(buffer_type *buffer)
Definition: buffer.c:954
buffer_create
buffer_type * buffer_create(size_t capacity)
Definition: buffer.c:78
buffer_pkt_tc
int buffer_pkt_tc(buffer_type *buffer)
Definition: buffer.c:894