Commit a5738f67 authored by Marek Vavrusa's avatar Marek Vavrusa

pkt: addressed question / question + header ambiguity.

parent bc9db4a3
......@@ -157,7 +157,7 @@ static void pkt_clear_payload(knot_pkt_t *pkt)
/* Keep question. */
pkt->parsed = 0;
pkt->size = knot_pkt_question_size(pkt);
pkt->size = KNOT_WIRE_HEADER_SIZE + knot_pkt_question_size(pkt);
knot_wire_set_ancount(pkt->wire, 0);
knot_wire_set_nscount(pkt->wire, 0);
knot_wire_set_arcount(pkt->wire, 0);
......@@ -213,15 +213,15 @@ int knot_pkt_init_response(knot_pkt_t *pkt, const knot_pkt_t *query)
}
/* Header + question size. */
size_t question_size = knot_pkt_question_size(query);
if (question_size > pkt->max_size) {
dbg_packet("%s: pkt max size < HEADER size\n", __func__);
size_t base_size = KNOT_WIRE_HEADER_SIZE + knot_pkt_question_size(query);
if (base_size > pkt->max_size) {
dbg_packet("%s: can't fit HEADER + QUESTION\n", __func__);
return KNOT_ESPACE;
}
pkt->query = query;
pkt->size = question_size;
pkt->size = base_size;
pkt->qname_size = query->qname_size;
memcpy(pkt->wire, query->wire, question_size);
memcpy(pkt->wire, query->wire, base_size);
/* Update size and flags. */
knot_wire_set_qr(pkt->wire);
......@@ -312,15 +312,11 @@ uint16_t knot_pkt_type(const knot_pkt_t *pkt)
uint16_t knot_pkt_question_size(const knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL) {
if (pkt == NULL || pkt->qname_size == 0) {
return 0;
}
uint16_t ret = KNOT_WIRE_HEADER_SIZE;
if (pkt->qname_size > 0) {
ret += pkt->qname_size + 2 * sizeof(uint16_t);
}
return ret;
return pkt->qname_size + 2 * sizeof(uint16_t);
}
/*----------------------------------------------------------------------------*/
......
......@@ -262,7 +262,9 @@ const knot_pktsection_t *knot_pkt_section(const knot_pkt_t *pkt, knot_section_t
*/
int knot_pkt_parse(knot_pkt_t *pkt, unsigned flags);
/*! \brief Parse packet QUESTION only. */
/*!
* \brief Parse packet header and a QUESTION section.
*/
int knot_pkt_parse_question(knot_pkt_t *pkt);
/*!
......
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