aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/librdns/resolver.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-04-11 13:36:53 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-04-11 13:36:53 +0100
commit1a23c4377601c5c550d616c709e6e1ee56fd7f05 (patch)
tree946d585be51b578473a5d4b513270667301d6012 /contrib/librdns/resolver.c
parentb9437540726e6e30f4bacd350b833ed8e330cb0a (diff)
downloadrspamd-1a23c4377601c5c550d616c709e6e1ee56fd7f05.tar.gz
rspamd-1a23c4377601c5c550d616c709e6e1ee56fd7f05.zip
[Minor] Connect UDP sockets when send was successful
Diffstat (limited to 'contrib/librdns/resolver.c')
-rw-r--r--contrib/librdns/resolver.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c
index 3130a5c96..2cc3695a7 100644
--- a/contrib/librdns/resolver.c
+++ b/contrib/librdns/resolver.c
@@ -68,15 +68,28 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req)
}
if (resolver->curve_plugin == NULL) {
- r = sendto (fd, req->packet, req->pos, 0,
- req->io->saddr,
- req->io->slen);
+ if (!req->io->connected) {
+ r = sendto (fd, req->packet, req->pos, 0,
+ req->io->saddr,
+ req->io->slen);
+ }
+ else {
+ r = send (fd, req->packet, req->pos, 0);
+ }
}
else {
- r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
- resolver->curve_plugin->data,
- req->io->saddr,
- req->io->slen);
+ if (!req->io->connected) {
+ r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
+ resolver->curve_plugin->data,
+ req->io->saddr,
+ req->io->slen);
+ }
+ else {
+ r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
+ resolver->curve_plugin->data,
+ NULL,
+ 0);
+ }
}
if (r == -1) {
if (errno == EAGAIN || errno == EINTR) {
@@ -98,6 +111,18 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req)
return -1;
}
}
+ else if (!req->io->connected) {
+ /* Connect socket */
+ r = connect (fd, req->io->saddr, req->io->slen);
+
+ if (r == -1) {
+ rdns_err ("cannot connect after sending request: %s for server %s",
+ strerror (errno), serv->name);
+ }
+ else {
+ req->io->connected = true;
+ }
+ }
if (new_req) {
/* Add request to hash table */
@@ -257,7 +282,7 @@ rdns_process_read (int fd, void *arg)
/* First read packet from socket */
if (resolver->curve_plugin == NULL) {
- r = recvfrom (fd, in, sizeof (in), 0, ioc->saddr, &ioc->slen);
+ r = recv (fd, in, sizeof (in), 0);
if (r > (int)(sizeof (struct dns_header) + sizeof (struct dns_query))) {
req = rdns_find_dns_request (in, ioc);
}