blob: 04af0aee267cc1d0c09006f2692f496c3538e1f9 [file] [log] [blame]
San Mehat9d10b342010-01-18 09:51:02 -08001/*
2 * Copyright (C) 2008 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
San Mehat9d10b342010-01-18 09:51:02 -080017#include <errno.h>
San Mehat18737842010-01-21 09:22:43 -080018#include <fcntl.h>
Lorenzo Colittia93126d2017-08-24 13:28:19 +090019#include <inttypes.h>
Lorenzo Colittic2841282015-11-25 22:13:57 +090020#include <netdb.h>
Luke Huang40962442019-02-26 11:46:10 +080021#include <spawn.h>
Olivier Baillyff2c0d82010-11-17 11:45:07 -080022#include <string.h>
San Mehat18737842010-01-21 09:22:43 -080023
San Mehat9d10b342010-01-18 09:51:02 -080024#include <sys/socket.h>
25#include <sys/stat.h>
San Mehat18737842010-01-21 09:22:43 -080026#include <sys/types.h>
27#include <sys/wait.h>
28
San Mehat9d10b342010-01-18 09:51:02 -080029#include <netinet/in.h>
30#include <arpa/inet.h>
31
Erik Kline5f0358b2018-02-16 15:08:09 +090032#include <array>
33#include <cstdlib>
waynema71a0b592018-11-21 13:31:34 +080034#include <regex>
Erik Kline5f0358b2018-02-16 15:08:09 +090035#include <string>
36#include <vector>
37
San Mehat9d10b342010-01-18 09:51:02 -080038#define LOG_TAG "TetherController"
Maciej Żenczykowski2cffd942019-05-05 13:40:35 -070039#include <android-base/scopeguard.h>
Lorenzo Colittia93126d2017-08-24 13:28:19 +090040#include <android-base/stringprintf.h>
George Burgess IVe3dc1312019-02-28 11:27:04 -080041#include <android-base/strings.h>
42#include <android-base/unique_fd.h>
Kazuhiro Ondo6b858eb2011-06-24 20:31:03 -050043#include <cutils/properties.h>
Logan Chien3f461482018-04-23 14:31:32 +080044#include <log/log.h>
Hungming Chen1da90082020-02-14 20:24:16 +080045#include <net/if.h>
Lorenzo Colitti52db3912020-02-17 23:59:45 +090046#include <netdutils/DumpWriter.h>
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +090047#include <netdutils/StatusOr.h>
San Mehat9d10b342010-01-18 09:51:02 -080048
Erik Klineb31fd692018-06-06 20:50:11 +090049#include "Controllers.h"
Lorenzo Colitti667c4772014-08-26 14:13:07 -070050#include "Fwmark.h"
Erik Kline1d065ba2016-06-08 13:24:45 +090051#include "InterfaceController.h"
Mike Yuf0e019f2019-03-13 14:43:39 +080052#include "NetdConstants.h"
Lorenzo Colittie20a5262017-05-09 18:30:44 +090053#include "NetworkController.h"
Hungming Chen1da90082020-02-14 20:24:16 +080054#include "OffloadUtils.h"
Mike Yuf0e019f2019-03-13 14:43:39 +080055#include "Permission.h"
San Mehat9d10b342010-01-18 09:51:02 -080056#include "TetherController.h"
57
Lorenzo Colittif0e051c2020-04-06 09:19:57 +000058#include "android/net/TetherOffloadRuleParcel.h"
59
Bernie Innocenti4debf3b2018-09-12 13:54:50 +090060namespace android {
61namespace net {
62
Lorenzo Colittie801d3c2020-02-18 00:00:35 +090063using android::base::Error;
Lorenzo Colittia93126d2017-08-24 13:28:19 +090064using android::base::Join;
George Burgess IVe3dc1312019-02-28 11:27:04 -080065using android::base::Pipe;
Lorenzo Colittie801d3c2020-02-18 00:00:35 +090066using android::base::Result;
67using android::base::StringAppendF;
Erik Klineb31fd692018-06-06 20:50:11 +090068using android::base::StringPrintf;
George Burgess IVe3dc1312019-02-28 11:27:04 -080069using android::base::unique_fd;
Lorenzo Colittif0e051c2020-04-06 09:19:57 +000070using android::net::TetherOffloadRuleParcel;
Lorenzo Colitti52db3912020-02-17 23:59:45 +090071using android::netdutils::DumpWriter;
72using android::netdutils::ScopedIndent;
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +090073using android::netdutils::statusFromErrno;
Erik Klineb31fd692018-06-06 20:50:11 +090074using android::netdutils::StatusOr;
Lorenzo Colittia93126d2017-08-24 13:28:19 +090075
Lorenzo Colitti799625c2015-02-25 12:52:00 +090076namespace {
77
Erik Kline1d065ba2016-06-08 13:24:45 +090078const char BP_TOOLS_MODE[] = "bp-tools";
79const char IPV4_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv4/ip_forward";
80const char IPV6_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv6/conf/all/forwarding";
81const char SEPARATOR[] = "|";
Erik Kline93f9b222017-10-22 21:24:58 +090082constexpr const char kTcpBeLiberal[] = "/proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal";
Hungming Chen68dade32020-02-20 13:50:56 +080083
Erik Kline5f0358b2018-02-16 15:08:09 +090084// Chosen to match AID_DNS_TETHER, as made "friendly" by fs_config_generator.py.
85constexpr const char kDnsmasqUsername[] = "dns_tether";
86
Lorenzo Colitti799625c2015-02-25 12:52:00 +090087bool writeToFile(const char* filename, const char* value) {
Nick Kralevichb95c60c2016-11-19 09:09:16 -080088 int fd = open(filename, O_WRONLY | O_CLOEXEC);
Nicolas Geoffrayafd40372015-03-16 11:58:06 +000089 if (fd < 0) {
90 ALOGE("Failed to open %s: %s", filename, strerror(errno));
91 return false;
92 }
93
94 const ssize_t len = strlen(value);
95 if (write(fd, value, len) != len) {
96 ALOGE("Failed to write %s to %s: %s", value, filename, strerror(errno));
97 close(fd);
98 return false;
99 }
100 close(fd);
101 return true;
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900102}
103
Erik Kline93f9b222017-10-22 21:24:58 +0900104// TODO: Consider altering TCP and UDP timeouts as well.
105void configureForTethering(bool enabled) {
106 writeToFile(kTcpBeLiberal, enabled ? "1" : "0");
107}
108
Erik Kline1d065ba2016-06-08 13:24:45 +0900109bool configureForIPv6Router(const char *interface) {
110 return (InterfaceController::setEnableIPv6(interface, 0) == 0)
111 && (InterfaceController::setAcceptIPv6Ra(interface, 0) == 0)
Erik Kline6cddf512016-08-09 15:28:42 +0900112 && (InterfaceController::setAcceptIPv6Dad(interface, 0) == 0)
113 && (InterfaceController::setIPv6DadTransmits(interface, "0") == 0)
Erik Kline1d065ba2016-06-08 13:24:45 +0900114 && (InterfaceController::setEnableIPv6(interface, 1) == 0);
115}
116
117void configureForIPv6Client(const char *interface) {
118 InterfaceController::setAcceptIPv6Ra(interface, 1);
Erik Kline6cddf512016-08-09 15:28:42 +0900119 InterfaceController::setAcceptIPv6Dad(interface, 1);
120 InterfaceController::setIPv6DadTransmits(interface, "1");
Erik Kline1d065ba2016-06-08 13:24:45 +0900121 InterfaceController::setEnableIPv6(interface, 0);
122}
123
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900124bool inBpToolsMode() {
125 // In BP tools mode, do not disable IP forwarding
126 char bootmode[PROPERTY_VALUE_MAX] = {0};
127 property_get("ro.bootmode", bootmode, "unknown");
128 return !strcmp(BP_TOOLS_MODE, bootmode);
129}
130
131} // namespace
132
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900133auto TetherController::iptablesRestoreFunction = execIptablesRestoreWithOutput;
134
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900135const std::string GET_TETHER_STATS_COMMAND = StringPrintf(
136 "*filter\n"
137 "-nvx -L %s\n"
138 "COMMIT\n", android::net::TetherController::LOCAL_TETHER_COUNTERS_CHAIN);
139
Erik Kline15079dd2018-05-18 23:10:56 +0900140int TetherController::DnsmasqState::sendCmd(int daemonFd, const std::string& cmd) {
141 if (cmd.empty()) return 0;
142
Erik Klineb31fd692018-06-06 20:50:11 +0900143 gLog.log("Sending update msg to dnsmasq [%s]", cmd.c_str());
Erik Kline15079dd2018-05-18 23:10:56 +0900144 // Send the trailing \0 as well.
145 if (write(daemonFd, cmd.c_str(), cmd.size() + 1) < 0) {
Erik Klineb31fd692018-06-06 20:50:11 +0900146 gLog.error("Failed to send update command to dnsmasq (%s)", strerror(errno));
Erik Kline15079dd2018-05-18 23:10:56 +0900147 errno = EREMOTEIO;
148 return -1;
149 }
150 return 0;
151}
152
153void TetherController::DnsmasqState::clear() {
154 update_ifaces_cmd.clear();
155 update_dns_cmd.clear();
156}
157
158int TetherController::DnsmasqState::sendAllState(int daemonFd) const {
159 return sendCmd(daemonFd, update_ifaces_cmd) | sendCmd(daemonFd, update_dns_cmd);
160}
161
Sreeram Ramachandran87475a12014-07-15 16:20:28 -0700162TetherController::TetherController() {
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900163 if (inBpToolsMode()) {
164 enableForwarding(BP_TOOLS_MODE);
165 } else {
166 setIpFwdEnabled();
167 }
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800168 maybeInitMaps();
San Mehat9d10b342010-01-18 09:51:02 -0800169}
170
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900171bool TetherController::setIpFwdEnabled() {
172 bool success = true;
Hugo Benichic4b3a0c2018-05-22 08:48:40 +0900173 bool disable = mForwardingRequests.empty();
174 const char* value = disable ? "0" : "1";
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900175 ALOGD("Setting IP forward enable = %s", value);
176 success &= writeToFile(IPV4_FORWARDING_PROC_FILE, value);
177 success &= writeToFile(IPV6_FORWARDING_PROC_FILE, value);
Hugo Benichic4b3a0c2018-05-22 08:48:40 +0900178 if (disable) {
179 // Turning off the forwarding sysconf in the kernel has the side effect
180 // of turning on ICMP redirect, which is a security hazard.
181 // Turn ICMP redirect back off immediately.
182 int rv = InterfaceController::disableIcmpRedirects();
183 success &= (rv == 0);
184 }
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900185 return success;
San Mehat9d10b342010-01-18 09:51:02 -0800186}
187
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900188bool TetherController::enableForwarding(const char* requester) {
189 // Don't return an error if this requester already requested forwarding. Only return errors for
190 // things that the caller caller needs to care about, such as "couldn't write to the file to
191 // enable forwarding".
192 mForwardingRequests.insert(requester);
193 return setIpFwdEnabled();
194}
San Mehat9d10b342010-01-18 09:51:02 -0800195
Lorenzo Colitti799625c2015-02-25 12:52:00 +0900196bool TetherController::disableForwarding(const char* requester) {
197 mForwardingRequests.erase(requester);
198 return setIpFwdEnabled();
199}
San Mehat9d10b342010-01-18 09:51:02 -0800200
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800201void TetherController::maybeInitMaps() {
202 if (!bpf::isBpfSupported()) return;
203
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800204 // Open BPF maps, ignoring errors because the device might not support BPF offload.
205 int fd = getTetherIngressMapFd();
Maciej Żenczykowski109ac532020-02-19 10:36:44 -0800206 if (fd >= 0) {
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800207 mBpfIngressMap.reset(fd);
Maciej Żenczykowski109ac532020-02-19 10:36:44 -0800208 mBpfIngressMap.clear();
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800209 }
210 fd = getTetherStatsMapFd();
Maciej Żenczykowski109ac532020-02-19 10:36:44 -0800211 if (fd >= 0) {
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800212 mBpfStatsMap.reset(fd);
Maciej Żenczykowski109ac532020-02-19 10:36:44 -0800213 mBpfStatsMap.clear();
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800214 }
Maciej Żenczykowskid25a7342020-05-04 18:18:38 -0700215 fd = getTetherLimitMapFd();
216 if (fd >= 0) {
217 mBpfLimitMap.reset(fd);
218 mBpfLimitMap.clear();
219 }
Hungming Chenc2e95fb2020-02-19 17:41:30 +0800220}
221
Luke Huang728cf4c2019-03-14 19:43:02 +0800222const std::set<std::string>& TetherController::getIpfwdRequesterList() const {
223 return mForwardingRequests;
San Mehat9d10b342010-01-18 09:51:02 -0800224}
225
Luke Huang91bd3e12019-08-20 11:33:52 +0800226int TetherController::startTethering(bool usingLegacyDnsProxy, int num_addrs, char** dhcp_ranges) {
227 if (!usingLegacyDnsProxy && num_addrs == 0) {
228 // Both DHCP and DnsProxy are disabled, we don't need to start dnsmasq
229 configureForTethering(true);
230 mIsTetheringStarted = true;
231 return 0;
232 }
233
234 if (mIsTetheringStarted) {
Steve Block5ea0c052012-01-06 19:18:11 +0000235 ALOGE("Tethering already started");
San Mehat9d10b342010-01-18 09:51:02 -0800236 errno = EBUSY;
Luke Huangb5733d72018-08-21 17:17:19 +0800237 return -errno;
San Mehat9d10b342010-01-18 09:51:02 -0800238 }
239
Steve Block7b984e32011-12-20 16:22:42 +0000240 ALOGD("Starting tethering services");
San Mehat9d10b342010-01-18 09:51:02 -0800241
George Burgess IVe3dc1312019-02-28 11:27:04 -0800242 unique_fd pipeRead, pipeWrite;
243 if (!Pipe(&pipeRead, &pipeWrite, O_CLOEXEC)) {
Luke Huangb5733d72018-08-21 17:17:19 +0800244 int res = errno;
Luke Huang94c43a12019-02-14 19:51:38 +0800245 ALOGE("pipe2() failed (%s)", strerror(errno));
Luke Huangb5733d72018-08-21 17:17:19 +0800246 return -res;
San Mehat9d10b342010-01-18 09:51:02 -0800247 }
248
Luke Huang94c43a12019-02-14 19:51:38 +0800249 // Set parameters
250 Fwmark fwmark;
251 fwmark.netId = NetworkController::LOCAL_NET_ID;
252 fwmark.explicitlySelected = true;
253 fwmark.protectedFromVpn = true;
254 fwmark.permission = PERMISSION_SYSTEM;
255 char markStr[UINT32_HEX_STRLEN];
256 snprintf(markStr, sizeof(markStr), "0x%x", fwmark.intValue);
San Mehat9d10b342010-01-18 09:51:02 -0800257
Luke Huang94c43a12019-02-14 19:51:38 +0800258 std::vector<const std::string> argVector = {
Erik Kline5f0358b2018-02-16 15:08:09 +0900259 "/system/bin/dnsmasq",
260 "--keep-in-foreground",
261 "--no-resolv",
262 "--no-poll",
263 "--dhcp-authoritative",
264 // TODO: pipe through metered status from ConnService
265 "--dhcp-option-force=43,ANDROID_METERED",
266 "--pid-file",
Luke Huang94c43a12019-02-14 19:51:38 +0800267 "--listen-mark",
268 markStr,
269 "--user",
270 kDnsmasqUsername,
271 };
San Mehat9d10b342010-01-18 09:51:02 -0800272
Luke Huang91bd3e12019-08-20 11:33:52 +0800273 if (!usingLegacyDnsProxy) {
274 argVector.push_back("--port=0");
275 }
276
277 // DHCP server will be disabled if num_addrs == 0 and no --dhcp-range is passed.
Luke Huang94c43a12019-02-14 19:51:38 +0800278 for (int addrIndex = 0; addrIndex < num_addrs; addrIndex += 2) {
279 argVector.push_back(StringPrintf("--dhcp-range=%s,%s,1h", dhcp_ranges[addrIndex],
280 dhcp_ranges[addrIndex + 1]));
San Mehat9d10b342010-01-18 09:51:02 -0800281 }
282
George Burgess IVe3dc1312019-02-28 11:27:04 -0800283 std::vector<char*> args(argVector.size() + 1);
Luke Huang94c43a12019-02-14 19:51:38 +0800284 for (unsigned i = 0; i < argVector.size(); i++) {
285 args[i] = (char*)argVector[i].c_str();
286 }
287
288 /*
289 * TODO: Create a monitoring thread to handle and restart
290 * the daemon if it exits prematurely
291 */
Luke Huang40962442019-02-26 11:46:10 +0800292
293 // Note that don't modify any memory between vfork and execv.
294 // Changing state of file descriptors would be fine. See posix_spawn_file_actions_add*
295 // dup2 creates fd without CLOEXEC, dnsmasq will receive commands through the
296 // duplicated fd.
297 posix_spawn_file_actions_t fa;
Maciej Żenczykowski2cffd942019-05-05 13:40:35 -0700298 int res = posix_spawn_file_actions_init(&fa);
Luke Huang40962442019-02-26 11:46:10 +0800299 if (res) {
Maciej Żenczykowski2cffd942019-05-05 13:40:35 -0700300 ALOGE("posix_spawn_file_actions_init failed (%s)", strerror(res));
301 return -res;
302 }
303 const android::base::ScopeGuard faGuard = [&] { posix_spawn_file_actions_destroy(&fa); };
304 res = posix_spawn_file_actions_adddup2(&fa, pipeRead.get(), STDIN_FILENO);
305 if (res) {
306 ALOGE("posix_spawn_file_actions_adddup2 failed (%s)", strerror(res));
Luke Huang94c43a12019-02-14 19:51:38 +0800307 return -res;
308 }
309
Luke Huang40962442019-02-26 11:46:10 +0800310 posix_spawnattr_t attr;
Maciej Żenczykowski2cffd942019-05-05 13:40:35 -0700311 res = posix_spawnattr_init(&attr);
Luke Huang40962442019-02-26 11:46:10 +0800312 if (res) {
Maciej Żenczykowski2cffd942019-05-05 13:40:35 -0700313 ALOGE("posix_spawnattr_init failed (%s)", strerror(res));
314 return -res;
315 }
316 const android::base::ScopeGuard attrGuard = [&] { posix_spawnattr_destroy(&attr); };
317 res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_USEVFORK);
318 if (res) {
319 ALOGE("posix_spawnattr_setflags failed (%s)", strerror(res));
Luke Huang40962442019-02-26 11:46:10 +0800320 return -res;
321 }
322
323 pid_t pid;
George Burgess IVe3dc1312019-02-28 11:27:04 -0800324 res = posix_spawn(&pid, args[0], &fa, &attr, &args[0], nullptr);
Luke Huang40962442019-02-26 11:46:10 +0800325 if (res) {
326 ALOGE("posix_spawn failed (%s)", strerror(res));
Luke Huang40962442019-02-26 11:46:10 +0800327 return -res;
328 }
Luke Huang94c43a12019-02-14 19:51:38 +0800329 mDaemonPid = pid;
George Burgess IVe3dc1312019-02-28 11:27:04 -0800330 mDaemonFd = pipeWrite.release();
Luke Huang94c43a12019-02-14 19:51:38 +0800331 configureForTethering(true);
Luke Huang91bd3e12019-08-20 11:33:52 +0800332 mIsTetheringStarted = true;
Luke Huang94c43a12019-02-14 19:51:38 +0800333 applyDnsInterfaces();
334 ALOGD("Tethering services running");
335
San Mehat9d10b342010-01-18 09:51:02 -0800336 return 0;
337}
338
Luke Huangb5733d72018-08-21 17:17:19 +0800339std::vector<char*> TetherController::toCstrVec(const std::vector<std::string>& addrs) {
340 std::vector<char*> addrsCstrVec{};
341 addrsCstrVec.reserve(addrs.size());
342 for (const auto& addr : addrs) {
343 addrsCstrVec.push_back(const_cast<char*>(addr.data()));
344 }
345 return addrsCstrVec;
346}
347
Luke Huang91bd3e12019-08-20 11:33:52 +0800348int TetherController::startTethering(bool usingLegacyDnsProxy,
349 const std::vector<std::string>& dhcpRanges) {
Luke Huangb5733d72018-08-21 17:17:19 +0800350 struct in_addr v4_addr;
351 for (const auto& dhcpRange : dhcpRanges) {
352 if (!inet_aton(dhcpRange.c_str(), &v4_addr)) {
353 return -EINVAL;
354 }
355 }
356 auto dhcp_ranges = toCstrVec(dhcpRanges);
Luke Huang91bd3e12019-08-20 11:33:52 +0800357 return startTethering(usingLegacyDnsProxy, dhcp_ranges.size(), dhcp_ranges.data());
Luke Huangb5733d72018-08-21 17:17:19 +0800358}
359
San Mehat9d10b342010-01-18 09:51:02 -0800360int TetherController::stopTethering() {
Erik Kline93f9b222017-10-22 21:24:58 +0900361 configureForTethering(false);
San Mehat9d10b342010-01-18 09:51:02 -0800362
Luke Huang91bd3e12019-08-20 11:33:52 +0800363 if (!mIsTetheringStarted) {
Steve Block5ea0c052012-01-06 19:18:11 +0000364 ALOGE("Tethering already stopped");
San Mehat9d10b342010-01-18 09:51:02 -0800365 return 0;
366 }
367
Luke Huang91bd3e12019-08-20 11:33:52 +0800368 mIsTetheringStarted = false;
369 // dnsmasq is not started
370 if (mDaemonPid == 0) {
371 return 0;
372 }
373
Steve Block7b984e32011-12-20 16:22:42 +0000374 ALOGD("Stopping tethering services");
San Mehat9d10b342010-01-18 09:51:02 -0800375
376 kill(mDaemonPid, SIGTERM);
Yi Kongbdfd57e2018-07-25 13:26:10 -0700377 waitpid(mDaemonPid, nullptr, 0);
San Mehat9d10b342010-01-18 09:51:02 -0800378 mDaemonPid = 0;
379 close(mDaemonFd);
380 mDaemonFd = -1;
Erik Kline15079dd2018-05-18 23:10:56 +0900381 mDnsmasqState.clear();
Steve Block7b984e32011-12-20 16:22:42 +0000382 ALOGD("Tethering services stopped");
San Mehat9d10b342010-01-18 09:51:02 -0800383 return 0;
384}
Matthew Xie19944102012-07-12 16:42:07 -0700385
San Mehat9d10b342010-01-18 09:51:02 -0800386bool TetherController::isTetheringStarted() {
Luke Huang91bd3e12019-08-20 11:33:52 +0800387 return mIsTetheringStarted;
San Mehat9d10b342010-01-18 09:51:02 -0800388}
389
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900390// dnsmasq can't parse commands larger than this due to the fixed-size buffer
391// in check_android_listeners(). The receiving buffer is 1024 bytes long, but
392// dnsmasq reads up to 1023 bytes.
Bernie Innocenti45238a12018-12-04 14:57:48 +0900393const size_t MAX_CMD_SIZE = 1023;
Kenny Rootcf52faf2010-02-18 09:59:55 -0800394
Luke Huang8dc1cac2019-03-30 16:12:31 +0800395// TODO: Remove overload function and update this after NDC migration.
Lorenzo Colitti667c4772014-08-26 14:13:07 -0700396int TetherController::setDnsForwarders(unsigned netId, char **servers, int numServers) {
Lorenzo Colitti667c4772014-08-26 14:13:07 -0700397 Fwmark fwmark;
398 fwmark.netId = netId;
399 fwmark.explicitlySelected = true;
400 fwmark.protectedFromVpn = true;
401 fwmark.permission = PERMISSION_SYSTEM;
402
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900403 std::string daemonCmd = StringPrintf("update_dns%s0x%x", SEPARATOR, fwmark.intValue);
San Mehat9d10b342010-01-18 09:51:02 -0800404
Erik Kline1d065ba2016-06-08 13:24:45 +0900405 mDnsForwarders.clear();
Bernie Innocenti45238a12018-12-04 14:57:48 +0900406 for (int i = 0; i < numServers; i++) {
Lorenzo Colitti667c4772014-08-26 14:13:07 -0700407 ALOGD("setDnsForwarders(0x%x %d = '%s')", fwmark.intValue, i, servers[i]);
San Mehat9d10b342010-01-18 09:51:02 -0800408
Lorenzo Colittic2841282015-11-25 22:13:57 +0900409 addrinfo *res, hints = { .ai_flags = AI_NUMERICHOST };
Yi Kongbdfd57e2018-07-25 13:26:10 -0700410 int ret = getaddrinfo(servers[i], nullptr, &hints, &res);
Lorenzo Colittic2841282015-11-25 22:13:57 +0900411 freeaddrinfo(res);
412 if (ret) {
Steve Block5ea0c052012-01-06 19:18:11 +0000413 ALOGE("Failed to parse DNS server '%s'", servers[i]);
Erik Kline1d065ba2016-06-08 13:24:45 +0900414 mDnsForwarders.clear();
Lorenzo Colittic2841282015-11-25 22:13:57 +0900415 errno = EINVAL;
Luke Huangb5733d72018-08-21 17:17:19 +0800416 return -errno;
San Mehat9d10b342010-01-18 09:51:02 -0800417 }
Kenny Rootcf52faf2010-02-18 09:59:55 -0800418
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900419 if (daemonCmd.size() + 1 + strlen(servers[i]) >= MAX_CMD_SIZE) {
420 ALOGE("Too many DNS servers listed");
Kenny Rootcf52faf2010-02-18 09:59:55 -0800421 break;
422 }
423
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900424 daemonCmd += SEPARATOR;
425 daemonCmd += servers[i];
Erik Kline1d065ba2016-06-08 13:24:45 +0900426 mDnsForwarders.push_back(servers[i]);
San Mehat9d10b342010-01-18 09:51:02 -0800427 }
428
Lorenzo Colitti667c4772014-08-26 14:13:07 -0700429 mDnsNetId = netId;
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900430 mDnsmasqState.update_dns_cmd = std::move(daemonCmd);
San Mehat9d10b342010-01-18 09:51:02 -0800431 if (mDaemonFd != -1) {
Erik Kline15079dd2018-05-18 23:10:56 +0900432 if (mDnsmasqState.sendAllState(mDaemonFd) != 0) {
Erik Kline1d065ba2016-06-08 13:24:45 +0900433 mDnsForwarders.clear();
Lorenzo Colittic2841282015-11-25 22:13:57 +0900434 errno = EREMOTEIO;
Luke Huangb5733d72018-08-21 17:17:19 +0800435 return -errno;
San Mehat9d10b342010-01-18 09:51:02 -0800436 }
437 }
438 return 0;
439}
440
Luke Huangb5733d72018-08-21 17:17:19 +0800441int TetherController::setDnsForwarders(unsigned netId, const std::vector<std::string>& servers) {
Luke Huangb5733d72018-08-21 17:17:19 +0800442 auto dnsServers = toCstrVec(servers);
443 return setDnsForwarders(netId, dnsServers.data(), dnsServers.size());
444}
445
Lorenzo Colitti667c4772014-08-26 14:13:07 -0700446unsigned TetherController::getDnsNetId() {
447 return mDnsNetId;
448}
449
Erik Kline1d065ba2016-06-08 13:24:45 +0900450const std::list<std::string> &TetherController::getDnsForwarders() const {
San Mehat9d10b342010-01-18 09:51:02 -0800451 return mDnsForwarders;
452}
453
Erik Kline1d065ba2016-06-08 13:24:45 +0900454bool TetherController::applyDnsInterfaces() {
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900455 std::string daemonCmd = "update_ifaces";
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800456 bool haveInterfaces = false;
457
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900458 for (const auto& ifname : mInterfaces) {
459 if (daemonCmd.size() + 1 + ifname.size() >= MAX_CMD_SIZE) {
460 ALOGE("Too many DNS servers listed");
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800461 break;
462 }
463
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900464 daemonCmd += SEPARATOR;
465 daemonCmd += ifname;
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800466 haveInterfaces = true;
467 }
468
Erik Kline15079dd2018-05-18 23:10:56 +0900469 if (!haveInterfaces) {
470 mDnsmasqState.update_ifaces_cmd.clear();
471 } else {
Bernie Innocenti15bb55c2018-06-03 16:19:51 +0900472 mDnsmasqState.update_ifaces_cmd = std::move(daemonCmd);
Erik Kline15079dd2018-05-18 23:10:56 +0900473 if (mDaemonFd != -1) return (mDnsmasqState.sendAllState(mDaemonFd) == 0);
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800474 }
Erik Kline1d065ba2016-06-08 13:24:45 +0900475 return true;
San Mehat9d10b342010-01-18 09:51:02 -0800476}
477
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800478int TetherController::tetherInterface(const char *interface) {
479 ALOGD("tetherInterface(%s)", interface);
JP Abgrall69261cb2014-06-19 18:35:24 -0700480 if (!isIfaceName(interface)) {
481 errno = ENOENT;
Luke Huangb5733d72018-08-21 17:17:19 +0800482 return -errno;
JP Abgrall69261cb2014-06-19 18:35:24 -0700483 }
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800484
Erik Kline1d065ba2016-06-08 13:24:45 +0900485 if (!configureForIPv6Router(interface)) {
486 configureForIPv6Client(interface);
Luke Huangb5733d72018-08-21 17:17:19 +0800487 return -EREMOTEIO;
Erik Kline1d065ba2016-06-08 13:24:45 +0900488 }
489 mInterfaces.push_back(interface);
490
491 if (!applyDnsInterfaces()) {
492 mInterfaces.pop_back();
493 configureForIPv6Client(interface);
Luke Huangb5733d72018-08-21 17:17:19 +0800494 return -EREMOTEIO;
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800495 } else {
496 return 0;
497 }
498}
499
San Mehat9d10b342010-01-18 09:51:02 -0800500int TetherController::untetherInterface(const char *interface) {
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800501 ALOGD("untetherInterface(%s)", interface);
502
Erik Kline1d065ba2016-06-08 13:24:45 +0900503 for (auto it = mInterfaces.cbegin(); it != mInterfaces.cend(); ++it) {
504 if (!strcmp(interface, it->c_str())) {
505 mInterfaces.erase(it);
Robert Greenwalt3d4c7582012-12-11 12:33:37 -0800506
Erik Kline1d065ba2016-06-08 13:24:45 +0900507 configureForIPv6Client(interface);
Luke Huangb5733d72018-08-21 17:17:19 +0800508 return applyDnsInterfaces() ? 0 : -EREMOTEIO;
San Mehat9d10b342010-01-18 09:51:02 -0800509 }
510 }
511 errno = ENOENT;
Luke Huangb5733d72018-08-21 17:17:19 +0800512 return -errno;
San Mehat9d10b342010-01-18 09:51:02 -0800513}
514
Erik Kline1d065ba2016-06-08 13:24:45 +0900515const std::list<std::string> &TetherController::getTetheredInterfaceList() const {
San Mehat9d10b342010-01-18 09:51:02 -0800516 return mInterfaces;
517}
Lorenzo Colittie20a5262017-05-09 18:30:44 +0900518
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900519int TetherController::setupIptablesHooks() {
520 int res;
521 res = setDefaults();
522 if (res < 0) {
523 return res;
524 }
525
526 // Used to limit downstream mss to the upstream pmtu so we don't end up fragmenting every large
527 // packet tethered devices send. This is IPv4-only, because in IPv6 we send the MTU in the RA.
528 // This is no longer optional and tethering will fail to start if it fails.
529 std::string mssRewriteCommand = StringPrintf(
530 "*mangle\n"
531 "-A %s -p tcp --tcp-flags SYN SYN -j TCPMSS --clamp-mss-to-pmtu\n"
532 "COMMIT\n", LOCAL_MANGLE_FORWARD);
533
534 // This is for tethering counters. This chain is reached via --goto, and then RETURNS.
535 std::string defaultCommands = StringPrintf(
536 "*filter\n"
537 ":%s -\n"
538 "COMMIT\n", LOCAL_TETHER_COUNTERS_CHAIN);
539
540 res = iptablesRestoreFunction(V4, mssRewriteCommand, nullptr);
541 if (res < 0) {
542 return res;
543 }
544
545 res = iptablesRestoreFunction(V4V6, defaultCommands, nullptr);
546 if (res < 0) {
547 return res;
548 }
549
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900550 mFwdIfaces.clear();
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900551
552 return 0;
553}
554
555int TetherController::setDefaults() {
556 std::string v4Cmd = StringPrintf(
557 "*filter\n"
558 ":%s -\n"
559 "-A %s -j DROP\n"
560 "COMMIT\n"
561 "*nat\n"
562 ":%s -\n"
563 "COMMIT\n", LOCAL_FORWARD, LOCAL_FORWARD, LOCAL_NAT_POSTROUTING);
564
565 std::string v6Cmd = StringPrintf(
Luke Huangae038f82018-11-05 11:17:31 +0900566 "*filter\n"
567 ":%s -\n"
568 "COMMIT\n"
569 "*raw\n"
570 ":%s -\n"
571 "COMMIT\n",
572 LOCAL_FORWARD, LOCAL_RAW_PREROUTING);
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900573
574 int res = iptablesRestoreFunction(V4, v4Cmd, nullptr);
575 if (res < 0) {
576 return res;
577 }
578
579 res = iptablesRestoreFunction(V6, v6Cmd, nullptr);
580 if (res < 0) {
581 return res;
582 }
583
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900584 return 0;
585}
586
587int TetherController::enableNat(const char* intIface, const char* extIface) {
588 ALOGV("enableNat(intIface=<%s>, extIface=<%s>)",intIface, extIface);
589
590 if (!isIfaceName(intIface) || !isIfaceName(extIface)) {
Luke Huang19b49c52018-10-22 12:12:05 +0900591 return -ENODEV;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900592 }
593
594 /* Bug: b/9565268. "enableNat wlan0 wlan0". For now we fail until java-land is fixed */
595 if (!strcmp(intIface, extIface)) {
596 ALOGE("Duplicate interface specified: %s %s", intIface, extIface);
Luke Huang19b49c52018-10-22 12:12:05 +0900597 return -EINVAL;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900598 }
599
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900600 if (isForwardingPairEnabled(intIface, extIface)) {
601 return 0;
602 }
603
604 // add this if we are the first enabled nat for this upstream
Maciej Żenczykowski99665c32020-04-09 10:50:42 +0000605 bool firstDownstreamForThisUpstream = !isAnyForwardingEnabledOnUpstream(extIface);
606 if (firstDownstreamForThisUpstream) {
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900607 std::vector<std::string> v4Cmds = {
608 "*nat",
609 StringPrintf("-A %s -o %s -j MASQUERADE", LOCAL_NAT_POSTROUTING, extIface),
610 "COMMIT\n"
611 };
612
Luke Huangae038f82018-11-05 11:17:31 +0900613 if (iptablesRestoreFunction(V4, Join(v4Cmds, '\n'), nullptr) || setupIPv6CountersChain() ||
614 setTetherGlobalAlertRule()) {
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900615 ALOGE("Error setting postroute rule: iface=%s", extIface);
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900616 if (!isAnyForwardingPairEnabled()) {
617 // unwind what's been done, but don't care about success - what more could we do?
618 setDefaults();
619 }
Luke Huang19b49c52018-10-22 12:12:05 +0900620 return -EREMOTEIO;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900621 }
622 }
623
624 if (setForwardRules(true, intIface, extIface) != 0) {
625 ALOGE("Error setting forward rules");
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900626 if (!isAnyForwardingPairEnabled()) {
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900627 setDefaults();
628 }
Luke Huang19b49c52018-10-22 12:12:05 +0900629 return -ENODEV;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900630 }
631
Maciej Żenczykowski99665c32020-04-09 10:50:42 +0000632 if (firstDownstreamForThisUpstream) maybeStartBpf(extIface);
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900633 return 0;
634}
635
Luke Huangae038f82018-11-05 11:17:31 +0900636int TetherController::setTetherGlobalAlertRule() {
637 // Only add this if we are the first enabled nat
638 if (isAnyForwardingPairEnabled()) {
639 return 0;
640 }
641 const std::string cmds =
642 "*filter\n" +
643 StringPrintf("-I %s -j %s\n", LOCAL_FORWARD, BandwidthController::LOCAL_GLOBAL_ALERT) +
644 "COMMIT\n";
645
646 return iptablesRestoreFunction(V4V6, cmds, nullptr);
647}
648
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900649int TetherController::setupIPv6CountersChain() {
650 // Only add this if we are the first enabled nat
651 if (isAnyForwardingPairEnabled()) {
652 return 0;
653 }
654
655 /*
656 * IPv6 tethering doesn't need the state-based conntrack rules, so
657 * it unconditionally jumps to the tether counters chain all the time.
658 */
Luke Huangae038f82018-11-05 11:17:31 +0900659 const std::string v6Cmds =
660 "*filter\n" +
661 StringPrintf("-A %s -g %s\n", LOCAL_FORWARD, LOCAL_TETHER_COUNTERS_CHAIN) + "COMMIT\n";
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900662
Luke Huangae038f82018-11-05 11:17:31 +0900663 return iptablesRestoreFunction(V6, v6Cmds, nullptr);
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900664}
665
666// Gets a pointer to the ForwardingDownstream for an interface pair in the map, or nullptr
667TetherController::ForwardingDownstream* TetherController::findForwardingDownstream(
668 const std::string& intIface, const std::string& extIface) {
669 auto extIfaceMatches = mFwdIfaces.equal_range(extIface);
670 for (auto it = extIfaceMatches.first; it != extIfaceMatches.second; ++it) {
671 if (it->second.iface == intIface) {
672 return &(it->second);
673 }
674 }
675 return nullptr;
676}
677
678void TetherController::addForwardingPair(const std::string& intIface, const std::string& extIface) {
679 ForwardingDownstream* existingEntry = findForwardingDownstream(intIface, extIface);
680 if (existingEntry != nullptr) {
681 existingEntry->active = true;
682 return;
683 }
684
685 mFwdIfaces.insert(std::pair<std::string, ForwardingDownstream>(extIface, {
686 .iface = intIface,
687 .active = true
688 }));
689}
690
691void TetherController::markForwardingPairDisabled(
692 const std::string& intIface, const std::string& extIface) {
693 ForwardingDownstream* existingEntry = findForwardingDownstream(intIface, extIface);
694 if (existingEntry == nullptr) {
695 return;
696 }
697
698 existingEntry->active = false;
699}
700
701bool TetherController::isForwardingPairEnabled(
702 const std::string& intIface, const std::string& extIface) {
703 ForwardingDownstream* existingEntry = findForwardingDownstream(intIface, extIface);
704 return existingEntry != nullptr && existingEntry->active;
705}
706
707bool TetherController::isAnyForwardingEnabledOnUpstream(const std::string& extIface) {
708 auto extIfaceMatches = mFwdIfaces.equal_range(extIface);
709 for (auto it = extIfaceMatches.first; it != extIfaceMatches.second; ++it) {
710 if (it->second.active) {
711 return true;
712 }
713 }
714 return false;
715}
716
717bool TetherController::isAnyForwardingPairEnabled() {
718 for (auto& it : mFwdIfaces) {
719 if (it.second.active) {
720 return true;
721 }
722 }
723 return false;
724}
725
726bool TetherController::tetherCountingRuleExists(
727 const std::string& iface1, const std::string& iface2) {
728 // A counting rule exists if NAT was ever enabled for this interface pair, so if the pair
729 // is in the map regardless of its active status. Rules are added both ways so we check with
730 // the 2 combinations.
731 return findForwardingDownstream(iface1, iface2) != nullptr
732 || findForwardingDownstream(iface2, iface1) != nullptr;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900733}
734
735/* static */
736std::string TetherController::makeTetherCountingRule(const char *if1, const char *if2) {
737 return StringPrintf("-A %s -i %s -o %s -j RETURN", LOCAL_TETHER_COUNTERS_CHAIN, if1, if2);
738}
739
740int TetherController::setForwardRules(bool add, const char *intIface, const char *extIface) {
741 const char *op = add ? "-A" : "-D";
742
743 std::string rpfilterCmd = StringPrintf(
744 "*raw\n"
745 "%s %s -i %s -m rpfilter --invert ! -s fe80::/64 -j DROP\n"
746 "COMMIT\n", op, LOCAL_RAW_PREROUTING, intIface);
747 if (iptablesRestoreFunction(V6, rpfilterCmd, nullptr) == -1 && add) {
Luke Huang19b49c52018-10-22 12:12:05 +0900748 return -EREMOTEIO;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900749 }
750
751 std::vector<std::string> v4 = {
hiroaki.yokoyama04f2cb52018-06-13 18:47:30 +0900752 "*raw",
753 StringPrintf("%s %s -p tcp --dport 21 -i %s -j CT --helper ftp", op,
754 LOCAL_RAW_PREROUTING, intIface),
755 StringPrintf("%s %s -p tcp --dport 1723 -i %s -j CT --helper pptp", op,
756 LOCAL_RAW_PREROUTING, intIface),
757 "COMMIT",
758 "*filter",
759 StringPrintf("%s %s -i %s -o %s -m state --state ESTABLISHED,RELATED -g %s", op,
760 LOCAL_FORWARD, extIface, intIface, LOCAL_TETHER_COUNTERS_CHAIN),
761 StringPrintf("%s %s -i %s -o %s -m state --state INVALID -j DROP", op, LOCAL_FORWARD,
762 intIface, extIface),
763 StringPrintf("%s %s -i %s -o %s -g %s", op, LOCAL_FORWARD, intIface, extIface,
764 LOCAL_TETHER_COUNTERS_CHAIN),
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900765 };
766
767 std::vector<std::string> v6 = {
768 "*filter",
769 };
770
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900771 // We only ever add tethering quota rules so that they stick.
772 if (add && !tetherCountingRuleExists(intIface, extIface)) {
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900773 v4.push_back(makeTetherCountingRule(intIface, extIface));
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900774 v4.push_back(makeTetherCountingRule(extIface, intIface));
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900775 v6.push_back(makeTetherCountingRule(intIface, extIface));
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900776 v6.push_back(makeTetherCountingRule(extIface, intIface));
777 }
778
779 // Always make sure the drop rule is at the end.
780 // TODO: instead of doing this, consider just rebuilding LOCAL_FORWARD completely from scratch
Lorenzo Colitti4604b4a2017-08-24 19:21:50 +0900781 // every time, starting with ":tetherctrl_FORWARD -\n". This would likely be a bit simpler.
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900782 if (add) {
783 v4.push_back(StringPrintf("-D %s -j DROP", LOCAL_FORWARD));
784 v4.push_back(StringPrintf("-A %s -j DROP", LOCAL_FORWARD));
785 }
786
787 v4.push_back("COMMIT\n");
788 v6.push_back("COMMIT\n");
789
790 // We only add IPv6 rules here, never remove them.
791 if (iptablesRestoreFunction(V4, Join(v4, '\n'), nullptr) == -1 ||
792 (add && iptablesRestoreFunction(V6, Join(v6, '\n'), nullptr) == -1)) {
793 // unwind what's been done, but don't care about success - what more could we do?
794 if (add) {
795 setForwardRules(false, intIface, extIface);
796 }
Luke Huang19b49c52018-10-22 12:12:05 +0900797 return -EREMOTEIO;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900798 }
799
Remi NGUYEN VAN3b47c792018-03-20 14:44:12 +0900800 if (add) {
801 addForwardingPair(intIface, extIface);
802 } else {
803 markForwardingPairDisabled(intIface, extIface);
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900804 }
805
806 return 0;
807}
808
809int TetherController::disableNat(const char* intIface, const char* extIface) {
810 if (!isIfaceName(intIface) || !isIfaceName(extIface)) {
Luke Huangae038f82018-11-05 11:17:31 +0900811 errno = ENODEV;
812 return -errno;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900813 }
814
815 setForwardRules(false, intIface, extIface);
Maciej Żenczykowski99665c32020-04-09 10:50:42 +0000816 if (!isAnyForwardingEnabledOnUpstream(extIface)) maybeStopBpf(extIface);
817 if (!isAnyForwardingPairEnabled()) setDefaults();
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900818 return 0;
819}
820
Lorenzo Colittif0e051c2020-04-06 09:19:57 +0000821namespace {
822Result<void> validateOffloadRule(const TetherOffloadRuleParcel& rule) {
823 struct ethhdr hdr;
824
825 if (rule.inputInterfaceIndex <= 0) {
826 return Error(ENODEV) << "Invalid input interface " << rule.inputInterfaceIndex;
827 }
828 if (rule.outputInterfaceIndex <= 0) {
829 return Error(ENODEV) << "Invalid output interface " << rule.inputInterfaceIndex;
830 }
831 if (rule.prefixLength != 128) {
832 return Error(EINVAL) << "Prefix length must be 128, not " << rule.prefixLength;
833 }
834 if (rule.destination.size() != sizeof(in6_addr)) {
835 return Error(EAFNOSUPPORT) << "Invalid IP address length " << rule.destination.size();
836 }
837 if (rule.srcL2Address.size() != sizeof(hdr.h_source)) {
838 return Error(ENXIO) << "Invalid L2 src address length " << rule.srcL2Address.size();
839 }
840 if (rule.dstL2Address.size() != sizeof(hdr.h_dest)) {
841 return Error(ENXIO) << "Invalid L2 dst address length " << rule.dstL2Address.size();
842 }
843 return Result<void>();
844}
845} // namespace
846
847Result<void> TetherController::addOffloadRule(const TetherOffloadRuleParcel& rule) {
848 Result<void> res = validateOffloadRule(rule);
849 if (!res.ok()) return res;
850
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900851 ethhdr hdr = {
852 .h_proto = htons(ETH_P_IPV6),
853 };
Lorenzo Colittif0e051c2020-04-06 09:19:57 +0000854 memcpy(&hdr.h_dest, rule.dstL2Address.data(), sizeof(hdr.h_dest));
855 memcpy(&hdr.h_source, rule.srcL2Address.data(), sizeof(hdr.h_source));
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900856
Lorenzo Colittif0e051c2020-04-06 09:19:57 +0000857 // Only downstream supported for now.
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900858 TetherIngressKey key = {
Lorenzo Colittif0e051c2020-04-06 09:19:57 +0000859 .iif = static_cast<uint32_t>(rule.inputInterfaceIndex),
860 .neigh6 = *(const in6_addr*)rule.destination.data(),
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900861 };
862
863 TetherIngressValue value = {
Maciej Żenczykowski1ec24532020-05-23 22:07:00 +0000864 .oif = static_cast<uint32_t>(rule.outputInterfaceIndex),
865 .macHeader = hdr,
866 .pmtu = 1500, // TODO: don't just blindly use this default
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900867 };
868
869 return mBpfIngressMap.writeValue(key, value, BPF_ANY);
870}
871
Lorenzo Colittif0e051c2020-04-06 09:19:57 +0000872Result<void> TetherController::removeOffloadRule(const TetherOffloadRuleParcel& rule) {
873 Result<void> res = validateOffloadRule(rule);
874 if (!res.ok()) return res;
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900875
876 TetherIngressKey key = {
Lorenzo Colittif0e051c2020-04-06 09:19:57 +0000877 .iif = static_cast<uint32_t>(rule.inputInterfaceIndex),
878 .neigh6 = *(const in6_addr*)rule.destination.data(),
Lorenzo Colittie801d3c2020-02-18 00:00:35 +0900879 };
880
881 Result<void> ret = mBpfIngressMap.deleteValue(key);
882
883 // Silently return success if the rule did not exist.
884 if (!ret.ok() && ret.error().code() == ENOENT) return {};
885
886 return ret;
887}
888
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900889void TetherController::addStats(TetherStatsList& statsList, const TetherStats& stats) {
890 for (TetherStats& existing : statsList) {
891 if (existing.addStatsIfMatch(stats)) {
892 return;
893 }
894 }
895 // No match. Insert a new interface pair.
896 statsList.push_back(stats);
897}
898
899/*
900 * Parse the ptks and bytes out of:
Lorenzo Colitti4604b4a2017-08-24 19:21:50 +0900901 * Chain tetherctrl_counters (4 references)
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900902 * pkts bytes target prot opt in out source destination
903 * 26 2373 RETURN all -- wlan0 rmnet0 0.0.0.0/0 0.0.0.0/0
904 * 27 2002 RETURN all -- rmnet0 wlan0 0.0.0.0/0 0.0.0.0/0
905 * 1040 107471 RETURN all -- bt-pan rmnet0 0.0.0.0/0 0.0.0.0/0
906 * 1450 1708806 RETURN all -- rmnet0 bt-pan 0.0.0.0/0 0.0.0.0/0
907 * or:
Lorenzo Colitti4604b4a2017-08-24 19:21:50 +0900908 * Chain tetherctrl_counters (0 references)
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900909 * pkts bytes target prot opt in out source destination
910 * 0 0 RETURN all wlan0 rmnet_data0 ::/0 ::/0
911 * 0 0 RETURN all rmnet_data0 wlan0 ::/0 ::/0
912 *
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900913 */
Lorenzo Colitti09353392017-08-24 14:20:32 +0900914int TetherController::addForwardChainStats(TetherStatsList& statsList,
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900915 const std::string& statsOutput,
916 std::string &extraProcessingInfo) {
waynema71a0b592018-11-21 13:31:34 +0800917 enum IndexOfIptChain {
918 ORIG_LINE,
919 PACKET_COUNTS,
920 BYTE_COUNTS,
921 HYPHEN,
922 IFACE0_NAME,
923 IFACE1_NAME,
924 SOURCE,
925 DESTINATION
926 };
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900927 TetherStats stats;
Lorenzo Colitti09353392017-08-24 14:20:32 +0900928 const TetherStats empty;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900929
waynema71a0b592018-11-21 13:31:34 +0800930 static const std::string NUM = "(\\d+)";
931 static const std::string IFACE = "([^\\s]+)";
932 static const std::string DST = "(0.0.0.0/0|::/0)";
933 static const std::string COUNTERS = "\\s*" + NUM + "\\s+" + NUM +
934 " RETURN all( -- | )" + IFACE + "\\s+" + IFACE +
935 "\\s+" + DST + "\\s+" + DST;
936 static const std::regex IP_RE(COUNTERS);
Lorenzo Colitti09353392017-08-24 14:20:32 +0900937
waynema71a0b592018-11-21 13:31:34 +0800938 const std::vector<std::string> lines = base::Split(statsOutput, "\n");
939 int headerLine = 0;
940 for (const std::string& line : lines) {
941 // Skip headers.
942 if (headerLine < 2) {
943 if (line.empty()) {
944 ALOGV("Empty header while parsing tethering stats");
945 return -EREMOTEIO;
946 }
947 headerLine++;
948 continue;
Lorenzo Colitti09353392017-08-24 14:20:32 +0900949 }
Lorenzo Colitti09353392017-08-24 14:20:32 +0900950
waynema71a0b592018-11-21 13:31:34 +0800951 if (line.empty()) continue;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900952
waynema71a0b592018-11-21 13:31:34 +0800953 extraProcessingInfo = line;
954 std::smatch matches;
955 if (!std::regex_search(line, matches, IP_RE)) return -EREMOTEIO;
956 // Here use IP_RE to distiguish IPv4 and IPv6 iptables.
957 // IPv4 has "--" indicating what to do with fragments...
958 // 26 2373 RETURN all -- wlan0 rmnet0 0.0.0.0/0 0.0.0.0/0
959 // ... but IPv6 does not.
960 // 26 2373 RETURN all wlan0 rmnet0 ::/0 ::/0
961 // TODO: Replace strtoXX() calls with ParseUint() /ParseInt()
962 int64_t packets = strtoul(matches[PACKET_COUNTS].str().c_str(), nullptr, 10);
963 int64_t bytes = strtoul(matches[BYTE_COUNTS].str().c_str(), nullptr, 10);
964 std::string iface0 = matches[IFACE0_NAME].str();
965 std::string iface1 = matches[IFACE1_NAME].str();
966 std::string rest = matches[SOURCE].str();
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900967
waynema71a0b592018-11-21 13:31:34 +0800968 ALOGV("parse iface0=<%s> iface1=<%s> pkts=%" PRId64 " bytes=%" PRId64
969 " rest=<%s> orig line=<%s>",
970 iface0.c_str(), iface1.c_str(), packets, bytes, rest.c_str(), line.c_str());
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900971 /*
972 * The following assumes that the 1st rule has in:extIface out:intIface,
973 * which is what TetherController sets up.
Lorenzo Colitti09353392017-08-24 14:20:32 +0900974 * The 1st matches rx, and sets up the pair for the tx side.
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900975 */
Lorenzo Colitti09353392017-08-24 14:20:32 +0900976 if (!stats.intIface[0]) {
waynema71a0b592018-11-21 13:31:34 +0800977 ALOGV("0Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64 " rx_packets=%" PRId64
978 " ", iface0.c_str(), iface1.c_str(), bytes, packets);
Lorenzo Colitti09353392017-08-24 14:20:32 +0900979 stats.intIface = iface0;
980 stats.extIface = iface1;
Lorenzo Colitti09353392017-08-24 14:20:32 +0900981 stats.txPackets = packets;
982 stats.txBytes = bytes;
Lorenzo Colitti9a65ac62017-09-04 18:07:56 +0900983 } else if (stats.intIface == iface1 && stats.extIface == iface0) {
waynema71a0b592018-11-21 13:31:34 +0800984 ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64 " rx_packets=%" PRId64
985 " ", iface0.c_str(), iface1.c_str(), bytes, packets);
Lorenzo Colitti9a65ac62017-09-04 18:07:56 +0900986 stats.rxPackets = packets;
987 stats.rxBytes = bytes;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900988 }
989 if (stats.rxBytes != -1 && stats.txBytes != -1) {
Lorenzo Colitti09353392017-08-24 14:20:32 +0900990 ALOGV("rx_bytes=%" PRId64" tx_bytes=%" PRId64, stats.rxBytes, stats.txBytes);
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900991 addStats(statsList, stats);
Lorenzo Colitti09353392017-08-24 14:20:32 +0900992 stats = empty;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900993 }
994 }
995
996 /* It is always an error to find only one side of the stats. */
Lorenzo Colitti38fd1362017-09-15 11:40:01 +0900997 if (((stats.rxBytes == -1) != (stats.txBytes == -1))) {
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +0900998 return -EREMOTEIO;
Lorenzo Colittia93126d2017-08-24 13:28:19 +0900999 }
1000 return 0;
1001}
1002
Lorenzo Colitti5192bf72017-09-04 13:30:59 +09001003StatusOr<TetherController::TetherStatsList> TetherController::getTetherStats() {
Lorenzo Colittia93126d2017-08-24 13:28:19 +09001004 TetherStatsList statsList;
Lorenzo Colitti5192bf72017-09-04 13:30:59 +09001005 std::string parsedIptablesOutput;
Lorenzo Colittia93126d2017-08-24 13:28:19 +09001006
1007 for (const IptablesTarget target : {V4, V6}) {
1008 std::string statsString;
Lorenzo Colitti09353392017-08-24 14:20:32 +09001009 if (int ret = iptablesRestoreFunction(target, GET_TETHER_STATS_COMMAND, &statsString)) {
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +09001010 return statusFromErrno(-ret, StringPrintf("failed to fetch tether stats (%d): %d",
1011 target, ret));
Lorenzo Colittia93126d2017-08-24 13:28:19 +09001012 }
1013
Lorenzo Colitti5192bf72017-09-04 13:30:59 +09001014 if (int ret = addForwardChainStats(statsList, statsString, parsedIptablesOutput)) {
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +09001015 return statusFromErrno(-ret, StringPrintf("failed to parse %s tether stats:\n%s",
1016 target == V4 ? "IPv4": "IPv6",
Lorenzo Colitti5192bf72017-09-04 13:30:59 +09001017 parsedIptablesOutput.c_str()));
Lorenzo Colittia93126d2017-08-24 13:28:19 +09001018 }
1019 }
1020
Hungming Chen41b0ed92020-06-02 00:13:20 +00001021 return statsList;
1022}
Hungming Chenc2e95fb2020-02-19 17:41:30 +08001023
Hungming Chen41b0ed92020-06-02 00:13:20 +00001024StatusOr<TetherController::TetherOffloadStatsList> TetherController::getTetherOffloadStats() {
1025 TetherOffloadStatsList statsList;
1026
1027 const auto processTetherStats = [&statsList](const uint32_t& key, const TetherStatsValue& value,
1028 const BpfMap<uint32_t, TetherStatsValue>&) {
1029 statsList.push_back({.ifIndex = static_cast<int>(key),
1030 .rxBytes = static_cast<int64_t>(value.rxBytes),
1031 .rxPackets = static_cast<int64_t>(value.rxPackets),
1032 .txBytes = static_cast<int64_t>(value.txBytes),
1033 .txPackets = static_cast<int64_t>(value.txPackets)});
Hungming Chen68dade32020-02-20 13:50:56 +08001034 return Result<void>();
1035 };
1036
1037 auto ret = mBpfStatsMap.iterateWithValue(processTetherStats);
1038 if (!ret.ok()) {
Hungming Chen41b0ed92020-06-02 00:13:20 +00001039 // Ignore error to return the remaining tether stats result.
Hungming Chen68dade32020-02-20 13:50:56 +08001040 ALOGE("Error processing tether stats from BPF maps: %s", ret.error().message().c_str());
Hungming Chenc2e95fb2020-02-19 17:41:30 +08001041 }
1042
Lorenzo Colitti9a8a9ff2017-01-31 19:06:59 +09001043 return statsList;
1044}
1045
Maciej Żenczykowskiac14cb52020-05-23 20:48:00 +00001046// Use UINT64_MAX (~0uLL) for unlimited.
1047Result<void> TetherController::setBpfLimit(uint32_t ifIndex, uint64_t limit) {
1048 // The common case is an update, where the stats already exist,
1049 // hence we read first, even though writing with BPF_NOEXIST
1050 // first would make the code simpler.
1051 uint64_t rxBytes, txBytes;
1052 auto statsEntry = mBpfStatsMap.readValue(ifIndex);
1053
1054 if (statsEntry.ok()) {
1055 // Ok, there was a stats entry.
1056 rxBytes = statsEntry.value().rxBytes;
1057 txBytes = statsEntry.value().txBytes;
1058 } else if (statsEntry.error().code() == ENOENT) {
1059 // No stats entry - create one with zeroes.
1060 TetherStatsValue stats = {};
1061 // This function is the *only* thing that can create entries.
1062 auto ret = mBpfStatsMap.writeValue(ifIndex, stats, BPF_NOEXIST);
1063 if (!ret.ok()) {
1064 ALOGE("mBpfStatsMap.writeValue failure: %s", strerror(ret.error().code()));
1065 return ret;
1066 }
1067 rxBytes = 0;
1068 txBytes = 0;
1069 } else {
1070 // Other error while trying to get stats entry.
1071 return statsEntry.error();
1072 }
1073
1074 // rxBytes + txBytes won't overflow even at 5gbps for ~936 years.
1075 uint64_t newLimit = rxBytes + txBytes + limit;
1076
1077 // if adding limit (e.g., if limit is UINT64_MAX) caused overflow: clamp to 'infinity'
1078 if (newLimit < rxBytes + txBytes) newLimit = ~0uLL;
1079
1080 auto ret = mBpfLimitMap.writeValue(ifIndex, newLimit, BPF_ANY);
1081 if (!ret.ok()) {
1082 ALOGE("mBpfLimitMap.writeValue failure: %s", strerror(ret.error().code()));
1083 return ret;
1084 }
1085
1086 return {};
1087}
1088
Hungming Chen1da90082020-02-14 20:24:16 +08001089void TetherController::maybeStartBpf(const char* extIface) {
Maciej Żenczykowskiaef13012020-02-18 17:13:09 -08001090 if (!bpf::isBpfSupported()) return;
1091
Hungming Chen1da90082020-02-14 20:24:16 +08001092 // TODO: perhaps ignore IPv4-only interface because IPv4 traffic downstream is not supported.
1093 int ifIndex = if_nametoindex(extIface);
1094 if (!ifIndex) {
1095 ALOGE("Fail to get index for interface %s", extIface);
1096 return;
1097 }
1098
1099 auto isEthernet = android::net::isEthernet(extIface);
1100 if (!isEthernet.ok()) {
1101 ALOGE("isEthernet(%s[%d]) failure: %s", extIface, ifIndex,
1102 isEthernet.error().message().c_str());
1103 return;
1104 }
1105
1106 int rv = getTetherIngressProgFd(isEthernet.value());
1107 if (rv < 0) {
1108 ALOGE("getTetherIngressProgFd(%d) failure: %s", isEthernet.value(), strerror(-rv));
1109 return;
1110 }
1111 unique_fd tetherProgFd(rv);
1112
1113 rv = tcFilterAddDevIngressTether(ifIndex, tetherProgFd, isEthernet.value());
1114 if (rv) {
1115 ALOGE("tcFilterAddDevIngressTether(%d[%s], %d) failure: %s", ifIndex, extIface,
1116 isEthernet.value(), strerror(-rv));
1117 return;
1118 }
Maciej Żenczykowskiac14cb52020-05-23 20:48:00 +00001119
1120 // For now we just set data limit to 'infinity' ie. unlimited.
1121 setBpfLimit(ifIndex, ~0uLL);
Hungming Chen1da90082020-02-14 20:24:16 +08001122}
1123
1124void TetherController::maybeStopBpf(const char* extIface) {
Maciej Żenczykowskiaef13012020-02-18 17:13:09 -08001125 if (!bpf::isBpfSupported()) return;
1126
Hungming Chen1da90082020-02-14 20:24:16 +08001127 // TODO: perhaps ignore IPv4-only interface because IPv4 traffic downstream is not supported.
1128 int ifIndex = if_nametoindex(extIface);
1129 if (!ifIndex) {
1130 ALOGE("Fail to get index for interface %s", extIface);
1131 return;
1132 }
1133
1134 int rv = tcFilterDelDevIngressTether(ifIndex);
1135 if (rv < 0) {
1136 ALOGE("tcFilterDelDevIngressTether(%d[%s]) failure: %s", ifIndex, extIface, strerror(-rv));
1137 }
1138}
1139
Lorenzo Colitti52db3912020-02-17 23:59:45 +09001140void TetherController::dumpIfaces(DumpWriter& dw) {
1141 dw.println("Interface pairs:");
1142
1143 ScopedIndent ifaceIndent(dw);
1144 for (const auto& it : mFwdIfaces) {
1145 dw.println("%s -> %s %s", it.first.c_str(), it.second.iface.c_str(),
1146 (it.second.active ? "ACTIVE" : "DISABLED"));
1147 }
1148}
1149
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001150namespace {
1151
1152std::string l2ToString(const uint8_t* addr, size_t len) {
1153 std::string str;
1154
1155 if (len == 0) return str;
1156
1157 StringAppendF(&str, "%02x", addr[0]);
1158 for (size_t i = 1; i < len; i++) {
1159 StringAppendF(&str, ":%02x", addr[i]);
1160 }
1161
1162 return str;
1163}
1164
1165} // namespace
1166
1167void TetherController::dumpBpf(DumpWriter& dw) {
Maciej Żenczykowskid25a7342020-05-04 18:18:38 -07001168 if (!mBpfIngressMap.isValid() || !mBpfStatsMap.isValid() || !mBpfLimitMap.isValid()) {
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001169 dw.println("BPF not supported");
1170 return;
1171 }
1172
Maciej Żenczykowski1ec24532020-05-23 22:07:00 +00001173 dw.println("BPF ingress map: iif v6addr -> oif srcmac dstmac ethertype [pmtu]");
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001174 const auto printIngressMap = [&dw](const TetherIngressKey& key, const TetherIngressValue& value,
1175 const BpfMap<TetherIngressKey, TetherIngressValue>&) {
1176 char addr[INET6_ADDRSTRLEN];
1177 std::string src = l2ToString(value.macHeader.h_source, sizeof(value.macHeader.h_source));
1178 std::string dst = l2ToString(value.macHeader.h_dest, sizeof(value.macHeader.h_dest));
1179 inet_ntop(AF_INET6, &key.neigh6, addr, sizeof(addr));
1180
Maciej Żenczykowski1ec24532020-05-23 22:07:00 +00001181 dw.println("%u %s -> %u %s %s %04x [%u]", key.iif, addr, value.oif, src.c_str(),
1182 dst.c_str(), ntohs(value.macHeader.h_proto), value.pmtu);
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001183
1184 return Result<void>();
1185 };
1186
1187 dw.incIndent();
1188 auto ret = mBpfIngressMap.iterateWithValue(printIngressMap);
1189 if (!ret.ok()) {
1190 dw.println("Error printing BPF ingress map: %s", ret.error().message().c_str());
1191 }
1192 dw.decIndent();
1193
1194 dw.println("BPF stats (downlink): iif -> packets bytes errors");
1195 const auto printStatsMap = [&dw](const uint32_t& key, const TetherStatsValue& value,
1196 const BpfMap<uint32_t, TetherStatsValue>&) {
Treehugger Robot15b21b72020-05-13 09:24:07 +00001197 dw.println("%u -> %" PRIu64 " %" PRIu64 " %" PRIu64, key, value.rxPackets, value.rxBytes,
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001198 value.rxErrors);
1199
1200 return Result<void>();
1201 };
1202
1203 dw.incIndent();
1204 ret = mBpfStatsMap.iterateWithValue(printStatsMap);
1205 if (!ret.ok()) {
1206 dw.println("Error printing BPF stats map: %s", ret.error().message().c_str());
1207 }
1208 dw.decIndent();
Maciej Żenczykowskid25a7342020-05-04 18:18:38 -07001209
1210 dw.println("BPF limit: iif -> bytes");
1211 const auto printLimitMap = [&dw](const uint32_t& key, const uint64_t& value,
1212 const BpfMap<uint32_t, uint64_t>&) {
1213 dw.println("%u -> %" PRIu64, key, value);
1214
1215 return Result<void>();
1216 };
1217
1218 dw.incIndent();
1219 ret = mBpfLimitMap.iterateWithValue(printLimitMap);
1220 if (!ret.ok()) {
1221 dw.println("Error printing BPF limit map: %s", ret.error().message().c_str());
1222 }
1223 dw.decIndent();
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001224}
1225
Lorenzo Colitti52db3912020-02-17 23:59:45 +09001226void TetherController::dump(DumpWriter& dw) {
1227 std::lock_guard guard(lock);
1228
1229 ScopedIndent tetherControllerIndent(dw);
1230 dw.println("TetherController");
1231 dw.incIndent();
1232
1233 dw.println("Forwarding requests: " + Join(mForwardingRequests, ' '));
1234 if (mDnsNetId != 0) {
1235 dw.println(StringPrintf("DNS: netId %d servers [%s]", mDnsNetId,
1236 Join(mDnsForwarders, ", ").c_str()));
1237 }
1238 if (mDaemonPid != 0) {
1239 dw.println("dnsmasq PID: %d", mDaemonPid);
1240 }
1241
1242 dumpIfaces(dw);
Lorenzo Colittie801d3c2020-02-18 00:00:35 +09001243 dw.println("");
1244 dumpBpf(dw);
Lorenzo Colitti52db3912020-02-17 23:59:45 +09001245}
1246
Lorenzo Colittie20a5262017-05-09 18:30:44 +09001247} // namespace net
1248} // namespace android