blob: 9162023bd3fef0b1a48ae9ecd479fddf26dd59e4 [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.
32 LEGACY, // Based on the UID; such tables can override the default network routes.
33 PRIVILEGED_LEGACY, // Based on the UID; such tables can bypass VPNs.
34 };
35
Sreeram Ramachandrana4811802014-04-10 12:10:24 -070036 static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
37
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070038 static int Init() WARN_UNUSED_RESULT;
Sreeram Ramachandran8fe9c8e2014-04-16 12:08:05 -070039
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070040 static int addInterfaceToNetwork(unsigned netId, const char* interface,
41 Permission permission) WARN_UNUSED_RESULT;
Lorenzo Colitti96f261e2014-06-23 15:09:54 +090042 static int removeInterfaceFromNetwork(unsigned netId, const char* interface,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070043 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran9c0d3132014-04-10 20:35:04 -070044
Sreeram Ramachandranb1425cc2014-06-23 18:54:27 -070045 static int addInterfaceToVpn(unsigned netId, const char* interface,
46 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
47 static int removeInterfaceFromVpn(unsigned netId, const char* interface,
48 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
Sreeram Ramachandran4043f012014-06-23 12:41:37 -070049
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070050 static int modifyNetworkPermission(unsigned netId, const char* interface,
51 Permission oldPermission,
52 Permission newPermission) WARN_UNUSED_RESULT;
53
54 static int addToDefaultNetwork(const char* interface, Permission permission) WARN_UNUSED_RESULT;
55 static int removeFromDefaultNetwork(const char* interface,
56 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran7619e1b2014-04-15 14:23:08 -070057
Sreeram Ramachandranb1425cc2014-06-23 18:54:27 -070058 static int addUsersToVpn(unsigned netId, const char* interface,
59 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
60 static int removeUsersFromVpn(unsigned netId, const char* interface,
61 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
62
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090063 static int addRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070064 TableType tableType, uid_t uid) WARN_UNUSED_RESULT;
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090065 static int removeRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070066 TableType tableType, uid_t uid) WARN_UNUSED_RESULT;
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070067};
68
Sreeram Ramachandranf4cfad32014-05-21 08:54:07 -070069#endif // NETD_SERVER_ROUTE_CONTROLLER_H