blob: 3023f802afbd04d51732f3c69788a5423c4a57e6 [file] [log] [blame]
Lorenzo Colittie4d626e2016-02-02 17:19:04 +09001/**
2 * Copyright (c) 2016, 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_NATIVE_SERVICE_H_
18#define _NETD_NATIVE_SERVICE_H_
19
Lorenzo Colitti89faa342016-02-26 11:38:47 +090020#include <vector>
21
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090022#include <binder/BinderService.h>
Erik Klineb31fd692018-06-06 20:50:11 +090023#include <netdutils/Log.h>
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090024
25#include "android/net/BnNetd.h"
Robin Lee9f9aae92016-03-30 18:33:07 +010026#include "android/net/UidRange.h"
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090027
28namespace android {
29namespace net {
30
31class NetdNativeService : public BinderService<NetdNativeService>, public BnNetd {
32 public:
Lorenzo Colittie4851de2016-03-17 13:23:28 +090033 static status_t start();
Lorenzo Colittic2c7b752016-02-23 22:25:11 +090034 static char const* getServiceName() { return "netd"; }
Erik Kline2d3a1632016-03-15 16:33:48 +090035 virtual status_t dump(int fd, const Vector<String16> &args) override;
36
Lorenzo Colittie4d626e2016-02-02 17:19:04 +090037 binder::Status isAlive(bool *alive) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090038
39 // Firewall commands.
Lorenzo Colitti89faa342016-02-26 11:38:47 +090040 binder::Status firewallReplaceUidChain(
Erik Klinef52d4522018-03-14 15:01:46 +090041 const std::string& chainName, bool isWhitelist,
Erik Kline2d3a1632016-03-15 16:33:48 +090042 const std::vector<int32_t>& uids, bool *ret) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090043
44 // Bandwidth control commands.
Lorenzo Colittidedd2712016-03-22 12:36:29 +090045 binder::Status bandwidthEnableDataSaver(bool enable, bool *ret) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090046
47 // Network and routing commands.
48 binder::Status networkCreatePhysical(int32_t netId, const std::string& permission)
49 override;
50 binder::Status networkCreateVpn(int32_t netId, bool hasDns, bool secure) override;
51 binder::Status networkDestroy(int32_t netId) override;
52
53 binder::Status networkAddInterface(int32_t netId, const std::string& iface) override;
54 binder::Status networkRemoveInterface(int32_t netId, const std::string& iface) override;
55
56 binder::Status networkAddUidRanges(int32_t netId, const std::vector<UidRange>& uids)
57 override;
58 binder::Status networkRemoveUidRanges(int32_t netId, const std::vector<UidRange>& uids)
59 override;
Robin Leeb8087362016-03-30 18:43:08 +010060 binder::Status networkRejectNonSecureVpn(bool enable, const std::vector<UidRange>& uids)
61 override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090062
63 // SOCK_DIAG commands.
Lorenzo Colitti563d98b2016-04-24 13:13:14 +090064 binder::Status socketDestroy(const std::vector<UidRange>& uids,
65 const std::vector<int32_t>& skipUids) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090066
67 // Resolver commands.
Pierre Imaibeedec32016-04-13 06:44:51 +090068 binder::Status setResolverConfiguration(int32_t netId, const std::vector<std::string>& servers,
Ben Schwartz4204ecf2017-10-02 12:35:48 -040069 const std::vector<std::string>& domains, const std::vector<int32_t>& params,
Erik Klinea1476fb2018-03-04 21:01:56 +090070 const std::string& tlsName,
71 const std::vector<std::string>& tlsServers,
Ben Schwartz4204ecf2017-10-02 12:35:48 -040072 const std::vector<std::string>& tlsFingerprints) override;
Pierre Imaibeedec32016-04-13 06:44:51 +090073 binder::Status getResolverInfo(int32_t netId, std::vector<std::string>* servers,
74 std::vector<std::string>* domains, std::vector<int32_t>* params,
75 std::vector<int32_t>* stats) override;
Erik Klinef48e4dd2016-07-18 04:02:07 +090076
Joel Scherpelzde937962017-06-01 13:20:21 +090077 binder::Status setIPv6AddrGenMode(const std::string& ifName, int32_t mode) override;
78
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090079 // NFLOG-related commands
80 binder::Status wakeupAddInterface(const std::string& ifName, const std::string& prefix,
81 int32_t mark, int32_t mask) override;
82
83 binder::Status wakeupDelInterface(const std::string& ifName, const std::string& prefix,
84 int32_t mark, int32_t mask) override;
85
Erik Klinef48e4dd2016-07-18 04:02:07 +090086 // Tethering-related commands.
87 binder::Status tetherApplyDnsInterfaces(bool *ret) override;
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +090088 binder::Status tetherGetStats(android::os::PersistableBundle *ret) override;
Erik Kline53c20882016-08-02 15:22:53 +090089
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090090 // Interface-related commands.
Erik Kline53c20882016-08-02 15:22:53 +090091 binder::Status interfaceAddAddress(const std::string &ifName,
92 const std::string &addrString, int prefixLength) override;
93 binder::Status interfaceDelAddress(const std::string &ifName,
94 const std::string &addrString, int prefixLength) override;
Erik Kline55b06f82016-07-04 09:57:18 +090095
96 binder::Status setProcSysNet(
97 int32_t family, int32_t which, const std::string &ifname, const std::string &parameter,
98 const std::string &value) override;
Robin Lee2cf56172016-09-13 18:55:42 +090099
100 // Metrics reporting level set / get (internal use only).
101 binder::Status getMetricsReportingLevel(int *reportingLevel) override;
102 binder::Status setMetricsReportingLevel(const int reportingLevel) override;
Nathan Harold1a371532017-01-30 12:30:48 -0800103
Benedict Wongb2daefb2017-12-06 22:05:46 -0800104 binder::Status ipSecSetEncapSocketOwner(const android::base::unique_fd& socket, int newUid);
105
Nathan Harold1a371532017-01-30 12:30:48 -0800106 binder::Status ipSecAllocateSpi(
107 int32_t transformId,
Nathan Harold1a371532017-01-30 12:30:48 -0800108 const std::string& localAddress,
109 const std::string& remoteAddress,
110 int32_t inSpi,
111 int32_t* outSpi);
112
113 binder::Status ipSecAddSecurityAssociation(
114 int32_t transformId,
115 int32_t mode,
Nathan Haroldda54f122018-01-09 16:42:57 -0800116 const std::string& sourceAddress,
117 const std::string& destinationAddress,
Benedict Wong96abf482018-01-22 13:56:41 -0800118 int32_t underlyingNetId,
Nathan Harold1a371532017-01-30 12:30:48 -0800119 int32_t spi,
Di Lu2ccb3e52018-01-03 16:19:20 -0800120 int32_t markValue,
121 int32_t markMask,
Nathan Harold1a371532017-01-30 12:30:48 -0800122 const std::string& authAlgo,
123 const std::vector<uint8_t>& authKey,
124 int32_t authTruncBits,
125 const std::string& cryptAlgo,
126 const std::vector<uint8_t>& cryptKey,
127 int32_t cryptTruncBits,
Benedict Wongbe65b432017-08-22 21:43:14 -0700128 const std::string& aeadAlgo,
129 const std::vector<uint8_t>& aeadKey,
130 int32_t aeadIcvBits,
Nathan Harold1a371532017-01-30 12:30:48 -0800131 int32_t encapType,
132 int32_t encapLocalPort,
ludiec836052017-05-20 14:17:05 -0700133 int32_t encapRemotePort);
Nathan Harold1a371532017-01-30 12:30:48 -0800134
135 binder::Status ipSecDeleteSecurityAssociation(
136 int32_t transformId,
Nathan Haroldda54f122018-01-09 16:42:57 -0800137 const std::string& sourceAddress,
138 const std::string& destinationAddress,
Di Lu2ccb3e52018-01-03 16:19:20 -0800139 int32_t spi,
140 int32_t markValue,
141 int32_t markMask);
Nathan Harold1a371532017-01-30 12:30:48 -0800142
143 binder::Status ipSecApplyTransportModeTransform(
144 const android::base::unique_fd& socket,
145 int32_t transformId,
146 int32_t direction,
Nathan Haroldda54f122018-01-09 16:42:57 -0800147 const std::string& sourceAddress,
148 const std::string& destinationAddress,
Nathan Harold1a371532017-01-30 12:30:48 -0800149 int32_t spi);
150
151 binder::Status ipSecRemoveTransportModeTransform(
152 const android::base::unique_fd& socket);
Chenbo Feng07d43fe2017-12-21 14:38:51 -0800153
Benedict Wong84a8dca2018-01-19 12:12:17 -0800154 binder::Status ipSecAddSecurityPolicy(
155 int32_t transformId,
156 int32_t direction,
157 const std::string& sourceAddress,
158 const std::string& destinationAddress,
159 int32_t spi,
160 int32_t markValue,
161 int32_t markMask);
162
163 binder::Status ipSecUpdateSecurityPolicy(
164 int32_t transformId,
165 int32_t direction,
166 const std::string& sourceAddress,
167 const std::string& destinationAddress,
168 int32_t spi,
169 int32_t markValue,
170 int32_t markMask);
171
172 binder::Status ipSecDeleteSecurityPolicy(
173 int32_t transformId,
174 int32_t direction,
175 const std::string& sourceAddress,
176 const std::string& destinationAddress,
177 int32_t markValue,
178 int32_t markMask);
179
Chenbo Feng07d43fe2017-12-21 14:38:51 -0800180 binder::Status trafficCheckBpfStatsEnable(bool* ret) override;
manojboopathi8707f232018-01-02 14:45:47 -0800181
182 binder::Status addVirtualTunnelInterface(
183 const std::string& deviceName,
184 const std::string& localAddress,
185 const std::string& remoteAddress,
186 int32_t iKey,
187 int32_t oKey);
188
189 binder::Status updateVirtualTunnelInterface(
190 const std::string& deviceName,
191 const std::string& localAddress,
192 const std::string& remoteAddress,
193 int32_t iKey,
194 int32_t oKey);
195
196 binder::Status removeVirtualTunnelInterface(const std::string& deviceName);
Luke Huang0051a622018-07-23 20:30:16 +0800197
198 // Idletimer-related commands
199 binder::Status idletimerAddInterface(const std::string& ifName, int32_t timeout,
200 const std::string& classLabel) override;
201 binder::Status idletimerRemoveInterface(const std::string& ifName, int32_t timeout,
202 const std::string& classLabel) override;
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900203};
204
205} // namespace net
206} // namespace android
207
208#endif // _NETD_NATIVE_SERVICE_H_