Commit 7fde8126 authored by Daniel Salzman's avatar Daniel Salzman

process_query: use KNOTD_STATE_NOOP for a response suppression

parent 9acda2f9
......@@ -408,6 +408,7 @@ knot_rrset_t knotd_qdata_zone_apex_rrset(knotd_qdata_t *qdata, uint16_t type);
/*! General query processing states. */
typedef enum {
KNOTD_STATE_NOOP = 0, /*!< No response. */
KNOTD_STATE_DONE = 4, /*!< Finished. */
KNOTD_STATE_FAIL = 5, /*!< Error. */
} knotd_state_t;
......
......@@ -63,7 +63,7 @@ static knotd_state_t log_message(knotd_state_t state, const knot_pkt_t *pkt,
assert(pkt && qdata && mod);
/* Skip empty packet. */
if (pkt->size == 0) {
if (state == KNOTD_STATE_NOOP) {
return state;
}
......
......@@ -163,8 +163,7 @@ static knotd_state_t ratelimit_apply(knotd_state_t state, knot_pkt_t *pkt,
} else {
// Drop the answer.
knotd_mod_stats_incr(mod, 1, 0, 1);
pkt->size = 0;
return KNOTD_STATE_DONE;
return KNOTD_STATE_NOOP;
}
}
......
......@@ -377,7 +377,7 @@ static knotd_state_t update_counters(knotd_state_t state, knot_pkt_t *pkt,
}
// Count response bytes.
if (stats->resp_bytes) {
if (stats->resp_bytes && state != KNOTD_STATE_NOOP) {
switch (operation) {
case OPERATION_QUERY:
knotd_mod_stats_incr(mod, CTR_RESP_BYTES, RESP_BYTES_REPLY,
......@@ -402,7 +402,7 @@ static knotd_state_t update_counters(knotd_state_t state, knot_pkt_t *pkt,
}
// Count the response code.
if (stats->rcode && pkt->size > 0) {
if (stats->rcode && state != KNOTD_STATE_NOOP) {
if (xfr_packets <= 1 || rcode != KNOT_RCODE_NOERROR) {
if (xfr_packets > 1) {
assert(rcode != KNOT_RCODE_NOERROR);
......@@ -456,14 +456,14 @@ static knotd_state_t update_counters(knotd_state_t state, knot_pkt_t *pkt,
if (qdata->query->opt_rr != NULL) {
knotd_mod_stats_incr(mod, CTR_EDNS, EDNS_REQ, 1);
}
if (pkt->opt_rr != NULL && pkt->size > 0) {
if (pkt->opt_rr != NULL && state != KNOTD_STATE_NOOP) {
knotd_mod_stats_incr(mod, CTR_EDNS, EDNS_RESP, 1);
}
}
// Count interesting message header flags.
if (stats->flag) {
if (pkt->size > 0 && knot_wire_get_tc(pkt->wire)) {
if (state != KNOTD_STATE_NOOP && knot_wire_get_tc(pkt->wire)) {
knotd_mod_stats_incr(mod, CTR_FLAG, FLAG_TC, 1);
}
if (pkt->opt_rr != NULL && knot_edns_do(pkt->opt_rr)) {
......@@ -477,7 +477,7 @@ static knotd_state_t update_counters(knotd_state_t state, knot_pkt_t *pkt,
}
// Count NODATA reply (RFC 2308, Section 2.2).
if (stats->nodata && rcode == KNOT_RCODE_NOERROR && pkt->size > 0 &&
if (stats->nodata && rcode == KNOT_RCODE_NOERROR && state != KNOTD_STATE_NOOP &&
knot_wire_get_ancount(pkt->wire) == 0 && !knot_wire_get_tc(pkt->wire) &&
(knot_wire_get_nscount(pkt->wire) == 0 ||
knot_pkt_rr(knot_pkt_section(pkt, KNOT_AUTHORITY), 0)->type == KNOT_RRTYPE_SOA)) {
......@@ -516,7 +516,7 @@ static knotd_state_t update_counters(knotd_state_t state, knot_pkt_t *pkt,
}
// Count the reply size.
if (stats->rsize && pkt->size > 0) {
if (stats->rsize && state != KNOTD_STATE_NOOP) {
uint64_t idx = pkt->size / BUCKET_SIZE;
knotd_mod_stats_incr(mod, CTR_RSIZE, MIN(idx, RSIZE_MAX_IDX), 1);
}
......
......@@ -542,11 +542,15 @@ static int process_query_out(knot_layer_t *ctx, knot_pkt_t *pkt)
}
finish:
if (next_state != KNOT_STATE_FAIL) {
set_rcode_to_packet(pkt, qdata);
} else {
switch (next_state) {
case KNOT_STATE_NOOP:
break;
case KNOT_STATE_FAIL:
/* Error processing. */
next_state = process_query_err(ctx, pkt);
break;
default:
set_rcode_to_packet(pkt, qdata);
}
/* After query processing code. */
......
......@@ -441,8 +441,7 @@ int update_process_query(knot_pkt_t *pkt, knotd_qdata_t *qdata)
}
/* No immediate response. */
pkt->size = 0;
return KNOT_STATE_DONE;
return KNOT_STATE_NOOP;
}
void updates_execute(conf_t *conf, zone_t *zone)
......
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