diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-09-05 09:17:46 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-09-05 09:17:46 +0000 |
| commit | 268fef50181fee1720eb8cf9d309b9b3d3b88ef7 (patch) | |
| tree | c4f771cd4df0058144826070b7c2a3edf1ec064a /server/TetherController.cpp | |
| parent | 0998fe87b913ffd2121ef274146153bd300e854a (diff) | |
| parent | 9a65ac6a69575ed7c20d30faa2f74839c4ec2aed (diff) | |
Merge changes from topic "tetherstats_binder"
* changes:
Swap TX and RX in addForwardChainStats for clarity.
Remove the gettetherstats command.
Add a binder RPC for tethering stats.
Diffstat (limited to 'server/TetherController.cpp')
| -rw-r--r-- | server/TetherController.cpp | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/server/TetherController.cpp b/server/TetherController.cpp index ad326823..13cf1d89 100644 --- a/server/TetherController.cpp +++ b/server/TetherController.cpp @@ -34,6 +34,7 @@ #include <android-base/stringprintf.h> #include <cutils/log.h> #include <cutils/properties.h> +#include <netdutils/StatusOr.h> #include "Fwmark.h" #include "NetdConstants.h" @@ -46,6 +47,8 @@ using android::base::Join; using android::base::StringPrintf; using android::base::StringAppendF; +using android::netdutils::StatusOr; +using android::netdutils::statusFromErrno; namespace { @@ -652,7 +655,7 @@ int TetherController::addForwardChainStats(TetherStatsList& statsList, extraProcessingInfo += statsLine + "\n"; if (statsLine.empty()) { ALOGE("Empty header while parsing tethering stats"); - return -1; + return -EREMOTEIO; } } @@ -689,12 +692,12 @@ int TetherController::addForwardChainStats(TetherStatsList& statsList, ALOGV("0Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets); stats.intIface = iface0; stats.extIface = iface1; - stats.rxPackets = packets; - stats.rxBytes = bytes; - } else if (stats.intIface == iface1 && stats.extIface == iface0) { - ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets); stats.txPackets = packets; stats.txBytes = bytes; + } else if (stats.intIface == iface1 && stats.extIface == iface0) { + ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets); + stats.rxPackets = packets; + stats.rxBytes = bytes; } if (stats.rxBytes != -1 && stats.txBytes != -1) { ALOGV("rx_bytes=%" PRId64" tx_bytes=%" PRId64, stats.rxBytes, stats.txBytes); @@ -706,40 +709,30 @@ int TetherController::addForwardChainStats(TetherStatsList& statsList, /* It is always an error to find only one side of the stats. */ if (((stats.rxBytes == -1) != (stats.txBytes == -1)) || !statsFound) { - return -1; + return -EREMOTEIO; } return 0; } -std::string TetherController::TetherStats::getStatsLine() const { - std::string msg; - StringAppendF(&msg, "%s %s %" PRId64" %" PRId64" %" PRId64" %" PRId64, intIface.c_str(), - extIface.c_str(), rxBytes, rxPackets, txBytes, txPackets); - return msg; -} - -int TetherController::getTetherStats(SocketClient *cli, std::string &extraProcessingInfo) { +StatusOr<TetherController::TetherStatsList> TetherController::getTetherStats() { TetherStatsList statsList; + std::string parsedIptablesOutput; for (const IptablesTarget target : {V4, V6}) { std::string statsString; if (int ret = iptablesRestoreFunction(target, GET_TETHER_STATS_COMMAND, &statsString)) { - ALOGE("Failed to run %s err=%d", GET_TETHER_STATS_COMMAND.c_str(), ret); - return -1; + return statusFromErrno(-ret, StringPrintf("failed to fetch tether stats (%d): %d", + target, ret)); } - if (int ret = addForwardChainStats(statsList, statsString, extraProcessingInfo)) { - return ret; + if (int ret = addForwardChainStats(statsList, statsString, parsedIptablesOutput)) { + return statusFromErrno(-ret, StringPrintf("failed to parse %s tether stats:\n%s", + target == V4 ? "IPv4": "IPv6", + parsedIptablesOutput.c_str())); } } - for (const auto& stats: statsList) { - cli->sendMsg(ResponseCode::TetheringStatsListResult, - stats.getStatsLine().c_str(), false); - } - cli->sendMsg(ResponseCode::CommandOkay, "Tethering stats list completed", false); - - return 0; + return statsList; } } // namespace net |
