Inform dnsmasq of the downstream ifaces.
This lets it filter the dns requests so we're not a public dns forwarder/spambot.
bug:7530468
Change-Id: I102fad738aff717e6ac40d4ac5a8d39a6fe2d2ca
diff --git a/TetherController.cpp b/TetherController.cpp
index cb48dbc..d067f11 100644
--- a/TetherController.cpp
+++ b/TetherController.cpp
@@ -163,6 +163,7 @@
close(pipefd[0]);
mDaemonPid = pid;
mDaemonFd = pipefd[1];
+ applyDnsInterfaces();
ALOGD("Tethering services running");
}
@@ -216,11 +217,11 @@
char *args[10];
int argc = 0;
- args[argc++] = "/system/bin/dhcpcd";
+ args[argc++] = (char *)"/system/bin/dhcpcd";
char host_name[128];
if (property_get("net.hostname", host_name, NULL) && (host_name[0] != '\0'))
{
- args[argc++] = "-h";
+ args[argc++] = (char *)"-h";
args[argc++] = host_name;
}
args[argc++] = (char*)iface;
@@ -307,19 +308,67 @@
return mDnsForwarders;
}
-int TetherController::tetherInterface(const char *interface) {
- mInterfaces->push_back(strdup(interface));
+int TetherController::applyDnsInterfaces() {
+ int i;
+ char daemonCmd[MAX_CMD_SIZE];
+
+ strcpy(daemonCmd, "update_ifaces");
+ int cmdLen = strlen(daemonCmd);
+ InterfaceCollection::iterator it;
+ bool haveInterfaces = false;
+
+ for (it = mInterfaces->begin(); it != mInterfaces->end(); ++it) {
+ cmdLen += (strlen(*it) + 1);
+ if (cmdLen + 1 >= MAX_CMD_SIZE) {
+ ALOGD("Too many DNS ifaces listed");
+ break;
+ }
+
+ strcat(daemonCmd, ":");
+ strcat(daemonCmd, *it);
+ haveInterfaces = true;
+ }
+
+ if ((mDaemonFd != -1) && haveInterfaces) {
+ ALOGD("Sending update msg to dnsmasq [%s]", daemonCmd);
+ if (write(mDaemonFd, daemonCmd, strlen(daemonCmd) +1) < 0) {
+ ALOGE("Failed to send update command to dnsmasq (%s)", strerror(errno));
+ return -1;
+ }
+ }
return 0;
}
+int TetherController::tetherInterface(const char *interface) {
+ ALOGD("tetherInterface(%s)", interface);
+ mInterfaces->push_back(strdup(interface));
+
+ if (applyDnsInterfaces()) {
+ InterfaceCollection::iterator it;
+ for (it = mInterfaces->begin(); it != mInterfaces->end(); ++it) {
+ if (!strcmp(interface, *it)) {
+ free(*it);
+ mInterfaces->erase(it);
+ break;
+ }
+ }
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
int TetherController::untetherInterface(const char *interface) {
InterfaceCollection::iterator it;
+ ALOGD("untetherInterface(%s)", interface);
+
for (it = mInterfaces->begin(); it != mInterfaces->end(); ++it) {
if (!strcmp(interface, *it)) {
free(*it);
mInterfaces->erase(it);
- return 0;
+
+ return applyDnsInterfaces();
}
}
errno = ENOENT;
diff --git a/TetherController.h b/TetherController.h
index d3106eb..02cd412 100644
--- a/TetherController.h
+++ b/TetherController.h
@@ -52,6 +52,9 @@
int tetherInterface(const char *interface);
int untetherInterface(const char *interface);
InterfaceCollection *getTetheredInterfaceList();
+
+private:
+ int applyDnsInterfaces();
};
#endif