Bug 753612 - Properly close wifi connection so 3G-data can get its own route. r=mrbkap,philipp

This commit is contained in:
Fabien Cazenave 2012-05-11 13:05:51 -07:00
parent 5184630926
commit 58a5606bda
3 changed files with 21 additions and 13 deletions

View File

@ -70,7 +70,7 @@ NetworkManager.prototype = {
debug("Network '" + network.name + "' changed state to " + network.state);
switch (network.state) {
case Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED:
case Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTING:
case Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED:
this.setAndConfigureActive();
break;
}
@ -142,6 +142,7 @@ NetworkManager.prototype = {
*/
setAndConfigureActive: function setAndConfigureActive() {
debug("Evaluating whether active network needs to be changed.");
let oldActive = this.active;
if (this._overriddenActive) {
debug("We have an override for the active network: " +
@ -149,19 +150,20 @@ NetworkManager.prototype = {
// The override was just set, so reconfigure the network.
if (this.active != this._overriddenActive) {
this.active = this._overriddenActive;
this.setDefaultRouteAndDNS();
this.setDefaultRouteAndDNS(oldActive);
}
return;
}
// If the active network is already of the preferred type, nothing to do.
if (this.active && this.active.type == this._preferredNetworkType) {
if (this.active &&
this.active.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED &&
this.active.type == this._preferredNetworkType) {
debug("Active network is already our preferred type. Not doing anything.");
return;
}
// Find a suitable network interface to activate.
let oldActive = this.active;
this.active = null;
for each (let network in this.networkInterfaces) {
if (network.state != Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED) {
@ -174,19 +176,18 @@ NetworkManager.prototype = {
}
}
if (this.active && (oldActive != this.active)) {
this.setDefaultRouteAndDNS();
this.setDefaultRouteAndDNS(oldActive);
}
},
setDefaultRouteAndDNS: function setDefaultRouteAndDNS() {
setDefaultRouteAndDNS: function setDefaultRouteAndDNS(oldInterface) {
debug("Going to change route and DNS to " + this.active.name);
if (this.active.dhcp) {
this.worker.postMessage({cmd: "runDHCPAndSetDefaultRouteAndDNS",
ifname: this.active.name});
} else {
this.worker.postMessage({cmd: "setDefaultRouteAndDNS",
ifname: this.active.name});
}
let options = {
cmd: this.active.dhcp ? "runDHCPAndSetDefaultRouteAndDNS" : "setDefaultRouteAndDNS",
ifname: this.active.name,
oldIfname: oldInterface ? oldInterface.name : null
};
this.worker.postMessage(options);
},
};

View File

@ -43,6 +43,10 @@ self.onmessage = function onmessage(event) {
* 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);
}
@ -63,6 +67,7 @@ function setDefaultRouteAndDNS(options) {
function runDHCPAndSetDefaultRouteAndDNS(options) {
let dhcp = libnetutils.dhcp_do_request(options.ifname);
dhcp.ifname = options.ifname;
dhcp.oldIfname = options.oldIfname;
//TODO this could be race-y... by the time we've finished the DHCP request
// and are now fudging with the routes, another network interface may have

View File

@ -730,6 +730,7 @@ var WifiManager = (function() {
if (eventData.indexOf("recv error") !== -1 && ++recvErrors < 10)
return true;
notifyStateChange({ state: "DISCONNECTED", BSSID: null, id: -1 });
notify("supplicantlost");
return false;
}
@ -841,6 +842,7 @@ var WifiManager = (function() {
manager.setWifiEnabled = function(enable, callback) {
if ((enable && manager.state !== "UNINITIALIZED") ||
(!enable && manager.state === "UNINITIALIZED")) {
callback(0);
return;
}