internet.h 3.84 KB
Newer Older
1
/*  Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
2 3 4 5 6 7 8 9 10 11 12 13 14 15

    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
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16 17 18 19 20 21 22 23
/*!
 * \file
 *
 * \brief IN zone lookup.
 *
 * \addtogroup query_processing
 * @{
 */
24

25
#pragma once
26 27

#include "libknot/packet/pkt.h"
28
#include "libknot/processing/layer.h"
29 30 31

/* Query data (from query processing). */
struct query_data;
32 33
struct query_plan;
struct query_module;
34
struct answer_data;
35 36 37 38 39 40 41 42 43 44 45 46

/*! \brief Internet query processing states. */
enum {
	BEGIN,   /* Begin name resolution. */
	NODATA,  /* Positive result with NO data. */
	HIT,     /* Positive result. */
	MISS,    /* Negative result. */
	DELEG,   /* Result is delegation. */
	FOLLOW,  /* Resolution not complete (CNAME/DNAME chain). */
	ERROR,   /* Resolution failed. */
	TRUNC    /* Finished, but truncated. */
};
47 48

/*!
49
 * \brief Answer query from an IN class zone.
50 51 52
 *
 * \retval FAIL if it encountered an error.
 * \retval DONE if finished.
53
 */
54
int internet_process_query(knot_pkt_t *resp, struct query_data *qdata);
55

56 57 58 59 60 61 62
/*!
 * \brief Initialize query plan for IN class zone.
 * \param plan
 * \return
 */
int internet_query_plan(struct query_plan *plan);

63 64 65 66 67 68 69
/*!
 * \brief Process answer in an IN class zone.
 *
 * \retval FAIL if it encountered an error.
 * \retval DONE if finished.
 * \retval NOOP if not supported.
 */
70
int internet_process_answer(knot_pkt_t *pkt, struct answer_data *data);
71

72 73 74 75 76 77 78 79
/*!
 * \brief Puts RRSet to packet, will store its RRSIG for later use.
 *
 * \param pkt         Packet to store RRSet into.
 * \param rr          RRSet to be stored.
 * \param rrsigs      RRSIGs to be stored.
 * \param compr_hint  Compression hint.
 * \param flags       Flags.
80
 * \param expand      Set to true if wildcards should be expanded.
81 82 83 84 85 86
 * \param qdata       Query data structure.
 *
 * \return KNOT_E*
 */
int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
              const knot_rrset_t *rrsigs, uint16_t compr_hint,
87
              uint32_t flags, struct query_data *qdata);
88

89 90
/*! \brief Require given QUERY TYPE or return error code. */
#define NS_NEED_QTYPE(qdata, qtype_want, error_rcode) \
Marek Vavrusa's avatar
Marek Vavrusa committed
91
	if (knot_pkt_qtype((qdata)->query) != (qtype_want)) { \
92
		qdata->rcode = (error_rcode); \
93
		return KNOT_STATE_FAIL; \
94 95 96 97
	}

/*! \brief Require given QUERY NAME or return error code. */
#define NS_NEED_QNAME(qdata, qname_want, error_rcode) \
Marek Vavrusa's avatar
Marek Vavrusa committed
98
	if (!knot_dname_is_equal(knot_pkt_qname((qdata)->query), (qname_want))) { \
99
		qdata->rcode = (error_rcode); \
100
		return KNOT_STATE_FAIL; \
101 102
	}

103 104 105
/*! \brief Require existing zone or return failure. */
#define NS_NEED_ZONE(qdata, error_rcode) \
	if ((qdata)->zone == NULL) { \
106
		qdata->rcode = (error_rcode); \
107
		return KNOT_STATE_FAIL; \
108 109 110 111 112 113
	}

/*! \brief Require existing zone contents or return failure. */
#define NS_NEED_ZONE_CONTENTS(qdata, error_rcode) \
	if ((qdata)->zone->contents == NULL) { \
		qdata->rcode = (error_rcode); \
114
		return KNOT_STATE_FAIL; \
115 116
	}

117
/*! \brief Require authentication. */
Daniel Salzman's avatar
Daniel Salzman committed
118
#define NS_NEED_AUTH(qdata, zone_name, action) \
119
	if (!process_query_acl_check(conf(), (zone_name), (action), (qdata))) { \
120
		return KNOT_STATE_FAIL; \
121
	} else { \
122
		if (process_query_verify(qdata) != KNOT_EOK) { \
123
			return KNOT_STATE_FAIL; \
124 125 126
		} \
	}

127 128
#define NS_NEED_TSIG_SIGNED(tsig_ctx, max_unsigned) \
	if (tsig_unsigned_count(tsig_ctx) > max_unsigned) { \
129
		return KNOT_STATE_FAIL; \
130 131
	}

132
/*! @} */