]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Connect UDP sockets when send was successful
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Apr 2019 12:36:53 +0000 (13:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Apr 2019 12:36:53 +0000 (13:36 +0100)
contrib/librdns/curve.c
contrib/librdns/dns_private.h
contrib/librdns/resolver.c

index a4bc154183a11cc47118e465b1d067a90211c662..f53d078b220711fbfc8810ccaf5da7a135d5caca 100644 (file)
@@ -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 */
index 3d25d21b8afa03a854e27cbbde2eb04a424c1089..f734e231201b605ab007bfad75a3ef896f3930c4 100644 (file)
@@ -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;
index 3130a5c964d788d471d7ad4789b62a1bfcef424d..2cc3695a747bc5d120da3aa9d389429c25f1d857 100644 (file)
@@ -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);
                }