RouteController.h revision 4043f01f8e25f24246efadc710ad7440aab75529
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 "NetdConstants.h"
21#include "Permission.h"
22
23#include <sys/types.h>
24
25class RouteController {
26public:
27    // 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
34    static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
35
36    static int Init() WARN_UNUSED_RESULT;
37
38    static int addInterfaceToNetwork(unsigned netId, const char* interface,
39                                     Permission permission) WARN_UNUSED_RESULT;
40    static int removeInterfaceFromNetwork(unsigned netId, const char* interface,
41                                          Permission permission) WARN_UNUSED_RESULT;
42
43    static int addInterfaceToVpn(unsigned netId, const char* interface) WARN_UNUSED_RESULT;
44    static int removeInterfaceFromVpn(unsigned netId, const char* interface) WARN_UNUSED_RESULT;
45
46    static int modifyNetworkPermission(unsigned netId, const char* interface,
47                                       Permission oldPermission,
48                                       Permission newPermission) WARN_UNUSED_RESULT;
49
50    static int addToDefaultNetwork(const char* interface, Permission permission) WARN_UNUSED_RESULT;
51    static int removeFromDefaultNetwork(const char* interface,
52                                        Permission permission) WARN_UNUSED_RESULT;
53
54    static int addRoute(const char* interface, const char* destination, const char* nexthop,
55                        TableType tableType, uid_t uid) WARN_UNUSED_RESULT;
56    static int removeRoute(const char* interface, const char* destination, const char* nexthop,
57                           TableType tableType, uid_t uid) WARN_UNUSED_RESULT;
58};
59
60#endif  // NETD_SERVER_ROUTE_CONTROLLER_H
61