bug 1162821 - filter dns name collision records r=sworkman IGNORE IDL
authorPatrick McManus <mcmanus@ducksong.com>
Fri, 08 May 2015 14:18:20 -0400
changeset 243098 b6b1185fcb09
parent 243097 ab4feae9bff8
child 243099 30bfca777090
push id28720
push userphilringnalda@gmail.com
push dateSat, 09 May 2015 21:17:12 +0000
treeherdermozilla-central@30bfca777090 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs1162821
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1162821 - filter dns name collision records r=sworkman IGNORE IDL
netwerk/dns/DNS.cpp
netwerk/dns/DNS.h
netwerk/dns/GetAddrInfo.cpp
netwerk/dns/nsHostResolver.h
netwerk/dns/nsIDNSService.idl
--- a/netwerk/dns/DNS.cpp
+++ b/netwerk/dns/DNS.cpp
@@ -255,28 +255,32 @@ NetAddrElement::NetAddrElement(const Net
   mAddress = netAddr.mAddress;
 }
 
 NetAddrElement::~NetAddrElement()
 {
 }
 
 AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo,
-                   bool disableIPv4, const char *cname)
+                   bool disableIPv4, bool filterNameCollision, const char *cname)
 {
   MOZ_ASSERT(prAddrInfo, "Cannot construct AddrInfo with a null prAddrInfo pointer!");
+  const uint32_t nameCollisionAddr = htonl(0x7f003535); // 127.0.53.53
 
   Init(host, cname);
   PRNetAddr tmpAddr;
   void *iter = nullptr;
   do {
     iter = PR_EnumerateAddrInfo(iter, prAddrInfo, 0, &tmpAddr);
-    if (iter && (!disableIPv4 || tmpAddr.raw.family != PR_AF_INET)) {
-      NetAddrElement *addrElement = new NetAddrElement(&tmpAddr);
-      mAddresses.insertBack(addrElement);
+    bool addIt = iter &&
+        (!disableIPv4 || tmpAddr.raw.family != PR_AF_INET) &&
+        (!filterNameCollision || tmpAddr.raw.family != PR_AF_INET || (tmpAddr.inet.ip != nameCollisionAddr));
+    if (addIt) {
+        NetAddrElement *addrElement = new NetAddrElement(&tmpAddr);
+        mAddresses.insertBack(addrElement);
     }
   } while (iter);
 }
 
 AddrInfo::AddrInfo(const char *host, const char *cname)
 {
   Init(host, cname);
 }
--- a/netwerk/dns/DNS.h
+++ b/netwerk/dns/DNS.h
@@ -125,17 +125,17 @@ public:
   NetAddr mAddress;
 };
 
 class AddrInfo {
 public:
   // Creates an AddrInfo object. It calls the AddrInfo(const char*, const char*)
   // to initialize the host and the cname.
   AddrInfo(const char *host, const PRAddrInfo *prAddrInfo, bool disableIPv4,
-           const char *cname);
+           bool filterNameCollision, const char *cname);
 
   // Creates a basic AddrInfo object (initialize only the host and the cname).
   AddrInfo(const char *host, const char *cname);
   ~AddrInfo();
 
   void AddAddress(NetAddrElement *address);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
--- a/netwerk/dns/GetAddrInfo.cpp
+++ b/netwerk/dns/GetAddrInfo.cpp
@@ -323,17 +323,19 @@ static MOZ_ALWAYS_INLINE nsresult
     return NS_ERROR_UNKNOWN_HOST;
   }
 
   const char* canonName = nullptr;
   if (aFlags & nsHostResolver::RES_CANON_NAME) {
     canonName = PR_GetCanonNameFromAddrInfo(prai);
   }
 
-  nsAutoPtr<AddrInfo> ai(new AddrInfo(aCanonHost, prai, disableIPv4, canonName));
+  bool filterNameCollision = !(aFlags & nsHostResolver::RES_ALLOW_NAME_COLLISION);
+  nsAutoPtr<AddrInfo> ai(new AddrInfo(aCanonHost, prai, disableIPv4,
+                                      filterNameCollision, canonName));
   PR_FreeAddrInfo(prai);
   if (ai->mAddresses.isEmpty()) {
     return NS_ERROR_UNKNOWN_HOST;
   }
 
   *aAddrInfo = ai.forget();
 
   return NS_OK;
--- a/netwerk/dns/nsHostResolver.h
+++ b/netwerk/dns/nsHostResolver.h
@@ -280,17 +280,19 @@ public:
      */
     enum {
         RES_BYPASS_CACHE = 1 << 0,
         RES_CANON_NAME   = 1 << 1,
         RES_PRIORITY_MEDIUM   = 1 << 2,
         RES_PRIORITY_LOW  = 1 << 3,
         RES_SPECULATE     = 1 << 4,
         //RES_DISABLE_IPV6 = 1 << 5, // Not used
-        RES_OFFLINE       = 1 << 6
+        RES_OFFLINE       = 1 << 6,
+        //RES_DISABLE_IPv4 = 1 << 7, // Not Used
+        RES_ALLOW_NAME_COLLISION = 1 << 8
     };
 
     size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
 
     /**
      * Flush the DNS cache.
      */
     void FlushCache();
--- a/netwerk/dns/nsIDNSService.idl
+++ b/netwerk/dns/nsIDNSService.idl
@@ -158,9 +158,14 @@ interface nsIDNSService : nsISupports
      * asyncResolve.
      */
     const unsigned long RESOLVE_OFFLINE = (1 << 6);
 
     /**
      * If set, only IPv6 addresses will be returned from resolve/asyncResolve.
      */
     const unsigned long RESOLVE_DISABLE_IPV4 = (1 << 7);
+
+    /**
+     * If set, allow name collision results (127.0.53.53) which are normally filtered.
+     */
+    const unsigned long RESOLVE_ALLOW_NAME_COLLISION = (1 << 8);
 };