| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #include "RouteController.h" |
| 18 | |
| Dan Albert | aa1be2b | 2015-01-06 09:36:17 -0800 | [diff] [blame] | 19 | #include <arpa/inet.h> |
| 20 | #include <errno.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <linux/fib_rules.h> |
| 23 | #include <net/if.h> |
| 24 | #include <sys/stat.h> |
| 25 | |
| Elliott Hughes | bd37832 | 2015-02-04 13:25:14 -0800 | [diff] [blame] | 26 | #include <private/android_filesystem_config.h> |
| 27 | |
| Dan Albert | aa1be2b | 2015-01-06 09:36:17 -0800 | [diff] [blame] | 28 | #include <map> |
| 29 | |
| Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 30 | #define LOG_TAG "Netd" |
| 31 | |
| Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 32 | #include "DummyNetwork.h" |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 33 | #include "Fwmark.h" |
| Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 34 | #include "NetdConstants.h" |
| Lorenzo Colitti | 1ef549d | 2017-02-13 18:32:09 +0900 | [diff] [blame] | 35 | #include "NetlinkCommands.h" |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 36 | #include "OffloadUtils.h" |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 37 | #include "UidRanges.h" |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 38 | |
| Bernie Innocenti | 189eb50 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 39 | #include <android-base/file.h> |
| Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 40 | #include <android-base/stringprintf.h> |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 41 | #include <android-base/strings.h> |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 42 | #include "log/log.h" |
| Bernie Innocenti | 189eb50 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 43 | #include "netid_client.h" |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 44 | #include "netutils/ifc.h" |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 45 | |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 46 | using android::base::StartsWith; |
| Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 47 | using android::base::StringPrintf; |
| Dan Albert | 5407e14 | 2015-03-16 10:05:59 -0700 | [diff] [blame] | 48 | using android::base::WriteStringToFile; |
| Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 49 | using android::net::UidRangeParcel; |
| Dan Albert | 5407e14 | 2015-03-16 10:05:59 -0700 | [diff] [blame] | 50 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 51 | namespace android::net { |
| Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 52 | |
| Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 53 | auto RouteController::iptablesRestoreCommandFunction = execIptablesRestoreCommand; |
| 54 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 55 | // BEGIN CONSTANTS -------------------------------------------------------------------------------- |
| 56 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 57 | const uint32_t ROUTE_TABLE_LOCAL_NETWORK = 97; |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 58 | const uint32_t ROUTE_TABLE_LEGACY_NETWORK = 98; |
| 59 | const uint32_t ROUTE_TABLE_LEGACY_SYSTEM = 99; |
| 60 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 61 | const char* const ROUTE_TABLE_NAME_LOCAL_NETWORK = "local_network"; |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 62 | const char* const ROUTE_TABLE_NAME_LEGACY_NETWORK = "legacy_network"; |
| 63 | const char* const ROUTE_TABLE_NAME_LEGACY_SYSTEM = "legacy_system"; |
| 64 | |
| Sreeram Ramachandran | bb40d51 | 2014-07-11 11:45:14 -0700 | [diff] [blame] | 65 | const char* const ROUTE_TABLE_NAME_LOCAL = "local"; |
| 66 | const char* const ROUTE_TABLE_NAME_MAIN = "main"; |
| 67 | |
| Lorenzo Colitti | b5d19e9 | 2017-09-25 18:39:33 +0900 | [diff] [blame] | 68 | // None of our regular routes specify priority, which causes them to have the default priority. |
| 69 | // For default throw routes, we use a fixed priority of 100000. |
| Lorenzo Colitti | 5e03a89 | 2017-09-08 11:31:59 +0900 | [diff] [blame] | 70 | uint32_t PRIO_THROW = 100000; |
| 71 | |
| Lorenzo Colitti | d78843e | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 72 | const char* const RouteController::LOCAL_MANGLE_INPUT = "routectrl_mangle_INPUT"; |
| 73 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 74 | const uint8_t AF_FAMILIES[] = {AF_INET, AF_INET6}; |
| 75 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 76 | const uid_t UID_ROOT = 0; |
| Lorenzo Colitti | 3093f56 | 2017-09-25 14:17:38 +0900 | [diff] [blame] | 77 | const uint32_t FWMARK_NONE = 0; |
| 78 | const uint32_t MASK_NONE = 0; |
| Lorenzo Colitti | 5ad4e98 | 2015-02-26 17:34:32 +0900 | [diff] [blame] | 79 | const char* const IIF_LOOPBACK = "lo"; |
| Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 80 | const char* const IIF_NONE = nullptr; |
| 81 | const char* const OIF_NONE = nullptr; |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 82 | const bool ACTION_ADD = true; |
| 83 | const bool ACTION_DEL = false; |
| 84 | const bool MODIFY_NON_UID_BASED_RULES = true; |
| 85 | |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 86 | const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables"; |
| Sreeram Ramachandran | c7d804c | 2014-07-09 07:39:30 -0700 | [diff] [blame] | 87 | const mode_t RT_TABLES_MODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; // mode 0644, rw-r--r-- |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 88 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 89 | // Avoids "non-constant-expression cannot be narrowed from type 'unsigned int' to 'unsigned short'" |
| 90 | // warnings when using RTA_LENGTH(x) inside static initializers (even when x is already uint16_t). |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 91 | static constexpr uint16_t U16_RTA_LENGTH(uint16_t x) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 92 | return RTA_LENGTH(x); |
| 93 | } |
| 94 | |
| 95 | // These are practically const, but can't be declared so, because they are used to initialize |
| 96 | // non-const pointers ("void* iov_base") in iovec arrays. |
| Lorenzo Colitti | 2b07867 | 2016-12-16 18:45:03 +0900 | [diff] [blame] | 97 | rtattr FRATTR_PRIORITY = { U16_RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY }; |
| 98 | rtattr FRATTR_TABLE = { U16_RTA_LENGTH(sizeof(uint32_t)), FRA_TABLE }; |
| 99 | rtattr FRATTR_FWMARK = { U16_RTA_LENGTH(sizeof(uint32_t)), FRA_FWMARK }; |
| 100 | rtattr FRATTR_FWMASK = { U16_RTA_LENGTH(sizeof(uint32_t)), FRA_FWMASK }; |
| Lorenzo Colitti | 2b07867 | 2016-12-16 18:45:03 +0900 | [diff] [blame] | 101 | rtattr FRATTR_UID_RANGE = { U16_RTA_LENGTH(sizeof(fib_rule_uid_range)), FRA_UID_RANGE }; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 102 | |
| Lorenzo Colitti | 2b07867 | 2016-12-16 18:45:03 +0900 | [diff] [blame] | 103 | rtattr RTATTR_TABLE = { U16_RTA_LENGTH(sizeof(uint32_t)), RTA_TABLE }; |
| 104 | rtattr RTATTR_OIF = { U16_RTA_LENGTH(sizeof(uint32_t)), RTA_OIF }; |
| Lorenzo Colitti | 5e03a89 | 2017-09-08 11:31:59 +0900 | [diff] [blame] | 105 | rtattr RTATTR_PRIO = { U16_RTA_LENGTH(sizeof(uint32_t)), RTA_PRIORITY }; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 106 | |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 107 | // One or more nested attributes in the RTA_METRICS attribute. |
| 108 | rtattr RTATTRX_MTU = { U16_RTA_LENGTH(sizeof(uint32_t)), RTAX_MTU}; |
| Lorenzo Colitti | 57d5468 | 2020-01-24 09:18:13 +0900 | [diff] [blame] | 109 | constexpr size_t RTATTRX_MTU_SIZE = RTA_SPACE(sizeof(uint32_t)); |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 110 | |
| 111 | // The RTA_METRICS attribute itself. |
| Lorenzo Colitti | 57d5468 | 2020-01-24 09:18:13 +0900 | [diff] [blame] | 112 | constexpr size_t RTATTR_METRICS_SIZE = RTATTRX_MTU_SIZE; |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 113 | rtattr RTATTR_METRICS = { U16_RTA_LENGTH(RTATTR_METRICS_SIZE), RTA_METRICS }; |
| 114 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 115 | uint8_t PADDING_BUFFER[RTA_ALIGNTO] = {0, 0, 0, 0}; |
| 116 | |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 117 | constexpr bool EXPLICIT = true; |
| 118 | constexpr bool IMPLICIT = false; |
| 119 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 120 | // END CONSTANTS ---------------------------------------------------------------------------------- |
| 121 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 122 | static const char* actionName(uint16_t action) { |
| Lorenzo Colitti | 0b073fb | 2017-02-10 07:49:12 +0900 | [diff] [blame] | 123 | static const char *ops[4] = {"adding", "deleting", "getting", "???"}; |
| 124 | return ops[action % 4]; |
| 125 | } |
| 126 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 127 | static const char* familyName(uint8_t family) { |
| Lorenzo Colitti | 0b073fb | 2017-02-10 07:49:12 +0900 | [diff] [blame] | 128 | switch (family) { |
| 129 | case AF_INET: return "IPv4"; |
| 130 | case AF_INET6: return "IPv6"; |
| 131 | default: return "???"; |
| 132 | } |
| 133 | } |
| 134 | |
| Lorenzo Colitti | 3810c97 | 2021-01-06 11:44:02 +0900 | [diff] [blame] | 135 | static void maybeModifyQdiscClsact(const char* interface, bool add); |
| 136 | |
| Lorenzo Colitti | 107075a | 2017-10-30 19:24:46 +0900 | [diff] [blame] | 137 | // Caller must hold sInterfaceToTableLock. |
| 138 | uint32_t RouteController::getRouteTableForInterfaceLocked(const char* interface) { |
| mtk13799 | 9f2913e | 2019-02-25 19:39:36 +0800 | [diff] [blame] | 139 | // If we already know the routing table for this interface name, use it. |
| 140 | // This ensures we can remove rules and routes for an interface that has been removed, |
| 141 | // or has been removed and re-added with a different interface index. |
| 142 | // |
| 143 | // The caller is responsible for ensuring that an interface is never added to a network |
| 144 | // until it has been removed from any network it was previously in. This ensures that |
| 145 | // if the same interface disconnects and then reconnects with a different interface ID |
| 146 | // when the reconnect happens the interface will not be in the map, and the code will |
| 147 | // determine the new routing table from the interface ID, below. |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 148 | auto iter = sInterfaceToTable.find(interface); |
| mtk13799 | 9f2913e | 2019-02-25 19:39:36 +0800 | [diff] [blame] | 149 | if (iter != sInterfaceToTable.end()) { |
| 150 | return iter->second; |
| 151 | } |
| 152 | |
| 153 | uint32_t index = if_nametoindex(interface); |
| 154 | if (index == 0) { |
| Lorenzo Colitti | b6dc40a | 2020-03-24 00:58:50 +0900 | [diff] [blame] | 155 | ALOGE("cannot find interface %s: %s", interface, strerror(errno)); |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 156 | return RT_TABLE_UNSPEC; |
| 157 | } |
| mtk13799 | 9f2913e | 2019-02-25 19:39:36 +0800 | [diff] [blame] | 158 | index += RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX; |
| 159 | sInterfaceToTable[interface] = index; |
| 160 | return index; |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| Rubin Xu | 6c00b61 | 2018-04-27 14:27:59 +0100 | [diff] [blame] | 163 | uint32_t RouteController::getIfIndex(const char* interface) { |
| Bernie Innocenti | abf8a34 | 2018-08-10 15:17:16 +0900 | [diff] [blame] | 164 | std::lock_guard lock(sInterfaceToTableLock); |
| Rubin Xu | 6c00b61 | 2018-04-27 14:27:59 +0100 | [diff] [blame] | 165 | |
| 166 | auto iter = sInterfaceToTable.find(interface); |
| 167 | if (iter == sInterfaceToTable.end()) { |
| 168 | ALOGE("getIfIndex: cannot find interface %s", interface); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| Lorenzo Colitti | b6dc40a | 2020-03-24 00:58:50 +0900 | [diff] [blame] | 172 | // For interfaces that are not in the local network, the routing table is always the interface |
| 173 | // index plus ROUTE_TABLE_OFFSET_FROM_INDEX. But for interfaces in the local network, there's no |
| 174 | // way to know the interface index from this table. Return 0 here so callers of this method do |
| 175 | // not get confused. |
| 176 | // TODO: stop calling this method from any caller that only wants interfaces in client mode. |
| 177 | int ifindex = iter->second; |
| 178 | if (ifindex == ROUTE_TABLE_LOCAL_NETWORK) { |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | return ifindex - ROUTE_TABLE_OFFSET_FROM_INDEX; |
| Rubin Xu | 6c00b61 | 2018-04-27 14:27:59 +0100 | [diff] [blame] | 183 | } |
| 184 | |
| Lorenzo Colitti | 107075a | 2017-10-30 19:24:46 +0900 | [diff] [blame] | 185 | uint32_t RouteController::getRouteTableForInterface(const char* interface) { |
| Bernie Innocenti | abf8a34 | 2018-08-10 15:17:16 +0900 | [diff] [blame] | 186 | std::lock_guard lock(sInterfaceToTableLock); |
| Lorenzo Colitti | 107075a | 2017-10-30 19:24:46 +0900 | [diff] [blame] | 187 | return getRouteTableForInterfaceLocked(interface); |
| 188 | } |
| 189 | |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 190 | void addTableName(uint32_t table, const std::string& name, std::string* contents) { |
| 191 | char tableString[UINT32_STRLEN]; |
| 192 | snprintf(tableString, sizeof(tableString), "%u", table); |
| 193 | *contents += tableString; |
| 194 | *contents += " "; |
| 195 | *contents += name; |
| 196 | *contents += "\n"; |
| 197 | } |
| 198 | |
| 199 | // Doesn't return success/failure as the file is optional; it's okay if we fail to update it. |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 200 | void RouteController::updateTableNamesFile() { |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 201 | std::string contents; |
| Sreeram Ramachandran | bb40d51 | 2014-07-11 11:45:14 -0700 | [diff] [blame] | 202 | |
| 203 | addTableName(RT_TABLE_LOCAL, ROUTE_TABLE_NAME_LOCAL, &contents); |
| 204 | addTableName(RT_TABLE_MAIN, ROUTE_TABLE_NAME_MAIN, &contents); |
| 205 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 206 | addTableName(ROUTE_TABLE_LOCAL_NETWORK, ROUTE_TABLE_NAME_LOCAL_NETWORK, &contents); |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 207 | addTableName(ROUTE_TABLE_LEGACY_NETWORK, ROUTE_TABLE_NAME_LEGACY_NETWORK, &contents); |
| 208 | addTableName(ROUTE_TABLE_LEGACY_SYSTEM, ROUTE_TABLE_NAME_LEGACY_SYSTEM, &contents); |
| Sreeram Ramachandran | bb40d51 | 2014-07-11 11:45:14 -0700 | [diff] [blame] | 209 | |
| Bernie Innocenti | abf8a34 | 2018-08-10 15:17:16 +0900 | [diff] [blame] | 210 | std::lock_guard lock(sInterfaceToTableLock); |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 211 | for (const auto& entry : sInterfaceToTable) { |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 212 | addTableName(entry.second, entry.first, &contents); |
| 213 | } |
| 214 | |
| Dan Albert | 5407e14 | 2015-03-16 10:05:59 -0700 | [diff] [blame] | 215 | if (!WriteStringToFile(contents, RT_TABLES_PATH, RT_TABLES_MODE, AID_SYSTEM, AID_WIFI)) { |
| Elliott Hughes | bd37832 | 2015-02-04 13:25:14 -0800 | [diff] [blame] | 216 | ALOGE("failed to write to %s (%s)", RT_TABLES_PATH, strerror(errno)); |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 217 | return; |
| 218 | } |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 221 | // Returns 0 on success or negative errno on failure. |
| 222 | int padInterfaceName(const char* input, char* name, size_t* length, uint16_t* padding) { |
| 223 | if (!input) { |
| 224 | *length = 0; |
| 225 | *padding = 0; |
| 226 | return 0; |
| 227 | } |
| 228 | *length = strlcpy(name, input, IFNAMSIZ) + 1; |
| 229 | if (*length > IFNAMSIZ) { |
| 230 | ALOGE("interface name too long (%zu > %u)", *length, IFNAMSIZ); |
| 231 | return -ENAMETOOLONG; |
| 232 | } |
| 233 | *padding = RTA_SPACE(*length) - RTA_LENGTH(*length); |
| 234 | return 0; |
| 235 | } |
| 236 | |
| Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 237 | // Adds or removes a routing rule for IPv4 and IPv6. |
| 238 | // |
| Lorenzo Colitti | 6b6f25f | 2015-03-03 17:22:57 +0900 | [diff] [blame] | 239 | // + If |table| is non-zero, the rule points at the specified routing table. Otherwise, the table is |
| Robin Lee | 4ef9464 | 2016-04-01 11:50:49 +0100 | [diff] [blame] | 240 | // unspecified. An unspecified table is not allowed when creating an FR_ACT_TO_TBL rule. |
| Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 241 | // + If |mask| is non-zero, the rule matches the specified fwmark and mask. Otherwise, |fwmark| is |
| 242 | // ignored. |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 243 | // + If |iif| is non-NULL, the rule matches the specified incoming interface. |
| 244 | // + If |oif| is non-NULL, the rule matches the specified outgoing interface. |
| 245 | // + If |uidStart| and |uidEnd| are not INVALID_UID, the rule matches packets from UIDs in that |
| 246 | // range (inclusive). Otherwise, the rule matches packets from all UIDs. |
| Lorenzo Colitti | 96f261e | 2014-06-23 15:09:54 +0900 | [diff] [blame] | 247 | // |
| 248 | // Returns 0 on success or negative errno on failure. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 249 | [[nodiscard]] static int modifyIpRule(uint16_t action, uint32_t priority, uint8_t ruleType, |
| 250 | uint32_t table, uint32_t fwmark, uint32_t mask, |
| 251 | const char* iif, const char* oif, uid_t uidStart, |
| 252 | uid_t uidEnd) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 253 | // Ensure that if you set a bit in the fwmark, it's not being ignored by the mask. |
| 254 | if (fwmark & ~mask) { |
| 255 | ALOGE("mask 0x%x does not select all the bits set in fwmark 0x%x", mask, fwmark); |
| 256 | return -ERANGE; |
| 257 | } |
| 258 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 259 | // Interface names must include exactly one terminating NULL and be properly padded, or older |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 260 | // kernels will refuse to delete rules. |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 261 | char iifName[IFNAMSIZ], oifName[IFNAMSIZ]; |
| 262 | size_t iifLength, oifLength; |
| 263 | uint16_t iifPadding, oifPadding; |
| 264 | if (int ret = padInterfaceName(iif, iifName, &iifLength, &iifPadding)) { |
| 265 | return ret; |
| 266 | } |
| 267 | if (int ret = padInterfaceName(oif, oifName, &oifLength, &oifPadding)) { |
| 268 | return ret; |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 269 | } |
| 270 | |
| Lorenzo Colitti | 5965651 | 2014-06-25 03:20:29 +0900 | [diff] [blame] | 271 | // Either both start and end UID must be specified, or neither. |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 272 | if ((uidStart == INVALID_UID) != (uidEnd == INVALID_UID)) { |
| Sreeram Ramachandran | cf89138 | 2014-07-01 15:49:20 -0700 | [diff] [blame] | 273 | ALOGE("incompatible start and end UIDs (%u vs %u)", uidStart, uidEnd); |
| Lorenzo Colitti | 5965651 | 2014-06-25 03:20:29 +0900 | [diff] [blame] | 274 | return -EUSERS; |
| 275 | } |
| Robin Lee | 4ef9464 | 2016-04-01 11:50:49 +0100 | [diff] [blame] | 276 | |
| Lorenzo Colitti | 7272368 | 2014-06-26 13:51:10 +0900 | [diff] [blame] | 277 | bool isUidRule = (uidStart != INVALID_UID); |
| Lorenzo Colitti | 5965651 | 2014-06-25 03:20:29 +0900 | [diff] [blame] | 278 | |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 279 | // Assemble a rule request and put it in an array of iovec structures. |
| 280 | fib_rule_hdr rule = { |
| Robin Lee | 4ef9464 | 2016-04-01 11:50:49 +0100 | [diff] [blame] | 281 | .action = ruleType, |
| Lorenzo Colitti | 6b6f25f | 2015-03-03 17:22:57 +0900 | [diff] [blame] | 282 | // Note that here we're implicitly setting rule.table to 0. When we want to specify a |
| 283 | // non-zero table, we do this via the FRATTR_TABLE attribute. |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 284 | }; |
| 285 | |
| Lorenzo Colitti | 6b6f25f | 2015-03-03 17:22:57 +0900 | [diff] [blame] | 286 | // Don't ever create a rule that looks up table 0, because table 0 is the local table. |
| 287 | // It's OK to specify a table ID of 0 when deleting a rule, because that doesn't actually select |
| 288 | // table 0, it's a wildcard that matches anything. |
| 289 | if (table == RT_TABLE_UNSPEC && rule.action == FR_ACT_TO_TBL && action != RTM_DELRULE) { |
| 290 | ALOGE("RT_TABLE_UNSPEC only allowed when deleting rules"); |
| 291 | return -ENOTUNIQ; |
| 292 | } |
| 293 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 294 | rtattr fraIifName = { U16_RTA_LENGTH(iifLength), FRA_IIFNAME }; |
| 295 | rtattr fraOifName = { U16_RTA_LENGTH(oifLength), FRA_OIFNAME }; |
| Lorenzo Colitti | 2b07867 | 2016-12-16 18:45:03 +0900 | [diff] [blame] | 296 | struct fib_rule_uid_range uidRange = { uidStart, uidEnd }; |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 297 | |
| 298 | iovec iov[] = { |
| Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 299 | { nullptr, 0 }, |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 300 | { &rule, sizeof(rule) }, |
| 301 | { &FRATTR_PRIORITY, sizeof(FRATTR_PRIORITY) }, |
| 302 | { &priority, sizeof(priority) }, |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 303 | { &FRATTR_TABLE, table != RT_TABLE_UNSPEC ? sizeof(FRATTR_TABLE) : 0 }, |
| 304 | { &table, table != RT_TABLE_UNSPEC ? sizeof(table) : 0 }, |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 305 | { &FRATTR_FWMARK, mask ? sizeof(FRATTR_FWMARK) : 0 }, |
| 306 | { &fwmark, mask ? sizeof(fwmark) : 0 }, |
| 307 | { &FRATTR_FWMASK, mask ? sizeof(FRATTR_FWMASK) : 0 }, |
| 308 | { &mask, mask ? sizeof(mask) : 0 }, |
| Lorenzo Colitti | 2b07867 | 2016-12-16 18:45:03 +0900 | [diff] [blame] | 309 | { &FRATTR_UID_RANGE, isUidRule ? sizeof(FRATTR_UID_RANGE) : 0 }, |
| 310 | { &uidRange, isUidRule ? sizeof(uidRange) : 0 }, |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 311 | { &fraIifName, iif != IIF_NONE ? sizeof(fraIifName) : 0 }, |
| 312 | { iifName, iifLength }, |
| 313 | { PADDING_BUFFER, iifPadding }, |
| 314 | { &fraOifName, oif != OIF_NONE ? sizeof(fraOifName) : 0 }, |
| 315 | { oifName, oifLength }, |
| 316 | { PADDING_BUFFER, oifPadding }, |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 317 | }; |
| 318 | |
| Lorenzo Colitti | 5c43799 | 2017-11-28 01:26:02 +0900 | [diff] [blame] | 319 | uint16_t flags = (action == RTM_NEWRULE) ? NETLINK_RULE_CREATE_FLAGS : NETLINK_REQUEST_FLAGS; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 320 | for (size_t i = 0; i < ARRAY_SIZE(AF_FAMILIES); ++i) { |
| 321 | rule.family = AF_FAMILIES[i]; |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 322 | if (int ret = sendNetlinkRequest(action, flags, iov, ARRAY_SIZE(iov), nullptr)) { |
| Lorenzo Colitti | 220ca73 | 2017-02-14 17:57:55 +0900 | [diff] [blame] | 323 | if (!(action == RTM_DELRULE && ret == -ENOENT && priority == RULE_PRIORITY_TETHERING)) { |
| 324 | // Don't log when deleting a tethering rule that's not there. This matches the |
| 325 | // behaviour of clearTetheringRules, which ignores ENOENT in this case. |
| 326 | ALOGE("Error %s %s rule: %s", actionName(action), familyName(rule.family), |
| 327 | strerror(-ret)); |
| 328 | } |
| Lorenzo Colitti | 96f261e | 2014-06-23 15:09:54 +0900 | [diff] [blame] | 329 | return ret; |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| Lorenzo Colitti | 96f261e | 2014-06-23 15:09:54 +0900 | [diff] [blame] | 333 | return 0; |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 336 | [[nodiscard]] static int modifyIpRule(uint16_t action, uint32_t priority, uint32_t table, |
| 337 | uint32_t fwmark, uint32_t mask, const char* iif, |
| 338 | const char* oif, uid_t uidStart, uid_t uidEnd) { |
| Robin Lee | 4ef9464 | 2016-04-01 11:50:49 +0100 | [diff] [blame] | 339 | return modifyIpRule(action, priority, FR_ACT_TO_TBL, table, fwmark, mask, iif, oif, uidStart, |
| 340 | uidEnd); |
| 341 | } |
| 342 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 343 | [[nodiscard]] static int modifyIpRule(uint16_t action, uint32_t priority, uint32_t table, |
| 344 | uint32_t fwmark, uint32_t mask) { |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 345 | return modifyIpRule(action, priority, table, fwmark, mask, IIF_NONE, OIF_NONE, INVALID_UID, |
| 346 | INVALID_UID); |
| 347 | } |
| 348 | |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 349 | // Adds or deletes an IPv4 or IPv6 route. |
| 350 | // Returns 0 on success or negative errno on failure. |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 351 | int modifyIpRoute(uint16_t action, uint16_t flags, uint32_t table, const char* interface, |
| 352 | const char* destination, const char* nexthop, uint32_t mtu) { |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 353 | // At least the destination must be non-null. |
| 354 | if (!destination) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 355 | ALOGE("null destination"); |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 356 | return -EFAULT; |
| 357 | } |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 358 | |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 359 | // Parse the prefix. |
| 360 | uint8_t rawAddress[sizeof(in6_addr)]; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 361 | uint8_t family; |
| 362 | uint8_t prefixLength; |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 363 | int rawLength = parsePrefix(destination, &family, rawAddress, sizeof(rawAddress), |
| 364 | &prefixLength); |
| 365 | if (rawLength < 0) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 366 | ALOGE("parsePrefix failed for destination %s (%s)", destination, strerror(-rawLength)); |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 367 | return rawLength; |
| 368 | } |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 369 | |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 370 | if (static_cast<size_t>(rawLength) > sizeof(rawAddress)) { |
| Sreeram Ramachandran | 1201e84 | 2014-07-01 15:06:05 -0700 | [diff] [blame] | 371 | ALOGE("impossible! address too long (%d vs %zu)", rawLength, sizeof(rawAddress)); |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 372 | return -ENOBUFS; // Cannot happen; parsePrefix only supports IPv4 and IPv6. |
| 373 | } |
| 374 | |
| Sreeram Ramachandran | de5d5df | 2014-07-26 18:43:25 -0700 | [diff] [blame] | 375 | uint8_t type = RTN_UNICAST; |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 376 | uint32_t ifindex; |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 377 | uint8_t rawNexthop[sizeof(in6_addr)]; |
| Sreeram Ramachandran | de5d5df | 2014-07-26 18:43:25 -0700 | [diff] [blame] | 378 | |
| 379 | if (nexthop && !strcmp(nexthop, "unreachable")) { |
| 380 | type = RTN_UNREACHABLE; |
| 381 | // 'interface' is likely non-NULL, as the caller (modifyRoute()) likely used it to lookup |
| 382 | // the table number. But it's an error to specify an interface ("dev ...") or a nexthop for |
| 383 | // unreachable routes, so nuke them. (IPv6 allows them to be specified; IPv4 doesn't.) |
| 384 | interface = OIF_NONE; |
| Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 385 | nexthop = nullptr; |
| Lorenzo Colitti | 4c95a12 | 2014-09-18 16:01:50 +0900 | [diff] [blame] | 386 | } else if (nexthop && !strcmp(nexthop, "throw")) { |
| 387 | type = RTN_THROW; |
| 388 | interface = OIF_NONE; |
| Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 389 | nexthop = nullptr; |
| Sreeram Ramachandran | de5d5df | 2014-07-26 18:43:25 -0700 | [diff] [blame] | 390 | } else { |
| 391 | // If an interface was specified, find the ifindex. |
| 392 | if (interface != OIF_NONE) { |
| 393 | ifindex = if_nametoindex(interface); |
| 394 | if (!ifindex) { |
| 395 | ALOGE("cannot find interface %s", interface); |
| 396 | return -ENODEV; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | // If a nexthop was specified, parse it as the same family as the prefix. |
| 401 | if (nexthop && inet_pton(family, nexthop, rawNexthop) <= 0) { |
| 402 | ALOGE("inet_pton failed for nexthop %s", nexthop); |
| 403 | return -EINVAL; |
| 404 | } |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 405 | } |
| 406 | |
| Lorenzo Colitti | 5e03a89 | 2017-09-08 11:31:59 +0900 | [diff] [blame] | 407 | bool isDefaultThrowRoute = (type == RTN_THROW && prefixLength == 0); |
| 408 | |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 409 | // Assemble a rtmsg and put it in an array of iovec structures. |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 410 | rtmsg route = { |
| Nick Desaulniers | 6b35750 | 2019-10-11 09:26:44 -0700 | [diff] [blame] | 411 | .rtm_family = family, |
| 412 | .rtm_dst_len = prefixLength, |
| 413 | .rtm_protocol = RTPROT_STATIC, |
| 414 | .rtm_scope = static_cast<uint8_t>(nexthop ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK), |
| 415 | .rtm_type = type, |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 416 | }; |
| Lorenzo Colitti | 4753afd | 2014-06-20 23:03:29 +0900 | [diff] [blame] | 417 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 418 | rtattr rtaDst = { U16_RTA_LENGTH(rawLength), RTA_DST }; |
| 419 | rtattr rtaGateway = { U16_RTA_LENGTH(rawLength), RTA_GATEWAY }; |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 420 | |
| 421 | iovec iov[] = { |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 422 | { nullptr, 0 }, |
| 423 | { &route, sizeof(route) }, |
| 424 | { &RTATTR_TABLE, sizeof(RTATTR_TABLE) }, |
| 425 | { &table, sizeof(table) }, |
| 426 | { &rtaDst, sizeof(rtaDst) }, |
| 427 | { rawAddress, static_cast<size_t>(rawLength) }, |
| 428 | { &RTATTR_OIF, interface != OIF_NONE ? sizeof(RTATTR_OIF) : 0 }, |
| 429 | { &ifindex, interface != OIF_NONE ? sizeof(ifindex) : 0 }, |
| 430 | { &rtaGateway, nexthop ? sizeof(rtaGateway) : 0 }, |
| 431 | { rawNexthop, nexthop ? static_cast<size_t>(rawLength) : 0 }, |
| 432 | { &RTATTR_METRICS, mtu != 0 ? sizeof(RTATTR_METRICS) : 0 }, |
| 433 | { &RTATTRX_MTU, mtu != 0 ? sizeof(RTATTRX_MTU) : 0 }, |
| 434 | { &mtu, mtu != 0 ? sizeof(mtu) : 0 }, |
| 435 | { &RTATTR_PRIO, isDefaultThrowRoute ? sizeof(RTATTR_PRIO) : 0 }, |
| 436 | { &PRIO_THROW, isDefaultThrowRoute ? sizeof(PRIO_THROW) : 0 }, |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 437 | }; |
| Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 438 | |
| Jimmy Chen | ce9e578 | 2019-03-08 16:12:55 +0800 | [diff] [blame] | 439 | // Allow creating multiple link-local routes in the same table, so we can make IPv6 |
| 440 | // work on all interfaces in the local_network table. |
| 441 | if (family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(reinterpret_cast<in6_addr*>(rawAddress))) { |
| 442 | flags &= ~NLM_F_EXCL; |
| 443 | } |
| 444 | |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 445 | int ret = sendNetlinkRequest(action, flags, iov, ARRAY_SIZE(iov), nullptr); |
| Lorenzo Colitti | 0b073fb | 2017-02-10 07:49:12 +0900 | [diff] [blame] | 446 | if (ret) { |
| 447 | ALOGE("Error %s route %s -> %s %s to table %u: %s", |
| 448 | actionName(action), destination, nexthop, interface, table, strerror(-ret)); |
| 449 | } |
| 450 | return ret; |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 453 | // An iptables rule to mark incoming packets on a network with the netId of the network. |
| 454 | // |
| 455 | // This is so that the kernel can: |
| 456 | // + Use the right fwmark for (and thus correctly route) replies (e.g.: TCP RST, ICMP errors, ping |
| 457 | // replies, SYN-ACKs, etc). |
| 458 | // + Mark sockets that accept connections from this interface so that the connection stays on the |
| 459 | // same interface. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 460 | int modifyIncomingPacketMark(unsigned netId, const char* interface, Permission permission, |
| 461 | bool add) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 462 | Fwmark fwmark; |
| 463 | |
| 464 | fwmark.netId = netId; |
| 465 | fwmark.explicitlySelected = true; |
| 466 | fwmark.protectedFromVpn = true; |
| 467 | fwmark.permission = permission; |
| 468 | |
| Benedict Wong | b9baf26 | 2017-12-03 15:43:08 -0800 | [diff] [blame] | 469 | const uint32_t mask = ~Fwmark::getUidBillingMask(); |
| 470 | |
| 471 | std::string cmd = StringPrintf( |
| 472 | "%s %s -i %s -j MARK --set-mark 0x%x/0x%x", add ? "-A" : "-D", |
| 473 | RouteController::LOCAL_MANGLE_INPUT, interface, fwmark.intValue, mask); |
| Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 474 | if (RouteController::iptablesRestoreCommandFunction(V4V6, "mangle", cmd, nullptr) != 0) { |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 475 | ALOGE("failed to change iptables rule that sets incoming packet mark"); |
| 476 | return -EREMOTEIO; |
| 477 | } |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 478 | |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
| Sreeram Ramachandran | 111bec2 | 2014-07-22 18:51:06 -0700 | [diff] [blame] | 482 | // A rule to route responses to the local network forwarded via the VPN. |
| 483 | // |
| 484 | // When a VPN is in effect, packets from the local network to upstream networks are forwarded into |
| 485 | // the VPN's tunnel interface. When the VPN forwards the responses, they emerge out of the tunnel. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 486 | [[nodiscard]] static int modifyVpnOutputToLocalRule(const char* vpnInterface, bool add) { |
| Sreeram Ramachandran | 111bec2 | 2014-07-22 18:51:06 -0700 | [diff] [blame] | 487 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_VPN_OUTPUT_TO_LOCAL, |
| 488 | ROUTE_TABLE_LOCAL_NETWORK, MARK_UNSET, MARK_UNSET, vpnInterface, OIF_NONE, |
| 489 | INVALID_UID, INVALID_UID); |
| 490 | } |
| 491 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 492 | // A rule to route all traffic from a given set of UIDs to go over the VPN. |
| 493 | // |
| 494 | // Notice that this rule doesn't use the netId. I.e., no matter what netId the user's socket may |
| 495 | // have, if they are subject to this VPN, their traffic has to go through it. Allows the traffic to |
| 496 | // bypass the VPN if the protectedFromVpn bit is set. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 497 | [[nodiscard]] static int modifyVpnUidRangeRule(uint32_t table, uid_t uidStart, uid_t uidEnd, |
| 498 | bool secure, bool add) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 499 | Fwmark fwmark; |
| 500 | Fwmark mask; |
| 501 | |
| 502 | fwmark.protectedFromVpn = false; |
| 503 | mask.protectedFromVpn = true; |
| 504 | |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 505 | uint32_t priority; |
| 506 | |
| 507 | if (secure) { |
| 508 | priority = RULE_PRIORITY_SECURE_VPN; |
| 509 | } else { |
| 510 | priority = RULE_PRIORITY_BYPASSABLE_VPN; |
| 511 | |
| 512 | fwmark.explicitlySelected = false; |
| 513 | mask.explicitlySelected = true; |
| 514 | } |
| 515 | |
| 516 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, priority, table, fwmark.intValue, |
| Lorenzo Colitti | 5ad4e98 | 2015-02-26 17:34:32 +0900 | [diff] [blame] | 517 | mask.intValue, IIF_LOOPBACK, OIF_NONE, uidStart, uidEnd); |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | // A rule to allow system apps to send traffic over this VPN even if they are not part of the target |
| 521 | // set of UIDs. |
| 522 | // |
| 523 | // This is needed for DnsProxyListener to correctly resolve a request for a user who is in the |
| 524 | // target set, but where the DnsProxyListener itself is not. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 525 | [[nodiscard]] static int modifyVpnSystemPermissionRule(unsigned netId, uint32_t table, bool secure, |
| 526 | bool add) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 527 | Fwmark fwmark; |
| 528 | Fwmark mask; |
| 529 | |
| 530 | fwmark.netId = netId; |
| 531 | mask.netId = FWMARK_NET_ID_MASK; |
| 532 | |
| 533 | fwmark.permission = PERMISSION_SYSTEM; |
| 534 | mask.permission = PERMISSION_SYSTEM; |
| 535 | |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 536 | uint32_t priority = secure ? RULE_PRIORITY_SECURE_VPN : RULE_PRIORITY_BYPASSABLE_VPN; |
| 537 | |
| 538 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, priority, table, fwmark.intValue, |
| 539 | mask.intValue); |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 542 | // A rule to route traffic based on an explicitly chosen network. |
| 543 | // |
| 544 | // Supports apps that use the multinetwork APIs to restrict their traffic to a network. |
| 545 | // |
| 546 | // Even though we check permissions at the time we set a netId into the fwmark of a socket, we need |
| 547 | // to check it again in the rules here, because a network's permissions may have been updated via |
| 548 | // modifyNetworkPermission(). |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 549 | [[nodiscard]] static int modifyExplicitNetworkRule(unsigned netId, uint32_t table, |
| 550 | Permission permission, uid_t uidStart, |
| 551 | uid_t uidEnd, bool add) { |
| Sreeram Ramachandran | eb27b7e | 2014-07-01 14:30:30 -0700 | [diff] [blame] | 552 | Fwmark fwmark; |
| 553 | Fwmark mask; |
| 554 | |
| 555 | fwmark.netId = netId; |
| 556 | mask.netId = FWMARK_NET_ID_MASK; |
| 557 | |
| Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 558 | fwmark.explicitlySelected = true; |
| 559 | mask.explicitlySelected = true; |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 560 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 561 | fwmark.permission = permission; |
| 562 | mask.permission = permission; |
| Sreeram Ramachandran | eb27b7e | 2014-07-01 14:30:30 -0700 | [diff] [blame] | 563 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 564 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_EXPLICIT_NETWORK, table, |
| Lorenzo Colitti | 758627c | 2018-03-15 01:49:20 +0900 | [diff] [blame] | 565 | fwmark.intValue, mask.intValue, IIF_LOOPBACK, OIF_NONE, uidStart, uidEnd); |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 568 | // A rule to route traffic based on a chosen outgoing interface. |
| 569 | // |
| 570 | // Supports apps that use SO_BINDTODEVICE or IP_PKTINFO options and the kernel that already knows |
| 571 | // the outgoing interface (typically for link-local communications). |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 572 | [[nodiscard]] static int modifyOutputInterfaceRules(const char* interface, uint32_t table, |
| 573 | Permission permission, uid_t uidStart, |
| 574 | uid_t uidEnd, bool add) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 575 | Fwmark fwmark; |
| 576 | Fwmark mask; |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 577 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 578 | fwmark.permission = permission; |
| 579 | mask.permission = permission; |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 580 | |
| Lorenzo Colitti | 57947f0 | 2015-02-27 16:45:55 +0900 | [diff] [blame] | 581 | // If this rule does not specify a UID range, then also add a corresponding high-priority rule |
| Lorenzo Colitti | 758627c | 2018-03-15 01:49:20 +0900 | [diff] [blame] | 582 | // for root. This covers kernel-originated packets, TEEd packets and any local daemons that open |
| 583 | // sockets as root. |
| Lorenzo Colitti | 57947f0 | 2015-02-27 16:45:55 +0900 | [diff] [blame] | 584 | if (uidStart == INVALID_UID && uidEnd == INVALID_UID) { |
| 585 | if (int ret = modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_VPN_OVERRIDE_OIF, |
| Lorenzo Colitti | 758627c | 2018-03-15 01:49:20 +0900 | [diff] [blame] | 586 | table, FWMARK_NONE, MASK_NONE, IIF_LOOPBACK, interface, |
| Lorenzo Colitti | 57947f0 | 2015-02-27 16:45:55 +0900 | [diff] [blame] | 587 | UID_ROOT, UID_ROOT)) { |
| 588 | return ret; |
| 589 | } |
| 590 | } |
| 591 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 592 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_OUTPUT_INTERFACE, table, |
| Lorenzo Colitti | 758627c | 2018-03-15 01:49:20 +0900 | [diff] [blame] | 593 | fwmark.intValue, mask.intValue, IIF_LOOPBACK, interface, uidStart, uidEnd); |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | // A rule to route traffic based on the chosen network. |
| 597 | // |
| 598 | // This is for sockets that have not explicitly requested a particular network, but have been |
| 599 | // bound to one when they called connect(). This ensures that sockets connected on a particular |
| 600 | // network stay on that network even if the default network changes. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 601 | [[nodiscard]] static int modifyImplicitNetworkRule(unsigned netId, uint32_t table, bool add) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 602 | Fwmark fwmark; |
| 603 | Fwmark mask; |
| 604 | |
| 605 | fwmark.netId = netId; |
| 606 | mask.netId = FWMARK_NET_ID_MASK; |
| 607 | |
| 608 | fwmark.explicitlySelected = false; |
| 609 | mask.explicitlySelected = true; |
| 610 | |
| Lorenzo Colitti | be0c7c3 | 2017-09-06 16:07:02 +0900 | [diff] [blame] | 611 | fwmark.permission = PERMISSION_NONE; |
| 612 | mask.permission = PERMISSION_NONE; |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 613 | |
| 614 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_IMPLICIT_NETWORK, table, |
| Lorenzo Colitti | 758627c | 2018-03-15 01:49:20 +0900 | [diff] [blame] | 615 | fwmark.intValue, mask.intValue, IIF_LOOPBACK, OIF_NONE, INVALID_UID, |
| 616 | INVALID_UID); |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| Sreeram Ramachandran | 48e19b0 | 2014-07-22 22:23:20 -0700 | [diff] [blame] | 619 | // A rule to enable split tunnel VPNs. |
| 620 | // |
| 621 | // If a packet with a VPN's netId doesn't find a route in the VPN's routing table, it's allowed to |
| Luke Huang | d286198 | 2019-05-17 19:47:28 +0800 | [diff] [blame] | 622 | // go over the default network, provided it has the permissions required by the default network. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 623 | int RouteController::modifyVpnFallthroughRule(uint16_t action, unsigned vpnNetId, |
| 624 | const char* physicalInterface, |
| 625 | Permission permission) { |
| Sreeram Ramachandran | 48e19b0 | 2014-07-22 22:23:20 -0700 | [diff] [blame] | 626 | uint32_t table = getRouteTableForInterface(physicalInterface); |
| 627 | if (table == RT_TABLE_UNSPEC) { |
| 628 | return -ESRCH; |
| 629 | } |
| 630 | |
| 631 | Fwmark fwmark; |
| 632 | Fwmark mask; |
| 633 | |
| 634 | fwmark.netId = vpnNetId; |
| 635 | mask.netId = FWMARK_NET_ID_MASK; |
| 636 | |
| Sreeram Ramachandran | 48e19b0 | 2014-07-22 22:23:20 -0700 | [diff] [blame] | 637 | fwmark.permission = permission; |
| 638 | mask.permission = permission; |
| 639 | |
| 640 | return modifyIpRule(action, RULE_PRIORITY_VPN_FALLTHROUGH, table, fwmark.intValue, |
| 641 | mask.intValue); |
| 642 | } |
| 643 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 644 | // Add rules to allow legacy routes added through the requestRouteToHost() API. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 645 | [[nodiscard]] static int addLegacyRouteRules() { |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 646 | Fwmark fwmark; |
| 647 | Fwmark mask; |
| 648 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 649 | fwmark.explicitlySelected = false; |
| 650 | mask.explicitlySelected = true; |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 651 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 652 | // Rules to allow legacy routes to override the default network. |
| 653 | if (int ret = modifyIpRule(RTM_NEWRULE, RULE_PRIORITY_LEGACY_SYSTEM, ROUTE_TABLE_LEGACY_SYSTEM, |
| 654 | fwmark.intValue, mask.intValue)) { |
| 655 | return ret; |
| 656 | } |
| 657 | if (int ret = modifyIpRule(RTM_NEWRULE, RULE_PRIORITY_LEGACY_NETWORK, |
| 658 | ROUTE_TABLE_LEGACY_NETWORK, fwmark.intValue, mask.intValue)) { |
| 659 | return ret; |
| 660 | } |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 661 | |
| 662 | fwmark.permission = PERMISSION_SYSTEM; |
| 663 | mask.permission = PERMISSION_SYSTEM; |
| 664 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 665 | // A rule to allow legacy routes from system apps to override VPNs. |
| 666 | return modifyIpRule(RTM_NEWRULE, RULE_PRIORITY_VPN_OVERRIDE_SYSTEM, ROUTE_TABLE_LEGACY_SYSTEM, |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 667 | fwmark.intValue, mask.intValue); |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 670 | // Add rules to lookup the local network when specified explicitly or otherwise. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 671 | [[nodiscard]] static int addLocalNetworkRules(unsigned localNetId) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 672 | if (int ret = modifyExplicitNetworkRule(localNetId, ROUTE_TABLE_LOCAL_NETWORK, PERMISSION_NONE, |
| 673 | INVALID_UID, INVALID_UID, ACTION_ADD)) { |
| 674 | return ret; |
| Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 677 | Fwmark fwmark; |
| 678 | Fwmark mask; |
| 679 | |
| 680 | fwmark.explicitlySelected = false; |
| 681 | mask.explicitlySelected = true; |
| 682 | |
| 683 | return modifyIpRule(RTM_NEWRULE, RULE_PRIORITY_LOCAL_NETWORK, ROUTE_TABLE_LOCAL_NETWORK, |
| 684 | fwmark.intValue, mask.intValue); |
| 685 | } |
| 686 | |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 687 | /* static */ |
| 688 | int RouteController::configureDummyNetwork() { |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 689 | const char *interface = DummyNetwork::INTERFACE_NAME; |
| 690 | uint32_t table = getRouteTableForInterface(interface); |
| 691 | if (table == RT_TABLE_UNSPEC) { |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 692 | // getRouteTableForInterface has already logged an error. |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 693 | return -ESRCH; |
| 694 | } |
| 695 | |
| 696 | ifc_init(); |
| 697 | int ret = ifc_up(interface); |
| 698 | ifc_close(); |
| 699 | if (ret) { |
| 700 | ALOGE("Can't bring up %s: %s", interface, strerror(errno)); |
| 701 | return -errno; |
| 702 | } |
| 703 | |
| Lorenzo Colitti | 57947f0 | 2015-02-27 16:45:55 +0900 | [diff] [blame] | 704 | if ((ret = modifyOutputInterfaceRules(interface, table, PERMISSION_NONE, |
| 705 | INVALID_UID, INVALID_UID, ACTION_ADD))) { |
| 706 | ALOGE("Can't create oif rules for %s: %s", interface, strerror(-ret)); |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 707 | return ret; |
| 708 | } |
| 709 | |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 710 | if ((ret = modifyIpRoute(RTM_NEWROUTE, NETLINK_ROUTE_CREATE_FLAGS, table, interface, |
| 711 | "0.0.0.0/0", nullptr, 0 /* mtu */))) { |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 712 | return ret; |
| 713 | } |
| 714 | |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 715 | if ((ret = modifyIpRoute(RTM_NEWROUTE, NETLINK_ROUTE_CREATE_FLAGS, table, interface, "::/0", |
| 716 | nullptr, 0 /* mtu */))) { |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 717 | return ret; |
| 718 | } |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
| Lorenzo Colitti | db74dba | 2014-07-29 18:26:21 +0900 | [diff] [blame] | 723 | // Add an explicit unreachable rule close to the end of the prioriy list to make it clear that |
| 724 | // relying on the kernel-default "from all lookup main" rule at priority 32766 is not intended |
| 725 | // behaviour. We do flush the kernel-default rules at startup, but having an explicit unreachable |
| 726 | // rule will hopefully make things even clearer. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 727 | [[nodiscard]] static int addUnreachableRule() { |
| Robin Lee | c125fe4 | 2016-05-02 08:53:34 +0100 | [diff] [blame] | 728 | return modifyIpRule(RTM_NEWRULE, RULE_PRIORITY_UNREACHABLE, FR_ACT_UNREACHABLE, RT_TABLE_UNSPEC, |
| 729 | MARK_UNSET, MARK_UNSET, IIF_NONE, OIF_NONE, INVALID_UID, INVALID_UID); |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 732 | [[nodiscard]] static int modifyLocalNetwork(unsigned netId, const char* interface, bool add) { |
| Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 733 | if (int ret = modifyIncomingPacketMark(netId, interface, PERMISSION_NONE, add)) { |
| 734 | return ret; |
| 735 | } |
| Lorenzo Colitti | 3810c97 | 2021-01-06 11:44:02 +0900 | [diff] [blame] | 736 | maybeModifyQdiscClsact(interface, add); |
| Lorenzo Colitti | 57947f0 | 2015-02-27 16:45:55 +0900 | [diff] [blame] | 737 | return modifyOutputInterfaceRules(interface, ROUTE_TABLE_LOCAL_NETWORK, PERMISSION_NONE, |
| 738 | INVALID_UID, INVALID_UID, add); |
| Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 741 | [[nodiscard]] static int modifyUidNetworkRule(unsigned netId, uint32_t table, uid_t uidStart, |
| 742 | uid_t uidEnd, bool add, bool explicitSelect) { |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 743 | if ((uidStart == INVALID_UID) || (uidEnd == INVALID_UID)) { |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 744 | ALOGE("modifyUidNetworkRule, invalid UIDs (%u, %u)", uidStart, uidEnd); |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 745 | return -EUSERS; |
| 746 | } |
| 747 | |
| 748 | Fwmark fwmark; |
| 749 | Fwmark mask; |
| 750 | |
| 751 | fwmark.netId = netId; |
| 752 | mask.netId = FWMARK_NET_ID_MASK; |
| 753 | |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 754 | fwmark.explicitlySelected = explicitSelect; |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 755 | mask.explicitlySelected = true; |
| 756 | |
| 757 | // Access to this network is controlled by UID rules, not permission bits. |
| 758 | fwmark.permission = PERMISSION_NONE; |
| 759 | mask.permission = PERMISSION_NONE; |
| 760 | |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 761 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, |
| 762 | explicitSelect ? RULE_PRIORITY_UID_EXPLICIT_NETWORK |
| 763 | : RULE_PRIORITY_UID_IMPLICIT_NETWORK, |
| 764 | table, fwmark.intValue, mask.intValue, IIF_LOOPBACK, OIF_NONE, uidStart, |
| 765 | uidEnd); |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | [[nodiscard]] static int modifyUidDefaultNetworkRule(uint32_t table, uid_t uidStart, uid_t uidEnd, |
| 769 | bool add) { |
| 770 | if ((uidStart == INVALID_UID) || (uidEnd == INVALID_UID)) { |
| 771 | ALOGE("modifyUidDefaultNetworkRule, invalid UIDs (%u, %u)", uidStart, uidEnd); |
| 772 | return -EUSERS; |
| 773 | } |
| 774 | |
| 775 | Fwmark fwmark; |
| 776 | Fwmark mask; |
| 777 | |
| 778 | fwmark.netId = NETID_UNSET; |
| 779 | mask.netId = FWMARK_NET_ID_MASK; |
| 780 | |
| 781 | // Access to this network is controlled by UID rules, not permission bits. |
| 782 | fwmark.permission = PERMISSION_NONE; |
| 783 | mask.permission = PERMISSION_NONE; |
| 784 | |
| 785 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_UID_DEFAULT_NETWORK, table, |
| 786 | fwmark.intValue, mask.intValue, IIF_LOOPBACK, OIF_NONE, uidStart, uidEnd); |
| 787 | } |
| 788 | |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 789 | /* static */ |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 790 | int RouteController::modifyPhysicalNetwork(unsigned netId, const char* interface, |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 791 | const UidRanges& uidRanges, Permission permission, |
| 792 | bool add, bool modifyNonUidBasedRules) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 793 | uint32_t table = getRouteTableForInterface(interface); |
| 794 | if (table == RT_TABLE_UNSPEC) { |
| 795 | return -ESRCH; |
| 796 | } |
| 797 | |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 798 | for (const UidRangeParcel& range : uidRanges.getRanges()) { |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 799 | if (int ret = modifyUidNetworkRule(netId, table, range.start, range.stop, add, EXPLICIT)) { |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 800 | return ret; |
| 801 | } |
| Ken Chen | a2206ec | 2021-03-24 17:15:44 +0800 | [diff] [blame] | 802 | if (int ret = modifyUidNetworkRule(netId, table, range.start, range.stop, add, IMPLICIT)) { |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 803 | return ret; |
| 804 | } |
| 805 | if (int ret = modifyUidDefaultNetworkRule(table, range.start, range.stop, add)) { |
| 806 | return ret; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | if (!modifyNonUidBasedRules) { |
| 811 | // we are done. |
| 812 | return 0; |
| 813 | } |
| 814 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 815 | if (int ret = modifyIncomingPacketMark(netId, interface, permission, add)) { |
| 816 | return ret; |
| 817 | } |
| 818 | if (int ret = modifyExplicitNetworkRule(netId, table, permission, INVALID_UID, INVALID_UID, |
| 819 | add)) { |
| 820 | return ret; |
| 821 | } |
| Lorenzo Colitti | 57947f0 | 2015-02-27 16:45:55 +0900 | [diff] [blame] | 822 | if (int ret = modifyOutputInterfaceRules(interface, table, permission, INVALID_UID, INVALID_UID, |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 823 | add)) { |
| 824 | return ret; |
| 825 | } |
| Lorenzo Colitti | be0c7c3 | 2017-09-06 16:07:02 +0900 | [diff] [blame] | 826 | |
| 827 | // Only set implicit rules for networks that don't require permissions. |
| 828 | // |
| 829 | // This is so that if the default network ceases to be the default network and then switches |
| 830 | // from requiring no permissions to requiring permissions, we ensure that apps only use the |
| 831 | // network if they explicitly select it. This is consistent with destroySocketsLackingPermission |
| 832 | // - it closes all sockets on the network except sockets that are explicitly selected. |
| 833 | // |
| 834 | // The lack of this rule only affects the special case above, because: |
| 835 | // - The only cases where we implicitly bind a socket to a network are the default network and |
| 836 | // the bypassable VPN that applies to the app, if any. |
| 837 | // - This rule doesn't affect VPNs because they don't support permissions at all. |
| 838 | // - The default network doesn't require permissions. While we support doing this, the framework |
| 839 | // never does it (partly because we'd end up in the situation where we tell apps that there is |
| 840 | // a default network, but they can't use it). |
| 841 | // - If the network is still the default network, the presence or absence of this rule does not |
| 842 | // matter. |
| 843 | // |
| 844 | // Therefore, for the lack of this rule to affect a socket, the socket has to have been |
| 845 | // implicitly bound to a network because at the time of connect() it was the default, and that |
| 846 | // network must no longer be the default, and must now require permissions. |
| 847 | if (permission == PERMISSION_NONE) { |
| 848 | return modifyImplicitNetworkRule(netId, table, add); |
| 849 | } |
| 850 | return 0; |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame^] | 853 | [[nodiscard]] static int modifyUidUnreachableRule(unsigned netId, uid_t uidStart, uid_t uidEnd, |
| 854 | bool add, bool explicitSelect) { |
| 855 | if ((uidStart == INVALID_UID) || (uidEnd == INVALID_UID)) { |
| 856 | ALOGE("modifyUidUnreachableRule, invalid UIDs (%u, %u)", uidStart, uidEnd); |
| 857 | return -EUSERS; |
| 858 | } |
| 859 | |
| 860 | Fwmark fwmark; |
| 861 | Fwmark mask; |
| 862 | |
| 863 | fwmark.netId = netId; |
| 864 | mask.netId = FWMARK_NET_ID_MASK; |
| 865 | |
| 866 | fwmark.explicitlySelected = explicitSelect; |
| 867 | mask.explicitlySelected = true; |
| 868 | |
| 869 | // Access to this network is controlled by UID rules, not permission bits. |
| 870 | fwmark.permission = PERMISSION_NONE; |
| 871 | mask.permission = PERMISSION_NONE; |
| 872 | |
| 873 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, |
| 874 | explicitSelect ? RULE_PRIORITY_UID_EXPLICIT_NETWORK |
| 875 | : RULE_PRIORITY_UID_IMPLICIT_NETWORK, |
| 876 | FR_ACT_UNREACHABLE, RT_TABLE_UNSPEC, fwmark.intValue, mask.intValue, |
| 877 | IIF_LOOPBACK, OIF_NONE, uidStart, uidEnd); |
| 878 | } |
| 879 | |
| 880 | [[nodiscard]] static int modifyUidDefaultUnreachableRule(uid_t uidStart, uid_t uidEnd, bool add) { |
| 881 | if ((uidStart == INVALID_UID) || (uidEnd == INVALID_UID)) { |
| 882 | ALOGE("modifyUidDefaultNetworkRule, invalid UIDs (%u, %u)", uidStart, uidEnd); |
| 883 | return -EUSERS; |
| 884 | } |
| 885 | |
| 886 | Fwmark fwmark; |
| 887 | Fwmark mask; |
| 888 | |
| 889 | fwmark.netId = NETID_UNSET; |
| 890 | mask.netId = FWMARK_NET_ID_MASK; |
| 891 | |
| 892 | // Access to this network is controlled by UID rules, not permission bits. |
| 893 | fwmark.permission = PERMISSION_NONE; |
| 894 | mask.permission = PERMISSION_NONE; |
| 895 | |
| 896 | return modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_UID_DEFAULT_UNREACHABLE, |
| 897 | FR_ACT_UNREACHABLE, RT_TABLE_UNSPEC, fwmark.intValue, mask.intValue, |
| 898 | IIF_LOOPBACK, OIF_NONE, uidStart, uidEnd); |
| 899 | } |
| 900 | |
| 901 | int RouteController::modifyUnreachableNetwork(unsigned netId, const UidRanges& uidRanges, |
| 902 | bool add) { |
| 903 | for (const UidRangeParcel& range : uidRanges.getRanges()) { |
| 904 | if (int ret = modifyUidUnreachableRule(netId, range.start, range.stop, add, EXPLICIT)) { |
| 905 | return ret; |
| 906 | } |
| 907 | if (int ret = modifyUidUnreachableRule(netId, range.start, range.stop, add, IMPLICIT)) { |
| 908 | return ret; |
| 909 | } |
| 910 | if (int ret = modifyUidDefaultUnreachableRule(range.start, range.stop, add)) { |
| 911 | return ret; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 918 | [[nodiscard]] static int modifyRejectNonSecureNetworkRule(const UidRanges& uidRanges, bool add) { |
| Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 919 | Fwmark fwmark; |
| 920 | Fwmark mask; |
| 921 | fwmark.protectedFromVpn = false; |
| 922 | mask.protectedFromVpn = true; |
| 923 | |
| Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 924 | for (const UidRangeParcel& range : uidRanges.getRanges()) { |
| 925 | if (int ret = modifyIpRule(add ? RTM_NEWRULE : RTM_DELRULE, RULE_PRIORITY_PROHIBIT_NON_VPN, |
| 926 | FR_ACT_PROHIBIT, RT_TABLE_UNSPEC, fwmark.intValue, mask.intValue, |
| 927 | IIF_LOOPBACK, OIF_NONE, range.start, range.stop)) { |
| Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 928 | return ret; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 935 | int RouteController::modifyVirtualNetwork(unsigned netId, const char* interface, |
| 936 | const UidRanges& uidRanges, bool secure, bool add, |
| 937 | bool modifyNonUidBasedRules) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 938 | uint32_t table = getRouteTableForInterface(interface); |
| 939 | if (table == RT_TABLE_UNSPEC) { |
| 940 | return -ESRCH; |
| 941 | } |
| 942 | |
| Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 943 | for (const UidRangeParcel& range : uidRanges.getRanges()) { |
| 944 | if (int ret = modifyVpnUidRangeRule(table, range.start, range.stop, secure, add)) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 945 | return ret; |
| 946 | } |
| Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 947 | if (int ret = modifyExplicitNetworkRule(netId, table, PERMISSION_NONE, range.start, |
| 948 | range.stop, add)) { |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 949 | return ret; |
| 950 | } |
| Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 951 | if (int ret = modifyOutputInterfaceRules(interface, table, PERMISSION_NONE, range.start, |
| 952 | range.stop, add)) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 953 | return ret; |
| 954 | } |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 957 | if (modifyNonUidBasedRules) { |
| 958 | if (int ret = modifyIncomingPacketMark(netId, interface, PERMISSION_NONE, add)) { |
| Sreeram Ramachandran | eb27b7e | 2014-07-01 14:30:30 -0700 | [diff] [blame] | 959 | return ret; |
| 960 | } |
| Sreeram Ramachandran | 111bec2 | 2014-07-22 18:51:06 -0700 | [diff] [blame] | 961 | if (int ret = modifyVpnOutputToLocalRule(interface, add)) { |
| 962 | return ret; |
| 963 | } |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 964 | if (int ret = modifyVpnSystemPermissionRule(netId, table, secure, add)) { |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 965 | return ret; |
| 966 | } |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 967 | return modifyExplicitNetworkRule(netId, table, PERMISSION_NONE, UID_ROOT, UID_ROOT, add); |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | return 0; |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 973 | int RouteController::modifyDefaultNetwork(uint16_t action, const char* interface, |
| 974 | Permission permission) { |
| Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 975 | uint32_t table = getRouteTableForInterface(interface); |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 976 | if (table == RT_TABLE_UNSPEC) { |
| Lorenzo Colitti | 96f261e | 2014-06-23 15:09:54 +0900 | [diff] [blame] | 977 | return -ESRCH; |
| Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 980 | Fwmark fwmark; |
| Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 981 | Fwmark mask; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 982 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 983 | fwmark.netId = NETID_UNSET; |
| Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 984 | mask.netId = FWMARK_NET_ID_MASK; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 985 | |
| 986 | fwmark.permission = permission; |
| Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 987 | mask.permission = permission; |
| 988 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 989 | return modifyIpRule(action, RULE_PRIORITY_DEFAULT_NETWORK, table, fwmark.intValue, |
| Lorenzo Colitti | 758627c | 2018-03-15 01:49:20 +0900 | [diff] [blame] | 990 | mask.intValue, IIF_LOOPBACK, OIF_NONE, INVALID_UID, INVALID_UID); |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 993 | int RouteController::modifyTetheredNetwork(uint16_t action, const char* inputInterface, |
| 994 | const char* outputInterface) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 995 | uint32_t table = getRouteTableForInterface(outputInterface); |
| 996 | if (table == RT_TABLE_UNSPEC) { |
| 997 | return -ESRCH; |
| 998 | } |
| 999 | |
| 1000 | return modifyIpRule(action, RULE_PRIORITY_TETHERING, table, MARK_UNSET, MARK_UNSET, |
| 1001 | inputInterface, OIF_NONE, INVALID_UID, INVALID_UID); |
| 1002 | } |
| 1003 | |
| Lorenzo Colitti | 92e8f96 | 2017-09-26 19:13:50 +0900 | [diff] [blame] | 1004 | // Adds or removes an IPv4 or IPv6 route to the specified table. |
| Lorenzo Colitti | f7fc8ec | 2014-06-18 00:41:58 +0900 | [diff] [blame] | 1005 | // Returns 0 on success or negative errno on failure. |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 1006 | int RouteController::modifyRoute(uint16_t action, uint16_t flags, const char* interface, |
| 1007 | const char* destination, const char* nexthop, TableType tableType, |
| 1008 | int mtu) { |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1009 | uint32_t table; |
| Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 1010 | switch (tableType) { |
| 1011 | case RouteController::INTERFACE: { |
| 1012 | table = getRouteTableForInterface(interface); |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1013 | if (table == RT_TABLE_UNSPEC) { |
| 1014 | return -ESRCH; |
| 1015 | } |
| Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 1016 | break; |
| 1017 | } |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 1018 | case RouteController::LOCAL_NETWORK: { |
| 1019 | table = ROUTE_TABLE_LOCAL_NETWORK; |
| 1020 | break; |
| 1021 | } |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1022 | case RouteController::LEGACY_NETWORK: { |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1023 | table = ROUTE_TABLE_LEGACY_NETWORK; |
| Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 1024 | break; |
| 1025 | } |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1026 | case RouteController::LEGACY_SYSTEM: { |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1027 | table = ROUTE_TABLE_LEGACY_SYSTEM; |
| Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 1028 | break; |
| 1029 | } |
| 1030 | } |
| Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 1031 | |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 1032 | int ret = modifyIpRoute(action, flags, table, interface, destination, nexthop, mtu); |
| Sreeram Ramachandran | 0321315 | 2014-10-30 10:01:07 -0700 | [diff] [blame] | 1033 | // Trying to add a route that already exists shouldn't cause an error. |
| 1034 | if (ret && !(action == RTM_NEWROUTE && ret == -EEXIST)) { |
| Lorenzo Colitti | f7fc8ec | 2014-06-18 00:41:58 +0900 | [diff] [blame] | 1035 | return ret; |
| Sreeram Ramachandran | c921337 | 2014-04-16 12:32:18 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| Lorenzo Colitti | f7fc8ec | 2014-06-18 00:41:58 +0900 | [diff] [blame] | 1038 | return 0; |
| Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| Lorenzo Colitti | 3810c97 | 2021-01-06 11:44:02 +0900 | [diff] [blame] | 1041 | static void maybeModifyQdiscClsact(const char* interface, bool add) { |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 1042 | // The clsact attaching of v4- tun interface is triggered by ClatdController::maybeStartBpf |
| 1043 | // because the clat is started before the v4- interface is added to the network and the |
| 1044 | // clat startup needs to add {in, e}gress filters. |
| 1045 | // TODO: remove this workaround once v4- tun interface clsact attaching is moved out from |
| 1046 | // ClatdController::maybeStartBpf. |
| 1047 | if (StartsWith(interface, "v4-") && add) return; |
| 1048 | |
| 1049 | // The interface may have already gone away in the delete case. |
| 1050 | uint32_t ifindex = if_nametoindex(interface); |
| 1051 | if (!ifindex) { |
| 1052 | ALOGE("cannot find interface %s", interface); |
| 1053 | return; |
| 1054 | } |
| 1055 | |
| 1056 | if (add) { |
| 1057 | if (int ret = tcQdiscAddDevClsact(ifindex)) { |
| 1058 | ALOGE("tcQdiscAddDevClsact(%d[%s]) failure: %s", ifindex, interface, strerror(-ret)); |
| 1059 | return; |
| 1060 | } |
| 1061 | } else { |
| 1062 | if (int ret = tcQdiscDelDevClsact(ifindex)) { |
| 1063 | ALOGE("tcQdiscDelDevClsact(%d[%s]) failure: %s", ifindex, interface, strerror(-ret)); |
| 1064 | return; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 1071 | [[nodiscard]] static int clearTetheringRules(const char* inputInterface) { |
| Lorenzo Colitti | 6b6f25f | 2015-03-03 17:22:57 +0900 | [diff] [blame] | 1072 | int ret = 0; |
| 1073 | while (ret == 0) { |
| 1074 | ret = modifyIpRule(RTM_DELRULE, RULE_PRIORITY_TETHERING, 0, MARK_UNSET, MARK_UNSET, |
| 1075 | inputInterface, OIF_NONE, INVALID_UID, INVALID_UID); |
| 1076 | } |
| 1077 | |
| 1078 | if (ret == -ENOENT) { |
| 1079 | return 0; |
| 1080 | } else { |
| 1081 | return ret; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 1085 | uint32_t getRulePriority(const nlmsghdr *nlh) { |
| 1086 | return getRtmU32Attribute(nlh, FRA_PRIORITY); |
| 1087 | } |
| 1088 | |
| 1089 | uint32_t getRouteTable(const nlmsghdr *nlh) { |
| 1090 | return getRtmU32Attribute(nlh, RTA_TABLE); |
| 1091 | } |
| 1092 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 1093 | [[nodiscard]] static int flushRules() { |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 1094 | NetlinkDumpFilter shouldDelete = [] (nlmsghdr *nlh) { |
| 1095 | // Don't touch rules at priority 0 because by default they are used for local input. |
| 1096 | return getRulePriority(nlh) != 0; |
| 1097 | }; |
| 1098 | return rtNetlinkFlush(RTM_GETRULE, RTM_DELRULE, "rules", shouldDelete); |
| 1099 | } |
| 1100 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 1101 | int RouteController::flushRoutes(uint32_t table) { |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 1102 | NetlinkDumpFilter shouldDelete = [table] (nlmsghdr *nlh) { |
| 1103 | return getRouteTable(nlh) == table; |
| 1104 | }; |
| 1105 | |
| 1106 | return rtNetlinkFlush(RTM_GETROUTE, RTM_DELROUTE, "routes", shouldDelete); |
| 1107 | } |
| 1108 | |
| 1109 | // Returns 0 on success or negative errno on failure. |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 1110 | int RouteController::flushRoutes(const char* interface) { |
| Bernie Innocenti | abf8a34 | 2018-08-10 15:17:16 +0900 | [diff] [blame] | 1111 | std::lock_guard lock(sInterfaceToTableLock); |
| Lorenzo Colitti | 107075a | 2017-10-30 19:24:46 +0900 | [diff] [blame] | 1112 | |
| 1113 | uint32_t table = getRouteTableForInterfaceLocked(interface); |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 1114 | if (table == RT_TABLE_UNSPEC) { |
| 1115 | return -ESRCH; |
| 1116 | } |
| 1117 | |
| 1118 | int ret = flushRoutes(table); |
| 1119 | |
| 1120 | // If we failed to flush routes, the caller may elect to keep this interface around, so keep |
| 1121 | // track of its name. |
| 1122 | if (ret == 0) { |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 1123 | sInterfaceToTable.erase(interface); |
| Lorenzo Colitti | f3e299a | 2017-02-14 17:24:28 +0900 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | return ret; |
| 1127 | } |
| 1128 | |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 1129 | int RouteController::Init(unsigned localNetId) { |
| Sreeram Ramachandran | b717e74 | 2014-07-19 00:22:15 -0700 | [diff] [blame] | 1130 | if (int ret = flushRules()) { |
| 1131 | return ret; |
| 1132 | } |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 1133 | if (int ret = addLegacyRouteRules()) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1134 | return ret; |
| 1135 | } |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 1136 | if (int ret = addLocalNetworkRules(localNetId)) { |
| 1137 | return ret; |
| 1138 | } |
| Sreeram Ramachandran | b717e74 | 2014-07-19 00:22:15 -0700 | [diff] [blame] | 1139 | if (int ret = addUnreachableRule()) { |
| 1140 | return ret; |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1141 | } |
| Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 1142 | // Don't complain if we can't add the dummy network, since not all devices support it. |
| 1143 | configureDummyNetwork(); |
| 1144 | |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1145 | updateTableNamesFile(); |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1146 | return 0; |
| Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 1149 | int RouteController::addInterfaceToLocalNetwork(unsigned netId, const char* interface) { |
| Lorenzo Colitti | b6dc40a | 2020-03-24 00:58:50 +0900 | [diff] [blame] | 1150 | if (int ret = modifyLocalNetwork(netId, interface, ACTION_ADD)) { |
| 1151 | return ret; |
| 1152 | } |
| 1153 | std::lock_guard lock(sInterfaceToTableLock); |
| 1154 | sInterfaceToTable[interface] = ROUTE_TABLE_LOCAL_NETWORK; |
| 1155 | return 0; |
| Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | int RouteController::removeInterfaceFromLocalNetwork(unsigned netId, const char* interface) { |
| Lorenzo Colitti | b6dc40a | 2020-03-24 00:58:50 +0900 | [diff] [blame] | 1159 | if (int ret = modifyLocalNetwork(netId, interface, ACTION_DEL)) { |
| 1160 | return ret; |
| 1161 | } |
| 1162 | std::lock_guard lock(sInterfaceToTableLock); |
| 1163 | sInterfaceToTable.erase(interface); |
| 1164 | return 0; |
| Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1167 | int RouteController::addInterfaceToPhysicalNetwork(unsigned netId, const char* interface, |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 1168 | Permission permission, |
| 1169 | const UidRanges& uidRanges) { |
| 1170 | if (int ret = modifyPhysicalNetwork(netId, interface, uidRanges, permission, ACTION_ADD, |
| 1171 | MODIFY_NON_UID_BASED_RULES)) { |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1172 | return ret; |
| 1173 | } |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 1174 | maybeModifyQdiscClsact(interface, ACTION_ADD); |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1175 | updateTableNamesFile(); |
| 1176 | return 0; |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1179 | int RouteController::removeInterfaceFromPhysicalNetwork(unsigned netId, const char* interface, |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 1180 | Permission permission, |
| 1181 | const UidRanges& uidRanges) { |
| 1182 | if (int ret = modifyPhysicalNetwork(netId, interface, uidRanges, permission, ACTION_DEL, |
| 1183 | MODIFY_NON_UID_BASED_RULES)) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1184 | return ret; |
| 1185 | } |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1186 | if (int ret = flushRoutes(interface)) { |
| 1187 | return ret; |
| 1188 | } |
| Lorenzo Colitti | 6b6f25f | 2015-03-03 17:22:57 +0900 | [diff] [blame] | 1189 | if (int ret = clearTetheringRules(interface)) { |
| 1190 | return ret; |
| 1191 | } |
| Hungming Chen | 7f72543 | 2020-02-07 17:47:23 +0800 | [diff] [blame] | 1192 | maybeModifyQdiscClsact(interface, ACTION_DEL); |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1193 | updateTableNamesFile(); |
| 1194 | return 0; |
| Sreeram Ramachandran | 379bd33 | 2014-04-10 19:58:06 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1197 | int RouteController::addInterfaceToVirtualNetwork(unsigned netId, const char* interface, |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 1198 | bool secure, const UidRanges& uidRanges) { |
| 1199 | if (int ret = modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_ADD, |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1200 | MODIFY_NON_UID_BASED_RULES)) { |
| 1201 | return ret; |
| 1202 | } |
| 1203 | updateTableNamesFile(); |
| 1204 | return 0; |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1207 | int RouteController::removeInterfaceFromVirtualNetwork(unsigned netId, const char* interface, |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 1208 | bool secure, const UidRanges& uidRanges) { |
| 1209 | if (int ret = modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_DEL, |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1210 | MODIFY_NON_UID_BASED_RULES)) { |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 1211 | return ret; |
| 1212 | } |
| Sreeram Ramachandran | 4acd34a | 2014-07-07 22:11:37 -0700 | [diff] [blame] | 1213 | if (int ret = flushRoutes(interface)) { |
| 1214 | return ret; |
| 1215 | } |
| 1216 | updateTableNamesFile(); |
| 1217 | return 0; |
| Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1220 | int RouteController::modifyPhysicalNetworkPermission(unsigned netId, const char* interface, |
| 1221 | Permission oldPermission, |
| 1222 | Permission newPermission) { |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 1223 | UidRanges noUidRanges; |
| Sreeram Ramachandran | 379bd33 | 2014-04-10 19:58:06 -0700 | [diff] [blame] | 1224 | // Add the new rules before deleting the old ones, to avoid race conditions. |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 1225 | if (int ret = modifyPhysicalNetwork(netId, interface, noUidRanges, newPermission, ACTION_ADD, |
| 1226 | MODIFY_NON_UID_BASED_RULES)) { |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1227 | return ret; |
| 1228 | } |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 1229 | return modifyPhysicalNetwork(netId, interface, noUidRanges, oldPermission, ACTION_DEL, |
| 1230 | MODIFY_NON_UID_BASED_RULES); |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 1233 | int RouteController::addUsersToRejectNonSecureNetworkRule(const UidRanges& uidRanges) { |
| 1234 | return modifyRejectNonSecureNetworkRule(uidRanges, true); |
| 1235 | } |
| 1236 | |
| 1237 | int RouteController::removeUsersFromRejectNonSecureNetworkRule(const UidRanges& uidRanges) { |
| 1238 | return modifyRejectNonSecureNetworkRule(uidRanges, false); |
| 1239 | } |
| 1240 | |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 1241 | int RouteController::addUsersToVirtualNetwork(unsigned netId, const char* interface, bool secure, |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1242 | const UidRanges& uidRanges) { |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 1243 | return modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_ADD, |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1244 | !MODIFY_NON_UID_BASED_RULES); |
| Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1247 | int RouteController::removeUsersFromVirtualNetwork(unsigned netId, const char* interface, |
| Sreeram Ramachandran | 95684ba | 2014-07-23 13:27:31 -0700 | [diff] [blame] | 1248 | bool secure, const UidRanges& uidRanges) { |
| 1249 | return modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_DEL, |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1250 | !MODIFY_NON_UID_BASED_RULES); |
| Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1253 | int RouteController::addInterfaceToDefaultNetwork(const char* interface, Permission permission) { |
| 1254 | return modifyDefaultNetwork(RTM_NEWRULE, interface, permission); |
| Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
| Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 1257 | int RouteController::removeInterfaceFromDefaultNetwork(const char* interface, |
| 1258 | Permission permission) { |
| 1259 | return modifyDefaultNetwork(RTM_DELRULE, interface, permission); |
| Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 1260 | } |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 1261 | |
| Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1262 | int RouteController::addRoute(const char* interface, const char* destination, const char* nexthop, |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 1263 | TableType tableType, int mtu) { |
| 1264 | return modifyRoute(RTM_NEWROUTE, NETLINK_ROUTE_CREATE_FLAGS, interface, destination, nexthop, |
| 1265 | tableType, mtu); |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
| Lorenzo Colitti | f7fc8ec | 2014-06-18 00:41:58 +0900 | [diff] [blame] | 1268 | int RouteController::removeRoute(const char* interface, const char* destination, |
| Sreeram Ramachandran | eb27b7e | 2014-07-01 14:30:30 -0700 | [diff] [blame] | 1269 | const char* nexthop, TableType tableType) { |
| Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 1270 | return modifyRoute(RTM_DELROUTE, NETLINK_REQUEST_FLAGS, interface, destination, nexthop, |
| 1271 | tableType, 0); |
| 1272 | } |
| 1273 | |
| 1274 | int RouteController::updateRoute(const char* interface, const char* destination, |
| 1275 | const char* nexthop, TableType tableType, int mtu) { |
| 1276 | return modifyRoute(RTM_NEWROUTE, NETLINK_ROUTE_REPLACE_FLAGS, interface, destination, nexthop, |
| 1277 | tableType, mtu); |
| Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 1278 | } |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 1279 | |
| 1280 | int RouteController::enableTethering(const char* inputInterface, const char* outputInterface) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 1281 | return modifyTetheredNetwork(RTM_NEWRULE, inputInterface, outputInterface); |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | int RouteController::disableTethering(const char* inputInterface, const char* outputInterface) { |
| Sreeram Ramachandran | fa9f4dc | 2014-07-22 18:16:44 -0700 | [diff] [blame] | 1285 | return modifyTetheredNetwork(RTM_DELRULE, inputInterface, outputInterface); |
| Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 1286 | } |
| Sreeram Ramachandran | 48e19b0 | 2014-07-22 22:23:20 -0700 | [diff] [blame] | 1287 | |
| 1288 | int RouteController::addVirtualNetworkFallthrough(unsigned vpnNetId, const char* physicalInterface, |
| 1289 | Permission permission) { |
| 1290 | return modifyVpnFallthroughRule(RTM_NEWRULE, vpnNetId, physicalInterface, permission); |
| 1291 | } |
| 1292 | |
| 1293 | int RouteController::removeVirtualNetworkFallthrough(unsigned vpnNetId, |
| 1294 | const char* physicalInterface, |
| 1295 | Permission permission) { |
| 1296 | return modifyVpnFallthroughRule(RTM_DELRULE, vpnNetId, physicalInterface, permission); |
| 1297 | } |
| Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 1298 | |
| Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 1299 | int RouteController::addUsersToPhysicalNetwork(unsigned netId, const char* interface, |
| 1300 | const UidRanges& uidRanges) { |
| 1301 | return modifyPhysicalNetwork(netId, interface, uidRanges, PERMISSION_NONE, ACTION_ADD, |
| 1302 | !MODIFY_NON_UID_BASED_RULES); |
| 1303 | } |
| 1304 | |
| 1305 | int RouteController::removeUsersFromPhysicalNetwork(unsigned netId, const char* interface, |
| 1306 | const UidRanges& uidRanges) { |
| 1307 | return modifyPhysicalNetwork(netId, interface, uidRanges, PERMISSION_NONE, ACTION_DEL, |
| 1308 | !MODIFY_NON_UID_BASED_RULES); |
| 1309 | } |
| 1310 | |
| Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame^] | 1311 | int RouteController::addUsersToUnreachableNetwork(unsigned netId, const UidRanges& uidRanges) { |
| 1312 | return modifyUnreachableNetwork(netId, uidRanges, ACTION_ADD); |
| 1313 | } |
| 1314 | |
| 1315 | int RouteController::removeUsersFromUnreachableNetwork(unsigned netId, const UidRanges& uidRanges) { |
| 1316 | return modifyUnreachableNetwork(netId, uidRanges, ACTION_DEL); |
| 1317 | } |
| 1318 | |
| Lorenzo Colitti | 107075a | 2017-10-30 19:24:46 +0900 | [diff] [blame] | 1319 | // Protects sInterfaceToTable. |
| Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 1320 | std::mutex RouteController::sInterfaceToTableLock; |
| Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 1321 | std::map<std::string, uint32_t> RouteController::sInterfaceToTable; |
| 1322 | |
| Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 1323 | } // namespace android::net |