* 0 0 ACCEPT all -- wlan0 rmnet0 0.0.0.0/0 0.0.0.0/0
*
*/
-int BandwidthController::parseForwardChainStats(TetherStats &stats, FILE *fp) {
+int BandwidthController::parseForwardChainStats(TetherStats &stats, FILE *fp,
+ std::string &extraProcessingInfo) {
int res;
char lineBuffer[MAX_IPT_OUTPUT_LINE_LEN];
char iface0[MAX_IPT_OUTPUT_LINE_LEN];
&packets, &bytes, iface0, iface1, rest);
ALOGV("parse res=%d iface0=<%s> iface1=<%s> pkts=%lld bytes=%lld rest=<%s> orig line=<%s>", res,
iface0, iface1, packets, bytes, rest, buffPtr);
+ extraProcessingInfo += buffPtr;
+
if (res != 5) {
continue;
}
return msg;
}
-int BandwidthController::getTetherStats(TetherStats &stats) {
+int BandwidthController::getTetherStats(TetherStats &stats, std::string &extraProcessingInfo) {
int res;
std::string fullCmd;
FILE *iptOutput;
iptOutput = popen(fullCmd.c_str(), "r");
if (!iptOutput) {
LOGE("Failed to run %s err=%s", fullCmd.c_str(), strerror(errno));
+ extraProcessingInfo += "Failed to run iptables.";
return -1;
}
- res = parseForwardChainStats(stats, iptOutput);
+ res = parseForwardChainStats(stats, iptOutput, extraProcessingInfo);
pclose(iptOutput);
/* Currently NatController doesn't do ipv6 tethering, so we are done. */
* stats should have ifaceIn and ifaceOut initialized.
* Byte counts should be left to the default (-1).
*/
- int getTetherStats(TetherStats &stats);
+ int getTetherStats(TetherStats &stats, std::string &extraProcessingInfo);
protected:
class QuotaInfo {
/*
* stats should have ifaceIn and ifaceOut initialized.
* fp should be a file to the FORWARD rules of iptables.
+ * extraProcessingInfo: contains raw parsed data, and error info.
*/
- static int parseForwardChainStats(TetherStats &stats, FILE *fp);
+ static int parseForwardChainStats(TetherStats &stats, FILE *fp,
+ std::string &extraProcessingInfo);
/*------------------*/
}
if (!strcmp(argv[1], "gettetherstats") || !strcmp(argv[1], "gts")) {
BandwidthController::TetherStats tetherStats;
+ std::string extraProcessingInfo = "";
if (argc != 4) {
sendGenericSyntaxError(cli, "gettetherstats <interface0> <interface1>");
return 0;
tetherStats.ifaceIn = argv[2];
tetherStats.ifaceOut = argv[3];
- int rc = sBandwidthCtrl->getTetherStats(tetherStats);
+ int rc = sBandwidthCtrl->getTetherStats(tetherStats, extraProcessingInfo);
if (rc) {
- sendGenericOpFailed(cli, "Failed to get tethering stats");
+ extraProcessingInfo.insert(0, "Failed to get tethering stats.\n");
+ sendGenericOpFailed(cli, extraProcessingInfo.c_str());
return 0;
}