mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Merge branch '3168-5-tidy-check_recursionquota' into 'main'
[5/5] Tidy check_recursionquota() Closes #3168 See merge request isc-projects/bind9!5886
This commit is contained in:
@@ -6315,6 +6315,22 @@ recparam_update(ns_query_recparam_t *param, dns_rdatatype_t qtype,
|
|||||||
dns_name_copy(qdomain, param->qdomain);
|
dns_name_copy(qdomain, param->qdomain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void
|
||||||
|
recursionquota_log(ns_client_t *client, atomic_uint_fast32_t *last_log_time,
|
||||||
|
const char *format, isc_quota_t *quota) {
|
||||||
|
isc_stdtime_t now;
|
||||||
|
|
||||||
|
isc_stdtime_get(&now);
|
||||||
|
if (now == atomic_load_relaxed(last_log_time)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic_store_relaxed(last_log_time, now);
|
||||||
|
ns_client_log(client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_QUERY,
|
||||||
|
ISC_LOG_WARNING, format, isc_quota_getused(quota),
|
||||||
|
isc_quota_getsoft(quota), isc_quota_getmax(quota));
|
||||||
|
}
|
||||||
|
|
||||||
static atomic_uint_fast32_t last_soft, last_hard;
|
static atomic_uint_fast32_t last_soft, last_hard;
|
||||||
|
|
||||||
/*%
|
/*%
|
||||||
@@ -6326,47 +6342,30 @@ check_recursionquota(ns_client_t *client, ns_query_rectype_t recursion_type) {
|
|||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
|
||||||
result = recursionquotatype_attach_soft(client, recursion_type);
|
result = recursionquotatype_attach_soft(client, recursion_type);
|
||||||
if (result == ISC_R_SOFTQUOTA) {
|
switch (result) {
|
||||||
isc_stdtime_t now;
|
case ISC_R_SOFTQUOTA:
|
||||||
isc_stdtime_get(&now);
|
recursionquota_log(client, &last_soft,
|
||||||
if (now != atomic_load_relaxed(&last_soft)) {
|
"recursive-clients soft limit exceeded "
|
||||||
atomic_store_relaxed(&last_soft, now);
|
"(%u/%u/%u), aborting oldest query",
|
||||||
ns_client_log(client, NS_LOGCATEGORY_CLIENT,
|
*quotap);
|
||||||
NS_LOGMODULE_QUERY, ISC_LOG_WARNING,
|
|
||||||
"recursive-clients soft limit "
|
|
||||||
"exceeded (%u/%u/%u), "
|
|
||||||
"aborting oldest query",
|
|
||||||
isc_quota_getused(*quotap),
|
|
||||||
isc_quota_getsoft(*quotap),
|
|
||||||
isc_quota_getmax(*quotap));
|
|
||||||
}
|
|
||||||
ns_client_killoldestquery(client);
|
ns_client_killoldestquery(client);
|
||||||
result = ISC_R_SUCCESS;
|
FALLTHROUGH;
|
||||||
} else if (result == ISC_R_QUOTA) {
|
case ISC_R_SUCCESS:
|
||||||
isc_stdtime_t now;
|
break;
|
||||||
isc_stdtime_get(&now);
|
case ISC_R_QUOTA:
|
||||||
if (now != atomic_load_relaxed(&last_hard)) {
|
recursionquota_log(client, &last_hard,
|
||||||
ns_server_t *sctx = client->manager->sctx;
|
"no more recursive clients (%u/%u/%u)",
|
||||||
atomic_store_relaxed(&last_hard, now);
|
&client->manager->sctx->recursionquota);
|
||||||
ns_client_log(client, NS_LOGCATEGORY_CLIENT,
|
|
||||||
NS_LOGMODULE_QUERY, ISC_LOG_WARNING,
|
|
||||||
"no more recursive clients "
|
|
||||||
"(%u/%u/%u): %s",
|
|
||||||
isc_quota_getused(&sctx->recursionquota),
|
|
||||||
isc_quota_getsoft(&sctx->recursionquota),
|
|
||||||
isc_quota_getmax(&sctx->recursionquota),
|
|
||||||
isc_result_totext(result));
|
|
||||||
}
|
|
||||||
ns_client_killoldestquery(client);
|
ns_client_killoldestquery(client);
|
||||||
}
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
return (result);
|
return (result);
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_message_clonebuffer(client->message);
|
dns_message_clonebuffer(client->message);
|
||||||
ns_client_recursing(client);
|
ns_client_recursing(client);
|
||||||
|
|
||||||
return (result);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
|
Reference in New Issue
Block a user