mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-22 17:39:53 +03:00
Merge pull request #1510 from domosekai/dns6
Fix DNS resolution when no IPv6 address is configured on any interface
This commit is contained in:
commit
a9239a6aab
@ -405,8 +405,15 @@ void DnsResolver(THREAD *t, void *param)
|
|||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
Zero(&hints, sizeof(hints));
|
Zero(&hints, sizeof(hints));
|
||||||
|
|
||||||
hints.ai_family = AF_INET6;
|
if (HasIPv6Address())
|
||||||
hints.ai_flags = AI_ALL | AI_ADDRCONFIG | AI_V4MAPPED;
|
{
|
||||||
|
hints.ai_family = AF_INET6;
|
||||||
|
hints.ai_flags = AI_ALL | AI_ADDRCONFIG | AI_V4MAPPED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
}
|
||||||
|
|
||||||
struct addrinfo *results;
|
struct addrinfo *results;
|
||||||
const int ret = getaddrinfo(resolver->Hostname, NULL, &hints, &results);
|
const int ret = getaddrinfo(resolver->Hostname, NULL, &hints, &results);
|
||||||
@ -417,18 +424,40 @@ void DnsResolver(THREAD *t, void *param)
|
|||||||
for (struct addrinfo *result = results; result != NULL; result = result->ai_next)
|
for (struct addrinfo *result = results; result != NULL; result = result->ai_next)
|
||||||
{
|
{
|
||||||
IP ip;
|
IP ip;
|
||||||
const struct sockaddr_in6 *in = (struct sockaddr_in6 *)result->ai_addr;
|
if (hints.ai_family == AF_INET6)
|
||||||
InAddrToIP6(&ip, &in->sin6_addr);
|
|
||||||
if (IsIP6(&ip) && ipv6_ok == false)
|
|
||||||
{
|
{
|
||||||
Copy(&resolver->IPv6, &ip, sizeof(resolver->IPv6));
|
const struct sockaddr_in6 *in = (struct sockaddr_in6 *)result->ai_addr;
|
||||||
resolver->IPv6.ipv6_scope_id = in->sin6_scope_id;
|
InAddrToIP6(&ip, &in->sin6_addr);
|
||||||
ipv6_ok = true;
|
if (IsIP6(&ip) && ipv6_ok == false)
|
||||||
|
{
|
||||||
|
Copy(&resolver->IPv6, &ip, sizeof(resolver->IPv6));
|
||||||
|
resolver->IPv6.ipv6_scope_id = in->sin6_scope_id;
|
||||||
|
ipv6_ok = true;
|
||||||
|
if (ipv4_ok)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (IsIP4(&ip) && ipv4_ok == false)
|
||||||
|
{
|
||||||
|
Copy(&resolver->IPv4, &ip, sizeof(resolver->IPv4));
|
||||||
|
ipv4_ok = true;
|
||||||
|
if (ipv6_ok)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (IsIP4(&ip) && ipv4_ok == false)
|
else
|
||||||
{
|
{
|
||||||
Copy(&resolver->IPv4, &ip, sizeof(resolver->IPv4));
|
const struct sockaddr_in *in = (struct sockaddr_in *)result->ai_addr;
|
||||||
ipv4_ok = true;
|
InAddrToIP(&ip, &in->sin_addr);
|
||||||
|
if (IsIP4(&ip))
|
||||||
|
{
|
||||||
|
Copy(&resolver->IPv4, &ip, sizeof(resolver->IPv4));
|
||||||
|
ipv4_ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9871,6 +9871,38 @@ bool IsIPv6Supported()
|
|||||||
#endif // NO_IPV6
|
#endif // NO_IPV6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether an IPv6 address is configured on any interface
|
||||||
|
bool HasIPv6Address()
|
||||||
|
{
|
||||||
|
LIST *o;
|
||||||
|
UINT i;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
o = GetHostIPAddressList();
|
||||||
|
|
||||||
|
ret = false;
|
||||||
|
|
||||||
|
for (i = 0; i < LIST_NUM(o); i++)
|
||||||
|
{
|
||||||
|
IP *p = LIST_DATA(o, i);
|
||||||
|
|
||||||
|
if (IsIP6(p))
|
||||||
|
{
|
||||||
|
UINT type = GetIPAddrType6(p);
|
||||||
|
if ((type & IPV6_ADDR_GLOBAL_UNICAST) && ((type & IPV6_ADDR_ZERO) == 0) && ((type & IPV6_ADDR_LOOPBACK) == 0))
|
||||||
|
{
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeHostIPAddressList(o);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Add the thread to the thread waiting list
|
// Add the thread to the thread waiting list
|
||||||
void AddWaitThread(THREAD *t)
|
void AddWaitThread(THREAD *t)
|
||||||
{
|
{
|
||||||
|
@ -1164,6 +1164,7 @@ SOCKLIST *NewSockList();
|
|||||||
void StopSockList(SOCKLIST *sl);
|
void StopSockList(SOCKLIST *sl);
|
||||||
void FreeSockList(SOCKLIST *sl);
|
void FreeSockList(SOCKLIST *sl);
|
||||||
bool IsIPv6Supported();
|
bool IsIPv6Supported();
|
||||||
|
bool HasIPv6Address();
|
||||||
void SetSockTos(SOCK *s, int tos);
|
void SetSockTos(SOCK *s, int tos);
|
||||||
void SetSockHighPriority(SOCK *s, bool flag);
|
void SetSockHighPriority(SOCK *s, bool flag);
|
||||||
void InitIpClientList();
|
void InitIpClientList();
|
||||||
|
Loading…
Reference in New Issue
Block a user