RouteController.h revision 6a773534e7f8541f221f27fb8063af079b1a5936
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 UidRanges;
26
27class RouteController {
28public:
29    // 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_NETWORK,  // Use a fixed table that's used to override the default network.
33        LEGACY_SYSTEM,   // A fixed table, only modifiable by system apps; overrides VPNs too.
34    };
35
36    static const int ROUTE_TABLE_OFFSET_FROM_INDEX = 1000;
37
38    static int Init() WARN_UNUSED_RESULT;
39
40    static int addInterfaceToLocalNetwork(unsigned netId, const char* interface) WARN_UNUSED_RESULT;
41    static int removeInterfaceFromLocalNetwork(unsigned netId,
42                                               const char* interface) WARN_UNUSED_RESULT;
43
44    static int addInterfaceToPhysicalNetwork(unsigned netId, const char* interface,
45                                             Permission permission) WARN_UNUSED_RESULT;
46    static int removeInterfaceFromPhysicalNetwork(unsigned netId, const char* interface,
47                                                  Permission permission) WARN_UNUSED_RESULT;
48
49    static int addInterfaceToVirtualNetwork(unsigned netId, const char* interface,
50                                            const UidRanges& uidRanges) WARN_UNUSED_RESULT;
51    static int removeInterfaceFromVirtualNetwork(unsigned netId, const char* interface,
52                                                 const UidRanges& uidRanges) WARN_UNUSED_RESULT;
53
54    static int modifyPhysicalNetworkPermission(unsigned netId, const char* interface,
55                                               Permission oldPermission,
56                                               Permission newPermission) WARN_UNUSED_RESULT;
57
58    static int addUsersToVirtualNetwork(unsigned netId, const char* interface,
59                                        const UidRanges& uidRanges) WARN_UNUSED_RESULT;
60    static int removeUsersFromVirtualNetwork(unsigned netId, const char* interface,
61                                             const UidRanges& uidRanges) WARN_UNUSED_RESULT;
62
63    static int addInterfaceToDefaultNetwork(const char* interface,
64                                            Permission permission) WARN_UNUSED_RESULT;
65    static int removeInterfaceFromDefaultNetwork(const char* interface,
66                                                 Permission permission) WARN_UNUSED_RESULT;
67
68    static int addRoute(const char* interface, const char* destination, const char* nexthop,
69                        TableType tableType) WARN_UNUSED_RESULT;
70    static int removeRoute(const char* interface, const char* destination, const char* nexthop,
71                           TableType tableType) WARN_UNUSED_RESULT;
72};
73
74#endif  // NETD_SERVER_ROUTE_CONTROLLER_H
75