diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index 5408adc66492..d06858b19c73 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -1403,19 +1403,14 @@ nsHostResolver::ThreadFunc(void *arg) bool getTtl = false; #endif - // 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; - nsresult status = GetAddrInfo(rec->host, af, rec->flags, rec->netInterface, + nsresult status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface, &ai, getTtl); #if defined(RES_RETRY_ON_FAILURE) if (NS_FAILED(status) && rs.Reset()) { - status = GetAddrInfo(rec->host, af, rec->flags, rec->netInterface, &ai, + status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface, &ai, getTtl); } #endif - TimeDuration elapsed = TimeStamp::Now() - startTime; uint32_t millis = static_cast(elapsed.ToMilliseconds()); diff --git a/netwerk/test/unit/test_dns_disable_ipv4.js b/netwerk/test/unit/test_dns_disable_ipv4.js new file mode 100644 index 000000000000..ec334b1f6da5 --- /dev/null +++ b/netwerk/test/unit/test_dns_disable_ipv4.js @@ -0,0 +1,40 @@ +// +// Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV4 flag doesn't +// return any IPv4 addresses. +// + +var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); +var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); + +var listener = { + onLookupComplete: function(inRequest, inRecord, inStatus) { + if (inStatus != Cr.NS_OK) { + do_check_eq(inStatus, Cr.NS_ERROR_UNKNOWN_HOST); + do_test_finished(); + return; + } + + while (true) { + try { + var answer = inRecord.getNextAddrAsString(); + // If there is an answer it should be an IPv6 address + dump(answer); + do_check_true(answer.indexOf(':') != -1); + } catch (e) { + break; + } + } + do_test_finished(); + } +}; + +function run_test() { + do_test_pending(); + try { + dns.asyncResolve("example.org", Ci.nsIDNSService.RESOLVE_DISABLE_IPV4, listener, null); + } catch (e) { + dump(e); + do_check_true(false); + do_test_finished(); + } +} diff --git a/netwerk/test/unit/test_dns_disable_ipv6.js b/netwerk/test/unit/test_dns_disable_ipv6.js new file mode 100644 index 000000000000..af5558d53e0e --- /dev/null +++ b/netwerk/test/unit/test_dns_disable_ipv6.js @@ -0,0 +1,41 @@ +// +// Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV6 flag doesn't +// return any IPv6 addresses. +// + +var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); +var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); + +var listener = { + onLookupComplete: function(inRequest, inRecord, inStatus) { + if (inStatus != Cr.NS_OK) { + do_check_eq(inStatus, Cr.NS_ERROR_UNKNOWN_HOST); + do_test_finished(); + return; + } + + while (true) { + try { + var answer = inRecord.getNextAddrAsString(); + // If there is an answer it should be an IPv4 address + dump(answer); + do_check_true(answer.indexOf(':') == -1); + do_check_true(answer.indexOf('.') != -1); + } catch (e) { + break; + } + } + do_test_finished(); + } +}; + +function run_test() { + do_test_pending(); + try { + dns.asyncResolve("example.com", Ci.nsIDNSService.RESOLVE_DISABLE_IPV6, listener, null); + } catch (e) { + dump(e); + do_check_true(false); + do_test_finished(); + } +} diff --git a/netwerk/test/unit/xpcshell.ini b/netwerk/test/unit/xpcshell.ini index 2605c11dfde1..f35f5e5bc0d1 100644 --- a/netwerk/test/unit/xpcshell.ini +++ b/netwerk/test/unit/xpcshell.ini @@ -324,3 +324,5 @@ skip-if = os == "android" [test_packaged_app_service.js] [test_suspend_channel_before_connect.js] [test_inhibit_caching.js] +[test_dns_disable_ipv4.js] +[test_dns_disable_ipv6.js]