aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-14 12:18:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-14 12:18:01 +0100
commit0478b4ee28138a886f9b457bdba7f2897e151093 (patch)
treeb415b34747c940c9329aec09006235803cefac8d /src
parent28403d98158bc8fd75dd3b80443dcb65999671a5 (diff)
downloadrspamd-0478b4ee28138a886f9b457bdba7f2897e151093.tar.gz
rspamd-0478b4ee28138a886f9b457bdba7f2897e151093.zip
[Fix] Call Lua callback on DNS timeouts
Diffstat (limited to 'src')
-rw-r--r--src/libserver/dns.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index 372ac28b7..6d488ccf3 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -15,6 +15,7 @@
*/
#include <contrib/librdns/rdns.h>
+#include <contrib/librdns/dns_private.h>
#include "config.h"
#include "dns.h"
#include "rspamd.h"
@@ -49,6 +50,7 @@ struct rspamd_dns_request_ud {
gpointer ud;
rspamd_mempool_t *pool;
struct rdns_request *req;
+ struct rdns_reply *reply;
};
static void
@@ -56,6 +58,21 @@ rspamd_dns_fin_cb (gpointer arg)
{
struct rspamd_dns_request_ud *reqdata = (struct rspamd_dns_request_ud *)arg;
+ if (reqdata->reply) {
+ reqdata->cb (reqdata->reply, reqdata->ud);
+ }
+ else {
+ struct rdns_reply fake_reply;
+
+ memset (&fake_reply, 0, sizeof (fake_reply));
+ fake_reply.code = RDNS_RC_TIMEOUT;
+ fake_reply.request = reqdata->req;
+ fake_reply.resolver = reqdata->req->resolver;
+ fake_reply.requested_name = reqdata->req->requested_names[0].name;
+
+ reqdata->cb (&fake_reply, reqdata->ud);
+ }
+
rdns_request_release (reqdata->req);
if (reqdata->pool == NULL) {
@@ -68,7 +85,7 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud)
{
struct rspamd_dns_request_ud *reqdata = ud;
- reqdata->cb (reply, reqdata->ud);
+ reqdata->reply = reply;
if (reqdata->session) {
/*
@@ -78,8 +95,12 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud)
rdns_request_retain (reply->request);
rspamd_session_remove_event (reqdata->session, rspamd_dns_fin_cb, reqdata);
}
- else if (reqdata->pool == NULL) {
- g_free (reqdata);
+ else {
+ reqdata->cb (reply, reqdata->ud);
+
+ if (reqdata->pool == NULL) {
+ g_free (reqdata);
+ }
}
}
@@ -103,11 +124,12 @@ make_dns_request (struct rspamd_dns_resolver *resolver,
if (pool != NULL) {
reqdata =
- rspamd_mempool_alloc (pool, sizeof (struct rspamd_dns_request_ud));
+ rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_dns_request_ud));
}
else {
- reqdata = g_malloc (sizeof (struct rspamd_dns_request_ud));
+ reqdata = g_malloc0 (sizeof (struct rspamd_dns_request_ud));
}
+
reqdata->pool = pool;
reqdata->session = session;
reqdata->cb = cb;