CommandListener.cpp revision 7e9eb7b48345af69283afa7ca58d3be0a329931b
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17// #define LOG_NDEBUG 0 18 19#include <stdlib.h> 20#include <sys/socket.h> 21#include <sys/types.h> 22#include <netinet/in.h> 23#include <arpa/inet.h> 24#include <dirent.h> 25#include <errno.h> 26#include <string.h> 27#include <fcntl.h> 28#include <linux/if.h> 29 30#define LOG_TAG "CommandListener" 31 32#include <cutils/log.h> 33#include <netutils/ifc.h> 34#include <sysutils/SocketClient.h> 35 36#include "CommandListener.h" 37#include "ResponseCode.h" 38#include "ThrottleController.h" 39#include "BandwidthController.h" 40#include "IdletimerController.h" 41#include "SecondaryTableController.h" 42#include "oem_iptables_hook.h" 43 44 45TetherController *CommandListener::sTetherCtrl = NULL; 46NatController *CommandListener::sNatCtrl = NULL; 47PppController *CommandListener::sPppCtrl = NULL; 48PanController *CommandListener::sPanCtrl = NULL; 49SoftapController *CommandListener::sSoftapCtrl = NULL; 50BandwidthController * CommandListener::sBandwidthCtrl = NULL; 51IdletimerController * CommandListener::sIdletimerCtrl = NULL; 52ResolverController *CommandListener::sResolverCtrl = NULL; 53SecondaryTableController *CommandListener::sSecondaryTableCtrl = NULL; 54 55CommandListener::CommandListener() : 56 FrameworkListener("netd", true) { 57 registerCmd(new InterfaceCmd()); 58 registerCmd(new IpFwdCmd()); 59 registerCmd(new TetherCmd()); 60 registerCmd(new NatCmd()); 61 registerCmd(new ListTtysCmd()); 62 registerCmd(new PppdCmd()); 63 registerCmd(new PanCmd()); 64 registerCmd(new SoftapCmd()); 65 registerCmd(new BandwidthControlCmd()); 66 registerCmd(new IdletimerControlCmd()); 67 registerCmd(new ResolverCmd()); 68 69 if (!sSecondaryTableCtrl) 70 sSecondaryTableCtrl = new SecondaryTableController(); 71 if (!sTetherCtrl) 72 sTetherCtrl = new TetherController(); 73 if (!sNatCtrl) 74 sNatCtrl = new NatController(sSecondaryTableCtrl); 75 if (!sPppCtrl) 76 sPppCtrl = new PppController(); 77 if (!sPanCtrl) 78 sPanCtrl = new PanController(); 79 if (!sSoftapCtrl) 80 sSoftapCtrl = new SoftapController(); 81 if (!sBandwidthCtrl) 82 sBandwidthCtrl = new BandwidthController(); 83 if (!sIdletimerCtrl) 84 sIdletimerCtrl = new IdletimerController(); 85 if (!sResolverCtrl) 86 sResolverCtrl = new ResolverController(); 87 88 /* 89 * This is the only time controllers are allowed to touch 90 * top-level chains in iptables. 91 * Each controller should setup custom chains and hook them into 92 * the top-level ones. 93 * THE ORDER IS IMPORTANT. TRIPPLE CHECK EACH setup function. 94 */ 95 /* Does DROP in nat: PREROUTING, FORWARD, OUTPUT */ 96 setupOemIptablesHook(); 97 /* Does DROPs in FORWARD by default */ 98 sNatCtrl->setupIptablesHooks(); 99 /* 100 * Does REJECT in INPUT, OUTPUT. Does counting also. 101 * No DROP/REJECT allowed later in netfilter-flow hook order. 102 */ 103 sBandwidthCtrl->setupIptablesHooks(); 104 /* 105 * Counts in nat: PREROUTING, POSTROUTING. 106 * No DROP/REJECT allowed later in netfilter-flow hook order. 107 */ 108 sIdletimerCtrl->setupIptablesHooks(); 109 110 sBandwidthCtrl->enableBandwidthControl(false); 111} 112 113CommandListener::InterfaceCmd::InterfaceCmd() : 114 NetdCommand("interface") { 115} 116 117int CommandListener::writeFile(const char *path, const char *value, int size) { 118 int fd = open(path, O_WRONLY); 119 if (fd < 0) { 120 ALOGE("Failed to open %s: %s", path, strerror(errno)); 121 return -1; 122 } 123 124 if (write(fd, value, size) != size) { 125 ALOGE("Failed to write %s: %s", path, strerror(errno)); 126 close(fd); 127 return -1; 128 } 129 close(fd); 130 return 0; 131} 132 133int CommandListener::InterfaceCmd::runCommand(SocketClient *cli, 134 int argc, char **argv) { 135 if (argc < 2) { 136 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 137 return 0; 138 } 139 140 if (!strcmp(argv[1], "list")) { 141 DIR *d; 142 struct dirent *de; 143 144 if (!(d = opendir("/sys/class/net"))) { 145 cli->sendMsg(ResponseCode::OperationFailed, "Failed to open sysfs dir", true); 146 return 0; 147 } 148 149 while((de = readdir(d))) { 150 if (de->d_name[0] == '.') 151 continue; 152 cli->sendMsg(ResponseCode::InterfaceListResult, de->d_name, false); 153 } 154 closedir(d); 155 cli->sendMsg(ResponseCode::CommandOkay, "Interface list completed", false); 156 return 0; 157 } else if (!strcmp(argv[1], "readrxcounter")) { 158 if (argc != 3) { 159 cli->sendMsg(ResponseCode::CommandSyntaxError, 160 "Usage: interface readrxcounter <interface>", false); 161 return 0; 162 } 163 unsigned long rx = 0, tx = 0; 164 if (readInterfaceCounters(argv[2], &rx, &tx)) { 165 cli->sendMsg(ResponseCode::OperationFailed, "Failed to read counters", true); 166 return 0; 167 } 168 169 char *msg; 170 asprintf(&msg, "%lu", rx); 171 cli->sendMsg(ResponseCode::InterfaceRxCounterResult, msg, false); 172 free(msg); 173 174 return 0; 175 } else if (!strcmp(argv[1], "readtxcounter")) { 176 if (argc != 3) { 177 cli->sendMsg(ResponseCode::CommandSyntaxError, 178 "Usage: interface readtxcounter <interface>", false); 179 return 0; 180 } 181 unsigned long rx = 0, tx = 0; 182 if (readInterfaceCounters(argv[2], &rx, &tx)) { 183 cli->sendMsg(ResponseCode::OperationFailed, "Failed to read counters", true); 184 return 0; 185 } 186 187 char *msg = NULL; 188 asprintf(&msg, "%lu", tx); 189 cli->sendMsg(ResponseCode::InterfaceTxCounterResult, msg, false); 190 free(msg); 191 return 0; 192 } else if (!strcmp(argv[1], "getthrottle")) { 193 if (argc != 4 || (argc == 4 && (strcmp(argv[3], "rx") && (strcmp(argv[3], "tx"))))) { 194 cli->sendMsg(ResponseCode::CommandSyntaxError, 195 "Usage: interface getthrottle <interface> <rx|tx>", false); 196 return 0; 197 } 198 int val = 0; 199 int rc = 0; 200 int voldRc = ResponseCode::InterfaceRxThrottleResult; 201 202 if (!strcmp(argv[3], "rx")) { 203 rc = ThrottleController::getInterfaceRxThrottle(argv[2], &val); 204 } else { 205 rc = ThrottleController::getInterfaceTxThrottle(argv[2], &val); 206 voldRc = ResponseCode::InterfaceTxThrottleResult; 207 } 208 if (rc) { 209 cli->sendMsg(ResponseCode::OperationFailed, "Failed to get throttle", true); 210 } else { 211 char *msg = NULL; 212 asprintf(&msg, "%u", val); 213 cli->sendMsg(voldRc, msg, false); 214 free(msg); 215 return 0; 216 } 217 return 0; 218 } else if (!strcmp(argv[1], "setthrottle")) { 219 if (argc != 5) { 220 cli->sendMsg(ResponseCode::CommandSyntaxError, 221 "Usage: interface setthrottle <interface> <rx_kbps> <tx_kbps>", false); 222 return 0; 223 } 224 if (ThrottleController::setInterfaceThrottle(argv[2], atoi(argv[3]), atoi(argv[4]))) { 225 cli->sendMsg(ResponseCode::OperationFailed, "Failed to set throttle", true); 226 } else { 227 cli->sendMsg(ResponseCode::CommandOkay, "Interface throttling set", false); 228 } 229 return 0; 230 } else { 231 /* 232 * These commands take a minimum of 3 arguments 233 */ 234 if (argc < 3) { 235 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 236 return 0; 237 } 238 239 // 0 1 2 3 4 5 6 7 240 // interface route add/remove iface default/secondary dest prefix gateway 241 if (!strcmp(argv[1], "route")) { 242 int prefix_length = 0; 243 if (argc < 8) { 244 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 245 return 0; 246 } 247 if (sscanf(argv[6], "%d", &prefix_length) != 1) { 248 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid route prefix", false); 249 return 0; 250 } 251 if (!strcmp(argv[2], "add")) { 252 if (!strcmp(argv[4], "default")) { 253 if (ifc_add_route(argv[3], argv[5], prefix_length, argv[7])) { 254 cli->sendMsg(ResponseCode::OperationFailed, 255 "Failed to add route to default table", true); 256 } else { 257 cli->sendMsg(ResponseCode::CommandOkay, 258 "Route added to default table", false); 259 } 260 } else if (!strcmp(argv[4], "secondary")) { 261 return sSecondaryTableCtrl->addRoute(cli, argv[3], argv[5], 262 prefix_length, argv[7]); 263 } else { 264 cli->sendMsg(ResponseCode::CommandParameterError, 265 "Invalid route type, expecting 'default' or 'secondary'", false); 266 return 0; 267 } 268 } else if (!strcmp(argv[2], "remove")) { 269 if (!strcmp(argv[4], "default")) { 270 if (ifc_remove_route(argv[3], argv[5], prefix_length, argv[7])) { 271 cli->sendMsg(ResponseCode::OperationFailed, 272 "Failed to remove route from default table", true); 273 } else { 274 cli->sendMsg(ResponseCode::CommandOkay, 275 "Route removed from default table", false); 276 } 277 } else if (!strcmp(argv[4], "secondary")) { 278 return sSecondaryTableCtrl->removeRoute(cli, argv[3], argv[5], 279 prefix_length, argv[7]); 280 } else { 281 cli->sendMsg(ResponseCode::CommandParameterError, 282 "Invalid route type, expecting 'default' or 'secondary'", false); 283 return 0; 284 } 285 } else { 286 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown interface cmd", false); 287 } 288 return 0; 289 } 290 291 if (!strcmp(argv[1], "getcfg")) { 292 struct in_addr addr; 293 int prefixLength; 294 unsigned char hwaddr[6]; 295 unsigned flags = 0; 296 297 ifc_init(); 298 memset(hwaddr, 0, sizeof(hwaddr)); 299 300 if (ifc_get_info(argv[2], &addr.s_addr, &prefixLength, &flags)) { 301 cli->sendMsg(ResponseCode::OperationFailed, "Interface not found", true); 302 ifc_close(); 303 return 0; 304 } 305 306 if (ifc_get_hwaddr(argv[2], (void *) hwaddr)) { 307 ALOGW("Failed to retrieve HW addr for %s (%s)", argv[2], strerror(errno)); 308 } 309 310 char *addr_s = strdup(inet_ntoa(addr)); 311 const char *updown, *brdcst, *loopbk, *ppp, *running, *multi; 312 313 updown = (flags & IFF_UP) ? "up" : "down"; 314 brdcst = (flags & IFF_BROADCAST) ? " broadcast" : ""; 315 loopbk = (flags & IFF_LOOPBACK) ? " loopback" : ""; 316 ppp = (flags & IFF_POINTOPOINT) ? " point-to-point" : ""; 317 running = (flags & IFF_RUNNING) ? " running" : ""; 318 multi = (flags & IFF_MULTICAST) ? " multicast" : ""; 319 320 char *flag_s; 321 322 asprintf(&flag_s, "%s%s%s%s%s%s", updown, brdcst, loopbk, ppp, running, multi); 323 324 char *msg = NULL; 325 asprintf(&msg, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x %s %d %s", 326 hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5], 327 addr_s, prefixLength, flag_s); 328 329 cli->sendMsg(ResponseCode::InterfaceGetCfgResult, msg, false); 330 331 free(addr_s); 332 free(flag_s); 333 free(msg); 334 335 ifc_close(); 336 return 0; 337 } else if (!strcmp(argv[1], "setcfg")) { 338 // arglist: iface addr prefixLength flags 339 if (argc < 5) { 340 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 341 return 0; 342 } 343 ALOGD("Setting iface cfg"); 344 345 struct in_addr addr; 346 unsigned flags = 0; 347 348 if (!inet_aton(argv[3], &addr)) { 349 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false); 350 return 0; 351 } 352 353 ifc_init(); 354 if (ifc_set_addr(argv[2], addr.s_addr)) { 355 cli->sendMsg(ResponseCode::OperationFailed, "Failed to set address", true); 356 ifc_close(); 357 return 0; 358 } 359 360 //Set prefix length on a non zero address 361 if (addr.s_addr != 0 && ifc_set_prefixLength(argv[2], atoi(argv[4]))) { 362 cli->sendMsg(ResponseCode::OperationFailed, "Failed to set prefixLength", true); 363 ifc_close(); 364 return 0; 365 } 366 367 /* Process flags */ 368 for (int i = 5; i < argc; i++) { 369 char *flag = argv[i]; 370 if (!strcmp(flag, "up")) { 371 ALOGD("Trying to bring up %s", argv[2]); 372 if (ifc_up(argv[2])) { 373 ALOGE("Error upping interface"); 374 cli->sendMsg(ResponseCode::OperationFailed, "Failed to up interface", true); 375 ifc_close(); 376 return 0; 377 } 378 } else if (!strcmp(flag, "down")) { 379 ALOGD("Trying to bring down %s", argv[2]); 380 if (ifc_down(argv[2])) { 381 ALOGE("Error downing interface"); 382 cli->sendMsg(ResponseCode::OperationFailed, "Failed to down interface", true); 383 ifc_close(); 384 return 0; 385 } 386 } else if (!strcmp(flag, "broadcast")) { 387 // currently ignored 388 } else if (!strcmp(flag, "multicast")) { 389 // currently ignored 390 } else if (!strcmp(flag, "running")) { 391 // currently ignored 392 } else if (!strcmp(flag, "loopback")) { 393 // currently ignored 394 } else if (!strcmp(flag, "point-to-point")) { 395 // currently ignored 396 } else { 397 cli->sendMsg(ResponseCode::CommandParameterError, "Flag unsupported", false); 398 ifc_close(); 399 return 0; 400 } 401 } 402 403 cli->sendMsg(ResponseCode::CommandOkay, "Interface configuration set", false); 404 ifc_close(); 405 return 0; 406 } else if (!strcmp(argv[1], "clearaddrs")) { 407 // arglist: iface 408 ALOGD("Clearing all IP addresses on %s", argv[2]); 409 410 ifc_clear_addresses(argv[2]); 411 412 cli->sendMsg(ResponseCode::CommandOkay, "Interface IP addresses cleared", false); 413 return 0; 414 } else if (!strcmp(argv[1], "ipv6privacyextensions")) { 415 if (argc != 4) { 416 cli->sendMsg(ResponseCode::CommandSyntaxError, 417 "Usage: interface ipv6privacyextensions <interface> <enable|disable>", 418 false); 419 return 0; 420 } 421 422 char *tmp; 423 asprintf(&tmp, "/proc/sys/net/ipv6/conf/%s/use_tempaddr", argv[2]); 424 425 if (writeFile(tmp, !strncmp(argv[3], "enable", 7) ? "2" : "0", 1) < 0) { 426 free(tmp); 427 cli->sendMsg(ResponseCode::OperationFailed, 428 "Failed to set ipv6 privacy extensions", true); 429 return 0; 430 } 431 432 free(tmp); 433 cli->sendMsg(ResponseCode::CommandOkay, "IPv6 privacy extensions changed", false); 434 return 0; 435 } else if (!strcmp(argv[1], "ipv6")) { 436 if (argc != 4) { 437 cli->sendMsg(ResponseCode::CommandSyntaxError, 438 "Usage: interface ipv6 <interface> <enable|disable>", 439 false); 440 return 0; 441 } 442 443 char *tmp; 444 asprintf(&tmp, "/proc/sys/net/ipv6/conf/%s/disable_ipv6", argv[2]); 445 446 if (writeFile(tmp, !strncmp(argv[3], "enable", 7) ? "0" : "1", 1) < 0) { 447 free(tmp); 448 cli->sendMsg(ResponseCode::OperationFailed, 449 "Failed to change IPv6 state", true); 450 return 0; 451 } 452 453 free(tmp); 454 cli->sendMsg(ResponseCode::CommandOkay, "IPv6 state changed", false); 455 return 0; 456 } else { 457 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown interface cmd", false); 458 return 0; 459 } 460 } 461 return 0; 462} 463 464 465CommandListener::ListTtysCmd::ListTtysCmd() : 466 NetdCommand("list_ttys") { 467} 468 469int CommandListener::ListTtysCmd::runCommand(SocketClient *cli, 470 int argc, char **argv) { 471 TtyCollection *tlist = sPppCtrl->getTtyList(); 472 TtyCollection::iterator it; 473 474 for (it = tlist->begin(); it != tlist->end(); ++it) { 475 cli->sendMsg(ResponseCode::TtyListResult, *it, false); 476 } 477 478 cli->sendMsg(ResponseCode::CommandOkay, "Ttys listed.", false); 479 return 0; 480} 481 482CommandListener::IpFwdCmd::IpFwdCmd() : 483 NetdCommand("ipfwd") { 484} 485 486int CommandListener::IpFwdCmd::runCommand(SocketClient *cli, 487 int argc, char **argv) { 488 int rc = 0; 489 490 if (argc < 2) { 491 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 492 return 0; 493 } 494 495 if (!strcmp(argv[1], "status")) { 496 char *tmp = NULL; 497 498 asprintf(&tmp, "Forwarding %s", (sTetherCtrl->getIpFwdEnabled() ? "enabled" : "disabled")); 499 cli->sendMsg(ResponseCode::IpFwdStatusResult, tmp, false); 500 free(tmp); 501 return 0; 502 } else if (!strcmp(argv[1], "enable")) { 503 rc = sTetherCtrl->setIpFwdEnabled(true); 504 } else if (!strcmp(argv[1], "disable")) { 505 rc = sTetherCtrl->setIpFwdEnabled(false); 506 } else { 507 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown ipfwd cmd", false); 508 return 0; 509 } 510 511 if (!rc) { 512 cli->sendMsg(ResponseCode::CommandOkay, "ipfwd operation succeeded", false); 513 } else { 514 cli->sendMsg(ResponseCode::OperationFailed, "ipfwd operation failed", true); 515 } 516 517 return 0; 518} 519 520CommandListener::TetherCmd::TetherCmd() : 521 NetdCommand("tether") { 522} 523 524int CommandListener::TetherCmd::runCommand(SocketClient *cli, 525 int argc, char **argv) { 526 int rc = 0; 527 528 if (argc < 2) { 529 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 530 return 0; 531 } 532 533 if (!strcmp(argv[1], "stop")) { 534 rc = sTetherCtrl->stopTethering(); 535 } else if (!strcmp(argv[1], "status")) { 536 char *tmp = NULL; 537 538 asprintf(&tmp, "Tethering services %s", 539 (sTetherCtrl->isTetheringStarted() ? "started" : "stopped")); 540 cli->sendMsg(ResponseCode::TetherStatusResult, tmp, false); 541 free(tmp); 542 return 0; 543 } else { 544 /* 545 * These commands take a minimum of 4 arguments 546 */ 547 if (argc < 4) { 548 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 549 return 0; 550 } 551 552 if (!strcmp(argv[1], "start")) { 553 if (argc % 2 == 1) { 554 cli->sendMsg(ResponseCode::CommandSyntaxError, "Bad number of arguments", false); 555 return 0; 556 } 557 558 int num_addrs = argc - 2; 559 int arg_index = 2; 560 int array_index = 0; 561 in_addr *addrs = (in_addr *)malloc(sizeof(in_addr) * num_addrs); 562 while (array_index < num_addrs) { 563 if (!inet_aton(argv[arg_index++], &(addrs[array_index++]))) { 564 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false); 565 free(addrs); 566 return 0; 567 } 568 } 569 rc = sTetherCtrl->startTethering(num_addrs, addrs); 570 free(addrs); 571 } else if (!strcmp(argv[1], "interface")) { 572 if (!strcmp(argv[2], "add")) { 573 rc = sTetherCtrl->tetherInterface(argv[3]); 574 } else if (!strcmp(argv[2], "remove")) { 575 rc = sTetherCtrl->untetherInterface(argv[3]); 576 } else if (!strcmp(argv[2], "list")) { 577 InterfaceCollection *ilist = sTetherCtrl->getTetheredInterfaceList(); 578 InterfaceCollection::iterator it; 579 580 for (it = ilist->begin(); it != ilist->end(); ++it) { 581 cli->sendMsg(ResponseCode::TetherInterfaceListResult, *it, false); 582 } 583 } else { 584 cli->sendMsg(ResponseCode::CommandParameterError, 585 "Unknown tether interface operation", false); 586 return 0; 587 } 588 } else if (!strcmp(argv[1], "dns")) { 589 if (!strcmp(argv[2], "set")) { 590 rc = sTetherCtrl->setDnsForwarders(&argv[3], argc - 3); 591 } else if (!strcmp(argv[2], "list")) { 592 NetAddressCollection *dlist = sTetherCtrl->getDnsForwarders(); 593 NetAddressCollection::iterator it; 594 595 for (it = dlist->begin(); it != dlist->end(); ++it) { 596 cli->sendMsg(ResponseCode::TetherDnsFwdTgtListResult, inet_ntoa(*it), false); 597 } 598 } else { 599 cli->sendMsg(ResponseCode::CommandParameterError, 600 "Unknown tether interface operation", false); 601 return 0; 602 } 603 } else { 604 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown tether cmd", false); 605 return 0; 606 } 607 } 608 609 if (!rc) { 610 cli->sendMsg(ResponseCode::CommandOkay, "Tether operation succeeded", false); 611 } else { 612 cli->sendMsg(ResponseCode::OperationFailed, "Tether operation failed", true); 613 } 614 615 return 0; 616} 617 618CommandListener::NatCmd::NatCmd() : 619 NetdCommand("nat") { 620} 621 622int CommandListener::NatCmd::runCommand(SocketClient *cli, 623 int argc, char **argv) { 624 int rc = 0; 625 626 if (argc < 5) { 627 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 628 return 0; 629 } 630 631 if (!strcmp(argv[1], "enable")) { 632 rc = sNatCtrl->enableNat(argc, argv); 633 if(!rc) { 634 /* Ignore ifaces for now. */ 635 rc = sBandwidthCtrl->setGlobalAlertInForwardChain(); 636 } 637 } else if (!strcmp(argv[1], "disable")) { 638 /* Ignore ifaces for now. */ 639 rc = sBandwidthCtrl->removeGlobalAlertInForwardChain(); 640 rc |= sNatCtrl->disableNat(argc, argv); 641 } else { 642 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown nat cmd", false); 643 return 0; 644 } 645 646 if (!rc) { 647 cli->sendMsg(ResponseCode::CommandOkay, "Nat operation succeeded", false); 648 } else { 649 cli->sendMsg(ResponseCode::OperationFailed, "Nat operation failed", true); 650 } 651 652 return 0; 653} 654 655CommandListener::PppdCmd::PppdCmd() : 656 NetdCommand("pppd") { 657} 658 659int CommandListener::PppdCmd::runCommand(SocketClient *cli, 660 int argc, char **argv) { 661 int rc = 0; 662 663 if (argc < 3) { 664 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 665 return 0; 666 } 667 668 if (!strcmp(argv[1], "attach")) { 669 struct in_addr l, r, dns1, dns2; 670 671 memset(&dns1, sizeof(struct in_addr), 0); 672 memset(&dns2, sizeof(struct in_addr), 0); 673 674 if (!inet_aton(argv[3], &l)) { 675 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid local address", false); 676 return 0; 677 } 678 if (!inet_aton(argv[4], &r)) { 679 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid remote address", false); 680 return 0; 681 } 682 if ((argc > 3) && (!inet_aton(argv[5], &dns1))) { 683 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid dns1 address", false); 684 return 0; 685 } 686 if ((argc > 4) && (!inet_aton(argv[6], &dns2))) { 687 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid dns2 address", false); 688 return 0; 689 } 690 rc = sPppCtrl->attachPppd(argv[2], l, r, dns1, dns2); 691 } else if (!strcmp(argv[1], "detach")) { 692 rc = sPppCtrl->detachPppd(argv[2]); 693 } else { 694 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown pppd cmd", false); 695 return 0; 696 } 697 698 if (!rc) { 699 cli->sendMsg(ResponseCode::CommandOkay, "Pppd operation succeeded", false); 700 } else { 701 cli->sendMsg(ResponseCode::OperationFailed, "Pppd operation failed", true); 702 } 703 704 return 0; 705} 706 707CommandListener::PanCmd::PanCmd() : 708 NetdCommand("pan") { 709} 710 711int CommandListener::PanCmd::runCommand(SocketClient *cli, 712 int argc, char **argv) { 713 int rc = 0; 714 715 if (argc < 2) { 716 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 717 return 0; 718 } 719 720 if (!strcmp(argv[1], "start")) { 721 rc = sPanCtrl->startPan(); 722 } else if (!strcmp(argv[1], "stop")) { 723 rc = sPanCtrl->stopPan(); 724 } else if (!strcmp(argv[1], "status")) { 725 char *tmp = NULL; 726 727 asprintf(&tmp, "Pan services %s", 728 (sPanCtrl->isPanStarted() ? "started" : "stopped")); 729 cli->sendMsg(ResponseCode::PanStatusResult, tmp, false); 730 free(tmp); 731 return 0; 732 } else { 733 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown pan cmd", false); 734 return 0; 735 } 736 737 if (!rc) { 738 cli->sendMsg(ResponseCode::CommandOkay, "Pan operation succeeded", false); 739 } else { 740 cli->sendMsg(ResponseCode::OperationFailed, "Pan operation failed", true); 741 } 742 743 return 0; 744} 745 746CommandListener::SoftapCmd::SoftapCmd() : 747 NetdCommand("softap") { 748} 749 750int CommandListener::SoftapCmd::runCommand(SocketClient *cli, 751 int argc, char **argv) { 752 int rc = 0, flag = 0; 753 char *retbuf = NULL; 754 755 if (argc < 2) { 756 cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Missing argument", false); 757 return 0; 758 } 759 760 if (!strcmp(argv[1], "startap")) { 761 rc = sSoftapCtrl->startSoftap(); 762 } else if (!strcmp(argv[1], "stopap")) { 763 rc = sSoftapCtrl->stopSoftap(); 764 } else if (!strcmp(argv[1], "fwreload")) { 765 rc = sSoftapCtrl->fwReloadSoftap(argc, argv); 766 } else if (!strcmp(argv[1], "clients")) { 767 rc = sSoftapCtrl->clientsSoftap(&retbuf); 768 if (!rc) { 769 cli->sendMsg(ResponseCode::CommandOkay, retbuf, false); 770 free(retbuf); 771 return 0; 772 } 773 } else if (!strcmp(argv[1], "status")) { 774 asprintf(&retbuf, "Softap service %s", 775 (sSoftapCtrl->isSoftapStarted() ? "started" : "stopped")); 776 cli->sendMsg(ResponseCode::SoftapStatusResult, retbuf, false); 777 free(retbuf); 778 return 0; 779 } else if (!strcmp(argv[1], "set")) { 780 rc = sSoftapCtrl->setSoftap(argc, argv); 781 } else { 782 cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Unknown cmd", false); 783 return 0; 784 } 785 786 if (!rc) { 787 cli->sendMsg(ResponseCode::CommandOkay, "Softap operation succeeded", false); 788 } else { 789 cli->sendMsg(ResponseCode::OperationFailed, "Softap operation failed", true); 790 } 791 792 return 0; 793} 794 795CommandListener::ResolverCmd::ResolverCmd() : 796 NetdCommand("resolver") { 797} 798 799int CommandListener::ResolverCmd::runCommand(SocketClient *cli, int argc, char **argv) { 800 int rc = 0; 801 struct in_addr addr; 802 803 if (argc < 2) { 804 cli->sendMsg(ResponseCode::CommandSyntaxError, "Resolver missing arguments", false); 805 return 0; 806 } 807 808 if (!strcmp(argv[1], "setdefaultif")) { // "resolver setdefaultif <iface>" 809 if (argc == 3) { 810 rc = sResolverCtrl->setDefaultInterface(argv[2]); 811 } else { 812 cli->sendMsg(ResponseCode::CommandSyntaxError, 813 "Wrong number of arguments to resolver setdefaultif", false); 814 return 0; 815 } 816 } else if (!strcmp(argv[1], "setifdns")) { // "resolver setifdns <iface> <dns1> <dns2> ..." 817 if (argc >= 4) { 818 rc = sResolverCtrl->setInterfaceDnsServers(argv[2], &argv[3], argc - 3); 819 } else { 820 cli->sendMsg(ResponseCode::CommandSyntaxError, 821 "Wrong number of arguments to resolver setifdns", false); 822 return 0; 823 } 824 825 // set the address of the interface to which the name servers 826 // are bound. Required in order to bind to right interface when 827 // doing the dns query. 828 if (!rc) { 829 ifc_init(); 830 ifc_get_info(argv[2], &addr.s_addr, NULL, 0); 831 832 rc = sResolverCtrl->setInterfaceAddress(argv[2], &addr); 833 } 834 } else if (!strcmp(argv[1], "flushdefaultif")) { // "resolver flushdefaultif" 835 if (argc == 2) { 836 rc = sResolverCtrl->flushDefaultDnsCache(); 837 } else { 838 cli->sendMsg(ResponseCode::CommandSyntaxError, 839 "Wrong number of arguments to resolver flushdefaultif", false); 840 return 0; 841 } 842 } else if (!strcmp(argv[1], "flushif")) { // "resolver flushif <iface>" 843 if (argc == 3) { 844 rc = sResolverCtrl->flushInterfaceDnsCache(argv[2]); 845 } else { 846 cli->sendMsg(ResponseCode::CommandSyntaxError, 847 "Wrong number of arguments to resolver setdefaultif", false); 848 return 0; 849 } 850 } else { 851 cli->sendMsg(ResponseCode::CommandSyntaxError,"Resolver unknown command", false); 852 return 0; 853 } 854 855 if (!rc) { 856 cli->sendMsg(ResponseCode::CommandOkay, "Resolver command succeeded", false); 857 } else { 858 cli->sendMsg(ResponseCode::OperationFailed, "Resolver command failed", true); 859 } 860 861 return 0; 862} 863 864int CommandListener::readInterfaceCounters(const char *iface, unsigned long *rx, unsigned long *tx) { 865 FILE *fp = fopen("/proc/net/dev", "r"); 866 if (!fp) { 867 ALOGE("Failed to open /proc/net/dev (%s)", strerror(errno)); 868 return -1; 869 } 870 871 char buffer[512]; 872 873 fgets(buffer, sizeof(buffer), fp); // Header 1 874 fgets(buffer, sizeof(buffer), fp); // Header 2 875 while(fgets(buffer, sizeof(buffer), fp)) { 876 buffer[strlen(buffer)-1] = '\0'; 877 878 char name[31]; 879 unsigned long d; 880 sscanf(buffer, "%30s %lu %lu %lu %lu %lu %lu %lu %lu %lu", 881 name, rx, &d, &d, &d, &d, &d, &d, &d, tx); 882 char *rxString = strchr(name, ':'); 883 *rxString = '\0'; 884 rxString++; 885 // when the rx count gets too big it changes from "name: 999" to "name:1000" 886 // and the sscanf munge the two together. Detect that and fix 887 // note that all the %lu will be off by one and the real tx value will be in d 888 if (*rxString != '\0') { 889 *tx = d; 890 sscanf(rxString, "%20lu", rx); 891 } 892 if (strcmp(name, iface)) { 893 continue; 894 } 895 fclose(fp); 896 return 0; 897 } 898 899 fclose(fp); 900 *rx = 0; 901 *tx = 0; 902 return 0; 903} 904 905CommandListener::BandwidthControlCmd::BandwidthControlCmd() : 906 NetdCommand("bandwidth") { 907} 908 909void CommandListener::BandwidthControlCmd::sendGenericSyntaxError(SocketClient *cli, const char *usageMsg) { 910 char *msg; 911 asprintf(&msg, "Usage: bandwidth %s", usageMsg); 912 cli->sendMsg(ResponseCode::CommandSyntaxError, msg, false); 913 free(msg); 914} 915 916void CommandListener::BandwidthControlCmd::sendGenericOkFail(SocketClient *cli, int cond) { 917 if (!cond) { 918 cli->sendMsg(ResponseCode::CommandOkay, "Bandwidth command succeeeded", false); 919 } else { 920 cli->sendMsg(ResponseCode::OperationFailed, "Bandwidth command failed", false); 921 } 922} 923 924void CommandListener::BandwidthControlCmd::sendGenericOpFailed(SocketClient *cli, const char *errMsg) { 925 cli->sendMsg(ResponseCode::OperationFailed, errMsg, false); 926} 927 928int CommandListener::BandwidthControlCmd::runCommand(SocketClient *cli, int argc, char **argv) { 929 if (argc < 2) { 930 sendGenericSyntaxError(cli, "<cmds> <args...>"); 931 return 0; 932 } 933 934 ALOGV("bwctrlcmd: argc=%d %s %s ...", argc, argv[0], argv[1]); 935 936 if (!strcmp(argv[1], "enable")) { 937 int rc = sBandwidthCtrl->enableBandwidthControl(true); 938 sendGenericOkFail(cli, rc); 939 return 0; 940 941 } 942 if (!strcmp(argv[1], "disable")) { 943 int rc = sBandwidthCtrl->disableBandwidthControl(); 944 sendGenericOkFail(cli, rc); 945 return 0; 946 947 } 948 if (!strcmp(argv[1], "removequota") || !strcmp(argv[1], "rq")) { 949 if (argc != 3) { 950 sendGenericSyntaxError(cli, "removequota <interface>"); 951 return 0; 952 } 953 int rc = sBandwidthCtrl->removeInterfaceSharedQuota(argv[2]); 954 sendGenericOkFail(cli, rc); 955 return 0; 956 957 } 958 if (!strcmp(argv[1], "getquota") || !strcmp(argv[1], "gq")) { 959 int64_t bytes; 960 if (argc != 2) { 961 sendGenericSyntaxError(cli, "getquota"); 962 return 0; 963 } 964 int rc = sBandwidthCtrl->getInterfaceSharedQuota(&bytes); 965 if (rc) { 966 sendGenericOpFailed(cli, "Failed to get quota"); 967 return 0; 968 } 969 970 char *msg; 971 asprintf(&msg, "%lld", bytes); 972 cli->sendMsg(ResponseCode::QuotaCounterResult, msg, false); 973 free(msg); 974 return 0; 975 976 } 977 if (!strcmp(argv[1], "getiquota") || !strcmp(argv[1], "giq")) { 978 int64_t bytes; 979 if (argc != 3) { 980 sendGenericSyntaxError(cli, "getiquota <iface>"); 981 return 0; 982 } 983 984 int rc = sBandwidthCtrl->getInterfaceQuota(argv[2], &bytes); 985 if (rc) { 986 sendGenericOpFailed(cli, "Failed to get quota"); 987 return 0; 988 } 989 char *msg; 990 asprintf(&msg, "%lld", bytes); 991 cli->sendMsg(ResponseCode::QuotaCounterResult, msg, false); 992 free(msg); 993 return 0; 994 995 } 996 if (!strcmp(argv[1], "setquota") || !strcmp(argv[1], "sq")) { 997 if (argc != 4) { 998 sendGenericSyntaxError(cli, "setquota <interface> <bytes>"); 999 return 0; 1000 } 1001 int rc = sBandwidthCtrl->setInterfaceSharedQuota(argv[2], atoll(argv[3])); 1002 sendGenericOkFail(cli, rc); 1003 return 0; 1004 } 1005 if (!strcmp(argv[1], "setquotas") || !strcmp(argv[1], "sqs")) { 1006 int rc; 1007 if (argc < 4) { 1008 sendGenericSyntaxError(cli, "setquotas <bytes> <interface> ..."); 1009 return 0; 1010 } 1011 1012 for (int q = 3; argc >= 4; q++, argc--) { 1013 rc = sBandwidthCtrl->setInterfaceSharedQuota(argv[q], atoll(argv[2])); 1014 if (rc) { 1015 char *msg; 1016 asprintf(&msg, "bandwidth setquotas %s %s failed", argv[2], argv[q]); 1017 cli->sendMsg(ResponseCode::OperationFailed, 1018 msg, false); 1019 free(msg); 1020 return 0; 1021 } 1022 } 1023 sendGenericOkFail(cli, rc); 1024 return 0; 1025 1026 } 1027 if (!strcmp(argv[1], "removequotas") || !strcmp(argv[1], "rqs")) { 1028 int rc; 1029 if (argc < 3) { 1030 sendGenericSyntaxError(cli, "removequotas <interface> ..."); 1031 return 0; 1032 } 1033 1034 for (int q = 2; argc >= 3; q++, argc--) { 1035 rc = sBandwidthCtrl->removeInterfaceSharedQuota(argv[q]); 1036 if (rc) { 1037 char *msg; 1038 asprintf(&msg, "bandwidth removequotas %s failed", argv[q]); 1039 cli->sendMsg(ResponseCode::OperationFailed, 1040 msg, false); 1041 free(msg); 1042 return 0; 1043 } 1044 } 1045 sendGenericOkFail(cli, rc); 1046 return 0; 1047 1048 } 1049 if (!strcmp(argv[1], "removeiquota") || !strcmp(argv[1], "riq")) { 1050 if (argc != 3) { 1051 sendGenericSyntaxError(cli, "removeiquota <interface>"); 1052 return 0; 1053 } 1054 int rc = sBandwidthCtrl->removeInterfaceQuota(argv[2]); 1055 sendGenericOkFail(cli, rc); 1056 return 0; 1057 1058 } 1059 if (!strcmp(argv[1], "setiquota") || !strcmp(argv[1], "siq")) { 1060 if (argc != 4) { 1061 sendGenericSyntaxError(cli, "setiquota <interface> <bytes>"); 1062 return 0; 1063 } 1064 int rc = sBandwidthCtrl->setInterfaceQuota(argv[2], atoll(argv[3])); 1065 sendGenericOkFail(cli, rc); 1066 return 0; 1067 1068 } 1069 if (!strcmp(argv[1], "addnaughtyapps") || !strcmp(argv[1], "ana")) { 1070 if (argc < 3) { 1071 sendGenericSyntaxError(cli, "addnaughtyapps <appUid> ..."); 1072 return 0; 1073 } 1074 int rc = sBandwidthCtrl->addNaughtyApps(argc - 2, argv + 2); 1075 sendGenericOkFail(cli, rc); 1076 return 0; 1077 1078 1079 } 1080 if (!strcmp(argv[1], "removenaughtyapps") || !strcmp(argv[1], "rna")) { 1081 if (argc < 3) { 1082 sendGenericSyntaxError(cli, "removenaughtyapps <appUid> ..."); 1083 return 0; 1084 } 1085 int rc = sBandwidthCtrl->removeNaughtyApps(argc - 2, argv + 2); 1086 sendGenericOkFail(cli, rc); 1087 return 0; 1088 1089 } 1090 if (!strcmp(argv[1], "setglobalalert") || !strcmp(argv[1], "sga")) { 1091 if (argc != 3) { 1092 sendGenericSyntaxError(cli, "setglobalalert <bytes>"); 1093 return 0; 1094 } 1095 int rc = sBandwidthCtrl->setGlobalAlert(atoll(argv[2])); 1096 sendGenericOkFail(cli, rc); 1097 return 0; 1098 1099 } 1100 if (!strcmp(argv[1], "debugsettetherglobalalert") || !strcmp(argv[1], "dstga")) { 1101 if (argc != 4) { 1102 sendGenericSyntaxError(cli, "debugsettetherglobalalert <interface0> <interface1>"); 1103 return 0; 1104 } 1105 /* We ignore the interfaces for now. */ 1106 int rc = sBandwidthCtrl->setGlobalAlertInForwardChain(); 1107 sendGenericOkFail(cli, rc); 1108 return 0; 1109 1110 } 1111 if (!strcmp(argv[1], "removeglobalalert") || !strcmp(argv[1], "rga")) { 1112 if (argc != 2) { 1113 sendGenericSyntaxError(cli, "removeglobalalert"); 1114 return 0; 1115 } 1116 int rc = sBandwidthCtrl->removeGlobalAlert(); 1117 sendGenericOkFail(cli, rc); 1118 return 0; 1119 1120 } 1121 if (!strcmp(argv[1], "debugremovetetherglobalalert") || !strcmp(argv[1], "drtga")) { 1122 if (argc != 4) { 1123 sendGenericSyntaxError(cli, "debugremovetetherglobalalert <interface0> <interface1>"); 1124 return 0; 1125 } 1126 /* We ignore the interfaces for now. */ 1127 int rc = sBandwidthCtrl->removeGlobalAlertInForwardChain(); 1128 sendGenericOkFail(cli, rc); 1129 return 0; 1130 1131 } 1132 if (!strcmp(argv[1], "setsharedalert") || !strcmp(argv[1], "ssa")) { 1133 if (argc != 3) { 1134 sendGenericSyntaxError(cli, "setsharedalert <bytes>"); 1135 return 0; 1136 } 1137 int rc = sBandwidthCtrl->setSharedAlert(atoll(argv[2])); 1138 sendGenericOkFail(cli, rc); 1139 return 0; 1140 1141 } 1142 if (!strcmp(argv[1], "removesharedalert") || !strcmp(argv[1], "rsa")) { 1143 if (argc != 2) { 1144 sendGenericSyntaxError(cli, "removesharedalert"); 1145 return 0; 1146 } 1147 int rc = sBandwidthCtrl->removeSharedAlert(); 1148 sendGenericOkFail(cli, rc); 1149 return 0; 1150 1151 } 1152 if (!strcmp(argv[1], "setinterfacealert") || !strcmp(argv[1], "sia")) { 1153 if (argc != 4) { 1154 sendGenericSyntaxError(cli, "setinterfacealert <interface> <bytes>"); 1155 return 0; 1156 } 1157 int rc = sBandwidthCtrl->setInterfaceAlert(argv[2], atoll(argv[3])); 1158 sendGenericOkFail(cli, rc); 1159 return 0; 1160 1161 } 1162 if (!strcmp(argv[1], "removeinterfacealert") || !strcmp(argv[1], "ria")) { 1163 if (argc != 3) { 1164 sendGenericSyntaxError(cli, "removeinterfacealert <interface>"); 1165 return 0; 1166 } 1167 int rc = sBandwidthCtrl->removeInterfaceAlert(argv[2]); 1168 sendGenericOkFail(cli, rc); 1169 return 0; 1170 1171 } 1172 if (!strcmp(argv[1], "gettetherstats") || !strcmp(argv[1], "gts")) { 1173 BandwidthController::TetherStats tetherStats; 1174 std::string extraProcessingInfo = ""; 1175 if (argc != 4) { 1176 sendGenericSyntaxError(cli, "gettetherstats <interface0> <interface1>"); 1177 return 0; 1178 } 1179 1180 tetherStats.ifaceIn = argv[2]; 1181 tetherStats.ifaceOut = argv[3]; 1182 int rc = sBandwidthCtrl->getTetherStats(tetherStats, extraProcessingInfo); 1183 if (rc) { 1184 extraProcessingInfo.insert(0, "Failed to get tethering stats.\n"); 1185 sendGenericOpFailed(cli, extraProcessingInfo.c_str()); 1186 return 0; 1187 } 1188 1189 char *msg = tetherStats.getStatsLine(); 1190 cli->sendMsg(ResponseCode::TetheringStatsResult, msg, false); 1191 free(msg); 1192 return 0; 1193 1194 } 1195 1196 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown bandwidth cmd", false); 1197 return 0; 1198} 1199 1200CommandListener::IdletimerControlCmd::IdletimerControlCmd() : 1201 NetdCommand("idletimer") { 1202} 1203 1204int CommandListener::IdletimerControlCmd::runCommand(SocketClient *cli, int argc, char **argv) { 1205 // TODO(ashish): Change the error statements 1206 if (argc < 2) { 1207 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 1208 return 0; 1209 } 1210 1211 ALOGV("idletimerctrlcmd: argc=%d %s %s ...", argc, argv[0], argv[1]); 1212 1213 if (!strcmp(argv[1], "enable")) { 1214 if (0 != sIdletimerCtrl->enableIdletimerControl()) { 1215 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 1216 } else { 1217 cli->sendMsg(ResponseCode::CommandOkay, "Enable success", false); 1218 } 1219 return 0; 1220 1221 } 1222 if (!strcmp(argv[1], "disable")) { 1223 if (0 != sIdletimerCtrl->disableIdletimerControl()) { 1224 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 1225 } else { 1226 cli->sendMsg(ResponseCode::CommandOkay, "Disable success", false); 1227 } 1228 return 0; 1229 } 1230 if (!strcmp(argv[1], "add")) { 1231 if (argc != 4) { 1232 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 1233 return 0; 1234 } 1235 if(0 != sIdletimerCtrl->addInterfaceIdletimer(argv[2], atoi(argv[3]))) { 1236 cli->sendMsg(ResponseCode::OperationFailed, "Failed to add interface", false); 1237 } else { 1238 cli->sendMsg(ResponseCode::CommandOkay, "Add success", false); 1239 } 1240 return 0; 1241 } 1242 if (!strcmp(argv[1], "remove")) { 1243 if (argc != 4) { 1244 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false); 1245 return 0; 1246 } 1247 // ashish: fixme timeout 1248 if (0 != sIdletimerCtrl->removeInterfaceIdletimer(argv[2], atoi(argv[3]))) { 1249 cli->sendMsg(ResponseCode::OperationFailed, "Failed to remove interface", false); 1250 } else { 1251 cli->sendMsg(ResponseCode::CommandOkay, "Remove success", false); 1252 } 1253 return 0; 1254 } 1255 1256 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown idletimer cmd", false); 1257 return 0; 1258} 1259