Skip to content

Commit

Permalink
[Project] Some fixes in SRV records handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Oct 1, 2019
1 parent b3eb4d1 commit 61506d5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/libutil/upstream.c
Expand Up @@ -28,6 +28,7 @@

struct upstream_inet_addr_entry {
rspamd_inet_addr_t *addr;
guint priority;
struct upstream_inet_addr_entry *next;
};

Expand All @@ -52,6 +53,7 @@ struct upstream {
guint checked;
guint dns_requests;
gint active_idx;
guint ttl;
gchar *name;
ev_timer ev;
gdouble last_fail;
Expand Down Expand Up @@ -464,7 +466,6 @@ rspamd_upstream_dns_cb (struct rdns_reply *reply, void *arg)

struct rspamd_upstream_srv_dns_cb {
struct upstream *up;
guint ttl;
guint priority;
guint port;
guint requests_inflight;
Expand Down Expand Up @@ -492,12 +493,16 @@ rspamd_upstream_dns_srv_phase2_cb (struct rdns_reply *reply, void *arg)
up_ent = g_malloc0 (sizeof (*up_ent));
up_ent->addr = rspamd_inet_address_new (AF_INET,
&entry->content.a.addr);
up_ent->priority = cbdata->priority;
rspamd_inet_address_set_port (up_ent->addr, cbdata->port);
LL_PREPEND (up->new_addrs, up_ent);
}
else if (entry->type == RDNS_REQUEST_AAAA) {
up_ent = g_malloc0 (sizeof (*up_ent));
up_ent->addr = rspamd_inet_address_new (AF_INET6,
&entry->content.aaa.addr);
up_ent->priority = cbdata->priority;
rspamd_inet_address_set_port (up_ent->addr, cbdata->port);
LL_PREPEND (up->new_addrs, up_ent);
}
entry = entry->next;
Expand Down Expand Up @@ -542,7 +547,8 @@ rspamd_upstream_dns_srv_cb (struct rdns_reply *reply, void *arg)
ncbdata = g_malloc0 (sizeof (*ncbdata));
ncbdata->priority = entry->content.srv.weight;
ncbdata->port = entry->content.srv.port;
ncbdata->ttl = entry->ttl;
/* XXX: for all entries? */
upstream->ttl = entry->ttl;

if (rdns_make_request_full (upstream->ctx->res,
rspamd_upstream_dns_srv_phase2_cb, ncbdata,
Expand Down Expand Up @@ -646,11 +652,16 @@ rspamd_upstream_lazy_resolve_cb (struct ev_loop *loop, ev_timer *w, int revents)
ev_timer_stop (loop, w);

if (up->ls) {

rspamd_upstream_resolve_addrs (up->ls, up);

w->repeat = rspamd_time_jitter (up->ls->limits.lazy_resolve_time,
up->ls->limits.lazy_resolve_time * .1);
if (up->ttl == 0 || up->ttl > up->ls->limits.lazy_resolve_time) {
w->repeat = rspamd_time_jitter (up->ls->limits.lazy_resolve_time,
up->ls->limits.lazy_resolve_time * .1);
}
else {
w->repeat = up->ttl;
}

ev_timer_again (loop, w);
}

Expand Down

0 comments on commit 61506d5

Please sign in to comment.