Commit 34f875df authored by Daniel Salzman's avatar Daniel Salzman

pkt: move knot_pkt_type to process_query

parent 61851fe4
......@@ -35,6 +35,36 @@
/*! \brief Accessor to query-specific data. */
#define QUERY_DATA(ctx) ((struct query_data *)(ctx)->data)
static uint16_t pkt_type(const knot_pkt_t *pkt)
{
assert(pkt);
bool is_query = (knot_wire_get_qr(pkt->wire) == 0);
uint16_t ret = KNOT_QUERY_INVALID;
uint8_t opcode = knot_wire_get_opcode(pkt->wire);
uint16_t query_type = knot_pkt_qtype(pkt);
switch (opcode) {
case KNOT_OPCODE_QUERY:
switch (query_type) {
case 0 /* RESERVED */: /* INVALID */ break;
case KNOT_RRTYPE_AXFR: ret = KNOT_QUERY_AXFR; break;
case KNOT_RRTYPE_IXFR: ret = KNOT_QUERY_IXFR; break;
default: ret = KNOT_QUERY_NORMAL; break;
}
break;
case KNOT_OPCODE_NOTIFY: ret = KNOT_QUERY_NOTIFY; break;
case KNOT_OPCODE_UPDATE: ret = KNOT_QUERY_UPDATE; break;
default: break;
}
if (!is_query) {
ret = ret|KNOT_RESPONSE;
}
return ret;
}
/*! \brief Reinitialize query data structure. */
static void query_data_init(knot_layer_t *ctx, void *module_param)
{
......@@ -111,7 +141,7 @@ static int process_query_in(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Store for processing. */
qdata->query = pkt;
qdata->packet_type = knot_pkt_type(pkt);
qdata->packet_type = pkt_type(pkt);
/* Declare having response. */
return KNOT_STATE_PRODUCE;
......@@ -187,7 +217,7 @@ static const zone_t *answer_zone_find(const knot_pkt_t *query, knot_zonedb_t *zo
}
if (zone == NULL) {
if (knot_pkt_type(query) == KNOT_QUERY_NORMAL) {
if (pkt_type(query) == KNOT_QUERY_NORMAL) {
zone = knot_zonedb_find_suffix(zonedb, qname);
} else {
// Direct match required.
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -21,6 +21,27 @@
#include "knot/updates/acl.h"
#include "contrib/sockaddr.h"
/*!
* \brief DNS query types.
*
* This type encompasses the different query types distinguished by both the
* OPCODE and the QTYPE.
*/
typedef enum {
KNOT_QUERY_INVALID = 0, /*!< Invalid query. */
KNOT_QUERY_NORMAL = 1 << 1, /*!< Normal query. */
KNOT_QUERY_AXFR = 1 << 2, /*!< Request for AXFR transfer. */
KNOT_QUERY_IXFR = 1 << 3, /*!< Request for IXFR transfer. */
KNOT_QUERY_NOTIFY = 1 << 4, /*!< NOTIFY query. */
KNOT_QUERY_UPDATE = 1 << 5, /*!< Dynamic update. */
KNOT_RESPONSE = 1 << 0, /*!< Is response. */
KNOT_RESPONSE_NORMAL = KNOT_RESPONSE|KNOT_QUERY_NORMAL,/*!< Normal response. */
KNOT_RESPONSE_AXFR = KNOT_RESPONSE|KNOT_QUERY_AXFR, /*!< AXFR transfer response. */
KNOT_RESPONSE_IXFR = KNOT_RESPONSE|KNOT_QUERY_IXFR, /*!< IXFR transfer response. */
KNOT_RESPONSE_NOTIFY = KNOT_RESPONSE|KNOT_QUERY_NOTIFY,/*!< NOTIFY response. */
KNOT_RESPONSE_UPDATE = KNOT_RESPONSE|KNOT_QUERY_UPDATE /*!< Dynamic update response. */
} pkt_type_t;
/* Query processing module implementation. */
const knot_layer_api_t *process_query_layer(void);
......
......@@ -406,39 +406,6 @@ int knot_pkt_reclaim(knot_pkt_t *pkt, uint16_t size)
}
}
_public_
uint16_t knot_pkt_type(const knot_pkt_t *pkt)
{
if (pkt == NULL) {
return 0;
}
bool is_query = (knot_wire_get_qr(pkt->wire) == 0);
uint16_t ret = KNOT_QUERY_INVALID;
uint8_t opcode = knot_wire_get_opcode(pkt->wire);
uint16_t query_type = knot_pkt_qtype(pkt);
switch (opcode) {
case KNOT_OPCODE_QUERY:
switch (query_type) {
case 0 /* RESERVED */: /* INVALID */ break;
case KNOT_RRTYPE_AXFR: ret = KNOT_QUERY_AXFR; break;
case KNOT_RRTYPE_IXFR: ret = KNOT_QUERY_IXFR; break;
default: ret = KNOT_QUERY_NORMAL; break;
}
break;
case KNOT_OPCODE_NOTIFY: ret = KNOT_QUERY_NOTIFY; break;
case KNOT_OPCODE_UPDATE: ret = KNOT_QUERY_UPDATE; break;
default: break;
}
if (!is_query) {
ret = ret|KNOT_RESPONSE;
}
return ret;
}
_public_
uint16_t knot_pkt_question_size(const knot_pkt_t *pkt)
{
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -41,28 +41,6 @@
/* Forward decls */
struct knot_pkt;
/// XXX: server internal, wipe from the library
/*!
* \brief DNS query types (internal use only).
*
* This type encompasses the different query types distinguished by both the
* OPCODE and the QTYPE.
*/
typedef enum {
KNOT_QUERY_INVALID = 0, /*!< Invalid query. */
KNOT_QUERY_NORMAL = 1 << 1, /*!< Normal query. */
KNOT_QUERY_AXFR = 1 << 2, /*!< Request for AXFR transfer. */
KNOT_QUERY_IXFR = 1 << 3, /*!< Request for IXFR transfer. */
KNOT_QUERY_NOTIFY = 1 << 4, /*!< NOTIFY query. */
KNOT_QUERY_UPDATE = 1 << 5, /*!< Dynamic update. */
KNOT_RESPONSE = 1 << 0, /*!< Is response. */
KNOT_RESPONSE_NORMAL = KNOT_RESPONSE|KNOT_QUERY_NORMAL,/*!< Normal response. */
KNOT_RESPONSE_AXFR = KNOT_RESPONSE|KNOT_QUERY_AXFR, /*!< AXFR transfer response. */
KNOT_RESPONSE_IXFR = KNOT_RESPONSE|KNOT_QUERY_IXFR, /*!< IXFR transfer response. */
KNOT_RESPONSE_NOTIFY = KNOT_RESPONSE|KNOT_QUERY_NOTIFY,/*!< NOTIFY response. */
KNOT_RESPONSE_UPDATE = KNOT_RESPONSE|KNOT_QUERY_UPDATE /*!< Dynamic update response. */
} knot_pkt_type_t;
/*!
* \brief Packet flags.
*/
......@@ -182,12 +160,6 @@ int knot_pkt_reserve(knot_pkt_t *pkt, uint16_t size);
*/
int knot_pkt_reclaim(knot_pkt_t *pkt, uint16_t size);
// XXX: probably useless
/*! \brief Classify packet according to the question.
* \return see enum knot_pkt_type_t
*/
uint16_t knot_pkt_type(const knot_pkt_t *pkt);
/*
* Packet QUESTION accessors.
*/
......
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