Bug 825501 - Remove IPv4 records manually because PR_GetAddrInfoByName dislike PR_AF_INET6. r=honzab

This commit is contained in:
Masatoshi Kimura 2013-01-25 08:30:12 +09:00
parent dd097c3d3f
commit 4cce0eb3d2
3 changed files with 18 additions and 8 deletions

View File

@ -175,7 +175,8 @@ NetAddrElement::~NetAddrElement()
{
}
AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo)
AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo,
bool disableIPv4)
{
size_t hostlen = strlen(host);
mHostName = static_cast<char*>(moz_xmalloc(hostlen + 1));
@ -185,7 +186,7 @@ AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo)
void *iter = nullptr;
do {
iter = PR_EnumerateAddrInfo(iter, prAddrInfo, 0, &tmpAddr);
if (iter) {
if (iter && (!disableIPv4 || tmpAddr.raw.family != PR_AF_INET)) {
NetAddrElement *addrElement = new NetAddrElement(&tmpAddr);
mAddresses.insertBack(addrElement);
}

View File

@ -121,7 +121,7 @@ public:
class AddrInfo {
public:
AddrInfo(const char *host, const PRAddrInfo *prAddrInfo);
AddrInfo(const char *host, const PRAddrInfo *prAddrInfo, bool disableIPv4);
~AddrInfo();
char *mHostName;

View File

@ -980,10 +980,14 @@ nsHostResolver::ThreadFunc(void *arg)
TimeStamp startTime = TimeStamp::Now();
prai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
// We need to remove IPv4 records manually
// because PR_GetAddrInfoByName doesn't support PR_AF_INET6.
bool disableIPv4 = rec->af == PR_AF_INET6;
uint16_t af = disableIPv4 ? PR_AF_UNSPEC : rec->af;
prai = PR_GetAddrInfoByName(rec->host, af, flags);
#if defined(RES_RETRY_ON_FAILURE)
if (!prai && rs.Reset())
prai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
prai = PR_GetAddrInfoByName(rec->host, af, flags);
#endif
TimeDuration elapsed = TimeStamp::Now() - startTime;
@ -993,9 +997,14 @@ nsHostResolver::ThreadFunc(void *arg)
nsresult status;
AddrInfo *ai = nullptr;
if (prai) {
ai = new AddrInfo(rec->host, prai);
ai = new AddrInfo(rec->host, prai, disableIPv4);
PR_FreeAddrInfo(prai);
if (ai->mAddresses.isEmpty()) {
delete ai;
ai = nullptr;
}
}
if (ai) {
status = NS_OK;
Telemetry::Accumulate(!rec->addr_info_gencnt ?