Commit 5d9609b4 authored by Daniel Salzman's avatar Daniel Salzman

libknot/pkt: extend knot_pkt_get_ext_rcode with TSIG RCODE

parent 6019651c
......@@ -20,6 +20,7 @@
#include "libknot/attribute.h"
#include "libknot/packet/pkt.h"
#include "libknot/codes.h"
#include "libknot/descriptor.h"
#include "libknot/errcode.h"
#include "libknot/rrtype/tsig.h"
......@@ -860,18 +861,56 @@ int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
}
_public_
uint16_t knot_pkt_get_ext_rcode(const knot_pkt_t *pkt)
uint16_t knot_pkt_ext_rcode(const knot_pkt_t *pkt)
{
if (pkt == NULL) {
return 0;
}
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
/* Get header RCODE. */
uint16_t rcode = knot_wire_get_rcode(pkt->wire);
if (pkt->opt_rr) {
/* Update to extended RCODE if EDNS is available. */
if (pkt->opt_rr != NULL) {
uint8_t opt_rcode = knot_edns_get_ext_rcode(pkt->opt_rr);
return knot_edns_whole_rcode(opt_rcode, rcode);
rcode = knot_edns_whole_rcode(opt_rcode, rcode);
}
/* Return if not NOTAUTH. */
if (rcode != KNOT_RCODE_NOTAUTH) {
return rcode;
}
/* Get TSIG RCODE. */
uint16_t tsig_rcode = KNOT_RCODE_NOERROR;
if (pkt->tsig_rr != NULL) {
tsig_rcode = knot_tsig_rdata_error(pkt->tsig_rr);
}
/* Return proper RCODE. */
if (tsig_rcode != KNOT_RCODE_NOERROR) {
return tsig_rcode;
} else {
return rcode;
}
}
_public_
const char *knot_pkt_ext_rcode_name(const knot_pkt_t *pkt)
{
if (pkt == NULL) {
return "";
}
uint16_t rcode = knot_pkt_ext_rcode(pkt);
const knot_lookup_t *item = NULL;
if (pkt->tsig_rr != NULL) {
item = knot_lookup_by_id(knot_tsig_rcode_names, rcode);
}
if (item == NULL) {
item = knot_lookup_by_id(knot_rcode_names, rcode);
}
return (item != NULL) ? item->name : "";
}
......@@ -316,17 +316,27 @@ int knot_pkt_parse_section(knot_pkt_t *pkt, unsigned flags);
int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags);
/*!
* \brief Get the Extended RCODE from the packet.
* \brief Get packet extended RCODE.
*
* Extended RCODE is created by using the Extended RCODE field from OPT RR as
* higher 8 bits and the RCODE from DNS Header as the lower 4 bits, resulting
* in a 12-bit unsigned integer. (See RFC 6891, Section 6.1.3).
* Extended RCODE is created by considering TSIG RCODE, EDNS RCODE and
* DNS Header RCODE. (See RFC 6895, Section 2.3).
*
* \param pkt Packet to get the response code from.
*
* \return Whole extended RCODE (0 if pkt == NULL).
*/
uint16_t knot_pkt_get_ext_rcode(const knot_pkt_t *pkt);
uint16_t knot_pkt_ext_rcode(const knot_pkt_t *pkt);
/*!
* \brief Get packet extended RCODE name.
*
* The packet parameter is important as the name depends on TSIG.
*
* \param pkt Packet to get the response code from.
*
* \return RCODE name (or empty string if not known).
*/
const char *knot_pkt_ext_rcode_name(const knot_pkt_t *pkt);
/*!
* \brief Checks if there is an OPT RR in the packet.
......
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