RouteController.h revision 82eab785bd5cb2eff0a263f5b0dcde13e9139588
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
17#ifndef NETD_SERVER_ROUTE_CONTROLLER_H
18#define NETD_SERVER_ROUTE_CONTROLLER_H
19
20#include "Permission.h"
21
22class RouteController {
23public:
24    // How the routing table number is determined for route modification requests.
25    enum TableType {
26        INTERFACE,  // Compute the table number based on the interface index.
27        LEGACY,  // Based on the UID; such tables can override the default network routes.
28        PRIVILEGED_LEGACY,  // Based on the UID; such tables can bypass VPNs.
29    };
30
31    static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
32
33    static void Init();
34
35    static bool addInterfaceToNetwork(unsigned netId, const char* interface, Permission permission);
36    static bool removeInterfaceFromNetwork(unsigned netId, const char* interface,
37                                           Permission permission);
38    static bool modifyNetworkPermission(unsigned netId, const char* interface,
39                                        Permission oldPermission, Permission newPermission);
40
41    static bool addToDefaultNetwork(const char* interface, Permission permission);
42    static bool removeFromDefaultNetwork(const char* interface, Permission permission);
43
44    static bool addRoute(const char* interface, const char* destination, const char* nexthop,
45                         TableType tableType, unsigned uid);
46    static bool removeRoute(const char* interface, const char* destination, const char* nexthop,
47                            TableType tableType, unsigned uid);
48};
49
50#endif  // NETD_SERVER_ROUTE_CONTROLLER_H
51