OpenDNSSEC-signer  1.4.5
Functions | Variables
buffer.c File Reference
#include "config.h"
#include "shared/log.h"
#include "wire/buffer.h"
#include <string.h>
Include dependency graph for buffer.c:

Go to the source code of this file.

Functions

buffer_typebuffer_create (allocator_type *allocator, size_t capacity)
 
void buffer_create_from (buffer_type *buffer, void *data, size_t size)
 
void buffer_clear (buffer_type *buffer)
 
void buffer_flip (buffer_type *buffer)
 
void buffer_rewind (buffer_type *buffer)
 
size_t buffer_position (buffer_type *buffer)
 
void buffer_set_position (buffer_type *buffer, size_t pos)
 
void buffer_skip (buffer_type *buffer, ssize_t count)
 
size_t buffer_read_dname (buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
 
int buffer_skip_dname (buffer_type *buffer)
 
int buffer_skip_rr (buffer_type *buffer, unsigned qrr)
 
size_t buffer_limit (buffer_type *buffer)
 
void buffer_set_limit (buffer_type *buffer, size_t limit)
 
size_t buffer_capacity (buffer_type *buffer)
 
uint8_t * buffer_at (buffer_type *buffer, size_t at)
 
uint8_t * buffer_begin (buffer_type *buffer)
 
uint8_t * buffer_end (buffer_type *buffer)
 
uint8_t * buffer_current (buffer_type *buffer)
 
size_t buffer_remaining (buffer_type *buffer)
 
int buffer_available (buffer_type *buffer, size_t count)
 
void buffer_write_u16_at (buffer_type *buffer, size_t at, uint16_t data)
 
void buffer_write (buffer_type *buffer, const void *data, size_t count)
 
void buffer_write_u8 (buffer_type *buffer, uint8_t data)
 
void buffer_write_u16 (buffer_type *buffer, uint16_t data)
 
void buffer_write_u32 (buffer_type *buffer, uint32_t data)
 
void buffer_write_rdf (buffer_type *buffer, ldns_rdf *rdf)
 
int buffer_write_rr (buffer_type *buffer, ldns_rr *rr)
 
void buffer_read (buffer_type *buffer, void *data, size_t count)
 
uint8_t buffer_read_u8 (buffer_type *buffer)
 
uint16_t buffer_read_u16 (buffer_type *buffer)
 
uint32_t buffer_read_u32 (buffer_type *buffer)
 
uint16_t buffer_pkt_id (buffer_type *buffer)
 
void buffer_pkt_set_random_id (buffer_type *buffer)
 
uint16_t buffer_pkt_flags (buffer_type *buffer)
 
void buffer_pkt_set_flags (buffer_type *buffer, uint16_t flags)
 
int buffer_pkt_qr (buffer_type *buffer)
 
void buffer_pkt_set_qr (buffer_type *buffer)
 
void buffer_pkt_clear_qr (buffer_type *buffer)
 
ldns_pkt_opcode buffer_pkt_opcode (buffer_type *buffer)
 
void buffer_pkt_set_opcode (buffer_type *buffer, ldns_pkt_opcode opcode)
 
int buffer_pkt_aa (buffer_type *buffer)
 
void buffer_pkt_set_aa (buffer_type *buffer)
 
int buffer_pkt_tc (buffer_type *buffer)
 
int buffer_pkt_rd (buffer_type *buffer)
 
int buffer_pkt_ra (buffer_type *buffer)
 
int buffer_pkt_ad (buffer_type *buffer)
 
int buffer_pkt_cd (buffer_type *buffer)
 
ldns_pkt_rcode buffer_pkt_rcode (buffer_type *buffer)
 
void buffer_pkt_set_rcode (buffer_type *buffer, ldns_pkt_rcode rcode)
 
const char * buffer_rcode2str (ldns_pkt_rcode rcode)
 
uint16_t buffer_pkt_qdcount (buffer_type *buffer)
 
void buffer_pkt_set_qdcount (buffer_type *buffer, uint16_t count)
 
uint16_t buffer_pkt_ancount (buffer_type *buffer)
 
void buffer_pkt_set_ancount (buffer_type *buffer, uint16_t count)
 
uint16_t buffer_pkt_nscount (buffer_type *buffer)
 
void buffer_pkt_set_nscount (buffer_type *buffer, uint16_t count)
 
uint16_t buffer_pkt_arcount (buffer_type *buffer)
 
void buffer_pkt_set_arcount (buffer_type *buffer, uint16_t count)
 
void buffer_pkt_query (buffer_type *buffer, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass)
 
void buffer_pkt_notify (buffer_type *buffer, ldns_rdf *qname, ldns_rr_class qclass)
 
void buffer_pkt_axfr (buffer_type *buffer, ldns_rdf *qname, ldns_rr_class qclass)
 
void buffer_pkt_print (FILE *fd, buffer_type *buffer)
 
void buffer_cleanup (buffer_type *buffer, allocator_type *allocator)
 

Variables

ods_lookup_table ods_rcode_str []
 

Function Documentation

uint8_t* buffer_at ( buffer_type buffer,
size_t  at 
)

Return a pointer to the data at the indicated position.

Definition at line 452 of file buffer.c.

References buffer_struct::data, and ods_log_assert.

Referenced by buffer_begin(), buffer_current(), buffer_end(), and tsig_rr_update().

int buffer_available ( buffer_type buffer,
size_t  count 
)

Check if the buffer has enough bytes available.

Definition at line 538 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by buffer_read(), buffer_read_dname(), buffer_skip_dname(), buffer_skip_rr(), buffer_write(), buffer_write_rr(), edns_rr_parse(), query_add_rr(), and tsig_rr_parse().

uint8_t* buffer_begin ( buffer_type buffer)

Return a pointer to the data at the beginning of the buffer.

Definition at line 465 of file buffer.c.

References buffer_at(), and ods_log_assert.

Referenced by buffer_pkt_print(), and sock_handle_udp().

size_t buffer_capacity ( buffer_type buffer)

Get the buffer's capacity.

Definition at line 440 of file buffer.c.

References buffer_struct::capacity, and ods_log_assert.

Referenced by query_prepare(), and tcp_conn_read().

void buffer_cleanup ( buffer_type buffer,
allocator_type allocator 
)

Clean up buffer.

Definition at line 1261 of file buffer.c.

References allocator_deallocate(), and buffer_struct::data.

Referenced by query_cleanup(), and xfrhandler_cleanup().

void buffer_clear ( buffer_type buffer)

Clear the buffer and make it ready for writing.

Definition at line 119 of file buffer.c.

References buffer_struct::capacity, buffer_struct::limit, ods_log_assert, and buffer_struct::position.

Referenced by query_prepare(), query_reset(), sock_handle_tcp_write(), and tcp_conn_ready().

buffer_type* buffer_create ( allocator_type allocator,
size_t  capacity 
)

Create a new buffer with the specified capacity.

Definition at line 78 of file buffer.c.

References allocator_alloc(), buffer_struct::capacity, buffer_struct::data, buffer_struct::fixed, buffer_struct::limit, and buffer_struct::position.

Referenced by query_create(), tcp_conn_create(), and xfrhandler_create().

void buffer_create_from ( buffer_type buffer,
void *  data,
size_t  size 
)

Create a buffer with the specified data.

Definition at line 102 of file buffer.c.

References buffer_struct::capacity, buffer_struct::data, buffer_struct::fixed, buffer_struct::limit, ods_log_assert, and buffer_struct::position.

uint8_t* buffer_current ( buffer_type buffer)

Return a pointer to the data at the buffer's current position.

Definition at line 489 of file buffer.c.

References buffer_at(), ods_log_assert, and buffer_struct::position.

Referenced by buffer_read_dname(), query_process(), sock_handle_tcp_read(), sock_handle_tcp_write(), tcp_conn_read(), tcp_conn_write(), and tsig_rr_parse().

uint8_t* buffer_end ( buffer_type buffer)

Return a pointer to the data at the end of the buffer.

Definition at line 477 of file buffer.c.

References buffer_at(), buffer_struct::limit, and ods_log_assert.

void buffer_flip ( buffer_type buffer)

Flip the buffer and make it ready for reading.

Definition at line 133 of file buffer.c.

References buffer_struct::limit, ods_log_assert, and buffer_struct::position.

Referenced by notify_send(), sock_handle_tcp_read(), sock_handle_tcp_write(), and sock_handle_udp().

size_t buffer_limit ( buffer_type buffer)

Get the buffer's limit.

Definition at line 411 of file buffer.c.

References buffer_struct::limit, and ods_log_assert.

Referenced by buffer_read_dname(), query_prepare(), query_process(), and tsig_rr_update().

int buffer_pkt_aa ( buffer_type buffer)

Get AA bit from buffer.

Definition at line 935 of file buffer.c.

References AA, and ods_log_assert.

int buffer_pkt_ad ( buffer_type buffer)

Get AD bit from buffer.

Definition at line 996 of file buffer.c.

References AD, and ods_log_assert.

uint16_t buffer_pkt_ancount ( buffer_type buffer)

Get ANCOUNT from buffer.

Definition at line 1086 of file buffer.c.

References ods_log_assert.

Referenced by axfr(), ixfr(), soa_request(), and tsig_rr_find().

uint16_t buffer_pkt_arcount ( buffer_type buffer)

Get ARCOUNT from buffer.

Definition at line 1136 of file buffer.c.

References ods_log_assert.

Referenced by query_add_optional(), and tsig_rr_find().

void buffer_pkt_axfr ( buffer_type buffer,
ldns_rdf *  qname,
ldns_rr_class  qclass 
)

Make a new axfr.

Definition at line 1219 of file buffer.c.

References buffer_pkt_set_qr().

int buffer_pkt_cd ( buffer_type buffer)

Get CD bit from buffer.

Definition at line 1008 of file buffer.c.

References CD, and ods_log_assert.

void buffer_pkt_clear_qr ( buffer_type buffer)

Clear QR bit in buffer.

Definition at line 897 of file buffer.c.

References ods_log_assert, and QR_CLR.

uint16_t buffer_pkt_flags ( buffer_type buffer)

Get flags from buffer.

Definition at line 847 of file buffer.c.

References ods_log_assert.

Referenced by query_prepare().

uint16_t buffer_pkt_id ( buffer_type buffer)

Get query id from buffer.

Definition at line 811 of file buffer.c.

References ods_log_assert.

Referenced by notify_send().

void buffer_pkt_notify ( buffer_type buffer,
ldns_rdf *  qname,
ldns_rr_class  qclass 
)

Make a new notify.

Definition at line 1206 of file buffer.c.

Referenced by notify_send().

uint16_t buffer_pkt_nscount ( buffer_type buffer)

Get NSCOUNT from buffer.

Definition at line 1111 of file buffer.c.

References ods_log_assert.

Referenced by tsig_rr_find().

ldns_pkt_opcode buffer_pkt_opcode ( buffer_type buffer)

Get OPCODE from buffer.

Definition at line 910 of file buffer.c.

References ods_log_assert, and OPCODE.

void buffer_pkt_print ( FILE *  fd,
buffer_type buffer 
)

Print packet buffer.

Definition at line 1233 of file buffer.c.

References buffer_begin(), buffer_remaining(), and ods_log_assert.

uint16_t buffer_pkt_qdcount ( buffer_type buffer)

Get QDCOUNT from buffer.

Definition at line 1061 of file buffer.c.

References ods_log_assert.

Referenced by tsig_rr_find().

int buffer_pkt_qr ( buffer_type buffer)

Get QR bit from buffer.

Definition at line 872 of file buffer.c.

References ods_log_assert, and QR.

Referenced by query_process(), and tsig_rr_update().

void buffer_pkt_query ( buffer_type buffer,
ldns_rdf *  qname,
ldns_rr_type  qtype,
ldns_rr_class  qclass 
)

Make a new query.

Definition at line 1192 of file buffer.c.

References buffer_pkt_set_flags().

int buffer_pkt_ra ( buffer_type buffer)

Get RA bit from buffer.

Definition at line 984 of file buffer.c.

References ods_log_assert, and RA.

ldns_pkt_rcode buffer_pkt_rcode ( buffer_type buffer)

Get RCODE from buffer.

Definition at line 1020 of file buffer.c.

References ods_log_assert, and RCODE.

int buffer_pkt_rd ( buffer_type buffer)

Get RD bit from buffer.

Definition at line 972 of file buffer.c.

References ods_log_assert, and RD.

void buffer_pkt_set_aa ( buffer_type buffer)

Set AA bit in buffer.

Definition at line 947 of file buffer.c.

References AA_SET, and ods_log_assert.

Referenced by notify_send(), and soa_request().

void buffer_pkt_set_ancount ( buffer_type buffer,
uint16_t  count 
)

Set ANCOUNT in buffer.

Definition at line 1098 of file buffer.c.

References buffer_write_u16_at(), and ods_log_assert.

Referenced by axfr(), ixfr(), notify_send(), and soa_request().

void buffer_pkt_set_arcount ( buffer_type buffer,
uint16_t  count 
)

Set ARCOUNT in buffer.

Definition at line 1148 of file buffer.c.

References buffer_write_u16_at(), and ods_log_assert.

Referenced by axfr(), ixfr(), query_add_optional(), and soa_request().

void buffer_pkt_set_flags ( buffer_type buffer,
uint16_t  flags 
)

Set flags in buffer.

Definition at line 859 of file buffer.c.

References buffer_write_u16_at(), and ods_log_assert.

Referenced by buffer_pkt_query(), and query_prepare().

void buffer_pkt_set_nscount ( buffer_type buffer,
uint16_t  count 
)

Set NSCOUNT in buffer.

Definition at line 1123 of file buffer.c.

References buffer_write_u16_at(), and ods_log_assert.

Referenced by axfr(), ixfr(), and soa_request().

void buffer_pkt_set_opcode ( buffer_type buffer,
ldns_pkt_opcode  opcode 
)

Set OPCODE in buffer.

Definition at line 922 of file buffer.c.

References ods_log_assert, and OPCODE_SET.

void buffer_pkt_set_qdcount ( buffer_type buffer,
uint16_t  count 
)

Set QDCOUNT in buffer.

Definition at line 1073 of file buffer.c.

References buffer_write_u16_at(), and ods_log_assert.

Referenced by axfr(), and ixfr().

void buffer_pkt_set_qr ( buffer_type buffer)

Set QR bit in buffer.

Definition at line 884 of file buffer.c.

References ods_log_assert, and QR_SET.

Referenced by buffer_pkt_axfr().

void buffer_pkt_set_random_id ( buffer_type buffer)

Set random query id in buffer.

Definition at line 832 of file buffer.c.

References buffer_write_u16_at(), and ods_log_assert.

void buffer_pkt_set_rcode ( buffer_type buffer,
ldns_pkt_rcode  rcode 
)

Set RCODE in buffer.

Definition at line 1032 of file buffer.c.

References ods_log_assert, and RCODE_SET.

Referenced by axfr(), ixfr(), and soa_request().

int buffer_pkt_tc ( buffer_type buffer)

Get TC bit from buffer.

Definition at line 960 of file buffer.c.

References ods_log_assert, and TC.

size_t buffer_position ( buffer_type buffer)
const char* buffer_rcode2str ( ldns_pkt_rcode  rcode)

Look up a descriptive text by each rcode.

Definition at line 1045 of file buffer.c.

References ods_struct_lookup_table::name, and ods_lookup_by_id().

void buffer_read ( buffer_type buffer,
void *  data,
size_t  count 
)

Read from buffer.

Definition at line 751 of file buffer.c.

References buffer_available(), buffer_struct::data, ods_log_assert, and buffer_struct::position.

Referenced by buffer_read_dname().

size_t buffer_read_dname ( buffer_type buffer,
uint8_t *  dname,
unsigned  allow_pointers 
)
uint16_t buffer_read_u16 ( buffer_type buffer)

Read uint16_t from buffer.

Definition at line 781 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by buffer_skip_rr(), edns_rr_parse(), and tsig_rr_parse().

uint32_t buffer_read_u32 ( buffer_type buffer)

Read uint32_t from buffer.

Definition at line 796 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by tsig_rr_parse().

uint8_t buffer_read_u8 ( buffer_type buffer)

Read uint8_t from buffer.

Definition at line 766 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by buffer_skip_dname(), and edns_rr_parse().

size_t buffer_remaining ( buffer_type buffer)

The number of bytes remaining between the buffer's position and limit.

Definition at line 514 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by buffer_pkt_print(), query_process(), sock_handle_tcp_read(), sock_handle_tcp_write(), sock_handle_udp(), tcp_conn_read(), and tcp_conn_write().

void buffer_rewind ( buffer_type buffer)

Make the buffer ready for re-reading the data.

Definition at line 147 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

void buffer_set_limit ( buffer_type buffer,
size_t  limit 
)

Set the buffer's limit.

Definition at line 423 of file buffer.c.

References buffer_struct::limit, ods_log_assert, and buffer_struct::position.

Referenced by axfr(), ixfr(), query_prepare(), sock_handle_tcp_read(), and tcp_conn_read().

void buffer_set_position ( buffer_type buffer,
size_t  pos 
)

Set the buffer's position.

Definition at line 172 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by axfr(), buffer_read_dname(), buffer_write_rr(), edns_rr_parse(), ixfr(), query_add_rr(), query_prepare(), tsig_rr_find(), and tsig_rr_parse().

void buffer_skip ( buffer_type buffer,
ssize_t  count 
)
int buffer_skip_dname ( buffer_type buffer)

Change the buffer's position so that one dname is skipped.

Definition at line 348 of file buffer.c.

References buffer_available(), buffer_read_u8(), buffer_skip(), and ods_log_assert.

Referenced by buffer_skip_rr(), and tsig_rr_parse().

int buffer_skip_rr ( buffer_type buffer,
unsigned  qrr 
)

Change the buffer's position so that one RR is skipped.

Definition at line 380 of file buffer.c.

References buffer_available(), buffer_read_u16(), buffer_skip(), and buffer_skip_dname().

Referenced by tsig_rr_find().

void buffer_write ( buffer_type buffer,
const void *  data,
size_t  count 
)

Write to buffer.

Definition at line 592 of file buffer.c.

References buffer_available(), buffer_struct::data, ods_log_assert, and buffer_struct::position.

Referenced by buffer_write_rdf(), query_add_optional(), and tsig_rr_append().

void buffer_write_rdf ( buffer_type buffer,
ldns_rdf *  rdf 
)

Write rdf to buffer.

Definition at line 649 of file buffer.c.

References buffer_write(), and ods_log_assert.

Referenced by buffer_write_rr(), query_add_rr(), and tsig_rr_append().

int buffer_write_rr ( buffer_type buffer,
ldns_rr *  rr 
)
void buffer_write_u16 ( buffer_type buffer,
uint16_t  data 
)

Write uint16_t to buffer.

Definition at line 621 of file buffer.c.

References buffer_write_u16_at(), ods_log_assert, and buffer_struct::position.

Referenced by buffer_write_rr(), query_add_rr(), and tsig_rr_append().

void buffer_write_u16_at ( buffer_type buffer,
size_t  at,
uint16_t  data 
)
void buffer_write_u32 ( buffer_type buffer,
uint32_t  data 
)

Write uint32_t to buffer.

Definition at line 635 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by buffer_write_rr(), query_add_rr(), and tsig_rr_append().

void buffer_write_u8 ( buffer_type buffer,
uint8_t  data 
)

Write uint8_t to buffer.

Definition at line 607 of file buffer.c.

References ods_log_assert, and buffer_struct::position.

Referenced by tsig_rr_append().

Variable Documentation

ods_lookup_table ods_rcode_str[]
Initial value:
= {
{ 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 }
}

Definition at line 57 of file buffer.c.