Commit bb12d8d9 authored by Lubos Slovak's avatar Lubos Slovak

Minor fixes.

refs #109
parent 15d98ce2
......@@ -37,6 +37,11 @@
#define KNOT_DNAME_MAXLEN 255 /*!< 1-byte maximum. */
#define KNOT_DNAME_MAXLABELS 127 /*!< 1-char labels. */
/*!
* \brief Often used sizes.
*/
#define KNOT_RR_HEADER_SIZE 10
/*!
* \brief DNS operation codes (OPCODEs).
*
......
......@@ -112,53 +112,13 @@ static int knot_packet_parse_rdata(knot_rrset_t *rr, const uint8_t *wire,
return ret;
}
// uint8_t* rd = knot_rrset_create_rdata(rr, rdlength);
// if (!rd) {
// return KNOT_ERROR;
// }
// uint8_t* np = rd + rdlength;
// const rdata_descriptor_t *desc = get_rdata_descriptor(knot_rrset_type(rr));
// if (!desc) {
// /*! \todo Free rdata mem ? Not essential, but nice. */
// return KNOT_EINVAL;
// }
// for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) {
// const int id = desc->block_types[i];
// if (descriptor_item_is_dname(id)) {
// knot_dname_t *dn = NULL;
// dn = knot_dname_parse_from_wire(wire, pos, total_size, NULL, NULL);
// if (dn == NULL) {
// return KNOT_EMALF;
// }
// /* Store ptr in rdata. */
// *((knot_dname_t**)rd) = dn;
// rd += sizeof(knot_dname_t*);
// } else if (descriptor_item_is_fixed(id)) {
// memcpy(rd, wire + *pos, id);
// rd += id; /* Item represents fixed len here */
// *pos += id;
// } else if (descriptor_item_is_remainder(id)) {
// size_t rchunk = np - rd;
// memcpy(rd, wire + *pos, rchunk);
// rd += rchunk;
// *pos += rchunk;
// } else {
// //NAPTR
// assert(knot_rrset_type(rr) == KNOT_RRTYPE_NAPTR);
// assert(0);
// }
// }
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
static knot_rrset_t *knot_packet_parse_rr(const uint8_t *wire, size_t *pos,
size_t size)
size_t size)
{
dbg_packet("Parsing RR from position: %zu, total size: %zu\n",
*pos, size);
......@@ -177,8 +137,7 @@ dbg_packet_exec_verb(
free(name);
);
/*! @todo Get rid of the numerical constant. */
if (size - *pos < 10) {
if (size - *pos < KNOT_RR_HEADER_SIZE) {
dbg_packet("Malformed RR: Not enough data to parse RR"
" header.\n");
knot_dname_free(&owner);
......@@ -203,7 +162,7 @@ dbg_packet_exec_verb(
"rdlength %u\n", rrset->type, rrset->rclass,
rrset->ttl, rdlength);
*pos += 10;
*pos += KNOT_RR_HEADER_SIZE;
if (size - *pos < rdlength) {
dbg_packet("Malformed RR: Not enough data to parse RR"
......@@ -510,8 +469,8 @@ knot_packet_t *knot_packet_new_mm(mm_ctx_t *mm)
/*----------------------------------------------------------------------------*/
int knot_packet_parse_from_wire(knot_packet_t *packet,
const uint8_t *wireformat, size_t size,
int question_only, knot_packet_flag_t flags)
const uint8_t *wireformat, size_t size,
int question_only, knot_packet_flag_t flags)
{
if (packet == NULL || wireformat == NULL || size < KNOT_WIRE_HEADER_SIZE)
return KNOT_EINVAL;
......@@ -542,7 +501,6 @@ dbg_packet_exec_detail(
return KNOT_EOK;
}
/*! \todo Replace by call to parse_rest()? */
err = knot_packet_parse_rest(packet, flags);
dbg_packet_exec_detail(
......
......@@ -341,9 +341,7 @@ static int knot_rrset_rdata_to_wire_one(const knot_rrset_t *rrset,
for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) {
int item = desc->block_types[i];
if (compr && descriptor_item_is_compr_dname(item)) {
knot_dname_t *dname;
memcpy(&dname, rdata + offset, sizeof(knot_dname_t *));
assert(dname);
const knot_dname_t *dname = rdata + offset;
int ret = knot_response_compress_dname(dname,
compr, *pos,
max_size - size - rdlength);
......@@ -359,12 +357,10 @@ dbg_response_exec_detail(
);
*pos += ret;
rdlength += ret;
offset += sizeof(knot_dname_t *);
offset += knot_dname_size(dname);
compr->wire_pos += ret;
} else if (descriptor_item_is_dname(item)) {
const knot_dname_t *dname = rdata + offset;
// memcpy(&dname, rdata + offset, sizeof(knot_dname_t *));
// assert(dname);
dbg_rrset_exec_detail(
char *name = knot_dname_to_str(dname);
dbg_rrset_detail("Saving this DNAME=%s\n", name);
......@@ -422,7 +418,7 @@ dbg_rrset_exec_detail(
assert(rrset->type == KNOT_RRTYPE_NAPTR);
/* Store the binary chunk. */
uint16_t chunk_size =
rrset_rdata_naptr_bin_chunk_size(rrset, rdata_pos);
rrset_rdata_naptr_bin_chunk_size(rrset, rdata_pos);
if (size + rdlength + chunk_size > max_size) {
dbg_rrset("rr: to_wire: NAPTR chunk does not "
"fit to wire.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment