/build/ldns-NeVfgT/ldns-1.9.2/packet.c
Go to the documentation of this file.
/*
* packet.c
*
* dns packet implementation
*
* 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 <strings.h>
#include <limits.h>
#ifdef HAVE_SSL
#include <openssl/rand.h>
#endif
/* Access functions
* do this as functions to get type checking
*/
#define LDNS_EDNS_MASK_DO_BIT 0x8000
#define LDNS_EDNS_MASK_CO_BIT 0x4000
#define LDNS_EDNS_MASK_UNASSIGNED (0xFFFF & ~( LDNS_EDNS_MASK_DO_BIT \
| LDNS_EDNS_MASK_CO_BIT ))
/* TODO defines for 3600 */
/* convert to and from numerical flag values */
ldns_lookup_table ldns_edns_flags[] = {
{ 3600, "do"},
{ 0, NULL}
};
/* read */
uint16_t
ldns_pkt_id(const ldns_pkt *packet)
{
return packet->_header->_id;
}
bool
ldns_pkt_qr(const ldns_pkt *packet)
{
return packet->_header->_qr;
}
bool
ldns_pkt_aa(const ldns_pkt *packet)
{
return packet->_header->_aa;
}
bool
ldns_pkt_tc(const ldns_pkt *packet)
{
return packet->_header->_tc;
}
bool
ldns_pkt_rd(const ldns_pkt *packet)
{
return packet->_header->_rd;
}
bool
ldns_pkt_cd(const ldns_pkt *packet)
{
return packet->_header->_cd;
}
bool
ldns_pkt_ra(const ldns_pkt *packet)
{
return packet->_header->_ra;
}
bool
ldns_pkt_ad(const ldns_pkt *packet)
{
return packet->_header->_ad;
}
ldns_pkt_opcode
ldns_pkt_get_opcode(const ldns_pkt *packet)
{
return packet->_header->_opcode;
}
ldns_pkt_rcode
ldns_pkt_get_rcode(const ldns_pkt *packet)
{
return packet->_header->_rcode;
}
uint16_t
ldns_pkt_qdcount(const ldns_pkt *packet)
{
return packet->_header->_qdcount;
}
uint16_t
ldns_pkt_ancount(const ldns_pkt *packet)
{
return packet->_header->_ancount;
}
uint16_t
ldns_pkt_nscount(const ldns_pkt *packet)
{
return packet->_header->_nscount;
}
uint16_t
ldns_pkt_arcount(const ldns_pkt *packet)
{
return packet->_header->_arcount;
}
ldns_rr_list *
ldns_pkt_question(const ldns_pkt *packet)
{
return packet->_question;
}
ldns_rr_list *
ldns_pkt_answer(const ldns_pkt *packet)
{
return packet->_answer;
}
ldns_rr_list *
ldns_pkt_authority(const ldns_pkt *packet)
{
return packet->_authority;
}
ldns_rr_list *
ldns_pkt_additional(const ldns_pkt *packet)
{
return packet->_additional;
}
/* return ALL section concatenated */
ldns_rr_list *
ldns_pkt_all(const ldns_pkt *packet)
{
ldns_rr_list *all, *prev_all;
all = ldns_rr_list_cat_clone(
ldns_pkt_question(packet),
ldns_pkt_answer(packet));
prev_all = all;
all = ldns_rr_list_cat_clone(all,
ldns_pkt_authority(packet));
ldns_rr_list_deep_free(prev_all);
prev_all = all;
all = ldns_rr_list_cat_clone(all,
ldns_pkt_additional(packet));
ldns_rr_list_deep_free(prev_all);
return all;
}
ldns_rr_list *
ldns_pkt_all_noquestion(const ldns_pkt *packet)
{
ldns_rr_list *all, *all2;
all = ldns_rr_list_cat_clone(
ldns_pkt_answer(packet),
ldns_pkt_authority(packet));
all2 = ldns_rr_list_cat_clone(all,
ldns_pkt_additional(packet));
ldns_rr_list_deep_free(all);
return all2;
}
size_t
ldns_pkt_size(const ldns_pkt *packet)
{
return packet->_size;
}
uint32_t
ldns_pkt_querytime(const ldns_pkt *packet)
{
return packet->_querytime;
}
ldns_rdf *
ldns_pkt_answerfrom(const ldns_pkt *packet)
{
return packet->_answerfrom;
}
struct timeval
ldns_pkt_timestamp(const ldns_pkt *packet)
{
return packet->timestamp;
}
uint16_t
ldns_pkt_edns_udp_size(const ldns_pkt *packet)
{
return packet->_edns_udp_size;
}
uint8_t
ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
{
return packet->_edns_extended_rcode;
}
uint8_t
ldns_pkt_edns_version(const ldns_pkt *packet)
{
return packet->_edns_version;
}
uint16_t
ldns_pkt_edns_z(const ldns_pkt *packet)
{
return packet->_edns_z;
}
bool
ldns_pkt_edns_do(const ldns_pkt *packet)
{
return (packet->_edns_z & LDNS_EDNS_MASK_DO_BIT);
}
void
ldns_pkt_set_edns_do(ldns_pkt *packet, bool value)
{
if (value) {
packet->_edns_z = packet->_edns_z | LDNS_EDNS_MASK_DO_BIT;
} else {
packet->_edns_z = packet->_edns_z & ~LDNS_EDNS_MASK_DO_BIT;
}
}
bool
ldns_pkt_edns_co(const ldns_pkt *packet)
{
return (packet->_edns_z & LDNS_EDNS_MASK_CO_BIT);
}
void
ldns_pkt_set_edns_co(ldns_pkt *packet, bool value)
{
if (value) {
packet->_edns_z = packet->_edns_z | LDNS_EDNS_MASK_CO_BIT;
} else {
packet->_edns_z = packet->_edns_z & ~LDNS_EDNS_MASK_CO_BIT;
}
}
uint16_t
ldns_pkt_edns_unassigned(const ldns_pkt *packet)
{
return (packet->_edns_z & LDNS_EDNS_MASK_UNASSIGNED);
}
void
ldns_pkt_set_edns_unassigned(ldns_pkt *packet, uint16_t value)
{
packet->_edns_z = (packet->_edns_z & ~LDNS_EDNS_MASK_UNASSIGNED)
| (value & LDNS_EDNS_MASK_UNASSIGNED);
}
ldns_rdf *
ldns_pkt_edns_data(const ldns_pkt *packet)
{
return packet->_edns_data;
}
/* return only those rr that share the ownername */
ldns_rr_list *
ldns_pkt_rr_list_by_name(const ldns_pkt *packet,
const ldns_rdf *ownername,
ldns_pkt_section sec)
{
ldns_rr_list *rrs;
ldns_rr_list *ret;
uint16_t i;
if (!packet) {
return NULL;
}
rrs = ldns_pkt_get_section_clone(packet, sec);
ret = NULL;
for(i = 0; i < ldns_rr_list_rr_count(rrs); i++) {
if (ldns_dname_compare(ldns_rr_owner(
ldns_rr_list_rr(rrs, i)),
ownername) == 0) {
/* owner names match */
if (ret == NULL) {
ret = ldns_rr_list_new();
}
ldns_rr_list_push_rr(ret,
ldns_rr_clone(
ldns_rr_list_rr(rrs, i))
);
}
}
ldns_rr_list_deep_free(rrs);
return ret;
}
/* return only those rr that share a type */
ldns_rr_list *
ldns_pkt_rr_list_by_type(const ldns_pkt *packet,
ldns_rr_type type,
ldns_pkt_section sec)
{
ldns_rr_list *rrs;
ldns_rr_list *new;
uint16_t i;
if(!packet) {
return NULL;
}
rrs = ldns_pkt_get_section_clone(packet, sec);
new = ldns_rr_list_new();
for(i = 0; i < ldns_rr_list_rr_count(rrs); i++) {
if (type == ldns_rr_get_type(ldns_rr_list_rr(rrs, i))) {
/* types match */
ldns_rr_list_push_rr(new,
ldns_rr_clone(
ldns_rr_list_rr(rrs, i))
);
}
}
ldns_rr_list_deep_free(rrs);
if (ldns_rr_list_rr_count(new) == 0) {
ldns_rr_list_free(new);
return NULL;
} else {
return new;
}
}
/* return only those rrs that share name and type */
ldns_rr_list *
ldns_pkt_rr_list_by_name_and_type(const ldns_pkt *packet,
const ldns_rdf *ownername,
ldns_rr_type type,
ldns_pkt_section sec)
{
ldns_rr_list *rrs;
ldns_rr_list *new;
ldns_rr_list *ret;
uint16_t i;
if(!packet) {
return NULL;
}
rrs = ldns_pkt_get_section_clone(packet, sec);
new = ldns_rr_list_new();
ret = NULL;
for(i = 0; i < ldns_rr_list_rr_count(rrs); i++) {
if (type == ldns_rr_get_type(ldns_rr_list_rr(rrs, i)) &&
ldns_dname_compare(ldns_rr_owner(ldns_rr_list_rr(rrs, i)),
ownername
) == 0
) {
/* types match */
ldns_rr_list_push_rr(new, ldns_rr_clone(ldns_rr_list_rr(rrs, i)));
ret = new;
}
}
ldns_rr_list_deep_free(rrs);
if (!ret) {
ldns_rr_list_free(new);
}
return ret;
}
bool
ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr)
{
bool result = false;
switch (sec) {
case LDNS_SECTION_QUESTION:
return ldns_rr_list_contains_rr(ldns_pkt_question(pkt), rr);
case LDNS_SECTION_ANSWER:
return ldns_rr_list_contains_rr(ldns_pkt_answer(pkt), rr);
case LDNS_SECTION_AUTHORITY:
return ldns_rr_list_contains_rr(ldns_pkt_authority(pkt), rr);
case LDNS_SECTION_ADDITIONAL:
return ldns_rr_list_contains_rr(ldns_pkt_additional(pkt), rr);
case LDNS_SECTION_ANY:
result = ldns_rr_list_contains_rr(ldns_pkt_question(pkt), rr);
/* fallthrough */
case LDNS_SECTION_ANY_NOQUESTION:
result = result
|| ldns_rr_list_contains_rr(ldns_pkt_answer(pkt), rr)
|| ldns_rr_list_contains_rr(ldns_pkt_authority(pkt), rr)
|| ldns_rr_list_contains_rr(ldns_pkt_additional(pkt), rr);
}
return result;
}
uint16_t
ldns_pkt_section_count(const ldns_pkt *packet, ldns_pkt_section s)
{
switch(s) {
case LDNS_SECTION_QUESTION:
return ldns_pkt_qdcount(packet);
case LDNS_SECTION_ANSWER:
return ldns_pkt_ancount(packet);
case LDNS_SECTION_AUTHORITY:
return ldns_pkt_nscount(packet);
case LDNS_SECTION_ADDITIONAL:
return ldns_pkt_arcount(packet);
case LDNS_SECTION_ANY:
return ldns_pkt_qdcount(packet) +
ldns_pkt_ancount(packet) +
ldns_pkt_nscount(packet) +
ldns_pkt_arcount(packet);
case LDNS_SECTION_ANY_NOQUESTION:
return ldns_pkt_ancount(packet) +
ldns_pkt_nscount(packet) +
ldns_pkt_arcount(packet);
default:
return 0;
}
}
bool
ldns_pkt_empty(ldns_pkt *p)
{
if (!p) {
return true; /* NULL is empty? */
}
if (ldns_pkt_section_count(p, LDNS_SECTION_ANY) > 0) {
return false;
} else {
return true;
}
}
ldns_rr_list *
ldns_pkt_get_section_clone(const ldns_pkt *packet, ldns_pkt_section s)
{
switch(s) {
case LDNS_SECTION_QUESTION:
return ldns_rr_list_clone(ldns_pkt_question(packet));
case LDNS_SECTION_ANSWER:
return ldns_rr_list_clone(ldns_pkt_answer(packet));
case LDNS_SECTION_AUTHORITY:
return ldns_rr_list_clone(ldns_pkt_authority(packet));
case LDNS_SECTION_ADDITIONAL:
return ldns_rr_list_clone(ldns_pkt_additional(packet));
case LDNS_SECTION_ANY:
/* these are already clones */
return ldns_pkt_all(packet);
case LDNS_SECTION_ANY_NOQUESTION:
return ldns_pkt_all_noquestion(packet);
default:
return NULL;
}
}
ldns_rr *ldns_pkt_tsig(const ldns_pkt *pkt) {
return pkt->_tsig_rr;
}
/* write */
void
ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
{
packet->_header->_id = id;
}
void
ldns_pkt_set_random_id(ldns_pkt *packet)
{
uint16_t rid = ldns_get_random();
ldns_pkt_set_id(packet, rid);
}
void
ldns_pkt_set_qr(ldns_pkt *packet, bool qr)
{
packet->_header->_qr = qr;
}
void
ldns_pkt_set_aa(ldns_pkt *packet, bool aa)
{
packet->_header->_aa = aa;
}
void
ldns_pkt_set_tc(ldns_pkt *packet, bool tc)
{
packet->_header->_tc = tc;
}
void
ldns_pkt_set_rd(ldns_pkt *packet, bool rd)
{
packet->_header->_rd = rd;
}
void
ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rr)
{
p->_additional = rr;
}
void
ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rr)
{
p->_question = rr;
}
void
ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rr)
{
p->_answer = rr;
}
void
ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rr)
{
p->_authority = rr;
}
void
ldns_pkt_set_cd(ldns_pkt *packet, bool cd)
{
packet->_header->_cd = cd;
}
void
ldns_pkt_set_ra(ldns_pkt *packet, bool ra)
{
packet->_header->_ra = ra;
}
void
ldns_pkt_set_ad(ldns_pkt *packet, bool ad)
{
packet->_header->_ad = ad;
}
void
ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
{
packet->_header->_opcode = opcode;
}
void
ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
{
packet->_header->_rcode = rcode;
}
void
ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
{
packet->_header->_qdcount = qdcount;
}
void
ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
{
packet->_header->_ancount = ancount;
}
void
ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
{
packet->_header->_nscount = nscount;
}
void
ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
{
packet->_header->_arcount = arcount;
}
void
ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time)
{
packet->_querytime = time;
}
void
ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *answerfrom)
{
packet->_answerfrom = answerfrom;
}
void
ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
{
packet->timestamp.tv_sec = timeval.tv_sec;
packet->timestamp.tv_usec = timeval.tv_usec;
}
void
ldns_pkt_set_size(ldns_pkt *packet, size_t s)
{
packet->_size = s;
}
void
ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
{
packet->_edns_udp_size = s;
}
void
ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
{
packet->_edns_extended_rcode = c;
}
void
ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
{
packet->_edns_version = v;
}
void
ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
{
packet->_edns_z = z;
}
void
ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
{
packet->_edns_data = data;
}
void
ldns_pkt_set_edns_option_list(ldns_pkt *packet, ldns_edns_option_list *list)
{
if (packet->_edns_list)
ldns_edns_option_list_deep_free(packet->_edns_list);
packet->_edns_list = list;
}
void
ldns_pkt_set_section_count(ldns_pkt *packet, ldns_pkt_section s, uint16_t count)
{
switch(s) {
case LDNS_SECTION_QUESTION:
ldns_pkt_set_qdcount(packet, count);
break;
case LDNS_SECTION_ANSWER:
ldns_pkt_set_ancount(packet, count);
break;
case LDNS_SECTION_AUTHORITY:
ldns_pkt_set_nscount(packet, count);
break;
case LDNS_SECTION_ADDITIONAL:
ldns_pkt_set_arcount(packet, count);
break;
case LDNS_SECTION_ANY:
case LDNS_SECTION_ANY_NOQUESTION:
break;
}
}
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
{
pkt->_tsig_rr = rr;
}
bool
ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr)
{
switch(section) {
case LDNS_SECTION_QUESTION:
if (!ldns_rr_list_push_rr(ldns_pkt_question(packet), rr)) {
return false;
}
ldns_pkt_set_qdcount(packet, ldns_pkt_qdcount(packet) + 1);
break;
case LDNS_SECTION_ANSWER:
if (!ldns_rr_list_push_rr(ldns_pkt_answer(packet), rr)) {
return false;
}
ldns_pkt_set_ancount(packet, ldns_pkt_ancount(packet) + 1);
break;
case LDNS_SECTION_AUTHORITY:
if (!ldns_rr_list_push_rr(ldns_pkt_authority(packet), rr)) {
return false;
}
ldns_pkt_set_nscount(packet, ldns_pkt_nscount(packet) + 1);
break;
case LDNS_SECTION_ADDITIONAL:
if (!ldns_rr_list_push_rr(ldns_pkt_additional(packet), rr)) {
return false;
}
ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet) + 1);
break;
case LDNS_SECTION_ANY:
case LDNS_SECTION_ANY_NOQUESTION:
/* shouldn't this error? */
break;
}
return true;
}
bool
ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr)
{
/* check to see if its there */
if (ldns_pkt_rr(pkt, sec, rr)) {
/* already there */
return false;
}
return ldns_pkt_push_rr(pkt, sec, rr);
}
bool
ldns_pkt_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
{
size_t i;
for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
if (!ldns_pkt_push_rr(p, s, ldns_rr_list_rr(list, i))) {
return false;
}
}
return true;
}
bool
ldns_pkt_safe_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
{
size_t i;
for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
if (!ldns_pkt_safe_push_rr(p, s, ldns_rr_list_rr(list, i))) {
return false;
}
}
return true;
}
bool
ldns_pkt_edns(const ldns_pkt *pkt)
{
return (ldns_pkt_edns_udp_size(pkt) > 0 ||
ldns_pkt_edns_extended_rcode(pkt) > 0 ||
ldns_pkt_edns_data(pkt) ||
ldns_pkt_edns_do(pkt) ||
ldns_pkt_edns_co(pkt) ||
pkt->_edns_list ||
pkt->_edns_present
);
}
ldns_edns_option_list*
pkt_edns_data2edns_option_list(const ldns_rdf *edns_data);
ldns_edns_option_list*
pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
{
size_t pos = 0;
ldns_edns_option_list* edns_list;
size_t max;
const uint8_t* wire;
if (!edns_data)
return NULL;
max = ldns_rdf_size(edns_data);
wire = ldns_rdf_data(edns_data);
if (!max)
return NULL;
if (!(edns_list = ldns_edns_option_list_new()))
return NULL;
while (pos < max) {
ldns_edns_option* edns;
uint8_t *data;
if (pos + 4 > max) { /* make sure the header fits */
ldns_edns_option_list_deep_free(edns_list);
return NULL;
}
ldns_edns_option_code code = ldns_read_uint16(&wire[pos]);
size_t size = ldns_read_uint16(&wire[pos+2]);
pos += 4;
if (pos + size > max) { /* make sure the size fits the data */
ldns_edns_option_list_deep_free(edns_list);
return NULL;
}
data = LDNS_XMALLOC(uint8_t, size);
if (!data) {
ldns_edns_option_list_deep_free(edns_list);
return NULL;
}
memcpy(data, &wire[pos], size);
pos += size;
edns = ldns_edns_new(code, size, data);
if (!edns) {
ldns_edns_option_list_deep_free(edns_list);
return NULL;
}
if (!ldns_edns_option_list_push(edns_list, edns)) {
ldns_edns_option_list_deep_free(edns_list);
return NULL;
}
}
return edns_list;
}
ldns_edns_option_list*
ldns_pkt_edns_get_option_list(ldns_pkt *packet)
{
/* return the list if it already exists */
if (packet->_edns_list != NULL)
return packet->_edns_list;
/* if the list doesn't exists, we create it by parsing the
* packet->_edns_data
*/
if (!ldns_pkt_edns_data(packet))
return NULL;
return ( packet->_edns_list
= pkt_edns_data2edns_option_list(ldns_pkt_edns_data(packet)));
}
/* Create/destroy/convert functions
*/
ldns_pkt *
ldns_pkt_new(void)
{
ldns_pkt *packet;
packet = LDNS_MALLOC(ldns_pkt);
if (!packet) {
return NULL;
}
packet->_header = LDNS_MALLOC(ldns_hdr);
if (!packet->_header) {
LDNS_FREE(packet);
return NULL;
}
packet->_question = ldns_rr_list_new();
packet->_answer = ldns_rr_list_new();
packet->_authority = ldns_rr_list_new();
packet->_additional = ldns_rr_list_new();
/* default everything to false */
ldns_pkt_set_qr(packet, false);
ldns_pkt_set_aa(packet, false);
ldns_pkt_set_tc(packet, false);
ldns_pkt_set_rd(packet, false);
ldns_pkt_set_ra(packet, false);
ldns_pkt_set_ad(packet, false);
ldns_pkt_set_cd(packet, false);
ldns_pkt_set_opcode(packet, LDNS_PACKET_QUERY);
ldns_pkt_set_rcode(packet, 0);
ldns_pkt_set_id(packet, 0);
ldns_pkt_set_size(packet, 0);
ldns_pkt_set_querytime(packet, 0);
memset(&packet->timestamp, 0, sizeof(packet->timestamp));
ldns_pkt_set_answerfrom(packet, NULL);
ldns_pkt_set_section_count(packet, LDNS_SECTION_QUESTION, 0);
ldns_pkt_set_section_count(packet, LDNS_SECTION_ANSWER, 0);
ldns_pkt_set_section_count(packet, LDNS_SECTION_AUTHORITY, 0);
ldns_pkt_set_section_count(packet, LDNS_SECTION_ADDITIONAL, 0);
ldns_pkt_set_edns_udp_size(packet, 0);
ldns_pkt_set_edns_extended_rcode(packet, 0);
ldns_pkt_set_edns_version(packet, 0);
ldns_pkt_set_edns_z(packet, 0);
ldns_pkt_set_edns_data(packet, NULL);
packet->_edns_list = NULL;
packet->_edns_present = false;
ldns_pkt_set_tsig(packet, NULL);
return packet;
}
void
ldns_pkt_free(ldns_pkt *packet)
{
if (packet) {
LDNS_FREE(packet->_header);
ldns_rr_list_deep_free(packet->_question);
ldns_rr_list_deep_free(packet->_answer);
ldns_rr_list_deep_free(packet->_authority);
ldns_rr_list_deep_free(packet->_additional);
ldns_rr_free(packet->_tsig_rr);
ldns_rdf_deep_free(packet->_edns_data);
ldns_edns_option_list_deep_free(packet->_edns_list);
ldns_rdf_deep_free(packet->_answerfrom);
LDNS_FREE(packet);
}
}
bool
ldns_pkt_set_flags(ldns_pkt *packet, uint16_t flags)
{
if (!packet) {
return false;
}
if ((flags & LDNS_QR) == LDNS_QR) {
ldns_pkt_set_qr(packet, true);
}
if ((flags & LDNS_AA) == LDNS_AA) {
ldns_pkt_set_aa(packet, true);
}
if ((flags & LDNS_RD) == LDNS_RD) {
ldns_pkt_set_rd(packet, true);
}
if ((flags & LDNS_TC) == LDNS_TC) {
ldns_pkt_set_tc(packet, true);
}
if ((flags & LDNS_CD) == LDNS_CD) {
ldns_pkt_set_cd(packet, true);
}
if ((flags & LDNS_RA) == LDNS_RA) {
ldns_pkt_set_ra(packet, true);
}
if ((flags & LDNS_AD) == LDNS_AD) {
ldns_pkt_set_ad(packet, true);
}
return true;
}
static ldns_rr*
ldns_pkt_authsoa(const ldns_rdf* rr_name, ldns_rr_class rr_class)
{
ldns_rr* soa_rr = ldns_rr_new();
ldns_rdf *owner_rdf;
ldns_rdf *mname_rdf;
ldns_rdf *rname_rdf;
ldns_rdf *serial_rdf;
ldns_rdf *refresh_rdf;
ldns_rdf *retry_rdf;
ldns_rdf *expire_rdf;
ldns_rdf *minimum_rdf;
if (!soa_rr) {
return NULL;
}
owner_rdf = ldns_rdf_clone(rr_name);
if (!owner_rdf) {
ldns_rr_free(soa_rr);
return NULL;
}
ldns_rr_set_owner(soa_rr, owner_rdf);
ldns_rr_set_type(soa_rr, LDNS_RR_TYPE_SOA);
ldns_rr_set_class(soa_rr, rr_class);
ldns_rr_set_question(soa_rr, false);
if (ldns_str2rdf_dname(&mname_rdf, ".") != LDNS_STATUS_OK) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, mname_rdf);
}
if (ldns_str2rdf_dname(&rname_rdf, ".") != LDNS_STATUS_OK) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, rname_rdf);
}
serial_rdf = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, 0);
if (!serial_rdf) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, serial_rdf);
}
refresh_rdf = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, 0);
if (!refresh_rdf) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, refresh_rdf);
}
retry_rdf = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, 0);
if (!retry_rdf) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, retry_rdf);
}
expire_rdf = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, 0);
if (!expire_rdf) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, expire_rdf);
}
minimum_rdf = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, 0);
if (!minimum_rdf) {
ldns_rr_free(soa_rr);
return NULL;
} else {
ldns_rr_push_rdf(soa_rr, minimum_rdf);
}
return soa_rr;
}
static ldns_status
ldns_pkt_query_new_frm_str_internal(ldns_pkt **p, const char *name,
ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags,
ldns_rr* authsoa_rr)
{
ldns_pkt *packet;
ldns_rr *question_rr;
ldns_rdf *name_rdf;
packet = ldns_pkt_new();
if (!packet) {
return LDNS_STATUS_MEM_ERR;
}
if (!ldns_pkt_set_flags(packet, flags)) {
ldns_pkt_free(packet);
return LDNS_STATUS_ERR;
}
question_rr = ldns_rr_new();
if (!question_rr) {
ldns_pkt_free(packet);
return LDNS_STATUS_MEM_ERR;
}
if (rr_type == 0) {
rr_type = LDNS_RR_TYPE_A;
}
if (rr_class == 0) {
rr_class = LDNS_RR_CLASS_IN;
}
if (ldns_str2rdf_dname(&name_rdf, name) == LDNS_STATUS_OK) {
ldns_rr_set_owner(question_rr, name_rdf);
ldns_rr_set_type(question_rr, rr_type);
ldns_rr_set_class(question_rr, rr_class);
ldns_rr_set_question(question_rr, true);
ldns_pkt_push_rr(packet, LDNS_SECTION_QUESTION, question_rr);
} else {
ldns_rr_free(question_rr);
ldns_pkt_free(packet);
return LDNS_STATUS_ERR;
}
if (authsoa_rr) {
ldns_pkt_push_rr(packet, LDNS_SECTION_AUTHORITY, authsoa_rr);
}
packet->_tsig_rr = NULL;
ldns_pkt_set_answerfrom(packet, NULL);
if (p) {
*p = packet;
return LDNS_STATUS_OK;
} else {
ldns_pkt_free(packet);
return LDNS_STATUS_NULL;
}
}
ldns_status
ldns_pkt_query_new_frm_str(ldns_pkt **p, const char *name,
ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
{
return ldns_pkt_query_new_frm_str_internal(p, name, rr_type,
rr_class, flags, NULL);
}
ldns_status
ldns_pkt_ixfr_request_new_frm_str(ldns_pkt **p, const char *name,
ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
{
ldns_rr* authsoa_rr = soa;
if (!authsoa_rr) {
ldns_rdf *name_rdf;
if (ldns_str2rdf_dname(&name_rdf, name) == LDNS_STATUS_OK) {
authsoa_rr = ldns_pkt_authsoa(name_rdf, rr_class);
}
ldns_rdf_free(name_rdf);
}
return ldns_pkt_query_new_frm_str_internal(p, name, LDNS_RR_TYPE_IXFR,
rr_class, flags, authsoa_rr);
}
static ldns_pkt *
ldns_pkt_query_new_internal(ldns_rdf *rr_name, ldns_rr_type rr_type,
ldns_rr_class rr_class, uint16_t flags, ldns_rr* authsoa_rr)
{
ldns_pkt *packet;
ldns_rr *question_rr;
packet = ldns_pkt_new();
if (!packet) {
return NULL;
}
if (!ldns_pkt_set_flags(packet, flags)) {
return NULL;
}
question_rr = ldns_rr_new();
if (!question_rr) {
ldns_pkt_free(packet);
return NULL;
}
if (rr_type == 0) {
rr_type = LDNS_RR_TYPE_A;
}
if (rr_class == 0) {
rr_class = LDNS_RR_CLASS_IN;
}
ldns_rr_set_owner(question_rr, rr_name);
ldns_rr_set_type(question_rr, rr_type);
ldns_rr_set_class(question_rr, rr_class);
ldns_rr_set_question(question_rr, true);
ldns_pkt_push_rr(packet, LDNS_SECTION_QUESTION, question_rr);
if (authsoa_rr) {
ldns_pkt_push_rr(packet, LDNS_SECTION_AUTHORITY, authsoa_rr);
}
packet->_tsig_rr = NULL;
return packet;
}
ldns_pkt *
ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type,
ldns_rr_class rr_class, uint16_t flags)
{
return ldns_pkt_query_new_internal(rr_name, rr_type,
rr_class, flags, NULL);
}
ldns_pkt *
ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class,
uint16_t flags, ldns_rr* soa)
{
ldns_rr* authsoa_rr = soa;
if (!authsoa_rr) {
authsoa_rr = ldns_pkt_authsoa(rr_name, rr_class);
}
return ldns_pkt_query_new_internal(rr_name, LDNS_RR_TYPE_IXFR,
rr_class, flags, authsoa_rr);
}
ldns_pkt_type
ldns_pkt_reply_type(const ldns_pkt *p)
{
ldns_rr_list *tmp;
if (!p) {
return LDNS_PACKET_UNKNOWN;
}
if (ldns_pkt_get_rcode(p) == LDNS_RCODE_NXDOMAIN) {
return LDNS_PACKET_NXDOMAIN;
}
if (ldns_pkt_ancount(p) == 0 && ldns_pkt_arcount(p) == 0
&& ldns_pkt_nscount(p) == 1) {
/* check for SOA */
tmp = ldns_pkt_rr_list_by_type(p, LDNS_RR_TYPE_SOA,
LDNS_SECTION_AUTHORITY);
if (tmp) {
ldns_rr_list_deep_free(tmp);
return LDNS_PACKET_NODATA;
} else {
/* I have no idea ... */
}
}
if (ldns_pkt_ancount(p) == 0 && ldns_pkt_nscount(p) > 0) {
tmp = ldns_pkt_rr_list_by_type(p, LDNS_RR_TYPE_NS,
LDNS_SECTION_AUTHORITY);
if (tmp) {
/* there are nameservers here */
ldns_rr_list_deep_free(tmp);
return LDNS_PACKET_REFERRAL;
} else {
/* I have no idea */
}
ldns_rr_list_deep_free(tmp);
}
/* if we cannot determine the packet type, we say it's an
* answer...
*/
return LDNS_PACKET_ANSWER;
}
ldns_pkt *
ldns_pkt_clone(const ldns_pkt *pkt)
{
ldns_pkt *new_pkt;
if (!pkt) {
return NULL;
}
new_pkt = ldns_pkt_new();
ldns_pkt_set_id(new_pkt, ldns_pkt_id(pkt));
ldns_pkt_set_qr(new_pkt, ldns_pkt_qr(pkt));
ldns_pkt_set_aa(new_pkt, ldns_pkt_aa(pkt));
ldns_pkt_set_tc(new_pkt, ldns_pkt_tc(pkt));
ldns_pkt_set_rd(new_pkt, ldns_pkt_rd(pkt));
ldns_pkt_set_cd(new_pkt, ldns_pkt_cd(pkt));
ldns_pkt_set_ra(new_pkt, ldns_pkt_ra(pkt));
ldns_pkt_set_ad(new_pkt, ldns_pkt_ad(pkt));
ldns_pkt_set_opcode(new_pkt, ldns_pkt_get_opcode(pkt));
ldns_pkt_set_rcode(new_pkt, ldns_pkt_get_rcode(pkt));
ldns_pkt_set_qdcount(new_pkt, ldns_pkt_qdcount(pkt));
ldns_pkt_set_ancount(new_pkt, ldns_pkt_ancount(pkt));
ldns_pkt_set_nscount(new_pkt, ldns_pkt_nscount(pkt));
ldns_pkt_set_arcount(new_pkt, ldns_pkt_arcount(pkt));
if (ldns_pkt_answerfrom(pkt))
ldns_pkt_set_answerfrom(new_pkt,
ldns_rdf_clone(ldns_pkt_answerfrom(pkt)));
ldns_pkt_set_timestamp(new_pkt, ldns_pkt_timestamp(pkt));
ldns_pkt_set_querytime(new_pkt, ldns_pkt_querytime(pkt));
ldns_pkt_set_size(new_pkt, ldns_pkt_size(pkt));
ldns_pkt_set_tsig(new_pkt, ldns_rr_clone(ldns_pkt_tsig(pkt)));
ldns_pkt_set_edns_udp_size(new_pkt, ldns_pkt_edns_udp_size(pkt));
ldns_pkt_set_edns_extended_rcode(new_pkt,
ldns_pkt_edns_extended_rcode(pkt));
ldns_pkt_set_edns_version(new_pkt, ldns_pkt_edns_version(pkt));
new_pkt->_edns_present = pkt->_edns_present;
ldns_pkt_set_edns_z(new_pkt, ldns_pkt_edns_z(pkt));
if(ldns_pkt_edns_data(pkt))
ldns_pkt_set_edns_data(new_pkt,
ldns_rdf_clone(ldns_pkt_edns_data(pkt)));
ldns_pkt_set_edns_do(new_pkt, ldns_pkt_edns_do(pkt));
ldns_pkt_set_edns_co(new_pkt, ldns_pkt_edns_co(pkt));
if (pkt->_edns_list)
ldns_pkt_set_edns_option_list(new_pkt,
ldns_edns_option_list_clone(pkt->_edns_list));
ldns_rr_list_deep_free(new_pkt->_question);
ldns_rr_list_deep_free(new_pkt->_answer);
ldns_rr_list_deep_free(new_pkt->_authority);
ldns_rr_list_deep_free(new_pkt->_additional);
new_pkt->_question = ldns_rr_list_clone(ldns_pkt_question(pkt));
new_pkt->_answer = ldns_rr_list_clone(ldns_pkt_answer(pkt));
new_pkt->_authority = ldns_rr_list_clone(ldns_pkt_authority(pkt));
new_pkt->_additional = ldns_rr_list_clone(ldns_pkt_additional(pkt));
return new_pkt;
}
config.h
ldns_dname_compare
int ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2)
Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6.
Definition dname.c:359
ldns_edns_option_code
enum ldns_enum_edns_option ldns_edns_option_code
Definition edns.h:46
ldns_edns_new
ldns_edns_option * ldns_edns_new(ldns_edns_option_code code, size_t size, void *data)
allocates a new EDNS structure and fills it.
Definition edns.c:139
ldns_edns_option_list
struct ldns_struct_edns_option_list ldns_edns_option_list
Definition edns.h:119
ldns_edns_option_list_new
ldns_edns_option_list * ldns_edns_option_list_new(void)
allocates space for a new list of EDNS options
Definition edns.c:209
ldns_edns_option_list_push
signed char ldns_edns_option_list_push(ldns_edns_option_list *options_list, ldns_edns_option *option)
adds an EDNS option at the end of the list of options.
Definition edns.c:338
ldns_edns_option_list_clone
ldns_edns_option_list * ldns_edns_option_list_clone(ldns_edns_option_list *options_list)
clone the EDNS options list and it's contents
Definition edns.c:224
ldns_edns_option_list_deep_free
void ldns_edns_option_list_deep_free(ldns_edns_option_list *options_list)
Definition edns.c:264
ldns_edns_option
struct ldns_struct_edns_option ldns_edns_option
Definition edns.h:106
LDNS_STATUS_NULL
@ LDNS_STATUS_NULL
Definition error.h:51
LDNS_STATUS_ERR
@ LDNS_STATUS_ERR
Definition error.h:37
LDNS_STATUS_MEM_ERR
@ LDNS_STATUS_MEM_ERR
Definition error.h:34
LDNS_STATUS_OK
@ LDNS_STATUS_OK
Definition error.h:26
ldns_status
enum ldns_enum_status ldns_status
Definition error.h:152
pkt_edns_data2edns_option_list
ldns_edns_option_list * pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
Definition packet.c:784
ldns_edns_flags
ldns_lookup_table ldns_edns_flags[]
EDNS flags.
Definition packet.c:36
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_edns_version
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet's edns version
Definition packet.c:222
ldns_pkt_set_ancount
void ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
Set the packet's an count.
Definition packet.c:588
pkt_edns_data2edns_option_list
ldns_edns_option_list * pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
Definition packet.c:784
ldns_pkt_set_rd
void ldns_pkt_set_rd(ldns_pkt *packet, signed char rd)
Set the packet's rd bit.
Definition packet.c:522
ldns_pkt_set_querytime
void ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time)
Set the packet's query time.
Definition packet.c:606
ldns_pkt_set_tsig
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
Set the packet's tsig rr.
Definition packet.c:691
ldns_pkt_push_rr_list
signed char ldns_pkt_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
push a rr_list on a packet
Definition packet.c:745
ldns_pkt_set_tc
void ldns_pkt_set_tc(ldns_pkt *packet, signed char tc)
Set the packet's tc bit.
Definition packet.c:516
ldns_pkt_get_opcode
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *packet)
Read the packet's code.
Definition packet.c:91
ldns_pkt_ixfr_request_new
ldns_pkt * ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, type and class.
Definition packet.c:1178
ldns_pkt_edns
signed char ldns_pkt_edns(const ldns_pkt *pkt)
returns true if this packet needs and EDNS rr to be sent.
Definition packet.c:769
ldns_pkt_safe_push_rr
signed char ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr)
push an rr on a packet, provided the RR is not there.
Definition packet.c:733
ldns_pkt_rr
signed char ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr)
check to see if an rr exist in the packet
Definition packet.c:396
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_set_opcode
void ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
Set the packet's opcode.
Definition packet.c:570
ldns_pkt_set_additional
void ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rr)
directly set the additional section
Definition packet.c:528
ldns_pkt_set_aa
void ldns_pkt_set_aa(ldns_pkt *packet, signed char aa)
Set the packet's aa bit.
Definition packet.c:510
ldns_pkt_question
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
Definition packet.c:127
ldns_pkt_set_random_id
void ldns_pkt_set_random_id(ldns_pkt *packet)
Set the packet's id to a random value.
Definition packet.c:496
ldns_pkt_set_edns_option_list
void ldns_pkt_set_edns_option_list(ldns_pkt *packet, ldns_edns_option_list *list)
Set the packet's structured EDNS data.
Definition packet.c:661
ldns_pkt_answerfrom
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *packet)
Return the packet's answerfrom.
Definition packet.c:198
ldns_pkt_id
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
Definition packet.c:43
ldns_pkt_arcount
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
Definition packet.c:121
ldns_pkt_edns_co
signed char ldns_pkt_edns_co(const ldns_pkt *packet)
return the packet's edns co bit
Definition packet.c:250
LDNS_EDNS_MASK_UNASSIGNED
#define LDNS_EDNS_MASK_UNASSIGNED
Definition packet.c:30
ldns_pkt_timestamp
struct timeval ldns_pkt_timestamp(const ldns_pkt *packet)
Return the packet's timestamp.
Definition packet.c:204
ldns_pkt_set_nscount
void ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
Set the packet's ns count.
Definition packet.c:594
ldns_pkt_all_noquestion
ldns_rr_list * ldns_pkt_all_noquestion(const ldns_pkt *packet)
Return the packet's answer, authority and additional sections concatenated, in a new rr_list clone.
Definition packet.c:171
ldns_pkt_set_authority
void ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rr)
directly set the authority section
Definition packet.c:546
ldns_pkt_set_ra
void ldns_pkt_set_ra(ldns_pkt *packet, signed char ra)
Set the packet's ra bit.
Definition packet.c:558
ldns_pkt_query_new
ldns_pkt * ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a packet with a query in it for the given name, type and class.
Definition packet.c:1170
ldns_pkt_set_timestamp
void ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
Set the packet's timestamp.
Definition packet.c:618
ldns_pkt_tsig
ldns_rr * ldns_pkt_tsig(const ldns_pkt *pkt)
Return the packet's tsig pseudo rr's.
Definition packet.c:484
ldns_pkt_set_cd
void ldns_pkt_set_cd(ldns_pkt *packet, signed char cd)
Set the packet's cd bit.
Definition packet.c:552
ldns_pkt_set_size
void ldns_pkt_set_size(ldns_pkt *packet, size_t s)
Set the packet's size.
Definition packet.c:625
ldns_pkt_aa
signed char ldns_pkt_aa(const ldns_pkt *packet)
Read the packet's aa bit.
Definition packet.c:55
ldns_pkt_rr_list_by_type
ldns_rr_list * ldns_pkt_rr_list_by_type(const ldns_pkt *packet, ldns_rr_type type, ldns_pkt_section sec)
return all the rr with a specific type from a packet.
Definition packet.c:323
ldns_pkt_empty
signed char ldns_pkt_empty(ldns_pkt *p)
check if a packet is empty
Definition packet.c:449
ldns_pkt_edns_get_option_list
ldns_edns_option_list * ldns_pkt_edns_get_option_list(ldns_pkt *packet)
Returns a list of structured EDNS options.
Definition packet.c:843
LDNS_EDNS_MASK_DO_BIT
#define LDNS_EDNS_MASK_DO_BIT
Definition packet.c:28
ldns_pkt_set_flags
signed char ldns_pkt_set_flags(ldns_pkt *packet, uint16_t flags)
sets the flags in a packet.
Definition packet.c:934
ldns_pkt_answer
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
Definition packet.c:133
ldns_pkt_set_edns_co
void ldns_pkt_set_edns_co(ldns_pkt *packet, signed char value)
Set the packet's edns co bit.
Definition packet.c:256
ldns_pkt_edns_unassigned
uint16_t ldns_pkt_edns_unassigned(const ldns_pkt *packet)
return the packet's EDNS header bits that are unassigned.
Definition packet.c:266
ldns_pkt_ancount
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
Definition packet.c:109
ldns_pkt_push_rr
signed char ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr)
push an rr on a packet
Definition packet.c:697
ldns_pkt_set_answer
void ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rr)
directly set the answer section
Definition packet.c:540
LDNS_EDNS_MASK_CO_BIT
#define LDNS_EDNS_MASK_CO_BIT
Definition packet.c:29
ldns_pkt_set_question
void ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rr)
directly set the question section
Definition packet.c:534
ldns_pkt_new
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
Definition packet.c:863
ldns_pkt_additional
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
Definition packet.c:145
ldns_pkt_set_edns_do
void ldns_pkt_set_edns_do(ldns_pkt *packet, signed char value)
Set the packet's edns do bit.
Definition packet.c:240
ldns_pkt_set_qdcount
void ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
Set the packet's qd count.
Definition packet.c:582
ldns_pkt_cd
signed char ldns_pkt_cd(const ldns_pkt *packet)
Read the packet's cd bit.
Definition packet.c:73
ldns_pkt_size
size_t ldns_pkt_size(const ldns_pkt *packet)
Return the packet's size in bytes.
Definition packet.c:186
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_rr_list_by_name
ldns_rr_list * ldns_pkt_rr_list_by_name(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_pkt_section sec)
return all the rr with a specific name from a packet.
Definition packet.c:286
ldns_pkt_qr
signed char ldns_pkt_qr(const ldns_pkt *packet)
Read the packet's qr bit.
Definition packet.c:49
ldns_pkt_querytime
uint32_t ldns_pkt_querytime(const ldns_pkt *packet)
Return the packet's querytime.
Definition packet.c:192
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_ad
void ldns_pkt_set_ad(ldns_pkt *packet, signed char ad)
Set the packet's ad bit.
Definition packet.c:564
ldns_pkt_all
ldns_rr_list * ldns_pkt_all(const ldns_pkt *packet)
Return the packet's question, answer, authority and additional sections concatenated,...
Definition packet.c:152
ldns_pkt_edns_extended_rcode
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet's edns extended rcode
Definition packet.c:216
ldns_pkt_section_count
uint16_t ldns_pkt_section_count(const ldns_pkt *packet, ldns_pkt_section s)
Return the number of RRs in the given section.
Definition packet.c:423
ldns_pkt_set_qr
void ldns_pkt_set_qr(ldns_pkt *packet, signed char qr)
Set the packet's qr bit.
Definition packet.c:504
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_clone
ldns_pkt * ldns_pkt_clone(const ldns_pkt *pkt)
clones the given packet, creating a fully allocated copy
Definition packet.c:1236
ldns_pkt_reply_type
ldns_pkt_type ldns_pkt_reply_type(const ldns_pkt *p)
looks inside the packet to determine what kind of packet it is, AUTH, NXDOMAIN, REFERRAL,...
Definition packet.c:1190
ldns_pkt_tc
signed char ldns_pkt_tc(const ldns_pkt *packet)
Read the packet's tc bit.
Definition packet.c:61
ldns_pkt_rd
signed char ldns_pkt_rd(const ldns_pkt *packet)
Read the packet's rd bit.
Definition packet.c:67
ldns_pkt_nscount
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
Definition packet.c:115
ldns_pkt_edns_do
signed char ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet's edns do bit
Definition packet.c:234
ldns_pkt_safe_push_rr_list
signed char ldns_pkt_safe_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
push an rr_list to a packet, provided the RRs are not already there.
Definition packet.c:757
ldns_pkt_get_section_clone
ldns_rr_list * ldns_pkt_get_section_clone(const ldns_pkt *packet, ldns_pkt_section s)
return all the rr_list's in the packet.
Definition packet.c:463
ldns_pkt_ra
signed char ldns_pkt_ra(const ldns_pkt *packet)
Read the packet's ra bit.
Definition packet.c:79
ldns_pkt_set_id
void ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
Set the packet's id.
Definition packet.c:490
ldns_pkt_qdcount
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
Definition packet.c:103
ldns_pkt_ad
signed char ldns_pkt_ad(const ldns_pkt *packet)
Read the packet's ad bit.
Definition packet.c:85
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_pkt_ixfr_request_new_frm_str
ldns_status ldns_pkt_ixfr_request_new_frm_str(ldns_pkt **p, const char *name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, class.
Definition packet.c:1111
ldns_pkt_set_answerfrom
void ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *answerfrom)
Set the packet's answering server.
Definition packet.c:612
ldns_pkt_set_section_count
void ldns_pkt_set_section_count(ldns_pkt *packet, ldns_pkt_section s, uint16_t count)
Set a packet's section count to x.
Definition packet.c:670
ldns_pkt_query_new_frm_str
ldns_status ldns_pkt_query_new_frm_str(ldns_pkt **p, const char *name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a query packet for the given name, type, class.
Definition packet.c:1103
ldns_pkt_edns_z
uint16_t ldns_pkt_edns_z(const ldns_pkt *packet)
return the packet's edns z value
Definition packet.c:228
ldns_pkt_rr_list_by_name_and_type
ldns_rr_list * ldns_pkt_rr_list_by_name_and_type(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_rr_type type, ldns_pkt_section sec)
return all the rr with a specific type and type from a packet.
Definition packet.c:359
ldns_pkt_authority
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
Definition packet.c:139
ldns_pkt_set_arcount
void ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
Set the packet's arcount.
Definition packet.c:600
ldns_pkt_get_rcode
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's response code.
Definition packet.c:97
ldns_pkt_set_rcode
void ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
Set the packet's response code.
Definition packet.c:576
ldns_pkt_edns_udp_size
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
Definition packet.c:210
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_pkt_set_edns_unassigned
void ldns_pkt_set_edns_unassigned(ldns_pkt *packet, uint16_t value)
Set the packet's EDNS header bits that are unassigned.
Definition packet.c:272
ldns_pkt_type
enum ldns_enum_pkt_type ldns_pkt_type
Definition packet.h:300
ldns_hdr
struct ldns_struct_hdr ldns_hdr
Definition packet.h:224
LDNS_RA
#define LDNS_RA
Definition packet.h:32
LDNS_QR
#define LDNS_QR
Definition packet.h:27
LDNS_CD
#define LDNS_CD
Definition packet.h:31
LDNS_TC
#define LDNS_TC
Definition packet.h:29
ldns_pkt_rcode
enum ldns_enum_pkt_rcode ldns_pkt_rcode
Definition packet.h:69
ldns_pkt
struct ldns_struct_pkt ldns_pkt
Definition packet.h:272
LDNS_PACKET_QUERY
@ LDNS_PACKET_QUERY
Definition packet.h:47
ldns_pkt_opcode
enum ldns_enum_pkt_opcode ldns_pkt_opcode
Definition packet.h:53
ldns_pkt_section
enum ldns_enum_pkt_section ldns_pkt_section
Definition packet.h:287
ldns_pkt_timestamp
struct timeval ldns_pkt_timestamp(const ldns_pkt *p)
Return the packet's timestamp.
Definition packet.c:204
LDNS_AA
#define LDNS_AA
Definition packet.h:28
LDNS_SECTION_ANY
@ LDNS_SECTION_ANY
bogus section, if not interested
Definition packet.h:283
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_SECTION_ANY_NOQUESTION
@ LDNS_SECTION_ANY_NOQUESTION
used to get all non-question rrs from a packet
Definition packet.h:285
LDNS_RD
#define LDNS_RD
Definition packet.h:30
LDNS_RCODE_NXDOMAIN
@ LDNS_RCODE_NXDOMAIN
Definition packet.h:60
LDNS_AD
#define LDNS_AD
Definition packet.h:33
LDNS_PACKET_REFERRAL
@ LDNS_PACKET_REFERRAL
Definition packet.h:294
LDNS_PACKET_UNKNOWN
@ LDNS_PACKET_UNKNOWN
Definition packet.h:298
LDNS_PACKET_NODATA
@ LDNS_PACKET_NODATA
Definition packet.h:297
LDNS_PACKET_NXDOMAIN
@ LDNS_PACKET_NXDOMAIN
Definition packet.h:296
LDNS_PACKET_ANSWER
@ LDNS_PACKET_ANSWER
Definition packet.h:295
ldns_rdf_data
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
Definition rdata.c:38
ldns_rdf_clone
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
Definition rdata.c:222
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_TYPE_INT32
@ LDNS_RDF_TYPE_INT32
32 bits
Definition rdata.h:56
ldns_native2rdf_int32
ldns_rdf * ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value)
returns an rdf that contains the given int32 value.
Definition rdata.c:147
ldns_rdf_size
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
Definition rdata.c:24
ldns_rdf
struct ldns_struct_rdf ldns_rdf
Definition rdata.h:211
ldns_rdf_free
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
Definition rdata.c:241
ldns_rr_list_free
void ldns_rr_list_free(ldns_rr_list *rr_list)
frees an rr_list structure.
Definition rr.c:1009
ldns_rr_list_deep_free
void ldns_rr_list_deep_free(ldns_rr_list *rr_list)
frees an rr_list structure and all rrs contained therein.
Definition rr.c:1018
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_rr_list_new
ldns_rr_list * ldns_rr_list_new(void)
creates a new rr_list structure.
Definition rr.c:998
ldns_rr_new
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
Definition rr.c:30
ldns_rr_list_contains_rr
signed char ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr)
returns true if the given rr is one of the rrs in the list, or if it is equal to one
Definition rr.c:1238
ldns_rr_type
enum ldns_enum_rr_type ldns_rr_type
Definition rr.h:260
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_A
@ LDNS_RR_TYPE_A
a host address
Definition rr.h:80
LDNS_RR_TYPE_IXFR
@ LDNS_RR_TYPE_IXFR
Definition rr.h:220
LDNS_RR_TYPE_SOA
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
Definition rr.h:90
LDNS_RR_TYPE_NS
@ LDNS_RR_TYPE_NS
an authoritative name server
Definition rr.h:82
ldns_rr_list_cat_clone
ldns_rr_list * ldns_rr_list_cat_clone(const ldns_rr_list *left, const ldns_rr_list *right)
concatenates two ldns_rr_lists together, but makes clones of the rr's (instead of pointer copying).
Definition rr.c:1057
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_list_rr_count
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
Definition rr.c:955
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_clone
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
Definition rr.c:1438
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_list
struct ldns_struct_rr_list ldns_rr_list
Definition rr.h:360
ldns_rr_class
enum ldns_enum_rr_class ldns_rr_class
Definition rr.h:61
ldns_rr_list_rr
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
Definition rr.c:988
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_rr_list_clone
ldns_rr_list * ldns_rr_list_clone(const ldns_rr_list *rrlist)
clones an rrlist.
Definition rr.c:1469
ldns_rr_owner
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
Definition rr.c:917
LDNS_RR_CLASS_IN
@ LDNS_RR_CLASS_IN
the Internet
Definition rr.h:47
ldns_str2rdf_dname
ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str)
convert a dname string into wireformat
Definition str2host.c:374
ldns_struct_hdr::_rd
signed char _rd
Recursion desired.
Definition packet.h:204
ldns_struct_hdr::_id
uint16_t _id
Id of a packet.
Definition packet.h:196
ldns_struct_hdr::_opcode
ldns_pkt_opcode _opcode
Query type.
Definition packet.h:212
ldns_struct_hdr::_cd
signed char _cd
Checking disabled.
Definition packet.h:206
ldns_struct_hdr::_ra
signed char _ra
Recursion available.
Definition packet.h:208
ldns_struct_hdr::_ancount
uint16_t _ancount
answer sec
Definition packet.h:218
ldns_struct_hdr::_qr
signed char _qr
Query bit (0=query, 1=answer).
Definition packet.h:198
ldns_struct_hdr::_tc
signed char _tc
Packet truncated.
Definition packet.h:202
ldns_struct_hdr::_ad
signed char _ad
Authentic data.
Definition packet.h:210
ldns_struct_hdr::_qdcount
uint16_t _qdcount
question sec
Definition packet.h:216
ldns_struct_hdr::_arcount
uint16_t _arcount
add sec
Definition packet.h:222
ldns_struct_hdr::_rcode
uint8_t _rcode
Response code.
Definition packet.h:214
ldns_struct_hdr::_nscount
uint16_t _nscount
auth sec
Definition packet.h:220
ldns_struct_hdr::_aa
signed char _aa
Authoritative answer.
Definition packet.h:200
ldns_struct_pkt::timestamp
struct timeval timestamp
Timestamp of the time the packet was sent or created.
Definition packet.h:242
ldns_struct_pkt::_edns_extended_rcode
uint8_t _edns_extended_rcode
EDNS0 Extended rcode.
Definition packet.h:252
ldns_struct_pkt::_authority
ldns_rr_list * _authority
Authority section.
Definition packet.h:268
ldns_struct_pkt::_header
ldns_hdr * _header
Header section.
Definition packet.h:237
ldns_struct_pkt::_querytime
uint32_t _querytime
The duration of the query this packet is an answer to.
Definition packet.h:244
ldns_struct_pkt::_edns_udp_size
uint16_t _edns_udp_size
EDNS0 available buffer size, see RFC2671.
Definition packet.h:250
ldns_struct_pkt::_answerfrom
ldns_rdf * _answerfrom
an rdf (A or AAAA) with the IP address of the server it is from
Definition packet.h:240
ldns_struct_pkt::_edns_present
uint8_t _edns_present
Definition packet.h:256
ldns_struct_pkt::_edns_version
uint8_t _edns_version
EDNS Version.
Definition packet.h:254
ldns_struct_pkt::_size
size_t _size
The size of the wire format of the packet in octets.
Definition packet.h:246
ldns_struct_pkt::_answer
ldns_rr_list * _answer
Answer section.
Definition packet.h:266
ldns_struct_pkt::_edns_data
ldns_rdf * _edns_data
Arbitrary EDNS rdata.
Definition packet.h:260
ldns_struct_pkt::_edns_list
ldns_edns_option_list * _edns_list
Structed EDNS data.
Definition packet.h:262
ldns_struct_pkt::_edns_z
uint16_t _edns_z
Reserved EDNS data bits.
Definition packet.h:258
ldns_struct_pkt::_additional
ldns_rr_list * _additional
Additional section.
Definition packet.h:270
ldns_struct_pkt::_tsig_rr
ldns_rr * _tsig_rr
Optional tsig rr.
Definition packet.h:248
ldns_struct_pkt::_question
ldns_rr_list * _question
Question section.
Definition packet.h:264
LDNS_FREE
#define LDNS_FREE(ptr)
Definition util.h:60
LDNS_MALLOC
#define LDNS_MALLOC(type)
Memory management macros.
Definition util.h:49
LDNS_XMALLOC
#define LDNS_XMALLOC(type, count)
Definition util.h:51
ldns_lookup_table
struct ldns_struct_lookup_table ldns_lookup_table
Definition util.h:182
ldns_get_random
uint16_t ldns_get_random(void)
Get random number.
Definition util.c:417