Commit a3fceff9 authored by Lubos Slovak's avatar Lubos Slovak

Replaced response structure with packet structure

- Compiles, but is not tested at all.

refs #816 @2h
parent 193ba194
......@@ -75,8 +75,6 @@ unittests_dnslib_SOURCES = \
dnslib/tests/dnslib/node_tests.h \
dnslib/tests/dnslib/rdata_tests.c \
dnslib/tests/dnslib/rdata_tests.h \
dnslib/tests/dnslib/response_tests.c \
dnslib/tests/dnslib/response_tests.h \
dnslib/tests/dnslib/rrset_tests.c \
dnslib/tests/dnslib/rrset_tests.h \
dnslib/tests/dnslib/zone_tests.c \
......@@ -148,8 +146,9 @@ libknot_la_SOURCES = \
dnslib/rrset.c \
dnslib/dname.c \
dnslib/node.c \
dnslib/response.c \
dnslib/packet.c \
dnslib/query.c \
dnslib/response2.c \
dnslib/zone.c \
dnslib/zonedb.c \
dnslib/zone-load.c \
......@@ -176,8 +175,9 @@ libknot_la_SOURCES = \
dnslib/tolower.c \
dnslib/zone-dump.h \
dnslib/dname.h \
dnslib/response.h \
dnslib/packet.h \
dnslib/query.h \
dnslib/response2.h \
dnslib/rrset.h \
dnslib/zone-load.h \
dnslib/utils.h \
......
......@@ -20,7 +20,7 @@
#include "dnslib/nsec3.h"
#include "dnslib/wire.h"
#include "dnslib/rdata.h"
#include "dnslib/response.h"
//#include "dnslib/response.h"
#include "dnslib/rrset.h"
#include "dnslib/tolower.h"
#include "dnslib/utils.h"
......
......@@ -7,103 +7,6 @@
#include "dnslib/descriptor.h"
#include "dnslib/wire.h"
/*----------------------------------------------------------------------------*/
/*!
* \brief Default sizes for response structure parts and steps for increasing
* them.
*/
enum {
DEFAULT_ANCOUNT = 6, /*!< Default count of Answer RRSets. */
DEFAULT_NSCOUNT = 8, /*!< Default count of Authority RRSets. */
DEFAULT_ARCOUNT = 28, /*!< Default count of Additional RRSets. */
DEFAULT_ANCOUNT_QUERY = 1, /*!< Default count of Answer RRSets. */
DEFAULT_NSCOUNT_QUERY = 0, /*!< Default count of Authority RRSets. */
DEFAULT_ARCOUNT_QUERY = 1, /*!< Default count of Additional RRSets. */
/*!
* \brief Default count of all domain names in response.
*
* Used for compression table.
*/
DEFAULT_DOMAINS_IN_RESPONSE = 22,
/*! \brief Default count of temporary RRSets stored in response. */
DEFAULT_TMP_RRSETS = 5,
/*! \brief Default count of temporary RRSets stored in query. */
DEFAULT_TMP_RRSETS_QUERY = 2,
STEP_ANCOUNT = 6, /*!< Step for increasing space for Answer RRSets. */
STEP_NSCOUNT = 8, /*!< Step for increasing space for Authority RRSets.*/
STEP_ARCOUNT = 8,/*!< Step for increasing space for Additional RRSets.*/
STEP_DOMAINS = 10, /*!< Step for resizing compression table. */
STEP_TMP_RRSETS = 5 /*!< Step for increasing temorary RRSets count. */
};
/*----------------------------------------------------------------------------*/
#define PREALLOC_RRSETS(count) (count * sizeof(dnslib_rrset_t *))
/*! \brief Sizes for preallocated space in the response structure. */
enum {
/*! \brief Size of the response structure itself. */
PREALLOC_PACKET = sizeof(dnslib_packet_t),
/*! \brief Space for QNAME dname structure. */
PREALLOC_QNAME_DNAME = sizeof(dnslib_dname_t),
/*! \brief Space for QNAME name (maximum domain name size). */
PREALLOC_QNAME_NAME = 256,
/*! \brief Space for QNAME labels (maximum label count). */
PREALLOC_QNAME_LABELS = 127,
/*! \brief Total space for QNAME. */
PREALLOC_QNAME = PREALLOC_QNAME_DNAME
+ PREALLOC_QNAME_NAME
+ PREALLOC_QNAME_LABELS,
/*!
* \brief Space for RR owner wire format.
*
* Temporary buffer, used when putting RRSets to the response.
*/
PREALLOC_RR_OWNER = 256,
// /*! \brief Space for Answer RRSets. */
// PREALLOC_ANSWER = DEFAULT_ANCOUNT * sizeof(dnslib_dname_t *),
// /*! \brief Space for Authority RRSets. */
// PREALLOC_AUTHORITY = DEFAULT_NSCOUNT * sizeof(dnslib_dname_t *),
// /*! \brief Space for Additional RRSets. */
// PREALLOC_ADDITIONAL = DEFAULT_ARCOUNT * sizeof(dnslib_dname_t *),
// /*! \brief Total size for Answer, Authority and Additional RRSets. */
// PREALLOC_RRSETS = PREALLOC_ANSWER
// + PREALLOC_AUTHORITY
// + PREALLOC_ADDITIONAL,
/*! \brief Space for one part of the compression table (domain names).*/
PREALLOC_DOMAINS =
DEFAULT_DOMAINS_IN_RESPONSE * sizeof(dnslib_dname_t *),
/*! \brief Space for other part of the compression table (offsets). */
PREALLOC_OFFSETS =
DEFAULT_DOMAINS_IN_RESPONSE * sizeof(size_t),
PREALLOC_COMPRESSION = PREALLOC_DOMAINS + PREALLOC_OFFSETS,
// /*! \brief Space for temporary RRSets. */
// PREALLOC_TMP_RRSETS =
// DEFAULT_TMP_RRSETS * sizeof(dnslib_rrset_t *),
PREALLOC_QUERY = PREALLOC_PACKET
+ PREALLOC_QNAME
+ PREALLOC_RRSETS(DEFAULT_ANCOUNT_QUERY)
+ PREALLOC_RRSETS(DEFAULT_NSCOUNT_QUERY)
+ PREALLOC_RRSETS(DEFAULT_ARCOUNT_QUERY)
+ PREALLOC_RRSETS(DEFAULT_TMP_RRSETS_QUERY),
/*! \brief Total preallocated size for the response. */
PREALLOC_RESPONSE = PREALLOC_PACKET
+ PREALLOC_QNAME
+ PREALLOC_RR_OWNER
+ PREALLOC_RRSETS(DEFAULT_ANCOUNT)
+ PREALLOC_RRSETS(DEFAULT_NSCOUNT)
+ PREALLOC_RRSETS(DEFAULT_ARCOUNT)
+ PREALLOC_COMPRESSION
+ PREALLOC_RRSETS(DEFAULT_TMP_RRSETS)
};
/*----------------------------------------------------------------------------*/
/* Non-API functions */
/*----------------------------------------------------------------------------*/
......@@ -612,22 +515,6 @@ static int dnslib_packet_parse_rrs(const uint8_t *wire, size_t *pos,
return err;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Frees all temporary RRSets stored in the response structure.
*
* \param resp Response structure to free the temporary RRSets from.
*/
static void dnslib_packet_free_tmp_rrsets(dnslib_packet_t *pkt)
{
for (int i = 0; i < pkt->tmp_rrsets_count; ++i) {
// TODO: this is quite ugly, but better than copying whole
// function (for reallocating rrset array)
dnslib_rrset_deep_free(
&(((dnslib_rrset_t **)(pkt->tmp_rrsets))[i]), 1, 1);
}
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Deallocates all space which was allocated additionally to the
......@@ -803,6 +690,13 @@ int dnslib_packet_is_query(const dnslib_packet_t *packet)
/*----------------------------------------------------------------------------*/
const dnslib_packet_t *dnslib_packet_query(const dnslib_packet_t *packet)
{
return packet->query;
}
/*----------------------------------------------------------------------------*/
short dnslib_packet_answer_rrset_count(const dnslib_packet_t *packet)
{
return packet->an_rrsets;
......@@ -902,6 +796,22 @@ int dnslib_packet_add_tmp_rrset(dnslib_packet_t *packet,
return DNSLIB_EOK;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Frees all temporary RRSets stored in the response structure.
*
* \param resp Response structure to free the temporary RRSets from.
*/
void dnslib_packet_free_tmp_rrsets(dnslib_packet_t *pkt)
{
for (int i = 0; i < pkt->tmp_rrsets_count; ++i) {
// TODO: this is quite ugly, but better than copying whole
// function (for reallocating rrset array)
dnslib_rrset_deep_free(
&(((dnslib_rrset_t **)(pkt->tmp_rrsets))[i]), 1, 1);
}
}
/*----------------------------------------------------------------------------*/
void dnslib_packet_free(dnslib_packet_t **packet)
......
......@@ -18,52 +18,52 @@
#include "dnslib/dname.h"
#include "dnslib/rrset.h"
#include "dnslib/edns.h"
#include "dnslib/response.h"
///*----------------------------------------------------------------------------*/
///*!
// * \brief Structure for holding information needed for compressing domain names.
// *
// * It's a simple table of domain names and their offsets in wire format of the
// * packet.
// *
// * \todo Consider using some better lookup structure, such as skip-list.
// */
//struct dnslib_compressed_dnames {
// const dnslib_dname_t **dnames; /*!< Domain names present in packet. */
// size_t *offsets; /*!< Offsets of domain names in the packet. */
// short count; /*!< Count of items in the previous arrays. */
// short max; /*!< Capacity of the structure (allocated). */
//};
//typedef struct dnslib_compressed_dnames dnslib_compressed_dnames_t;
///*----------------------------------------------------------------------------*/
///*!
// * \brief Structure representing the DNS packet header.
// */
//struct dnslib_header {
// uint16_t id; /*!< ID stored in host byte order. */
// uint8_t flags1; /*!< First octet of header flags. */
// uint8_t flags2; /*!< Second octet of header flags. */
// uint16_t qdcount; /*!< Number of Question RRs, in host byte order. */
// uint16_t ancount; /*!< Number of Answer RRs, in host byte order. */
// uint16_t nscount; /*!< Number of Authority RRs, in host byte order. */
// uint16_t arcount; /*!< Number of Additional RRs, in host byte order. */
//};
//typedef struct dnslib_header dnslib_header_t;
///*!
// * \brief Structure representing one Question entry in the DNS packet.
// */
//struct dnslib_question {
// dnslib_dname_t *qname; /*!< Question domain name. */
// uint16_t qtype; /*!< Question TYPE. */
// uint16_t qclass; /*!< Question CLASS. */
//};
//typedef struct dnslib_question dnslib_question_t;
//#include "dnslib/response.h"
/*----------------------------------------------------------------------------*/
/*!
* \brief Structure for holding information needed for compressing domain names.
*
* It's a simple table of domain names and their offsets in wire format of the
* packet.
*
* \todo Consider using some better lookup structure, such as skip-list.
*/
struct dnslib_compressed_dnames {
const dnslib_dname_t **dnames; /*!< Domain names present in packet. */
size_t *offsets; /*!< Offsets of domain names in the packet. */
short count; /*!< Count of items in the previous arrays. */
short max; /*!< Capacity of the structure (allocated). */
};
typedef struct dnslib_compressed_dnames dnslib_compressed_dnames_t;
/*----------------------------------------------------------------------------*/
/*!
* \brief Structure representing the DNS packet header.
*/
struct dnslib_header {
uint16_t id; /*!< ID stored in host byte order. */
uint8_t flags1; /*!< First octet of header flags. */
uint8_t flags2; /*!< Second octet of header flags. */
uint16_t qdcount; /*!< Number of Question RRs, in host byte order. */
uint16_t ancount; /*!< Number of Answer RRs, in host byte order. */
uint16_t nscount; /*!< Number of Authority RRs, in host byte order. */
uint16_t arcount; /*!< Number of Additional RRs, in host byte order. */
};
typedef struct dnslib_header dnslib_header_t;
/*!
* \brief Structure representing one Question entry in the DNS packet.
*/
struct dnslib_question {
dnslib_dname_t *qname; /*!< Question domain name. */
uint16_t qtype; /*!< Question TYPE. */
uint16_t qclass; /*!< Question CLASS. */
};
typedef struct dnslib_question dnslib_question_t;
enum dnslib_packet_prealloc_type {
DNSLIB_PACKET_PREALLOC_NONE,
......@@ -125,6 +125,103 @@ struct dnslib_packet {
typedef struct dnslib_packet dnslib_packet_t;
/*----------------------------------------------------------------------------*/
/*!
* \brief Default sizes for response structure parts and steps for increasing
* them.
*/
enum {
DEFAULT_ANCOUNT = 6, /*!< Default count of Answer RRSets. */
DEFAULT_NSCOUNT = 8, /*!< Default count of Authority RRSets. */
DEFAULT_ARCOUNT = 28, /*!< Default count of Additional RRSets. */
DEFAULT_ANCOUNT_QUERY = 1, /*!< Default count of Answer RRSets. */
DEFAULT_NSCOUNT_QUERY = 0, /*!< Default count of Authority RRSets. */
DEFAULT_ARCOUNT_QUERY = 1, /*!< Default count of Additional RRSets. */
/*!
* \brief Default count of all domain names in response.
*
* Used for compression table.
*/
DEFAULT_DOMAINS_IN_RESPONSE = 22,
/*! \brief Default count of temporary RRSets stored in response. */
DEFAULT_TMP_RRSETS = 5,
/*! \brief Default count of temporary RRSets stored in query. */
DEFAULT_TMP_RRSETS_QUERY = 2,
STEP_ANCOUNT = 6, /*!< Step for increasing space for Answer RRSets. */
STEP_NSCOUNT = 8, /*!< Step for increasing space for Authority RRSets.*/
STEP_ARCOUNT = 8,/*!< Step for increasing space for Additional RRSets.*/
STEP_DOMAINS = 10, /*!< Step for resizing compression table. */
STEP_TMP_RRSETS = 5 /*!< Step for increasing temorary RRSets count. */
};
/*----------------------------------------------------------------------------*/
#define PREALLOC_RRSETS(count) (count * sizeof(dnslib_rrset_t *))
/*! \brief Sizes for preallocated space in the response structure. */
enum {
/*! \brief Size of the response structure itself. */
PREALLOC_PACKET = sizeof(dnslib_packet_t),
/*! \brief Space for QNAME dname structure. */
PREALLOC_QNAME_DNAME = sizeof(dnslib_dname_t),
/*! \brief Space for QNAME name (maximum domain name size). */
PREALLOC_QNAME_NAME = 256,
/*! \brief Space for QNAME labels (maximum label count). */
PREALLOC_QNAME_LABELS = 127,
/*! \brief Total space for QNAME. */
PREALLOC_QNAME = PREALLOC_QNAME_DNAME
+ PREALLOC_QNAME_NAME
+ PREALLOC_QNAME_LABELS,
/*!
* \brief Space for RR owner wire format.
*
* Temporary buffer, used when putting RRSets to the response.
*/
PREALLOC_RR_OWNER = 256,
// /*! \brief Space for Answer RRSets. */
// PREALLOC_ANSWER = DEFAULT_ANCOUNT * sizeof(dnslib_dname_t *),
// /*! \brief Space for Authority RRSets. */
// PREALLOC_AUTHORITY = DEFAULT_NSCOUNT * sizeof(dnslib_dname_t *),
// /*! \brief Space for Additional RRSets. */
// PREALLOC_ADDITIONAL = DEFAULT_ARCOUNT * sizeof(dnslib_dname_t *),
// /*! \brief Total size for Answer, Authority and Additional RRSets. */
// PREALLOC_RRSETS = PREALLOC_ANSWER
// + PREALLOC_AUTHORITY
// + PREALLOC_ADDITIONAL,
/*! \brief Space for one part of the compression table (domain names).*/
PREALLOC_DOMAINS =
DEFAULT_DOMAINS_IN_RESPONSE * sizeof(dnslib_dname_t *),
/*! \brief Space for other part of the compression table (offsets). */
PREALLOC_OFFSETS =
DEFAULT_DOMAINS_IN_RESPONSE * sizeof(size_t),
PREALLOC_COMPRESSION = PREALLOC_DOMAINS + PREALLOC_OFFSETS,
// /*! \brief Space for temporary RRSets. */
// PREALLOC_TMP_RRSETS =
// DEFAULT_TMP_RRSETS * sizeof(dnslib_rrset_t *),
PREALLOC_QUERY = PREALLOC_PACKET
+ PREALLOC_QNAME
+ PREALLOC_RRSETS(DEFAULT_ANCOUNT_QUERY)
+ PREALLOC_RRSETS(DEFAULT_NSCOUNT_QUERY)
+ PREALLOC_RRSETS(DEFAULT_ARCOUNT_QUERY)
+ PREALLOC_RRSETS(DEFAULT_TMP_RRSETS_QUERY),
/*! \brief Total preallocated size for the response. */
PREALLOC_RESPONSE = PREALLOC_PACKET
+ PREALLOC_QNAME
+ PREALLOC_RR_OWNER
+ PREALLOC_RRSETS(DEFAULT_ANCOUNT)
+ PREALLOC_RRSETS(DEFAULT_NSCOUNT)
+ PREALLOC_RRSETS(DEFAULT_ARCOUNT)
+ PREALLOC_COMPRESSION
+ PREALLOC_RRSETS(DEFAULT_TMP_RRSETS)
};
/*----------------------------------------------------------------------------*/
/*!
* \brief Creates new empty packet structure.
......@@ -189,6 +286,8 @@ uint16_t dnslib_packet_qclass(const dnslib_packet_t *packet);
int dnslib_packet_is_query(const dnslib_packet_t *packet);
const dnslib_packet_t *dnslib_packet_query(const dnslib_packet_t *packet);
/*!
* \brief Returns number of RRSets in Answer section of the packet.
*
......@@ -285,6 +384,8 @@ int dnslib_packet_contains(const dnslib_packet_t *packet,
int dnslib_packet_add_tmp_rrset(dnslib_packet_t *response,
dnslib_rrset_t *tmp_rrset);
void dnslib_packet_free_tmp_rrsets(dnslib_packet_t *pkt);
/*!
* \brief Properly destroys the packet structure.
*
......
......@@ -2,14 +2,14 @@
/*----------------------------------------------------------------------------*/
int dnslib_response_dnssec_requested(const dnslib_packet_t *query)
int dnslib_query_dnssec_requested(const dnslib_packet_t *query)
{
return dnslib_edns_do(&query->opt_rr);
}
/*----------------------------------------------------------------------------*/
int dnslib_response_nsid_requested(const dnslib_packet_t *query)
int dnslib_query_nsid_requested(const dnslib_packet_t *query)
{
return dnslib_edns_has_option(&query->opt_rr, EDNS_OPTION_NSID);
}
......@@ -14,6 +14,12 @@
#include "dnslib/error.h"
#include "dnslib/debug.h"
/*!
* \brief Default maximum DNS response size
*
* This size must be supported by all servers and clients.
*/
static const short DNSLIB_MAX_RESPONSE_SIZE = 512;
/*!
* \brief Default sizes for response structure parts and steps for increasing
......
......@@ -22,13 +22,6 @@
#include "dnslib/rrset.h"
#include "dnslib/edns.h"
/*!
* \brief Default maximum DNS response size
*
* This size must be supported by all servers and clients.
*/
static const short DNSLIB_MAX_RESPONSE_SIZE = 512;
/*----------------------------------------------------------------------------*/
/*!
* \brief Structure for holding information needed for compressing domain names.
......
#include <stdlib.h>
#include "dnslib/response2.h"
#include "dnslib/wire.h"
#include "dnslib/descriptor.h"
#include "dnslib/dnslib-common.h"
#include "dnslib/error.h"
#include "dnslib/debug.h"
#include "dnslib/packet.h"
/*----------------------------------------------------------------------------*/
/*!
......@@ -38,6 +44,8 @@ struct dnslib_compr {
typedef struct dnslib_compr dnslib_compr_t;
static const size_t DNSLIB_RESPONSE_MAX_PTR = 16383;
/*----------------------------------------------------------------------------*/
/* Non-API functions */
/*----------------------------------------------------------------------------*/
......@@ -758,11 +766,27 @@ static int dnslib_response_realloc_rrsets(const dnslib_rrset_t ***rrsets,
return DNSLIB_EOK;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Converts the stored response OPT RR to wire format and adds it to
* the response wire format.
*
* \param resp Response structure.
*/
static void dnslib_response2_edns_to_wire(dnslib_packet_t *resp)
{
resp->size += dnslib_edns_to_wire(&resp->opt_rr,
resp->wireformat + resp->size,
resp->max_size - resp->size);
resp->header.arcount += 1;
}
/*----------------------------------------------------------------------------*/
/* API functions */
/*----------------------------------------------------------------------------*/
int dnslib_response_init_from_query(dnslib_packet_t *response,
int dnslib_response2_init_from_query(dnslib_packet_t *response,
dnslib_packet_t *query)
{
// copy the header from the query
......@@ -799,7 +823,25 @@ int dnslib_response_init_from_query(dnslib_packet_t *response,
/*----------------------------------------------------------------------------*/
int dnslib_response_add_opt(dnslib_packet_t *resp,
void dnslib_response2_clear(dnslib_packet_t *resp, int clear_question)
{
resp->size = (clear_question) ? DNSLIB_WIRE_HEADER_SIZE
: DNSLIB_WIRE_HEADER_SIZE + 4
+ dnslib_dname_size(resp->question.qname);
resp->an_rrsets = 0;
resp->ns_rrsets = 0;
resp->ar_rrsets = 0;
resp->compression.count = 0;
dnslib_packet_free_tmp_rrsets(resp);
resp->tmp_rrsets_count = 0;
resp->header.ancount = 0;
resp->header.nscount = 0;
resp->header.arcount = 0;
}
/*----------------------------------------------------------------------------*/
int dnslib_response2_add_opt(dnslib_packet_t *resp,
const dnslib_opt_rr_t *opt_rr,
int override_max_size)
{
......@@ -823,7 +865,8 @@ int dnslib_response_add_opt(dnslib_packet_t *resp,
// set max size (less is OK)
if (override_max_size) {
return dnslib_response_set_max_size(resp, resp->opt_rr.payload);
return dnslib_response2_set_max_size(resp,
resp->opt_rr.payload);
//resp->max_size = resp->opt_rr.payload;
}
......@@ -832,7 +875,7 @@ int dnslib_response_add_opt(dnslib_packet_t *resp,
/*----------------------------------------------------------------------------*/
int dnslib_response_set_max_size(dnslib_packet_t *resp, int max_size)
int dnslib_response2_set_max_size(dnslib_packet_t *resp, int max_size)
{
if (resp == NULL || max_size <= 0) {
return DNSLIB_EBADARG;
......@@ -858,7 +901,7 @@ int dnslib_response_set_max_size(dnslib_packet_t *resp, int max_size)
/*----------------------------------------------------------------------------*/
int dnslib_response_add_rrset_answer(dnslib_packet_t *response,
int dnslib_response2_add_rrset_answer(dnslib_packet_t *response,
const dnslib_rrset_t *rrset, int tc,
int check_duplicates, int compr_cs)
{
......@@ -903,7 +946,7 @@ int dnslib_response_add_rrset_answer(dnslib_packet_t *response,
/*----------------------------------------------------------------------------*/
int dnslib_response_add_rrset_authority(dnslib_packet_t *response,
int dnslib_response2_add_rrset_authority(dnslib_packet_t *response,
const dnslib_rrset_t *rrset, int tc,
int check_duplicates, int compr_cs)
{
......@@ -921,7 +964,7 @@ int dnslib_response_add_rrset_authority(dnslib_packet_t *response,
}
if (check_duplicates && dnslib_packet_contains(response, rrset,
DNSLIB_RRSET_COMPARE_PTR))) {
DNSLIB_RRSET_COMPARE_PTR)) {
return DNSLIB_EOK;
}
......@@ -944,7 +987,7 @@ int dnslib_response_add_rrset_authority(dnslib_packet_t *response,
/*----------------------------------------------------------------------------*/
int dnslib_response_add_rrset_additional(dnslib_packet_t *response,
int dnslib_response2_add_rrset_additional(dnslib_packet_t *response,
const dnslib_rrset_t *rrset, int tc,
int check_duplicates, int compr_cs)
{
......@@ -955,7 +998,7 @@ int dnslib_response_add_rrset_additional(dnslib_packet_t *response,
// if this is the first additional RRSet, add EDNS OPT RR first
if (response->header.arcount == 0
&& response->opt_rr.version != EDNS_NOT_SUPPORTED) {
dnslib_response_edns_to_wire(response);
dnslib_response2_edns_to_wire(response);
}
if (response->ar_rrsets == response->max_ar_rrsets
......@@ -988,7 +1031,7 @@ int dnslib_response_add_rrset_additional(dnslib_packet_t *response,
/*----------------------------------------------------------------------------*/
void dnslib_response_set_rcode(dnslib_packet_t *response, short rcode)
void dnslib_response2_set_rcode(dnslib_packet_t *response, short rcode)
{
dnslib_wire_flags_set_rcode(&response->header.flags2, rcode);
dnslib_wire_set_rcode(response->wireformat, rcode);
......@@ -996,7 +1039,7 @@ void dnslib_response_set_rcode(dnslib_packet_t *response, short rcode)
/*----------------------------------------------------------------------------*/
void dnslib_response_set_aa(dnslib_packet_t *response)
void dnslib_response2_set_aa(dnslib_packet_t *response)
{
dnslib_wire_flags_set_aa(&response->header.flags1);
dnslib_wire_set_aa(response->wireformat);
......@@ -1004,7 +1047,7 @@ void dnslib_response_set_aa(dnslib_packet_t *response)
/*----------------------------------------------------------------------------*/
void dnslib_response_set_tc(dnslib_packet_t *response)
void dnslib_response2_set_tc(dnslib_packet_t *response)
{
dnslib_wire_flags_set_tc(&response->header.flags1);
dnslib_wire_set_tc(response->wireformat);
......@@ -1012,7 +1055,7 @@ void dnslib_response_set_tc(dnslib_packet_t *response)
/*----------------------------------------------------------------------------*/
int dnslib_response_add_nsid(dnslib_packet_t *response, const uint8_t *data,
int dnslib_response2_add_nsid(dnslib_packet_t *response, const uint8_t *data,
uint16_t length)
{
return dnslib_edns_add_option(&response->opt_rr,
......@@ -1021,7 +1064,7 @@ int dnslib_response_add_nsid(dnslib_packet_t *response, const uint8_t *data,
/*----------------------------------------------------------------------------*/
int dnslib_response_to_wire(dnslib_packet_t *resp,
int dnslib_response2_to_wire(dnslib_packet_t *resp,
uint8_t **resp_wire, size_t *resp_size)
{
if (resp == NULL || resp_wire == NULL || resp_size == NULL
......@@ -1034,7 +1077,7 @@ int dnslib_response_to_wire(dnslib_packet_t *resp,
// if there are no additional RRSets, add EDNS OPT RR
if (resp->header.arcount == 0
&& resp->opt_rr.version != EDNS_NOT_SUPPORTED) {
dnslib_response_edns_to_wire(resp);
dnslib_response2_edns_to_wire(resp);
}
// set ANCOUNT to the packet
......
......@@ -44,9 +44,21 @@ static const short DNSLIB_MAX_RESPONSE_SIZE = 512;
*
* \retval DNSLIB_EOK
*/
int dnslib_response_init_from_query(dnslib_packet_t *response,
int dnslib_response2_init_from_query(dnslib_packet_t *response,
dnslib_packet_t *query);
/*!
* \brief Clears the response structure for reuse.
*
* After call to this function, the response will be in the same state as if
* dnslib_response_new() was called. The maximum wire size is retained.
*
* \param response Response structure to clear.
*
* \todo Replace the use of this function with something else maybe?
*/
void dnslib_response2_clear(dnslib_packet_t *resp, int clear_question);
/*!
* \brief Sets the OPT RR of the response.
*
......@@ -65,7 +77,7 @@ int dnslib_response_init_from_query(dnslib_packet_t *response,
*
* \todo Needs test.
*/
int dnslib_response_add_opt(dnslib_packet_t *resp,
int dnslib_response2_add_opt(dnslib_packet_t *resp,
const dnslib_opt_rr_t *opt_rr,
int override_max_size);
......@@ -91,7 +103,7 @@ int dnslib_response_add_opt(dnslib_packet_t *resp,
*
* \todo Needs test.
*/
int dnslib_response_set_max_size(dnslib_packet_t *resp, int max_size);
int dnslib_response2_set_max_size(dnslib_packet_t *resp, int max_size);
/*!
* \brief Adds a RRSet to the Answer section of the response.
......@@ -109,7 +121,7 @@ int dnslib_response_set_max_size(dnslib_packet_t *resp, int max_size);
* \retval DNSLIB_ENOMEM
* \retval DNSLIB_ESPACE
*/
int dnslib_response_add_rrset_answer(dnslib_packet_t *response,
int dnslib_response2_add_rrset_answer(dnslib_packet_t *response,
const dnslib_rrset_t *rrset, int tc,
int check_duplicates, int compr_cs);
......@@ -129,7 +141,7 @@ int dnslib_response_add_rrset_answer(dnslib_packet_t *response,
* \retval DNSLIB_ENOMEM
* \retval DNSLIB_ESPACE
*/
int dnslib_response_add_rrset_authority(dnslib_packet_t *response,
int dnslib_response2_add_rrset_authority(dnslib_packet_t *response,
const dnslib_rrset_t *rrset, int tc,
int check_duplicates, int compr_cs);
......@@ -149,7 +161,7 @@ int dnslib_response_add_rrset_authority(dnslib_packet_t *response,
* \retval DNSLIB_ENOMEM
* \retval DNSLIB_ESPACE
*/
int dnslib_response_add_rrset_additional(dnslib_packet_t *response,
int dnslib_response2_add_rrset_additional(dnslib_packet_t *response,
const dnslib_rrset_t *rrset, int tc,
int check_duplicates, int compr_cs);
......@@ -159,21 +171,21 @@ int dnslib_response_add_rrset_additional(dnslib_packet_t *response,
* \param response Response to set the RCODE in.
* \param rcode RCODE to set.
*/
void dnslib_response_set_rcode(dnslib_packet_t *response, short rcode);
void dnslib_response2_set_rcode(dnslib_packet_t *response, short rcode);
/*!
* \brief Sets the AA bit of the response to 1.
*
* \param response Response in which the AA bit should be set.
*/
void dnslib_response_set_aa(dnslib_packet_t *response);
void dnslib_response2_set_aa(dnslib_packet_t *response);
/*!
* \brief Sets the TC bit of the response to 1.
*
* \param response Response in which the TC bit should be set.
*/
void dnslib_response_set_tc(dnslib_packet_t *response);
void dnslib_response2_set_tc(dnslib_packet_t *response);
/*!
* \brief Adds NSID option to the response.
......@@ -185,7 +197,7 @@ void dnslib_response_set_tc(dnslib_packet_t *response);
* \retval DNSLIB_EOK
* \retval DNSLIB_ENOMEM
*/
int dnslib_response_add_nsid(dnslib_packet_t *response, const uint8_t *data,
int dnslib_response2_add_nsid(dnslib_packet_t *response, const uint8_t *data,
uint16_t length);
/*!
......@@ -200,8 +212,8 @@ int dnslib_response_add_nsid(dnslib_packet_t *response, const uint8_t *data,
* \retval DNSLIB_EOK
* \retval DNSLIB_EBADARG
*/
int dnslib_response_to_wire(dnslib_packet_t *response,
uint8_t **resp_wire, size_t *resp_size);
int dnslib_response2_to_wire(dnslib_packet_t *response,
uint8_t **resp_wire, size_t *resp_size);