Nat-related commands porting
Test: built, flashed, booted
system/netd/tests/runtests.sh passes
Change-Id: I14e80377bc1b7c08993c3cf8fbf2b6fd0f99f4ba
diff --git a/server/BandwidthController.cpp b/server/BandwidthController.cpp
index 6a40ba2..e0dc25e 100644
--- a/server/BandwidthController.cpp
+++ b/server/BandwidthController.cpp
@@ -652,12 +652,13 @@
int BandwidthController::setGlobalAlert(int64_t bytes) {
const char *alertName = ALERT_GLOBAL_NAME;
- int res = 0;
if (!bytes) {
ALOGE("Invalid bytes value. 1..max_int64.");
return -ERANGE;
}
+
+ int res = 0;
if (mGlobalAlertBytes) {
res = updateQuota(alertName, bytes);
} else {
@@ -676,7 +677,6 @@
int BandwidthController::setGlobalAlertInForwardChain() {
const char *alertName = ALERT_GLOBAL_NAME;
- int res = 0;
mGlobalAlertTetherCount++;
ALOGV("setGlobalAlertInForwardChain(): %d tether", mGlobalAlertTetherCount);
@@ -691,19 +691,20 @@
}
/* We only add the rule if this was the 1st tether added. */
- res = runIptablesAlertFwdCmd(IptOpInsert, alertName, mGlobalAlertBytes);
- return res;
+ return (runIptablesAlertFwdCmd(IptOpInsert, alertName, mGlobalAlertBytes) == 0) ? 0
+ : -EREMOTEIO;
}
int BandwidthController::removeGlobalAlert() {
const char *alertName = ALERT_GLOBAL_NAME;
- int res = 0;
if (!mGlobalAlertBytes) {
ALOGE("No prior alert set");
return -1;
}
+
+ int res = 0;
res = runIptablesAlertCmd(IptOpDelete, alertName, mGlobalAlertBytes);
if (mGlobalAlertTetherCount) {
res |= runIptablesAlertFwdCmd(IptOpDelete, alertName, mGlobalAlertBytes);
@@ -713,12 +714,11 @@
}
int BandwidthController::removeGlobalAlertInForwardChain() {
- int res = 0;
const char *alertName = ALERT_GLOBAL_NAME;
if (!mGlobalAlertTetherCount) {
ALOGE("No prior alert set");
- return -1;
+ return -ENOENT;
}
mGlobalAlertTetherCount--;
@@ -732,8 +732,8 @@
}
/* We only detete the rule if this was the last tether removed. */
- res = runIptablesAlertFwdCmd(IptOpDelete, alertName, mGlobalAlertBytes);
- return res;
+ return (runIptablesAlertFwdCmd(IptOpDelete, alertName, mGlobalAlertBytes) == 0) ? 0
+ : -EREMOTEIO;
}
int BandwidthController::setSharedAlert(int64_t bytes) {