diff options
| author | Erik Kline <ek@google.com> | 2018-05-18 23:10:56 +0900 |
|---|---|---|
| committer | Erik Kline <ek@google.com> | 2018-05-22 14:38:32 +0900 |
| commit | 15079dd9de50f6bcc402e68b7ddfc037dc7921f1 (patch) | |
| tree | da4216ad40a31c0263e2e5208703f4c2f4a01a4c /server/TetherController.cpp | |
| parent | aa77e4c9c7bb2faeee062403b3700a2316327482 (diff) | |
Always push all state to dnsmasq
Test: as follows
- built, flashed, booted
- manual use of tethering
Bug: 31634369
Bug: 36988090
Bug: 64090733
Bug: 79956831
Change-Id: I27f572dab0e3ddbe4b7586363a0bd05a3e66403c
Diffstat (limited to 'server/TetherController.cpp')
| -rw-r--r-- | server/TetherController.cpp | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/server/TetherController.cpp b/server/TetherController.cpp index 00430b6d..7facb7bd 100644 --- a/server/TetherController.cpp +++ b/server/TetherController.cpp @@ -123,6 +123,28 @@ const std::string GET_TETHER_STATS_COMMAND = StringPrintf( "-nvx -L %s\n" "COMMIT\n", android::net::TetherController::LOCAL_TETHER_COUNTERS_CHAIN); +int TetherController::DnsmasqState::sendCmd(int daemonFd, const std::string& cmd) { + if (cmd.empty()) return 0; + + ALOGD("Sending update msg to dnsmasq [%s]", cmd.c_str()); + // Send the trailing \0 as well. + if (write(daemonFd, cmd.c_str(), cmd.size() + 1) < 0) { + ALOGE("Failed to send update command to dnsmasq (%s)", strerror(errno)); + errno = EREMOTEIO; + return -1; + } + return 0; +} + +void TetherController::DnsmasqState::clear() { + update_ifaces_cmd.clear(); + update_dns_cmd.clear(); +} + +int TetherController::DnsmasqState::sendAllState(int daemonFd) const { + return sendCmd(daemonFd, update_ifaces_cmd) | sendCmd(daemonFd, update_dns_cmd); +} + TetherController::TetherController() { if (inBpToolsMode()) { enableForwarding(BP_TOOLS_MODE); @@ -259,6 +281,7 @@ int TetherController::stopTethering() { mDaemonPid = 0; close(mDaemonFd); mDaemonFd = -1; + mDnsmasqState.clear(); ALOGD("Tethering services stopped"); return 0; } @@ -271,7 +294,7 @@ bool TetherController::isTetheringStarted() { int TetherController::setDnsForwarders(unsigned netId, char **servers, int numServers) { int i; - char daemonCmd[MAX_CMD_SIZE]; + char daemonCmd[MAX_CMD_SIZE] = {}; Fwmark fwmark; fwmark.netId = netId; @@ -308,10 +331,9 @@ int TetherController::setDnsForwarders(unsigned netId, char **servers, int numSe } mDnsNetId = netId; + mDnsmasqState.update_dns_cmd = std::string(daemonCmd); if (mDaemonFd != -1) { - ALOGD("Sending update msg to dnsmasq [%s]", daemonCmd); - if (write(mDaemonFd, daemonCmd, strlen(daemonCmd) +1) < 0) { - ALOGE("Failed to send update command to dnsmasq (%s)", strerror(errno)); + if (mDnsmasqState.sendAllState(mDaemonFd) != 0) { mDnsForwarders.clear(); errno = EREMOTEIO; return -1; @@ -329,7 +351,7 @@ const std::list<std::string> &TetherController::getDnsForwarders() const { } bool TetherController::applyDnsInterfaces() { - char daemonCmd[MAX_CMD_SIZE]; + char daemonCmd[MAX_CMD_SIZE] = {}; strcpy(daemonCmd, "update_ifaces"); int cmdLen = strlen(daemonCmd); @@ -347,12 +369,11 @@ bool TetherController::applyDnsInterfaces() { haveInterfaces = true; } - if ((mDaemonFd != -1) && haveInterfaces) { - ALOGD("Sending update msg to dnsmasq [%s]", daemonCmd); - if (write(mDaemonFd, daemonCmd, strlen(daemonCmd) +1) < 0) { - ALOGE("Failed to send update command to dnsmasq (%s)", strerror(errno)); - return false; - } + if (!haveInterfaces) { + mDnsmasqState.update_ifaces_cmd.clear(); + } else { + mDnsmasqState.update_ifaces_cmd = std::string(daemonCmd); + if (mDaemonFd != -1) return (mDnsmasqState.sendAllState(mDaemonFd) == 0); } return true; } |
