summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-01 16:43:37 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-01 16:43:37 +0000
commit64ea2a9a90d392777141eba37acb611e9fa0ba24 (patch)
tree817de817a605599c1405c0336125d63b9f443490 /contrib
parent1acb4ba50c7344332a2b35d118c6f34d9f7edaff (diff)
downloadrspamd-64ea2a9a90d392777141eba37acb611e9fa0ba24.tar.gz
rspamd-64ea2a9a90d392777141eba37acb611e9fa0ba24.zip
[Minor] Rdns: Use flags for IO channels
Diffstat (limited to 'contrib')
-rw-r--r--contrib/librdns/dns_private.h14
-rw-r--r--contrib/librdns/resolver.c18
2 files changed, 20 insertions, 12 deletions
diff --git a/contrib/librdns/dns_private.h b/contrib/librdns/dns_private.h
index 19729f1e6..5d77cbebe 100644
--- a/contrib/librdns/dns_private.h
+++ b/contrib/librdns/dns_private.h
@@ -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;
diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c
index a0f09a294..b100322b1 100644
--- a/contrib/librdns/resolver.c
+++ b/contrib/librdns/resolver.c
@@ -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 {