struct rdns_fake_reply_idx *idx;
if (resolver == NULL || !resolver->initialized) {
+ if (resolver == NULL) {
+ return NULL;
+ }
+
+ rdns_err ("resolver is uninitialized");
+
return NULL;
}
req = malloc (sizeof (struct rdns_request));
if (req == NULL) {
+ rdns_err ("failed to allocate memory for request: %s",
+ strerror (errno));
return NULL;
}
if (req->requested_names == NULL) {
free (req);
+ rdns_err ("failed to allocate memory for request data: %s",
+ strerror (errno));
+
return NULL;
}
clen = strlen (cur_name);
if (clen == 0) {
- rdns_info ("got empty name to resolve");
+ rdns_warn ("got empty name to resolve");
rdns_request_free (req);
return NULL;
}
tlen += clen;
}
else if (last_name == NULL) {
- rdns_info ("got NULL as the first name to resolve");
+ rdns_err ("got NULL as the first name to resolve");
rdns_request_free (req);
return NULL;
}
if (req->state != RDNS_REQUEST_FAKE) {
if (!rdns_format_dns_name (resolver, last_name, clen,
&req->requested_names[cur].name, &olen)) {
+ rdns_err ("cannot format %s", last_name);
rdns_request_free (req);
return NULL;
}
type = req->requested_names[i].type;
if (queries > 1) {
if (!rdns_add_rr (req, cur_name, clen, type, &comp)) {
+ rdns_err ("cannot add rr", cur_name);
REF_RELEASE (req);
rnds_compression_free (comp);
return NULL;
}
} else {
if (!rdns_add_rr (req, cur_name, clen, type, NULL)) {
+ rdns_err ("cannot add rr", cur_name);
REF_RELEASE (req);
rnds_compression_free (comp);
return NULL;
r = rdns_send_request (req, req->io->sock, true);
if (r == -1) {
+ rdns_info ("cannot send DNS request");
REF_RELEASE (req);
return NULL;
}
struct rdns_io_channel *ioc;
if (!resolver->async_binded) {
+ rdns_err ("no async backend specified");
return false;
}
if (resolver->servers == NULL) {
+ rdns_err ("no DNS servers defined");
return false;
}
for (i = 0; i < serv->io_cnt; i ++) {
ioc = calloc (1, sizeof (struct rdns_io_channel));
if (ioc == NULL) {
- rdns_err ("cannot allocate memory for the resolver");
+ rdns_err ("cannot allocate memory for the resolver IO channels");
return false;
}
+
ioc->sock = rdns_make_client_socket (serv->name, serv->port, SOCK_DGRAM);
- ioc->active = true;
+
if (ioc->sock == -1) {
- rdns_err ("cannot open socket to %s:%d %s", serv->name, serv->port, strerror (errno));
+ ioc->active = false;
+ rdns_err ("cannot open socket to %s:%d %s",
+ serv->name, serv->port, strerror (errno));
free (ioc);
return false;
}
#include "utlist.h"
#include "uthash.h"
#include "rdns_event.h"
+#include "unix-std.h"
static struct rdns_upstream_elt* rspamd_dns_select_upstream (const char *name,
size_t len, void *ups_data);
int priority, unsigned int io_cnt, void *ud)
{
struct rspamd_dns_resolver *dns_resolver = ud;
+ struct rspamd_config *cfg;
+ rspamd_inet_addr_t *addr;
+ gint test_fd;
+
+ cfg = dns_resolver->cfg;
+
+ msg_info_config ("parsed nameserver %s from resolv.conf", name);
+
+ /* Try to open a connection */
+ if (!rspamd_parse_inet_address (&addr, name, strlen (name))) {
+ msg_warn_config ("cannot parse nameserver address %s", name);
+
+ return FALSE;
+ }
+
+ rspamd_inet_address_set_port (addr, port);
+ test_fd = rspamd_inet_address_connect (addr, SOCK_DGRAM, TRUE);
+
+ if (test_fd == -1) {
+ msg_warn_config ("cannot open connection to nameserver at address %s: %s",
+ name, strerror (errno));
+ rspamd_inet_address_free (addr);
+
+ return FALSE;
+ }
+
+ rspamd_inet_address_free (addr);
+ close (test_fd);
return rspamd_upstreams_add_upstream (dns_resolver->ups, name, port,
RSPAMD_UPSTREAM_PARSE_NAMESERVER,