Bug 1175817 - [NetworkManager] remove old default routes explicitly. r=echen,smaug
authorJessica Jong <jjong@mozilla.com>
Fri, 11 Sep 2015 15:26:58 +0800
changeset 294842 249a0976312db313758331110fd216f6c89250e7
parent 294841 dce452074fb75daca43fbc0ac207202de537ccc7
child 294843 f2065d4a08982f0bf86b439f67b11a5a04ce7272
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechen, smaug
bugs1175817
milestone43.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 1175817 - [NetworkManager] remove old default routes explicitly. r=echen,smaug
dom/system/gonk/NetworkManager.js
dom/system/gonk/NetworkService.js
dom/system/gonk/NetworkUtils.cpp
dom/system/gonk/NetworkUtils.h
dom/system/gonk/nsINetworkService.idl
dom/webidl/NetworkOptions.webidl
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -988,23 +988,28 @@ NetworkManager.prototype = {
           debug("removeDefaultRoute failed");
         }
         // Always resolve.
         aResolve();
       });
     });
   },
 
-  _setDefaultRouteAndProxy: function(aNetwork, aOldInterface) {
+  _setDefaultRouteAndProxy: function(aNetwork, aOldNetwork) {
+    if (aOldNetwork) {
+      return this._removeDefaultRoute(aOldNetwork.info)
+        .then(() => this._setDefaultRouteAndProxy(aNetwork, null));
+    }
+
     return new Promise((aResolve, aReject) => {
       let networkInfo = aNetwork.info;
       let gateways = networkInfo.getGateways();
-      let oldInterfaceName = (aOldInterface ? aOldInterface.info.name : "");
+
       gNetworkService.setDefaultRoute(networkInfo.name, gateways.length, gateways,
-                                      oldInterfaceName, (aSuccess) => {
+                                      (aSuccess) => {
         if (!aSuccess) {
           gNetworkService.destroyNetwork(networkInfo.name, function() {
             aReject("setDefaultRoute failed");
           });
           return;
         }
         this.setNetworkProxy(aNetwork);
         aResolve();
--- a/dom/system/gonk/NetworkService.js
+++ b/dom/system/gonk/NetworkService.js
@@ -458,24 +458,21 @@ NetworkService.prototype = {
       dnses: aDnses,
       gateways: aGateways
     };
     this.controlMessage(options, function(aResult) {
       aCallback.setDnsResult(aResult.success ? null : aResult.reason);
     });
   },
 
-  setDefaultRoute: function(aInterfaceName, aCount, aGateways,
-                            aOldInterfaceName, aCallback) {
+  setDefaultRoute: function(aInterfaceName, aCount, aGateways, aCallback) {
     debug("Going to change default route to " + aInterfaceName);
     let options = {
       cmd: "setDefaultRoute",
       ifname: aInterfaceName,
-      oldIfname: (aOldInterfaceName && aOldInterfaceName !== aInterfaceName) ?
-                 aOldInterfaceName : null,
       gateways: aGateways
     };
     this.controlMessage(options, function(aResult) {
       aCallback.nativeCommandResult(!aResult.error);
     });
   },
 
   removeDefaultRoute: function(aInterfaceName, aCount, aGateways, aCallback) {
--- a/dom/system/gonk/NetworkUtils.cpp
+++ b/dom/system/gonk/NetworkUtils.cpp
@@ -2002,23 +2002,16 @@ CommandResult NetworkUtils::setDefaultRo
 
 /**
  * Set default route and DNS servers for given network interface by obsoleted libnetutils.
  */
 CommandResult NetworkUtils::setDefaultRouteLegacy(NetworkParams& aOptions)
 {
   NS_ConvertUTF16toUTF8 autoIfname(aOptions.mIfname);
 
-  if (!aOptions.mOldIfname.IsEmpty()) {
-    // Remove IPv4's default route.
-    WARN_IF_FAILED(mNetUtils->do_ifc_remove_default_route(GET_CHAR(mOldIfname)));
-    // Remove IPv6's default route.
-    WARN_IF_FAILED(mNetUtils->do_ifc_remove_route(GET_CHAR(mOldIfname), "::", 0, NULL));
-  }
-
   uint32_t length = aOptions.mGateways.Length();
   if (length > 0) {
     for (uint32_t i = 0; i < length; i++) {
       NS_ConvertUTF16toUTF8 autoGateway(aOptions.mGateways[i]);
 
       int type = getIpType(autoGateway.get());
       if (type != AF_INET && type != AF_INET6) {
         continue;
--- a/dom/system/gonk/NetworkUtils.h
+++ b/dom/system/gonk/NetworkUtils.h
@@ -105,17 +105,16 @@ public:
     COPY_FIELD(mId)
     COPY_FIELD(mCmd)
     COPY_OPT_STRING_FIELD(mDomain, EmptyString())
     COPY_OPT_STRING_FIELD(mGateway, EmptyString())
     COPY_SEQUENCE_FIELD(mGateways, nsString)
     COPY_OPT_STRING_FIELD(mIfname, EmptyString())
     COPY_OPT_STRING_FIELD(mIp, EmptyString())
     COPY_OPT_FIELD(mPrefixLength, 0)
-    COPY_OPT_STRING_FIELD(mOldIfname, EmptyString())
     COPY_OPT_STRING_FIELD(mMode, EmptyString())
     COPY_OPT_FIELD(mReport, false)
     COPY_OPT_FIELD(mEnabled, false)
     COPY_OPT_STRING_FIELD(mWifictrlinterfacename, EmptyString())
     COPY_OPT_STRING_FIELD(mInternalIfname, EmptyString())
     COPY_OPT_STRING_FIELD(mExternalIfname, EmptyString())
     COPY_OPT_FIELD(mEnable, false)
     COPY_OPT_STRING_FIELD(mSsid, EmptyString())
@@ -158,17 +157,16 @@ public:
   int32_t mId;
   nsString mCmd;
   nsString mDomain;
   nsString mGateway;
   nsTArray<nsString> mGateways;
   nsString mIfname;
   nsString mIp;
   uint32_t mPrefixLength;
-  nsString mOldIfname;
   nsString mMode;
   bool mReport;
   bool mEnabled;
   nsString mWifictrlinterfacename;
   nsString mInternalIfname;
   nsString mExternalIfname;
   bool mEnable;
   nsString mSsid;
--- a/dom/system/gonk/nsINetworkService.idl
+++ b/dom/system/gonk/nsINetworkService.idl
@@ -152,17 +152,17 @@ interface nsIDhcpRequestCallback : nsISu
    */
   void dhcpRequestResult(in boolean success, in jsval dhcpInfo);
 };
 
 
 /**
  * Provide network services.
  */
-[scriptable, uuid(5d6b1877-890a-4c7f-8403-94d57ceba6cf)]
+[scriptable, uuid(fcd0abd4-8525-469f-a166-12edb4081f3e)]
 interface nsINetworkService : nsISupports
 {
   const long MODIFY_ROUTE_ADD    = 0;
   const long MODIFY_ROUTE_REMOVE = 1;
 
   /**
    * Enable or disable Wifi Tethering
    *
@@ -305,26 +305,23 @@ interface nsINetworkService : nsISupport
    * Set default route.
    *
    * @param interfaceName
    *        The network interface name of the default route we want to set.
    * @param count
    *        Number of elements in gateways.
    * @param gateways
    *        Default gateways for setting default route.
-   * @param oldInterfaceName
-   *        The previous network interface name.
    *
    * @param callback
    *        Callback to notify the result of setting default route.
    */
   void setDefaultRoute(in DOMString interfaceName,
                        in unsigned long count,
                        [array, size_is(count)] in wstring gateways,
-                       in DOMString oldInterfaceName,
                        in nsINativeCommandCallback callback);
 
   /**
    * Remove default route.
    *
    * @param interfaceName
    *        The network interface name of the default route we want to remove.
    * @param count
--- a/dom/webidl/NetworkOptions.webidl
+++ b/dom/webidl/NetworkOptions.webidl
@@ -12,17 +12,16 @@ dictionary NetworkCommandOptions
   DOMString ifname;                   // for "removeNetworkRoute", "setDNS",
                                       //     "setDefaultRouteAndDNS", "removeDefaultRoute"
                                       //     "addHostRoute", "removeHostRoute"
                                       //     "removeHostRoutes".
   DOMString ip;                       // for "removeNetworkRoute", "setWifiTethering".
   unsigned long prefixLength;         // for "removeNetworkRoute".
   DOMString domain;                   // for "setDNS"
   sequence<DOMString> dnses;          // for "setDNS", "setDefaultRouteAndDNS".
-  DOMString oldIfname;                // for "setDefaultRouteAndDNS".
   DOMString gateway;                  // for "addSecondaryRoute", "removeSecondaryRoute".
   sequence<DOMString> gateways;       // for "setDefaultRouteAndDNS", "removeDefaultRoute".
   DOMString mode;                     // for "setWifiOperationMode".
   boolean report;                     // for "setWifiOperationMode".
   boolean enabled;                    // for "setDhcpServer".
   DOMString wifictrlinterfacename;    // for "setWifiTethering".
   DOMString internalIfname;           // for "setWifiTethering".
   DOMString externalIfname;           // for "setWifiTethering".