diff --git a/include/fluent-bit/flb_network.h b/include/fluent-bit/flb_network.h index 76fac1b20a2..24a7d6f191d 100644 --- a/include/fluent-bit/flb_network.h +++ b/include/fluent-bit/flb_network.h @@ -77,6 +77,9 @@ struct flb_net_setup { /* prioritize ipv4 results when trying to establish a connection*/ int dns_prefer_ipv4; + /* prioritize ipv6 results when trying to establish a connection*/ + int dns_prefer_ipv6; + /* maximum number of allowed active TCP connections */ int max_worker_connections; }; diff --git a/src/flb_network.c b/src/flb_network.c index b6773c6e601..5b62a697535 100644 --- a/src/flb_network.c +++ b/src/flb_network.c @@ -104,6 +104,7 @@ void flb_net_setup_init(struct flb_net_setup *net) net->dns_mode = NULL; net->dns_resolver = NULL; net->dns_prefer_ipv4 = FLB_FALSE; + net->dns_prefer_ipv6 = FLB_FALSE; net->keepalive = FLB_TRUE; net->keepalive_idle_timeout = 30; net->keepalive_max_recycle = 0; @@ -1268,7 +1269,23 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port, sorted_res = flb_net_sort_addrinfo_list(res, AF_INET); if (sorted_res == NULL) { - flb_debug("[net] error sorting getaddrinfo results"); + flb_debug("[net] error sorting ipv4 getaddrinfo results"); + + if (use_async_dns) { + flb_net_free_translated_addrinfo(res); + } + else { + freeaddrinfo(res); + } + + return -1; + } + } + else if (u_conn->net->dns_prefer_ipv6) { + sorted_res = flb_net_sort_addrinfo_list(res, AF_INET6); + + if (sorted_res == NULL) { + flb_debug("[net] error sorting ipv6 getaddrinfo results"); if (use_async_dns) { flb_net_free_translated_addrinfo(res);