aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-18 23:41:13 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-18 23:41:13 +0100
commitc70116611f001ff7990431e2abdc078bec4e4f4b (patch)
treebf954ed4d68f0396db4d94851eb7e36694067633 /src/libutil/util.c
parent83b35fdc4dc6694b1eb1a66d3aba896e207987da (diff)
downloadrspamd-c70116611f001ff7990431e2abdc078bec4e4f4b.tar.gz
rspamd-c70116611f001ff7990431e2abdc078bec4e4f4b.zip
[Minor] Always prefer IPv4 when resolving addresses
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r--src/libutil/util.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 29c12ca2f..d55a8e8ac 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -83,6 +83,7 @@
#include "cryptobox.h"
#include "zlib.h"
+#include "contrib/uthash/utlist.h"
/* Check log messages intensity once per minute */
#define CHECK_TIME 60
@@ -418,6 +419,12 @@ out:
return (-1);
}
+static int
+rspamd_prefer_v4_hack (const struct addrinfo *a1, const struct addrinfo *a2)
+{
+ return a1->ai_addr->sa_family - a2->ai_addr->sa_family;
+}
+
/**
* Make a universal socket
* @param credits host, ip or path to unix socket
@@ -480,6 +487,7 @@ rspamd_socket (const gchar *credits, guint16 port,
rspamd_snprintf (portbuf, sizeof (portbuf), "%d", (int)port);
if ((r = getaddrinfo (credits, portbuf, &hints, &res)) == 0) {
+ LL_SORT2 (res, rspamd_prefer_v4_hack, ai_next);
r = rspamd_inet_socket_create (type, res, is_server, async, NULL);
freeaddrinfo (res);
return r;
@@ -572,7 +580,9 @@ rspamd_sockets_list (const gchar *credits, guint16 port,
rspamd_snprintf (portbuf, sizeof (portbuf), "%d", (int)port);
if ((r = getaddrinfo (credits, portbuf, &hints, &res)) == 0) {
- fd = rspamd_inet_socket_create (type, res, is_server, async, &result);
+ LL_SORT2 (res, rspamd_prefer_v4_hack, ai_next);
+ fd = rspamd_inet_socket_create (type, res, is_server, async,
+ &result);
freeaddrinfo (res);
if (result == NULL) {