diff options
Diffstat (limited to 'src/libnetdata/socket')
-rw-r--r-- | src/libnetdata/socket/socket.c | 18 | ||||
-rw-r--r-- | src/libnetdata/socket/socket.h | 9 |
2 files changed, 24 insertions, 3 deletions
diff --git a/src/libnetdata/socket/socket.c b/src/libnetdata/socket/socket.c index 7170a3963..85f67a2ba 100644 --- a/src/libnetdata/socket/socket.c +++ b/src/libnetdata/socket/socket.c @@ -839,7 +839,15 @@ static inline int connect_to_unix(const char *path, struct timeval *timeout) { // service the service name or port to connect to // timeout the timeout for establishing a connection -int connect_to_this_ip46(int protocol, int socktype, const char *host, uint32_t scope_id, const char *service, struct timeval *timeout) { +int connect_to_this_ip46( + int protocol, + int socktype, + const char *host, + uint32_t scope_id, + const char *service, + struct timeval *timeout, + bool *fallback_ipv4) +{ struct addrinfo hints; struct addrinfo *ai_head = NULL, *ai = NULL; @@ -872,6 +880,9 @@ int connect_to_this_ip46(int protocol, int socktype, const char *host, uint32_t for (ai = ai_head; ai != NULL && fd == -1; ai = ai->ai_next) { if(nd_thread_signaled_to_cancel()) break; + if (fallback_ipv4 && *fallback_ipv4 && ai->ai_family == PF_INET6) + continue; + if (ai->ai_family == PF_INET6) { struct sockaddr_in6 *pSadrIn6 = (struct sockaddr_in6 *) ai->ai_addr; if(pSadrIn6->sin6_scope_id == 0) { @@ -953,6 +964,9 @@ int connect_to_this_ip46(int protocol, int socktype, const char *host, uint32_t close(fd); fd = -1; + + if (fallback_ipv4 && ai->ai_family == PF_INET6) + *fallback_ipv4 = true; break; default: @@ -1074,7 +1088,7 @@ int connect_to_this(const char *definition, int default_port, struct timeval *ti service = default_service; - return connect_to_this_ip46(protocol, socktype, host, scope_id, service, timeout); + return connect_to_this_ip46(protocol, socktype, host, scope_id, service, timeout,NULL); } void foreach_entry_in_connection_string(const char *destination, bool (*callback)(char *entry, void *data), void *data) { diff --git a/src/libnetdata/socket/socket.h b/src/libnetdata/socket/socket.h index 8eab8bfdd..8147c9774 100644 --- a/src/libnetdata/socket/socket.h +++ b/src/libnetdata/socket/socket.h @@ -33,7 +33,14 @@ int listen_sockets_setup(LISTEN_SOCKETS *sockets); void listen_sockets_close(LISTEN_SOCKETS *sockets); void foreach_entry_in_connection_string(const char *destination, bool (*callback)(char *entry, void *data), void *data); -int connect_to_this_ip46(int protocol, int socktype, const char *host, uint32_t scope_id, const char *service, struct timeval *timeout); +int connect_to_this_ip46( + int protocol, + int socktype, + const char *host, + uint32_t scope_id, + const char *service, + struct timeval *timeout, + bool *fallback_ipv4); int connect_to_this(const char *definition, int default_port, struct timeval *timeout); int connect_to_one_of(const char *destination, int default_port, struct timeval *timeout, size_t *reconnects_counter, char *connected_to, size_t connected_to_size); int connect_to_one_of_urls(const char *destination, int default_port, struct timeval *timeout, size_t *reconnects_counter, char *connected_to, size_t connected_to_size); |