Bug 809006 - B2G Network Manager: Unable to set default route and DNS when required system properties not available. r=vicamo, a=blocking-basecamp
authorShian-Yow Wu <swu@mozilla.com>
Wed, 07 Nov 2012 15:12:52 +0800
changeset 116722 ba469d2bf081b605556a1302845e3393eff4b434
parent 116721 7c6eb01a102a475ada2d35037f2030adc30c8337
child 116723 c0f1dea0301535cd7b0459c166bfc3aed4347f7c
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo, blocking-basecamp
bugs809006
milestone18.0a2
Bug 809006 - B2G Network Manager: Unable to set default route and DNS when required system properties not available. r=vicamo, a=blocking-basecamp
dom/system/gonk/NetworkManager.js
dom/system/gonk/net_worker.js
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -384,17 +384,20 @@ NetworkManager.prototype = {
     Services.io.offline = !this.active;
   },
 
   setDefaultRouteAndDNS: function setDefaultRouteAndDNS(oldInterface) {
     debug("Going to change route and DNS to " + this.active.name);
     let options = {
       cmd: this.active.dhcp ? "runDHCPAndSetDefaultRouteAndDNS" : "setDefaultRouteAndDNS",
       ifname: this.active.name,
-      oldIfname: (oldInterface && oldInterface != this.active) ? oldInterface.name : null
+      oldIfname: (oldInterface && oldInterface != this.active) ? oldInterface.name : null,
+      gateway_str: this.active.gateway,
+      dns1_str: this.active.dns1,
+      dns2_str: this.active.dns2
     };
     this.worker.postMessage(options);
     this.setNetworkProxy();
   },
 
   removeDefaultRoute: function removeDefaultRoute(ifname) {
     debug("Remove default route for " + ifname);
     let options = {
--- a/dom/system/gonk/net_worker.js
+++ b/dom/system/gonk/net_worker.js
@@ -118,21 +118,19 @@ function networkInterfaceStatsSuccess(pa
 
 /**
  * Get network interface properties from the system property table.
  *
  * @param ifname
  *        Name of the network interface.
  */
 function getIFProperties(ifname) {
-  let gateway_str = libcutils.property_get("net." + ifname + ".gw");
   return {
     ifname:      ifname,
-    gateway:     netHelpers.stringToIP(gateway_str),
-    gateway_str: gateway_str,
+    gateway_str: libcutils.property_get("net." + ifname + ".gw"),
     dns1_str:    libcutils.property_get("net." + ifname + ".dns1"),
     dns2_str:    libcutils.property_get("net." + ifname + ".dns2"),
   };
 }
 
 /**
  * Routines accessible to the main thread.
  */
@@ -154,23 +152,25 @@ self.onmessage = function onmessage(even
 /**
  * Set default route and DNS servers for given network interface.
  */
 function setDefaultRouteAndDNS(options) {
   if (options.oldIfname) {
     libnetutils.ifc_remove_default_route(options.oldIfname);
   }
 
-  if (!options.gateway || !options.dns1_str) {
-    options = getIFProperties(options.ifname);
-  }
+  let ifprops = getIFProperties(options.ifname);
+  let gateway_str = options.gateway_str || ifprops.gateway_str;
+  let dns1_str = options.dns1_str || ifprops.dns1_str;
+  let dns2_str = options.dns2_str || ifprops.dns2_str;
+  let gateway = netHelpers.stringToIP(gateway_str);
 
-  libnetutils.ifc_set_default_route(options.ifname, options.gateway);
-  libcutils.property_set("net.dns1", options.dns1_str);
-  libcutils.property_set("net.dns2", options.dns2_str);
+  libnetutils.ifc_set_default_route(options.ifname, gateway);
+  libcutils.property_set("net.dns1", dns1_str);
+  libcutils.property_set("net.dns2", dns2_str);
 
   // Bump the DNS change property.
   let dnschange = libcutils.property_get("net.dnschange", "0");
   libcutils.property_set("net.dnschange", (parseInt(dnschange, 10) + 1).toString());
 }
 
 /**
  * Run DHCP and set default route and DNS servers for a given