Add a local boolean to PhysicalNetwork.
Test: netd_integration_test
Change-Id: I4df07a077eee0c034624054d186ab01ff9297939
Bug: 64955351
diff --git a/server/NetdNativeService.cpp b/server/NetdNativeService.cpp
index c8aa12e..63c004d 100644
--- a/server/NetdNativeService.cpp
+++ b/server/NetdNativeService.cpp
@@ -272,7 +272,8 @@
// tests.
binder::Status NetdNativeService::networkCreatePhysical(int32_t netId, int32_t permission) {
ENFORCE_NETWORK_STACK_PERMISSIONS();
- int ret = gCtls->netCtrl.createPhysicalNetwork(netId, convertPermission(permission));
+ int ret = gCtls->netCtrl.createPhysicalNetwork(netId, convertPermission(permission),
+ false /* local */);
return statusFromErrcode(ret);
}
@@ -292,8 +293,11 @@
ENFORCE_NETWORK_STACK_PERMISSIONS();
int ret = -EINVAL;
if (config.networkType == NativeNetworkType::PHYSICAL) {
- ret = gCtls->netCtrl.createPhysicalNetwork(config.netId,
- convertPermission(config.permission));
+ ret = gCtls->netCtrl.createPhysicalNetwork(
+ config.netId, convertPermission(config.permission), false /* isLocalNetwork */);
+ } else if (config.networkType == NativeNetworkType::PHYSICAL_LOCAL) {
+ ret = gCtls->netCtrl.createPhysicalNetwork(
+ config.netId, convertPermission(config.permission), true /* isLocalNetwork */);
} else if (config.networkType == NativeNetworkType::VIRTUAL) {
ret = gCtls->netCtrl.createVirtualNetwork(config.netId, config.secure, config.vpnType,
config.excludeLocalRoutes);
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index ca9ec22..5233a1e 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -382,7 +382,8 @@
return network && network->isVirtual();
}
-int NetworkController::createPhysicalNetworkLocked(unsigned netId, Permission permission) {
+int NetworkController::createPhysicalNetworkLocked(unsigned netId, Permission permission,
+ bool local) {
if (!((MIN_NET_ID <= netId && netId <= MAX_NET_ID) ||
(MIN_OEM_ID <= netId && netId <= MAX_OEM_ID))) {
ALOGE("invalid netId %u", netId);
@@ -394,7 +395,7 @@
return -EEXIST;
}
- PhysicalNetwork* physicalNetwork = new PhysicalNetwork(netId, mDelegateImpl);
+ PhysicalNetwork* physicalNetwork = new PhysicalNetwork(netId, mDelegateImpl, local);
if (int ret = physicalNetwork->setPermission(permission)) {
ALOGE("inconceivable! setPermission cannot fail on an empty network");
delete physicalNetwork;
@@ -408,9 +409,9 @@
return 0;
}
-int NetworkController::createPhysicalNetwork(unsigned netId, Permission permission) {
+int NetworkController::createPhysicalNetwork(unsigned netId, Permission permission, bool local) {
ScopedWLock lock(mRWLock);
- return createPhysicalNetworkLocked(netId, permission);
+ return createPhysicalNetworkLocked(netId, permission, local);
}
int NetworkController::createPhysicalOemNetwork(Permission permission, unsigned *pNetId) {
@@ -431,7 +432,7 @@
return -ENONET;
}
- int ret = createPhysicalNetworkLocked(*pNetId, permission);
+ int ret = createPhysicalNetworkLocked(*pNetId, permission, false /* local */);
if (ret) {
*pNetId = 0;
}
diff --git a/server/NetworkController.h b/server/NetworkController.h
index e9ef091..d4156f9 100644
--- a/server/NetworkController.h
+++ b/server/NetworkController.h
@@ -105,7 +105,7 @@
unsigned getNetworkForInterface(const char* interface) const;
bool isVirtualNetwork(unsigned netId) const;
- [[nodiscard]] int createPhysicalNetwork(unsigned netId, Permission permission);
+ [[nodiscard]] int createPhysicalNetwork(unsigned netId, Permission permission, bool local);
[[nodiscard]] int createPhysicalOemNetwork(Permission permission, unsigned* netId);
[[nodiscard]] int createVirtualNetwork(unsigned netId, bool secure, NativeVpnType vpnType,
bool excludeLocalRoutes);
@@ -165,7 +165,8 @@
Network* getPhysicalOrUnreachableNetworkForUserLocked(uid_t uid) const;
Permission getPermissionForUserLocked(uid_t uid) const;
int checkUserNetworkAccessLocked(uid_t uid, unsigned netId) const;
- [[nodiscard]] int createPhysicalNetworkLocked(unsigned netId, Permission permission);
+ [[nodiscard]] int createPhysicalNetworkLocked(unsigned netId, Permission permission,
+ bool local);
[[nodiscard]] int modifyRoute(unsigned netId, const char* interface, const char* destination,
const char* nexthop, RouteOperation op, bool legacy, uid_t uid,
diff --git a/server/PhysicalNetwork.cpp b/server/PhysicalNetwork.cpp
index 6813064..923412a 100644
--- a/server/PhysicalNetwork.cpp
+++ b/server/PhysicalNetwork.cpp
@@ -56,8 +56,16 @@
PhysicalNetwork::Delegate::~Delegate() {}
-PhysicalNetwork::PhysicalNetwork(unsigned netId, PhysicalNetwork::Delegate* delegate) :
- Network(netId), mDelegate(delegate), mPermission(PERMISSION_NONE), mIsDefault(false) {
+PhysicalNetwork::PhysicalNetwork(unsigned netId, PhysicalNetwork::Delegate* delegate, bool local)
+ : Network(netId),
+ mDelegate(delegate),
+ mPermission(PERMISSION_NONE),
+ mIsDefault(false),
+ mIsLocalNetwork(local) {
+ // TODO : remove this log, it's only present to avoid -Wunused-private-field from blocking
+ // compilation
+ ALOGI("Created physical network instance netId=%d local=%s", netId,
+ mIsLocalNetwork ? "true" : "false");
}
PhysicalNetwork::~PhysicalNetwork() {}
diff --git a/server/PhysicalNetwork.h b/server/PhysicalNetwork.h
index f114cca..7166e0e 100644
--- a/server/PhysicalNetwork.h
+++ b/server/PhysicalNetwork.h
@@ -33,7 +33,7 @@
Permission permission) = 0;
};
- PhysicalNetwork(unsigned netId, Delegate* delegate);
+ PhysicalNetwork(unsigned netId, Delegate* delegate, bool local);
virtual ~PhysicalNetwork();
// These refer to permissions that apps must have in order to use this network.
@@ -58,6 +58,7 @@
Delegate* const mDelegate;
Permission mPermission;
bool mIsDefault;
+ const bool mIsLocalNetwork;
};
} // namespace android::net