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; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 46 | |
| 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 Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 60 | binder::Status networkRejectNonSecureVpn(bool enable, const std::vector<UidRange>& uids) |
| 61 | override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 62 | |
| 63 | // SOCK_DIAG commands. |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 64 | binder::Status socketDestroy(const std::vector<UidRange>& uids, |
| 65 | const std::vector<int32_t>& skipUids) override; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 66 | |
| 67 | // Resolver commands. |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 68 | binder::Status setResolverConfiguration(int32_t netId, const std::vector<std::string>& servers, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 69 | const std::vector<std::string>& domains, const std::vector<int32_t>& params, |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 70 | const std::string& tlsName, |
| 71 | const std::vector<std::string>& tlsServers, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 72 | const std::vector<std::string>& tlsFingerprints) override; |
Pierre Imai | beedec3 | 2016-04-13 06:44:51 +0900 | [diff] [blame] | 73 | 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 Kline | f48e4dd | 2016-07-18 04:02:07 +0900 | [diff] [blame] | 76 | |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 77 | binder::Status setIPv6AddrGenMode(const std::string& ifName, int32_t mode) override; |
| 78 | |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 79 | // 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 Kline | f48e4dd | 2016-07-18 04:02:07 +0900 | [diff] [blame] | 86 | // Tethering-related commands. |
| 87 | binder::Status tetherApplyDnsInterfaces(bool *ret) override; |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 88 | binder::Status tetherGetStats(android::os::PersistableBundle *ret) override; |
Erik Kline | 53c2088 | 2016-08-02 15:22:53 +0900 | [diff] [blame] | 89 | |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 90 | // Interface-related commands. |
Erik Kline | 53c2088 | 2016-08-02 15:22:53 +0900 | [diff] [blame] | 91 | 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 Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 95 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame^] | 96 | binder::Status getProcSysNet(int32_t ipversion, int32_t which, const std::string& ifname, |
| 97 | const std::string& parameter, std::string* value) override; |
| 98 | binder::Status setProcSysNet(int32_t ipversion, int32_t which, const std::string& ifname, |
| 99 | const std::string& parameter, const std::string& value) override; |
Robin Lee | 2cf5617 | 2016-09-13 18:55:42 +0900 | [diff] [blame] | 100 | |
| 101 | // Metrics reporting level set / get (internal use only). |
| 102 | binder::Status getMetricsReportingLevel(int *reportingLevel) override; |
| 103 | binder::Status setMetricsReportingLevel(const int reportingLevel) override; |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 104 | |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 105 | binder::Status ipSecSetEncapSocketOwner(const android::base::unique_fd& socket, int newUid); |
| 106 | |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 107 | binder::Status ipSecAllocateSpi( |
| 108 | int32_t transformId, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 109 | const std::string& localAddress, |
| 110 | const std::string& remoteAddress, |
| 111 | int32_t inSpi, |
| 112 | int32_t* outSpi); |
| 113 | |
| 114 | binder::Status ipSecAddSecurityAssociation( |
| 115 | int32_t transformId, |
| 116 | int32_t mode, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 117 | const std::string& sourceAddress, |
| 118 | const std::string& destinationAddress, |
Benedict Wong | 96abf48 | 2018-01-22 13:56:41 -0800 | [diff] [blame] | 119 | int32_t underlyingNetId, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 120 | int32_t spi, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 121 | int32_t markValue, |
| 122 | int32_t markMask, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 123 | const std::string& authAlgo, |
| 124 | const std::vector<uint8_t>& authKey, |
| 125 | int32_t authTruncBits, |
| 126 | const std::string& cryptAlgo, |
| 127 | const std::vector<uint8_t>& cryptKey, |
| 128 | int32_t cryptTruncBits, |
Benedict Wong | be65b43 | 2017-08-22 21:43:14 -0700 | [diff] [blame] | 129 | const std::string& aeadAlgo, |
| 130 | const std::vector<uint8_t>& aeadKey, |
| 131 | int32_t aeadIcvBits, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 132 | int32_t encapType, |
| 133 | int32_t encapLocalPort, |
ludi | ec83605 | 2017-05-20 14:17:05 -0700 | [diff] [blame] | 134 | int32_t encapRemotePort); |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 135 | |
| 136 | binder::Status ipSecDeleteSecurityAssociation( |
| 137 | int32_t transformId, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 138 | const std::string& sourceAddress, |
| 139 | const std::string& destinationAddress, |
Di Lu | 2ccb3e5 | 2018-01-03 16:19:20 -0800 | [diff] [blame] | 140 | int32_t spi, |
| 141 | int32_t markValue, |
| 142 | int32_t markMask); |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 143 | |
| 144 | binder::Status ipSecApplyTransportModeTransform( |
| 145 | const android::base::unique_fd& socket, |
| 146 | int32_t transformId, |
| 147 | int32_t direction, |
Nathan Harold | da54f12 | 2018-01-09 16:42:57 -0800 | [diff] [blame] | 148 | const std::string& sourceAddress, |
| 149 | const std::string& destinationAddress, |
Nathan Harold | 1a37153 | 2017-01-30 12:30:48 -0800 | [diff] [blame] | 150 | int32_t spi); |
| 151 | |
| 152 | binder::Status ipSecRemoveTransportModeTransform( |
| 153 | const android::base::unique_fd& socket); |
Chenbo Feng | 07d43fe | 2017-12-21 14:38:51 -0800 | [diff] [blame] | 154 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 155 | binder::Status ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 156 | int32_t direction, const std::string& tmplSrcAddress, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 157 | const std::string& tmplDstAddress, int32_t spi, |
| 158 | int32_t markValue, int32_t markMask); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 159 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 160 | binder::Status ipSecUpdateSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 161 | int32_t direction, const std::string& tmplSrcAddress, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 162 | const std::string& tmplDstAddress, int32_t spi, |
| 163 | int32_t markValue, int32_t markMask); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 164 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 165 | binder::Status ipSecDeleteSecurityPolicy(int32_t transformId, int32_t selAddrFamily, |
| 166 | int32_t direction, int32_t markValue, |
Benedict Wong | ad600cb | 2018-05-14 17:22:35 -0700 | [diff] [blame] | 167 | int32_t markMask); |
Benedict Wong | 84a8dca | 2018-01-19 12:12:17 -0800 | [diff] [blame] | 168 | |
Chenbo Feng | 07d43fe | 2017-12-21 14:38:51 -0800 | [diff] [blame] | 169 | binder::Status trafficCheckBpfStatsEnable(bool* ret) override; |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 170 | |
| 171 | binder::Status addVirtualTunnelInterface( |
| 172 | const std::string& deviceName, |
| 173 | const std::string& localAddress, |
| 174 | const std::string& remoteAddress, |
| 175 | int32_t iKey, |
| 176 | int32_t oKey); |
| 177 | |
| 178 | binder::Status updateVirtualTunnelInterface( |
| 179 | const std::string& deviceName, |
| 180 | const std::string& localAddress, |
| 181 | const std::string& remoteAddress, |
| 182 | int32_t iKey, |
| 183 | int32_t oKey); |
| 184 | |
| 185 | binder::Status removeVirtualTunnelInterface(const std::string& deviceName); |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 186 | |
| 187 | // Idletimer-related commands |
| 188 | binder::Status idletimerAddInterface(const std::string& ifName, int32_t timeout, |
| 189 | const std::string& classLabel) override; |
| 190 | binder::Status idletimerRemoveInterface(const std::string& ifName, int32_t timeout, |
| 191 | const std::string& classLabel) override; |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 192 | |
Luke Huang | a67dd56 | 2018-07-17 19:58:25 +0800 | [diff] [blame] | 193 | // Strict-related commands |
| 194 | binder::Status strictUidCleartextPenalty(int32_t uid, int32_t policyPenalty) override; |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 195 | |
| 196 | // Clatd-related commands |
| 197 | binder::Status clatdStart(const std::string& ifName) override; |
| 198 | binder::Status clatdStop(const std::string& ifName) override; |
Luke Huang | 457d470 | 2018-08-16 15:39:15 +0800 | [diff] [blame] | 199 | |
| 200 | // Ipfw-related commands |
| 201 | binder::Status ipfwdEnabled(bool* status) override; |
| 202 | binder::Status ipfwdEnableForwarding(const std::string& requester) override; |
| 203 | binder::Status ipfwdDisableForwarding(const std::string& requester) override; |
| 204 | binder::Status ipfwdAddInterfaceForward(const std::string& fromIface, |
| 205 | const std::string& toIface) override; |
| 206 | binder::Status ipfwdRemoveInterfaceForward(const std::string& fromIface, |
| 207 | const std::string& toIface) override; |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | } // namespace net |
| 211 | } // namespace android |
| 212 | |
| 213 | #endif // _NETD_NATIVE_SERVICE_H_ |