blob: 77179cd1a00d7fa2caf9249b63be6c6085bc7f6d [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;
Luke Huange64fa382018-07-24 16:38:22 +080043 binder::Status firewallSetFirewallType(int32_t firewallType) override;
44 binder::Status firewallSetInterfaceRule(const std::string& ifName,
45 int32_t firewallRule) override;
46 binder::Status firewallSetUidRule(int32_t childChain, int32_t uid,
47 int32_t firewallRule) override;
48 binder::Status firewallEnableChildChain(int32_t childChain, bool enable) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090049
50 // Bandwidth control commands.
Lorenzo Colittidedd2712016-03-22 12:36:29 +090051 binder::Status bandwidthEnableDataSaver(bool enable, bool *ret) override;
Luke Huang531f5d32018-08-03 15:19:05 +080052 binder::Status bandwidthSetInterfaceQuota(const std::string& ifName, int64_t bytes) override;
53 binder::Status bandwidthRemoveInterfaceQuota(const std::string& ifName) override;
54 binder::Status bandwidthSetInterfaceAlert(const std::string& ifName, int64_t bytes) override;
55 binder::Status bandwidthRemoveInterfaceAlert(const std::string& ifName) override;
56 binder::Status bandwidthSetGlobalAlert(int64_t bytes) override;
57 binder::Status bandwidthAddNaughtyApp(int32_t uid) override;
58 binder::Status bandwidthRemoveNaughtyApp(int32_t uid) override;
59 binder::Status bandwidthAddNiceApp(int32_t uid) override;
60 binder::Status bandwidthRemoveNiceApp(int32_t uid) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090061
62 // Network and routing commands.
Luke Huangb670d162018-08-23 20:01:13 +080063 binder::Status networkCreatePhysical(int32_t netId, int32_t permission) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090064 binder::Status networkCreateVpn(int32_t netId, bool hasDns, bool secure) override;
65 binder::Status networkDestroy(int32_t netId) override;
66
67 binder::Status networkAddInterface(int32_t netId, const std::string& iface) override;
68 binder::Status networkRemoveInterface(int32_t netId, const std::string& iface) override;
69
70 binder::Status networkAddUidRanges(int32_t netId, const std::vector<UidRange>& uids)
71 override;
72 binder::Status networkRemoveUidRanges(int32_t netId, const std::vector<UidRange>& uids)
73 override;
Robin Leeb8087362016-03-30 18:43:08 +010074 binder::Status networkRejectNonSecureVpn(bool enable, const std::vector<UidRange>& uids)
75 override;
Luke Huangb670d162018-08-23 20:01:13 +080076 binder::Status networkAddRoute(int32_t netId, const std::string& ifName,
77 const std::string& destination,
78 const std::string& nextHop) override;
79 binder::Status networkRemoveRoute(int32_t netId, const std::string& ifName,
80 const std::string& destination,
81 const std::string& nextHop) override;
82 binder::Status networkAddLegacyRoute(int32_t netId, const std::string& ifName,
83 const std::string& destination, const std::string& nextHop,
84 int32_t uid) override;
85 binder::Status networkRemoveLegacyRoute(int32_t netId, const std::string& ifName,
86 const std::string& destination,
87 const std::string& nextHop, int32_t uid) override;
88 binder::Status networkSetDefault(int32_t netId) override;
89 binder::Status networkClearDefault() override;
90 binder::Status networkSetPermissionForNetwork(int32_t netId, int32_t permission) override;
91 binder::Status networkSetPermissionForUser(int32_t permission,
92 const std::vector<int32_t>& uids) override;
93 binder::Status networkClearPermissionForUser(const std::vector<int32_t>& uids) override;
94 binder::Status networkSetProtectAllow(int32_t uid) override;
95 binder::Status networkSetProtectDeny(int32_t uid) override;
96 // For test (internal use only).
97 binder::Status networkGetDefault(int32_t* netId) override;
98 binder::Status networkCanProtect(int32_t uid, bool* ret) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +090099
100 // SOCK_DIAG commands.
Lorenzo Colitti563d98b2016-04-24 13:13:14 +0900101 binder::Status socketDestroy(const std::vector<UidRange>& uids,
102 const std::vector<int32_t>& skipUids) override;
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900103
104 // Resolver commands.
Pierre Imaibeedec32016-04-13 06:44:51 +0900105 binder::Status setResolverConfiguration(int32_t netId, const std::vector<std::string>& servers,
Ben Schwartz4204ecf2017-10-02 12:35:48 -0400106 const std::vector<std::string>& domains, const std::vector<int32_t>& params,
Erik Klinea1476fb2018-03-04 21:01:56 +0900107 const std::string& tlsName,
108 const std::vector<std::string>& tlsServers,
Ben Schwartz4204ecf2017-10-02 12:35:48 -0400109 const std::vector<std::string>& tlsFingerprints) override;
Pierre Imaibeedec32016-04-13 06:44:51 +0900110 binder::Status getResolverInfo(int32_t netId, std::vector<std::string>* servers,
111 std::vector<std::string>* domains, std::vector<int32_t>* params,
112 std::vector<int32_t>* stats) override;
Erik Klinef48e4dd2016-07-18 04:02:07 +0900113
Joel Scherpelzde937962017-06-01 13:20:21 +0900114 binder::Status setIPv6AddrGenMode(const std::string& ifName, int32_t mode) override;
115
Joel Scherpelz08b84cd2017-05-22 13:11:54 +0900116 // NFLOG-related commands
117 binder::Status wakeupAddInterface(const std::string& ifName, const std::string& prefix,
118 int32_t mark, int32_t mask) override;
119
120 binder::Status wakeupDelInterface(const std::string& ifName, const std::string& prefix,
121 int32_t mark, int32_t mask) override;
122
Erik Klinef48e4dd2016-07-18 04:02:07 +0900123 // Tethering-related commands.
124 binder::Status tetherApplyDnsInterfaces(bool *ret) override;
Luke Huangcaebcbb2018-09-27 20:37:14 +0800125 binder::Status tetherGetStats(
126 std::vector<android::net::TetherStatsParcel>* tetherStatsVec) override;
Luke Huangb5733d72018-08-21 17:17:19 +0800127 binder::Status tetherStart(const std::vector<std::string>& dhcpRanges) override;
128 binder::Status tetherStop() override;
129 binder::Status tetherIsEnabled(bool* enabled) override;
130 binder::Status tetherInterfaceAdd(const std::string& ifName) override;
131 binder::Status tetherInterfaceRemove(const std::string& ifName) override;
132 binder::Status tetherInterfaceList(std::vector<std::string>* ifList) override;
133 binder::Status tetherDnsSet(int32_t netId, const std::vector<std::string>& dnsAddrs) override;
134 binder::Status tetherDnsList(std::vector<std::string>* dnsList) override;
Erik Kline53c20882016-08-02 15:22:53 +0900135
Lorenzo Colittid33e96d2016-12-15 23:59:01 +0900136 // Interface-related commands.
Erik Kline53c20882016-08-02 15:22:53 +0900137 binder::Status interfaceAddAddress(const std::string &ifName,
138 const std::string &addrString, int prefixLength) override;
139 binder::Status interfaceDelAddress(const std::string &ifName,
140 const std::string &addrString, int prefixLength) override;
Erik Kline55b06f82016-07-04 09:57:18 +0900141
Erik Kline38e51f12018-09-06 20:14:44 +0900142 binder::Status getProcSysNet(int32_t ipversion, int32_t which, const std::string& ifname,
143 const std::string& parameter, std::string* value) override;
144 binder::Status setProcSysNet(int32_t ipversion, int32_t which, const std::string& ifname,
145 const std::string& parameter, const std::string& value) override;
Robin Lee2cf56172016-09-13 18:55:42 +0900146
147 // Metrics reporting level set / get (internal use only).
148 binder::Status getMetricsReportingLevel(int *reportingLevel) override;
149 binder::Status setMetricsReportingLevel(const int reportingLevel) override;
Nathan Harold1a371532017-01-30 12:30:48 -0800150
Benedict Wongb2daefb2017-12-06 22:05:46 -0800151 binder::Status ipSecSetEncapSocketOwner(const android::base::unique_fd& socket, int newUid);
152
Nathan Harold1a371532017-01-30 12:30:48 -0800153 binder::Status ipSecAllocateSpi(
154 int32_t transformId,
Nathan Harold1a371532017-01-30 12:30:48 -0800155 const std::string& localAddress,
156 const std::string& remoteAddress,
157 int32_t inSpi,
158 int32_t* outSpi);
159
160 binder::Status ipSecAddSecurityAssociation(
161 int32_t transformId,
162 int32_t mode,
Nathan Haroldda54f122018-01-09 16:42:57 -0800163 const std::string& sourceAddress,
164 const std::string& destinationAddress,
Benedict Wong96abf482018-01-22 13:56:41 -0800165 int32_t underlyingNetId,
Nathan Harold1a371532017-01-30 12:30:48 -0800166 int32_t spi,
Di Lu2ccb3e52018-01-03 16:19:20 -0800167 int32_t markValue,
168 int32_t markMask,
Nathan Harold1a371532017-01-30 12:30:48 -0800169 const std::string& authAlgo,
170 const std::vector<uint8_t>& authKey,
171 int32_t authTruncBits,
172 const std::string& cryptAlgo,
173 const std::vector<uint8_t>& cryptKey,
174 int32_t cryptTruncBits,
Benedict Wongbe65b432017-08-22 21:43:14 -0700175 const std::string& aeadAlgo,
176 const std::vector<uint8_t>& aeadKey,
177 int32_t aeadIcvBits,
Nathan Harold1a371532017-01-30 12:30:48 -0800178 int32_t encapType,
179 int32_t encapLocalPort,
ludiec836052017-05-20 14:17:05 -0700180 int32_t encapRemotePort);
Nathan Harold1a371532017-01-30 12:30:48 -0800181
182 binder::Status ipSecDeleteSecurityAssociation(
183 int32_t transformId,
Nathan Haroldda54f122018-01-09 16:42:57 -0800184 const std::string& sourceAddress,
185 const std::string& destinationAddress,
Di Lu2ccb3e52018-01-03 16:19:20 -0800186 int32_t spi,
187 int32_t markValue,
188 int32_t markMask);
Nathan Harold1a371532017-01-30 12:30:48 -0800189
190 binder::Status ipSecApplyTransportModeTransform(
191 const android::base::unique_fd& socket,
192 int32_t transformId,
193 int32_t direction,
Nathan Haroldda54f122018-01-09 16:42:57 -0800194 const std::string& sourceAddress,
195 const std::string& destinationAddress,
Nathan Harold1a371532017-01-30 12:30:48 -0800196 int32_t spi);
197
198 binder::Status ipSecRemoveTransportModeTransform(
199 const android::base::unique_fd& socket);
Chenbo Feng07d43fe2017-12-21 14:38:51 -0800200
Benedict Wonga04ffa72018-05-09 21:42:42 -0700201 binder::Status ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
202 int32_t direction, const std::string& tmplSrcAddress,
Benedict Wongad600cb2018-05-14 17:22:35 -0700203 const std::string& tmplDstAddress, int32_t spi,
204 int32_t markValue, int32_t markMask);
Benedict Wong84a8dca2018-01-19 12:12:17 -0800205
Benedict Wonga04ffa72018-05-09 21:42:42 -0700206 binder::Status ipSecUpdateSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
207 int32_t direction, const std::string& tmplSrcAddress,
Benedict Wongad600cb2018-05-14 17:22:35 -0700208 const std::string& tmplDstAddress, int32_t spi,
209 int32_t markValue, int32_t markMask);
Benedict Wong84a8dca2018-01-19 12:12:17 -0800210
Benedict Wonga04ffa72018-05-09 21:42:42 -0700211 binder::Status ipSecDeleteSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
212 int32_t direction, int32_t markValue,
Benedict Wongad600cb2018-05-14 17:22:35 -0700213 int32_t markMask);
Benedict Wong84a8dca2018-01-19 12:12:17 -0800214
Chenbo Feng07d43fe2017-12-21 14:38:51 -0800215 binder::Status trafficCheckBpfStatsEnable(bool* ret) override;
manojboopathi8707f232018-01-02 14:45:47 -0800216
217 binder::Status addVirtualTunnelInterface(
218 const std::string& deviceName,
219 const std::string& localAddress,
220 const std::string& remoteAddress,
221 int32_t iKey,
222 int32_t oKey);
223
224 binder::Status updateVirtualTunnelInterface(
225 const std::string& deviceName,
226 const std::string& localAddress,
227 const std::string& remoteAddress,
228 int32_t iKey,
229 int32_t oKey);
230
231 binder::Status removeVirtualTunnelInterface(const std::string& deviceName);
Luke Huang0051a622018-07-23 20:30:16 +0800232
233 // Idletimer-related commands
234 binder::Status idletimerAddInterface(const std::string& ifName, int32_t timeout,
235 const std::string& classLabel) override;
236 binder::Status idletimerRemoveInterface(const std::string& ifName, int32_t timeout,
237 const std::string& classLabel) override;
Luke Huang6d301232018-08-01 14:05:18 +0800238
Luke Huanga67dd562018-07-17 19:58:25 +0800239 // Strict-related commands
240 binder::Status strictUidCleartextPenalty(int32_t uid, int32_t policyPenalty) override;
Luke Huang6d301232018-08-01 14:05:18 +0800241
242 // Clatd-related commands
243 binder::Status clatdStart(const std::string& ifName) override;
244 binder::Status clatdStop(const std::string& ifName) override;
Luke Huang457d4702018-08-16 15:39:15 +0800245
246 // Ipfw-related commands
247 binder::Status ipfwdEnabled(bool* status) override;
248 binder::Status ipfwdEnableForwarding(const std::string& requester) override;
249 binder::Status ipfwdDisableForwarding(const std::string& requester) override;
250 binder::Status ipfwdAddInterfaceForward(const std::string& fromIface,
251 const std::string& toIface) override;
252 binder::Status ipfwdRemoveInterfaceForward(const std::string& fromIface,
253 const std::string& toIface) override;
Luke Huangb670d162018-08-23 20:01:13 +0800254
255 private:
256 std::vector<uid_t> intsToUids(const std::vector<int32_t>& intUids);
257 Permission convertPermission(int32_t permission);
Luke Huange64fa382018-07-24 16:38:22 +0800258 static FirewallRule parseRule(int32_t firewallRule);
259 static ChildChain parseChildChain(int32_t childChain);
Lorenzo Colittie4d626e2016-02-02 17:19:04 +0900260};
261
262} // namespace net
263} // namespace android
264
265#endif // _NETD_NATIVE_SERVICE_H_