Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #include "FwmarkServer.h" |
| 18 | |
Hugo Benichi | 456c906 | 2017-01-04 12:19:16 +0900 | [diff] [blame] | 19 | #include <netinet/in.h> |
Lorenzo Colitti | 09175be | 2017-11-17 14:01:21 +0900 | [diff] [blame] | 20 | #include <selinux/selinux.h> |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 21 | #include <sys/socket.h> |
| 22 | #include <unistd.h> |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 23 | #include <utils/String16.h> |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 24 | |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 25 | #include <android-base/cmsg.h> |
| 26 | #include <android-base/logging.h> |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 27 | #include <binder/IServiceManager.h> |
Bernie Innocenti | 189eb50 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 28 | #include <netd_resolv/resolv.h> // NETID_UNSET |
| 29 | |
| 30 | #include "Fwmark.h" |
| 31 | #include "FwmarkCommand.h" |
| 32 | #include "NetdConstants.h" |
| 33 | #include "NetworkController.h" |
| 34 | #include "TrafficController.h" |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 35 | |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 36 | using android::String16; |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 37 | using android::base::ReceiveFileDescriptorVector; |
| 38 | using android::base::unique_fd; |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 39 | using android::net::metrics::INetdEventListener; |
| 40 | |
Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 41 | namespace android { |
| 42 | namespace net { |
| 43 | |
Lorenzo Colitti | 09175be | 2017-11-17 14:01:21 +0900 | [diff] [blame] | 44 | constexpr const char *SYSTEM_SERVER_CONTEXT = "u:r:system_server:s0"; |
| 45 | |
| 46 | bool isSystemServer(SocketClient* client) { |
| 47 | if (client->getUid() != AID_SYSTEM) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | char *context; |
| 52 | if (getpeercon(client->getSocket(), &context)) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // We can't use context_new and context_type_get as they're private to libselinux. So just do |
| 57 | // a string match instead. |
| 58 | bool ret = !strcmp(context, SYSTEM_SERVER_CONTEXT); |
| 59 | freecon(context); |
| 60 | |
| 61 | return ret; |
| 62 | } |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 63 | |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 64 | FwmarkServer::FwmarkServer(NetworkController* networkController, EventReporter* eventReporter, |
| 65 | TrafficController* trafficCtrl) |
| 66 | : SocketListener(SOCKET_NAME, true), |
| 67 | mNetworkController(networkController), |
| 68 | mEventReporter(eventReporter), |
| 69 | mTrafficCtrl(trafficCtrl) {} |
| 70 | |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 71 | bool FwmarkServer::onDataAvailable(SocketClient* client) { |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 72 | int socketFd = -1; |
| 73 | int error = processClient(client, &socketFd); |
| 74 | if (socketFd >= 0) { |
| 75 | close(socketFd); |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | // Always send a response even if there were connection errors or read errors, so that we don't |
| 79 | // inadvertently cause the client to hang (which always waits for a response). |
| 80 | client->sendData(&error, sizeof(error)); |
| 81 | |
| 82 | // Always close the client connection (by returning false). This prevents a DoS attack where |
| 83 | // the client issues multiple commands on the same connection, never reading the responses, |
| 84 | // causing its receive buffer to fill up, and thus causing our client->sendData() to block. |
| 85 | return false; |
| 86 | } |
| 87 | |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 88 | int FwmarkServer::processClient(SocketClient* client, int* socketFd) { |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 89 | FwmarkCommand command; |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 90 | FwmarkConnectInfo connectInfo; |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 91 | |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 92 | char buf[sizeof(command) + sizeof(connectInfo)]; |
| 93 | std::vector<unique_fd> received_fds; |
| 94 | ssize_t messageLength = |
| 95 | ReceiveFileDescriptorVector(client->getSocket(), buf, sizeof(buf), 1, &received_fds); |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 96 | |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 97 | if (messageLength < 0) { |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 98 | return -errno; |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 99 | } else if (messageLength == 0) { |
| 100 | return -ESHUTDOWN; |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 103 | memcpy(&command, buf, sizeof(command)); |
| 104 | memcpy(&connectInfo, buf + sizeof(command), sizeof(connectInfo)); |
| 105 | |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 106 | if (!((command.cmdId != FwmarkCommand::ON_CONNECT_COMPLETE && messageLength == sizeof(command)) |
| 107 | || (command.cmdId == FwmarkCommand::ON_CONNECT_COMPLETE |
| 108 | && messageLength == sizeof(command) + sizeof(connectInfo)))) { |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 109 | return -EBADMSG; |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Paul Jensen | d1df597 | 2015-05-06 07:29:56 -0400 | [diff] [blame] | 112 | Permission permission = mNetworkController->getPermissionForUser(client->getUid()); |
| 113 | |
| 114 | if (command.cmdId == FwmarkCommand::QUERY_USER_ACCESS) { |
| 115 | if ((permission & PERMISSION_SYSTEM) != PERMISSION_SYSTEM) { |
| 116 | return -EPERM; |
| 117 | } |
| 118 | return mNetworkController->checkUserNetworkAccess(command.uid, command.netId); |
| 119 | } |
| 120 | |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 121 | if (command.cmdId == FwmarkCommand::SET_COUNTERSET) { |
Chenbo Feng | b4a4fa1 | 2019-01-09 17:20:45 -0800 | [diff] [blame] | 122 | return mTrafficCtrl->setCounterSet(command.trafficCtrlInfo, command.uid, client->getUid()); |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | if (command.cmdId == FwmarkCommand::DELETE_TAGDATA) { |
Chenbo Feng | b4a4fa1 | 2019-01-09 17:20:45 -0800 | [diff] [blame] | 126 | return mTrafficCtrl->deleteTagData(command.trafficCtrlInfo, command.uid, client->getUid()); |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 129 | if (received_fds.size() != 1) { |
| 130 | LOG(ERROR) << "FwmarkServer received " << received_fds.size() << " fds from client?"; |
| 131 | return -EBADF; |
| 132 | } else if (received_fds[0] < 0) { |
| 133 | LOG(ERROR) << "FwmarkServer received fd -1 from ReceiveFileDescriptorVector?"; |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 134 | return -EBADF; |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Josh Gao | ba76bd6 | 2020-01-06 17:22:41 -0800 | [diff] [blame^] | 137 | *socketFd = received_fds[0].release(); |
| 138 | |
Remi NGUYEN VAN | eabc5da | 2018-04-24 18:54:58 +0900 | [diff] [blame] | 139 | int family; |
| 140 | socklen_t familyLen = sizeof(family); |
| 141 | if (getsockopt(*socketFd, SOL_SOCKET, SO_DOMAIN, &family, &familyLen) == -1) { |
| 142 | return -errno; |
| 143 | } |
| 144 | if (!FwmarkCommand::isSupportedFamily(family)) { |
| 145 | return -EAFNOSUPPORT; |
| 146 | } |
| 147 | |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 148 | Fwmark fwmark; |
Sreeram Ramachandran | 5ff58d4 | 2014-05-14 09:57:31 -0700 | [diff] [blame] | 149 | socklen_t fwmarkLen = sizeof(fwmark.intValue); |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 150 | if (getsockopt(*socketFd, SOL_SOCKET, SO_MARK, &fwmark.intValue, &fwmarkLen) == -1) { |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 151 | return -errno; |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 154 | switch (command.cmdId) { |
| 155 | case FwmarkCommand::ON_ACCEPT: { |
Sreeram Ramachandran | 070b2d2 | 2014-07-11 17:06:12 -0700 | [diff] [blame] | 156 | // Called after a socket accept(). The kernel would've marked the NetId and necessary |
Sreeram Ramachandran | a675b00 | 2014-07-05 11:00:55 -0700 | [diff] [blame] | 157 | // permissions bits, so we just add the rest of the user's permissions here. |
| 158 | permission = static_cast<Permission>(permission | fwmark.permission); |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 159 | break; |
| 160 | } |
| 161 | |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 162 | case FwmarkCommand::ON_CONNECT: { |
Sreeram Ramachandran | 1011b49 | 2014-07-24 19:04:32 -0700 | [diff] [blame] | 163 | // Called before a socket connect() happens. Set an appropriate NetId into the fwmark so |
| 164 | // that the socket routes consistently over that network. Do this even if the socket |
| 165 | // already has a NetId, so that calling connect() multiple times still works. |
Sreeram Ramachandran | 070b2d2 | 2014-07-11 17:06:12 -0700 | [diff] [blame] | 166 | // |
Sreeram Ramachandran | 1011b49 | 2014-07-24 19:04:32 -0700 | [diff] [blame] | 167 | // But if the explicit bit was set, the existing NetId was explicitly preferred (and not |
| 168 | // a case of connect() being called multiple times). Don't reset the NetId in that case. |
| 169 | // |
| 170 | // An "appropriate" NetId is the NetId of a bypassable VPN that applies to the user, or |
| 171 | // failing that, the default network. We'll never set the NetId of a secure VPN here. |
| 172 | // See the comments in the implementation of getNetworkForConnect() for more details. |
| 173 | // |
| 174 | // If the protect bit is set, this could be either a system proxy (e.g.: the dns proxy |
| 175 | // or the download manager) acting on behalf of another user, or a VPN provider. If it's |
| 176 | // a proxy, we shouldn't reset the NetId. If it's a VPN provider, we should set the |
| 177 | // default network's NetId. |
| 178 | // |
| 179 | // There's no easy way to tell the difference between a proxy and a VPN app. We can't |
| 180 | // use PERMISSION_SYSTEM to identify the proxy because a VPN app may also have those |
| 181 | // permissions. So we use the following heuristic: |
| 182 | // |
| 183 | // If it's a proxy, but the existing NetId is not a VPN, that means the user (that the |
| 184 | // proxy is acting on behalf of) is not subject to a VPN, so the proxy must have picked |
| 185 | // the default network's NetId. So, it's okay to replace that with the current default |
| 186 | // network's NetId (which in all likelihood is the same). |
| 187 | // |
| 188 | // Conversely, if it's a VPN provider, the existing NetId cannot be a VPN. The only time |
| 189 | // we set a VPN's NetId into a socket without setting the explicit bit is here, in |
| 190 | // ON_CONNECT, but we won't do that if the socket has the protect bit set. If the VPN |
| 191 | // provider connect()ed (and got the VPN NetId set) and then called protect(), we |
| 192 | // would've unset the NetId in PROTECT_FROM_VPN below. |
| 193 | // |
| 194 | // So, overall (when the explicit bit is not set but the protect bit is set), if the |
| 195 | // existing NetId is a VPN, don't reset it. Else, set the default network's NetId. |
| 196 | if (!fwmark.explicitlySelected) { |
| 197 | if (!fwmark.protectedFromVpn) { |
| 198 | fwmark.netId = mNetworkController->getNetworkForConnect(client->getUid()); |
| 199 | } else if (!mNetworkController->isVirtualNetwork(fwmark.netId)) { |
| 200 | fwmark.netId = mNetworkController->getDefaultNetwork(); |
| 201 | } |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 202 | } |
| 203 | break; |
| 204 | } |
| 205 | |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 206 | case FwmarkCommand::ON_CONNECT_COMPLETE: { |
| 207 | // Called after a socket connect() completes. |
| 208 | // This reports connect event including netId, destination IP address, destination port, |
Hugo Benichi | 7dfaa78 | 2016-10-31 15:07:23 +0900 | [diff] [blame] | 209 | // uid, connect latency, and connect errno if any. |
Hugo Benichi | 456c906 | 2017-01-04 12:19:16 +0900 | [diff] [blame] | 210 | |
| 211 | // Skip reporting if connect() happened on a UDP socket. |
| 212 | int socketProto; |
| 213 | socklen_t intSize = sizeof(socketProto); |
| 214 | const int ret = getsockopt(*socketFd, SOL_SOCKET, SO_PROTOCOL, &socketProto, &intSize); |
| 215 | if ((ret != 0) || (socketProto == IPPROTO_UDP)) { |
| 216 | break; |
| 217 | } |
| 218 | |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 219 | android::sp<android::net::metrics::INetdEventListener> netdEventListener = |
| 220 | mEventReporter->getNetdEventListener(); |
| 221 | |
| 222 | if (netdEventListener != nullptr) { |
| 223 | char addrstr[INET6_ADDRSTRLEN]; |
| 224 | char portstr[sizeof("65536")]; |
| 225 | const int ret = getnameinfo((sockaddr*) &connectInfo.addr, sizeof(connectInfo.addr), |
| 226 | addrstr, sizeof(addrstr), portstr, sizeof(portstr), |
| 227 | NI_NUMERICHOST | NI_NUMERICSERV); |
| 228 | |
Hugo Benichi | 7dfaa78 | 2016-10-31 15:07:23 +0900 | [diff] [blame] | 229 | netdEventListener->onConnectEvent(fwmark.netId, connectInfo.error, |
| 230 | connectInfo.latencyMs, |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 231 | (ret == 0) ? String16(addrstr) : String16(""), |
Yi Kong | bdfd57e | 2018-07-25 13:26:10 -0700 | [diff] [blame] | 232 | (ret == 0) ? strtoul(portstr, nullptr, 10) : 0, client->getUid()); |
Michal Karpinski | 7d37453 | 2016-10-06 19:33:55 +0100 | [diff] [blame] | 233 | } |
| 234 | break; |
| 235 | } |
| 236 | |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 237 | case FwmarkCommand::SELECT_NETWORK: { |
Sreeram Ramachandran | ec00884 | 2014-05-21 14:01:16 -0700 | [diff] [blame] | 238 | fwmark.netId = command.netId; |
| 239 | if (command.netId == NETID_UNSET) { |
| 240 | fwmark.explicitlySelected = false; |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 241 | fwmark.protectedFromVpn = false; |
| 242 | permission = PERMISSION_NONE; |
Lorenzo Colitti | a1067c8 | 2014-10-02 22:47:41 +0900 | [diff] [blame] | 243 | } else { |
| 244 | if (int ret = mNetworkController->checkUserNetworkAccess(client->getUid(), |
| 245 | command.netId)) { |
| 246 | return ret; |
| 247 | } |
Sreeram Ramachandran | ec00884 | 2014-05-21 14:01:16 -0700 | [diff] [blame] | 248 | fwmark.explicitlySelected = true; |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 249 | fwmark.protectedFromVpn = mNetworkController->canProtect(client->getUid()); |
Sreeram Ramachandran | ec00884 | 2014-05-21 14:01:16 -0700 | [diff] [blame] | 250 | } |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | |
Sreeram Ramachandran | efbe05d | 2014-05-21 11:41:39 -0700 | [diff] [blame] | 254 | case FwmarkCommand::PROTECT_FROM_VPN: { |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 255 | if (!mNetworkController->canProtect(client->getUid())) { |
| 256 | return -EPERM; |
| 257 | } |
Sreeram Ramachandran | 1011b49 | 2014-07-24 19:04:32 -0700 | [diff] [blame] | 258 | // If a bypassable VPN's provider app calls connect() and then protect(), it will end up |
| 259 | // with a socket that looks like that of a system proxy but is not (see comments for |
| 260 | // ON_CONNECT above). So, reset the NetId. |
| 261 | // |
| 262 | // In any case, it's appropriate that if the socket has an implicit VPN NetId mark, the |
| 263 | // PROTECT_FROM_VPN command should unset it. |
| 264 | if (!fwmark.explicitlySelected && mNetworkController->isVirtualNetwork(fwmark.netId)) { |
| 265 | fwmark.netId = mNetworkController->getDefaultNetwork(); |
| 266 | } |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 267 | fwmark.protectedFromVpn = true; |
| 268 | permission = static_cast<Permission>(permission | fwmark.permission); |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 269 | break; |
| 270 | } |
| 271 | |
Sreeram Ramachandran | a69d947 | 2014-07-11 16:27:02 -0700 | [diff] [blame] | 272 | case FwmarkCommand::SELECT_FOR_USER: { |
| 273 | if ((permission & PERMISSION_SYSTEM) != PERMISSION_SYSTEM) { |
| 274 | return -EPERM; |
| 275 | } |
Sreeram Ramachandran | 1011b49 | 2014-07-24 19:04:32 -0700 | [diff] [blame] | 276 | fwmark.netId = mNetworkController->getNetworkForUser(command.uid); |
Sreeram Ramachandran | a69d947 | 2014-07-11 16:27:02 -0700 | [diff] [blame] | 277 | fwmark.protectedFromVpn = true; |
| 278 | break; |
| 279 | } |
| 280 | |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 281 | case FwmarkCommand::TAG_SOCKET: { |
| 282 | // If the UID is -1, tag as the caller's UID: |
| 283 | // - TrafficStats and NetworkManagementSocketTagger use -1 to indicate "use the |
| 284 | // caller's UID". |
| 285 | // - xt_qtaguid will see -1 on the command line, fail to parse it as a uint32_t, and |
| 286 | // fall back to current_fsuid(). |
| 287 | if (static_cast<int>(command.uid) == -1) { |
| 288 | command.uid = client->getUid(); |
| 289 | } |
Chenbo Feng | b4a4fa1 | 2019-01-09 17:20:45 -0800 | [diff] [blame] | 290 | return mTrafficCtrl->tagSocket(*socketFd, command.trafficCtrlInfo, command.uid, |
| 291 | client->getUid()); |
Chenbo Feng | 9944ba8 | 2017-10-10 17:33:20 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | case FwmarkCommand::UNTAG_SOCKET: { |
| 295 | // Any process can untag a socket it has an fd for. |
| 296 | return mTrafficCtrl->untagSocket(*socketFd); |
| 297 | } |
| 298 | |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 299 | default: { |
| 300 | // unknown command |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 301 | return -EPROTO; |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Sreeram Ramachandran | a675b00 | 2014-07-05 11:00:55 -0700 | [diff] [blame] | 305 | fwmark.permission = permission; |
| 306 | |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 307 | if (setsockopt(*socketFd, SOL_SOCKET, SO_MARK, &fwmark.intValue, |
| 308 | sizeof(fwmark.intValue)) == -1) { |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 309 | return -errno; |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Sreeram Ramachandran | 3a069e6 | 2014-06-22 11:02:57 -0700 | [diff] [blame] | 312 | return 0; |
Sreeram Ramachandran | 030b36e | 2014-05-11 21:04:03 -0700 | [diff] [blame] | 313 | } |
Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 314 | |
| 315 | } // namespace net |
| 316 | } // namespace android |