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