]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add helper function for recursive-clients logging
authorMichał Kępień <michal@isc.org>
Tue, 14 Jun 2022 11:13:32 +0000 (13:13 +0200)
committerMichał Kępień <michal@isc.org>
Tue, 14 Jun 2022 11:13:32 +0000 (13:13 +0200)
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.

lib/ns/query.c

index dc382c7e33494977e721f69a6fb03de9d1528661..322810b66d90369353a30b2406651346e449f1bc 100644 (file)
@@ -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) {