Skip to content
Snippets Groups Projects
Commit 138618f3 authored by Lubos Slovak's avatar Lubos Slovak
Browse files

ext-rcode: Review fixes

parent 87ae0d84
Branches
Tags
2 merge requests!330Knsupdate pubkey processing fix,!299Fixed (Extended) RCODE handling
...@@ -119,8 +119,8 @@ static bool dname_cname_cannot_synth(const knot_rrset_t *rrset, const knot_dname ...@@ -119,8 +119,8 @@ static bool dname_cname_cannot_synth(const knot_rrset_t *rrset, const knot_dname
/*! \brief DNSSEC both requested & available. */ /*! \brief DNSSEC both requested & available. */
static bool have_dnssec(struct query_data *qdata) static bool have_dnssec(struct query_data *qdata)
{ {
assert(qdata->rcode == KNOT_RCODE_NOERROR);
return knot_pkt_has_dnssec(qdata->query) && return knot_pkt_has_dnssec(qdata->query) &&
qdata->rcode != KNOT_RCODE_BADVERS &&
zone_contents_is_signed(qdata->zone->contents); zone_contents_is_signed(qdata->zone->contents);
} }
......
...@@ -267,8 +267,8 @@ static int answer_edns_put(knot_pkt_t *resp, struct query_data *qdata) ...@@ -267,8 +267,8 @@ static int answer_edns_put(knot_pkt_t *resp, struct query_data *qdata)
assert(resp->current == KNOT_ADDITIONAL); assert(resp->current == KNOT_ADDITIONAL);
ret = knot_pkt_put(resp, KNOT_COMPR_HINT_NONE, &qdata->opt_rr, 0); ret = knot_pkt_put(resp, KNOT_COMPR_HINT_NONE, &qdata->opt_rr, 0);
if (ret == KNOT_EOK) { if (ret == KNOT_EOK) {
/* Save position of the Ext RCODE field. */ /* Save position of the OPT RR. */
qdata->ext_rcode = wire_end + KNOT_EDNS_EXT_RCODE_POS; qdata->opt_rr_pos = wire_end;
} }
return ret; return ret;
...@@ -337,13 +337,13 @@ static int set_rcode_to_packet(knot_pkt_t *pkt, struct query_data *qdata) ...@@ -337,13 +337,13 @@ static int set_rcode_to_packet(knot_pkt_t *pkt, struct query_data *qdata)
if (ext_rcode != 0) { if (ext_rcode != 0) {
/* If there is no OPT RR and Ext RCODE is set, result in /* If there is no OPT RR and Ext RCODE is set, result in
* SERVFAIL. This should not happen! * SERVFAIL. This may happen if adding OPT failed.
*/ */
if (qdata->ext_rcode == NULL) { if (qdata->opt_rr_pos == NULL) {
qdata->rcode = KNOT_RCODE_SERVFAIL; qdata->rcode = KNOT_RCODE_SERVFAIL;
ret = KNOT_ERROR; ret = KNOT_ERROR;
} else { } else {
*qdata->ext_rcode = ext_rcode; knot_edns_set_ext_rcode_wire(qdata->opt_rr_pos, ext_rcode);
} }
} }
...@@ -373,14 +373,12 @@ static int process_query_err(knot_layer_t *ctx, knot_pkt_t *pkt) ...@@ -373,14 +373,12 @@ static int process_query_err(knot_layer_t *ctx, knot_pkt_t *pkt)
} }
/* Put OPT RR to the additional section. */ /* Put OPT RR to the additional section. */
int ret = answer_edns_reserve(pkt, qdata); ret = answer_edns_reserve(pkt, qdata);
ret = ret || answer_edns_put(pkt, qdata); if (ret == KNOT_EOK) {
(void) answer_edns_put(pkt, qdata);
if (ret != KNOT_EOK) {
qdata->rcode = KNOT_RCODE_SERVFAIL;
} }
/* Set final RCODE to packet. */ /* Set final RCODE to packet. If the above failed, SERVFAIL will be set. */
(void) set_rcode_to_packet(pkt, qdata); (void) set_rcode_to_packet(pkt, qdata);
/* Transaction security (if applicable). */ /* Transaction security (if applicable). */
......
...@@ -69,7 +69,6 @@ struct process_query_param { ...@@ -69,7 +69,6 @@ struct process_query_param {
/*! \brief Query processing intermediate data. */ /*! \brief Query processing intermediate data. */
struct query_data { struct query_data {
uint16_t rcode; /*!< Resulting RCODE (Whole extended RCODE). */ uint16_t rcode; /*!< Resulting RCODE (Whole extended RCODE). */
uint8_t *ext_rcode; /*!< Place of the Ext RCODE field of OPT RR in wire. */
uint16_t rcode_tsig; /*!< Resulting TSIG RCODE. */ uint16_t rcode_tsig; /*!< Resulting TSIG RCODE. */
uint16_t packet_type; /*!< Resolved packet type. */ uint16_t packet_type; /*!< Resolved packet type. */
knot_pkt_t *query; /*!< Query to be solved. */ knot_pkt_t *query; /*!< Query to be solved. */
...@@ -86,6 +85,7 @@ struct query_data { ...@@ -86,6 +85,7 @@ struct query_data {
/* EDNS */ /* EDNS */
knot_rrset_t opt_rr; knot_rrset_t opt_rr;
uint8_t *opt_rr_pos; /*!< Place of the OPT RR in wire. */
/* Extensions. */ /* Extensions. */
void *ext; void *ext;
......
...@@ -171,6 +171,17 @@ static inline uint16_t knot_edns_whole_rcode(uint8_t ext_rcode, uint8_t rcode) ...@@ -171,6 +171,17 @@ static inline uint16_t knot_edns_whole_rcode(uint8_t ext_rcode, uint8_t rcode)
*/ */
void knot_edns_set_ext_rcode(knot_rrset_t *opt_rr, uint8_t ext_rcode); void knot_edns_set_ext_rcode(knot_rrset_t *opt_rr, uint8_t ext_rcode);
/*!
* \brief Sets the Extended RCODE field in OPT RR wire.
*
* \param opt_rr Position of the OPT RR in packet.
* \param ext_rcode Higher 8 bits of Extended RCODE.
*/
inline void knot_edns_set_ext_rcode_wire(uint8_t *opt_rr, uint8_t ext_rcode)
{
*(opt_rr + KNOT_EDNS_EXT_RCODE_POS) = ext_rcode;
}
/*! /*!
* \brief Returns the EDNS version stored in the OPT RR. * \brief Returns the EDNS version stored in the OPT RR.
* *
......
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