OSDN Git Service

Pass a socket mark to clatd so it can bind to its network.
authorLorenzo Colitti <lorenzo@google.com>
Mon, 9 Jun 2014 05:09:20 +0000 (14:09 +0900)
committerLorenzo Colitti <lorenzo@google.com>
Fri, 13 Jun 2014 02:34:18 +0000 (11:34 +0900)
Bug: 15340961
Change-Id: If15e90cbd5526f6c8fd839d4d009846d64d9e77a

server/ClatdController.cpp
server/Fwmark.h

index 46834c6..b91b69a 100644 (file)
@@ -22,6 +22,7 @@
 #include <cutils/log.h>
 
 #include "ClatdController.h"
+#include "Fwmark.h"
 #include "NetdConstants.h"
 #include "NetworkController.h"
 
@@ -49,14 +50,23 @@ int ClatdController::startClatd(char *interface) {
     }
 
     if (!pid) {
-        char netId[UINT32_STRLEN];
-        snprintf(netId, sizeof(netId), "%u", mNetCtrl->getNetworkId(interface));
+        // Pass in the interface, a netid to use for DNS lookups, and a fwmark for outgoing packets.
+        unsigned netId = mNetCtrl->getNetworkId(interface);
+        char netIdString[UINT32_STRLEN];
+        snprintf(netIdString, sizeof(netIdString), "%u", netId);
+
+        Fwmark fwmark = { netId, true, true, PERMISSION_CONNECTIVITY_INTERNAL };
+        char fwmarkString[UINT32_HEX_STRLEN];
+        snprintf(fwmarkString, sizeof(fwmarkString), "0x%x", fwmark.intValue);
+
         char *args[] = {
-            (char*)"/system/bin/clatd",
-            (char*)"-i",
+            (char *) "/system/bin/clatd",
+            (char *) "-i",
             interface,
-            (char*)"-n",
-            netId,
+            (char *) "-n",
+            netIdString,
+            (char *) "-m",
+            fwmarkString,
             NULL
         };
 
index 768219d..cb2900f 100644 (file)
@@ -22,7 +22,6 @@
 #include <stdint.h>
 
 union Fwmark {
-    Fwmark() : intValue(0) {}
     uint32_t intValue;
     struct {
         unsigned netId          : 16;
@@ -30,6 +29,10 @@ union Fwmark {
         bool protectedFromVpn   :  1;
         Permission permission   :  2;
     };
+    Fwmark() : intValue(0) {}
+    Fwmark(unsigned netId, bool explicitlySelected, bool protectedFromVpn, Permission permission)
+        : netId(netId), explicitlySelected(explicitlySelected),
+          protectedFromVpn(protectedFromVpn), permission(permission) {}
 };
 
 static const unsigned FWMARK_NET_ID_MASK = 0xffff;