blob: 33db69f4125ad659319c3bc855fcb00a2c8cc1c7 [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 {
31 INTERFACE, // Compute the table number based on the interface index.
Sreeram Ramachandraneb27b7e2014-07-01 14:30:30 -070032 LEGACY, // Use a fixed table that's used to override the default network.
33 PRIVILEGED_LEGACY, // A fixed table, only modifiable by privileged apps; overrides VPNs.
Sreeram Ramachandran38b7af12014-05-22 14:21:49 -070034 };
35
Sreeram Ramachandraneb27b7e2014-07-01 14:30:30 -070036 static const int ROUTE_TABLE_LEGACY = 98;
37 static const int ROUTE_TABLE_PRIVILEGED_LEGACY = 99;
Sreeram Ramachandrana4811802014-04-10 12:10:24 -070038 static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
39
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070040 static int Init() WARN_UNUSED_RESULT;
Sreeram Ramachandran8fe9c8e2014-04-16 12:08:05 -070041
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070042 static int addInterfaceToNetwork(unsigned netId, const char* interface,
43 Permission permission) WARN_UNUSED_RESULT;
Lorenzo Colitti96f261e2014-06-23 15:09:54 +090044 static int removeInterfaceFromNetwork(unsigned netId, const char* interface,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070045 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran9c0d3132014-04-10 20:35:04 -070046
Sreeram Ramachandranb1425cc2014-06-23 18:54:27 -070047 static int addInterfaceToVpn(unsigned netId, const char* interface,
48 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
49 static int removeInterfaceFromVpn(unsigned netId, const char* interface,
50 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
Sreeram Ramachandran4043f012014-06-23 12:41:37 -070051
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070052 static int modifyNetworkPermission(unsigned netId, const char* interface,
53 Permission oldPermission,
54 Permission newPermission) WARN_UNUSED_RESULT;
55
56 static int addToDefaultNetwork(const char* interface, Permission permission) WARN_UNUSED_RESULT;
57 static int removeFromDefaultNetwork(const char* interface,
58 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran7619e1b2014-04-15 14:23:08 -070059
Sreeram Ramachandranb1425cc2014-06-23 18:54:27 -070060 static int addUsersToVpn(unsigned netId, const char* interface,
61 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
62 static int removeUsersFromVpn(unsigned netId, const char* interface,
63 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
64
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090065 static int addRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandraneb27b7e2014-07-01 14:30:30 -070066 TableType tableType) WARN_UNUSED_RESULT;
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090067 static int removeRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandraneb27b7e2014-07-01 14:30:30 -070068 TableType tableType) WARN_UNUSED_RESULT;
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070069};
70
Sreeram Ramachandranf4cfad32014-05-21 08:54:07 -070071#endif // NETD_SERVER_ROUTE_CONTROLLER_H