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