blob: 1f5dc9761241d0a6b5a3edeae2964c89da5d28f8 [file] [log] [blame]
Lorenzo Colittie4d626e2016-02-02 17:19:04 +09001/**
2 * Copyright (c) 2016, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "Netd"
18
Luke Huangcaebcbb2018-09-27 20:37:14 +080019#include <cinttypes>
Xiao Ma33d562a2018-12-16 16:27:38 +090020#include <numeric>
Ben Schwartz4204ecf2017-10-02 12:35:48 -040021#include <set>
Xiao Ma64b15b72019-03-20 11:33:15 +090022#include <string>
Erik Kline38e51f12018-09-06 20:14:44 +090023#include <tuple>
Lorenzo Colitti89faa342016-02-26 11:38:47 +090024#include <vector>
25
Chenbo Fengf5663d82018-11-08 16:10:48 -080026#include <android-base/file.h>
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090027#include <android-base/stringprintf.h>
Ben Schwartz4204ecf2017-10-02 12:35:48 -040028#include <android-base/strings.h>
Luke Huange3f11812019-05-02 18:10:15 +080029#include <binder/IPCThreadState.h>
30#include <binder/IServiceManager.h>
31#include <binder/Status.h>
Robin Lee2cf56172016-09-13 18:55:42 +090032#include <cutils/properties.h>
Logan Chien3f461482018-04-23 14:31:32 +080033#include <log/log.h>
Luke Huange3f11812019-05-02 18:10:15 +080034#include <netdutils/DumpWriter.h>
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090035#include <utils/Errors.h>
Pierre Imaibeedec32016-04-13 06:44:51 +090036#include <utils/String16.h>
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090037
Lorenzo Colitti89faa342016-02-26 11:38:47 +090038#include "Controllers.h"
Chiachang Wang00fc62f2019-12-04 20:38:26 +080039#include "Fwmark.h"
Erik Kline55b06f82016-07-04 09:57:18 +090040#include "InterfaceController.h"
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090041#include "NetdNativeService.h"
Luke Huang0e5e69d2019-03-06 15:42:38 +080042#include "OemNetdListener.h"
Luke Huangb670d162018-08-23 20:01:13 +080043#include "Permission.h"
Erik Kline85890042018-05-25 19:19:11 +090044#include "Process.h"
Robin Leeb8087362016-03-30 18:43:08 +010045#include "RouteController.h"
Lorenzo Colitti563d98b2016-04-24 13:13:14 +090046#include "SockDiag.h"
Robin Leeb8087362016-03-30 18:43:08 +010047#include "UidRanges.h"
Xiao Ma33d562a2018-12-16 16:27:38 +090048#include "android/net/BnNetd.h"
Luke Huang743e0312020-05-26 17:21:28 +080049#include "binder_utils/BinderUtil.h"
50#include "binder_utils/NetdPermissions.h"
Bernie Innocenti189eb502018-10-01 23:10:18 +090051#include "netid_client.h" // NETID_UNSET
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090052
53using android::base::StringPrintf;
Chenbo Fengf5663d82018-11-08 16:10:48 -080054using android::base::WriteStringToFile;
Ken Chenab5f3472021-04-04 11:28:06 +080055using android::net::NativeNetworkType;
Lorenzo Colitti182cd3c2020-04-04 00:44:01 +090056using android::net::TetherOffloadRuleParcel;
Luke Huangcaebcbb2018-09-27 20:37:14 +080057using android::net::TetherStatsParcel;
Luke Huang94658ac2018-10-18 19:35:12 +090058using android::net::UidRangeParcel;
Ken Chend9aa98a2021-05-23 14:56:43 +080059using android::net::netd::aidl::NativeUidRangeConfig;
Luke Huangb257d612019-03-14 21:19:13 +080060using android::netdutils::DumpWriter;
61using android::netdutils::ScopedIndent;
Luke Huange203a152018-11-23 11:47:28 +080062using android::os::ParcelFileDescriptor;
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090063
64namespace android {
65namespace net {
66
67namespace {
Erik Klineb31fd692018-06-06 20:50:11 +090068const char OPT_SHORT[] = "--short";
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090069
markchienf97bab62020-02-24 11:52:20 +080070// The input permissions should be equivalent that this function would return ok if any of them is
71// granted.
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +090072binder::Status checkAnyPermission(const std::vector<const char*>& permissions) {
Luke Huanga38b65c2018-09-26 16:31:03 +080073 pid_t pid = IPCThreadState::self()->getCallingPid();
74 uid_t uid = IPCThreadState::self()->getCallingUid();
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090075
markchienf97bab62020-02-24 11:52:20 +080076 // TODO: Do the pure permission check in this function. Have another method
77 // (e.g. checkNetworkStackPermission) to wrap AID_SYSTEM and
78 // AID_NETWORK_STACK uid check.
Luke Huanga38b65c2018-09-26 16:31:03 +080079 // If the caller is the system UID, don't check permissions.
80 // Otherwise, if the system server's binder thread pool is full, and all the threads are
81 // blocked on a thread that's waiting for us to complete, we deadlock. http://b/69389492
82 //
83 // From a security perspective, there is currently no difference, because:
Luke Huangeedd6a52020-03-04 16:43:12 +080084 // 1. The system server has the NETWORK_STACK permission, which grants access to all the
85 // IPCs in this file.
Luke Huanga38b65c2018-09-26 16:31:03 +080086 // 2. AID_SYSTEM always has all permissions. See ActivityManager#checkComponentPermission.
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +090087 if (uid == AID_SYSTEM) {
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090088 return binder::Status::ok();
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090089 }
markchienf97bab62020-02-24 11:52:20 +080090 // AID_NETWORK_STACK own MAINLINE_NETWORK_STACK permission, don't IPC to system server to check
91 // MAINLINE_NETWORK_STACK permission. Cross-process(netd, networkstack and system server)
92 // deadlock: http://b/149766727
93 if (uid == AID_NETWORK_STACK) {
94 for (const char* permission : permissions) {
95 if (std::strcmp(permission, PERM_MAINLINE_NETWORK_STACK) == 0) {
96 return binder::Status::ok();
97 }
98 }
99 }
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900100
101 for (const char* permission : permissions) {
102 if (checkPermission(String16(permission), pid, uid)) {
103 return binder::Status::ok();
104 }
105 }
106
107 auto err = StringPrintf("UID %d / PID %d does not have any of the following permissions: %s",
108 uid, pid, android::base::Join(permissions, ',').c_str());
109 return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, err.c_str());
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900110}
111
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900112#define ENFORCE_ANY_PERMISSION(...) \
113 do { \
114 binder::Status status = checkAnyPermission({__VA_ARGS__}); \
115 if (!status.isOk()) { \
116 return status; \
117 } \
118 } while (0)
Robin Lee2cf56172016-09-13 18:55:42 +0900119
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900120#define NETD_LOCKING_RPC(lock, ... /* permissions */) \
121 ENFORCE_ANY_PERMISSION(__VA_ARGS__); \
Bernie Innocentiabf8a342018-08-10 15:17:16 +0900122 std::lock_guard _lock(lock);
Lorenzo Colitti89faa342016-02-26 11:38:47 +0900123
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900124#define NETD_BIG_LOCK_RPC(... /* permissions */) NETD_LOCKING_RPC(gBigNetdLock, __VA_ARGS__)
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900125
Luke Huangf7782042018-08-08 13:13:04 +0800126#define RETURN_BINDER_STATUS_IF_NOT_OK(logEntry, res) \
127 do { \
128 if (!isOk((res))) { \
129 logErrorStatus((logEntry), (res)); \
130 return asBinderStatus((res)); \
131 } \
132 } while (0)
133
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900134#define ENFORCE_NETWORK_STACK_PERMISSIONS() \
135 ENFORCE_ANY_PERMISSION(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK)
136
Luke Huangf7782042018-08-08 13:13:04 +0800137void logErrorStatus(netdutils::LogEntry& logEntry, const netdutils::Status& status) {
138 gLog.log(logEntry.returns(status.code()).withAutomaticDuration());
139}
140
Bernie Innocenti97f388f2018-10-16 19:17:08 +0900141binder::Status asBinderStatus(const netdutils::Status& status) {
142 if (isOk(status)) {
143 return binder::Status::ok();
144 }
145 return binder::Status::fromServiceSpecificError(status.code(), status.msg().c_str());
146}
147
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900148template <typename T>
149binder::Status asBinderStatus(const base::Result<T> result) {
150 if (result.ok()) return binder::Status::ok();
151
152 return binder::Status::fromServiceSpecificError(result.error().code(),
153 result.error().message().c_str());
154}
155
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900156inline binder::Status statusFromErrcode(int ret) {
157 if (ret) {
158 return binder::Status::fromServiceSpecificError(-ret, strerror(-ret));
159 }
160 return binder::Status::ok();
161}
162
Erik Klineb31fd692018-06-06 20:50:11 +0900163bool contains(const Vector<String16>& words, const String16& word) {
164 for (const auto& w : words) {
165 if (w == word) return true;
166 }
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900167
Erik Klineb31fd692018-06-06 20:50:11 +0900168 return false;
169}
170
171} // namespace
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900172
Luke Huange3f11812019-05-02 18:10:15 +0800173NetdNativeService::NetdNativeService() {
174 // register log callback to BnNetd::logFunc
Jooyung Hanf2422582020-11-04 14:21:46 +0900175 BnNetd::logFunc = [](const auto& log) {
176 binderCallLogFn(log, [](const std::string& msg) { gLog.info("%s", msg.c_str()); });
177 };
Luke Huange3f11812019-05-02 18:10:15 +0800178}
179
Lorenzo Colittie4851de2016-03-17 13:23:28 +0900180status_t NetdNativeService::start() {
181 IPCThreadState::self()->disableBackgroundScheduling(true);
Erik Klineb31fd692018-06-06 20:50:11 +0900182 const status_t ret = BinderService<NetdNativeService>::publish();
Lorenzo Colittie4851de2016-03-17 13:23:28 +0900183 if (ret != android::OK) {
184 return ret;
185 }
186 sp<ProcessState> ps(ProcessState::self());
187 ps->startThreadPool();
188 ps->giveThreadPoolName();
Xiao Ma33d562a2018-12-16 16:27:38 +0900189
Lorenzo Colittie4851de2016-03-17 13:23:28 +0900190 return android::OK;
191}
192
Hugo Benichi7b314e12018-01-15 21:54:00 +0900193status_t NetdNativeService::dump(int fd, const Vector<String16> &args) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900194 const binder::Status dump_permission = checkAnyPermission({PERM_DUMP});
Erik Kline2d3a1632016-03-15 16:33:48 +0900195 if (!dump_permission.isOk()) {
196 const String8 msg(dump_permission.toString8());
197 write(fd, msg.string(), msg.size());
198 return PERMISSION_DENIED;
199 }
200
201 // This method does not grab any locks. If individual classes need locking
202 // their dump() methods MUST handle locking appropriately.
Hugo Benichi7b314e12018-01-15 21:54:00 +0900203
Erik Kline2d3a1632016-03-15 16:33:48 +0900204 DumpWriter dw(fd);
Hugo Benichi7b314e12018-01-15 21:54:00 +0900205
206 if (!args.isEmpty() && args[0] == TcpSocketMonitor::DUMP_KEYWORD) {
207 dw.blankline();
208 gCtls->tcpSocketMonitor.dump(dw);
209 dw.blankline();
210 return NO_ERROR;
211 }
212
Chenbo Fengef297172018-03-26 10:53:33 -0700213 if (!args.isEmpty() && args[0] == TrafficController::DUMP_KEYWORD) {
214 dw.blankline();
215 gCtls->trafficCtrl.dump(dw, true);
216 dw.blankline();
217 return NO_ERROR;
218 }
219
Erik Kline85890042018-05-25 19:19:11 +0900220 process::dump(dw);
Erik Kline2d3a1632016-03-15 16:33:48 +0900221 dw.blankline();
222 gCtls->netCtrl.dump(dw);
223 dw.blankline();
224
Chenbo Fengef297172018-03-26 10:53:33 -0700225 gCtls->trafficCtrl.dump(dw, false);
226 dw.blankline();
227
Benedict Wongaf855432018-05-10 17:07:37 -0700228 gCtls->xfrmCtrl.dump(dw);
229 dw.blankline();
230
Maciej Żenczykowski55262712019-03-29 23:44:56 -0700231 gCtls->clatdCtrl.dump(dw);
232 dw.blankline();
233
Lorenzo Colitti52db3912020-02-17 23:59:45 +0900234 gCtls->tetherCtrl.dump(dw);
235 dw.blankline();
236
Erik Klineb31fd692018-06-06 20:50:11 +0900237 {
238 ScopedIndent indentLog(dw);
239 if (contains(args, String16(OPT_SHORT))) {
240 dw.println("Log: <omitted>");
241 } else {
242 dw.println("Log:");
243 ScopedIndent indentLogEntries(dw);
244 gLog.forEachEntry([&dw](const std::string& entry) mutable { dw.println(entry); });
245 }
246 dw.blankline();
247 }
248
Luke Huang528af602018-08-29 19:06:05 +0800249 {
250 ScopedIndent indentLog(dw);
251 if (contains(args, String16(OPT_SHORT))) {
252 dw.println("UnsolicitedLog: <omitted>");
253 } else {
254 dw.println("UnsolicitedLog:");
255 ScopedIndent indentLogEntries(dw);
256 gUnsolicitedLog.forEachEntry(
257 [&dw](const std::string& entry) mutable { dw.println(entry); });
258 }
259 dw.blankline();
260 }
261
Erik Kline2d3a1632016-03-15 16:33:48 +0900262 return NO_ERROR;
263}
264
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900265binder::Status NetdNativeService::isAlive(bool *alive) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800266 NETD_BIG_LOCK_RPC(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900267
268 *alive = true;
Erik Klineb31fd692018-06-06 20:50:11 +0900269
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900270 return binder::Status::ok();
271}
272
Erik Klinef52d4522018-03-14 15:01:46 +0900273binder::Status NetdNativeService::firewallReplaceUidChain(const std::string& chainName,
Lorenzo Colitticdd79f12020-07-30 12:03:40 +0900274 bool isAllowlist,
275 const std::vector<int32_t>& uids,
276 bool* ret) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800277 NETD_LOCKING_RPC(gCtls->firewallCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Lorenzo Colitticdd79f12020-07-30 12:03:40 +0900278 int err = gCtls->firewallCtrl.replaceUidChain(chainName, isAllowlist, uids);
Lorenzo Colitti89faa342016-02-26 11:38:47 +0900279 *ret = (err == 0);
280 return binder::Status::ok();
Lorenzo Colitti89faa342016-02-26 11:38:47 +0900281}
Lorenzo Colittidedd2712016-03-22 12:36:29 +0900282
283binder::Status NetdNativeService::bandwidthEnableDataSaver(bool enable, bool *ret) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800284 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Lorenzo Colittidedd2712016-03-22 12:36:29 +0900285 int err = gCtls->bandwidthCtrl.enableDataSaver(enable);
286 *ret = (err == 0);
287 return binder::Status::ok();
288}
289
Luke Huang531f5d32018-08-03 15:19:05 +0800290binder::Status NetdNativeService::bandwidthSetInterfaceQuota(const std::string& ifName,
291 int64_t bytes) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900292 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang531f5d32018-08-03 15:19:05 +0800293 int res = gCtls->bandwidthCtrl.setInterfaceQuota(ifName, bytes);
Luke Huang531f5d32018-08-03 15:19:05 +0800294 return statusFromErrcode(res);
295}
296
297binder::Status NetdNativeService::bandwidthRemoveInterfaceQuota(const std::string& ifName) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900298 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang531f5d32018-08-03 15:19:05 +0800299 int res = gCtls->bandwidthCtrl.removeInterfaceQuota(ifName);
Luke Huang531f5d32018-08-03 15:19:05 +0800300 return statusFromErrcode(res);
301}
302
303binder::Status NetdNativeService::bandwidthSetInterfaceAlert(const std::string& ifName,
304 int64_t bytes) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900305 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang531f5d32018-08-03 15:19:05 +0800306 int res = gCtls->bandwidthCtrl.setInterfaceAlert(ifName, bytes);
Luke Huang531f5d32018-08-03 15:19:05 +0800307 return statusFromErrcode(res);
308}
309
310binder::Status NetdNativeService::bandwidthRemoveInterfaceAlert(const std::string& ifName) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900311 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang531f5d32018-08-03 15:19:05 +0800312 int res = gCtls->bandwidthCtrl.removeInterfaceAlert(ifName);
Luke Huang531f5d32018-08-03 15:19:05 +0800313 return statusFromErrcode(res);
314}
315
316binder::Status NetdNativeService::bandwidthSetGlobalAlert(int64_t bytes) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900317 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang531f5d32018-08-03 15:19:05 +0800318 int res = gCtls->bandwidthCtrl.setGlobalAlert(bytes);
Luke Huang531f5d32018-08-03 15:19:05 +0800319 return statusFromErrcode(res);
320}
321
322binder::Status NetdNativeService::bandwidthAddNaughtyApp(int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900323 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Patrick Rohr79203972020-12-29 18:16:35 +0100324 std::vector<uint32_t> appUids = {static_cast<uint32_t>(abs(uid))};
325 int res = gCtls->bandwidthCtrl.addNaughtyApps(appUids);
Luke Huang531f5d32018-08-03 15:19:05 +0800326 return statusFromErrcode(res);
327}
328
329binder::Status NetdNativeService::bandwidthRemoveNaughtyApp(int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900330 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Patrick Rohr79203972020-12-29 18:16:35 +0100331 std::vector<uint32_t> appUids = {static_cast<uint32_t>(abs(uid))};
332 int res = gCtls->bandwidthCtrl.removeNaughtyApps(appUids);
Luke Huang531f5d32018-08-03 15:19:05 +0800333 return statusFromErrcode(res);
334}
335
336binder::Status NetdNativeService::bandwidthAddNiceApp(int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900337 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Patrick Rohr79203972020-12-29 18:16:35 +0100338 std::vector<uint32_t> appUids = {static_cast<uint32_t>(abs(uid))};
339 int res = gCtls->bandwidthCtrl.addNiceApps(appUids);
Luke Huang531f5d32018-08-03 15:19:05 +0800340 return statusFromErrcode(res);
341}
342
343binder::Status NetdNativeService::bandwidthRemoveNiceApp(int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900344 NETD_LOCKING_RPC(gCtls->bandwidthCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Patrick Rohr79203972020-12-29 18:16:35 +0100345 std::vector<uint32_t> appUids = {static_cast<uint32_t>(abs(uid))};
346 int res = gCtls->bandwidthCtrl.removeNiceApps(appUids);
Luke Huang531f5d32018-08-03 15:19:05 +0800347 return statusFromErrcode(res);
348}
349
Ken Chenab5f3472021-04-04 11:28:06 +0800350// TODO: Remove this function when there are no users. Currently, it is still used by DNS resolver
351// tests.
Luke Huangb670d162018-08-23 20:01:13 +0800352binder::Status NetdNativeService::networkCreatePhysical(int32_t netId, int32_t permission) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800353 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +0800354 int ret = gCtls->netCtrl.createPhysicalNetwork(netId, convertPermission(permission));
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900355 return statusFromErrcode(ret);
356}
357
Ken Chenab5f3472021-04-04 11:28:06 +0800358// TODO: Remove this function when there are no users. Currently, it is still used by DNS resolver
359// tests.
cken67cd14c2018-12-05 17:26:59 +0900360binder::Status NetdNativeService::networkCreateVpn(int32_t netId, bool secure) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900361 ENFORCE_NETWORK_STACK_PERMISSIONS();
Ken Chenab5f3472021-04-04 11:28:06 +0800362 // The value of vpnType does not matter here, because it is not used in AOSP and is only
363 // implemented by OEMs. Also, the RPC is going to deprecate. Just pick a value defined in INetd
364 // as default.
365 int ret = gCtls->netCtrl.createVirtualNetwork(netId, secure, NativeVpnType::LEGACY);
366 return statusFromErrcode(ret);
367}
368
369binder::Status NetdNativeService::networkCreate(const NativeNetworkConfig& config) {
370 ENFORCE_NETWORK_STACK_PERMISSIONS();
371 int ret = -EINVAL;
372 if (config.networkType == NativeNetworkType::PHYSICAL) {
373 ret = gCtls->netCtrl.createPhysicalNetwork(config.netId,
374 convertPermission(config.permission));
375 } else if (config.networkType == NativeNetworkType::VIRTUAL) {
376 ret = gCtls->netCtrl.createVirtualNetwork(config.netId, config.secure, config.vpnType);
377 }
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900378 return statusFromErrcode(ret);
379}
380
381binder::Status NetdNativeService::networkDestroy(int32_t netId) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900382 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangd33a8f42019-03-14 16:10:04 +0800383 // NetworkController::destroyNetwork is thread-safe.
Mike Yu4fe1b9c2019-01-29 17:50:19 +0800384 const int ret = gCtls->netCtrl.destroyNetwork(netId);
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900385 return statusFromErrcode(ret);
386}
387
388binder::Status NetdNativeService::networkAddInterface(int32_t netId, const std::string& iface) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800389 ENFORCE_NETWORK_STACK_PERMISSIONS();
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900390 int ret = gCtls->netCtrl.addInterfaceToNetwork(netId, iface.c_str());
391 return statusFromErrcode(ret);
392}
393
394binder::Status NetdNativeService::networkRemoveInterface(int32_t netId, const std::string& iface) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800395 ENFORCE_NETWORK_STACK_PERMISSIONS();
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900396 int ret = gCtls->netCtrl.removeInterfaceFromNetwork(netId, iface.c_str());
397 return statusFromErrcode(ret);
398}
399
Luke Huang94658ac2018-10-18 19:35:12 +0900400binder::Status NetdNativeService::networkAddUidRanges(
401 int32_t netId, const std::vector<UidRangeParcel>& uidRangeArray) {
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900402 // NetworkController::addUsersToNetwork is thread-safe.
Luke Huangeedd6a52020-03-04 16:43:12 +0800403 ENFORCE_NETWORK_STACK_PERMISSIONS();
Ken Chend9aa98a2021-05-23 14:56:43 +0800404 int ret = gCtls->netCtrl.addUsersToNetwork(netId, UidRanges(uidRangeArray),
405 UidRanges::DEFAULT_SUB_PRIORITY);
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900406 return statusFromErrcode(ret);
407}
408
Luke Huang94658ac2018-10-18 19:35:12 +0900409binder::Status NetdNativeService::networkRemoveUidRanges(
410 int32_t netId, const std::vector<UidRangeParcel>& uidRangeArray) {
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900411 // NetworkController::removeUsersFromNetwork is thread-safe.
Luke Huangeedd6a52020-03-04 16:43:12 +0800412 ENFORCE_NETWORK_STACK_PERMISSIONS();
Ken Chend9aa98a2021-05-23 14:56:43 +0800413 int ret = gCtls->netCtrl.removeUsersFromNetwork(netId, UidRanges(uidRangeArray),
414 UidRanges::DEFAULT_SUB_PRIORITY);
415 return statusFromErrcode(ret);
416}
417
418binder::Status NetdNativeService::networkAddUidRangesParcel(const NativeUidRangeConfig& config) {
419 ENFORCE_NETWORK_STACK_PERMISSIONS();
420 int ret = gCtls->netCtrl.addUsersToNetwork(config.netId, UidRanges(config.uidRanges),
421 config.subPriority);
422 return statusFromErrcode(ret);
423}
424
425binder::Status NetdNativeService::networkRemoveUidRangesParcel(const NativeUidRangeConfig& config) {
426 ENFORCE_NETWORK_STACK_PERMISSIONS();
427 int ret = gCtls->netCtrl.removeUsersFromNetwork(config.netId, UidRanges(config.uidRanges),
428 config.subPriority);
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900429 return statusFromErrcode(ret);
430}
431
Luke Huang94658ac2018-10-18 19:35:12 +0900432binder::Status NetdNativeService::networkRejectNonSecureVpn(
433 bool add, const std::vector<UidRangeParcel>& uidRangeArray) {
Robin Leeb8087362016-03-30 18:43:08 +0100434 // TODO: elsewhere RouteController is only used from the tethering and network controllers, so
435 // it should be possible to use the same lock as NetworkController. However, every call through
436 // the CommandListener "network" command will need to hold this lock too, not just the ones that
437 // read/modify network internal state (that is sufficient for ::dump() because it doesn't
438 // look at routes, but it's not enough here).
Luke Huangeedd6a52020-03-04 16:43:12 +0800439 NETD_BIG_LOCK_RPC(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Lorenzo Colitti563d98b2016-04-24 13:13:14 +0900440 UidRanges uidRanges(uidRangeArray);
Robin Leeb8087362016-03-30 18:43:08 +0100441
442 int err;
443 if (add) {
444 err = RouteController::addUsersToRejectNonSecureNetworkRule(uidRanges);
445 } else {
446 err = RouteController::removeUsersFromRejectNonSecureNetworkRule(uidRanges);
447 }
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900448 return statusFromErrcode(err);
Robin Leeb8087362016-03-30 18:43:08 +0100449}
450
Luke Huang94658ac2018-10-18 19:35:12 +0900451binder::Status NetdNativeService::socketDestroy(const std::vector<UidRangeParcel>& uids,
452 const std::vector<int32_t>& skipUids) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800453 ENFORCE_NETWORK_STACK_PERMISSIONS();
Lorenzo Colitti563d98b2016-04-24 13:13:14 +0900454
455 SockDiag sd;
456 if (!sd.open()) {
457 return binder::Status::fromServiceSpecificError(EIO,
458 String8("Could not open SOCK_DIAG socket"));
459 }
460
461 UidRanges uidRanges(uids);
Lorenzo Colittie5c3c992016-07-26 17:53:50 +0900462 int err = sd.destroySockets(uidRanges, std::set<uid_t>(skipUids.begin(), skipUids.end()),
463 true /* excludeLoopback */);
Lorenzo Colitti563d98b2016-04-24 13:13:14 +0900464 if (err) {
465 return binder::Status::fromServiceSpecificError(-err,
466 String8::format("destroySockets: %s", strerror(-err)));
467 }
Pierre Imaibeedec32016-04-13 06:44:51 +0900468 return binder::Status::ok();
469}
Lorenzo Colitti563d98b2016-04-24 13:13:14 +0900470
Erik Klinef48e4dd2016-07-18 04:02:07 +0900471binder::Status NetdNativeService::tetherApplyDnsInterfaces(bool *ret) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900472 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Erik Klinef48e4dd2016-07-18 04:02:07 +0900473 *ret = gCtls->tetherCtrl.applyDnsInterfaces();
474 return binder::Status::ok();
475}
476
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900477namespace {
478
Hungming Chenf40dc092020-03-12 16:21:03 +0800479constexpr const int UNUSED_IFINDEX = 0;
480
Luke Huangcaebcbb2018-09-27 20:37:14 +0800481void tetherAddStatsByInterface(TetherController::TetherStats* tetherStatsParcel,
482 const TetherController::TetherStats& tetherStats) {
483 if (tetherStatsParcel->extIface == tetherStats.extIface) {
484 tetherStatsParcel->rxBytes += tetherStats.rxBytes;
485 tetherStatsParcel->rxPackets += tetherStats.rxPackets;
486 tetherStatsParcel->txBytes += tetherStats.txBytes;
487 tetherStatsParcel->txPackets += tetherStats.txPackets;
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900488 }
Luke Huangcaebcbb2018-09-27 20:37:14 +0800489}
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900490
Luke Huangcaebcbb2018-09-27 20:37:14 +0800491TetherStatsParcel toTetherStatsParcel(const TetherController::TetherStats& stats) {
492 TetherStatsParcel result;
493 result.iface = stats.extIface;
494 result.rxBytes = stats.rxBytes;
495 result.rxPackets = stats.rxPackets;
496 result.txBytes = stats.txBytes;
497 result.txPackets = stats.txPackets;
Hungming Chenf40dc092020-03-12 16:21:03 +0800498 result.ifIndex = UNUSED_IFINDEX;
Luke Huangcaebcbb2018-09-27 20:37:14 +0800499 return result;
500}
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900501
Luke Huangcaebcbb2018-09-27 20:37:14 +0800502void setTetherStatsParcelVecByInterface(std::vector<TetherStatsParcel>* tetherStatsVec,
503 const TetherController::TetherStatsList& statsList) {
504 std::map<std::string, TetherController::TetherStats> statsMap;
505 for (const auto& stats : statsList) {
506 auto iter = statsMap.find(stats.extIface);
507 if (iter != statsMap.end()) {
508 tetherAddStatsByInterface(&(iter->second), stats);
509 } else {
510 statsMap.insert(
511 std::pair<std::string, TetherController::TetherStats>(stats.extIface, stats));
512 }
513 }
514 for (auto iter = statsMap.begin(); iter != statsMap.end(); iter++) {
515 tetherStatsVec->push_back(toTetherStatsParcel(iter->second));
516 }
517}
518
519std::vector<std::string> tetherStatsParcelVecToStringVec(std::vector<TetherStatsParcel>* tVec) {
520 std::vector<std::string> result;
521 for (const auto& t : *tVec) {
522 result.push_back(StringPrintf("%s:%" PRId64 ",%" PRId64 ",%" PRId64 ",%" PRId64,
523 t.iface.c_str(), t.rxBytes, t.rxPackets, t.txBytes,
524 t.txPackets));
525 }
526 return result;
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900527}
528
529} // namespace
530
Luke Huangcaebcbb2018-09-27 20:37:14 +0800531binder::Status NetdNativeService::tetherGetStats(
532 std::vector<TetherStatsParcel>* tetherStatsParcelVec) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900533 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Lorenzo Colitti5192bf72017-09-04 13:30:59 +0900534 const auto& statsList = gCtls->tetherCtrl.getTetherStats();
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900535 if (!isOk(statsList)) {
Nathan Harold28ccfef2018-03-16 19:02:47 -0700536 return asBinderStatus(statsList);
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900537 }
Luke Huangcaebcbb2018-09-27 20:37:14 +0800538 setTetherStatsParcelVecByInterface(tetherStatsParcelVec, statsList.value());
539 auto statsResults = tetherStatsParcelVecToStringVec(tetherStatsParcelVec);
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900540 return binder::Status::ok();
541}
542
Erik Kline53c20882016-08-02 15:22:53 +0900543binder::Status NetdNativeService::interfaceAddAddress(const std::string &ifName,
544 const std::string &addrString, int prefixLength) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800545 ENFORCE_NETWORK_STACK_PERMISSIONS();
Erik Kline53c20882016-08-02 15:22:53 +0900546 const int err = InterfaceController::addAddress(
547 ifName.c_str(), addrString.c_str(), prefixLength);
548 if (err != 0) {
549 return binder::Status::fromServiceSpecificError(-err,
550 String8::format("InterfaceController error: %s", strerror(-err)));
551 }
552 return binder::Status::ok();
553}
554
555binder::Status NetdNativeService::interfaceDelAddress(const std::string &ifName,
556 const std::string &addrString, int prefixLength) {
Luke Huangeedd6a52020-03-04 16:43:12 +0800557 ENFORCE_NETWORK_STACK_PERMISSIONS();
Erik Kline53c20882016-08-02 15:22:53 +0900558 const int err = InterfaceController::delAddress(
559 ifName.c_str(), addrString.c_str(), prefixLength);
560 if (err != 0) {
561 return binder::Status::fromServiceSpecificError(-err,
562 String8::format("InterfaceController error: %s", strerror(-err)));
563 }
564 return binder::Status::ok();
565}
566
Erik Kline38e51f12018-09-06 20:14:44 +0900567namespace {
Erik Kline55b06f82016-07-04 09:57:18 +0900568
Erik Kline38e51f12018-09-06 20:14:44 +0900569std::tuple<binder::Status, const char*, const char*> getPathComponents(int32_t ipversion,
570 int32_t category) {
571 const char* ipversionStr = nullptr;
572 switch (ipversion) {
Erik Kline55b06f82016-07-04 09:57:18 +0900573 case INetd::IPV4:
Erik Kline38e51f12018-09-06 20:14:44 +0900574 ipversionStr = "ipv4";
Erik Kline55b06f82016-07-04 09:57:18 +0900575 break;
576 case INetd::IPV6:
Erik Kline38e51f12018-09-06 20:14:44 +0900577 ipversionStr = "ipv6";
Erik Kline55b06f82016-07-04 09:57:18 +0900578 break;
579 default:
Erik Kline38e51f12018-09-06 20:14:44 +0900580 return {binder::Status::fromServiceSpecificError(EAFNOSUPPORT, "Bad IP version"),
581 nullptr, nullptr};
Erik Kline55b06f82016-07-04 09:57:18 +0900582 }
583
Erik Kline38e51f12018-09-06 20:14:44 +0900584 const char* whichStr = nullptr;
585 switch (category) {
Erik Kline55b06f82016-07-04 09:57:18 +0900586 case INetd::CONF:
587 whichStr = "conf";
588 break;
589 case INetd::NEIGH:
590 whichStr = "neigh";
591 break;
592 default:
Erik Kline38e51f12018-09-06 20:14:44 +0900593 return {binder::Status::fromServiceSpecificError(EINVAL, "Bad category"), nullptr,
594 nullptr};
Erik Kline55b06f82016-07-04 09:57:18 +0900595 }
596
Erik Kline38e51f12018-09-06 20:14:44 +0900597 return {binder::Status::ok(), ipversionStr, whichStr};
598}
599
600} // namespace
601
602binder::Status NetdNativeService::getProcSysNet(int32_t ipversion, int32_t which,
603 const std::string& ifname,
604 const std::string& parameter, std::string* value) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900605 ENFORCE_NETWORK_STACK_PERMISSIONS();
Erik Kline38e51f12018-09-06 20:14:44 +0900606 const auto pathParts = getPathComponents(ipversion, which);
607 const auto& pathStatus = std::get<0>(pathParts);
608 if (!pathStatus.isOk()) {
Erik Kline38e51f12018-09-06 20:14:44 +0900609 return pathStatus;
Erik Kline55b06f82016-07-04 09:57:18 +0900610 }
Erik Kline38e51f12018-09-06 20:14:44 +0900611
612 const int err = InterfaceController::getParameter(std::get<1>(pathParts),
613 std::get<2>(pathParts), ifname.c_str(),
614 parameter.c_str(), value);
Erik Kline38e51f12018-09-06 20:14:44 +0900615 return statusFromErrcode(err);
616}
617
618binder::Status NetdNativeService::setProcSysNet(int32_t ipversion, int32_t which,
619 const std::string& ifname,
620 const std::string& parameter,
621 const std::string& value) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900622 ENFORCE_NETWORK_STACK_PERMISSIONS();
Erik Kline38e51f12018-09-06 20:14:44 +0900623 const auto pathParts = getPathComponents(ipversion, which);
624 const auto& pathStatus = std::get<0>(pathParts);
625 if (!pathStatus.isOk()) {
Erik Kline38e51f12018-09-06 20:14:44 +0900626 return pathStatus;
627 }
628
629 const int err = InterfaceController::setParameter(std::get<1>(pathParts),
630 std::get<2>(pathParts), ifname.c_str(),
631 parameter.c_str(), value.c_str());
Erik Kline38e51f12018-09-06 20:14:44 +0900632 return statusFromErrcode(err);
Erik Kline55b06f82016-07-04 09:57:18 +0900633}
634
Luke Huange203a152018-11-23 11:47:28 +0800635binder::Status NetdNativeService::ipSecSetEncapSocketOwner(const ParcelFileDescriptor& socket,
636 int newUid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900637 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wongb2daefb2017-12-06 22:05:46 -0800638
639 uid_t callerUid = IPCThreadState::self()->getCallingUid();
Luke Huange203a152018-11-23 11:47:28 +0800640 return asBinderStatus(
641 gCtls->xfrmCtrl.ipSecSetEncapSocketOwner(socket.get(), newUid, callerUid));
Benedict Wongb2daefb2017-12-06 22:05:46 -0800642}
643
Nathan Harold1a371532017-01-30 12:30:48 -0800644binder::Status NetdNativeService::ipSecAllocateSpi(
645 int32_t transformId,
Nathan Haroldda54f122018-01-09 16:42:57 -0800646 const std::string& sourceAddress,
647 const std::string& destinationAddress,
Nathan Harold1a371532017-01-30 12:30:48 -0800648 int32_t inSpi,
649 int32_t* outSpi) {
650 // Necessary locking done in IpSecService and kernel
Luke Huangeedd6a52020-03-04 16:43:12 +0800651 ENFORCE_NETWORK_STACK_PERMISSIONS();
ludi6e8eccd2017-08-14 14:40:37 -0700652 return asBinderStatus(gCtls->xfrmCtrl.ipSecAllocateSpi(
Nathan Harold1a371532017-01-30 12:30:48 -0800653 transformId,
Nathan Haroldda54f122018-01-09 16:42:57 -0800654 sourceAddress,
655 destinationAddress,
Nathan Harold1a371532017-01-30 12:30:48 -0800656 inSpi,
657 outSpi));
658}
659
660binder::Status NetdNativeService::ipSecAddSecurityAssociation(
Benedict Wonga450e722018-05-07 10:29:02 -0700661 int32_t transformId, int32_t mode, const std::string& sourceAddress,
662 const std::string& destinationAddress, int32_t underlyingNetId, int32_t spi,
663 int32_t markValue, int32_t markMask, const std::string& authAlgo,
664 const std::vector<uint8_t>& authKey, int32_t authTruncBits, const std::string& cryptAlgo,
665 const std::vector<uint8_t>& cryptKey, int32_t cryptTruncBits, const std::string& aeadAlgo,
666 const std::vector<uint8_t>& aeadKey, int32_t aeadIcvBits, int32_t encapType,
667 int32_t encapLocalPort, int32_t encapRemotePort, int32_t interfaceId) {
Nathan Harold1a371532017-01-30 12:30:48 -0800668 // Necessary locking done in IpSecService and kernel
Luke Huangeedd6a52020-03-04 16:43:12 +0800669 ENFORCE_NETWORK_STACK_PERMISSIONS();
ludi6e8eccd2017-08-14 14:40:37 -0700670 return asBinderStatus(gCtls->xfrmCtrl.ipSecAddSecurityAssociation(
Benedict Wongad600cb2018-05-14 17:22:35 -0700671 transformId, mode, sourceAddress, destinationAddress, underlyingNetId, spi, markValue,
672 markMask, authAlgo, authKey, authTruncBits, cryptAlgo, cryptKey, cryptTruncBits,
Benedict Wonga450e722018-05-07 10:29:02 -0700673 aeadAlgo, aeadKey, aeadIcvBits, encapType, encapLocalPort, encapRemotePort,
674 interfaceId));
Nathan Harold1a371532017-01-30 12:30:48 -0800675}
676
677binder::Status NetdNativeService::ipSecDeleteSecurityAssociation(
Benedict Wonga450e722018-05-07 10:29:02 -0700678 int32_t transformId, const std::string& sourceAddress,
679 const std::string& destinationAddress, int32_t spi, int32_t markValue, int32_t markMask,
680 int32_t interfaceId) {
Nathan Harold1a371532017-01-30 12:30:48 -0800681 // Necessary locking done in IpSecService and kernel
Luke Huangeedd6a52020-03-04 16:43:12 +0800682 ENFORCE_NETWORK_STACK_PERMISSIONS();
ludi6e8eccd2017-08-14 14:40:37 -0700683 return asBinderStatus(gCtls->xfrmCtrl.ipSecDeleteSecurityAssociation(
Benedict Wonga450e722018-05-07 10:29:02 -0700684 transformId, sourceAddress, destinationAddress, spi, markValue, markMask, interfaceId));
Nathan Harold1a371532017-01-30 12:30:48 -0800685}
686
687binder::Status NetdNativeService::ipSecApplyTransportModeTransform(
Luke Huange203a152018-11-23 11:47:28 +0800688 const ParcelFileDescriptor& socket, int32_t transformId, int32_t direction,
689 const std::string& sourceAddress, const std::string& destinationAddress, int32_t spi) {
Nathan Harold1a371532017-01-30 12:30:48 -0800690 // Necessary locking done in IpSecService and kernel
Luke Huangeedd6a52020-03-04 16:43:12 +0800691 ENFORCE_NETWORK_STACK_PERMISSIONS();
ludi6e8eccd2017-08-14 14:40:37 -0700692 return asBinderStatus(gCtls->xfrmCtrl.ipSecApplyTransportModeTransform(
Luke Huange203a152018-11-23 11:47:28 +0800693 socket.get(), transformId, direction, sourceAddress, destinationAddress, spi));
Nathan Harold1a371532017-01-30 12:30:48 -0800694}
695
696binder::Status NetdNativeService::ipSecRemoveTransportModeTransform(
Luke Huange203a152018-11-23 11:47:28 +0800697 const ParcelFileDescriptor& socket) {
Nathan Harold1a371532017-01-30 12:30:48 -0800698 // Necessary locking done in IpSecService and kernel
Luke Huangeedd6a52020-03-04 16:43:12 +0800699 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huange203a152018-11-23 11:47:28 +0800700 return asBinderStatus(gCtls->xfrmCtrl.ipSecRemoveTransportModeTransform(socket.get()));
Nathan Harold1a371532017-01-30 12:30:48 -0800701}
702
Benedict Wonga04ffa72018-05-09 21:42:42 -0700703binder::Status NetdNativeService::ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
704 int32_t direction,
Benedict Wongad600cb2018-05-14 17:22:35 -0700705 const std::string& tmplSrcAddress,
706 const std::string& tmplDstAddress,
707 int32_t spi, int32_t markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700708 int32_t markMask, int32_t interfaceId) {
Benedict Wong84a8dca2018-01-19 12:12:17 -0800709 // Necessary locking done in IpSecService and kernel
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900710 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wong84a8dca2018-01-19 12:12:17 -0800711 return asBinderStatus(gCtls->xfrmCtrl.ipSecAddSecurityPolicy(
Benedict Wonga04ffa72018-05-09 21:42:42 -0700712 transformId, selAddrFamily, direction, tmplSrcAddress, tmplDstAddress, spi, markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700713 markMask, interfaceId));
Benedict Wong84a8dca2018-01-19 12:12:17 -0800714}
715
Benedict Wonga450e722018-05-07 10:29:02 -0700716binder::Status NetdNativeService::ipSecUpdateSecurityPolicy(
717 int32_t transformId, int32_t selAddrFamily, int32_t direction,
718 const std::string& tmplSrcAddress, const std::string& tmplDstAddress, int32_t spi,
719 int32_t markValue, int32_t markMask, int32_t interfaceId) {
Benedict Wong84a8dca2018-01-19 12:12:17 -0800720 // Necessary locking done in IpSecService and kernel
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900721 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wong84a8dca2018-01-19 12:12:17 -0800722 return asBinderStatus(gCtls->xfrmCtrl.ipSecUpdateSecurityPolicy(
Benedict Wonga04ffa72018-05-09 21:42:42 -0700723 transformId, selAddrFamily, direction, tmplSrcAddress, tmplDstAddress, spi, markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700724 markMask, interfaceId));
Benedict Wong84a8dca2018-01-19 12:12:17 -0800725}
726
Benedict Wonga04ffa72018-05-09 21:42:42 -0700727binder::Status NetdNativeService::ipSecDeleteSecurityPolicy(int32_t transformId,
728 int32_t selAddrFamily,
729 int32_t direction, int32_t markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700730 int32_t markMask, int32_t interfaceId) {
Benedict Wong84a8dca2018-01-19 12:12:17 -0800731 // Necessary locking done in IpSecService and kernel
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900732 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wong84a8dca2018-01-19 12:12:17 -0800733 return asBinderStatus(gCtls->xfrmCtrl.ipSecDeleteSecurityPolicy(
Benedict Wonga450e722018-05-07 10:29:02 -0700734 transformId, selAddrFamily, direction, markValue, markMask, interfaceId));
Benedict Wong84a8dca2018-01-19 12:12:17 -0800735}
736
Benedict Wong319f17e2018-05-15 17:06:44 -0700737binder::Status NetdNativeService::ipSecAddTunnelInterface(const std::string& deviceName,
738 const std::string& localAddress,
739 const std::string& remoteAddress,
Benedict Wonga450e722018-05-07 10:29:02 -0700740 int32_t iKey, int32_t oKey,
741 int32_t interfaceId) {
manojboopathi8707f232018-01-02 14:45:47 -0800742 // Necessary locking done in IpSecService and kernel
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900743 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wong319f17e2018-05-15 17:06:44 -0700744 netdutils::Status result = gCtls->xfrmCtrl.ipSecAddTunnelInterface(
Benedict Wonga450e722018-05-07 10:29:02 -0700745 deviceName, localAddress, remoteAddress, iKey, oKey, interfaceId, false);
Benedict Wong319f17e2018-05-15 17:06:44 -0700746 return binder::Status::ok();
manojboopathi8707f232018-01-02 14:45:47 -0800747}
748
Benedict Wong319f17e2018-05-15 17:06:44 -0700749binder::Status NetdNativeService::ipSecUpdateTunnelInterface(const std::string& deviceName,
750 const std::string& localAddress,
751 const std::string& remoteAddress,
Benedict Wonga450e722018-05-07 10:29:02 -0700752 int32_t iKey, int32_t oKey,
753 int32_t interfaceId) {
manojboopathi8707f232018-01-02 14:45:47 -0800754 // Necessary locking done in IpSecService and kernel
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900755 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wong319f17e2018-05-15 17:06:44 -0700756 netdutils::Status result = gCtls->xfrmCtrl.ipSecAddTunnelInterface(
Benedict Wonga450e722018-05-07 10:29:02 -0700757 deviceName, localAddress, remoteAddress, iKey, oKey, interfaceId, true);
Benedict Wong319f17e2018-05-15 17:06:44 -0700758 return binder::Status::ok();
manojboopathi8707f232018-01-02 14:45:47 -0800759}
760
Benedict Wong319f17e2018-05-15 17:06:44 -0700761binder::Status NetdNativeService::ipSecRemoveTunnelInterface(const std::string& deviceName) {
manojboopathi8707f232018-01-02 14:45:47 -0800762 // Necessary locking done in IpSecService and kernel
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900763 ENFORCE_NETWORK_STACK_PERMISSIONS();
Benedict Wong319f17e2018-05-15 17:06:44 -0700764 netdutils::Status result = gCtls->xfrmCtrl.ipSecRemoveTunnelInterface(deviceName);
Benedict Wong319f17e2018-05-15 17:06:44 -0700765 return binder::Status::ok();
manojboopathi8707f232018-01-02 14:45:47 -0800766}
767
Joel Scherpelzde937962017-06-01 13:20:21 +0900768binder::Status NetdNativeService::setIPv6AddrGenMode(const std::string& ifName,
769 int32_t mode) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900770 ENFORCE_NETWORK_STACK_PERMISSIONS();
Nathan Harold28ccfef2018-03-16 19:02:47 -0700771 return asBinderStatus(InterfaceController::setIPv6AddrGenMode(ifName, mode));
Joel Scherpelzde937962017-06-01 13:20:21 +0900772}
773
Joel Scherpelz08b84cd2017-05-22 13:11:54 +0900774binder::Status NetdNativeService::wakeupAddInterface(const std::string& ifName,
775 const std::string& prefix, int32_t mark,
776 int32_t mask) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900777 ENFORCE_NETWORK_STACK_PERMISSIONS();
Nathan Harold28ccfef2018-03-16 19:02:47 -0700778 return asBinderStatus(gCtls->wakeupCtrl.addInterface(ifName, prefix, mark, mask));
Joel Scherpelz08b84cd2017-05-22 13:11:54 +0900779}
780
781binder::Status NetdNativeService::wakeupDelInterface(const std::string& ifName,
782 const std::string& prefix, int32_t mark,
783 int32_t mask) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900784 ENFORCE_NETWORK_STACK_PERMISSIONS();
Nathan Harold28ccfef2018-03-16 19:02:47 -0700785 return asBinderStatus(gCtls->wakeupCtrl.delInterface(ifName, prefix, mark, mask));
Joel Scherpelz08b84cd2017-05-22 13:11:54 +0900786}
787
Chenbo Feng873ae142019-04-10 12:26:06 -0700788binder::Status NetdNativeService::trafficSwapActiveStatsMap() {
789 ENFORCE_NETWORK_STACK_PERMISSIONS();
790 return asBinderStatus(gCtls->trafficCtrl.swapActiveStatsMap());
791}
792
Luke Huang0051a622018-07-23 20:30:16 +0800793binder::Status NetdNativeService::idletimerAddInterface(const std::string& ifName, int32_t timeout,
794 const std::string& classLabel) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900795 NETD_LOCKING_RPC(gCtls->idletimerCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang0051a622018-07-23 20:30:16 +0800796 int res =
797 gCtls->idletimerCtrl.addInterfaceIdletimer(ifName.c_str(), timeout, classLabel.c_str());
Luke Huang0051a622018-07-23 20:30:16 +0800798 return statusFromErrcode(res);
799}
800
801binder::Status NetdNativeService::idletimerRemoveInterface(const std::string& ifName,
802 int32_t timeout,
803 const std::string& classLabel) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900804 NETD_LOCKING_RPC(gCtls->idletimerCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang0051a622018-07-23 20:30:16 +0800805 int res = gCtls->idletimerCtrl.removeInterfaceIdletimer(ifName.c_str(), timeout,
806 classLabel.c_str());
Luke Huang0051a622018-07-23 20:30:16 +0800807 return statusFromErrcode(res);
808}
Luke Huanga67dd562018-07-17 19:58:25 +0800809
810binder::Status NetdNativeService::strictUidCleartextPenalty(int32_t uid, int32_t policyPenalty) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900811 NETD_LOCKING_RPC(gCtls->strictCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huanga67dd562018-07-17 19:58:25 +0800812 StrictPenalty penalty;
813 switch (policyPenalty) {
814 case INetd::PENALTY_POLICY_REJECT:
815 penalty = REJECT;
816 break;
817 case INetd::PENALTY_POLICY_LOG:
818 penalty = LOG;
819 break;
820 case INetd::PENALTY_POLICY_ACCEPT:
821 penalty = ACCEPT;
822 break;
823 default:
824 return statusFromErrcode(-EINVAL);
825 break;
826 }
827 int res = gCtls->strictCtrl.setUidCleartextPenalty((uid_t) uid, penalty);
Luke Huanga67dd562018-07-17 19:58:25 +0800828 return statusFromErrcode(res);
829}
Luke Huange64fa382018-07-24 16:38:22 +0800830
Lorenzo Colitti7ef8c0f2019-01-11 22:34:58 +0900831binder::Status NetdNativeService::clatdStart(const std::string& ifName,
832 const std::string& nat64Prefix, std::string* v6Addr) {
Maciej Żenczykowski56280272019-03-30 03:32:51 -0700833 ENFORCE_ANY_PERMISSION(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Lorenzo Colitti7ef8c0f2019-01-11 22:34:58 +0900834 int res = gCtls->clatdCtrl.startClatd(ifName.c_str(), nat64Prefix, v6Addr);
Luke Huang6d301232018-08-01 14:05:18 +0800835 return statusFromErrcode(res);
836}
837
838binder::Status NetdNativeService::clatdStop(const std::string& ifName) {
Maciej Żenczykowski56280272019-03-30 03:32:51 -0700839 ENFORCE_ANY_PERMISSION(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang6d301232018-08-01 14:05:18 +0800840 int res = gCtls->clatdCtrl.stopClatd(ifName.c_str());
Luke Huang6d301232018-08-01 14:05:18 +0800841 return statusFromErrcode(res);
842}
Luke Huanga67dd562018-07-17 19:58:25 +0800843
Luke Huang457d4702018-08-16 15:39:15 +0800844binder::Status NetdNativeService::ipfwdEnabled(bool* status) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900845 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang728cf4c2019-03-14 19:43:02 +0800846 *status = (gCtls->tetherCtrl.getIpfwdRequesterList().size() > 0) ? true : false;
847 return binder::Status::ok();
848}
849
850binder::Status NetdNativeService::ipfwdGetRequesterList(std::vector<std::string>* requesterList) {
851 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
852 for (const auto& requester : gCtls->tetherCtrl.getIpfwdRequesterList()) {
853 requesterList->push_back(requester);
854 }
Luke Huang457d4702018-08-16 15:39:15 +0800855 return binder::Status::ok();
856}
857
858binder::Status NetdNativeService::ipfwdEnableForwarding(const std::string& requester) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900859 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang457d4702018-08-16 15:39:15 +0800860 int res = (gCtls->tetherCtrl.enableForwarding(requester.c_str())) ? 0 : -EREMOTEIO;
Luke Huang457d4702018-08-16 15:39:15 +0800861 return statusFromErrcode(res);
862}
863
864binder::Status NetdNativeService::ipfwdDisableForwarding(const std::string& requester) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900865 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang457d4702018-08-16 15:39:15 +0800866 int res = (gCtls->tetherCtrl.disableForwarding(requester.c_str())) ? 0 : -EREMOTEIO;
Luke Huang457d4702018-08-16 15:39:15 +0800867 return statusFromErrcode(res);
868}
869
870binder::Status NetdNativeService::ipfwdAddInterfaceForward(const std::string& fromIface,
871 const std::string& toIface) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900872 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huang457d4702018-08-16 15:39:15 +0800873 int res = RouteController::enableTethering(fromIface.c_str(), toIface.c_str());
Luke Huang457d4702018-08-16 15:39:15 +0800874 return statusFromErrcode(res);
875}
876
877binder::Status NetdNativeService::ipfwdRemoveInterfaceForward(const std::string& fromIface,
878 const std::string& toIface) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900879 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huang457d4702018-08-16 15:39:15 +0800880 int res = RouteController::disableTethering(fromIface.c_str(), toIface.c_str());
Luke Huang457d4702018-08-16 15:39:15 +0800881 return statusFromErrcode(res);
882}
883
Luke Huangf7782042018-08-08 13:13:04 +0800884namespace {
Luke Huangeedd6a52020-03-04 16:43:12 +0800885
Luke Huangf7782042018-08-08 13:13:04 +0800886std::string addCurlyBrackets(const std::string& s) {
887 return "{" + s + "}";
888}
889
890} // namespace
Xiao Ma33d562a2018-12-16 16:27:38 +0900891
Luke Huangf7782042018-08-08 13:13:04 +0800892binder::Status NetdNativeService::interfaceGetList(std::vector<std::string>* interfaceListResult) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900893 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800894 const auto& ifaceList = InterfaceController::getIfaceNames();
Luke Huangf7782042018-08-08 13:13:04 +0800895
896 interfaceListResult->clear();
897 interfaceListResult->reserve(ifaceList.value().size());
898 interfaceListResult->insert(end(*interfaceListResult), begin(ifaceList.value()),
899 end(ifaceList.value()));
900
Luke Huangf7782042018-08-08 13:13:04 +0800901 return binder::Status::ok();
902}
903
904std::string interfaceConfigurationParcelToString(const InterfaceConfigurationParcel& cfg) {
905 std::vector<std::string> result{cfg.ifName, cfg.hwAddr, cfg.ipv4Addr,
906 std::to_string(cfg.prefixLength)};
907 result.insert(end(result), begin(cfg.flags), end(cfg.flags));
908 return addCurlyBrackets(base::Join(result, ", "));
909}
910
911binder::Status NetdNativeService::interfaceGetCfg(
912 const std::string& ifName, InterfaceConfigurationParcel* interfaceGetCfgResult) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900913 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800914 auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName);
915
916 const auto& cfgRes = InterfaceController::getCfg(ifName);
917 RETURN_BINDER_STATUS_IF_NOT_OK(entry, cfgRes);
918
919 *interfaceGetCfgResult = cfgRes.value();
920 gLog.log(entry.returns(interfaceConfigurationParcelToString(*interfaceGetCfgResult))
921 .withAutomaticDuration());
922 return binder::Status::ok();
923}
924
925binder::Status NetdNativeService::interfaceSetCfg(const InterfaceConfigurationParcel& cfg) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900926 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800927 auto entry = gLog.newEntry()
928 .prettyFunction(__PRETTY_FUNCTION__)
929 .arg(interfaceConfigurationParcelToString(cfg));
930
931 const auto& res = InterfaceController::setCfg(cfg);
932 RETURN_BINDER_STATUS_IF_NOT_OK(entry, res);
933
934 gLog.log(entry.withAutomaticDuration());
935 return binder::Status::ok();
936}
937
938binder::Status NetdNativeService::interfaceSetIPv6PrivacyExtensions(const std::string& ifName,
939 bool enable) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900940 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800941 int res = InterfaceController::setIPv6PrivacyExtensions(ifName.c_str(), enable);
Luke Huangf7782042018-08-08 13:13:04 +0800942 return statusFromErrcode(res);
943}
944
945binder::Status NetdNativeService::interfaceClearAddrs(const std::string& ifName) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900946 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800947 int res = InterfaceController::clearAddrs(ifName.c_str());
Luke Huangf7782042018-08-08 13:13:04 +0800948 return statusFromErrcode(res);
949}
950
951binder::Status NetdNativeService::interfaceSetEnableIPv6(const std::string& ifName, bool enable) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900952 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800953 int res = InterfaceController::setEnableIPv6(ifName.c_str(), enable);
Luke Huangf7782042018-08-08 13:13:04 +0800954 return statusFromErrcode(res);
955}
956
957binder::Status NetdNativeService::interfaceSetMtu(const std::string& ifName, int32_t mtuValue) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900958 NETD_LOCKING_RPC(InterfaceController::mutex, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangf7782042018-08-08 13:13:04 +0800959 std::string mtu = std::to_string(mtuValue);
960 int res = InterfaceController::setMtu(ifName.c_str(), mtu.c_str());
Luke Huangf7782042018-08-08 13:13:04 +0800961 return statusFromErrcode(res);
962}
963
Luke Huangb5733d72018-08-21 17:17:19 +0800964binder::Status NetdNativeService::tetherStart(const std::vector<std::string>& dhcpRanges) {
Chiachang Wang08cb2112019-12-10 09:53:24 +0800965 TetherConfigParcel config;
966 config.usingLegacyDnsProxy = true;
967 config.dhcpRanges = dhcpRanges;
968 return tetherStartWithConfiguration(config);
Luke Huang91bd3e12019-08-20 11:33:52 +0800969}
970
Chiachang Wang08cb2112019-12-10 09:53:24 +0800971binder::Status NetdNativeService::tetherStartWithConfiguration(const TetherConfigParcel& config) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900972 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Chiachang Wang08cb2112019-12-10 09:53:24 +0800973 if (config.dhcpRanges.size() % 2 == 1) {
Luke Huangb5733d72018-08-21 17:17:19 +0800974 return statusFromErrcode(-EINVAL);
975 }
Chiachang Wang08cb2112019-12-10 09:53:24 +0800976 // TODO: Pass TetherConfigParcel directly.
977 int res = gCtls->tetherCtrl.startTethering(config.usingLegacyDnsProxy, config.dhcpRanges);
Luke Huangb5733d72018-08-21 17:17:19 +0800978 return statusFromErrcode(res);
979}
980
981binder::Status NetdNativeService::tetherStop() {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900982 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +0800983 int res = gCtls->tetherCtrl.stopTethering();
Luke Huangb5733d72018-08-21 17:17:19 +0800984 return statusFromErrcode(res);
985}
986
987binder::Status NetdNativeService::tetherIsEnabled(bool* enabled) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900988 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +0800989 *enabled = gCtls->tetherCtrl.isTetheringStarted();
Luke Huangb5733d72018-08-21 17:17:19 +0800990 return binder::Status::ok();
991}
992
993binder::Status NetdNativeService::tetherInterfaceAdd(const std::string& ifName) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +0900994 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +0800995 int res = gCtls->tetherCtrl.tetherInterface(ifName.c_str());
Luke Huangb5733d72018-08-21 17:17:19 +0800996 return statusFromErrcode(res);
997}
998
999binder::Status NetdNativeService::tetherInterfaceRemove(const std::string& ifName) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001000 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +08001001 int res = gCtls->tetherCtrl.untetherInterface(ifName.c_str());
Luke Huangb5733d72018-08-21 17:17:19 +08001002 return statusFromErrcode(res);
1003}
1004
1005binder::Status NetdNativeService::tetherInterfaceList(std::vector<std::string>* ifList) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001006 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +08001007 for (const auto& ifname : gCtls->tetherCtrl.getTetheredInterfaceList()) {
1008 ifList->push_back(ifname);
1009 }
Luke Huangb5733d72018-08-21 17:17:19 +08001010 return binder::Status::ok();
1011}
1012
1013binder::Status NetdNativeService::tetherDnsSet(int32_t netId,
1014 const std::vector<std::string>& dnsAddrs) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001015 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +08001016 int res = gCtls->tetherCtrl.setDnsForwarders(netId, dnsAddrs);
Luke Huangb5733d72018-08-21 17:17:19 +08001017 return statusFromErrcode(res);
1018}
1019
1020binder::Status NetdNativeService::tetherDnsList(std::vector<std::string>* dnsList) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001021 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangb5733d72018-08-21 17:17:19 +08001022 for (const auto& fwdr : gCtls->tetherCtrl.getDnsForwarders()) {
1023 dnsList->push_back(fwdr);
1024 }
Luke Huangb5733d72018-08-21 17:17:19 +08001025 return binder::Status::ok();
1026}
1027
Tyler Wearfa94a272019-12-05 15:01:48 -08001028binder::Status NetdNativeService::networkAddRouteParcel(int32_t netId,
1029 const RouteInfoParcel& route) {
1030 // Public methods of NetworkController are thread-safe.
1031 ENFORCE_NETWORK_STACK_PERMISSIONS();
1032 bool legacy = false;
1033 uid_t uid = 0; // UID is only meaningful for legacy routes.
1034
1035 // convert Parcel to parameters
1036 int res = gCtls->netCtrl.addRoute(netId, route.ifName.c_str(), route.destination.c_str(),
1037 route.nextHop.empty() ? nullptr : route.nextHop.c_str(),
1038 legacy, uid, route.mtu);
1039 return statusFromErrcode(res);
1040}
1041
1042binder::Status NetdNativeService::networkUpdateRouteParcel(int32_t netId,
1043 const RouteInfoParcel& route) {
1044 // Public methods of NetworkController are thread-safe.
1045 ENFORCE_NETWORK_STACK_PERMISSIONS();
1046 bool legacy = false;
1047 uid_t uid = 0; // UID is only meaningful for legacy routes.
1048
1049 // convert Parcel to parameters
1050 int res = gCtls->netCtrl.updateRoute(netId, route.ifName.c_str(), route.destination.c_str(),
1051 route.nextHop.empty() ? nullptr : route.nextHop.c_str(),
1052 legacy, uid, route.mtu);
1053 return statusFromErrcode(res);
1054}
1055
1056binder::Status NetdNativeService::networkRemoveRouteParcel(int32_t netId,
1057 const RouteInfoParcel& route) {
1058 return networkRemoveRoute(netId, route.ifName, route.destination, route.nextHop);
1059}
1060
Luke Huangb670d162018-08-23 20:01:13 +08001061binder::Status NetdNativeService::networkAddRoute(int32_t netId, const std::string& ifName,
1062 const std::string& destination,
1063 const std::string& nextHop) {
1064 // Public methods of NetworkController are thread-safe.
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001065 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001066 bool legacy = false;
1067 uid_t uid = 0; // UID is only meaningful for legacy routes.
1068 int res = gCtls->netCtrl.addRoute(netId, ifName.c_str(), destination.c_str(),
Tyler Wearfa94a272019-12-05 15:01:48 -08001069 nextHop.empty() ? nullptr : nextHop.c_str(), legacy, uid, 0);
Luke Huangb670d162018-08-23 20:01:13 +08001070 return statusFromErrcode(res);
1071}
1072
1073binder::Status NetdNativeService::networkRemoveRoute(int32_t netId, const std::string& ifName,
1074 const std::string& destination,
1075 const std::string& nextHop) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001076 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001077 bool legacy = false;
1078 uid_t uid = 0; // UID is only meaningful for legacy routes.
1079 int res = gCtls->netCtrl.removeRoute(netId, ifName.c_str(), destination.c_str(),
1080 nextHop.empty() ? nullptr : nextHop.c_str(), legacy, uid);
Luke Huangb670d162018-08-23 20:01:13 +08001081 return statusFromErrcode(res);
1082}
1083
1084binder::Status NetdNativeService::networkAddLegacyRoute(int32_t netId, const std::string& ifName,
1085 const std::string& destination,
1086 const std::string& nextHop, int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001087 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001088 bool legacy = true;
1089 int res = gCtls->netCtrl.addRoute(netId, ifName.c_str(), destination.c_str(),
1090 nextHop.empty() ? nullptr : nextHop.c_str(), legacy,
Tyler Wearfa94a272019-12-05 15:01:48 -08001091 (uid_t)uid, 0);
Luke Huangb670d162018-08-23 20:01:13 +08001092 return statusFromErrcode(res);
1093}
1094
1095binder::Status NetdNativeService::networkRemoveLegacyRoute(int32_t netId, const std::string& ifName,
1096 const std::string& destination,
1097 const std::string& nextHop,
1098 int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001099 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001100 bool legacy = true;
1101 int res = gCtls->netCtrl.removeRoute(netId, ifName.c_str(), destination.c_str(),
1102 nextHop.empty() ? nullptr : nextHop.c_str(), legacy,
1103 (uid_t) uid);
Luke Huangb670d162018-08-23 20:01:13 +08001104 return statusFromErrcode(res);
1105}
1106
1107binder::Status NetdNativeService::networkGetDefault(int32_t* netId) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001108 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001109 *netId = gCtls->netCtrl.getDefaultNetwork();
Luke Huangb670d162018-08-23 20:01:13 +08001110 return binder::Status::ok();
1111}
1112
1113binder::Status NetdNativeService::networkSetDefault(int32_t netId) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001114 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001115 int res = gCtls->netCtrl.setDefaultNetwork(netId);
Luke Huangb670d162018-08-23 20:01:13 +08001116 return statusFromErrcode(res);
1117}
1118
1119binder::Status NetdNativeService::networkClearDefault() {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001120 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001121 unsigned netId = NETID_UNSET;
1122 int res = gCtls->netCtrl.setDefaultNetwork(netId);
Luke Huangb670d162018-08-23 20:01:13 +08001123 return statusFromErrcode(res);
1124}
1125
1126std::vector<uid_t> NetdNativeService::intsToUids(const std::vector<int32_t>& intUids) {
1127 return {begin(intUids), end(intUids)};
1128}
1129
1130Permission NetdNativeService::convertPermission(int32_t permission) {
1131 switch (permission) {
1132 case INetd::PERMISSION_NETWORK:
1133 return Permission::PERMISSION_NETWORK;
1134 case INetd::PERMISSION_SYSTEM:
1135 return Permission::PERMISSION_SYSTEM;
1136 default:
1137 return Permission::PERMISSION_NONE;
1138 }
1139}
1140
1141binder::Status NetdNativeService::networkSetPermissionForNetwork(int32_t netId,
1142 int32_t permission) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001143 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001144 std::vector<unsigned> netIds = {(unsigned) netId};
1145 int res = gCtls->netCtrl.setPermissionForNetworks(convertPermission(permission), netIds);
Luke Huangb670d162018-08-23 20:01:13 +08001146 return statusFromErrcode(res);
1147}
1148
1149binder::Status NetdNativeService::networkSetPermissionForUser(int32_t permission,
1150 const std::vector<int32_t>& uids) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001151 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001152 gCtls->netCtrl.setPermissionForUsers(convertPermission(permission), intsToUids(uids));
Luke Huangb670d162018-08-23 20:01:13 +08001153 return binder::Status::ok();
1154}
1155
1156binder::Status NetdNativeService::networkClearPermissionForUser(const std::vector<int32_t>& uids) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001157 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001158 Permission permission = Permission::PERMISSION_NONE;
1159 gCtls->netCtrl.setPermissionForUsers(permission, intsToUids(uids));
Luke Huangb670d162018-08-23 20:01:13 +08001160 return binder::Status::ok();
1161}
1162
Ken Chen155fb6a2020-12-10 18:50:19 +08001163binder::Status NetdNativeService::networkSetProtectAllow(int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001164 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001165 std::vector<uid_t> uids = {(uid_t) uid};
1166 gCtls->netCtrl.allowProtect(uids);
Luke Huangb670d162018-08-23 20:01:13 +08001167 return binder::Status::ok();
1168}
1169
1170binder::Status NetdNativeService::networkSetProtectDeny(int32_t uid) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001171 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001172 std::vector<uid_t> uids = {(uid_t) uid};
1173 gCtls->netCtrl.denyProtect(uids);
Luke Huangb670d162018-08-23 20:01:13 +08001174 return binder::Status::ok();
1175}
1176
1177binder::Status NetdNativeService::networkCanProtect(int32_t uid, bool* ret) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001178 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huangb670d162018-08-23 20:01:13 +08001179 *ret = gCtls->netCtrl.canProtect((uid_t) uid);
Luke Huangb670d162018-08-23 20:01:13 +08001180 return binder::Status::ok();
1181}
1182
Chenbo Feng48eaed32018-12-26 17:40:21 -08001183binder::Status NetdNativeService::trafficSetNetPermForUids(int32_t permission,
1184 const std::vector<int32_t>& uids) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001185 ENFORCE_NETWORK_STACK_PERMISSIONS();
Chenbo Feng48eaed32018-12-26 17:40:21 -08001186 gCtls->trafficCtrl.setPermissionForUids(permission, intsToUids(uids));
Chenbo Feng48eaed32018-12-26 17:40:21 -08001187 return binder::Status::ok();
1188}
1189
Luke Huange64fa382018-07-24 16:38:22 +08001190binder::Status NetdNativeService::firewallSetFirewallType(int32_t firewallType) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001191 NETD_LOCKING_RPC(gCtls->firewallCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huange64fa382018-07-24 16:38:22 +08001192 auto type = static_cast<FirewallType>(firewallType);
1193
1194 int res = gCtls->firewallCtrl.setFirewallType(type);
Luke Huange64fa382018-07-24 16:38:22 +08001195 return statusFromErrcode(res);
1196}
1197
1198binder::Status NetdNativeService::firewallSetInterfaceRule(const std::string& ifName,
1199 int32_t firewallRule) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001200 NETD_LOCKING_RPC(gCtls->firewallCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huange64fa382018-07-24 16:38:22 +08001201 auto rule = static_cast<FirewallRule>(firewallRule);
1202
1203 int res = gCtls->firewallCtrl.setInterfaceRule(ifName.c_str(), rule);
Luke Huange64fa382018-07-24 16:38:22 +08001204 return statusFromErrcode(res);
1205}
1206
1207binder::Status NetdNativeService::firewallSetUidRule(int32_t childChain, int32_t uid,
1208 int32_t firewallRule) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001209 NETD_LOCKING_RPC(gCtls->firewallCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huange64fa382018-07-24 16:38:22 +08001210 auto chain = static_cast<ChildChain>(childChain);
1211 auto rule = static_cast<FirewallRule>(firewallRule);
1212
1213 int res = gCtls->firewallCtrl.setUidRule(chain, uid, rule);
Luke Huange64fa382018-07-24 16:38:22 +08001214 return statusFromErrcode(res);
1215}
1216
1217binder::Status NetdNativeService::firewallEnableChildChain(int32_t childChain, bool enable) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001218 NETD_LOCKING_RPC(gCtls->firewallCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huange64fa382018-07-24 16:38:22 +08001219 auto chain = static_cast<ChildChain>(childChain);
1220
1221 int res = gCtls->firewallCtrl.enableChildChains(chain, enable);
Luke Huange64fa382018-07-24 16:38:22 +08001222 return statusFromErrcode(res);
1223}
1224
Rubin Xuec27ff22019-01-08 21:33:03 +00001225binder::Status NetdNativeService::firewallAddUidInterfaceRules(const std::string& ifName,
1226 const std::vector<int32_t>& uids) {
1227 ENFORCE_NETWORK_STACK_PERMISSIONS();
1228
1229 return asBinderStatus(gCtls->trafficCtrl.addUidInterfaceRules(
1230 RouteController::getIfIndex(ifName.c_str()), uids));
1231}
1232
1233binder::Status NetdNativeService::firewallRemoveUidInterfaceRules(
1234 const std::vector<int32_t>& uids) {
1235 ENFORCE_NETWORK_STACK_PERMISSIONS();
1236
1237 return asBinderStatus(gCtls->trafficCtrl.removeUidInterfaceRules(uids));
1238}
1239
Luke Huang19b49c52018-10-22 12:12:05 +09001240binder::Status NetdNativeService::tetherAddForward(const std::string& intIface,
1241 const std::string& extIface) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001242 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huang19b49c52018-10-22 12:12:05 +09001243
1244 int res = gCtls->tetherCtrl.enableNat(intIface.c_str(), extIface.c_str());
Luke Huang19b49c52018-10-22 12:12:05 +09001245 return statusFromErrcode(res);
1246}
1247
1248binder::Status NetdNativeService::tetherRemoveForward(const std::string& intIface,
1249 const std::string& extIface) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001250 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Luke Huangae038f82018-11-05 11:17:31 +09001251 int res = gCtls->tetherCtrl.disableNat(intIface.c_str(), extIface.c_str());
Luke Huang19b49c52018-10-22 12:12:05 +09001252 return statusFromErrcode(res);
1253}
1254
Chenbo Fengf5663d82018-11-08 16:10:48 -08001255binder::Status NetdNativeService::setTcpRWmemorySize(const std::string& rmemValues,
1256 const std::string& wmemValues) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001257 ENFORCE_NETWORK_STACK_PERMISSIONS();
Chenbo Fengf5663d82018-11-08 16:10:48 -08001258 if (!WriteStringToFile(rmemValues, TCP_RMEM_PROC_FILE)) {
1259 int ret = -errno;
Chenbo Fengf5663d82018-11-08 16:10:48 -08001260 return statusFromErrcode(ret);
1261 }
1262
1263 if (!WriteStringToFile(wmemValues, TCP_WMEM_PROC_FILE)) {
1264 int ret = -errno;
Chenbo Fengf5663d82018-11-08 16:10:48 -08001265 return statusFromErrcode(ret);
1266 }
Chenbo Fengf5663d82018-11-08 16:10:48 -08001267 return binder::Status::ok();
1268}
1269
Luke Huang528af602018-08-29 19:06:05 +08001270binder::Status NetdNativeService::registerUnsolicitedEventListener(
1271 const android::sp<android::net::INetdUnsolicitedEventListener>& listener) {
Remi NGUYEN VANa686ebc2019-02-07 12:25:23 +09001272 ENFORCE_NETWORK_STACK_PERMISSIONS();
Bernie Innocenti9ee088d2019-02-01 17:14:32 +09001273 gCtls->eventReporter.registerUnsolEventListener(listener);
Luke Huang528af602018-08-29 19:06:05 +08001274 return binder::Status::ok();
1275}
1276
Luke Huange60bfd82019-04-26 11:39:31 +08001277binder::Status NetdNativeService::getOemNetd(android::sp<android::IBinder>* listener) {
1278 ENFORCE_NETWORK_STACK_PERMISSIONS();
Luke Huang0e5e69d2019-03-06 15:42:38 +08001279 *listener = com::android::internal::net::OemNetdListener::getListener();
1280
Luke Huange60bfd82019-04-26 11:39:31 +08001281 return binder::Status::ok();
1282}
1283
Chiachang Wang00fc62f2019-12-04 20:38:26 +08001284binder::Status NetdNativeService::getFwmarkForNetwork(int32_t netId, MarkMaskParcel* markMask) {
1285 ENFORCE_NETWORK_STACK_PERMISSIONS();
1286
1287 Fwmark fwmark;
1288 fwmark.netId = netId;
1289 markMask->mask = FWMARK_NET_ID_MASK;
1290 markMask->mark = fwmark.intValue;
1291 return binder::Status::ok();
1292}
1293
Hungming Chenea8b2302021-02-04 20:31:52 +08001294// TODO: remark @deprecated in INetd.aidl.
1295binder::Status NetdNativeService::tetherOffloadRuleAdd(const TetherOffloadRuleParcel& /* rule */) {
1296 // deprecated
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001297 ENFORCE_NETWORK_STACK_PERMISSIONS();
Hungming Chenea8b2302021-02-04 20:31:52 +08001298 return binder::Status::fromExceptionCode(binder::Status::EX_UNSUPPORTED_OPERATION);
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001299}
1300
Hungming Chenea8b2302021-02-04 20:31:52 +08001301// TODO: remark @deprecated in INetd.aidl.
1302binder::Status NetdNativeService::tetherOffloadRuleRemove(
1303 const TetherOffloadRuleParcel& /* rule */) {
1304 // deprecated
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001305 ENFORCE_NETWORK_STACK_PERMISSIONS();
Hungming Chenea8b2302021-02-04 20:31:52 +08001306 return binder::Status::fromExceptionCode(binder::Status::EX_UNSUPPORTED_OPERATION);
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001307}
1308
Hungming Chenea8b2302021-02-04 20:31:52 +08001309// TODO: remark @deprecated in INetd.aidl.
Hungming Chenf40dc092020-03-12 16:21:03 +08001310binder::Status NetdNativeService::tetherOffloadGetStats(
Hungming Chenea8b2302021-02-04 20:31:52 +08001311 std::vector<TetherStatsParcel>* /* tetherStatsParcelVec */) {
1312 // deprecated
Hungming Chenf40dc092020-03-12 16:21:03 +08001313 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Hungming Chenea8b2302021-02-04 20:31:52 +08001314 return binder::Status::fromExceptionCode(binder::Status::EX_UNSUPPORTED_OPERATION);
Hungming Chenf40dc092020-03-12 16:21:03 +08001315}
1316
Hungming Chenea8b2302021-02-04 20:31:52 +08001317// TODO: remark @deprecated in INetd.aidl.
1318binder::Status NetdNativeService::tetherOffloadSetInterfaceQuota(int /* ifIndex */,
1319 int64_t /* quotaBytes */) {
1320 // deprecated
Hungming Chen0c476712020-03-16 13:53:19 +08001321 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Hungming Chenea8b2302021-02-04 20:31:52 +08001322 return binder::Status::fromExceptionCode(binder::Status::EX_UNSUPPORTED_OPERATION);
Hungming Chen0c476712020-03-16 13:53:19 +08001323}
1324
Hungming Chenea8b2302021-02-04 20:31:52 +08001325// TODO: remark @deprecated in INetd.aidl.
Hungming Chen468a20c2020-04-17 20:00:27 +08001326binder::Status NetdNativeService::tetherOffloadGetAndClearStats(
Hungming Chenea8b2302021-02-04 20:31:52 +08001327 int /* ifIndex */, android::net::TetherStatsParcel* /* tetherStats */) {
1328 // deprecated
Hungming Chen468a20c2020-04-17 20:00:27 +08001329 NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
Hungming Chenea8b2302021-02-04 20:31:52 +08001330 return binder::Status::fromExceptionCode(binder::Status::EX_UNSUPPORTED_OPERATION);
Hungming Chen468a20c2020-04-17 20:00:27 +08001331}
1332
Lorenzo Colittie4d626e2016-02-02 17:19:04 +09001333} // namespace net
1334} // namespace android