#include <android-base/stringprintf.h>
#include <cutils/log.h>
+#include <cutils/properties.h>
#include <utils/Errors.h>
#include <utils/String16.h>
#include "Controllers.h"
#include "DumpWriter.h"
+#include "EventReporter.h"
+#include "InterfaceController.h"
#include "NetdConstants.h"
#include "NetdNativeService.h"
#include "RouteController.h"
}
}
+#define ENFORCE_DEBUGGABLE() { \
+ char value[PROPERTY_VALUE_MAX + 1]; \
+ if (property_get("ro.debuggable", value, NULL) != 1 \
+ || value[0] != '1') { \
+ return binder::Status::fromExceptionCode( \
+ binder::Status::EX_SECURITY, \
+ String8("Not available in production builds.") \
+ ); \
+ } \
+}
+
#define ENFORCE_PERMISSION(permission) { \
binder::Status status = checkPermission((permission)); \
if (!status.isOk()) { \
return binder::Status::ok();
}
+binder::Status NetdNativeService::interfaceAddAddress(const std::string &ifName,
+ const std::string &addrString, int prefixLength) {
+ ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+
+ const int err = InterfaceController::addAddress(
+ ifName.c_str(), addrString.c_str(), prefixLength);
+ if (err != 0) {
+ return binder::Status::fromServiceSpecificError(-err,
+ String8::format("InterfaceController error: %s", strerror(-err)));
+ }
+ return binder::Status::ok();
+}
+
+binder::Status NetdNativeService::interfaceDelAddress(const std::string &ifName,
+ const std::string &addrString, int prefixLength) {
+ ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+
+ const int err = InterfaceController::delAddress(
+ ifName.c_str(), addrString.c_str(), prefixLength);
+ if (err != 0) {
+ return binder::Status::fromServiceSpecificError(-err,
+ String8::format("InterfaceController error: %s", strerror(-err)));
+ }
+ return binder::Status::ok();
+}
+
+binder::Status NetdNativeService::setProcSysNet(
+ int32_t family, int32_t which, const std::string &ifname, const std::string ¶meter,
+ const std::string &value) {
+ ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+
+ const char *familyStr;
+ switch (family) {
+ case INetd::IPV4:
+ familyStr = "ipv4";
+ break;
+ case INetd::IPV6:
+ familyStr = "ipv6";
+ break;
+ default:
+ return binder::Status::fromServiceSpecificError(EAFNOSUPPORT, String8("Bad family"));
+ }
+
+ const char *whichStr;
+ switch (which) {
+ case INetd::CONF:
+ whichStr = "conf";
+ break;
+ case INetd::NEIGH:
+ whichStr = "neigh";
+ break;
+ default:
+ return binder::Status::fromServiceSpecificError(EINVAL, String8("Bad category"));
+ }
+
+ const int err = InterfaceController::setParameter(
+ familyStr, whichStr, ifname.c_str(), parameter.c_str(),
+ value.c_str());
+ if (err != 0) {
+ return binder::Status::fromServiceSpecificError(-err,
+ String8::format("ResolverController error: %s", strerror(-err)));
+ }
+ return binder::Status::ok();
+}
+
+binder::Status NetdNativeService::getMetricsReportingLevel(int *reportingLevel) {
+ // This function intentionally does not lock, since the only thing it does is one read from an
+ // atomic_int.
+ ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+ ENFORCE_DEBUGGABLE();
+
+ *reportingLevel = gCtls->eventReporter.getMetricsReportingLevel();
+ return binder::Status::ok();
+}
+
+binder::Status NetdNativeService::setMetricsReportingLevel(const int reportingLevel) {
+ // This function intentionally does not lock, since the only thing it does is one write to an
+ // atomic_int.
+ ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+ ENFORCE_DEBUGGABLE();
+
+ return (gCtls->eventReporter.setMetricsReportingLevel(reportingLevel) == 0)
+ ? binder::Status::ok()
+ : binder::Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT);
+}
+
} // namespace net
} // namespace android