зеркало из https://github.com/mozilla/gecko-dev.git
Bug 762426 - B2G network manager: support multiple simultaneously connected network interfaces. r=philikon
This commit is contained in:
Родитель
92cbfb4790
Коммит
e313daecc3
|
@ -156,7 +156,19 @@ NetworkManager.prototype = {
|
|||
debug("Network " + network.name + " changed state to " + network.state);
|
||||
switch (network.state) {
|
||||
case Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED:
|
||||
// Add host route on secondary APN
|
||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||
this.addHostRoute(network);
|
||||
}
|
||||
this.setAndConfigureActive();
|
||||
break;
|
||||
case Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED:
|
||||
// Remove host route on secondary APN
|
||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||
this.removeHostRoute(network);
|
||||
}
|
||||
this.setAndConfigureActive();
|
||||
break;
|
||||
}
|
||||
|
@ -185,6 +197,11 @@ NetworkManager.prototype = {
|
|||
Cr.NS_ERROR_INVALID_ARG);
|
||||
}
|
||||
this.networkInterfaces[network.name] = network;
|
||||
// Add host route on secondary APN
|
||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||
this.addHostRoute(network);
|
||||
}
|
||||
this.setAndConfigureActive();
|
||||
Services.obs.notifyObservers(network, TOPIC_INTERFACE_REGISTERED, null);
|
||||
debug("Network '" + network.name + "' registered.");
|
||||
|
@ -200,6 +217,11 @@ NetworkManager.prototype = {
|
|||
Cr.NS_ERROR_INVALID_ARG);
|
||||
}
|
||||
delete this.networkInterfaces[network.name];
|
||||
// Remove host route on secondary APN
|
||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||
this.removeHostRoute(network);
|
||||
}
|
||||
this.setAndConfigureActive();
|
||||
Services.obs.notifyObservers(network, TOPIC_INTERFACE_UNREGISTERED, null);
|
||||
debug("Network '" + network.name + "' unregistered.");
|
||||
|
@ -263,6 +285,12 @@ NetworkManager.prototype = {
|
|||
// The override was just set, so reconfigure the network.
|
||||
if (this.active != this._overriddenActive) {
|
||||
this.active = this._overriddenActive;
|
||||
// Don't set default route and DNS on secondary APN
|
||||
if (oldActive &&
|
||||
(oldActive.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||
oldActive.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL)) {
|
||||
return;
|
||||
}
|
||||
this.setDefaultRouteAndDNS(oldActive);
|
||||
}
|
||||
return;
|
||||
|
@ -289,6 +317,12 @@ NetworkManager.prototype = {
|
|||
}
|
||||
}
|
||||
if (this.active) {
|
||||
// Don't set default route and DNS on secondary APN
|
||||
if (oldActive &&
|
||||
(oldActive.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||
oldActive.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL)) {
|
||||
return;
|
||||
}
|
||||
this.setDefaultRouteAndDNS(oldActive);
|
||||
}
|
||||
Services.io.offline = !this.active;
|
||||
|
@ -305,6 +339,34 @@ NetworkManager.prototype = {
|
|||
this.setNetworkProxy();
|
||||
},
|
||||
|
||||
addHostRoute: function addHostRoute(network) {
|
||||
debug("Going to add host route on " + network.name);
|
||||
let options = {
|
||||
cmd: "addHostRoute",
|
||||
ifname: network.name,
|
||||
dns1: network.dns1,
|
||||
dns2: network.dns2,
|
||||
gateway: network.gateway,
|
||||
httpproxy: network.httpProxyHost,
|
||||
mmsproxy: Services.prefs.getCharPref("ril.data.mmsproxy")
|
||||
};
|
||||
this.worker.postMessage(options);
|
||||
},
|
||||
|
||||
removeHostRoute: function removeHostRoute(network) {
|
||||
debug("Going to remove host route on " + network.name);
|
||||
let options = {
|
||||
cmd: "removeHostRoute",
|
||||
ifname: network.name,
|
||||
dns1: network.dns1,
|
||||
dns2: network.dns2,
|
||||
gateway: network.gateway,
|
||||
httpproxy: network.httpProxyHost,
|
||||
mmsproxy: Services.prefs.getCharPref("ril.data.mmsproxy")
|
||||
};
|
||||
this.worker.postMessage(options);
|
||||
},
|
||||
|
||||
setNetworkProxy: function setNetworkProxy() {
|
||||
try {
|
||||
if (!this.active.httpProxyHost || this.active.httpProxyHost == "") {
|
||||
|
|
|
@ -1757,9 +1757,10 @@ let RILNetworkInterface = {
|
|||
|
||||
state: Ci.nsINetworkInterface.NETWORK_STATE_UNKNOWN,
|
||||
|
||||
NETWORK_TYPE_WIFI: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
NETWORK_TYPE_MOBILE: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
|
||||
NETWORK_TYPE_MOBILE_MMS: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS,
|
||||
NETWORK_TYPE_WIFI: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
NETWORK_TYPE_MOBILE: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
|
||||
NETWORK_TYPE_MOBILE_MMS: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS,
|
||||
NETWORK_TYPE_MOBILE_SUPL: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL,
|
||||
|
||||
/**
|
||||
* Standard values for the APN connection retry process
|
||||
|
|
|
@ -166,6 +166,26 @@ function runDHCPAndSetDefaultRouteAndDNS(options) {
|
|||
setDefaultRouteAndDNS(dhcp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add host route for given network interface.
|
||||
*/
|
||||
function addHostRoute(options) {
|
||||
libnetutils.ifc_add_route(options.ifname, options.dns1, 32, options.gateway);
|
||||
libnetutils.ifc_add_route(options.ifname, options.dns2, 32, options.gateway);
|
||||
libnetutils.ifc_add_route(options.ifname, options.httpproxy, 32, options.gateway);
|
||||
libnetutils.ifc_add_route(options.ifname, options.mmsproxy, 32, options.gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove host route for given network interface.
|
||||
*/
|
||||
function removeHostRoute(options) {
|
||||
libnetutils.ifc_remove_route(options.ifname, options.dns1, 32, options.gateway);
|
||||
libnetutils.ifc_remove_route(options.ifname, options.dns2, 32, options.gateway);
|
||||
libnetutils.ifc_remove_route(options.ifname, options.httpproxy, 32, options.gateway);
|
||||
libnetutils.ifc_remove_route(options.ifname, options.mmsproxy, 32, options.gateway);
|
||||
}
|
||||
|
||||
let gCommandQueue = [];
|
||||
let gCurrentCommand = null;
|
||||
let gCurrentCallback = null;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
/**
|
||||
* Information about networks that is exposed to network manager API consumers.
|
||||
*/
|
||||
[scriptable, uuid(463ed2f3-1739-41bc-a967-1e816764f915)]
|
||||
[scriptable, uuid(d70b9d95-87d5-4ce9-aff7-4323dac79b07)]
|
||||
interface nsINetworkInterface : nsISupports
|
||||
{
|
||||
const long NETWORK_STATE_UNKNOWN = -1;
|
||||
|
@ -27,6 +27,7 @@ interface nsINetworkInterface : nsISupports
|
|||
const long NETWORK_TYPE_WIFI = 0;
|
||||
const long NETWORK_TYPE_MOBILE = 1;
|
||||
const long NETWORK_TYPE_MOBILE_MMS = 2;
|
||||
const long NETWORK_TYPE_MOBILE_SUPL = 3;
|
||||
|
||||
/**
|
||||
* Network type. One of the NETWORK_TYPE_* constants.
|
||||
|
|
|
@ -157,6 +157,18 @@ let libnetutils = (function () {
|
|||
ctypes.int,
|
||||
ctypes.int,
|
||||
ctypes.int),
|
||||
ifc_add_route: library.declare("ifc_add_route", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.char.ptr, // dst
|
||||
ctypes.int, // prefix_length
|
||||
ctypes.char.ptr), // gw
|
||||
ifc_remove_route: library.declare("ifc_remove_route", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.char.ptr, // dst
|
||||
ctypes.int, // prefix_length
|
||||
ctypes.char.ptr), // gw
|
||||
dhcp_stop: library.declare("dhcp_stop", ctypes.default_abi,
|
||||
ctypes.int,
|
||||
ctypes.char.ptr),
|
||||
|
|
|
@ -1380,9 +1380,10 @@ let WifiNetworkInterface = {
|
|||
|
||||
state: Ci.nsINetworkInterface.NETWORK_STATE_UNKNOWN,
|
||||
|
||||
NETWORK_TYPE_WIFI: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
NETWORK_TYPE_MOBILE: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
|
||||
NETWORK_TYPE_MOBILE_MMS: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS,
|
||||
NETWORK_TYPE_WIFI: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
NETWORK_TYPE_MOBILE: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
|
||||
NETWORK_TYPE_MOBILE_MMS: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS,
|
||||
NETWORK_TYPE_MOBILE_SUPL: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL,
|
||||
|
||||
type: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче