Bug 1589447 - Add network id change event on Linux and Android, r=kershaw,valentin
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 14 Nov 2019 13:37:50 +0000
changeset 501934 20eae859997faaff797e2c925531a4075d077175
parent 501933 3a1f314c3022866babf30d8899f3d19af4f91389
child 501935 474430e7ea37c836c40d3fb9f93a3566f7e36af1
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskershaw, valentin
bugs1589447
milestone72.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 1589447 - Add network id change event on Linux and Android, r=kershaw,valentin This patch adds network ID change event to Linux and Android. On these platforms network ID change event is equal to network change event. Differential Revision: https://phabricator.services.mozilla.com/D50391
netwerk/system/android/nsAndroidNetworkLinkService.cpp
netwerk/system/android/nsAndroidNetworkLinkService.h
netwerk/system/linux/nsNetworkLinkService.cpp
netwerk/system/linux/nsNetworkLinkService.h
netwerk/system/netlink/NetlinkService.cpp
netwerk/system/netlink/NetlinkService.h
--- a/netwerk/system/android/nsAndroidNetworkLinkService.cpp
+++ b/netwerk/system/android/nsAndroidNetworkLinkService.cpp
@@ -148,16 +148,23 @@ void nsAndroidNetworkLinkService::OnNetw
 
     RefPtr<nsAndroidNetworkLinkService> self = this;
     NS_DispatchToMainThread(NS_NewRunnableFunction(
         "nsAndroidNetworkLinkService::OnNetworkChanged",
         [self]() { self->SendEvent(NS_NETWORK_LINK_DATA_CHANGED); }));
   }
 }
 
+void nsAndroidNetworkLinkService::OnNetworkIDChanged() {
+  RefPtr<nsAndroidNetworkLinkService> self = this;
+  NS_DispatchToMainThread(NS_NewRunnableFunction(
+      "nsAndroidNetworkLinkService::OnNetworkIDChanged",
+      [self]() { self->SendEvent(NS_NETWORK_LINK_DATA_NETWORKID_CHANGED); }));
+}
+
 void nsAndroidNetworkLinkService::OnLinkUp() {
   RefPtr<nsAndroidNetworkLinkService> self = this;
   NS_DispatchToMainThread(NS_NewRunnableFunction(
       "nsAndroidNetworkLinkService::OnLinkUp",
       [self]() { self->SendEvent(NS_NETWORK_LINK_DATA_UP); }));
 }
 
 void nsAndroidNetworkLinkService::OnLinkDown() {
--- a/netwerk/system/android/nsAndroidNetworkLinkService.h
+++ b/netwerk/system/android/nsAndroidNetworkLinkService.h
@@ -21,16 +21,17 @@ class nsAndroidNetworkLinkService
   NS_DECL_NSINETWORKLINKSERVICE
   NS_DECL_NSIOBSERVER
 
   nsAndroidNetworkLinkService();
 
   nsresult Init();
 
   void OnNetworkChanged() override;
+  void OnNetworkIDChanged() override;
   void OnLinkUp() override;
   void OnLinkDown() override;
   void OnLinkStatusKnown() override;
 
  private:
   virtual ~nsAndroidNetworkLinkService() = default;
 
   // Called when xpcom-shutdown-threads is received.
--- a/netwerk/system/linux/nsNetworkLinkService.cpp
+++ b/netwerk/system/linux/nsNetworkLinkService.cpp
@@ -128,16 +128,23 @@ void nsNetworkLinkService::OnNetworkChan
 
     RefPtr<nsNetworkLinkService> self = this;
     NS_DispatchToMainThread(NS_NewRunnableFunction(
         "nsNetworkLinkService::OnNetworkChanged",
         [self]() { self->SendEvent(NS_NETWORK_LINK_DATA_CHANGED); }));
   }
 }
 
+void nsNetworkLinkService::OnNetworkIDChanged() {
+  RefPtr<nsNetworkLinkService> self = this;
+  NS_DispatchToMainThread(NS_NewRunnableFunction(
+      "nsNetworkLinkService::OnNetworkIDChanged",
+      [self]() { self->SendEvent(NS_NETWORK_LINK_DATA_NETWORKID_CHANGED); }));
+}
+
 void nsNetworkLinkService::OnLinkUp() {
   RefPtr<nsNetworkLinkService> self = this;
   NS_DispatchToMainThread(NS_NewRunnableFunction(
       "nsNetworkLinkService::OnLinkUp",
       [self]() { self->SendEvent(NS_NETWORK_LINK_DATA_UP); }));
 }
 
 void nsNetworkLinkService::OnLinkDown() {
--- a/netwerk/system/linux/nsNetworkLinkService.h
+++ b/netwerk/system/linux/nsNetworkLinkService.h
@@ -20,16 +20,17 @@ class nsNetworkLinkService : public nsIN
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSINETWORKLINKSERVICE
   NS_DECL_NSIOBSERVER
 
   nsNetworkLinkService();
   nsresult Init();
 
   void OnNetworkChanged() override;
+  void OnNetworkIDChanged() override;
   void OnLinkUp() override;
   void OnLinkDown() override;
   void OnLinkStatusKnown() override;
 
  private:
   virtual ~nsNetworkLinkService() = default;
 
   // Called when xpcom-shutdown-threads is received.
--- a/netwerk/system/netlink/NetlinkService.cpp
+++ b/netwerk/system/netlink/NetlinkService.cpp
@@ -819,19 +819,20 @@ void NetlinkService::OnAddrMessage(struc
   if (!linkInfo) {
     // This can happen during startup
     LOG(("Cannot find link info [ifIdx=%u, addr=%s/%u", ifIdx, addrStr.get(),
          address->GetPrefixLen()));
     return;
   }
 
   // There might be already an equal address in the array even in case of
-  // RTM_NEWADDR message, e.g. when lifetime of IPv6 address is renewed. Remove
-  // existing equal address in case of RTM_DELADDR as well as RTM_NEWADDR
-  // message and add a new one in the latter case.
+  // RTM_NEWADDR message, e.g. when lifetime of IPv6 address is renewed. Equal
+  // in this case means that IP and prefix is the same but some attributes might
+  // be different. Remove existing equal address in case of RTM_DELADDR as well
+  // as RTM_NEWADDR message and add a new one in the latter case.
   for (uint32_t i = 0; i < linkInfo->mAddresses.Length(); ++i) {
     if (linkInfo->mAddresses[i]->Equals(address)) {
       LOG(("Removing address [ifIdx=%u, addr=%s/%u]", ifIdx, addrStr.get(),
            address->GetPrefixLen()));
       linkInfo->mAddresses.RemoveElementAt(i);
       break;
     }
   }
@@ -870,25 +871,17 @@ void NetlinkService::OnAddrMessage(struc
 #else
         LOG(("Removing neighbor"));
 #endif
         iter.Remove();
       }
     }
   }
 
-  if (linkInfo->UpdateStatus()) {
-    TriggerNetworkIDCalculation();
-  } else {
-    // Even if the link status hasn't changed, network ID might have changed
-    // if it's an address change on a link that's up.
-    if (linkInfo->mLink->IsUp()) {
-      TriggerNetworkIDCalculation();
-    }
-  }
+  TriggerNetworkIDCalculation();
 }
 
 void NetlinkService::OnRouteMessage(struct nlmsghdr* aNlh) {
   LOG(("NetlinkService::OnRouteMessage [type=%s]",
        aNlh->nlmsg_type == RTM_NEWROUTE ? "new" : "del"));
 
   nsAutoPtr<NetlinkRoute> route(new NetlinkRoute());
   if (!route->Init(aNlh)) {
@@ -1789,16 +1782,17 @@ void NetlinkService::CalculateNetworkID(
 
   if (idChanged && !initialIDCalculation) {
     RefPtr<NetlinkServiceListener> listener;
     {
       MutexAutoLock lock(mMutex);
       listener = mListener;
     }
     if (listener) {
+      listener->OnNetworkIDChanged();
       listener->OnNetworkChanged();
     }
   }
 
   initialIDCalculation = false;
 }
 
 void NetlinkService::GetNetworkID(nsACString& aNetworkID) {
--- a/netwerk/system/netlink/NetlinkService.h
+++ b/netwerk/system/netlink/NetlinkService.h
@@ -30,16 +30,17 @@ class NetlinkAddress;
 class NetlinkNeighbor;
 class NetlinkLink;
 class NetlinkRoute;
 class NetlinkMsg;
 
 class NetlinkServiceListener : public nsISupports {
  public:
   virtual void OnNetworkChanged() = 0;
+  virtual void OnNetworkIDChanged() = 0;
   virtual void OnLinkUp() = 0;
   virtual void OnLinkDown() = 0;
   virtual void OnLinkStatusKnown() = 0;
 
  protected:
   virtual ~NetlinkServiceListener() = default;
 };