[v9_9] refactor max-recursion-queries

- the counters weren't set correctly when fetches timed out.
  instead we now pass down a counter object.

(cherry picked from commit 05e448935c)
(cherry picked from commit 6c049c57d9)
This commit is contained in:
Evan Hunt
2014-11-19 18:38:52 -08:00
parent cc5b3627b1
commit 1d47cb124d
24 changed files with 676 additions and 120 deletions

View File

@@ -13,8 +13,6 @@
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id$
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@@ -28,7 +26,7 @@ top_srcdir = @top_srcdir@
#
HEADERS = app.h assertions.h backtrace.h base32.h base64.h \
bind9.h bitstring.h boolean.h buffer.h bufferlist.h \
commandline.h entropy.h error.h event.h \
commandline.h counter.h entropy.h error.h event.h \
eventclass.h file.h formatcheck.h fsaccess.h \
hash.h heap.h hex.h hmacmd5.h hmacsha.h httpd.h \
interfaceiter.h @ISC_IPV6_H@ iterated_hash.h \

View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef ISC_COUNTER_H
#define ISC_COUNTER_H 1
/*****
***** Module Info
*****/
/*! \file isc/quota.h
*
* \brief The isc_quota_t object is a simple helper object for implementing
* quotas on things like the number of simultaneous connections to
* a server. It keeps track of the amount of quota in use, and
* encapsulates the locking necessary to allow multiple tasks to
* share a quota.
*/
/***
*** Imports.
***/
#include <isc/lang.h>
#include <isc/mutex.h>
#include <isc/types.h>
/*****
***** Types.
*****/
ISC_LANG_BEGINDECLS
void
isc_quota_soft(isc_quota_t *quota, int soft);
/*%<
* Set a soft quota.
*/
void
isc_quota_max(isc_quota_t *quota, int max);
/*%<
* Re-set a maximum quota.
*/
isc_result_t
isc_quota_reserve(isc_quota_t *quota);
/*%<
* Attempt to reserve one unit of 'quota'.
*
* Returns:
* \li #ISC_R_SUCCESS Success
* \li #ISC_R_SOFTQUOTA Success soft quota reached
* \li #ISC_R_QUOTA Quota is full
*/
void
isc_quota_release(isc_quota_t *quota);
isc_result_t
isc_quota_attach(isc_quota_t *quota, isc_quota_t **p);
/*%<
* Like isc_quota_reserve, and also attaches '*p' to the
* quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA).
*/
void
isc_quota_detach(isc_quota_t **p);
/*%<
* Like isc_quota_release, and also detaches '*p' from the
* quota.
*/
isc_result_t
isc_counter_create(isc_mem_t *mctx, int limit, isc_counter_t **counterp);
/*%<
* Allocate and initialize a counter object.
*/
isc_result_t
isc_counter_increment(isc_counter_t *counter);
/*%<
* Increment the counter.
*
* If the counter limit is nonzero and has been reached, then
* return ISC_R_QUOTA, otherwise ISC_R_SUCCESS. (The counter is
* incremented regardless of return value.)
*/
unsigned int
isc_counter_used(isc_counter_t *counter);
/*%<
* Return the current counter value.
*/
void
isc_counter_setlimit(isc_counter_t *counter, int limit);
/*%<
* Set the counter limit.
*/
void
isc_counter_attach(isc_counter_t *source, isc_counter_t **targetp);
/*%<
* Attach to a counter object, increasing its reference counter.
*/
void
isc_counter_detach(isc_counter_t **counterp);
/*%<
* Detach (and destroy if reference counter has dropped to zero)
* a counter object.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_COUNTER_H */

View File

@@ -50,6 +50,7 @@ typedef struct isc_buffer isc_buffer_t; /*%< Buffer */
typedef ISC_LIST(isc_buffer_t) isc_bufferlist_t; /*%< Buffer List */
typedef struct isc_constregion isc_constregion_t; /*%< Const region */
typedef struct isc_consttextregion isc_consttextregion_t; /*%< Const Text Region */
typedef struct isc_counter isc_counter_t; /*%< Counter */
typedef struct isc_entropy isc_entropy_t; /*%< Entropy */
typedef struct isc_entropysource isc_entropysource_t; /*%< Entropy Source */
typedef struct isc_event isc_event_t; /*%< Event */