San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 17 | #include <errno.h> |
San Mehat | 1873784 | 2010-01-21 09:22:43 -0800 | [diff] [blame] | 18 | #include <fcntl.h> |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 19 | #include <inttypes.h> |
Lorenzo Colitti | c284128 | 2015-11-25 22:13:57 +0900 | [diff] [blame] | 20 | #include <netdb.h> |
Olivier Bailly | ff2c0d8 | 2010-11-17 11:45:07 -0800 | [diff] [blame] | 21 | #include <string.h> |
San Mehat | 1873784 | 2010-01-21 09:22:43 -0800 | [diff] [blame] | 22 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
San Mehat | 1873784 | 2010-01-21 09:22:43 -0800 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <sys/wait.h> |
| 27 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 28 | #include <netinet/in.h> |
| 29 | #include <arpa/inet.h> |
| 30 | |
Erik Kline | 5f0358b | 2018-02-16 15:08:09 +0900 | [diff] [blame] | 31 | #include <array> |
| 32 | #include <cstdlib> |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 33 | #include <regex> |
Erik Kline | 5f0358b | 2018-02-16 15:08:09 +0900 | [diff] [blame] | 34 | #include <string> |
| 35 | #include <vector> |
| 36 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 37 | #define LOG_TAG "TetherController" |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 38 | #include <android-base/strings.h> |
| 39 | #include <android-base/stringprintf.h> |
Kazuhiro Ondo | 6b858eb | 2011-06-24 20:31:03 -0500 | [diff] [blame] | 40 | #include <cutils/properties.h> |
Logan Chien | 3f46148 | 2018-04-23 14:31:32 +0800 | [diff] [blame] | 41 | #include <log/log.h> |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 42 | #include <netdutils/StatusOr.h> |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 43 | |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 44 | #include "Controllers.h" |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 45 | #include "Fwmark.h" |
JP Abgrall | 69261cb | 2014-06-19 18:35:24 -0700 | [diff] [blame] | 46 | #include "NetdConstants.h" |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 47 | #include "Permission.h" |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 48 | #include "InterfaceController.h" |
Lorenzo Colitti | e20a526 | 2017-05-09 18:30:44 +0900 | [diff] [blame] | 49 | #include "NetworkController.h" |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 50 | #include "ResponseCode.h" |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 51 | #include "TetherController.h" |
| 52 | |
Bernie Innocenti | 4debf3b | 2018-09-12 13:54:50 +0900 | [diff] [blame] | 53 | namespace android { |
| 54 | namespace net { |
| 55 | |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 56 | using android::base::Join; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 57 | using android::base::StringAppendF; |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 58 | using android::base::StringPrintf; |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 59 | using android::netdutils::statusFromErrno; |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 60 | using android::netdutils::StatusOr; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 61 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 62 | namespace { |
| 63 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 64 | const char BP_TOOLS_MODE[] = "bp-tools"; |
| 65 | const char IPV4_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv4/ip_forward"; |
| 66 | const char IPV6_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv6/conf/all/forwarding"; |
| 67 | const char SEPARATOR[] = "|"; |
Erik Kline | 93f9b22 | 2017-10-22 21:24:58 +0900 | [diff] [blame] | 68 | constexpr const char kTcpBeLiberal[] = "/proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal"; |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 69 | |
Erik Kline | 5f0358b | 2018-02-16 15:08:09 +0900 | [diff] [blame] | 70 | // Chosen to match AID_DNS_TETHER, as made "friendly" by fs_config_generator.py. |
| 71 | constexpr const char kDnsmasqUsername[] = "dns_tether"; |
| 72 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 73 | bool writeToFile(const char* filename, const char* value) { |
Nick Kralevich | b95c60c | 2016-11-19 09:09:16 -0800 | [diff] [blame] | 74 | int fd = open(filename, O_WRONLY | O_CLOEXEC); |
Nicolas Geoffray | afd4037 | 2015-03-16 11:58:06 +0000 | [diff] [blame] | 75 | if (fd < 0) { |
| 76 | ALOGE("Failed to open %s: %s", filename, strerror(errno)); |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | const ssize_t len = strlen(value); |
| 81 | if (write(fd, value, len) != len) { |
| 82 | ALOGE("Failed to write %s to %s: %s", value, filename, strerror(errno)); |
| 83 | close(fd); |
| 84 | return false; |
| 85 | } |
| 86 | close(fd); |
| 87 | return true; |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 88 | } |
| 89 | |
Erik Kline | 93f9b22 | 2017-10-22 21:24:58 +0900 | [diff] [blame] | 90 | // TODO: Consider altering TCP and UDP timeouts as well. |
| 91 | void configureForTethering(bool enabled) { |
| 92 | writeToFile(kTcpBeLiberal, enabled ? "1" : "0"); |
| 93 | } |
| 94 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 95 | bool configureForIPv6Router(const char *interface) { |
| 96 | return (InterfaceController::setEnableIPv6(interface, 0) == 0) |
| 97 | && (InterfaceController::setAcceptIPv6Ra(interface, 0) == 0) |
Erik Kline | 6cddf51 | 2016-08-09 15:28:42 +0900 | [diff] [blame] | 98 | && (InterfaceController::setAcceptIPv6Dad(interface, 0) == 0) |
| 99 | && (InterfaceController::setIPv6DadTransmits(interface, "0") == 0) |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 100 | && (InterfaceController::setEnableIPv6(interface, 1) == 0); |
| 101 | } |
| 102 | |
| 103 | void configureForIPv6Client(const char *interface) { |
| 104 | InterfaceController::setAcceptIPv6Ra(interface, 1); |
Erik Kline | 6cddf51 | 2016-08-09 15:28:42 +0900 | [diff] [blame] | 105 | InterfaceController::setAcceptIPv6Dad(interface, 1); |
| 106 | InterfaceController::setIPv6DadTransmits(interface, "1"); |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 107 | InterfaceController::setEnableIPv6(interface, 0); |
| 108 | } |
| 109 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 110 | bool inBpToolsMode() { |
| 111 | // In BP tools mode, do not disable IP forwarding |
| 112 | char bootmode[PROPERTY_VALUE_MAX] = {0}; |
| 113 | property_get("ro.bootmode", bootmode, "unknown"); |
| 114 | return !strcmp(BP_TOOLS_MODE, bootmode); |
| 115 | } |
| 116 | |
| 117 | } // namespace |
| 118 | |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 119 | auto TetherController::iptablesRestoreFunction = execIptablesRestoreWithOutput; |
| 120 | |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 121 | const std::string GET_TETHER_STATS_COMMAND = StringPrintf( |
| 122 | "*filter\n" |
| 123 | "-nvx -L %s\n" |
| 124 | "COMMIT\n", android::net::TetherController::LOCAL_TETHER_COUNTERS_CHAIN); |
| 125 | |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 126 | int TetherController::DnsmasqState::sendCmd(int daemonFd, const std::string& cmd) { |
| 127 | if (cmd.empty()) return 0; |
| 128 | |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 129 | gLog.log("Sending update msg to dnsmasq [%s]", cmd.c_str()); |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 130 | // Send the trailing \0 as well. |
| 131 | if (write(daemonFd, cmd.c_str(), cmd.size() + 1) < 0) { |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 132 | gLog.error("Failed to send update command to dnsmasq (%s)", strerror(errno)); |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 133 | errno = EREMOTEIO; |
| 134 | return -1; |
| 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | void TetherController::DnsmasqState::clear() { |
| 140 | update_ifaces_cmd.clear(); |
| 141 | update_dns_cmd.clear(); |
| 142 | } |
| 143 | |
| 144 | int TetherController::DnsmasqState::sendAllState(int daemonFd) const { |
| 145 | return sendCmd(daemonFd, update_ifaces_cmd) | sendCmd(daemonFd, update_dns_cmd); |
| 146 | } |
| 147 | |
Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 148 | TetherController::TetherController() { |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 149 | if (inBpToolsMode()) { |
| 150 | enableForwarding(BP_TOOLS_MODE); |
| 151 | } else { |
| 152 | setIpFwdEnabled(); |
| 153 | } |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 156 | bool TetherController::setIpFwdEnabled() { |
| 157 | bool success = true; |
Hugo Benichi | c4b3a0c | 2018-05-22 08:48:40 +0900 | [diff] [blame] | 158 | bool disable = mForwardingRequests.empty(); |
| 159 | const char* value = disable ? "0" : "1"; |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 160 | ALOGD("Setting IP forward enable = %s", value); |
| 161 | success &= writeToFile(IPV4_FORWARDING_PROC_FILE, value); |
| 162 | success &= writeToFile(IPV6_FORWARDING_PROC_FILE, value); |
Hugo Benichi | c4b3a0c | 2018-05-22 08:48:40 +0900 | [diff] [blame] | 163 | if (disable) { |
| 164 | // Turning off the forwarding sysconf in the kernel has the side effect |
| 165 | // of turning on ICMP redirect, which is a security hazard. |
| 166 | // Turn ICMP redirect back off immediately. |
| 167 | int rv = InterfaceController::disableIcmpRedirects(); |
| 168 | success &= (rv == 0); |
| 169 | } |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 170 | return success; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 173 | bool TetherController::enableForwarding(const char* requester) { |
| 174 | // Don't return an error if this requester already requested forwarding. Only return errors for |
| 175 | // things that the caller caller needs to care about, such as "couldn't write to the file to |
| 176 | // enable forwarding". |
| 177 | mForwardingRequests.insert(requester); |
| 178 | return setIpFwdEnabled(); |
| 179 | } |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 180 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 181 | bool TetherController::disableForwarding(const char* requester) { |
| 182 | mForwardingRequests.erase(requester); |
| 183 | return setIpFwdEnabled(); |
| 184 | } |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 185 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 186 | size_t TetherController::forwardingRequestCount() { |
| 187 | return mForwardingRequests.size(); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Erik Kline | 13fa01f | 2015-11-12 17:49:23 +0900 | [diff] [blame] | 190 | int TetherController::startTethering(int num_addrs, char **dhcp_ranges) { |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 191 | if (mDaemonPid != 0) { |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 192 | ALOGE("Tethering already started"); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 193 | errno = EBUSY; |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 194 | return -errno; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Steve Block | 7b984e3 | 2011-12-20 16:22:42 +0000 | [diff] [blame] | 197 | ALOGD("Starting tethering services"); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 198 | |
| 199 | pid_t pid; |
| 200 | int pipefd[2]; |
| 201 | |
| 202 | if (pipe(pipefd) < 0) { |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 203 | int res = errno; |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 204 | ALOGE("pipe failed (%s)", strerror(errno)); |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 205 | return -res; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* |
| 209 | * TODO: Create a monitoring thread to handle and restart |
| 210 | * the daemon if it exits prematurely |
| 211 | */ |
| 212 | if ((pid = fork()) < 0) { |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 213 | int res = errno; |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 214 | ALOGE("fork failed (%s)", strerror(errno)); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 215 | close(pipefd[0]); |
| 216 | close(pipefd[1]); |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 217 | return -res; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | if (!pid) { |
| 221 | close(pipefd[1]); |
| 222 | if (pipefd[0] != STDIN_FILENO) { |
| 223 | if (dup2(pipefd[0], STDIN_FILENO) != STDIN_FILENO) { |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 224 | int res = errno; |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 225 | ALOGE("dup2 failed (%s)", strerror(errno)); |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 226 | return -res; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 227 | } |
| 228 | close(pipefd[0]); |
| 229 | } |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 230 | |
Lorenzo Colitti | e20a526 | 2017-05-09 18:30:44 +0900 | [diff] [blame] | 231 | Fwmark fwmark; |
| 232 | fwmark.netId = NetworkController::LOCAL_NET_ID; |
| 233 | fwmark.explicitlySelected = true; |
| 234 | fwmark.protectedFromVpn = true; |
| 235 | fwmark.permission = PERMISSION_SYSTEM; |
| 236 | char markStr[UINT32_HEX_STRLEN]; |
| 237 | snprintf(markStr, sizeof(markStr), "0x%x", fwmark.intValue); |
| 238 | |
Erik Kline | 5f0358b | 2018-02-16 15:08:09 +0900 | [diff] [blame] | 239 | std::vector<const std::string> argVector = { |
| 240 | "/system/bin/dnsmasq", |
| 241 | "--keep-in-foreground", |
| 242 | "--no-resolv", |
| 243 | "--no-poll", |
| 244 | "--dhcp-authoritative", |
| 245 | // TODO: pipe through metered status from ConnService |
| 246 | "--dhcp-option-force=43,ANDROID_METERED", |
| 247 | "--pid-file", |
| 248 | "--listen-mark", markStr, |
| 249 | "--user", kDnsmasqUsername, |
| 250 | }; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 251 | |
Remi NGUYEN VAN | edbf5f6 | 2018-08-06 15:03:18 +0900 | [diff] [blame] | 252 | // DHCP server will be disabled if num_addrs == 0 and no --dhcp-range is passed. |
Erik Kline | 13fa01f | 2015-11-12 17:49:23 +0900 | [diff] [blame] | 253 | for (int addrIndex = 0; addrIndex < num_addrs; addrIndex += 2) { |
Remi NGUYEN VAN | edbf5f6 | 2018-08-06 15:03:18 +0900 | [diff] [blame] | 254 | argVector.push_back(StringPrintf("--dhcp-range=%s,%s,1h", dhcp_ranges[addrIndex], |
| 255 | dhcp_ranges[addrIndex + 1])); |
Erik Kline | 5f0358b | 2018-02-16 15:08:09 +0900 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | auto args = (char**)std::calloc(argVector.size() + 1, sizeof(char*)); |
| 259 | for (unsigned i = 0; i < argVector.size(); i++) { |
| 260 | args[i] = (char*)argVector[i].c_str(); |
Robert Greenwalt | 3208ea0 | 2010-03-24 16:32:55 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | if (execv(args[0], args)) { |
Erik Kline | 5f0358b | 2018-02-16 15:08:09 +0900 | [diff] [blame] | 264 | ALOGE("execv failed (%s)", strerror(errno)); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 265 | } |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 266 | ALOGE("Should never get here!"); |
JP Abgrall | ce4f379 | 2012-08-06 13:44:44 -0700 | [diff] [blame] | 267 | _exit(-1); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 268 | } else { |
| 269 | close(pipefd[0]); |
| 270 | mDaemonPid = pid; |
| 271 | mDaemonFd = pipefd[1]; |
Erik Kline | 93f9b22 | 2017-10-22 21:24:58 +0900 | [diff] [blame] | 272 | configureForTethering(true); |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 273 | applyDnsInterfaces(); |
Steve Block | 7b984e3 | 2011-12-20 16:22:42 +0000 | [diff] [blame] | 274 | ALOGD("Tethering services running"); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 280 | std::vector<char*> TetherController::toCstrVec(const std::vector<std::string>& addrs) { |
| 281 | std::vector<char*> addrsCstrVec{}; |
| 282 | addrsCstrVec.reserve(addrs.size()); |
| 283 | for (const auto& addr : addrs) { |
| 284 | addrsCstrVec.push_back(const_cast<char*>(addr.data())); |
| 285 | } |
| 286 | return addrsCstrVec; |
| 287 | } |
| 288 | |
| 289 | int TetherController::startTethering(const std::vector<std::string>& dhcpRanges) { |
| 290 | struct in_addr v4_addr; |
| 291 | for (const auto& dhcpRange : dhcpRanges) { |
| 292 | if (!inet_aton(dhcpRange.c_str(), &v4_addr)) { |
| 293 | return -EINVAL; |
| 294 | } |
| 295 | } |
| 296 | auto dhcp_ranges = toCstrVec(dhcpRanges); |
| 297 | return startTethering(dhcp_ranges.size(), dhcp_ranges.data()); |
| 298 | } |
| 299 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 300 | int TetherController::stopTethering() { |
Erik Kline | 93f9b22 | 2017-10-22 21:24:58 +0900 | [diff] [blame] | 301 | configureForTethering(false); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 302 | |
| 303 | if (mDaemonPid == 0) { |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 304 | ALOGE("Tethering already stopped"); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 305 | return 0; |
| 306 | } |
| 307 | |
Steve Block | 7b984e3 | 2011-12-20 16:22:42 +0000 | [diff] [blame] | 308 | ALOGD("Stopping tethering services"); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 309 | |
| 310 | kill(mDaemonPid, SIGTERM); |
Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 311 | waitpid(mDaemonPid, nullptr, 0); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 312 | mDaemonPid = 0; |
| 313 | close(mDaemonFd); |
| 314 | mDaemonFd = -1; |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 315 | mDnsmasqState.clear(); |
Steve Block | 7b984e3 | 2011-12-20 16:22:42 +0000 | [diff] [blame] | 316 | ALOGD("Tethering services stopped"); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 317 | return 0; |
| 318 | } |
Matthew Xie | 1994410 | 2012-07-12 16:42:07 -0700 | [diff] [blame] | 319 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 320 | bool TetherController::isTetheringStarted() { |
| 321 | return (mDaemonPid == 0 ? false : true); |
| 322 | } |
| 323 | |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 324 | // dnsmasq can't parse commands larger than this due to the fixed-size buffer |
| 325 | // in check_android_listeners(). The receiving buffer is 1024 bytes long, but |
| 326 | // dnsmasq reads up to 1023 bytes. |
Bernie Innocenti | 45238a1 | 2018-12-04 14:57:48 +0900 | [diff] [blame] | 327 | const size_t MAX_CMD_SIZE = 1023; |
Kenny Root | cf52faf | 2010-02-18 09:59:55 -0800 | [diff] [blame] | 328 | |
Bernie Innocenti | 45238a1 | 2018-12-04 14:57:48 +0900 | [diff] [blame] | 329 | // TODO: convert callers to the overload taking a vector<string> |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 330 | int TetherController::setDnsForwarders(unsigned netId, char **servers, int numServers) { |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 331 | Fwmark fwmark; |
| 332 | fwmark.netId = netId; |
| 333 | fwmark.explicitlySelected = true; |
| 334 | fwmark.protectedFromVpn = true; |
| 335 | fwmark.permission = PERMISSION_SYSTEM; |
| 336 | |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 337 | std::string daemonCmd = StringPrintf("update_dns%s0x%x", SEPARATOR, fwmark.intValue); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 338 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 339 | mDnsForwarders.clear(); |
Bernie Innocenti | 45238a1 | 2018-12-04 14:57:48 +0900 | [diff] [blame] | 340 | for (int i = 0; i < numServers; i++) { |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 341 | ALOGD("setDnsForwarders(0x%x %d = '%s')", fwmark.intValue, i, servers[i]); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 342 | |
Lorenzo Colitti | c284128 | 2015-11-25 22:13:57 +0900 | [diff] [blame] | 343 | addrinfo *res, hints = { .ai_flags = AI_NUMERICHOST }; |
Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 344 | int ret = getaddrinfo(servers[i], nullptr, &hints, &res); |
Lorenzo Colitti | c284128 | 2015-11-25 22:13:57 +0900 | [diff] [blame] | 345 | freeaddrinfo(res); |
| 346 | if (ret) { |
Steve Block | 5ea0c05 | 2012-01-06 19:18:11 +0000 | [diff] [blame] | 347 | ALOGE("Failed to parse DNS server '%s'", servers[i]); |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 348 | mDnsForwarders.clear(); |
Lorenzo Colitti | c284128 | 2015-11-25 22:13:57 +0900 | [diff] [blame] | 349 | errno = EINVAL; |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 350 | return -errno; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 351 | } |
Kenny Root | cf52faf | 2010-02-18 09:59:55 -0800 | [diff] [blame] | 352 | |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 353 | if (daemonCmd.size() + 1 + strlen(servers[i]) >= MAX_CMD_SIZE) { |
| 354 | ALOGE("Too many DNS servers listed"); |
Kenny Root | cf52faf | 2010-02-18 09:59:55 -0800 | [diff] [blame] | 355 | break; |
| 356 | } |
| 357 | |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 358 | daemonCmd += SEPARATOR; |
| 359 | daemonCmd += servers[i]; |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 360 | mDnsForwarders.push_back(servers[i]); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 361 | } |
| 362 | |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 363 | mDnsNetId = netId; |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 364 | mDnsmasqState.update_dns_cmd = std::move(daemonCmd); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 365 | if (mDaemonFd != -1) { |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 366 | if (mDnsmasqState.sendAllState(mDaemonFd) != 0) { |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 367 | mDnsForwarders.clear(); |
Lorenzo Colitti | c284128 | 2015-11-25 22:13:57 +0900 | [diff] [blame] | 368 | errno = EREMOTEIO; |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 369 | return -errno; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | return 0; |
| 373 | } |
| 374 | |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 375 | int TetherController::setDnsForwarders(unsigned netId, const std::vector<std::string>& servers) { |
| 376 | struct in_addr v4_addr; |
| 377 | struct in6_addr v6_addr; |
| 378 | for (const auto& server : servers) { |
| 379 | if (!inet_pton(AF_INET, server.c_str(), &v4_addr) && |
| 380 | !inet_pton(AF_INET6, server.c_str(), &v6_addr)) { |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | } |
| 384 | auto dnsServers = toCstrVec(servers); |
| 385 | return setDnsForwarders(netId, dnsServers.data(), dnsServers.size()); |
| 386 | } |
| 387 | |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 388 | unsigned TetherController::getDnsNetId() { |
| 389 | return mDnsNetId; |
| 390 | } |
| 391 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 392 | const std::list<std::string> &TetherController::getDnsForwarders() const { |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 393 | return mDnsForwarders; |
| 394 | } |
| 395 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 396 | bool TetherController::applyDnsInterfaces() { |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 397 | std::string daemonCmd = "update_ifaces"; |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 398 | bool haveInterfaces = false; |
| 399 | |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 400 | for (const auto& ifname : mInterfaces) { |
| 401 | if (daemonCmd.size() + 1 + ifname.size() >= MAX_CMD_SIZE) { |
| 402 | ALOGE("Too many DNS servers listed"); |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 406 | daemonCmd += SEPARATOR; |
| 407 | daemonCmd += ifname; |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 408 | haveInterfaces = true; |
| 409 | } |
| 410 | |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 411 | if (!haveInterfaces) { |
| 412 | mDnsmasqState.update_ifaces_cmd.clear(); |
| 413 | } else { |
Bernie Innocenti | 15bb55c | 2018-06-03 16:19:51 +0900 | [diff] [blame] | 414 | mDnsmasqState.update_ifaces_cmd = std::move(daemonCmd); |
Erik Kline | 15079dd | 2018-05-18 23:10:56 +0900 | [diff] [blame] | 415 | if (mDaemonFd != -1) return (mDnsmasqState.sendAllState(mDaemonFd) == 0); |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 416 | } |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 417 | return true; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 420 | int TetherController::tetherInterface(const char *interface) { |
| 421 | ALOGD("tetherInterface(%s)", interface); |
JP Abgrall | 69261cb | 2014-06-19 18:35:24 -0700 | [diff] [blame] | 422 | if (!isIfaceName(interface)) { |
| 423 | errno = ENOENT; |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 424 | return -errno; |
JP Abgrall | 69261cb | 2014-06-19 18:35:24 -0700 | [diff] [blame] | 425 | } |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 426 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 427 | if (!configureForIPv6Router(interface)) { |
| 428 | configureForIPv6Client(interface); |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 429 | return -EREMOTEIO; |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 430 | } |
| 431 | mInterfaces.push_back(interface); |
| 432 | |
| 433 | if (!applyDnsInterfaces()) { |
| 434 | mInterfaces.pop_back(); |
| 435 | configureForIPv6Client(interface); |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 436 | return -EREMOTEIO; |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 437 | } else { |
| 438 | return 0; |
| 439 | } |
| 440 | } |
| 441 | |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 442 | int TetherController::untetherInterface(const char *interface) { |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 443 | ALOGD("untetherInterface(%s)", interface); |
| 444 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 445 | for (auto it = mInterfaces.cbegin(); it != mInterfaces.cend(); ++it) { |
| 446 | if (!strcmp(interface, it->c_str())) { |
| 447 | mInterfaces.erase(it); |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 448 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 449 | configureForIPv6Client(interface); |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 450 | return applyDnsInterfaces() ? 0 : -EREMOTEIO; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | errno = ENOENT; |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 454 | return -errno; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Erik Kline | 1d065ba | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 457 | const std::list<std::string> &TetherController::getTetheredInterfaceList() const { |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 458 | return mInterfaces; |
| 459 | } |
Lorenzo Colitti | e20a526 | 2017-05-09 18:30:44 +0900 | [diff] [blame] | 460 | |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 461 | int TetherController::setupIptablesHooks() { |
| 462 | int res; |
| 463 | res = setDefaults(); |
| 464 | if (res < 0) { |
| 465 | return res; |
| 466 | } |
| 467 | |
| 468 | // Used to limit downstream mss to the upstream pmtu so we don't end up fragmenting every large |
| 469 | // packet tethered devices send. This is IPv4-only, because in IPv6 we send the MTU in the RA. |
| 470 | // This is no longer optional and tethering will fail to start if it fails. |
| 471 | std::string mssRewriteCommand = StringPrintf( |
| 472 | "*mangle\n" |
| 473 | "-A %s -p tcp --tcp-flags SYN SYN -j TCPMSS --clamp-mss-to-pmtu\n" |
| 474 | "COMMIT\n", LOCAL_MANGLE_FORWARD); |
| 475 | |
| 476 | // This is for tethering counters. This chain is reached via --goto, and then RETURNS. |
| 477 | std::string defaultCommands = StringPrintf( |
| 478 | "*filter\n" |
| 479 | ":%s -\n" |
| 480 | "COMMIT\n", LOCAL_TETHER_COUNTERS_CHAIN); |
| 481 | |
| 482 | res = iptablesRestoreFunction(V4, mssRewriteCommand, nullptr); |
| 483 | if (res < 0) { |
| 484 | return res; |
| 485 | } |
| 486 | |
| 487 | res = iptablesRestoreFunction(V4V6, defaultCommands, nullptr); |
| 488 | if (res < 0) { |
| 489 | return res; |
| 490 | } |
| 491 | |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 492 | mFwdIfaces.clear(); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | int TetherController::setDefaults() { |
| 498 | std::string v4Cmd = StringPrintf( |
| 499 | "*filter\n" |
| 500 | ":%s -\n" |
| 501 | "-A %s -j DROP\n" |
| 502 | "COMMIT\n" |
| 503 | "*nat\n" |
| 504 | ":%s -\n" |
| 505 | "COMMIT\n", LOCAL_FORWARD, LOCAL_FORWARD, LOCAL_NAT_POSTROUTING); |
| 506 | |
| 507 | std::string v6Cmd = StringPrintf( |
Luke Huang | ae038f8 | 2018-11-05 11:17:31 +0900 | [diff] [blame] | 508 | "*filter\n" |
| 509 | ":%s -\n" |
| 510 | "COMMIT\n" |
| 511 | "*raw\n" |
| 512 | ":%s -\n" |
| 513 | "COMMIT\n", |
| 514 | LOCAL_FORWARD, LOCAL_RAW_PREROUTING); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 515 | |
| 516 | int res = iptablesRestoreFunction(V4, v4Cmd, nullptr); |
| 517 | if (res < 0) { |
| 518 | return res; |
| 519 | } |
| 520 | |
| 521 | res = iptablesRestoreFunction(V6, v6Cmd, nullptr); |
| 522 | if (res < 0) { |
| 523 | return res; |
| 524 | } |
| 525 | |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | int TetherController::enableNat(const char* intIface, const char* extIface) { |
| 530 | ALOGV("enableNat(intIface=<%s>, extIface=<%s>)",intIface, extIface); |
| 531 | |
| 532 | if (!isIfaceName(intIface) || !isIfaceName(extIface)) { |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 533 | return -ENODEV; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* Bug: b/9565268. "enableNat wlan0 wlan0". For now we fail until java-land is fixed */ |
| 537 | if (!strcmp(intIface, extIface)) { |
| 538 | ALOGE("Duplicate interface specified: %s %s", intIface, extIface); |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 539 | return -EINVAL; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 540 | } |
| 541 | |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 542 | if (isForwardingPairEnabled(intIface, extIface)) { |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | // add this if we are the first enabled nat for this upstream |
| 547 | if (!isAnyForwardingEnabledOnUpstream(extIface)) { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 548 | std::vector<std::string> v4Cmds = { |
| 549 | "*nat", |
| 550 | StringPrintf("-A %s -o %s -j MASQUERADE", LOCAL_NAT_POSTROUTING, extIface), |
| 551 | "COMMIT\n" |
| 552 | }; |
| 553 | |
Luke Huang | ae038f8 | 2018-11-05 11:17:31 +0900 | [diff] [blame] | 554 | if (iptablesRestoreFunction(V4, Join(v4Cmds, '\n'), nullptr) || setupIPv6CountersChain() || |
| 555 | setTetherGlobalAlertRule()) { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 556 | ALOGE("Error setting postroute rule: iface=%s", extIface); |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 557 | if (!isAnyForwardingPairEnabled()) { |
| 558 | // unwind what's been done, but don't care about success - what more could we do? |
| 559 | setDefaults(); |
| 560 | } |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 561 | return -EREMOTEIO; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
| 565 | if (setForwardRules(true, intIface, extIface) != 0) { |
| 566 | ALOGE("Error setting forward rules"); |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 567 | if (!isAnyForwardingPairEnabled()) { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 568 | setDefaults(); |
| 569 | } |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 570 | return -ENODEV; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 571 | } |
| 572 | |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 573 | return 0; |
| 574 | } |
| 575 | |
Luke Huang | ae038f8 | 2018-11-05 11:17:31 +0900 | [diff] [blame] | 576 | int TetherController::setTetherGlobalAlertRule() { |
| 577 | // Only add this if we are the first enabled nat |
| 578 | if (isAnyForwardingPairEnabled()) { |
| 579 | return 0; |
| 580 | } |
| 581 | const std::string cmds = |
| 582 | "*filter\n" + |
| 583 | StringPrintf("-I %s -j %s\n", LOCAL_FORWARD, BandwidthController::LOCAL_GLOBAL_ALERT) + |
| 584 | "COMMIT\n"; |
| 585 | |
| 586 | return iptablesRestoreFunction(V4V6, cmds, nullptr); |
| 587 | } |
| 588 | |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 589 | int TetherController::setupIPv6CountersChain() { |
| 590 | // Only add this if we are the first enabled nat |
| 591 | if (isAnyForwardingPairEnabled()) { |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * IPv6 tethering doesn't need the state-based conntrack rules, so |
| 597 | * it unconditionally jumps to the tether counters chain all the time. |
| 598 | */ |
Luke Huang | ae038f8 | 2018-11-05 11:17:31 +0900 | [diff] [blame] | 599 | const std::string v6Cmds = |
| 600 | "*filter\n" + |
| 601 | StringPrintf("-A %s -g %s\n", LOCAL_FORWARD, LOCAL_TETHER_COUNTERS_CHAIN) + "COMMIT\n"; |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 602 | |
Luke Huang | ae038f8 | 2018-11-05 11:17:31 +0900 | [diff] [blame] | 603 | return iptablesRestoreFunction(V6, v6Cmds, nullptr); |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | // Gets a pointer to the ForwardingDownstream for an interface pair in the map, or nullptr |
| 607 | TetherController::ForwardingDownstream* TetherController::findForwardingDownstream( |
| 608 | const std::string& intIface, const std::string& extIface) { |
| 609 | auto extIfaceMatches = mFwdIfaces.equal_range(extIface); |
| 610 | for (auto it = extIfaceMatches.first; it != extIfaceMatches.second; ++it) { |
| 611 | if (it->second.iface == intIface) { |
| 612 | return &(it->second); |
| 613 | } |
| 614 | } |
| 615 | return nullptr; |
| 616 | } |
| 617 | |
| 618 | void TetherController::addForwardingPair(const std::string& intIface, const std::string& extIface) { |
| 619 | ForwardingDownstream* existingEntry = findForwardingDownstream(intIface, extIface); |
| 620 | if (existingEntry != nullptr) { |
| 621 | existingEntry->active = true; |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | mFwdIfaces.insert(std::pair<std::string, ForwardingDownstream>(extIface, { |
| 626 | .iface = intIface, |
| 627 | .active = true |
| 628 | })); |
| 629 | } |
| 630 | |
| 631 | void TetherController::markForwardingPairDisabled( |
| 632 | const std::string& intIface, const std::string& extIface) { |
| 633 | ForwardingDownstream* existingEntry = findForwardingDownstream(intIface, extIface); |
| 634 | if (existingEntry == nullptr) { |
| 635 | return; |
| 636 | } |
| 637 | |
| 638 | existingEntry->active = false; |
| 639 | } |
| 640 | |
| 641 | bool TetherController::isForwardingPairEnabled( |
| 642 | const std::string& intIface, const std::string& extIface) { |
| 643 | ForwardingDownstream* existingEntry = findForwardingDownstream(intIface, extIface); |
| 644 | return existingEntry != nullptr && existingEntry->active; |
| 645 | } |
| 646 | |
| 647 | bool TetherController::isAnyForwardingEnabledOnUpstream(const std::string& extIface) { |
| 648 | auto extIfaceMatches = mFwdIfaces.equal_range(extIface); |
| 649 | for (auto it = extIfaceMatches.first; it != extIfaceMatches.second; ++it) { |
| 650 | if (it->second.active) { |
| 651 | return true; |
| 652 | } |
| 653 | } |
| 654 | return false; |
| 655 | } |
| 656 | |
| 657 | bool TetherController::isAnyForwardingPairEnabled() { |
| 658 | for (auto& it : mFwdIfaces) { |
| 659 | if (it.second.active) { |
| 660 | return true; |
| 661 | } |
| 662 | } |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | bool TetherController::tetherCountingRuleExists( |
| 667 | const std::string& iface1, const std::string& iface2) { |
| 668 | // A counting rule exists if NAT was ever enabled for this interface pair, so if the pair |
| 669 | // is in the map regardless of its active status. Rules are added both ways so we check with |
| 670 | // the 2 combinations. |
| 671 | return findForwardingDownstream(iface1, iface2) != nullptr |
| 672 | || findForwardingDownstream(iface2, iface1) != nullptr; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /* static */ |
| 676 | std::string TetherController::makeTetherCountingRule(const char *if1, const char *if2) { |
| 677 | return StringPrintf("-A %s -i %s -o %s -j RETURN", LOCAL_TETHER_COUNTERS_CHAIN, if1, if2); |
| 678 | } |
| 679 | |
| 680 | int TetherController::setForwardRules(bool add, const char *intIface, const char *extIface) { |
| 681 | const char *op = add ? "-A" : "-D"; |
| 682 | |
| 683 | std::string rpfilterCmd = StringPrintf( |
| 684 | "*raw\n" |
| 685 | "%s %s -i %s -m rpfilter --invert ! -s fe80::/64 -j DROP\n" |
| 686 | "COMMIT\n", op, LOCAL_RAW_PREROUTING, intIface); |
| 687 | if (iptablesRestoreFunction(V6, rpfilterCmd, nullptr) == -1 && add) { |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 688 | return -EREMOTEIO; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | std::vector<std::string> v4 = { |
hiroaki.yokoyama | 04f2cb5 | 2018-06-13 18:47:30 +0900 | [diff] [blame] | 692 | "*raw", |
| 693 | StringPrintf("%s %s -p tcp --dport 21 -i %s -j CT --helper ftp", op, |
| 694 | LOCAL_RAW_PREROUTING, intIface), |
| 695 | StringPrintf("%s %s -p tcp --dport 1723 -i %s -j CT --helper pptp", op, |
| 696 | LOCAL_RAW_PREROUTING, intIface), |
| 697 | "COMMIT", |
| 698 | "*filter", |
| 699 | StringPrintf("%s %s -i %s -o %s -m state --state ESTABLISHED,RELATED -g %s", op, |
| 700 | LOCAL_FORWARD, extIface, intIface, LOCAL_TETHER_COUNTERS_CHAIN), |
| 701 | StringPrintf("%s %s -i %s -o %s -m state --state INVALID -j DROP", op, LOCAL_FORWARD, |
| 702 | intIface, extIface), |
| 703 | StringPrintf("%s %s -i %s -o %s -g %s", op, LOCAL_FORWARD, intIface, extIface, |
| 704 | LOCAL_TETHER_COUNTERS_CHAIN), |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 705 | }; |
| 706 | |
| 707 | std::vector<std::string> v6 = { |
| 708 | "*filter", |
| 709 | }; |
| 710 | |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 711 | // We only ever add tethering quota rules so that they stick. |
| 712 | if (add && !tetherCountingRuleExists(intIface, extIface)) { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 713 | v4.push_back(makeTetherCountingRule(intIface, extIface)); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 714 | v4.push_back(makeTetherCountingRule(extIface, intIface)); |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 715 | v6.push_back(makeTetherCountingRule(intIface, extIface)); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 716 | v6.push_back(makeTetherCountingRule(extIface, intIface)); |
| 717 | } |
| 718 | |
| 719 | // Always make sure the drop rule is at the end. |
| 720 | // TODO: instead of doing this, consider just rebuilding LOCAL_FORWARD completely from scratch |
Lorenzo Colitti | 4604b4a | 2017-08-24 19:21:50 +0900 | [diff] [blame] | 721 | // every time, starting with ":tetherctrl_FORWARD -\n". This would likely be a bit simpler. |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 722 | if (add) { |
| 723 | v4.push_back(StringPrintf("-D %s -j DROP", LOCAL_FORWARD)); |
| 724 | v4.push_back(StringPrintf("-A %s -j DROP", LOCAL_FORWARD)); |
| 725 | } |
| 726 | |
| 727 | v4.push_back("COMMIT\n"); |
| 728 | v6.push_back("COMMIT\n"); |
| 729 | |
| 730 | // We only add IPv6 rules here, never remove them. |
| 731 | if (iptablesRestoreFunction(V4, Join(v4, '\n'), nullptr) == -1 || |
| 732 | (add && iptablesRestoreFunction(V6, Join(v6, '\n'), nullptr) == -1)) { |
| 733 | // unwind what's been done, but don't care about success - what more could we do? |
| 734 | if (add) { |
| 735 | setForwardRules(false, intIface, extIface); |
| 736 | } |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 737 | return -EREMOTEIO; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 738 | } |
| 739 | |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 740 | if (add) { |
| 741 | addForwardingPair(intIface, extIface); |
| 742 | } else { |
| 743 | markForwardingPairDisabled(intIface, extIface); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | int TetherController::disableNat(const char* intIface, const char* extIface) { |
| 750 | if (!isIfaceName(intIface) || !isIfaceName(extIface)) { |
Luke Huang | ae038f8 | 2018-11-05 11:17:31 +0900 | [diff] [blame] | 751 | errno = ENODEV; |
| 752 | return -errno; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | setForwardRules(false, intIface, extIface); |
Remi NGUYEN VAN | 3b47c79 | 2018-03-20 14:44:12 +0900 | [diff] [blame] | 756 | if (!isAnyForwardingPairEnabled()) { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 757 | setDefaults(); |
| 758 | } |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | void TetherController::addStats(TetherStatsList& statsList, const TetherStats& stats) { |
| 763 | for (TetherStats& existing : statsList) { |
| 764 | if (existing.addStatsIfMatch(stats)) { |
| 765 | return; |
| 766 | } |
| 767 | } |
| 768 | // No match. Insert a new interface pair. |
| 769 | statsList.push_back(stats); |
| 770 | } |
| 771 | |
| 772 | /* |
| 773 | * Parse the ptks and bytes out of: |
Lorenzo Colitti | 4604b4a | 2017-08-24 19:21:50 +0900 | [diff] [blame] | 774 | * Chain tetherctrl_counters (4 references) |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 775 | * pkts bytes target prot opt in out source destination |
| 776 | * 26 2373 RETURN all -- wlan0 rmnet0 0.0.0.0/0 0.0.0.0/0 |
| 777 | * 27 2002 RETURN all -- rmnet0 wlan0 0.0.0.0/0 0.0.0.0/0 |
| 778 | * 1040 107471 RETURN all -- bt-pan rmnet0 0.0.0.0/0 0.0.0.0/0 |
| 779 | * 1450 1708806 RETURN all -- rmnet0 bt-pan 0.0.0.0/0 0.0.0.0/0 |
| 780 | * or: |
Lorenzo Colitti | 4604b4a | 2017-08-24 19:21:50 +0900 | [diff] [blame] | 781 | * Chain tetherctrl_counters (0 references) |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 782 | * pkts bytes target prot opt in out source destination |
| 783 | * 0 0 RETURN all wlan0 rmnet_data0 ::/0 ::/0 |
| 784 | * 0 0 RETURN all rmnet_data0 wlan0 ::/0 ::/0 |
| 785 | * |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 786 | */ |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 787 | int TetherController::addForwardChainStats(TetherStatsList& statsList, |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 788 | const std::string& statsOutput, |
| 789 | std::string &extraProcessingInfo) { |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 790 | enum IndexOfIptChain { |
| 791 | ORIG_LINE, |
| 792 | PACKET_COUNTS, |
| 793 | BYTE_COUNTS, |
| 794 | HYPHEN, |
| 795 | IFACE0_NAME, |
| 796 | IFACE1_NAME, |
| 797 | SOURCE, |
| 798 | DESTINATION |
| 799 | }; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 800 | TetherStats stats; |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 801 | const TetherStats empty; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 802 | |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 803 | static const std::string NUM = "(\\d+)"; |
| 804 | static const std::string IFACE = "([^\\s]+)"; |
| 805 | static const std::string DST = "(0.0.0.0/0|::/0)"; |
| 806 | static const std::string COUNTERS = "\\s*" + NUM + "\\s+" + NUM + |
| 807 | " RETURN all( -- | )" + IFACE + "\\s+" + IFACE + |
| 808 | "\\s+" + DST + "\\s+" + DST; |
| 809 | static const std::regex IP_RE(COUNTERS); |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 810 | |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 811 | const std::vector<std::string> lines = base::Split(statsOutput, "\n"); |
| 812 | int headerLine = 0; |
| 813 | for (const std::string& line : lines) { |
| 814 | // Skip headers. |
| 815 | if (headerLine < 2) { |
| 816 | if (line.empty()) { |
| 817 | ALOGV("Empty header while parsing tethering stats"); |
| 818 | return -EREMOTEIO; |
| 819 | } |
| 820 | headerLine++; |
| 821 | continue; |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 822 | } |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 823 | |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 824 | if (line.empty()) continue; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 825 | |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 826 | extraProcessingInfo = line; |
| 827 | std::smatch matches; |
| 828 | if (!std::regex_search(line, matches, IP_RE)) return -EREMOTEIO; |
| 829 | // Here use IP_RE to distiguish IPv4 and IPv6 iptables. |
| 830 | // IPv4 has "--" indicating what to do with fragments... |
| 831 | // 26 2373 RETURN all -- wlan0 rmnet0 0.0.0.0/0 0.0.0.0/0 |
| 832 | // ... but IPv6 does not. |
| 833 | // 26 2373 RETURN all wlan0 rmnet0 ::/0 ::/0 |
| 834 | // TODO: Replace strtoXX() calls with ParseUint() /ParseInt() |
| 835 | int64_t packets = strtoul(matches[PACKET_COUNTS].str().c_str(), nullptr, 10); |
| 836 | int64_t bytes = strtoul(matches[BYTE_COUNTS].str().c_str(), nullptr, 10); |
| 837 | std::string iface0 = matches[IFACE0_NAME].str(); |
| 838 | std::string iface1 = matches[IFACE1_NAME].str(); |
| 839 | std::string rest = matches[SOURCE].str(); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 840 | |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 841 | ALOGV("parse iface0=<%s> iface1=<%s> pkts=%" PRId64 " bytes=%" PRId64 |
| 842 | " rest=<%s> orig line=<%s>", |
| 843 | iface0.c_str(), iface1.c_str(), packets, bytes, rest.c_str(), line.c_str()); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 844 | /* |
| 845 | * The following assumes that the 1st rule has in:extIface out:intIface, |
| 846 | * which is what TetherController sets up. |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 847 | * The 1st matches rx, and sets up the pair for the tx side. |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 848 | */ |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 849 | if (!stats.intIface[0]) { |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 850 | ALOGV("0Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64 " rx_packets=%" PRId64 |
| 851 | " ", iface0.c_str(), iface1.c_str(), bytes, packets); |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 852 | stats.intIface = iface0; |
| 853 | stats.extIface = iface1; |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 854 | stats.txPackets = packets; |
| 855 | stats.txBytes = bytes; |
Lorenzo Colitti | 9a65ac6 | 2017-09-04 18:07:56 +0900 | [diff] [blame] | 856 | } else if (stats.intIface == iface1 && stats.extIface == iface0) { |
waynema | 71a0b59 | 2018-11-21 13:31:34 +0800 | [diff] [blame^] | 857 | ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64 " rx_packets=%" PRId64 |
| 858 | " ", iface0.c_str(), iface1.c_str(), bytes, packets); |
Lorenzo Colitti | 9a65ac6 | 2017-09-04 18:07:56 +0900 | [diff] [blame] | 859 | stats.rxPackets = packets; |
| 860 | stats.rxBytes = bytes; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 861 | } |
| 862 | if (stats.rxBytes != -1 && stats.txBytes != -1) { |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 863 | ALOGV("rx_bytes=%" PRId64" tx_bytes=%" PRId64, stats.rxBytes, stats.txBytes); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 864 | addStats(statsList, stats); |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 865 | stats = empty; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | /* It is always an error to find only one side of the stats. */ |
Lorenzo Colitti | 38fd136 | 2017-09-15 11:40:01 +0900 | [diff] [blame] | 870 | if (((stats.rxBytes == -1) != (stats.txBytes == -1))) { |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 871 | return -EREMOTEIO; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 872 | } |
| 873 | return 0; |
| 874 | } |
| 875 | |
Lorenzo Colitti | 5192bf7 | 2017-09-04 13:30:59 +0900 | [diff] [blame] | 876 | StatusOr<TetherController::TetherStatsList> TetherController::getTetherStats() { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 877 | TetherStatsList statsList; |
Lorenzo Colitti | 5192bf7 | 2017-09-04 13:30:59 +0900 | [diff] [blame] | 878 | std::string parsedIptablesOutput; |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 879 | |
| 880 | for (const IptablesTarget target : {V4, V6}) { |
| 881 | std::string statsString; |
Lorenzo Colitti | 0935339 | 2017-08-24 14:20:32 +0900 | [diff] [blame] | 882 | if (int ret = iptablesRestoreFunction(target, GET_TETHER_STATS_COMMAND, &statsString)) { |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 883 | return statusFromErrno(-ret, StringPrintf("failed to fetch tether stats (%d): %d", |
| 884 | target, ret)); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 885 | } |
| 886 | |
Lorenzo Colitti | 5192bf7 | 2017-09-04 13:30:59 +0900 | [diff] [blame] | 887 | if (int ret = addForwardChainStats(statsList, statsString, parsedIptablesOutput)) { |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 888 | return statusFromErrno(-ret, StringPrintf("failed to parse %s tether stats:\n%s", |
| 889 | target == V4 ? "IPv4": "IPv6", |
Lorenzo Colitti | 5192bf7 | 2017-09-04 13:30:59 +0900 | [diff] [blame] | 890 | parsedIptablesOutput.c_str())); |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 894 | return statsList; |
| 895 | } |
| 896 | |
Lorenzo Colitti | e20a526 | 2017-05-09 18:30:44 +0900 | [diff] [blame] | 897 | } // namespace net |
| 898 | } // namespace android |