Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 1 | /** |
| 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 Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 22 | #include <binder/BinderService.h> |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame] | 23 | #include <netdutils/Log.h> |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 24 | |
| 25 | #include "android/net/BnNetd.h" |
| 26 | |
| 27 | namespace android { |
| 28 | namespace net { |
| 29 | |
| 30 | class NetdNativeService : public BinderService<NetdNativeService>, public BnNetd { |
| 31 | public: |
Lorenzo Colitti | e4851de | 2016-03-17 13:23:28 +0900 | [diff] [blame] | 32 | static status_t start(); |
Lorenzo Colitti | c2c7b75 | 2016-02-23 22:25:11 +0900 | [diff] [blame] | 33 | static char const* getServiceName() { return "netd"; } |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 34 | virtual status_t dump(int fd, const Vector<String16> &args) override; |
| 35 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 36 | binder::Status isAlive(bool *alive) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 37 | |
| 38 | // Firewall commands. |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 39 | binder::Status firewallReplaceUidChain( |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 40 | const std::string& chainName, bool isWhitelist, |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 41 | const std::vector<int32_t>& uids, bool *ret) override; |
Luke Huang | e64fa38 | 2018-07-24 16:38:22 +0800 | [diff] [blame] | 42 | binder::Status firewallSetFirewallType(int32_t firewallType) override; |
| 43 | binder::Status firewallSetInterfaceRule(const std::string& ifName, |
| 44 | int32_t firewallRule) override; |
| 45 | binder::Status firewallSetUidRule(int32_t childChain, int32_t uid, |
| 46 | int32_t firewallRule) override; |
| 47 | binder::Status firewallEnableChildChain(int32_t childChain, bool enable) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 48 | |
| 49 | // Bandwidth control commands. |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 50 | binder::Status bandwidthEnableDataSaver(bool enable, bool *ret) override; |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame] | 51 | binder::Status bandwidthSetInterfaceQuota(const std::string& ifName, int64_t bytes) override; |
| 52 | binder::Status bandwidthRemoveInterfaceQuota(const std::string& ifName) override; |
| 53 | binder::Status bandwidthSetInterfaceAlert(const std::string& ifName, int64_t bytes) override; |
| 54 | binder::Status bandwidthRemoveInterfaceAlert(const std::string& ifName) override; |
| 55 | binder::Status bandwidthSetGlobalAlert(int64_t bytes) override; |
| 56 | binder::Status bandwidthAddNaughtyApp(int32_t uid) override; |
| 57 | binder::Status bandwidthRemoveNaughtyApp(int32_t uid) override; |
| 58 | binder::Status bandwidthAddNiceApp(int32_t uid) override; |
| 59 | binder::Status bandwidthRemoveNiceApp(int32_t uid) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 60 | |
| 61 | // Network and routing commands. |
Luke Huang | b670d16 | 2018-08-23 20:01:13 +0800 | [diff] [blame] | 62 | binder::Status networkCreatePhysical(int32_t netId, int32_t permission) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 63 | binder::Status networkCreateVpn(int32_t netId, bool hasDns, bool secure) override; |
| 64 | binder::Status networkDestroy(int32_t netId) override; |
| 65 | |
| 66 | binder::Status networkAddInterface(int32_t netId, const std::string& iface) override; |
| 67 | binder::Status networkRemoveInterface(int32_t netId, const std::string& iface) override; |
| 68 | |
Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 69 | binder::Status networkAddUidRanges(int32_t netId, |
| 70 | const std::vector<UidRangeParcel>& uids) override; |
| 71 | binder::Status networkRemoveUidRanges(int32_t netId, |
| 72 | const std::vector<UidRangeParcel>& uids) override; |
| 73 | binder::Status networkRejectNonSecureVpn(bool enable, |
| 74 | const std::vector<UidRangeParcel>& uids) override; |
Luke Huang | b670d16 | 2018-08-23 20:01:13 +0800 | [diff] [blame] | 75 | binder::Status networkAddRoute(int32_t netId, const std::string& ifName, |
| 76 | const std::string& destination, |
| 77 | const std::string& nextHop) override; |
| 78 | binder::Status networkRemoveRoute(int32_t netId, const std::string& ifName, |
| 79 | const std::string& destination, |
| 80 | const std::string& nextHop) override; |
| 81 | binder::Status networkAddLegacyRoute(int32_t netId, const std::string& ifName, |
| 82 | const std::string& destination, const std::string& nextHop, |
| 83 | int32_t uid) override; |
| 84 | binder::Status networkRemoveLegacyRoute(int32_t netId, const std::string& ifName, |
| 85 | const std::string& destination, |
| 86 | const std::string& nextHop, int32_t uid) override; |
| 87 | binder::Status networkSetDefault(int32_t netId) override; |
| 88 | binder::Status networkClearDefault() override; |
| 89 | binder::Status networkSetPermissionForNetwork(int32_t netId, int32_t permission) override; |
| 90 | binder::Status networkSetPermissionForUser(int32_t permission, |
| 91 | const std::vector<int32_t>& uids) override; |
| 92 | binder::Status networkClearPermissionForUser(const std::vector<int32_t>& uids) override; |
| 93 | binder::Status networkSetProtectAllow(int32_t uid) override; |
| 94 | binder::Status networkSetProtectDeny(int32_t uid) override; |
| 95 | // For test (internal use only). |
| 96 | binder::Status networkGetDefault(int32_t* netId) override; |
| 97 | binder::Status networkCanProtect(int32_t uid, bool* ret) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 98 | |
| 99 | // SOCK_DIAG commands. |
Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 100 | binder::Status socketDestroy(const std::vector<UidRangeParcel>& uids, |
| 101 | const std::vector<int32_t>& skipUids) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 102 | |
| 103 | // Resolver commands. |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 104 | binder::Status setResolverConfiguration(int32_t netId, const std::vector<std::string>& servers, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 105 | const std::vector<std::string>& domains, const std::vector<int32_t>& params, |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 106 | const std::string& tlsName, |
| 107 | const std::vector<std::string>& tlsServers, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 108 | const std::vector<std::string>& tlsFingerprints) override; |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 109 | binder::Status getResolverInfo(int32_t netId, std::vector<std::string>* servers, |
| 110 | std::vector<std::string>* domains, std::vector<int32_t>* params, |
| 111 | std::vector<int32_t>* stats) override; |
Erik Kline | f48e4dd | 2016-07-18 04:02:07 +0900 | [diff] [blame] | 112 | |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 113 | binder::Status setIPv6AddrGenMode(const std::string& ifName, int32_t mode) override; |
| 114 | |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 115 | // NFLOG-related commands |
| 116 | binder::Status wakeupAddInterface(const std::string& ifName, const std::string& prefix, |
| 117 | int32_t mark, int32_t mask) override; |
| 118 | |
| 119 | binder::Status wakeupDelInterface(const std::string& ifName, const std::string& prefix, |
| 120 | int32_t mark, int32_t mask) override; |
| 121 | |
Erik Kline | f48e4dd | 2016-07-18 04:02:07 +0900 | [diff] [blame] | 122 | // Tethering-related commands. |
| 123 | binder::Status tetherApplyDnsInterfaces(bool *ret) override; |
Luke Huang | caebcbb | 2018-09-27 20:37:14 +0800 | [diff] [blame] | 124 | binder::Status tetherGetStats( |
| 125 | std::vector<android::net::TetherStatsParcel>* tetherStatsVec) override; |
Luke Huang | b5733d7 | 2018-08-21 17:17:19 +0800 | [diff] [blame] | 126 | binder::Status tetherStart(const std::vector<std::string>& dhcpRanges) override; |
| 127 | binder::Status tetherStop() override; |
| 128 | binder::Status tetherIsEnabled(bool* enabled) override; |
| 129 | binder::Status tetherInterfaceAdd(const std::string& ifName) override; |
| 130 | binder::Status tetherInterfaceRemove(const std::string& ifName) override; |
| 131 | binder::Status tetherInterfaceList(std::vector<std::string>* ifList) override; |
| 132 | binder::Status tetherDnsSet(int32_t netId, const std::vector<std::string>& dnsAddrs) override; |
| 133 | binder::Status tetherDnsList(std::vector<std::string>* dnsList) override; |
Erik Kline | 53c2088 | 2016-08-02 15:22:53 +0900 | [diff] [blame] | 134 | |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 135 | // Interface-related commands. |
Erik Kline | 53c2088 | 2016-08-02 15:22:53 +0900 | [diff] [blame] | 136 | binder::Status interfaceAddAddress(const std::string &ifName, |
| 137 | const std::string &addrString, int prefixLength) override; |
| 138 | binder::Status interfaceDelAddress(const std::string &ifName, |
| 139 | const std::string &addrString, int prefixLength) override; |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame] | 140 | binder::Status interfaceGetList(std::vector<std::string>* interfaceListResult) override; |
| 141 | binder::Status interfaceGetCfg(const std::string& ifName, |
| 142 | InterfaceConfigurationParcel* interfaceGetCfgResult) override; |
| 143 | binder::Status interfaceSetCfg(const InterfaceConfigurationParcel& cfg) override; |
| 144 | binder::Status interfaceSetIPv6PrivacyExtensions(const std::string& ifName, |
| 145 | bool enable) override; |
| 146 | binder::Status interfaceClearAddrs(const std::string& ifName) override; |
| 147 | binder::Status interfaceSetEnableIPv6(const std::string& ifName, bool enable) override; |
| 148 | binder::Status interfaceSetMtu(const std::string& ifName, int32_t mtuValue) override; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 149 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 150 | binder::Status getProcSysNet(int32_t ipversion, int32_t which, const std::string& ifname, |
| 151 | const std::string& parameter, std::string* value) override; |
| 152 | binder::Status setProcSysNet(int32_t ipversion, int32_t which, const std::string& ifname, |
| 153 | const std::string& parameter, const std::string& value) override; |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 154 | |
| 155 | // Metrics reporting level set / get (internal use only). |
| 156 | binder::Status getMetricsReportingLevel(int *reportingLevel) override; |
| 157 | binder::Status setMetricsReportingLevel(const int reportingLevel) override; |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 158 | |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 159 | binder::Status ipSecSetEncapSocketOwner(const android::base::unique_fd& socket, int newUid); |
| 160 | |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 161 | binder::Status ipSecAllocateSpi( |
| 162 | int32_t transformId, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 163 | const std::string& localAddress, |
| 164 | const std::string& remoteAddress, |
| 165 | int32_t inSpi, |
| 166 | int32_t* outSpi); |
| 167 | |
| 168 | binder::Status ipSecAddSecurityAssociation( |
| 169 | int32_t transformId, |
| 170 | int32_t mode, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 171 | const std::string& sourceAddress, |
| 172 | const std::string& destinationAddress, |
Benedict Wong | 96abf48 | 2018-01-22 13:56:41 -0800 | [diff] [blame] | 173 | int32_t underlyingNetId, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 174 | int32_t spi, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 175 | int32_t markValue, |
| 176 | int32_t markMask, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 177 | const std::string& authAlgo, |
| 178 | const std::vector<uint8_t>& authKey, |
| 179 | int32_t authTruncBits, |
| 180 | const std::string& cryptAlgo, |
| 181 | const std::vector<uint8_t>& cryptKey, |
| 182 | int32_t cryptTruncBits, |
Benedict Wong | be65b43 | 2017-08-22 21:43:14 -0700 | [diff] [blame] | 183 | const std::string& aeadAlgo, |
| 184 | const std::vector<uint8_t>& aeadKey, |
| 185 | int32_t aeadIcvBits, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 186 | int32_t encapType, |
| 187 | int32_t encapLocalPort, |
ludi | ec83605 | 2017-05-20 14:17:05 -0700 | [diff] [blame] | 188 | int32_t encapRemotePort); |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 189 | |
| 190 | binder::Status ipSecDeleteSecurityAssociation( |
| 191 | int32_t transformId, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 192 | const std::string& sourceAddress, |
| 193 | const std::string& destinationAddress, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 194 | int32_t spi, |
| 195 | int32_t markValue, |
| 196 | int32_t markMask); |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 197 | |
| 198 | binder::Status ipSecApplyTransportModeTransform( |
| 199 | const android::base::unique_fd& socket, |
| 200 | int32_t transformId, |
| 201 | int32_t direction, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 202 | const std::string& sourceAddress, |
| 203 | const std::string& destinationAddress, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 204 | int32_t spi); |
| 205 | |
| 206 | binder::Status ipSecRemoveTransportModeTransform( |
| 207 | const android::base::unique_fd& socket); |
Chenbo Feng | 07d43fe | 2017-12-21 14:38:51 -0800 | [diff] [blame] | 208 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 209 | binder::Status ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 210 | int32_t direction, const std::string& tmplSrcAddress, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 211 | const std::string& tmplDstAddress, int32_t spi, |
| 212 | int32_t markValue, int32_t markMask); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 213 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 214 | binder::Status ipSecUpdateSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 215 | int32_t direction, const std::string& tmplSrcAddress, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 216 | const std::string& tmplDstAddress, int32_t spi, |
| 217 | int32_t markValue, int32_t markMask); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 218 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 219 | binder::Status ipSecDeleteSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 220 | int32_t direction, int32_t markValue, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 221 | int32_t markMask); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 222 | |
Chenbo Feng | 07d43fe | 2017-12-21 14:38:51 -0800 | [diff] [blame] | 223 | binder::Status trafficCheckBpfStatsEnable(bool* ret) override; |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 224 | |
Benedict Wong | 319f17e | 2018-05-15 17:06:44 -0700 | [diff] [blame^] | 225 | binder::Status ipSecAddTunnelInterface(const std::string& deviceName, |
| 226 | const std::string& localAddress, |
| 227 | const std::string& remoteAddress, int32_t iKey, |
| 228 | int32_t oKey); |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 229 | |
Benedict Wong | 319f17e | 2018-05-15 17:06:44 -0700 | [diff] [blame^] | 230 | binder::Status ipSecUpdateTunnelInterface(const std::string& deviceName, |
| 231 | const std::string& localAddress, |
| 232 | const std::string& remoteAddress, int32_t iKey, |
| 233 | int32_t oKey); |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 234 | |
Benedict Wong | 319f17e | 2018-05-15 17:06:44 -0700 | [diff] [blame^] | 235 | binder::Status ipSecRemoveTunnelInterface(const std::string& deviceName); |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 236 | |
| 237 | // Idletimer-related commands |
| 238 | binder::Status idletimerAddInterface(const std::string& ifName, int32_t timeout, |
| 239 | const std::string& classLabel) override; |
| 240 | binder::Status idletimerRemoveInterface(const std::string& ifName, int32_t timeout, |
| 241 | const std::string& classLabel) override; |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 242 | |
Luke Huang | a67dd56 | 2018-07-17 19:58:25 +0800 | [diff] [blame] | 243 | // Strict-related commands |
| 244 | binder::Status strictUidCleartextPenalty(int32_t uid, int32_t policyPenalty) override; |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 245 | |
| 246 | // Clatd-related commands |
| 247 | binder::Status clatdStart(const std::string& ifName) override; |
| 248 | binder::Status clatdStop(const std::string& ifName) override; |
Luke Huang | 457d470 | 2018-08-16 15:39:15 +0800 | [diff] [blame] | 249 | |
| 250 | // Ipfw-related commands |
| 251 | binder::Status ipfwdEnabled(bool* status) override; |
| 252 | binder::Status ipfwdEnableForwarding(const std::string& requester) override; |
| 253 | binder::Status ipfwdDisableForwarding(const std::string& requester) override; |
| 254 | binder::Status ipfwdAddInterfaceForward(const std::string& fromIface, |
| 255 | const std::string& toIface) override; |
| 256 | binder::Status ipfwdRemoveInterfaceForward(const std::string& fromIface, |
| 257 | const std::string& toIface) override; |
Luke Huang | 19b49c5 | 2018-10-22 12:12:05 +0900 | [diff] [blame] | 258 | // Tether-forward-related commands |
| 259 | binder::Status tetherAddForward(const std::string& intIface, |
| 260 | const std::string& extIface) override; |
| 261 | binder::Status tetherRemoveForward(const std::string& intIface, |
| 262 | const std::string& extIface) override; |
Luke Huang | b670d16 | 2018-08-23 20:01:13 +0800 | [diff] [blame] | 263 | |
| 264 | private: |
| 265 | std::vector<uid_t> intsToUids(const std::vector<int32_t>& intUids); |
| 266 | Permission convertPermission(int32_t permission); |
Luke Huang | e64fa38 | 2018-07-24 16:38:22 +0800 | [diff] [blame] | 267 | static FirewallRule parseRule(int32_t firewallRule); |
| 268 | static ChildChain parseChildChain(int32_t childChain); |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | } // namespace net |
| 272 | } // namespace android |
| 273 | |
| 274 | #endif // _NETD_NATIVE_SERVICE_H_ |