Bug 1558840 - Add nsINetworkLinkService.dnsSuffixList implementation for windows r=mayhemer
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 10 Oct 2019 16:21:19 +0000
changeset 497305 71e49603ed69ca06aa1ff437b0e534153480f5cf
parent 497304 b085b41c10ce17ce0315234a48292e14513bca6f
child 497306 d5a6d3421d546b79418ddd279e8dc24b739e2cff
push id36682
push userncsoregi@mozilla.com
push dateSat, 12 Oct 2019 09:52:03 +0000
treeherdermozilla-central@06ea2371f897 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1558840
milestone71.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 1558840 - Add nsINetworkLinkService.dnsSuffixList implementation for windows r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D48556
modules/libpref/init/StaticPrefList.yaml
netwerk/base/nsINetworkLinkService.idl
netwerk/system/android/nsAndroidNetworkLinkService.cpp
netwerk/system/linux/nsNetworkLinkService.cpp
netwerk/system/mac/nsNetworkLinkService.mm
netwerk/system/win32/nsNotifyAddrListener.cpp
netwerk/system/win32/nsNotifyAddrListener.h
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -6542,16 +6542,22 @@
   type: RelaxedAtomicBool
 # ifdef XP_WIN
   value: false
 # else
   value: true
 # endif
   mirror: always
 
+# Whether to check the dnsSuffix on network changes
+- name: network.notify.dnsSuffixList
+  type: RelaxedAtomicBool
+  value: true
+  mirror: always
+
 # IP addresses that are used by netlink service to check whether default route
 # is used for outgoing traffic. They are used just to check routing rules,
 # no packets are sent to those hosts. Initially, addresses of host
 # detectportal.firefox.com were used but they don't necessarily need to be
 # updated when addresses of this host change.
 - name: network.netlink.route.check.IPv4
   type: String
   value: "23.219.91.27"
--- a/netwerk/base/nsINetworkLinkService.idl
+++ b/netwerk/base/nsINetworkLinkService.idl
@@ -46,16 +46,21 @@ interface nsINetworkLinkService : nsISup
    */
   readonly attribute unsigned long linkType;
 
   /**
    * A string uniquely identifying the current active network interfaces.
    * Empty when there are no active network interfaces.
    */
   readonly attribute ACString networkID;
+
+  /**
+   * The list of DNS suffixes for the currently active network interfaces.
+   */
+  readonly attribute Array<ACString> dnsSuffixList;
 };
 
 %{C++
 /**
  * We send notifications through nsIObserverService with topic
  * NS_NETWORK_LINK_TOPIC whenever one of isLinkUp or linkStatusKnown
  * changes. We pass one of the NS_NETWORK_LINK_DATA_ constants below
  * as the aData parameter of the notification.
--- a/netwerk/system/android/nsAndroidNetworkLinkService.cpp
+++ b/netwerk/system/android/nsAndroidNetworkLinkService.cpp
@@ -126,16 +126,22 @@ nsAndroidNetworkLinkService::GetNetworkI
   if (!mNetlinkSvc) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   mNetlinkSvc->GetNetworkID(aNetworkID);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsAndroidNetworkLinkService::GetDnsSuffixList(
+    nsTArray<nsCString>& aDnsSuffixList) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
 void nsAndroidNetworkLinkService::OnNetworkChanged() {
   if (mozilla::StaticPrefs::network_notify_changed()) {
     if (!mNetworkChangeTime.IsNull()) {
       mozilla::Telemetry::AccumulateTimeDelta(
           mozilla::Telemetry::NETWORK_TIME_BETWEEN_NETWORK_CHANGE_EVENTS,
           mNetworkChangeTime);
     }
     mNetworkChangeTime = mozilla::TimeStamp::Now();
--- a/netwerk/system/linux/nsNetworkLinkService.cpp
+++ b/netwerk/system/linux/nsNetworkLinkService.cpp
@@ -54,16 +54,21 @@ nsNetworkLinkService::GetNetworkID(nsACS
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   mNetlinkSvc->GetNetworkID(aNetworkID);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsNetworkLinkService::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 nsNetworkLinkService::Observe(nsISupports* subject, const char* topic,
                               const char16_t* data) {
   if (!strcmp("xpcom-shutdown-threads", topic)) {
     Shutdown();
   }
 
   return NS_OK;
 }
--- a/netwerk/system/mac/nsNetworkLinkService.mm
+++ b/netwerk/system/mac/nsNetworkLinkService.mm
@@ -106,16 +106,21 @@ nsNetworkLinkService::GetLinkType(uint32
 
 NS_IMETHODIMP
 nsNetworkLinkService::GetNetworkID(nsACString& aNetworkID) {
   MutexAutoLock lock(mMutex);
   aNetworkID = mNetworkId;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsNetworkLinkService::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
 #ifndef SA_SIZE
 #  define SA_SIZE(sa)                                 \
     ((!(sa) || ((struct sockaddr*)(sa))->sa_len == 0) \
          ? sizeof(uint32_t)                           \
          : 1 + ((((struct sockaddr*)(sa))->sa_len - 1) | (sizeof(uint32_t) - 1)))
 #endif
 
 static bool getMac(struct sockaddr_dl* sdl, char* buf, size_t bufsize) {
--- a/netwerk/system/win32/nsNotifyAddrListener.cpp
+++ b/netwerk/system/win32/nsNotifyAddrListener.cpp
@@ -156,16 +156,24 @@ nsNotifyAddrListener::GetLinkType(uint32
 
 NS_IMETHODIMP
 nsNotifyAddrListener::GetNetworkID(nsACString& aNetworkID) {
   MutexAutoLock lock(mMutex);
   aNetworkID = mNetworkId;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsNotifyAddrListener::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
+  aDnsSuffixList.Clear();
+  MutexAutoLock lock(mMutex);
+  aDnsSuffixList.AppendElements(mDnsSuffixList);
+  return NS_OK;
+}
+
 //
 // Hash the sorted network ids
 //
 void nsNotifyAddrListener::HashSortedNetworkIds(std::vector<GUID> nwGUIDS,
                                                 SHA1Sum& sha1) {
   std::sort(nwGUIDS.begin(), nwGUIDS.end(), [](const GUID& a, const GUID& b) {
     return memcmp(&a, &b, sizeof(GUID)) < 0;
   });
@@ -587,16 +595,18 @@ 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 sumAll = 0;
 
+  nsTArray<nsCString> dnsSuffixList;
+
   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 ||
@@ -614,31 +624,45 @@ nsNotifyAddrListener::CheckAdaptersAddre
       // 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];
         }
       }
+
+      if (StaticPrefs::network_notify_dnsSuffixList()) {
+        nsCString suffix = NS_ConvertUTF16toUTF8(adapter->DnsSuffix);
+        if (!suffix.IsEmpty()) {
+          LOG(("  found DNS suffix=%s\n", suffix.get()));
+          dnsSuffixList.AppendElement(suffix);
+        }
+      }
+
       linkUp = true;
       sumAll ^= sum;
     }
     mLinkUp = linkUp;
     mStatusKnown = true;
   }
   free(adapterList);
 
   if (mLinkUp) {
     /* Store the checksum only if one or more interfaces are up */
     mIPInterfaceChecksum = sumAll;
   }
 
   CoUninitialize();
 
+  if (StaticPrefs::network_notify_dnsSuffixList()) {
+    MutexAutoLock lock(mMutex);
+    mDnsSuffixList.SwapElements(dnsSuffixList);
+  }
+
   calculateNetworkId();
 
   return ret;
 }
 
 /**
  * Checks the status of all network adapters.  If one is up and has a valid IP
  * address, sets mLinkUp to true.  Sets mStatusKnown to true if the link status
--- a/netwerk/system/win32/nsNotifyAddrListener.h
+++ b/netwerk/system/win32/nsNotifyAddrListener.h
@@ -76,16 +76,17 @@ class nsNotifyAddrListener : public nsIN
   nsresult NetworkChanged();
 
   // Figure out the current network identification
   void calculateNetworkId(void);
   bool findMac(char* gateway);
 
   mozilla::Mutex mMutex;
   nsCString mNetworkId;
+  nsTArray<nsCString> mDnsSuffixList;
 
   HANDLE mCheckEvent;
 
   // set true when mCheckEvent means shutdown
   bool mShutdown;
 
   // This is a checksum of various meta data for all network interfaces
   // considered UP at last check.