mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 05:28:00 +00:00
Add helper function for recursive-clients logging
Reduce code duplication in check_recursionquota() by extracting its parts responsible for logging to a separate helper function. Remove result text from the "no more recursive clients" message because it always says "quota reached" (as the relevant branch is only evaluated when 'result' is set to ISC_R_QUOTA) and therefore brings no additional value.
This commit is contained in:
parent
296587903a
commit
a06cdfc7b7
@ -6315,6 +6315,22 @@ recparam_update(ns_query_recparam_t *param, dns_rdatatype_t qtype,
|
||||
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;
|
||||
|
||||
/*%
|
||||
@ -6327,36 +6343,16 @@ check_recursionquota(ns_client_t *client, ns_query_rectype_t recursion_type) {
|
||||
|
||||
result = recursionquotatype_attach_soft(client, recursion_type);
|
||||
if (result == ISC_R_SOFTQUOTA) {
|
||||
isc_stdtime_t now;
|
||||
isc_stdtime_get(&now);
|
||||
if (now != atomic_load_relaxed(&last_soft)) {
|
||||
atomic_store_relaxed(&last_soft, now);
|
||||
ns_client_log(client, NS_LOGCATEGORY_CLIENT,
|
||||
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));
|
||||
}
|
||||
recursionquota_log(client, &last_soft,
|
||||
"recursive-clients soft limit exceeded "
|
||||
"(%u/%u/%u), aborting oldest query",
|
||||
*quotap);
|
||||
ns_client_killoldestquery(client);
|
||||
result = ISC_R_SUCCESS;
|
||||
} else if (result == ISC_R_QUOTA) {
|
||||
isc_stdtime_t now;
|
||||
isc_stdtime_get(&now);
|
||||
if (now != atomic_load_relaxed(&last_hard)) {
|
||||
ns_server_t *sctx = client->manager->sctx;
|
||||
atomic_store_relaxed(&last_hard, now);
|
||||
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));
|
||||
}
|
||||
recursionquota_log(client, &last_hard,
|
||||
"no more recursive clients (%u/%u/%u)",
|
||||
&client->manager->sctx->recursionquota);
|
||||
ns_client_killoldestquery(client);
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user