Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 1 | /** |
| 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 | |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 19 | #include <set> |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 20 | #include <tuple> |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 23 | #include <android-base/stringprintf.h> |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 24 | #include <android-base/strings.h> |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 25 | #include <cutils/properties.h> |
Logan Chien | 3f46148 | 2018-04-23 14:31:32 +0800 | [diff] [blame] | 26 | #include <log/log.h> |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 27 | #include <utils/Errors.h> |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 28 | #include <utils/String16.h> |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 29 | |
| 30 | #include <binder/IPCThreadState.h> |
| 31 | #include <binder/IServiceManager.h> |
| 32 | #include "android/net/BnNetd.h" |
| 33 | |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 34 | #include <openssl/base64.h> |
| 35 | |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 36 | #include "Controllers.h" |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 37 | #include "DumpWriter.h" |
Michal Karpinski | d544011 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 38 | #include "EventReporter.h" |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 39 | #include "InterfaceController.h" |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 40 | #include "NetdConstants.h" |
| 41 | #include "NetdNativeService.h" |
Erik Kline | 8589004 | 2018-05-25 19:19:11 +0900 | [diff] [blame] | 42 | #include "Process.h" |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 43 | #include "RouteController.h" |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 44 | #include "SockDiag.h" |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 45 | #include "UidRanges.h" |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 46 | |
| 47 | using android::base::StringPrintf; |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 48 | using android::os::PersistableBundle; |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 49 | |
| 50 | namespace android { |
| 51 | namespace net { |
| 52 | |
| 53 | namespace { |
| 54 | |
| 55 | const char CONNECTIVITY_INTERNAL[] = "android.permission.CONNECTIVITY_INTERNAL"; |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 56 | const char NETWORK_STACK[] = "android.permission.NETWORK_STACK"; |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 57 | const char DUMP[] = "android.permission.DUMP"; |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 58 | const char OPT_SHORT[] = "--short"; |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 59 | |
| 60 | binder::Status checkPermission(const char *permission) { |
| 61 | pid_t pid; |
| 62 | uid_t uid; |
| 63 | |
| 64 | if (checkCallingPermission(String16(permission), (int32_t *) &pid, (int32_t *) &uid)) { |
| 65 | return binder::Status::ok(); |
| 66 | } else { |
| 67 | auto err = StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission); |
| 68 | return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str())); |
| 69 | } |
| 70 | } |
| 71 | |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 72 | #define ENFORCE_DEBUGGABLE() { \ |
| 73 | char value[PROPERTY_VALUE_MAX + 1]; \ |
Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 74 | if (property_get("ro.debuggable", value, nullptr) != 1 \ |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 75 | || value[0] != '1') { \ |
| 76 | return binder::Status::fromExceptionCode( \ |
| 77 | binder::Status::EX_SECURITY, \ |
| 78 | String8("Not available in production builds.") \ |
| 79 | ); \ |
| 80 | } \ |
| 81 | } |
| 82 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 83 | #define ENFORCE_PERMISSION(permission) { \ |
| 84 | binder::Status status = checkPermission((permission)); \ |
| 85 | if (!status.isOk()) { \ |
| 86 | return status; \ |
| 87 | } \ |
| 88 | } |
| 89 | |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 90 | #define NETD_LOCKING_RPC(permission, lock) \ |
| 91 | ENFORCE_PERMISSION(permission); \ |
Bernie Innocenti | abf8a34 | 2018-08-10 15:17:16 +0900 | [diff] [blame] | 92 | std::lock_guard _lock(lock); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 93 | |
| 94 | #define NETD_BIG_LOCK_RPC(permission) NETD_LOCKING_RPC((permission), gBigNetdLock) |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 95 | |
| 96 | inline binder::Status statusFromErrcode(int ret) { |
| 97 | if (ret) { |
| 98 | return binder::Status::fromServiceSpecificError(-ret, strerror(-ret)); |
| 99 | } |
| 100 | return binder::Status::ok(); |
| 101 | } |
| 102 | |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 103 | bool contains(const Vector<String16>& words, const String16& word) { |
| 104 | for (const auto& w : words) { |
| 105 | if (w == word) return true; |
| 106 | } |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 107 | |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | |
| 111 | } // namespace |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 112 | |
Lorenzo Colitti | e4851de | 2016-03-17 13:23:28 +0900 | [diff] [blame] | 113 | status_t NetdNativeService::start() { |
| 114 | IPCThreadState::self()->disableBackgroundScheduling(true); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 115 | const status_t ret = BinderService<NetdNativeService>::publish(); |
Lorenzo Colitti | e4851de | 2016-03-17 13:23:28 +0900 | [diff] [blame] | 116 | if (ret != android::OK) { |
| 117 | return ret; |
| 118 | } |
| 119 | sp<ProcessState> ps(ProcessState::self()); |
| 120 | ps->startThreadPool(); |
| 121 | ps->giveThreadPoolName(); |
| 122 | return android::OK; |
| 123 | } |
| 124 | |
Hugo Benichi | 7b314e1 | 2018-01-15 21:54:00 +0900 | [diff] [blame] | 125 | status_t NetdNativeService::dump(int fd, const Vector<String16> &args) { |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 126 | const binder::Status dump_permission = checkPermission(DUMP); |
| 127 | if (!dump_permission.isOk()) { |
| 128 | const String8 msg(dump_permission.toString8()); |
| 129 | write(fd, msg.string(), msg.size()); |
| 130 | return PERMISSION_DENIED; |
| 131 | } |
| 132 | |
| 133 | // This method does not grab any locks. If individual classes need locking |
| 134 | // their dump() methods MUST handle locking appropriately. |
Hugo Benichi | 7b314e1 | 2018-01-15 21:54:00 +0900 | [diff] [blame] | 135 | |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 136 | DumpWriter dw(fd); |
Hugo Benichi | 7b314e1 | 2018-01-15 21:54:00 +0900 | [diff] [blame] | 137 | |
| 138 | if (!args.isEmpty() && args[0] == TcpSocketMonitor::DUMP_KEYWORD) { |
| 139 | dw.blankline(); |
| 140 | gCtls->tcpSocketMonitor.dump(dw); |
| 141 | dw.blankline(); |
| 142 | return NO_ERROR; |
| 143 | } |
| 144 | |
Chenbo Feng | ef29717 | 2018-03-26 10:53:33 -0700 | [diff] [blame] | 145 | if (!args.isEmpty() && args[0] == TrafficController::DUMP_KEYWORD) { |
| 146 | dw.blankline(); |
| 147 | gCtls->trafficCtrl.dump(dw, true); |
| 148 | dw.blankline(); |
| 149 | return NO_ERROR; |
| 150 | } |
| 151 | |
Erik Kline | 8589004 | 2018-05-25 19:19:11 +0900 | [diff] [blame] | 152 | process::dump(dw); |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 153 | dw.blankline(); |
| 154 | gCtls->netCtrl.dump(dw); |
| 155 | dw.blankline(); |
| 156 | |
Chenbo Feng | ef29717 | 2018-03-26 10:53:33 -0700 | [diff] [blame] | 157 | gCtls->trafficCtrl.dump(dw, false); |
| 158 | dw.blankline(); |
| 159 | |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 160 | { |
| 161 | ScopedIndent indentLog(dw); |
| 162 | if (contains(args, String16(OPT_SHORT))) { |
| 163 | dw.println("Log: <omitted>"); |
| 164 | } else { |
| 165 | dw.println("Log:"); |
| 166 | ScopedIndent indentLogEntries(dw); |
| 167 | gLog.forEachEntry([&dw](const std::string& entry) mutable { dw.println(entry); }); |
| 168 | } |
| 169 | dw.blankline(); |
| 170 | } |
| 171 | |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 172 | return NO_ERROR; |
| 173 | } |
| 174 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 175 | binder::Status NetdNativeService::isAlive(bool *alive) { |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 176 | NETD_BIG_LOCK_RPC(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 177 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__); |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 178 | |
| 179 | *alive = true; |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 180 | |
| 181 | gLog.log(entry.returns(*alive)); |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 182 | return binder::Status::ok(); |
| 183 | } |
| 184 | |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 185 | binder::Status NetdNativeService::firewallReplaceUidChain(const std::string& chainName, |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 186 | bool isWhitelist, const std::vector<int32_t>& uids, bool *ret) { |
| 187 | NETD_LOCKING_RPC(CONNECTIVITY_INTERNAL, gCtls->firewallCtrl.lock); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 188 | auto entry = gLog.newEntry() |
| 189 | .prettyFunction(__PRETTY_FUNCTION__) |
| 190 | .arg(chainName) |
| 191 | .arg(isWhitelist) |
| 192 | .arg(uids); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 193 | |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 194 | int err = gCtls->firewallCtrl.replaceUidChain(chainName, isWhitelist, uids); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 195 | *ret = (err == 0); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 196 | |
| 197 | gLog.log(entry.returns(*ret).withAutomaticDuration()); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 198 | return binder::Status::ok(); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 199 | } |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 200 | |
| 201 | binder::Status NetdNativeService::bandwidthEnableDataSaver(bool enable, bool *ret) { |
| 202 | NETD_LOCKING_RPC(CONNECTIVITY_INTERNAL, gCtls->bandwidthCtrl.lock); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 203 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(enable); |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 204 | |
| 205 | int err = gCtls->bandwidthCtrl.enableDataSaver(enable); |
| 206 | *ret = (err == 0); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 207 | gLog.log(entry.returns(*ret).withAutomaticDuration()); |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 208 | return binder::Status::ok(); |
| 209 | } |
| 210 | |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame] | 211 | binder::Status NetdNativeService::bandwidthSetInterfaceQuota(const std::string& ifName, |
| 212 | int64_t bytes) { |
| 213 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 214 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName).arg(bytes); |
| 215 | |
| 216 | int res = gCtls->bandwidthCtrl.setInterfaceQuota(ifName, bytes); |
| 217 | |
| 218 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 219 | return statusFromErrcode(res); |
| 220 | } |
| 221 | |
| 222 | binder::Status NetdNativeService::bandwidthRemoveInterfaceQuota(const std::string& ifName) { |
| 223 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 224 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName); |
| 225 | |
| 226 | int res = gCtls->bandwidthCtrl.removeInterfaceQuota(ifName); |
| 227 | |
| 228 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 229 | return statusFromErrcode(res); |
| 230 | } |
| 231 | |
| 232 | binder::Status NetdNativeService::bandwidthSetInterfaceAlert(const std::string& ifName, |
| 233 | int64_t bytes) { |
| 234 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 235 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName).arg(bytes); |
| 236 | |
| 237 | int res = gCtls->bandwidthCtrl.setInterfaceAlert(ifName, bytes); |
| 238 | |
| 239 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 240 | return statusFromErrcode(res); |
| 241 | } |
| 242 | |
| 243 | binder::Status NetdNativeService::bandwidthRemoveInterfaceAlert(const std::string& ifName) { |
| 244 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 245 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName); |
| 246 | |
| 247 | int res = gCtls->bandwidthCtrl.removeInterfaceAlert(ifName); |
| 248 | |
| 249 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 250 | return statusFromErrcode(res); |
| 251 | } |
| 252 | |
| 253 | binder::Status NetdNativeService::bandwidthSetGlobalAlert(int64_t bytes) { |
| 254 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 255 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(bytes); |
| 256 | |
| 257 | int res = gCtls->bandwidthCtrl.setGlobalAlert(bytes); |
| 258 | |
| 259 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 260 | return statusFromErrcode(res); |
| 261 | } |
| 262 | |
| 263 | binder::Status NetdNativeService::bandwidthAddNaughtyApp(int32_t uid) { |
| 264 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 265 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(uid); |
| 266 | |
| 267 | std::vector<std::string> appStrUids = {std::to_string(abs(uid))}; |
| 268 | int res = gCtls->bandwidthCtrl.addNaughtyApps(appStrUids); |
| 269 | |
| 270 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 271 | return statusFromErrcode(res); |
| 272 | } |
| 273 | |
| 274 | binder::Status NetdNativeService::bandwidthRemoveNaughtyApp(int32_t uid) { |
| 275 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 276 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(uid); |
| 277 | |
| 278 | std::vector<std::string> appStrUids = {std::to_string(abs(uid))}; |
| 279 | int res = gCtls->bandwidthCtrl.removeNaughtyApps(appStrUids); |
| 280 | |
| 281 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 282 | return statusFromErrcode(res); |
| 283 | } |
| 284 | |
| 285 | binder::Status NetdNativeService::bandwidthAddNiceApp(int32_t uid) { |
| 286 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 287 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(uid); |
| 288 | |
| 289 | std::vector<std::string> appStrUids = {std::to_string(abs(uid))}; |
| 290 | int res = gCtls->bandwidthCtrl.addNiceApps(appStrUids); |
| 291 | |
| 292 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 293 | return statusFromErrcode(res); |
| 294 | } |
| 295 | |
| 296 | binder::Status NetdNativeService::bandwidthRemoveNiceApp(int32_t uid) { |
| 297 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->bandwidthCtrl.lock); |
| 298 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(uid); |
| 299 | |
| 300 | std::vector<std::string> appStrUids = {std::to_string(abs(uid))}; |
| 301 | int res = gCtls->bandwidthCtrl.removeNiceApps(appStrUids); |
| 302 | |
| 303 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 304 | return statusFromErrcode(res); |
| 305 | } |
| 306 | |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 307 | binder::Status NetdNativeService::networkCreatePhysical(int32_t netId, |
| 308 | const std::string& permission) { |
| 309 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 310 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(netId).arg(permission); |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 311 | int ret = gCtls->netCtrl.createPhysicalNetwork(netId, stringToPermission(permission.c_str())); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 312 | gLog.log(entry.returns(ret).withAutomaticDuration()); |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 313 | return statusFromErrcode(ret); |
| 314 | } |
| 315 | |
| 316 | binder::Status NetdNativeService::networkCreateVpn(int32_t netId, bool hasDns, bool secure) { |
| 317 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 318 | int ret = gCtls->netCtrl.createVirtualNetwork(netId, hasDns, secure); |
| 319 | return statusFromErrcode(ret); |
| 320 | } |
| 321 | |
| 322 | binder::Status NetdNativeService::networkDestroy(int32_t netId) { |
Erik Kline | c8b6a9c | 2018-01-15 17:06:48 +0900 | [diff] [blame] | 323 | ENFORCE_PERMISSION(NETWORK_STACK); |
| 324 | // Both of these functions manage their own locking internally. |
| 325 | const int ret = gCtls->netCtrl.destroyNetwork(netId); |
| 326 | gCtls->resolverCtrl.clearDnsServers(netId); |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 327 | return statusFromErrcode(ret); |
| 328 | } |
| 329 | |
| 330 | binder::Status NetdNativeService::networkAddInterface(int32_t netId, const std::string& iface) { |
| 331 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 332 | int ret = gCtls->netCtrl.addInterfaceToNetwork(netId, iface.c_str()); |
| 333 | return statusFromErrcode(ret); |
| 334 | } |
| 335 | |
| 336 | binder::Status NetdNativeService::networkRemoveInterface(int32_t netId, const std::string& iface) { |
| 337 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 338 | int ret = gCtls->netCtrl.removeInterfaceFromNetwork(netId, iface.c_str()); |
| 339 | return statusFromErrcode(ret); |
| 340 | } |
| 341 | |
| 342 | binder::Status NetdNativeService::networkAddUidRanges(int32_t netId, |
| 343 | const std::vector<UidRange>& uidRangeArray) { |
| 344 | // NetworkController::addUsersToNetwork is thread-safe. |
| 345 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 346 | int ret = gCtls->netCtrl.addUsersToNetwork(netId, UidRanges(uidRangeArray)); |
| 347 | return statusFromErrcode(ret); |
| 348 | } |
| 349 | |
| 350 | binder::Status NetdNativeService::networkRemoveUidRanges(int32_t netId, |
| 351 | const std::vector<UidRange>& uidRangeArray) { |
| 352 | // NetworkController::removeUsersFromNetwork is thread-safe. |
| 353 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 354 | int ret = gCtls->netCtrl.removeUsersFromNetwork(netId, UidRanges(uidRangeArray)); |
| 355 | return statusFromErrcode(ret); |
| 356 | } |
| 357 | |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 358 | binder::Status NetdNativeService::networkRejectNonSecureVpn(bool add, |
| 359 | const std::vector<UidRange>& uidRangeArray) { |
| 360 | // TODO: elsewhere RouteController is only used from the tethering and network controllers, so |
| 361 | // it should be possible to use the same lock as NetworkController. However, every call through |
| 362 | // the CommandListener "network" command will need to hold this lock too, not just the ones that |
| 363 | // read/modify network internal state (that is sufficient for ::dump() because it doesn't |
| 364 | // look at routes, but it's not enough here). |
| 365 | NETD_BIG_LOCK_RPC(CONNECTIVITY_INTERNAL); |
| 366 | |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 367 | UidRanges uidRanges(uidRangeArray); |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 368 | |
| 369 | int err; |
| 370 | if (add) { |
| 371 | err = RouteController::addUsersToRejectNonSecureNetworkRule(uidRanges); |
| 372 | } else { |
| 373 | err = RouteController::removeUsersFromRejectNonSecureNetworkRule(uidRanges); |
| 374 | } |
| 375 | |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 376 | return statusFromErrcode(err); |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 379 | binder::Status NetdNativeService::socketDestroy(const std::vector<UidRange>& uids, |
| 380 | const std::vector<int32_t>& skipUids) { |
| 381 | |
| 382 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 383 | |
| 384 | SockDiag sd; |
| 385 | if (!sd.open()) { |
| 386 | return binder::Status::fromServiceSpecificError(EIO, |
| 387 | String8("Could not open SOCK_DIAG socket")); |
| 388 | } |
| 389 | |
| 390 | UidRanges uidRanges(uids); |
Lorenzo Colitti | e5c3c99 | 2016-07-26 17:53:50 +0900 | [diff] [blame] | 391 | int err = sd.destroySockets(uidRanges, std::set<uid_t>(skipUids.begin(), skipUids.end()), |
| 392 | true /* excludeLoopback */); |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 393 | |
| 394 | if (err) { |
| 395 | return binder::Status::fromServiceSpecificError(-err, |
| 396 | String8::format("destroySockets: %s", strerror(-err))); |
| 397 | } |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 398 | return binder::Status::ok(); |
| 399 | } |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 400 | |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 401 | // Parse a base64 encoded string into a vector of bytes. |
| 402 | // On failure, return an empty vector. |
| 403 | static std::vector<uint8_t> parseBase64(const std::string& input) { |
| 404 | std::vector<uint8_t> decoded; |
| 405 | size_t out_len; |
| 406 | if (EVP_DecodedLength(&out_len, input.size()) != 1) { |
| 407 | return decoded; |
| 408 | } |
| 409 | // out_len is now an upper bound on the output length. |
| 410 | decoded.resize(out_len); |
| 411 | if (EVP_DecodeBase64(decoded.data(), &out_len, decoded.size(), |
| 412 | reinterpret_cast<const uint8_t*>(input.data()), input.size()) == 1) { |
| 413 | // Possibly shrink the vector if the actual output was smaller than the bound. |
| 414 | decoded.resize(out_len); |
| 415 | } else { |
| 416 | decoded.clear(); |
| 417 | } |
| 418 | if (out_len != SHA256_SIZE) { |
| 419 | decoded.clear(); |
| 420 | } |
| 421 | return decoded; |
| 422 | } |
| 423 | |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 424 | binder::Status NetdNativeService::setResolverConfiguration(int32_t netId, |
| 425 | const std::vector<std::string>& servers, const std::vector<std::string>& domains, |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 426 | const std::vector<int32_t>& params, const std::string& tlsName, |
| 427 | const std::vector<std::string>& tlsServers, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 428 | const std::vector<std::string>& tlsFingerprints) { |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 429 | // This function intentionally does not lock within Netd, as Bionic is thread-safe. |
| 430 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 431 | auto entry = gLog.newEntry() |
| 432 | .prettyFunction(__PRETTY_FUNCTION__) |
| 433 | .arg(netId) |
| 434 | .arg(servers) |
| 435 | .arg(domains) |
| 436 | .arg(params) |
| 437 | .arg(tlsName) |
| 438 | .arg(tlsServers) |
| 439 | .arg(tlsFingerprints); |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 440 | |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 441 | std::set<std::vector<uint8_t>> decoded_fingerprints; |
| 442 | for (const std::string& fingerprint : tlsFingerprints) { |
| 443 | std::vector<uint8_t> decoded = parseBase64(fingerprint); |
| 444 | if (decoded.empty()) { |
| 445 | return binder::Status::fromServiceSpecificError(EINVAL, |
| 446 | String8::format("ResolverController error: bad fingerprint")); |
| 447 | } |
| 448 | decoded_fingerprints.emplace(decoded); |
| 449 | } |
| 450 | |
| 451 | int err = gCtls->resolverCtrl.setResolverConfiguration(netId, servers, domains, params, |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 452 | tlsName, tlsServers, decoded_fingerprints); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 453 | gLog.log(entry.returns(err).withAutomaticDuration()); |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 454 | if (err != 0) { |
| 455 | return binder::Status::fromServiceSpecificError(-err, |
| 456 | String8::format("ResolverController error: %s", strerror(-err))); |
| 457 | } |
| 458 | return binder::Status::ok(); |
| 459 | } |
| 460 | |
| 461 | binder::Status NetdNativeService::getResolverInfo(int32_t netId, |
| 462 | std::vector<std::string>* servers, std::vector<std::string>* domains, |
| 463 | std::vector<int32_t>* params, std::vector<int32_t>* stats) { |
| 464 | // This function intentionally does not lock within Netd, as Bionic is thread-safe. |
| 465 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 466 | |
| 467 | int err = gCtls->resolverCtrl.getResolverInfo(netId, servers, domains, params, stats); |
| 468 | if (err != 0) { |
| 469 | return binder::Status::fromServiceSpecificError(-err, |
| 470 | String8::format("ResolverController error: %s", strerror(-err))); |
| 471 | } |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 472 | return binder::Status::ok(); |
| 473 | } |
| 474 | |
Erik Kline | f48e4dd | 2016-07-18 04:02:07 +0900 | [diff] [blame] | 475 | binder::Status NetdNativeService::tetherApplyDnsInterfaces(bool *ret) { |
Luke Huang | d1ee462 | 2018-06-29 13:49:58 +0800 | [diff] [blame] | 476 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
Erik Kline | f48e4dd | 2016-07-18 04:02:07 +0900 | [diff] [blame] | 477 | |
| 478 | *ret = gCtls->tetherCtrl.applyDnsInterfaces(); |
| 479 | return binder::Status::ok(); |
| 480 | } |
| 481 | |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 482 | namespace { |
| 483 | |
| 484 | void tetherAddStats(PersistableBundle *bundle, const TetherController::TetherStats& stats) { |
| 485 | String16 iface = String16(stats.extIface.c_str()); |
| 486 | std::vector<int64_t> statsVector(INetd::TETHER_STATS_ARRAY_SIZE); |
| 487 | |
| 488 | bundle->getLongVector(iface, &statsVector); |
| 489 | if (statsVector.size() == 0) { |
| 490 | for (int i = 0; i < INetd::TETHER_STATS_ARRAY_SIZE; i++) statsVector.push_back(0); |
| 491 | } |
| 492 | |
Lorenzo Colitti | 9a65ac6 | 2017-09-04 18:07:56 +0900 | [diff] [blame] | 493 | statsVector[INetd::TETHER_STATS_RX_BYTES] += stats.rxBytes; |
| 494 | statsVector[INetd::TETHER_STATS_RX_PACKETS] += stats.rxPackets; |
| 495 | statsVector[INetd::TETHER_STATS_TX_BYTES] += stats.txBytes; |
| 496 | statsVector[INetd::TETHER_STATS_TX_PACKETS] += stats.txPackets; |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 497 | |
| 498 | bundle->putLongVector(iface, statsVector); |
| 499 | } |
| 500 | |
| 501 | } // namespace |
| 502 | |
| 503 | binder::Status NetdNativeService::tetherGetStats(PersistableBundle *bundle) { |
Luke Huang | d1ee462 | 2018-06-29 13:49:58 +0800 | [diff] [blame] | 504 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 505 | |
Lorenzo Colitti | 5192bf7 | 2017-09-04 13:30:59 +0900 | [diff] [blame] | 506 | const auto& statsList = gCtls->tetherCtrl.getTetherStats(); |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 507 | if (!isOk(statsList)) { |
Nathan Harold | 28ccfef | 2018-03-16 19:02:47 -0700 | [diff] [blame] | 508 | return asBinderStatus(statsList); |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | for (const auto& stats : statsList.value()) { |
| 512 | tetherAddStats(bundle, stats); |
| 513 | } |
| 514 | |
| 515 | return binder::Status::ok(); |
| 516 | } |
| 517 | |
Erik Kline | 53c2088 | 2016-08-02 15:22:53 +0900 | [diff] [blame] | 518 | binder::Status NetdNativeService::interfaceAddAddress(const std::string &ifName, |
| 519 | const std::string &addrString, int prefixLength) { |
| 520 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 521 | |
| 522 | const int err = InterfaceController::addAddress( |
| 523 | ifName.c_str(), addrString.c_str(), prefixLength); |
| 524 | if (err != 0) { |
| 525 | return binder::Status::fromServiceSpecificError(-err, |
| 526 | String8::format("InterfaceController error: %s", strerror(-err))); |
| 527 | } |
| 528 | return binder::Status::ok(); |
| 529 | } |
| 530 | |
| 531 | binder::Status NetdNativeService::interfaceDelAddress(const std::string &ifName, |
| 532 | const std::string &addrString, int prefixLength) { |
| 533 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 534 | |
| 535 | const int err = InterfaceController::delAddress( |
| 536 | ifName.c_str(), addrString.c_str(), prefixLength); |
| 537 | if (err != 0) { |
| 538 | return binder::Status::fromServiceSpecificError(-err, |
| 539 | String8::format("InterfaceController error: %s", strerror(-err))); |
| 540 | } |
| 541 | return binder::Status::ok(); |
| 542 | } |
| 543 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 544 | namespace { |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 545 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 546 | std::tuple<binder::Status, const char*, const char*> getPathComponents(int32_t ipversion, |
| 547 | int32_t category) { |
| 548 | const char* ipversionStr = nullptr; |
| 549 | switch (ipversion) { |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 550 | case INetd::IPV4: |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 551 | ipversionStr = "ipv4"; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 552 | break; |
| 553 | case INetd::IPV6: |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 554 | ipversionStr = "ipv6"; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 555 | break; |
| 556 | default: |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 557 | return {binder::Status::fromServiceSpecificError(EAFNOSUPPORT, "Bad IP version"), |
| 558 | nullptr, nullptr}; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 559 | } |
| 560 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 561 | const char* whichStr = nullptr; |
| 562 | switch (category) { |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 563 | case INetd::CONF: |
| 564 | whichStr = "conf"; |
| 565 | break; |
| 566 | case INetd::NEIGH: |
| 567 | whichStr = "neigh"; |
| 568 | break; |
| 569 | default: |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 570 | return {binder::Status::fromServiceSpecificError(EINVAL, "Bad category"), nullptr, |
| 571 | nullptr}; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 572 | } |
| 573 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 574 | return {binder::Status::ok(), ipversionStr, whichStr}; |
| 575 | } |
| 576 | |
| 577 | } // namespace |
| 578 | |
| 579 | binder::Status NetdNativeService::getProcSysNet(int32_t ipversion, int32_t which, |
| 580 | const std::string& ifname, |
| 581 | const std::string& parameter, std::string* value) { |
| 582 | ENFORCE_PERMISSION(NETWORK_STACK); |
| 583 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__) |
| 584 | .args(ipversion, which, ifname, parameter); |
| 585 | |
| 586 | const auto pathParts = getPathComponents(ipversion, which); |
| 587 | const auto& pathStatus = std::get<0>(pathParts); |
| 588 | if (!pathStatus.isOk()) { |
| 589 | gLog.log(entry.returns(pathStatus.exceptionCode()).withAutomaticDuration()); |
| 590 | return pathStatus; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 591 | } |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 592 | |
| 593 | const int err = InterfaceController::getParameter(std::get<1>(pathParts), |
| 594 | std::get<2>(pathParts), ifname.c_str(), |
| 595 | parameter.c_str(), value); |
| 596 | entry.returns(err); |
| 597 | if (err == 0) entry.returns(*value); |
| 598 | gLog.log(entry.withAutomaticDuration()); |
| 599 | return statusFromErrcode(err); |
| 600 | } |
| 601 | |
| 602 | binder::Status NetdNativeService::setProcSysNet(int32_t ipversion, int32_t which, |
| 603 | const std::string& ifname, |
| 604 | const std::string& parameter, |
| 605 | const std::string& value) { |
| 606 | ENFORCE_PERMISSION(NETWORK_STACK); |
| 607 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__) |
| 608 | .args(ipversion, which, ifname, parameter, value); |
| 609 | |
| 610 | const auto pathParts = getPathComponents(ipversion, which); |
| 611 | const auto& pathStatus = std::get<0>(pathParts); |
| 612 | if (!pathStatus.isOk()) { |
| 613 | gLog.log(entry.returns(pathStatus.exceptionCode()).withAutomaticDuration()); |
| 614 | return pathStatus; |
| 615 | } |
| 616 | |
| 617 | const int err = InterfaceController::setParameter(std::get<1>(pathParts), |
| 618 | std::get<2>(pathParts), ifname.c_str(), |
| 619 | parameter.c_str(), value.c_str()); |
| 620 | gLog.log(entry.returns(err).withAutomaticDuration()); |
| 621 | return statusFromErrcode(err); |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 622 | } |
| 623 | |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 624 | binder::Status NetdNativeService::getMetricsReportingLevel(int *reportingLevel) { |
| 625 | // This function intentionally does not lock, since the only thing it does is one read from an |
| 626 | // atomic_int. |
| 627 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 628 | ENFORCE_DEBUGGABLE(); |
| 629 | |
Michal Karpinski | d544011 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 630 | *reportingLevel = gCtls->eventReporter.getMetricsReportingLevel(); |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 631 | return binder::Status::ok(); |
| 632 | } |
| 633 | |
| 634 | binder::Status NetdNativeService::setMetricsReportingLevel(const int reportingLevel) { |
| 635 | // This function intentionally does not lock, since the only thing it does is one write to an |
| 636 | // atomic_int. |
| 637 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
| 638 | ENFORCE_DEBUGGABLE(); |
| 639 | |
Michal Karpinski | d544011 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 640 | return (gCtls->eventReporter.setMetricsReportingLevel(reportingLevel) == 0) |
| 641 | ? binder::Status::ok() |
| 642 | : binder::Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT); |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 643 | } |
| 644 | |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 645 | binder::Status NetdNativeService::ipSecSetEncapSocketOwner(const android::base::unique_fd& socket, |
| 646 | int newUid) { |
| 647 | ENFORCE_PERMISSION(NETWORK_STACK) |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 648 | gLog.log("ipSecSetEncapSocketOwner()"); |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 649 | |
| 650 | uid_t callerUid = IPCThreadState::self()->getCallingUid(); |
| 651 | return asBinderStatus(gCtls->xfrmCtrl.ipSecSetEncapSocketOwner(socket, newUid, callerUid)); |
| 652 | } |
| 653 | |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 654 | binder::Status NetdNativeService::ipSecAllocateSpi( |
| 655 | int32_t transformId, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 656 | const std::string& sourceAddress, |
| 657 | const std::string& destinationAddress, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 658 | int32_t inSpi, |
| 659 | int32_t* outSpi) { |
| 660 | // Necessary locking done in IpSecService and kernel |
| 661 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 662 | gLog.log("ipSecAllocateSpi()"); |
ludi | 6e8eccd | 2017-08-14 14:40:37 -0700 | [diff] [blame] | 663 | return asBinderStatus(gCtls->xfrmCtrl.ipSecAllocateSpi( |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 664 | transformId, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 665 | sourceAddress, |
| 666 | destinationAddress, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 667 | inSpi, |
| 668 | outSpi)); |
| 669 | } |
| 670 | |
| 671 | binder::Status NetdNativeService::ipSecAddSecurityAssociation( |
| 672 | int32_t transformId, |
| 673 | int32_t mode, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 674 | const std::string& sourceAddress, |
| 675 | const std::string& destinationAddress, |
Benedict Wong | 96abf48 | 2018-01-22 13:56:41 -0800 | [diff] [blame] | 676 | int32_t underlyingNetId, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 677 | int32_t spi, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 678 | int32_t markValue, |
| 679 | int32_t markMask, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 680 | const std::string& authAlgo, const std::vector<uint8_t>& authKey, int32_t authTruncBits, |
| 681 | const std::string& cryptAlgo, const std::vector<uint8_t>& cryptKey, int32_t cryptTruncBits, |
Benedict Wong | be65b43 | 2017-08-22 21:43:14 -0700 | [diff] [blame] | 682 | const std::string& aeadAlgo, const std::vector<uint8_t>& aeadKey, int32_t aeadIcvBits, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 683 | int32_t encapType, |
| 684 | int32_t encapLocalPort, |
ludi | ec83605 | 2017-05-20 14:17:05 -0700 | [diff] [blame] | 685 | int32_t encapRemotePort) { |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 686 | // Necessary locking done in IpSecService and kernel |
| 687 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 688 | gLog.log("ipSecAddSecurityAssociation()"); |
ludi | 6e8eccd | 2017-08-14 14:40:37 -0700 | [diff] [blame] | 689 | return asBinderStatus(gCtls->xfrmCtrl.ipSecAddSecurityAssociation( |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 690 | transformId, mode, sourceAddress, destinationAddress, underlyingNetId, spi, markValue, |
| 691 | markMask, authAlgo, authKey, authTruncBits, cryptAlgo, cryptKey, cryptTruncBits, |
| 692 | aeadAlgo, aeadKey, aeadIcvBits, encapType, encapLocalPort, encapRemotePort)); |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | binder::Status NetdNativeService::ipSecDeleteSecurityAssociation( |
| 696 | int32_t transformId, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 697 | const std::string& sourceAddress, |
| 698 | const std::string& destinationAddress, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 699 | int32_t spi, |
| 700 | int32_t markValue, |
| 701 | int32_t markMask) { |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 702 | // Necessary locking done in IpSecService and kernel |
| 703 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 704 | gLog.log("ipSecDeleteSecurityAssociation()"); |
ludi | 6e8eccd | 2017-08-14 14:40:37 -0700 | [diff] [blame] | 705 | return asBinderStatus(gCtls->xfrmCtrl.ipSecDeleteSecurityAssociation( |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 706 | transformId, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 707 | sourceAddress, |
| 708 | destinationAddress, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 709 | spi, |
| 710 | markValue, |
| 711 | markMask)); |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | binder::Status NetdNativeService::ipSecApplyTransportModeTransform( |
| 715 | const android::base::unique_fd& socket, |
| 716 | int32_t transformId, |
| 717 | int32_t direction, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 718 | const std::string& sourceAddress, |
| 719 | const std::string& destinationAddress, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 720 | int32_t spi) { |
| 721 | // Necessary locking done in IpSecService and kernel |
| 722 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 723 | gLog.log("ipSecApplyTransportModeTransform()"); |
ludi | 6e8eccd | 2017-08-14 14:40:37 -0700 | [diff] [blame] | 724 | return asBinderStatus(gCtls->xfrmCtrl.ipSecApplyTransportModeTransform( |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 725 | socket, |
| 726 | transformId, |
| 727 | direction, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 728 | sourceAddress, |
| 729 | destinationAddress, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 730 | spi)); |
| 731 | } |
| 732 | |
| 733 | binder::Status NetdNativeService::ipSecRemoveTransportModeTransform( |
| 734 | const android::base::unique_fd& socket) { |
| 735 | // Necessary locking done in IpSecService and kernel |
| 736 | ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 737 | gLog.log("ipSecRemoveTransportModeTransform()"); |
ludi | 6e8eccd | 2017-08-14 14:40:37 -0700 | [diff] [blame] | 738 | return asBinderStatus(gCtls->xfrmCtrl.ipSecRemoveTransportModeTransform( |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 739 | socket)); |
| 740 | } |
| 741 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 742 | binder::Status NetdNativeService::ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 743 | int32_t direction, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 744 | const std::string& tmplSrcAddress, |
| 745 | const std::string& tmplDstAddress, |
| 746 | int32_t spi, int32_t markValue, |
| 747 | int32_t markMask) { |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 748 | // Necessary locking done in IpSecService and kernel |
| 749 | ENFORCE_PERMISSION(NETWORK_STACK); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 750 | gLog.log("ipSecAddSecurityPolicy()"); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 751 | return asBinderStatus(gCtls->xfrmCtrl.ipSecAddSecurityPolicy( |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 752 | transformId, selAddrFamily, direction, tmplSrcAddress, tmplDstAddress, spi, markValue, |
| 753 | markMask)); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 754 | } |
| 755 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 756 | binder::Status NetdNativeService::ipSecUpdateSecurityPolicy(int32_t transformId, |
| 757 | int32_t selAddrFamily, |
| 758 | int32_t direction, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 759 | const std::string& tmplSrcAddress, |
| 760 | const std::string& tmplDstAddress, |
| 761 | int32_t spi, int32_t markValue, |
| 762 | int32_t markMask) { |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 763 | // Necessary locking done in IpSecService and kernel |
| 764 | ENFORCE_PERMISSION(NETWORK_STACK); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 765 | gLog.log("ipSecAddSecurityPolicy()"); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 766 | return asBinderStatus(gCtls->xfrmCtrl.ipSecUpdateSecurityPolicy( |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 767 | transformId, selAddrFamily, direction, tmplSrcAddress, tmplDstAddress, spi, markValue, |
| 768 | markMask)); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 771 | binder::Status NetdNativeService::ipSecDeleteSecurityPolicy(int32_t transformId, |
| 772 | int32_t selAddrFamily, |
| 773 | int32_t direction, int32_t markValue, |
| 774 | int32_t markMask) { |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 775 | // Necessary locking done in IpSecService and kernel |
| 776 | ENFORCE_PERMISSION(NETWORK_STACK); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 777 | gLog.log("ipSecAddSecurityPolicy()"); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 778 | return asBinderStatus(gCtls->xfrmCtrl.ipSecDeleteSecurityPolicy( |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 779 | transformId, selAddrFamily, direction, markValue, markMask)); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 780 | } |
| 781 | |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 782 | binder::Status NetdNativeService::addVirtualTunnelInterface( |
| 783 | const std::string& deviceName, |
| 784 | const std::string& localAddress, |
| 785 | const std::string& remoteAddress, |
| 786 | int32_t iKey, |
| 787 | int32_t oKey) { |
| 788 | // Necessary locking done in IpSecService and kernel |
| 789 | ENFORCE_PERMISSION(NETWORK_STACK); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 790 | gLog.log("addVirtualTunnelInterface()"); |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 791 | int ret = gCtls->xfrmCtrl.addVirtualTunnelInterface( |
| 792 | deviceName, |
| 793 | localAddress, |
| 794 | remoteAddress, |
| 795 | iKey, |
| 796 | oKey, |
| 797 | false); |
| 798 | |
| 799 | return (ret == 0) ? binder::Status::ok() : |
| 800 | asBinderStatus(netdutils::statusFromErrno( |
| 801 | ret, "Error in creating virtual tunnel interface.")); |
| 802 | } |
| 803 | |
| 804 | binder::Status NetdNativeService::updateVirtualTunnelInterface( |
| 805 | const std::string& deviceName, |
| 806 | const std::string& localAddress, |
| 807 | const std::string& remoteAddress, |
| 808 | int32_t iKey, |
| 809 | int32_t oKey) { |
| 810 | // Necessary locking done in IpSecService and kernel |
| 811 | ENFORCE_PERMISSION(NETWORK_STACK); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 812 | gLog.log("updateVirtualTunnelInterface()"); |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 813 | int ret = gCtls->xfrmCtrl.addVirtualTunnelInterface( |
| 814 | deviceName, |
| 815 | localAddress, |
| 816 | remoteAddress, |
| 817 | iKey, |
| 818 | oKey, |
| 819 | true); |
| 820 | |
| 821 | return (ret == 0) ? binder::Status::ok() : |
| 822 | asBinderStatus(netdutils::statusFromErrno( |
| 823 | ret, "Error in updating virtual tunnel interface.")); |
| 824 | } |
| 825 | |
| 826 | binder::Status NetdNativeService::removeVirtualTunnelInterface(const std::string& deviceName) { |
| 827 | // Necessary locking done in IpSecService and kernel |
| 828 | ENFORCE_PERMISSION(NETWORK_STACK); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 829 | gLog.log("removeVirtualTunnelInterface()"); |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 830 | int ret = gCtls->xfrmCtrl.removeVirtualTunnelInterface(deviceName); |
| 831 | |
| 832 | return (ret == 0) ? binder::Status::ok() : |
| 833 | asBinderStatus(netdutils::statusFromErrno( |
| 834 | ret, "Error in removing virtual tunnel interface.")); |
| 835 | } |
| 836 | |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 837 | binder::Status NetdNativeService::setIPv6AddrGenMode(const std::string& ifName, |
| 838 | int32_t mode) { |
| 839 | ENFORCE_PERMISSION(NETWORK_STACK); |
Nathan Harold | 28ccfef | 2018-03-16 19:02:47 -0700 | [diff] [blame] | 840 | return asBinderStatus(InterfaceController::setIPv6AddrGenMode(ifName, mode)); |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 841 | } |
| 842 | |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 843 | binder::Status NetdNativeService::wakeupAddInterface(const std::string& ifName, |
| 844 | const std::string& prefix, int32_t mark, |
| 845 | int32_t mask) { |
| 846 | ENFORCE_PERMISSION(NETWORK_STACK); |
Nathan Harold | 28ccfef | 2018-03-16 19:02:47 -0700 | [diff] [blame] | 847 | return asBinderStatus(gCtls->wakeupCtrl.addInterface(ifName, prefix, mark, mask)); |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | binder::Status NetdNativeService::wakeupDelInterface(const std::string& ifName, |
| 851 | const std::string& prefix, int32_t mark, |
| 852 | int32_t mask) { |
| 853 | ENFORCE_PERMISSION(NETWORK_STACK); |
Nathan Harold | 28ccfef | 2018-03-16 19:02:47 -0700 | [diff] [blame] | 854 | return asBinderStatus(gCtls->wakeupCtrl.delInterface(ifName, prefix, mark, mask)); |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 855 | } |
| 856 | |
Chenbo Feng | 07d43fe | 2017-12-21 14:38:51 -0800 | [diff] [blame] | 857 | binder::Status NetdNativeService::trafficCheckBpfStatsEnable(bool* ret) { |
| 858 | ENFORCE_PERMISSION(NETWORK_STACK); |
| 859 | *ret = gCtls->trafficCtrl.checkBpfStatsEnable(); |
| 860 | return binder::Status::ok(); |
| 861 | } |
| 862 | |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 863 | binder::Status NetdNativeService::idletimerAddInterface(const std::string& ifName, int32_t timeout, |
| 864 | const std::string& classLabel) { |
| 865 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->idletimerCtrl.lock); |
| 866 | auto entry = gLog.newEntry() |
| 867 | .prettyFunction(__PRETTY_FUNCTION__) |
| 868 | .arg(ifName) |
| 869 | .arg(timeout) |
| 870 | .arg(classLabel); |
| 871 | int res = |
| 872 | gCtls->idletimerCtrl.addInterfaceIdletimer(ifName.c_str(), timeout, classLabel.c_str()); |
| 873 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 874 | return statusFromErrcode(res); |
| 875 | } |
| 876 | |
| 877 | binder::Status NetdNativeService::idletimerRemoveInterface(const std::string& ifName, |
| 878 | int32_t timeout, |
| 879 | const std::string& classLabel) { |
| 880 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->idletimerCtrl.lock); |
| 881 | auto entry = gLog.newEntry() |
| 882 | .prettyFunction(__PRETTY_FUNCTION__) |
| 883 | .arg(ifName) |
| 884 | .arg(timeout) |
| 885 | .arg(classLabel); |
| 886 | int res = gCtls->idletimerCtrl.removeInterfaceIdletimer(ifName.c_str(), timeout, |
| 887 | classLabel.c_str()); |
| 888 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 889 | return statusFromErrcode(res); |
| 890 | } |
Luke Huang | a67dd56 | 2018-07-17 19:58:25 +0800 | [diff] [blame] | 891 | |
| 892 | binder::Status NetdNativeService::strictUidCleartextPenalty(int32_t uid, int32_t policyPenalty) { |
| 893 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->strictCtrl.lock); |
| 894 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(uid).arg(policyPenalty); |
| 895 | StrictPenalty penalty; |
| 896 | switch (policyPenalty) { |
| 897 | case INetd::PENALTY_POLICY_REJECT: |
| 898 | penalty = REJECT; |
| 899 | break; |
| 900 | case INetd::PENALTY_POLICY_LOG: |
| 901 | penalty = LOG; |
| 902 | break; |
| 903 | case INetd::PENALTY_POLICY_ACCEPT: |
| 904 | penalty = ACCEPT; |
| 905 | break; |
| 906 | default: |
| 907 | return statusFromErrcode(-EINVAL); |
| 908 | break; |
| 909 | } |
| 910 | int res = gCtls->strictCtrl.setUidCleartextPenalty((uid_t) uid, penalty); |
| 911 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 912 | return statusFromErrcode(res); |
| 913 | } |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 914 | binder::Status NetdNativeService::clatdStart(const std::string& ifName) { |
| 915 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->clatdCtrl.mutex); |
| 916 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName); |
| 917 | int res = gCtls->clatdCtrl.startClatd(ifName.c_str()); |
| 918 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 919 | return statusFromErrcode(res); |
| 920 | } |
| 921 | |
| 922 | binder::Status NetdNativeService::clatdStop(const std::string& ifName) { |
| 923 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->clatdCtrl.mutex); |
| 924 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName); |
| 925 | int res = gCtls->clatdCtrl.stopClatd(ifName.c_str()); |
| 926 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 927 | return statusFromErrcode(res); |
| 928 | } |
Luke Huang | a67dd56 | 2018-07-17 19:58:25 +0800 | [diff] [blame] | 929 | |
Luke Huang | 457d470 | 2018-08-16 15:39:15 +0800 | [diff] [blame] | 930 | binder::Status NetdNativeService::ipfwdEnabled(bool* status) { |
| 931 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 932 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__); |
| 933 | *status = (gCtls->tetherCtrl.forwardingRequestCount() > 0) ? true : false; |
| 934 | gLog.log(entry.returns(*status).withAutomaticDuration()); |
| 935 | return binder::Status::ok(); |
| 936 | } |
| 937 | |
| 938 | binder::Status NetdNativeService::ipfwdEnableForwarding(const std::string& requester) { |
| 939 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 940 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(requester); |
| 941 | int res = (gCtls->tetherCtrl.enableForwarding(requester.c_str())) ? 0 : -EREMOTEIO; |
| 942 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 943 | return statusFromErrcode(res); |
| 944 | } |
| 945 | |
| 946 | binder::Status NetdNativeService::ipfwdDisableForwarding(const std::string& requester) { |
| 947 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 948 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(requester); |
| 949 | int res = (gCtls->tetherCtrl.disableForwarding(requester.c_str())) ? 0 : -EREMOTEIO; |
| 950 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 951 | return statusFromErrcode(res); |
| 952 | } |
| 953 | |
| 954 | binder::Status NetdNativeService::ipfwdAddInterfaceForward(const std::string& fromIface, |
| 955 | const std::string& toIface) { |
| 956 | ENFORCE_PERMISSION(NETWORK_STACK); |
| 957 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(fromIface).arg(toIface); |
| 958 | int res = RouteController::enableTethering(fromIface.c_str(), toIface.c_str()); |
| 959 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 960 | return statusFromErrcode(res); |
| 961 | } |
| 962 | |
| 963 | binder::Status NetdNativeService::ipfwdRemoveInterfaceForward(const std::string& fromIface, |
| 964 | const std::string& toIface) { |
| 965 | ENFORCE_PERMISSION(NETWORK_STACK); |
| 966 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(fromIface).arg(toIface); |
| 967 | int res = RouteController::disableTethering(fromIface.c_str(), toIface.c_str()); |
| 968 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 969 | return statusFromErrcode(res); |
| 970 | } |
| 971 | |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame^] | 972 | binder::Status NetdNativeService::tetherStart(const std::vector<std::string>& dhcpRanges) { |
| 973 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 974 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(dhcpRanges); |
| 975 | if (dhcpRanges.size() % 2 == 1) { |
| 976 | return statusFromErrcode(-EINVAL); |
| 977 | } |
| 978 | int res = gCtls->tetherCtrl.startTethering(dhcpRanges); |
| 979 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 980 | return statusFromErrcode(res); |
| 981 | } |
| 982 | |
| 983 | binder::Status NetdNativeService::tetherStop() { |
| 984 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 985 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__); |
| 986 | int res = gCtls->tetherCtrl.stopTethering(); |
| 987 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 988 | return statusFromErrcode(res); |
| 989 | } |
| 990 | |
| 991 | binder::Status NetdNativeService::tetherIsEnabled(bool* enabled) { |
| 992 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 993 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__); |
| 994 | *enabled = gCtls->tetherCtrl.isTetheringStarted(); |
| 995 | gLog.log(entry.returns(*enabled).withAutomaticDuration()); |
| 996 | return binder::Status::ok(); |
| 997 | } |
| 998 | |
| 999 | binder::Status NetdNativeService::tetherInterfaceAdd(const std::string& ifName) { |
| 1000 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 1001 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName); |
| 1002 | int res = gCtls->tetherCtrl.tetherInterface(ifName.c_str()); |
| 1003 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 1004 | return statusFromErrcode(res); |
| 1005 | } |
| 1006 | |
| 1007 | binder::Status NetdNativeService::tetherInterfaceRemove(const std::string& ifName) { |
| 1008 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 1009 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(ifName); |
| 1010 | int res = gCtls->tetherCtrl.untetherInterface(ifName.c_str()); |
| 1011 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 1012 | return statusFromErrcode(res); |
| 1013 | } |
| 1014 | |
| 1015 | binder::Status NetdNativeService::tetherInterfaceList(std::vector<std::string>* ifList) { |
| 1016 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 1017 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__); |
| 1018 | for (const auto& ifname : gCtls->tetherCtrl.getTetheredInterfaceList()) { |
| 1019 | ifList->push_back(ifname); |
| 1020 | } |
| 1021 | gLog.log(entry.returns(true).withAutomaticDuration()); |
| 1022 | return binder::Status::ok(); |
| 1023 | } |
| 1024 | |
| 1025 | binder::Status NetdNativeService::tetherDnsSet(int32_t netId, |
| 1026 | const std::vector<std::string>& dnsAddrs) { |
| 1027 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 1028 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(netId).arg(dnsAddrs); |
| 1029 | int res = gCtls->tetherCtrl.setDnsForwarders(netId, dnsAddrs); |
| 1030 | gLog.log(entry.returns(res).withAutomaticDuration()); |
| 1031 | return statusFromErrcode(res); |
| 1032 | } |
| 1033 | |
| 1034 | binder::Status NetdNativeService::tetherDnsList(std::vector<std::string>* dnsList) { |
| 1035 | NETD_LOCKING_RPC(NETWORK_STACK, gCtls->tetherCtrl.lock); |
| 1036 | auto entry = gLog.newEntry().prettyFunction(__PRETTY_FUNCTION__); |
| 1037 | for (const auto& fwdr : gCtls->tetherCtrl.getDnsForwarders()) { |
| 1038 | dnsList->push_back(fwdr); |
| 1039 | } |
| 1040 | gLog.log(entry.returns(true).withAutomaticDuration()); |
| 1041 | return binder::Status::ok(); |
| 1042 | } |
| 1043 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 1044 | } // namespace net |
| 1045 | } // namespace android |