From 74cd4ce0445f633872a3daa4dbaa60b9869d7da7 Mon Sep 17 00:00:00 2001 From: Jessica Jong Date: Wed, 23 Sep 2015 15:35:29 +0800 Subject: [PATCH] Bug 1174998 - Part 1: add setMtu() support in NetworkService. r=echen,smaug --HG-- extra : commitid : HTYjKaoJwgb --- dom/system/gonk/NetworkService.js | 14 +++++++++++ dom/system/gonk/NetworkUtils.cpp | 29 +++++++++++++++++++++ dom/system/gonk/NetworkUtils.h | 4 +++ dom/system/gonk/nsINetworkService.idl | 36 +++++++++++++++++++-------- dom/webidl/NetworkOptions.webidl | 2 ++ 5 files changed, 74 insertions(+), 11 deletions(-) diff --git a/dom/system/gonk/NetworkService.js b/dom/system/gonk/NetworkService.js index c7f5ab68b73a..e621bccc6af5 100644 --- a/dom/system/gonk/NetworkService.js +++ b/dom/system/gonk/NetworkService.js @@ -801,6 +801,20 @@ NetworkService.prototype = { }); }); }, + + setMtu: function (aInterfaceName, aMtu, aCallback) { + debug("Set MTU on " + aInterfaceName + ": " + aMtu); + + let params = { + cmd: "setMtu", + ifname: aInterfaceName, + mtu: aMtu + }; + + this.controlMessage(params, function(aResult) { + aCallback.nativeCommandResult(!aResult.error); + }); + } }; this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkService]); diff --git a/dom/system/gonk/NetworkUtils.cpp b/dom/system/gonk/NetworkUtils.cpp index cb7b84f485e5..f057556e2448 100644 --- a/dom/system/gonk/NetworkUtils.cpp +++ b/dom/system/gonk/NetworkUtils.cpp @@ -1438,6 +1438,17 @@ void NetworkUtils::disableIpv6(CommandChain* aChain, setIpv6Enabled(aChain, aCallback, aResult, false); } +void NetworkUtils::setMtu(CommandChain* aChain, + CommandCallback aCallback, + NetworkResultOptions& aResult) +{ + char command[MAX_COMMAND_SIZE]; + PR_snprintf(command, MAX_COMMAND_SIZE - 1, "interface setmtu %s %d", + GET_CHAR(mIfname), GET_FIELD(mMtu)); + + doCommand(command, aChain, aCallback); +} + #undef GET_CHAR #undef GET_FIELD @@ -1676,6 +1687,7 @@ void NetworkUtils::ExecuteCommand(NetworkParams aOptions) BUILD_ENTRY(createNetwork), BUILD_ENTRY(destroyNetwork), BUILD_ENTRY(getNetId), + BUILD_ENTRY(setMtu), #undef BUILD_ENTRY }; @@ -2714,6 +2726,23 @@ CommandResult NetworkUtils::getNetId(NetworkParams& aOptions) return result; } +CommandResult NetworkUtils::setMtu(NetworkParams& aOptions) +{ + // Setting/getting mtu is supported since Kitkat. + if (SDK_VERSION < 19) { + ERROR("setMtu is not supported in current SDK_VERSION."); + return -1; + } + + static CommandFunc COMMAND_CHAIN[] = { + setMtu, + defaultAsyncSuccessHandler, + }; + + runChain(aOptions, COMMAND_CHAIN, defaultAsyncFailureHandler); + return CommandResult::Pending(); +} + void NetworkUtils::sendBroadcastMessage(uint32_t code, char* reason) { NetworkResultOptions result; diff --git a/dom/system/gonk/NetworkUtils.h b/dom/system/gonk/NetworkUtils.h index 9f33e411712e..d78184fcc5dd 100644 --- a/dom/system/gonk/NetworkUtils.h +++ b/dom/system/gonk/NetworkUtils.h @@ -144,6 +144,7 @@ public: COPY_OPT_FIELD(mGateway_long, 0) COPY_OPT_FIELD(mDns1_long, 0) COPY_OPT_FIELD(mDns2_long, 0) + COPY_OPT_FIELD(mMtu, 0) mLoopIndex = 0; @@ -196,6 +197,7 @@ public: long mGateway_long; long mDns1_long; long mDns2_long; + long mMtu; // Auxiliary information required to carry accros command chain. int mNetId; // A locally defined id per interface. @@ -312,6 +314,7 @@ private: CommandResult createNetwork(NetworkParams& aOptions); CommandResult destroyNetwork(NetworkParams& aOptions); CommandResult getNetId(NetworkParams& aOptions); + CommandResult setMtu(NetworkParams& aOptions); CommandResult addHostRouteLegacy(NetworkParams& aOptions); CommandResult removeHostRouteLegacy(NetworkParams& aOptions); @@ -402,6 +405,7 @@ private: static void modifyRouteOnInterface(PARAMS, bool aDoAdd); static void enableIpv6(PARAMS); static void disableIpv6(PARAMS); + static void setMtu(PARAMS); static void setIpv6Enabled(PARAMS, bool aEnabled); static void addRouteToSecondaryTable(PARAMS); static void removeRouteFromSecondaryTable(PARAMS); diff --git a/dom/system/gonk/nsINetworkService.idl b/dom/system/gonk/nsINetworkService.idl index 5b988031a487..974fbd797a22 100644 --- a/dom/system/gonk/nsINetworkService.idl +++ b/dom/system/gonk/nsINetworkService.idl @@ -157,7 +157,7 @@ interface nsIDhcpRequestCallback : nsISupports /** * Provide network services. */ -[scriptable, uuid(fcd0abd4-8525-469f-a166-12edb4081f3e)] +[scriptable, uuid(8f689d9f-30c0-4809-8bf6-87120e71f3ee)] interface nsINetworkService : nsISupports { const long MODIFY_ROUTE_ADD = 0; @@ -482,9 +482,9 @@ interface nsINetworkService : nsISupports in nsINativeCommandCallback callback); /** - * Reset all connections + * Reset all connections on a specified network interface. * - * @param networkInterface + * @param interfaceName * The network interface name which we want to reset. * * @param callback @@ -494,25 +494,25 @@ interface nsINetworkService : nsISupports in nsINativeCommandCallback callback); /** - * Create network (required to call prior to any networking operation) + * Create network (required to call prior to any networking operation). * - * @param networkInterface - * The network interface name which we want to reset. + * @param interfaceName + * The network interface name which we want to create network for. * * @param callback - * Callback to notify the result of resetting connections. + * Callback to notify the result of creating network. */ void createNetwork(in DOMString interfaceName, in nsINativeCommandCallback callback); /** - * Destroy network (required to call prior to any networking operation) + * Destroy network. * - * @param networkInterface - * The network interface name which we want to reset. + * @param interfaceName + * The network interface name of the network we want to destroy. * * @param callback - * Callback to notify the result of resetting connections. + * Callback to notify the result of destroying network. */ void destroyNetwork(in DOMString interfaceName, in nsINativeCommandCallback callback); @@ -529,4 +529,18 @@ interface nsINetworkService : nsISupports * */ jsval getNetId(in DOMString interfaceName); + + /** + * Set maximum transmission unit on a network interface. + * + * @param interfaceName + * The name of the network interface that we want to set mtu. + * @param mtu + * Size of maximum tranmission unit. + * + * @param callback + * Callback to notify the result of setting mtu. + */ + void setMtu(in DOMString interfaceName, in long mtu, + in nsINativeCommandCallback callback); }; diff --git a/dom/webidl/NetworkOptions.webidl b/dom/webidl/NetworkOptions.webidl index c6c91f042d6d..ab5e67983081 100644 --- a/dom/webidl/NetworkOptions.webidl +++ b/dom/webidl/NetworkOptions.webidl @@ -54,6 +54,8 @@ dictionary NetworkCommandOptions long gateway_long; // for "ifc_configure". long dns1_long; // for "ifc_configure". long dns2_long; // for "ifc_configure". + + long mtu; // for "setMtu". }; /**