blob: a54adae767bff55dbbc8847f2e93d4d0f7448a85 [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 Ramachandran5c181bf2014-04-07 14:10:04 -070025class RouteController {
26public:
Sreeram Ramachandran38b7af12014-05-22 14:21:49 -070027 // How the routing table number is determined for route modification requests.
28 enum TableType {
29 INTERFACE, // Compute the table number based on the interface index.
30 LEGACY, // Based on the UID; such tables can override the default network routes.
31 PRIVILEGED_LEGACY, // Based on the UID; such tables can bypass VPNs.
32 };
33
Sreeram Ramachandrana4811802014-04-10 12:10:24 -070034 static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
35
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070036 static int Init() WARN_UNUSED_RESULT;
Sreeram Ramachandran8fe9c8e2014-04-16 12:08:05 -070037
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070038 static int addInterfaceToNetwork(unsigned netId, const char* interface,
39 Permission permission) WARN_UNUSED_RESULT;
Lorenzo Colitti96f261e2014-06-23 15:09:54 +090040 static int removeInterfaceFromNetwork(unsigned netId, const char* interface,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070041 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran9c0d3132014-04-10 20:35:04 -070042
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070043 static int modifyNetworkPermission(unsigned netId, const char* interface,
44 Permission oldPermission,
45 Permission newPermission) WARN_UNUSED_RESULT;
46
47 static int addToDefaultNetwork(const char* interface, Permission permission) WARN_UNUSED_RESULT;
48 static int removeFromDefaultNetwork(const char* interface,
49 Permission permission) WARN_UNUSED_RESULT;
Sreeram Ramachandran7619e1b2014-04-15 14:23:08 -070050
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090051 static int addRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070052 TableType tableType, uid_t uid) WARN_UNUSED_RESULT;
Lorenzo Colittif7fc8ec2014-06-18 00:41:58 +090053 static int removeRoute(const char* interface, const char* destination, const char* nexthop,
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070054 TableType tableType, uid_t uid) WARN_UNUSED_RESULT;
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070055};
56
Sreeram Ramachandranf4cfad32014-05-21 08:54:07 -070057#endif // NETD_SERVER_ROUTE_CONTROLLER_H