Bug 1321841 - Better checksum for "live" adapters. r=bagder
authorLiang-Heng Chen <xeonchen@gmail.com>
Wed, 18 Jan 2017 05:40:00 -0500
changeset 358170 111109712e7700e8544d0da27589016662d48399
parent 358169 fe7445d0ec0a017bb016fad6a21ae8f1d5bf0984
child 358171 bbbbcc7e8a1bf0b432f22a04994d920a091c591f
push id10621
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 16:02:43 +0000
treeherdermozilla-aurora@dca7b42e6c67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1321841
milestone53.0a1
Bug 1321841 - Better checksum for "live" adapters. r=bagder MozReview-Commit-ID: Ldql5weiLyy
netwerk/system/win32/nsNotifyAddrListener.cpp
--- a/netwerk/system/win32/nsNotifyAddrListener.cpp
+++ b/netwerk/system/win32/nsNotifyAddrListener.cpp
@@ -630,55 +630,57 @@ nsNotifyAddrListener::CheckAdaptersAddre
     }
 
     //
     // Since NotifyIpInterfaceChange() signals a change more often than we
     // think is a worthy change, we checksum the entire state of all interfaces
     // that are UP. If the checksum is the same as previous check, nothing
     // of interest changed!
     //
-    ULONG sum = 0;
+    ULONG sumAll = 0;
 
     if (ret == ERROR_SUCCESS) {
         bool linkUp = false;
+        ULONG sum = 0;
 
         for (PIP_ADAPTER_ADDRESSES adapter = adapterList; adapter;
              adapter = adapter->Next) {
             if (adapter->OperStatus != IfOperStatusUp ||
                 !adapter->FirstUnicastAddress ||
                 adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK ||
                 CheckICSGateway(adapter) ) {
                 continue;
             }
 
+            sum <<= 2;
             // Add chars from AdapterName to the checksum.
             for (int i = 0; adapter->AdapterName[i]; ++i) {
-                sum <<= 2;
                 sum += adapter->AdapterName[i];
             }
 
             // Add bytes from each socket address to the checksum.
             for (PIP_ADAPTER_UNICAST_ADDRESS pip = adapter->FirstUnicastAddress;
                  pip; pip = pip->Next) {
                 SOCKET_ADDRESS *sockAddr = &pip->Address;
                 for (int i = 0; i < sockAddr->iSockaddrLength; ++i) {
                     sum += (reinterpret_cast<unsigned char *>
                             (sockAddr->lpSockaddr))[i];
                 }
             }
             linkUp = true;
+            sumAll ^= sum;
         }
         mLinkUp = linkUp;
         mStatusKnown = true;
     }
     free(adapterList);
 
     if (mLinkUp) {
         /* Store the checksum only if one or more interfaces are up */
-        mIPInterfaceChecksum = sum;
+        mIPInterfaceChecksum = sumAll;
     }
 
     CoUninitialize();
 
     return ret;
 }
 
 /**