Sreeram Ramachandran | d736d4b | 2014-03-26 18:33:47 -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 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 17 | #pragma once |
Sreeram Ramachandran | d736d4b | 2014-03-26 18:33:47 -0700 | [diff] [blame] | 18 | |
Chiachang Wang | 5320c1a | 2022-03-07 19:19:33 +0800 | [diff] [blame] | 19 | #include "InterfaceController.h" // getParameter |
| 20 | #include "NetdConstants.h" // IptablesTarget |
| 21 | #include "Network.h" // UidRangeMap |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 22 | #include "Permission.h" |
| 23 | |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 24 | #include <android-base/thread_annotations.h> |
| 25 | |
Lorenzo Colitti | 60367db | 2017-02-13 16:31:45 +0900 | [diff] [blame] | 26 | #include <linux/netlink.h> |
Luke Huang | d1ee462 | 2018-06-29 13:49:58 +0800 | [diff] [blame] | 27 | #include <sys/types.h> |
| 28 | #include <map> |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 29 | #include <mutex> |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 30 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 31 | namespace android::net { |
Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 32 | |
Ken Chen | 69839af | 2021-01-05 22:48:32 +0800 | [diff] [blame] | 33 | // clang-format off |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 34 | constexpr int32_t RULE_PRIORITY_VPN_OVERRIDE_SYSTEM = 10000; |
| 35 | constexpr int32_t RULE_PRIORITY_VPN_OVERRIDE_OIF = 11000; |
| 36 | constexpr int32_t RULE_PRIORITY_VPN_OUTPUT_TO_LOCAL = 12000; |
| 37 | constexpr int32_t RULE_PRIORITY_SECURE_VPN = 13000; |
| 38 | constexpr int32_t RULE_PRIORITY_PROHIBIT_NON_VPN = 14000; |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 39 | // Rules used when applications explicitly select a network that they have permission to use only |
| 40 | // because they are in the list of UID ranges for that network. |
| 41 | // |
| 42 | // Sockets from these UIDs will not match RULE_PRIORITY_EXPLICIT_NETWORK rules because they will |
| 43 | // not have the necessary permission bits in the fwmark. We cannot just give any socket on any of |
| 44 | // these networks the permission bits, because if the UID that created the socket loses access to |
| 45 | // the network, then the socket must not match any rule that selects that network. |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 46 | constexpr int32_t RULE_PRIORITY_UID_EXPLICIT_NETWORK = 15000; |
| 47 | constexpr int32_t RULE_PRIORITY_EXPLICIT_NETWORK = 16000; |
| 48 | constexpr int32_t RULE_PRIORITY_OUTPUT_INTERFACE = 17000; |
| 49 | constexpr int32_t RULE_PRIORITY_LEGACY_SYSTEM = 18000; |
| 50 | constexpr int32_t RULE_PRIORITY_LEGACY_NETWORK = 19000; |
| 51 | constexpr int32_t RULE_PRIORITY_LOCAL_NETWORK = 20000; |
| 52 | constexpr int32_t RULE_PRIORITY_TETHERING = 21000; |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 53 | // Implicit rules for sockets that connected on a given network because the network was the default |
| 54 | // network for the UID. |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 55 | constexpr int32_t RULE_PRIORITY_UID_IMPLICIT_NETWORK = 22000; |
| 56 | constexpr int32_t RULE_PRIORITY_IMPLICIT_NETWORK = 23000; |
| 57 | constexpr int32_t RULE_PRIORITY_BYPASSABLE_VPN_NO_LOCAL_EXCLUSION = 24000; |
chiachangwang | 0d5ae98 | 2022-05-17 05:16:16 +0000 | [diff] [blame] | 58 | // Sets of rules used for excluding local routes from the VPN. Look up tables |
| 59 | // that contain directly-connected local routes taken from the default network. |
| 60 | // The first set is used for apps that have a per-UID default network. The rule |
| 61 | // UID ranges match those of the per-UID default network rule for that network. |
| 62 | // The second set has no UID ranges and is used for apps whose default network |
| 63 | // is the system default network network. |
| 64 | constexpr int32_t RULE_PRIORITY_UID_LOCAL_ROUTES = 25000; |
| 65 | constexpr int32_t RULE_PRIORITY_LOCAL_ROUTES = 26000; |
| 66 | constexpr int32_t RULE_PRIORITY_BYPASSABLE_VPN_LOCAL_EXCLUSION = 27000; |
| 67 | constexpr int32_t RULE_PRIORITY_VPN_FALLTHROUGH = 28000; |
| 68 | constexpr int32_t RULE_PRIORITY_UID_DEFAULT_NETWORK = 29000; |
Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame] | 69 | // Rule used when framework wants to disable default network from specified applications. There will |
| 70 | // be a small interval the same uid range exists in both UID_DEFAULT_UNREACHABLE and |
| 71 | // UID_DEFAULT_NETWORK when framework is switching user preferences. |
| 72 | // |
| 73 | // framework --> netd |
| 74 | // step 1: set uid to unreachable network |
| 75 | // step 2: remove uid from OEM-paid network list |
Ken Chen | 55db380 | 2021-03-30 13:47:49 +0800 | [diff] [blame] | 76 | // or |
| 77 | // step 1: add uid to OEM-paid network list |
| 78 | // step 2: remove uid from unreachable network |
Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame] | 79 | // |
Ken Chen | 55db380 | 2021-03-30 13:47:49 +0800 | [diff] [blame] | 80 | // The priority is lower than UID_DEFAULT_NETWORK. Otherwise, the app will be told by |
| 81 | // ConnectivityService that it has a network in step 1 of the second case. But if it tries to use |
| 82 | // the network, it will not work. That will potentially cause a user-visible error. |
chiachangwang | 0d5ae98 | 2022-05-17 05:16:16 +0000 | [diff] [blame] | 83 | constexpr int32_t RULE_PRIORITY_UID_DEFAULT_UNREACHABLE = 30000; |
| 84 | constexpr int32_t RULE_PRIORITY_DEFAULT_NETWORK = 31000; |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 85 | constexpr int32_t RULE_PRIORITY_UNREACHABLE = 32000; |
Ken Chen | 69839af | 2021-01-05 22:48:32 +0800 | [diff] [blame] | 86 | // clang-format on |
| 87 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 88 | class UidRanges; |
| 89 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 90 | class RouteController { |
| 91 | public: |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 92 | // How the routing table number is determined for route modification requests. |
| 93 | enum TableType { |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 94 | INTERFACE, // Compute the table number based on the interface index. |
Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 95 | LOCAL_NETWORK, // A fixed table used for routes to directly-connected clients/peers. |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 96 | LEGACY_NETWORK, // Use a fixed table that's used to override the default network. |
| 97 | LEGACY_SYSTEM, // A fixed table, only modifiable by system apps; overrides VPNs too. |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Sreeram Ramachandran | a481180 | 2014-04-10 12:10:24 -0700 | [diff] [blame] | 100 | static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000; |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 101 | // Offset for the table of virtual local network created from the physical interface. |
| 102 | static const int ROUTE_TABLE_OFFSET_FROM_INDEX_FOR_LOCAL = 1000000000; |
Sreeram Ramachandran | a481180 | 2014-04-10 12:10:24 -0700 | [diff] [blame] | 103 | |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 104 | static constexpr const char* INTERFACE_LOCAL_SUFFIX = "_local"; |
| 105 | static constexpr const char* RT_TABLES_PATH = "/data/misc/net/rt_tables"; |
Lorenzo Colitti | d78843e | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 106 | static const char* const LOCAL_MANGLE_INPUT; |
| 107 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 108 | [[nodiscard]] static int Init(unsigned localNetId); |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 109 | |
Rubin Xu | 6c00b61 | 2018-04-27 14:27:59 +0100 | [diff] [blame] | 110 | // Returns an ifindex given the interface name, by looking up in sInterfaceToTable. |
| 111 | // This is currently only used by NetworkController::addInterfaceToNetwork |
| 112 | // and should probabaly be changed to passing the ifindex into RouteController instead. |
| 113 | // We do this instead of calling if_nametoindex because the same interface name can |
| 114 | // correspond to different interface indices over time. This way, even if the interface |
| 115 | // index has changed, we can still free any map entries indexed by the ifindex that was |
| 116 | // used to add them. |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 117 | static uint32_t getIfIndex(const char* interface) EXCLUDES(sInterfaceToTableLock); |
Rubin Xu | 6c00b61 | 2018-04-27 14:27:59 +0100 | [diff] [blame] | 118 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 119 | [[nodiscard]] static int addInterfaceToLocalNetwork(unsigned netId, const char* interface); |
| 120 | [[nodiscard]] static int removeInterfaceFromLocalNetwork(unsigned netId, const char* interface); |
Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 121 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 122 | [[nodiscard]] static int addInterfaceToPhysicalNetwork(unsigned netId, const char* interface, |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 123 | Permission permission, |
Chalard Jean | e479f31 | 2022-12-12 18:27:49 +0900 | [diff] [blame] | 124 | const UidRangeMap& uidRangeMap, |
| 125 | bool local); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 126 | [[nodiscard]] static int removeInterfaceFromPhysicalNetwork(unsigned netId, |
| 127 | const char* interface, |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 128 | Permission permission, |
Chalard Jean | e479f31 | 2022-12-12 18:27:49 +0900 | [diff] [blame] | 129 | const UidRangeMap& uidRangeMap, |
| 130 | bool local); |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 131 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 132 | [[nodiscard]] static int addInterfaceToVirtualNetwork(unsigned netId, const char* interface, |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 133 | bool secure, |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 134 | const UidRangeMap& uidRangeMap, |
| 135 | bool excludeLocalRoutes); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 136 | [[nodiscard]] static int removeInterfaceFromVirtualNetwork(unsigned netId, |
| 137 | const char* interface, bool secure, |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 138 | const UidRangeMap& uidRangeMap, |
| 139 | bool excludeLocalRoutes); |
Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 140 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 141 | [[nodiscard]] static int modifyPhysicalNetworkPermission(unsigned netId, const char* interface, |
| 142 | Permission oldPermission, |
Chalard Jean | e479f31 | 2022-12-12 18:27:49 +0900 | [diff] [blame] | 143 | Permission newPermission, bool local); |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 144 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 145 | [[nodiscard]] static int addUsersToVirtualNetwork(unsigned netId, const char* interface, |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 146 | bool secure, const UidRangeMap& uidRangeMap, |
| 147 | bool excludeLocalRoutes); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 148 | [[nodiscard]] static int removeUsersFromVirtualNetwork(unsigned netId, const char* interface, |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 149 | bool secure, |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 150 | const UidRangeMap& uidRangeMap, |
| 151 | bool excludeLocalRoutes); |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 152 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 153 | [[nodiscard]] static int addUsersToRejectNonSecureNetworkRule(const UidRanges& uidRanges); |
| 154 | [[nodiscard]] static int removeUsersFromRejectNonSecureNetworkRule(const UidRanges& uidRanges); |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 155 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 156 | [[nodiscard]] static int addInterfaceToDefaultNetwork(const char* interface, |
| 157 | Permission permission); |
| 158 | [[nodiscard]] static int removeInterfaceFromDefaultNetwork(const char* interface, |
| 159 | Permission permission); |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 160 | |
Sreeram Ramachandran | de5d5df | 2014-07-26 18:43:25 -0700 | [diff] [blame] | 161 | // |nexthop| can be NULL (to indicate a directly-connected route), "unreachable" (to indicate a |
Lorenzo Colitti | 4c95a12 | 2014-09-18 16:01:50 +0900 | [diff] [blame] | 162 | // route that's blocked), "throw" (to indicate the lack of a match), or a regular IP address. |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 163 | [[nodiscard]] static int addRoute(const char* interface, const char* destination, |
Taras Antoshchuk | 0cceda2 | 2021-09-24 18:40:03 +0200 | [diff] [blame] | 164 | const char* nexthop, TableType tableType, int mtu, |
| 165 | int priority); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 166 | [[nodiscard]] static int removeRoute(const char* interface, const char* destination, |
Taras Antoshchuk | 0cceda2 | 2021-09-24 18:40:03 +0200 | [diff] [blame] | 167 | const char* nexthop, TableType tableType, int priority); |
Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 168 | [[nodiscard]] static int updateRoute(const char* interface, const char* destination, |
| 169 | const char* nexthop, TableType tableType, int mtu); |
Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 170 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 171 | [[nodiscard]] static int enableTethering(const char* inputInterface, |
| 172 | const char* outputInterface); |
| 173 | [[nodiscard]] static int disableTethering(const char* inputInterface, |
| 174 | const char* outputInterface); |
Sreeram Ramachandran | 48e19b0 | 2014-07-22 22:23:20 -0700 | [diff] [blame] | 175 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 176 | [[nodiscard]] static int addVirtualNetworkFallthrough(unsigned vpnNetId, |
| 177 | const char* physicalInterface, |
| 178 | Permission permission); |
| 179 | [[nodiscard]] static int removeVirtualNetworkFallthrough(unsigned vpnNetId, |
| 180 | const char* physicalInterface, |
| 181 | Permission permission); |
Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 182 | |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 183 | [[nodiscard]] static int addUsersToPhysicalNetwork(unsigned netId, const char* interface, |
Chalard Jean | e479f31 | 2022-12-12 18:27:49 +0900 | [diff] [blame] | 184 | const UidRangeMap& uidRangeMap, bool local); |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 185 | |
| 186 | [[nodiscard]] static int removeUsersFromPhysicalNetwork(unsigned netId, const char* interface, |
Chalard Jean | e479f31 | 2022-12-12 18:27:49 +0900 | [diff] [blame] | 187 | const UidRangeMap& uidRangeMap, |
| 188 | bool local); |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 189 | |
Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame] | 190 | [[nodiscard]] static int addUsersToUnreachableNetwork(unsigned netId, |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 191 | const UidRangeMap& uidRangeMap); |
Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame] | 192 | |
| 193 | [[nodiscard]] static int removeUsersFromUnreachableNetwork(unsigned netId, |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 194 | const UidRangeMap& uidRangeMap); |
Ken Chen | 4e8ef9b | 2021-03-17 01:57:19 +0800 | [diff] [blame] | 195 | |
Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 196 | // For testing. |
| 197 | static int (*iptablesRestoreCommandFunction)(IptablesTarget, const std::string&, |
| 198 | const std::string&, std::string *); |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 199 | static uint32_t (*ifNameToIndexFunction)(const char*); |
Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 200 | |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 201 | private: |
Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 202 | friend class RouteControllerTest; |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 203 | |
chiachangwang | d3f3d06 | 2022-10-31 10:50:18 +0000 | [diff] [blame] | 204 | // An expandable array for fixed local prefix though it's only one element now. |
| 205 | static constexpr const char* V4_FIXED_LOCAL_PREFIXES[] = { |
| 206 | // The multicast range is 224.0.0.0/4 but only limit it to 224.0.0.0/24 since the IPv4 |
| 207 | // definitions are not as precise as for IPv6, it is the only range that the standards |
| 208 | // (RFC 2365 and RFC 5771) specify is link-local and must not be forwarded. |
| 209 | "224.0.0.0/24" // Link-local multicast; non-internet routable |
| 210 | }; |
| 211 | |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 212 | static std::mutex sInterfaceToTableLock; |
| 213 | static std::map<std::string, uint32_t> sInterfaceToTable GUARDED_BY(sInterfaceToTableLock); |
Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 214 | |
| 215 | static int configureDummyNetwork(); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 216 | [[nodiscard]] static int flushRoutes(const char* interface) EXCLUDES(sInterfaceToTableLock); |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 217 | [[nodiscard]] static int flushRoutes(const char* interface, bool local) |
| 218 | EXCLUDES(sInterfaceToTableLock); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 219 | [[nodiscard]] static int flushRoutes(uint32_t table); |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 220 | static uint32_t getRouteTableForInterfaceLocked(const char* interface, bool local) |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 221 | REQUIRES(sInterfaceToTableLock); |
Chiachang Wang | f79e356 | 2022-01-15 13:31:04 +0800 | [diff] [blame] | 222 | static uint32_t getRouteTableForInterface(const char* interface, bool local) |
| 223 | EXCLUDES(sInterfaceToTableLock); |
Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 224 | static int modifyDefaultNetwork(uint16_t action, const char* interface, Permission permission); |
Ken Chen | 8738e1c | 2020-11-24 11:38:54 +0800 | [diff] [blame] | 225 | static int modifyPhysicalNetwork(unsigned netId, const char* interface, |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 226 | const UidRangeMap& uidRangeMap, Permission permission, |
Chalard Jean | e479f31 | 2022-12-12 18:27:49 +0900 | [diff] [blame] | 227 | bool add, bool modifyNonUidBasedRules, bool local); |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 228 | static int modifyUnreachableNetwork(unsigned netId, const UidRangeMap& uidRangeMap, bool add); |
Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 229 | static int modifyRoute(uint16_t action, uint16_t flags, const char* interface, |
| 230 | const char* destination, const char* nexthop, TableType tableType, |
Chiachang | f9e81ac | 2022-05-12 05:21:20 +0000 | [diff] [blame] | 231 | int mtu, int priority, bool isLocal); |
Lorenzo Colitti | 02cb80a | 2017-10-30 19:21:06 +0900 | [diff] [blame] | 232 | static int modifyTetheredNetwork(uint16_t action, const char* inputInterface, |
| 233 | const char* outputInterface); |
| 234 | static int modifyVpnFallthroughRule(uint16_t action, unsigned vpnNetId, |
| 235 | const char* physicalInterface, Permission permission); |
| 236 | static int modifyVirtualNetwork(unsigned netId, const char* interface, |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 237 | const UidRangeMap& uidRangeMap, bool secure, bool add, |
Chiachang Wang | 2e9443f | 2022-01-14 22:55:36 +0800 | [diff] [blame] | 238 | bool modifyNonUidBasedRules, bool excludeLocalRoutes); |
Luke Huang | 534980c | 2018-07-06 17:50:11 +0800 | [diff] [blame] | 239 | static void updateTableNamesFile() EXCLUDES(sInterfaceToTableLock); |
Chiachang Wang | 8b9cdd2 | 2022-01-27 10:43:28 +0800 | [diff] [blame] | 240 | static int modifyVpnLocalExclusionRule(bool add, const char* physicalInterface); |
Chiachang | f9e81ac | 2022-05-12 05:21:20 +0000 | [diff] [blame] | 241 | |
chiachangwang | 0d5ae98 | 2022-05-17 05:16:16 +0000 | [diff] [blame] | 242 | static int modifyUidLocalNetworkRule(const char* interface, uid_t uidStart, uid_t uidEnd, |
| 243 | bool add); |
chiachangwang | 2efd0ce | 2022-06-15 02:42:44 +0000 | [diff] [blame] | 244 | static bool isLocalRoute(TableType tableType, const char* destination, const char* nexthop); |
| 245 | static bool isWithinIpv4LocalPrefix(const char* addrstr); |
chiachangwang | 5308c04 | 2022-08-25 06:55:19 +0000 | [diff] [blame] | 246 | static int addFixedLocalRoutes(const char* interface); |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
Lorenzo Colitti | 60367db | 2017-02-13 16:31:45 +0900 | [diff] [blame] | 249 | // Public because they are called by by RouteControllerTest.cpp. |
| 250 | // TODO: come up with a scheme of unit testing this code that does not rely on making all its |
| 251 | // functions public. |
Tyler Wear | fa94a27 | 2019-12-05 15:01:48 -0800 | [diff] [blame] | 252 | [[nodiscard]] int modifyIpRoute(uint16_t action, uint16_t flags, uint32_t table, |
| 253 | const char* interface, const char* destination, const char* nexthop, |
Taras Antoshchuk | 0cceda2 | 2021-09-24 18:40:03 +0200 | [diff] [blame] | 254 | uint32_t mtu, uint32_t priority); |
Lorenzo Colitti | 60367db | 2017-02-13 16:31:45 +0900 | [diff] [blame] | 255 | uint32_t getRulePriority(const nlmsghdr *nlh); |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 256 | [[nodiscard]] int modifyIncomingPacketMark(unsigned netId, const char* interface, |
| 257 | Permission permission, bool add); |
Lorenzo Colitti | 60367db | 2017-02-13 16:31:45 +0900 | [diff] [blame] | 258 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 259 | } // namespace android::net |