internet.h 2.55 KB
Newer Older
1
/*  Copyright (C) 2017 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 16

    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/>.
 */

17
#pragma once
18 19

#include "libknot/packet/pkt.h"
20
#include "knot/include/module.h"
21 22

/*!
23
 * \brief Answer query from an IN class zone.
24
 *
25 26
 * \retval KNOT_STATE_FAIL if it encountered an error.
 * \retval KNOT_STATE_DONE if finished.
27
 */
28
int internet_process_query(knot_pkt_t *pkt, knotd_qdata_t *qdata);
29

30 31
/*! \brief Require given QUERY TYPE or return error code. */
#define NS_NEED_QTYPE(qdata, qtype_want, error_rcode) \
32
	if (knot_pkt_qtype((qdata)->query) != (qtype_want)) { \
33
		qdata->rcode = (error_rcode); \
34
		return KNOT_STATE_FAIL; \
35 36 37 38
	}

/*! \brief Require given QUERY NAME or return error code. */
#define NS_NEED_QNAME(qdata, qname_want, error_rcode) \
39
	if (!knot_dname_is_equal(knot_pkt_qname((qdata)->query), (qname_want))) { \
40
		qdata->rcode = (error_rcode); \
41
		return KNOT_STATE_FAIL; \
42 43
	}

44 45
/*! \brief Require existing zone or return failure. */
#define NS_NEED_ZONE(qdata, error_rcode) \
46
	if ((qdata)->extra->zone == NULL) { \
47
		qdata->rcode = (error_rcode); \
48
		return KNOT_STATE_FAIL; \
49 50 51 52
	}

/*! \brief Require existing zone contents or return failure. */
#define NS_NEED_ZONE_CONTENTS(qdata, error_rcode) \
53
	if ((qdata)->extra->zone->contents == NULL) { \
54
		qdata->rcode = (error_rcode); \
55
		return KNOT_STATE_FAIL; \
56 57
	}

58
/*! \brief Require authentication. */
59
#define NS_NEED_AUTH(qdata, zone_name, action) \
60 61
	if (!process_query_acl_check(conf(), (zone_name), (action), (qdata)) || \
	    process_query_verify(qdata) != KNOT_EOK) { \
62
		return KNOT_STATE_FAIL; \
63 64
	}

65
/*! \brief Require maximum number of unsigned messages. */
66 67
#define NS_NEED_TSIG_SIGNED(tsig_ctx, max_unsigned) \
	if (tsig_unsigned_count(tsig_ctx) > max_unsigned) { \
68
		return KNOT_STATE_FAIL; \
69
	}
70 71 72

/*! \brief Require the zone not to be frozen. */
#define NS_NEED_NOT_FROZEN(qdata, error_rcode) \
73
	if ((qdata)->extra->zone->events.ufrozen) { \
74 75 76
		(qdata)->rcode = (error_rcode); \
		return KNOT_STATE_FAIL; \
	}