]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Rdns: Use flags for IO channels
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 1 Jan 2022 16:43:37 +0000 (16:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 1 Jan 2022 16:43:37 +0000 (16:43 +0000)
contrib/librdns/dns_private.h
contrib/librdns/resolver.c

index 19729f1e6cea832ef6e467cc0d8d4ff33c77509d..5d77cbebeb6f94b5ad56d4f74b6a9f29a7f556a4 100644 (file)
@@ -98,6 +98,16 @@ struct rdns_request {
 };
 
 
+enum rdns_io_channel_flags {
+       RDNS_CHANNEL_CONNECTED = 1u << 0u,
+       RDNS_CHANNEL_ACTIVE = 1u << 1u,
+       RDNS_CHANNEL_TCP = 1u << 2u,
+};
+
+#define IS_CHANNEL_CONNECTED(ioc) (((ioc)->flags & RDNS_CHANNEL_CONNECTED) != 0)
+#define IS_CHANNEL_ACTIVE(ioc) (((ioc)->flags & RDNS_CHANNEL_ACTIVE) != 0)
+
+
 /**
  * IO channel for a specific DNS server
  */
@@ -107,8 +117,7 @@ struct rdns_io_channel {
        struct sockaddr *saddr;
        socklen_t slen;
        int sock; /**< persistent socket                                          */
-       bool active;
-       bool connected;
+       int flags; /**< see enum rdns_io_channel_flags */
        void *async_io; /** async opaque ptr */
        struct rdns_request *requests; /**< requests in flight                                         */
        uint64_t uses;
@@ -131,7 +140,6 @@ struct rdns_fake_reply {
 
 struct rdns_resolver {
        struct rdns_server *servers;
-       struct rdns_io_channel *io_channels; /**< hash of io chains indexed by socket        */
        struct rdns_async_context *async; /** async callbacks */
        void *periodic; /** periodic event for resolver */
        struct rdns_upstream_context *ups;
index a0f09a294f05f0efbbc65fbdec6ef0ac909ea1ee..b100322b14464c2d3b598fb753ef521794f4ea13 100644 (file)
@@ -68,7 +68,7 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req)
        }
 
        if (resolver->curve_plugin == NULL) {
-               if (!req->io->connected) {
+               if (!IS_CHANNEL_CONNECTED(req->io)) {
                        r = sendto (fd, req->packet, req->pos, 0,
                                        req->io->saddr,
                                        req->io->slen);
@@ -78,7 +78,7 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req)
                }
        }
        else {
-               if (!req->io->connected) {
+               if (!IS_CHANNEL_CONNECTED(req->io)) {
                        r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
                                        resolver->curve_plugin->data,
                                        req->io->saddr,
@@ -111,7 +111,7 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req)
                        return -1;
                }
        }
-       else if (!req->io->connected) {
+       else if (!IS_CHANNEL_CONNECTED(req->io)) {
                /* Connect socket */
                r = connect (fd, req->io->saddr, req->io->slen);
 
@@ -120,7 +120,7 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req)
                                        strerror (errno), serv->name);
                }
                else {
-                       req->io->connected = true;
+                       req->io->flags |= RDNS_CHANNEL_CONNECTED;
                }
        }
 
@@ -356,7 +356,7 @@ rdns_process_timer (void *arg)
                return;
        }
 
-       if (!req->io->active || req->retransmits == 1) {
+       if (!IS_CHANNEL_ACTIVE(req->io) || req->retransmits == 1) {
 
                if (resolver->ups) {
                        cnt = resolver->ups->count (resolver->ups->data);
@@ -368,7 +368,7 @@ rdns_process_timer (void *arg)
                        }
                }
 
-               if (!req->io->active || cnt > 1) {
+               if (!IS_CHANNEL_ACTIVE(req->io) || cnt > 1) {
                        /* Do not reschedule IO requests on inactive sockets */
                        rdns_debug ("reschedule request with id: %d", (int)req->id);
                        rdns_request_unschedule (req);
@@ -493,7 +493,7 @@ rdns_process_ioc_refresh (void *arg)
                                                continue;
                                        }
                                        nioc->srv = serv;
-                                       nioc->active = true;
+                                       nioc->flags = RDNS_CHANNEL_ACTIVE;
                                        nioc->resolver = resolver;
                                        nioc->async_io = resolver->async->add_read (resolver->async->data,
                                                        nioc->sock, nioc);
@@ -501,7 +501,7 @@ rdns_process_ioc_refresh (void *arg)
                                        serv->io_channels[i] = nioc;
                                        rdns_debug ("scheduled io channel for server %s to be refreshed after "
                                                        "%lu usages", serv->name, (unsigned long)ioc->uses);
-                                       ioc->active = false;
+                                       ioc->flags &= ~RDNS_CHANNEL_ACTIVE;
                                        REF_RELEASE (ioc);
                                }
                        }
@@ -893,10 +893,10 @@ rdns_resolver_init (struct rdns_resolver *resolver)
                                        &ioc->saddr, &ioc->slen);
 
                        if (ioc->sock == -1) {
-                               ioc->active = false;
                                rdns_err ("cannot open socket to %s:%d %s",
                                                serv->name, serv->port, strerror (errno));
                                free (ioc);
+
                                return false;
                        }
                        else {