Change dnsmasq input command argument separator
Heretofore netd issued commands to dnsmasq over a stdin channel
using ":" as an argument separator. This make it very complicated
to issue commands that involve IPv6 addresses.
This changes the separator from ":" to "|".
Additionally:
- Pass DHCP range string literals through to startTethering(),
still performing string literal to IPv4 address validation.
Bug: 9580643
Change-Id: I210daf311a4c3d84dae3ed054b92c9fa399a791f
diff --git a/server/TetherController.cpp b/server/TetherController.cpp
index 88baa31..3b6d0fb 100644
--- a/server/TetherController.cpp
+++ b/server/TetherController.cpp
@@ -41,6 +41,7 @@
static const char BP_TOOLS_MODE[] = "bp-tools";
static const char IPV4_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv4/ip_forward";
static const char IPV6_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv6/conf/all/forwarding";
+static const char SEPARATOR[] = "|";
bool writeToFile(const char* filename, const char* value) {
int fd = open(filename, O_WRONLY);
@@ -121,7 +122,7 @@
#define TETHER_START_CONST_ARG 8
-int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
+int TetherController::startTethering(int num_addrs, char **dhcp_ranges) {
if (mDaemonPid != 0) {
ALOGE("Tethering already started");
errno = EBUSY;
@@ -173,12 +174,9 @@
args[7] = (char *)"";
int nextArg = TETHER_START_CONST_ARG;
- for (int addrIndex=0; addrIndex < num_addrs;) {
- char *start = strdup(inet_ntoa(addrs[addrIndex++]));
- char *end = strdup(inet_ntoa(addrs[addrIndex++]));
- asprintf(&(args[nextArg++]),"--dhcp-range=%s,%s,1h", start, end);
- free(start);
- free(end);
+ for (int addrIndex = 0; addrIndex < num_addrs; addrIndex += 2) {
+ asprintf(&(args[nextArg++]),"--dhcp-range=%s,%s,1h",
+ dhcp_ranges[addrIndex], dhcp_ranges[addrIndex+1]);
}
if (execv(args[0], args)) {
@@ -231,7 +229,7 @@
fwmark.protectedFromVpn = true;
fwmark.permission = PERMISSION_SYSTEM;
- snprintf(daemonCmd, sizeof(daemonCmd), "update_dns:0x%x", fwmark.intValue);
+ snprintf(daemonCmd, sizeof(daemonCmd), "update_dns%s0x%x", SEPARATOR, fwmark.intValue);
int cmdLen = strlen(daemonCmd);
mDnsForwarders->clear();
@@ -252,7 +250,7 @@
break;
}
- strcat(daemonCmd, ":");
+ strcat(daemonCmd, SEPARATOR);
strcat(daemonCmd, servers[i]);
mDnsForwarders->push_back(a);
}
@@ -292,7 +290,7 @@
break;
}
- strcat(daemonCmd, ":");
+ strcat(daemonCmd, SEPARATOR);
strcat(daemonCmd, *it);
haveInterfaces = true;
}