Commit 3208ea0b authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Add support for multiple dhcp ranges.

We need multiple dhcp ranges to support dhcp on different interfaces.

bug:2533491
Change-Id: I3b568e81c048c6aff1a752ac4a81669034104413
parent 1caafe66
......@@ -324,17 +324,24 @@ int CommandListener::TetherCmd::runCommand(SocketClient *cli,
}
if (!strcmp(argv[1], "start")) {
struct in_addr s, e;
if (!inet_aton(argv[2], &s)) {
cli->sendMsg(ResponseCode::CommandParameterError, "Invalid start address", false);
if (argc % 2 == 1) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Bad number of arguments", false);
return 0;
}
if (!inet_aton(argv[3], &e)) {
cli->sendMsg(ResponseCode::CommandParameterError, "Invalid end address", false);
return 0;
int num_addrs = argc - 2;
int arg_index = 2;
int array_index = 0;
in_addr *addrs = (in_addr *)malloc(sizeof(in_addr) * num_addrs);
while (array_index < num_addrs) {
if (!inet_aton(argv[arg_index++], &(addrs[array_index++]))) {
cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false);
free(addrs);
return 0;
}
}
rc = sTetherCtrl->startTethering(s, e);
rc = sTetherCtrl->startTethering(num_addrs, addrs);
free(addrs);
} else if (!strcmp(argv[1], "interface")) {
if (!strcmp(argv[2], "add")) {
rc = sTetherCtrl->tetherInterface(argv[3]);
......
......@@ -86,8 +86,7 @@ bool TetherController::getIpFwdEnabled() {
return (enabled == '1' ? true : false);
}
int TetherController::startTethering(struct in_addr dhcpStart, struct in_addr dhcpEnd) {
int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
if (mDaemonPid != 0) {
LOGE("Tethering already started");
errno = EBUSY;
......@@ -124,17 +123,27 @@ int TetherController::startTethering(struct in_addr dhcpStart, struct in_addr dh
}
close(pipefd[0]);
}
char *start = strdup(inet_ntoa(dhcpStart));
char *end = strdup(inet_ntoa(dhcpEnd));
char *range;
asprintf(&range, "--dhcp-range=%s,%s,1h", start, end);
int num_processed_args = 4 + (num_addrs/2) + 1; // 1 null for termination
char **args = (char **)malloc(sizeof(char *) * num_processed_args);
args[num_processed_args - 1] = NULL;
args[0] = (char *)"/system/bin/dnsmasq";
args[1] = (char *)"--no-daemon";
args[2] = (char *)"--no-resolv";
args[3] = (char *)"--no-poll";
int nextArg = 4;
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);
}
if (execl("/system/bin/dnsmasq", "/system/bin/dnsmasq", "--no-daemon", "--no-resolv",
"--no-poll", "--no-hosts", range, (char *) NULL)) {
if (execv(args[0], args)) {
LOGE("execl failed (%s)", strerror(errno));
}
LOGE("Should never get here!");
free(args);
return 0;
} else {
close(pipefd[0]);
......@@ -237,4 +246,3 @@ int TetherController::untetherInterface(const char *interface) {
InterfaceCollection *TetherController::getTetheredInterfaceList() {
return mInterfaces;
}
......@@ -37,7 +37,8 @@ public:
int setIpFwdEnabled(bool enable);
bool getIpFwdEnabled();
int startTethering(struct in_addr dhcpStart, struct in_addr dhcpEnd);
int startTethering(int num_addrs, struct in_addr* addrs);
int stopTethering();
bool isTetheringStarted();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment