Allow starting dnsmasq without DHCP
dnsmasq will not start DHCP if no --dhcp-range flag is set. Allow
tethering start command to be called without DHCP ranges, so dnsmasq can
be started without this flag.
Bug: b/109584964
Test: manual: flashed a build with no --dhcp-range flag
Change-Id: I109f64240690aef701deabd49120eab0aba0e8a8
diff --git a/server/CommandListener.cpp b/server/CommandListener.cpp
index 3730bce..e3c1743 100644
--- a/server/CommandListener.cpp
+++ b/server/CommandListener.cpp
@@ -446,6 +446,24 @@
cli->sendMsg(ResponseCode::TetherDnsFwdTgtListResult, fwdr.c_str(), false);
}
}
+ } else if (!strcmp(argv[1], "start")) {
+ if (argc % 2 == 1) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError, "Bad number of arguments", false);
+ return 0;
+ }
+
+ const int num_addrs = argc - 2;
+ // TODO: consider moving this validation into TetherController.
+ struct in_addr tmp_addr;
+ for (int arg_index = 2; arg_index < argc; arg_index++) {
+ if (!inet_aton(argv[arg_index], &tmp_addr)) {
+ cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false);
+ return 0;
+ }
+ }
+
+ char** dhcp_ranges = num_addrs == 0 ? NULL : argv + 2;
+ rc = gCtls->tetherCtrl.startTethering(num_addrs, dhcp_ranges);
} else {
/*
* These commands take a minimum of 4 arguments
@@ -455,24 +473,7 @@
return 0;
}
- if (!strcmp(argv[1], "start")) {
- if (argc % 2 == 1) {
- cli->sendMsg(ResponseCode::CommandSyntaxError, "Bad number of arguments", false);
- return 0;
- }
-
- const int num_addrs = argc - 2;
- // TODO: consider moving this validation into TetherController.
- struct in_addr tmp_addr;
- for (int arg_index = 2; arg_index < argc; arg_index++) {
- if (!inet_aton(argv[arg_index], &tmp_addr)) {
- cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false);
- return 0;
- }
- }
-
- rc = gCtls->tetherCtrl.startTethering(num_addrs, &(argv[2]));
- } else if (!strcmp(argv[1], "interface")) {
+ if (!strcmp(argv[1], "interface")) {
if (!strcmp(argv[2], "add")) {
rc = gCtls->tetherCtrl.tetherInterface(argv[3]);
} else if (!strcmp(argv[2], "remove")) {
diff --git a/server/TetherController.cpp b/server/TetherController.cpp
index c7f3042..0ca1b77 100644
--- a/server/TetherController.cpp
+++ b/server/TetherController.cpp
@@ -247,10 +247,10 @@
"--user", kDnsmasqUsername,
};
+ // DHCP server will be disabled if num_addrs == 0 and no --dhcp-range is passed.
for (int addrIndex = 0; addrIndex < num_addrs; addrIndex += 2) {
- argVector.push_back(
- StringPrintf("--dhcp-range=%s,%s,1h",
- dhcp_ranges[addrIndex], dhcp_ranges[addrIndex+1]));
+ argVector.push_back(StringPrintf("--dhcp-range=%s,%s,1h", dhcp_ranges[addrIndex],
+ dhcp_ranges[addrIndex + 1]));
}
auto args = (char**)std::calloc(argVector.size() + 1, sizeof(char*));