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 | |
Sreeram Ramachandran | f4cfad3 | 2014-05-21 08:54:07 -0700 | [diff] [blame] | 17 | #ifndef NETD_SERVER_ROUTE_CONTROLLER_H |
| 18 | #define NETD_SERVER_ROUTE_CONTROLLER_H |
Sreeram Ramachandran | d736d4b | 2014-03-26 18:33:47 -0700 | [diff] [blame] | 19 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 20 | #include "NetdConstants.h" |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 21 | #include "Permission.h" |
| 22 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 23 | #include <sys/types.h> |
| 24 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 25 | class UidRanges; |
| 26 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 27 | class RouteController { |
| 28 | public: |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 29 | // How the routing table number is determined for route modification requests. |
| 30 | enum TableType { |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 31 | INTERFACE, // Compute the table number based on the interface index. |
| 32 | LEGACY_NETWORK, // Use a fixed table that's used to override the default network. |
| 33 | 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] | 34 | }; |
| 35 | |
Sreeram Ramachandran | a481180 | 2014-04-10 12:10:24 -0700 | [diff] [blame] | 36 | static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000; |
| 37 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 38 | static int Init() WARN_UNUSED_RESULT; |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 39 | |
Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame^] | 40 | static int addInterfaceToLocalNetwork(unsigned netId, const char* interface) WARN_UNUSED_RESULT; |
| 41 | static int removeInterfaceFromLocalNetwork(unsigned netId, |
| 42 | const char* interface) WARN_UNUSED_RESULT; |
| 43 | |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 44 | static int addInterfaceToPhysicalNetwork(unsigned netId, const char* interface, |
| 45 | Permission permission) WARN_UNUSED_RESULT; |
| 46 | static int removeInterfaceFromPhysicalNetwork(unsigned netId, const char* interface, |
| 47 | Permission permission) WARN_UNUSED_RESULT; |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 48 | |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 49 | static int addInterfaceToVirtualNetwork(unsigned netId, const char* interface, |
| 50 | const UidRanges& uidRanges) WARN_UNUSED_RESULT; |
| 51 | static int removeInterfaceFromVirtualNetwork(unsigned netId, const char* interface, |
| 52 | const UidRanges& uidRanges) WARN_UNUSED_RESULT; |
Sreeram Ramachandran | 4043f01 | 2014-06-23 12:41:37 -0700 | [diff] [blame] | 53 | |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 54 | static int modifyPhysicalNetworkPermission(unsigned netId, const char* interface, |
| 55 | Permission oldPermission, |
| 56 | Permission newPermission) WARN_UNUSED_RESULT; |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 57 | |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 58 | static int addUsersToVirtualNetwork(unsigned netId, const char* interface, |
| 59 | const UidRanges& uidRanges) WARN_UNUSED_RESULT; |
| 60 | static int removeUsersFromVirtualNetwork(unsigned netId, const char* interface, |
| 61 | const UidRanges& uidRanges) WARN_UNUSED_RESULT; |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 62 | |
Sreeram Ramachandran | 5009d5e | 2014-07-03 12:20:48 -0700 | [diff] [blame] | 63 | static int addInterfaceToDefaultNetwork(const char* interface, |
| 64 | Permission permission) WARN_UNUSED_RESULT; |
| 65 | static int removeInterfaceFromDefaultNetwork(const char* interface, |
| 66 | Permission permission) WARN_UNUSED_RESULT; |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 67 | |
Lorenzo Colitti | f7fc8ec | 2014-06-18 00:41:58 +0900 | [diff] [blame] | 68 | static int addRoute(const char* interface, const char* destination, const char* nexthop, |
Sreeram Ramachandran | eb27b7e | 2014-07-01 14:30:30 -0700 | [diff] [blame] | 69 | TableType tableType) WARN_UNUSED_RESULT; |
Lorenzo Colitti | f7fc8ec | 2014-06-18 00:41:58 +0900 | [diff] [blame] | 70 | static int removeRoute(const char* interface, const char* destination, const char* nexthop, |
Sreeram Ramachandran | eb27b7e | 2014-07-01 14:30:30 -0700 | [diff] [blame] | 71 | TableType tableType) WARN_UNUSED_RESULT; |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Sreeram Ramachandran | f4cfad3 | 2014-05-21 08:54:07 -0700 | [diff] [blame] | 74 | #endif // NETD_SERVER_ROUTE_CONTROLLER_H |