Bug 1174998 - Part 1: add setMtu() support in NetworkService. r=echen,smaug
authorJessica Jong <jjong@mozilla.com>
Wed, 23 Sep 2015 15:35:29 +0800
changeset 264048 88018925cf28f9ccfd9ee9677fd2741671eae28a
parent 264047 9fd8cdf1d7db6dd03102cd6e8d483bdeff990a6d
child 264049 e3de9e349f1da6c70dff1fc33b09dfff42820784
push id65512
push userkwierso@gmail.com
push dateWed, 23 Sep 2015 20:23:51 +0000
treeherdermozilla-inbound@b00078e693a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechen, smaug
bugs1174998
milestone44.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 1174998 - Part 1: add setMtu() support in NetworkService. r=echen,smaug
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/NetworkService.js
+++ b/dom/system/gonk/NetworkService.js
@@ -796,11 +796,25 @@ NetworkService.prototype = {
         if (result.error) {
           aReject(result.reason);
           return;
         }
         aResolve(result.netId);
       });
     });
   },
+
+  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]);
--- a/dom/system/gonk/NetworkUtils.cpp
+++ b/dom/system/gonk/NetworkUtils.cpp
@@ -1433,16 +1433,27 @@ void NetworkUtils::enableIpv6(CommandCha
 
 void NetworkUtils::disableIpv6(CommandChain* aChain,
                                CommandCallback aCallback,
                                NetworkResultOptions& aResult)
 {
   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
 
 /*
  * Netd command success/fail function
  */
 #define ASSIGN_FIELD(prop)  aResult.prop = aChain->getParams().prop;
 #define ASSIGN_FIELD_VALUE(prop, value)  aResult.prop = value;
@@ -1671,16 +1682,17 @@ void NetworkUtils::ExecuteCommand(Networ
     BUILD_ENTRY(dhcpRequest),
     BUILD_ENTRY(stopDhcp),
     BUILD_ENTRY(enableInterface),
     BUILD_ENTRY(disableInterface),
     BUILD_ENTRY(resetConnections),
     BUILD_ENTRY(createNetwork),
     BUILD_ENTRY(destroyNetwork),
     BUILD_ENTRY(getNetId),
+    BUILD_ENTRY(setMtu),
 
     #undef BUILD_ENTRY
   };
 
   // Loop until we find the command name which matches aOptions.mCmd.
   CommandHandler handler = nullptr;
   for (size_t i = 0; i < mozilla::ArrayLength(COMMAND_HANDLER_TABLE); i++) {
     if (aOptions.mCmd.EqualsASCII(COMMAND_HANDLER_TABLE[i].mCommandName)) {
@@ -2709,16 +2721,33 @@ CommandResult NetworkUtils::getNetId(Net
   NetIdManager::NetIdInfo netIdInfo;
   if (-1 == mNetIdManager.lookup(GET_FIELD(mIfname), &netIdInfo)) {
     return ESRCH;
   }
   result.mNetId.AppendInt(netIdInfo.mNetId, 10);
   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;
   switch(code) {
     case NETD_COMMAND_INTERFACE_CHANGE:
       result.mTopic = NS_ConvertUTF8toUTF16("netd-interface-change");
       break;
     case NETD_COMMAND_BANDWIDTH_CONTROLLER:
--- a/dom/system/gonk/NetworkUtils.h
+++ b/dom/system/gonk/NetworkUtils.h
@@ -139,16 +139,17 @@ public:
     COPY_OPT_STRING_FIELD(mCurInternalIfname, EmptyString())
     COPY_OPT_STRING_FIELD(mCurExternalIfname, EmptyString())
     COPY_OPT_FIELD(mThreshold, -1)
     COPY_OPT_FIELD(mIpaddr, 0)
     COPY_OPT_FIELD(mMask, 0)
     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;
 
 #undef COPY_SEQUENCE_FIELD
 #undef COPY_OPT_STRING_FIELD
 #undef COPY_OPT_FIELD
 #undef COPY_FIELD
   }
@@ -191,16 +192,17 @@ public:
   nsString mCurInternalIfname;
   nsString mCurExternalIfname;
   long mThreshold;
   long mIpaddr;
   long mMask;
   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.
   uint32_t mLoopIndex; // Loop index for adding/removing multiple gateways.
 };
 
 // CommandChain store the necessary information to execute command one by one.
 // Including :
@@ -307,16 +309,17 @@ private:
   CommandResult setDhcpServer(NetworkParams& aOptions);
   CommandResult setWifiTethering(NetworkParams& aOptions);
   CommandResult setUSBTethering(NetworkParams& aOptions);
   CommandResult enableUsbRndis(NetworkParams& aOptions);
   CommandResult updateUpStream(NetworkParams& aOptions);
   CommandResult createNetwork(NetworkParams& aOptions);
   CommandResult destroyNetwork(NetworkParams& aOptions);
   CommandResult getNetId(NetworkParams& aOptions);
+  CommandResult setMtu(NetworkParams& aOptions);
 
   CommandResult addHostRouteLegacy(NetworkParams& aOptions);
   CommandResult removeHostRouteLegacy(NetworkParams& aOptions);
   CommandResult setDefaultRouteLegacy(NetworkParams& aOptions);
   CommandResult removeDefaultRouteLegacy(NetworkParams& aOptions);
   CommandResult removeNetworkRouteLegacy(NetworkParams& aOptions);
 
 
@@ -397,16 +400,17 @@ private:
   static void removeDefaultRoute(PARAMS);
   static void removeNetworkRouteSuccess(PARAMS);
   static void removeNetworkRoute(PARAMS);
   static void addRouteToInterface(PARAMS);
   static void removeRouteFromInterface(PARAMS);
   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);
   static void defaultAsyncSuccessHandler(PARAMS);
 
 #undef PARAMS
 
   /**
--- 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(fcd0abd4-8525-469f-a166-12edb4081f3e)]
+[scriptable, uuid(8f689d9f-30c0-4809-8bf6-87120e71f3ee)]
 interface nsINetworkService : nsISupports
 {
   const long MODIFY_ROUTE_ADD    = 0;
   const long MODIFY_ROUTE_REMOVE = 1;
 
   /**
    * Enable or disable Wifi Tethering
    *
@@ -477,56 +477,70 @@ interface nsINetworkService : nsISupport
    *
    * @param callback
    *        Callback to notify the result of disabling network interface.
    */
   void disableInterface(in DOMString interfaceName,
                         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
    *        Callback to notify the result of resetting connections.
    */
   void resetConnections(in DOMString interfaceName,
                         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);
 
   /**
    * Query the netId associated with given network interface name.
    *
    * @param interfaceName
    *        The network interface name which we want to query.
    *
    * @return A deferred promise that resolves with a string to indicate.
    *         the queried netId on success and rejects if the interface name
    *         is invalid.
    *
    */
   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);
 };
--- a/dom/webidl/NetworkOptions.webidl
+++ b/dom/webidl/NetworkOptions.webidl
@@ -49,16 +49,18 @@ dictionary NetworkCommandOptions
   DOMString curInternalIfname;        // for "updateUpStream".
   DOMString curExternalIfname;        // for "updateUpStream".
 
   long ipaddr;                        // for "ifc_configure".
   long mask;                          // for "ifc_configure".
   long gateway_long;                  // for "ifc_configure".
   long dns1_long;                     // for "ifc_configure".
   long dns2_long;                     // for "ifc_configure".
+
+  long mtu;                           // for "setMtu".
 };
 
 /**
 * This dictionary holds the parameters sent back to NetworkService.js.
 */
 dictionary NetworkResultOptions
 {
   long id = 0;                        // opaque id.