resolved conflicts for merge of 80adaddf to master
Change-Id: I53c036b229352430c3faf57ce1d02fa889827690
diff --git a/Android.mk b/Android.mk
index 3f4f5dd..8045ad7 100644
--- a/Android.mk
+++ b/Android.mk
@@ -19,6 +19,7 @@
NetlinkManager.cpp \
PanController.cpp \
PppController.cpp \
+ ResolverController.cpp \
SoftapController.cpp \
TetherController.cpp \
ThrottleController.cpp \
@@ -26,7 +27,6 @@
main.cpp \
-
LOCAL_MODULE:= netd
LOCAL_C_INCLUDES := $(KERNEL_HEADERS) \
diff --git a/CommandListener.cpp b/CommandListener.cpp
index f1ee7ec..9236605 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -54,6 +54,7 @@
PanController *CommandListener::sPanCtrl = NULL;
SoftapController *CommandListener::sSoftapCtrl = NULL;
BandwidthController * CommandListener::sBandwidthCtrl = NULL;
+ResolverController *CommandListener::sResolverCtrl = NULL;
CommandListener::CommandListener() :
FrameworkListener("netd") {
@@ -66,6 +67,7 @@
registerCmd(new PanCmd());
registerCmd(new SoftapCmd());
registerCmd(new BandwidthControlCmd());
+ registerCmd(new ResolverCmd());
if (!sTetherCtrl)
sTetherCtrl = new TetherController();
@@ -79,6 +81,8 @@
sSoftapCtrl = new SoftapController();
if (!sBandwidthCtrl)
sBandwidthCtrl = new BandwidthController();
+ if (!sResolverCtrl)
+ sResolverCtrl = new ResolverController();
}
CommandListener::InterfaceCmd::InterfaceCmd() :
@@ -696,6 +700,75 @@
return 0;
}
+CommandListener::ResolverCmd::ResolverCmd() :
+ NetdCommand("resolver") {
+}
+
+int CommandListener::ResolverCmd::runCommand(SocketClient *cli, int argc, char **argv) {
+ int rc = 0;
+ struct in_addr addr;
+
+ if (argc < 2) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError, "Resolver missing arguments", false);
+ return 0;
+ }
+
+ if (!strcmp(argv[1], "setdefaultif")) { // "resolver setdefaultif <iface>"
+ if (argc == 3) {
+ rc = sResolverCtrl->setDefaultInterface(argv[2]);
+ } else {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Wrong number of arguments to resolver setdefaultif", false);
+ return 0;
+ }
+ } else if (!strcmp(argv[1], "setifdns")) { // "resolver setifdns <iface> <dns1> <dns2> ..."
+ if (argc >= 4) {
+ rc = sResolverCtrl->setInterfaceDnsServers(argv[2], &argv[3], argc - 3);
+ } else {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Wrong number of arguments to resolver setifdns", false);
+ return 0;
+ }
+
+ // set the address of the interface to which the name servers
+ // are bound. Required in order to bind to right interface when
+ // doing the dns query.
+ if (!rc) {
+ ifc_init();
+ ifc_get_info(argv[2], &addr.s_addr, NULL, 0);
+
+ rc = sResolverCtrl->setInterfaceAddress(argv[2], &addr);
+ }
+ } else if (!strcmp(argv[1], "flushdefaultif")) { // "resolver flushdefaultif"
+ if (argc == 2) {
+ rc = sResolverCtrl->flushDefaultDnsCache();
+ } else {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Wrong number of arguments to resolver flushdefaultif", false);
+ return 0;
+ }
+ } else if (!strcmp(argv[1], "flushif")) { // "resolver flushif <iface>"
+ if (argc == 3) {
+ rc = sResolverCtrl->flushInterfaceDnsCache(argv[2]);
+ } else {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Wrong number of arguments to resolver setdefaultif", false);
+ return 0;
+ }
+ } else {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,"Resolver unknown command", false);
+ return 0;
+ }
+
+ if (!rc) {
+ cli->sendMsg(ResponseCode::CommandOkay, "Resolver command succeeded", false);
+ } else {
+ cli->sendMsg(ResponseCode::OperationFailed, "Resolver command failed", true);
+ }
+
+ return 0;
+}
+
int CommandListener::readInterfaceCounters(const char *iface, unsigned long *rx, unsigned long *tx) {
FILE *fp = fopen("/proc/net/dev", "r");
if (!fp) {
diff --git a/CommandListener.h b/CommandListener.h
index d3be025..05e990e 100644
--- a/CommandListener.h
+++ b/CommandListener.h
@@ -26,6 +26,7 @@
#include "PanController.h"
#include "SoftapController.h"
#include "BandwidthController.h"
+#include "ResolverController.h"
class CommandListener : public FrameworkListener {
static TetherController *sTetherCtrl;
@@ -34,6 +35,7 @@
static PanController *sPanCtrl;
static SoftapController *sSoftapCtrl;
static BandwidthController *sBandwidthCtrl;
+ static ResolverController *sResolverCtrl;
public:
CommandListener();
@@ -105,6 +107,13 @@
virtual ~BandwidthControlCmd() {}
int runCommand(SocketClient *c, int argc, char ** argv);
};
+
+ class ResolverCmd : public NetdCommand {
+ public:
+ ResolverCmd();
+ virtual ~ResolverCmd() {}
+ int runCommand(SocketClient *c, int argc, char ** argv);
+ };
};
#endif
diff --git a/ResolverController.cpp b/ResolverController.cpp
new file mode 100644
index 0000000..b079f81
--- /dev/null
+++ b/ResolverController.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "ResolverController"
+#define DBG 0
+
+#include <cutils/log.h>
+
+#include <linux/if.h>
+#include <resolv.h>
+
+#include "ResolverController.h"
+
+int ResolverController::setDefaultInterface(const char* iface) {
+ if (DBG) {
+ LOGD("setDefaultInterface iface = %s\n", iface);
+ }
+
+ _resolv_set_default_iface(iface);
+
+ return 0;
+}
+
+int ResolverController::setInterfaceDnsServers(const char* iface, char** servers, int numservers) {
+ if (DBG) {
+ LOGD("setInterfaceDnsServers iface = %s\n", iface);
+ }
+
+ _resolv_set_nameservers_for_iface(iface, servers, numservers);
+
+ return 0;
+}
+
+int ResolverController::setInterfaceAddress(const char* iface, struct in_addr* addr) {
+ if (DBG) {
+ LOGD("setInterfaceAddress iface = %s\n", iface);
+ }
+
+ _resolv_set_addr_of_iface(iface, addr);
+
+ return 0;
+}
+
+int ResolverController::flushDefaultDnsCache() {
+ if (DBG) {
+ LOGD("flushDefaultDnsCache\n");
+ }
+
+ _resolv_flush_cache_for_default_iface();
+
+ return 0;
+}
+
+int ResolverController::flushInterfaceDnsCache(const char* iface) {
+ if (DBG) {
+ LOGD("flushInterfaceDnsCache iface = %s\n", iface);
+ }
+
+ _resolv_flush_cache_for_iface(iface);
+
+ return 0;
+}
diff --git a/ResolverController.h b/ResolverController.h
new file mode 100644
index 0000000..c6260da
--- /dev/null
+++ b/ResolverController.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _RESOLVER_CONTROLLER_H_
+#define _RESOLVER_CONTROLLER_H_
+
+#include <netinet/in.h>
+#include <linux/in.h>
+
+class ResolverController {
+public:
+ ResolverController() {};
+ virtual ~ResolverController() {};
+
+ int setDefaultInterface(const char* iface);
+ int setInterfaceDnsServers(const char* iface, char** servers, int numservers);
+ int setInterfaceAddress(const char* iface, struct in_addr* addr);
+ int flushDefaultDnsCache();
+ int flushInterfaceDnsCache(const char* iface);
+};
+
+#endif /* _RESOLVER_CONTROLLER_H_ */