summaryrefslogtreecommitdiff
path: root/server/NetworkController.h
diff options
context:
space:
mode:
authorNiranjan Pendharkar <npendhar@codeaurora.org>2017-07-24 09:54:07 -0700
committerNiranjan Pendharkar <npendhar@codeaurora.org>2017-07-24 10:38:34 -0700
commit4c18bd9164104e0a1a81ea505d569937edb30afa (patch)
treeb92f3dedc99d418effb263b439355bcb5f71edae /server/NetworkController.h
parentc5bb2f0c2bc608fde168136e8fd00f2a6de3db3f (diff)
downloadnetd-4c18bd9164104e0a1a81ea505d569937edb30afa.tar.gz
netd: recognize NDK type in ndc network api
ndc network command now accepts strings describing net_handle_t. For e.g. ndc network create handle42966108894 Test: manual Bug: 36682246 CRs-fixed: 2070022 Change-Id: I44857af3d82ea408ae429f9fe16fcf5c876851ae
Diffstat (limited to 'server/NetworkController.h')
-rw-r--r--server/NetworkController.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/server/NetworkController.h b/server/NetworkController.h
index d5451ee8..eff38232 100644
--- a/server/NetworkController.h
+++ b/server/NetworkController.h
@@ -17,6 +17,7 @@
#ifndef NETD_SERVER_NETWORK_CONTROLLER_H
#define NETD_SERVER_NETWORK_CONTROLLER_H
+#include <android/multinetwork.h>
#include "NetdConstants.h"
#include "Permission.h"
@@ -33,6 +34,36 @@ struct android_net_context;
namespace android {
namespace net {
+// Utility to convert from netId to net_handle_t. Doing this here as opposed to exporting
+// from net.c as it may have NDK implications. Besides no conversion available in net.c for
+// obtaining handle given netId.
+// TODO: Use getnetidfromhandle() in net.c.
+static inline unsigned netHandleToNetId(net_handle_t fromNetHandle) {
+ const uint32_t k32BitMask = 0xffffffff;
+ // This value MUST be kept in sync with the corresponding value in
+ // the android.net.Network#getNetworkHandle() implementation.
+ const uint32_t kHandleMagic = 0xfacade;
+
+ // Check for minimum acceptable version of the API in the low bits.
+ if (fromNetHandle != NETWORK_UNSPECIFIED &&
+ (fromNetHandle & k32BitMask) != kHandleMagic) {
+ return 0;
+ }
+
+ return ((fromNetHandle >> (CHAR_BIT * sizeof(k32BitMask))) & k32BitMask);
+}
+
+// Utility to convert from nethandle to netid, keep in sync with getNetworkHandle
+// in Network.java.
+static inline net_handle_t netIdToNetHandle(unsigned fromNetId) {
+ const net_handle_t HANDLE_MAGIC = 0xfacade;
+
+ if (!fromNetId) {
+ return NETWORK_UNSPECIFIED;
+ }
+ return (((net_handle_t)fromNetId << 32) | HANDLE_MAGIC);
+}
+
class DumpWriter;
class Network;
class UidRanges;