blob: 1d6075dbde9deeff339d30195bee753c8c61e467 [file] [log] [blame]
Sreeram Ramachandrand736d4b2014-03-26 18:33:47 -07001/*
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 Ramachandranf4cfad32014-05-21 08:54:07 -070017#ifndef NETD_SERVER_ROUTE_CONTROLLER_H
18#define NETD_SERVER_ROUTE_CONTROLLER_H
Sreeram Ramachandrand736d4b2014-03-26 18:33:47 -070019
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070020#include "NetdConstants.h"
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070021#include "Permission.h"
22
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070023#include <sys/types.h>
24
Sreeram Ramachandranb1425cc2014-06-23 18:54:27 -070025class UidRanges;
26
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070027class RouteController {
28public:
Sreeram Ramachandran38b7af12014-05-22 14:21:49 -070029 // How the routing table number is determined for route modification requests.
30 enum TableType {
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070031 INTERFACE, // Compute the table number based on the interface index.
Sreeram Ramachandran87475a12014-07-15 16:20:28 -070032 LOCAL_NETWORK, // A fixed table used for routes to directly-connected clients/peers.
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070033 LEGACY_NETWORK, // Use a fixed table that's used to override the default network.
34 LEGACY_SYSTEM, // A fixed table, only modifiable by system apps; overrides VPNs too.
Sreeram Ramachandran38b7af12014-05-22 14:21:49 -070035 };
36
Sreeram Ramachandrana4811802014-04-10 12:10:24 -070037 static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
38
Sreeram Ramachandran87475a12014-07-15 16:20:28 -070039 static int Init(unsigned localNetId) WARN_UNUSED_RESULT;
Sreeram Ramachandran8fe9c8e2014-04-16 12:08:05 -070040
Sreeram Ramachandran6a773532014-07-11 09:10:20 -070041 static int addInterfaceToLocalNetwork(unsigned netId, const char* interface) WARN_UNUSED_RESULT;
42 static int removeInterfaceFromLocalNetwork(unsigned netId,
43 const char* interface) WARN_UNUSED_RESULT;
44
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070045 static int addInterfaceToPhysicalNetwork(unsigned netId, const char* interface,
46 Permission permission) WARN_UNUSED_RESULT;
47 static int removeInterfaceFromPhysicalNetwork(unsigned netId, const char* interface,
48 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran9c0d3132014-04-10 20:35:04 -070049
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070050 static int addInterfaceToVirtualNetwork(unsigned netId, const char* interface,
51 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
52 static int removeInterfaceFromVirtualNetwork(unsigned netId, const char* interface,
53 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
Sreeram Ramachandran4043f012014-06-23 12:41:37 -070054
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070055 static int modifyPhysicalNetworkPermission(unsigned netId, const char* interface,
56 Permission oldPermission,
57 Permission newPermission) WARN_UNUSED_RESULT;
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070058
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070059 static int addUsersToVirtualNetwork(unsigned netId, const char* interface,
60 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
61 static int removeUsersFromVirtualNetwork(unsigned netId, const char* interface,
62 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
Sreeram Ramachandran7619e1b2014-04-15 14:23:08 -070063
Sreeram Ramachandran5009d5e2014-07-03 12:20:48 -070064 static int addInterfaceToDefaultNetwork(const char* interface,
65 Permission permission) WARN_UNUSED_RESULT;
66 static int removeInterfaceFromDefaultNetwork(const char* interface,
67 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandranb1425cc2014-06-23 18:54:27 -070068
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090069 static int addRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandraneb27b7e2014-07-01 14:30:30 -070070 TableType tableType) WARN_UNUSED_RESULT;
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090071 static int removeRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandraneb27b7e2014-07-01 14:30:30 -070072 TableType tableType) WARN_UNUSED_RESULT;
Sreeram Ramachandran87475a12014-07-15 16:20:28 -070073
74 static int enableTethering(const char* inputInterface,
75 const char* outputInterface) WARN_UNUSED_RESULT;
76 static int disableTethering(const char* inputInterface,
77 const char* outputInterface) WARN_UNUSED_RESULT;
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070078};
79
Sreeram Ramachandranf4cfad32014-05-21 08:54:07 -070080#endif // NETD_SERVER_ROUTE_CONTROLLER_H