]> source.dussan.org Git - rspamd.git/commitdiff
Add constraints to dns requests ammount per task.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 21 Jul 2015 12:33:49 +0000 (13:33 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 21 Jul 2015 14:00:31 +0000 (15:00 +0100)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/dns.c
src/libserver/dns.h

index c6087b157753ae91d1e66ec5ef0dc1aac8766db5..3ddd2958653b76c15a274c9d4430563918270a91 100644 (file)
@@ -254,6 +254,7 @@ struct rspamd_config {
        guint32 dns_throttling_time;                    /**< time in seconds for DNS throttling                                 */
        guint32 dns_io_per_server;                      /**< number of sockets per DNS server                                   */
        GList *nameservers;                             /**< list of nameservers or NULL to parse resolv.conf   */
+       guint32 dns_max_requests;                       /**< limit of DNS requests per task                                     */
 
        guint upstream_max_errors;                                              /**< upstream max errors before shutting off                    */
        gdouble upstream_error_time;                                    /**< rate of upstream errors                                                    */
index 7c898431fe1ef3dca7329a2f5c287595d5a0826d..a56779f2eb7b2b3f828d33025475d76cc866d9f5 100644 (file)
@@ -1265,6 +1265,11 @@ rspamd_rcl_config_init (void)
                rspamd_rcl_parse_struct_integer,
                G_STRUCT_OFFSET (struct rspamd_config, dns_io_per_server),
                RSPAMD_CL_FLAG_INT_32);
+       rspamd_rcl_add_default_handler (sub,
+               "dns_max_requests",
+               rspamd_rcl_parse_struct_integer,
+               G_STRUCT_OFFSET (struct rspamd_config, dns_max_requests),
+               RSPAMD_CL_FLAG_INT_32);
 
        /* New DNS configuration */
        ssub = rspamd_rcl_add_section (&sub->subsections, "dns", NULL,
index da444cba212e9413fafd9f79c3bec98a69b68d74..2c95a5e0e2a0dae7631d452a1deea57b55e87a24 100644 (file)
@@ -173,6 +173,7 @@ rspamd_config_defaults (struct rspamd_config *cfg)
        cfg->log_extended = TRUE;
 
        cfg->min_word_len = DEFAULT_MIN_WORD;
+       cfg->dns_max_requests = 64;
 }
 
 void
index 3e97160aff3a08125840b2a61b1afd053eb10390..1821cb69a3aa1688c4791b5c158cf25551b9b2b2 100644 (file)
@@ -117,6 +117,32 @@ make_dns_request (struct rspamd_dns_resolver *resolver,
        return TRUE;
 }
 
+gboolean make_dns_request_task (struct rspamd_task *task,
+       dns_callback_type cb,
+       gpointer ud,
+       enum rdns_request_type type,
+       const char *name)
+{
+       gboolean ret;
+
+       if (task->dns_requests >= task->cfg->dns_max_requests) {
+               return FALSE;
+       }
+
+       ret = make_dns_request (task->resolver, task->s, task->task_pool, cb, ud,
+                       type, name);
+
+       if (ret) {
+               task->dns_requests ++;
+
+               if (task->dns_requests >= task->cfg->dns_max_requests) {
+                       msg_info ("<%s> stop resolving on reaching %ud requests",
+                                       task->message_id, task->dns_requests);
+               }
+       }
+
+       return ret;
+}
 
 struct rspamd_dns_resolver *
 dns_resolver_init (rspamd_logger_t *logger,
index ffe80fae0162fec41eef2c42783062e9432df7f2..bc27f7d48c7cf58f21ef0a8695135cf9ea8ee09e 100644 (file)
@@ -66,4 +66,10 @@ gboolean make_dns_request (struct rspamd_dns_resolver *resolver,
        enum rdns_request_type type,
        const char *name);
 
+gboolean make_dns_request_task (struct rspamd_task *task,
+       dns_callback_type cb,
+       gpointer ud,
+       enum rdns_request_type type,
+       const char *name);
+
 #endif