Skip to content

Commit

Permalink
check for ipv6 in resolver to avoid global init order problems (fix #557
Browse files Browse the repository at this point in the history
, fix #562)
  • Loading branch information
lavv17 committed Jan 11, 2020
1 parent af9fde5 commit 5d34493
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
15 changes: 14 additions & 1 deletion src/Resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ int Resolver::FindAddressFamily(const char *name)
return -1;
}

bool Resolver::IsAddressFamilySupporded(int af)
{
#if INET6
// check if ipv6 is really supported
if(af==AF_INET6 && (!FindGlobalIPv6Address() || !CanCreateIpv6Socket()))
{
LogNote(4, "IPv6 is not supported or configured");
return false;
}
#endif // INET6
return true;
}

void Resolver::ParseOrder(const char *s,int *o)
{
const char * const delim="\t ";
Expand All @@ -364,7 +377,7 @@ void Resolver::ParseOrder(const char *s,int *o)
for(s1=strtok(s1,delim); s1; s1=strtok(0,delim))
{
int af=FindAddressFamily(s1);
if(af!=-1 && idx<15)
if(af!=-1 && idx<15 && IsAddressFamilySupporded(af))
{
if(o) o[idx]=af;
idx++;
Expand Down
3 changes: 2 additions & 1 deletion src/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "Cache.h"
#include "network.h"

class Resolver : public SMTask, protected ProtoLog
class Resolver : public SMTask, protected ProtoLog, protected Networker
{
xstring hostname;
xstring portname;
Expand All @@ -53,6 +53,7 @@ class Resolver : public SMTask, protected ProtoLog
void DoGethostbyname();

static int FindAddressFamily(const char *name);
static bool IsAddressFamilySupporded(int af);
static void ParseOrder(const char *s,int *o);

void LookupOne(const char *name);
Expand Down
15 changes: 1 addition & 14 deletions src/network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ const char *Networker::FindGlobalIPv6Address()
return 0;
}

static bool CanCreateIpv6Socket()
bool Networker::CanCreateIpv6Socket()
{
#if INET6
bool can=true;
Expand All @@ -472,16 +472,3 @@ static bool CanCreateIpv6Socket()
return false;
#endif
}

static struct NetworkInit : private Networker {
NetworkInit();
} NETWORK_INIT;

NetworkInit::NetworkInit()
{
#if INET6
// check if ipv6 is really supported
if(!Networker::FindGlobalIPv6Address() || !CanCreateIpv6Socket())
ResMgr::Set("dns:order",0,"inet");
#endif // INET6
}
1 change: 1 addition & 0 deletions src/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class Networker
static int SocketCreateUnboundTCP(int af,const char *hostname);
static void SocketSinglePF(int sock,int pf);
static const char *FindGlobalIPv6Address();
static bool CanCreateIpv6Socket();
};

#endif //NETWORK_H

0 comments on commit 5d34493

Please sign in to comment.