diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-04-11 13:36:53 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-04-11 13:36:53 +0100 |
commit | 1a23c4377601c5c550d616c709e6e1ee56fd7f05 (patch) | |
tree | 946d585be51b578473a5d4b513270667301d6012 /contrib | |
parent | b9437540726e6e30f4bacd350b833ed8e330cb0a (diff) | |
download | rspamd-1a23c4377601c5c550d616c709e6e1ee56fd7f05.tar.gz rspamd-1a23c4377601c5c550d616c709e6e1ee56fd7f05.zip |
[Minor] Connect UDP sockets when send was successful
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/librdns/curve.c | 2 | ||||
-rw-r--r-- | contrib/librdns/dns_private.h | 1 | ||||
-rw-r--r-- | contrib/librdns/resolver.c | 41 |
3 files changed, 35 insertions, 9 deletions
diff --git a/contrib/librdns/curve.c b/contrib/librdns/curve.c index a4bc15418..f53d078b2 100644 --- a/contrib/librdns/curve.c +++ b/contrib/librdns/curve.c @@ -782,7 +782,7 @@ rdns_curve_recv (struct rdns_io_channel *ioc, void *buf, size_t len, void *plugi struct rdns_resolver *resolver; resolver = ctx->resolver; - ret = recvfrom (ioc->sock, buf, len, 0, saddr, &slen); + ret = recv (ioc->sock, buf, len, 0); if (ret <= 0 || ret < 64) { /* Definitely not a DNSCurve packet */ diff --git a/contrib/librdns/dns_private.h b/contrib/librdns/dns_private.h index 3d25d21b8..f734e2312 100644 --- a/contrib/librdns/dns_private.h +++ b/contrib/librdns/dns_private.h @@ -108,6 +108,7 @@ struct rdns_io_channel { socklen_t slen; int sock; /**< persistent socket */ bool active; + bool connected; void *async_io; /** async opaque ptr */ struct rdns_request *requests; /**< requests in flight */ uint64_t uses; 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); } |