28#include "fsm.h" 29#include "phase.h" 30#include "lcp.h" 31#include "ipcp.h" 32#include "modem.h" 33#include "command.h" 34#include "hdlc.h" 35#include "vars.h" 36#include "auth.h" 37#include <netdb.h> 38#include <sys/socket.h> 39#include <arpa/inet.h> 40#include <net/route.h> 41#include "os.h" 42#include <paths.h> 43 44extern int MakeArgs(); 45extern void Cleanup(), TtyTermMode(), PacketMode(); 46extern int EnableCommand(), DisableCommand(), DisplayCommand(); 47extern int AcceptCommand(), DenyCommand(); 48extern int LocalAuthCommand(); 49extern int LoadCommand(), SaveCommand(); 50extern int ChangeParity(char *); 51extern int SelectSystem(); 52extern int ShowRoute(); 53extern void TtyOldMode(), TtyCommandMode(); 54extern struct pppvars pppVars; 55 56struct in_addr ifnetmask; 57 58static int ShowCommand(), TerminalCommand(), QuitCommand(); 59static int CloseCommand(), DialCommand(), DownCommand(); 60static int SetCommand(), AddCommand(), DeleteCommand(); 61static int ShellCommand(); 62 63static int 64HelpCommand(list, argc, argv, plist) 65struct cmdtab *list; 66int argc; 67char **argv; 68struct cmdtab *plist; 69{ 70 struct cmdtab *cmd; 71 int n; 72 char c; 73 74 if (argc > 0) { 75 for (cmd = plist; cmd->name; cmd++) { 76 if (strcmp(cmd->name, *argv) == 0 && (cmd->lauth & VarLocalAuth)) { 77 printf("%s %s\n", cmd->name, cmd->syntax); 78 return(1); 79 } 80 } 81 return(1); 82 } 83 n = 0; 84 for (cmd = plist; cmd->func; cmd++) { 85 if (cmd->name && (cmd->lauth & VarLocalAuth)) { 86 c = (n & 1)? '\n' : '\t'; 87 printf(" %-8s: %-20s%c", cmd->name, cmd->helpmes, c); 88 n++; 89 } 90 } 91 if (n & 1) 92 printf("\n"); 93 return(1); 94} 95 96int 97IsInteractive() 98{ 99 char *mes = NULL; 100 101 if (mode & MODE_AUTO) 102 mes = "Working in auto mode."; 103 else if (mode & MODE_DIRECT) 104 mes = "Working in direct mode."; 105 else if (mode & MODE_DEDICATED) 106 mes = "Working in dedicated mode."; 107 if (mes) { 108 printf("%s\n", mes); 109 return(0); 110 } 111 return(1); 112} 113 114static int 115DialCommand(cmdlist, argc, argv) 116struct cmdtab *cmdlist; 117int argc; 118char **argv; 119{ 120 int tries; 121 122 if (LcpFsm.state > ST_CLOSED) { 123 printf("LCP state is [%s]\n", StateNames[LcpFsm.state]); 124 return(1); 125 } 126 if (!IsInteractive()) 127 return(1); 128 if (argc > 0) { 129 if (SelectSystem(*argv, CONFFILE) < 0) { 130 printf("%s: not found.\n", *argv); 131 return(1); 132 } 133 } 134 tries = 0; 135 do { 136 printf("Dial attempt %u\n", ++tries); 137 modem = OpenModem(mode); 138 if (modem < 0) { 139 printf("failed to open modem.\n"); 140 modem = 0; 141 break; 142 } 143 if (DialModem()) { 144 sleep(1); 145 ModemTimeout(); 146 PacketMode(); 147 break; 148 } 149 } while (VarDialTries == 0 || tries < VarDialTries); 150 return(1); 151} 152 153static int 154ShellCommand(cmdlist, argc, argv) 155struct cmdtab *cmdlist; 156int argc; 157char **argv; 158{ 159 const char *shell; 160 pid_t shpid; 161 162 if((shell = getenv("SHELL")) == 0) { 163 shell = _PATH_BSHELL; 164 } 165 166#ifndef HAVE_SHELL_CMD_WITH_ANY_MODE 167 if( mode != MODE_INTER) { 168 fprintf(stdout, 169 "Can start an shell only in interactive mode\n"); 170 return(1); 171 } 172#else 173 if(argc == 0 && !(mode & MODE_INTER)) { 174 fprintf(stderr, 175 "Can start an interactive shell only in interactive mode\n"); 176 return(1); 177 } 178#endif /* HAVE_SHELL_CMD_WITH_ANY_MODE */ 179 180 if((shpid = fork()) == 0) { 181 int i; 182 for(i = 3; i < getdtablesize(); i++) 183 (void)close(i); 184 185 /* 186 * We are running setuid, we should change to 187 * real user for avoiding security problems. 188 */ 189 setgid( getgid() ); 190 setuid( getuid() ); 191 192 TtyOldMode(); 193 if(argc > 0) 194 execvp(argv[0], argv); 195 else 196 execl(shell, shell, NULL); 197 198 fprintf(stdout, "exec() of %s failed\n", argc > 0? argv[0]: shell); 199 exit(255); 200 } 201 if( shpid == (pid_t)-1 ) { 202 fprintf(stdout, "Fork failed\n"); 203 } else { 204 int status; 205 (void)waitpid(shpid, &status, 0); 206 } 207 208 TtyCommandMode(1); 209 210 return(0); 211} 212 213static char StrOption[] = "option .."; 214static char StrRemote[] = "[remote]"; 215char StrNull[] = ""; 216 217struct cmdtab Commands[] = { 218 { "accept", NULL, AcceptCommand, LOCAL_AUTH, 219 "accept option request", StrOption}, 220 { "add", NULL, AddCommand, LOCAL_AUTH, 221 "add route", "dest mask gateway"}, 222 { "close", NULL, CloseCommand, LOCAL_AUTH, 223 "Close connection", StrNull}, 224 { "delete", NULL, DeleteCommand, LOCAL_AUTH, 225 "delete route", "dest gateway"}, 226 { "deny", NULL, DenyCommand, LOCAL_AUTH, 227 "Deny option request", StrOption}, 228 { "dial", "call", DialCommand, LOCAL_AUTH, 229 "Dial and login", StrRemote}, 230 { "disable", NULL, DisableCommand, LOCAL_AUTH, 231 "Disable option", StrOption}, 232 { "display", NULL, DisplayCommand, LOCAL_AUTH, 233 "Display option configs", StrNull}, 234 { "enable", NULL, EnableCommand, LOCAL_AUTH, 235 "Enable option", StrOption}, 236 { "passwd", NULL, LocalAuthCommand,LOCAL_NO_AUTH, 237 "Password for manipulation", StrOption}, 238 { "load", NULL, LoadCommand, LOCAL_AUTH, 239 "Load settings", StrRemote}, 240 { "save", NULL, SaveCommand, LOCAL_AUTH, 241 "Save settings", StrNull}, 242 { "set", "setup", SetCommand, LOCAL_AUTH, 243 "Set parameters", "var value"}, 244 { "shell", "!", ShellCommand, LOCAL_AUTH, 245 "Run a subshell", "[sh command]"}, 246 { "show", NULL, ShowCommand, LOCAL_AUTH, 247 "Show status and statictics", "var"}, 248 { "term", NULL, TerminalCommand,LOCAL_AUTH, 249 "Enter to terminal mode", StrNull}, 250 { "quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH, 251 "Quit PPP program", StrNull}, 252 { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, 253 "Display this message", "[command]", (void *)Commands }, 254 { NULL, "down", DownCommand, LOCAL_AUTH, 255 "Generate down event", StrNull}, 256 { NULL, NULL, NULL }, 257}; 258 259extern int ReportCcpStatus(); 260extern int ReportLcpStatus(); 261extern int ReportIpcpStatus(); 262extern int ReportProtStatus(); 263extern int ReportCompress(); 264extern int ShowModemStatus(); 265extern int ReportHdlcStatus(); 266extern int ShowMemMap(); 267 268static char *LogLevelName[] = { 269 LM_PHASE, LM_CHAT, LM_LQM, LM_LCP, 270 LM_TCPIP, LM_HDLC, LM_ASYNC, 271}; 272 273static int ShowDebugLevel() 274{ 275 int i; 276 277 printf("%02x: ", loglevel); 278 for (i = LOG_PHASE; i < MAXLOGLEVEL; i++) { 279 if (loglevel & (1 << i)) 280 printf("%s ", LogLevelName[i]); 281 } 282 printf("\n"); 283 return(1); 284} 285 286static int ShowEscape() 287{ 288 int code, bit; 289 290 if (EscMap[32]) { 291 for (code = 0; code < 32; code++) { 292 if (EscMap[code]) { 293 for (bit = 0; bit < 8; bit++) { 294 if (EscMap[code] & (1<<bit)) { 295 printf(" 0x%02x", (code << 3) + bit); 296 } 297 } 298 } 299 } 300 printf("\n"); 301 } 302 return(1); 303} 304 305static int ShowTimeout() 306{ 307 printf(" Idle Timer: %d secs LQR Timer: %d secs Retry Timer: %d secs\n", 308 VarIdleTimeout, VarLqrTimeout, VarRetryTimeout); 309 return(1); 310} 311 312static int ShowAuthKey() 313{ 314 printf("AuthName = %s\n", VarAuthName); 315 printf("AuthKey = %s\n", VarAuthKey); 316 return(1); 317} 318 319static int ShowVersion() 320{ 321 extern char *VarVersion[]; 322 extern char *VarLocalVersion[]; 323 324 printf("%s - %s \n", VarVersion, VarLocalVersion); 325 return(1); 326} 327 328static int ShowLogList() 329{ 330 ListLog(); 331 return(1); 332} 333 334static int ShowRedial() 335{ 336 printf(" Redial Timer: "); 337 338 if (VarRedialTimeout >= 0) { 339 printf(" %d seconds, ", VarRedialTimeout); 340 } 341 else { 342 printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); 343 } 344 345 if (VarDialTries) 346 printf("%d dial tries", VarDialTries); 347 348 printf("\n"); 349 350 return(1); 351} 352 353 354extern int ShowIfilter(), ShowOfilter(), ShowDfilter(), ShowAfilter(); 355 356struct cmdtab ShowCommands[] = { 357 { "afilter", NULL, ShowAfilter, LOCAL_AUTH, 358 "Show keep Alive filters", StrOption}, 359 { "auth", NULL, ShowAuthKey, LOCAL_AUTH, 360 "Show auth name/key", StrNull}, 361 { "ccp", NULL, ReportCcpStatus, LOCAL_AUTH, 362 "Show CCP status", StrNull}, 363 { "compress", NULL, ReportCompress, LOCAL_AUTH, 364 "Show compression statictics", StrNull}, 365 { "debug", NULL, ShowDebugLevel, LOCAL_AUTH, 366 "Show current debug level", StrNull}, 367 { "dfilter", NULL, ShowDfilter, LOCAL_AUTH, 368 "Show Demand filters", StrOption}, 369 { "escape", NULL, ShowEscape, LOCAL_AUTH, 370 "Show escape characters", StrNull}, 371 { "hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH, 372 "Show HDLC error summary", StrNull}, 373 { "ifilter", NULL, ShowIfilter, LOCAL_AUTH, 374 "Show Input filters", StrOption}, 375 { "ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH, 376 "Show IPCP status", StrNull}, 377 { "lcp", NULL, ReportLcpStatus, LOCAL_AUTH, 378 "Show LCP status", StrNull}, 379 { "log", NULL, ShowLogList, LOCAL_AUTH, 380 "Show log records", StrNull}, 381 { "mem", NULL, ShowMemMap, LOCAL_AUTH, 382 "Show memory map", StrNull}, 383 { "modem", NULL, ShowModemStatus, LOCAL_AUTH, 384 "Show modem setups", StrNull}, 385 { "ofilter", NULL, ShowOfilter, LOCAL_AUTH, 386 "Show Output filters", StrOption}, 387 { "proto", NULL, ReportProtStatus, LOCAL_AUTH, 388 "Show protocol summary", StrNull}, 389 { "route", NULL, ShowRoute, LOCAL_AUTH, 390 "Show routing table", StrNull}, 391 { "timeout", NULL, ShowTimeout, LOCAL_AUTH, 392 "Show Idle timeout value", StrNull}, 393 { "redial", NULL, ShowRedial, LOCAL_AUTH, 394 "Show Redial timeout value", StrNull}, 395 { "version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH, 396 "Show version string", StrNull}, 397 { "help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH, 398 "Display this message", StrNull, (void *)ShowCommands}, 399 { NULL, NULL, NULL }, 400}; 401 402struct cmdtab * 403FindCommand(cmds, str, pmatch) 404struct cmdtab *cmds; 405char *str; 406int *pmatch; 407{ 408 int nmatch = 0; 409 int len = strlen(str); 410 struct cmdtab *found = NULL; 411 412 while (cmds->func) { 413 if (cmds->name && strncmp(str, cmds->name, len) == 0) { 414 nmatch++; 415 found = cmds; 416 } else if (cmds->alias && strncmp(str, cmds->alias, len) == 0) { 417 nmatch++; 418 found = cmds; 419 } 420 cmds++; 421 } 422 *pmatch = nmatch; 423 return(found); 424} 425 426int 427FindExec(cmdlist, argc, argv) 428struct cmdtab *cmdlist; 429int argc; 430char **argv; 431{ 432 struct cmdtab *cmd; 433 int val = 1; 434 int nmatch; 435 436 cmd = FindCommand(cmdlist, *argv, &nmatch); 437 if (nmatch > 1) 438 printf("Ambiguous.\n"); 439 else if (cmd && ( cmd->lauth & VarLocalAuth ) ) 440 val = (cmd->func)(cmd, --argc, ++argv, cmd->args); 441 else 442 printf("what?\n"); 443 return(val); 444} 445 446void 447Prompt(flag) 448int flag; 449{ 450 char *pconnect, *pauth; 451 452 if (!(mode & MODE_INTER)) 453 return; 454 455 if (flag) printf("\n"); 456 457 if ( VarLocalAuth == LOCAL_AUTH ) 458 pauth = " ON "; 459 else 460 pauth = " on "; 461 if (IpcpFsm.state == ST_OPENED && phase == PHASE_NETWORK) 462 pconnect = "PPP"; 463 else 464 pconnect = "ppp"; 465 printf("%s%s%s> ", pconnect, pauth, VarShortHost); 466 fflush(stdout); 467} 468 469void 470DecodeCommand(buff, nb, prompt) 471char *buff; 472int nb; 473int prompt; 474{ 475 char *vector[20]; 476 char **argv; 477 int argc, val; 478 char *cp; 479 480 val = 1; 481 if (nb > 0) { 482 cp = buff + strcspn(buff, "\r\n"); 483 if (cp) 484 *cp = '\0'; 485 { 486 argc = MakeArgs(buff, &vector); 487 argv = vector; 488 489 if (argc > 0) 490 val = FindExec(Commands, argc, argv); 491 } 492 } 493 if (val && prompt) 494 Prompt(0); 495} 496 497static int 498ShowCommand(list, argc, argv) 499struct cmdtab *list; 500int argc; 501char **argv; 502{ 503 int val = 1; 504 505 if (argc > 0) 506 val = FindExec(ShowCommands, argc, argv); 507 else 508 printf("Use ``show ?'' to get a list.\n"); 509 return(val); 510} 511 512static int 513TerminalCommand() 514{ 515 if (LcpFsm.state > ST_CLOSED) { 516 printf("LCP state is [%s]\n", StateNames[LcpFsm.state]); 517 return(1); 518 } 519 if (!IsInteractive()) 520 return(1); 521 modem = OpenModem(mode); 522 if (modem < 0) { 523 printf("failed to open modem.\n"); 524 modem = 0; 525 return(1); 526 } 527 printf("Enter to terminal mode.\n"); 528 printf("Type `~?' for help.\n"); 529 TtyTermMode(); 530 return(0); 531} 532 533static int 534QuitCommand(list, argc, argv) 535struct cmdtab *list; 536int argc; 537char **argv; 538{ 539 if (mode & (MODE_DIRECT|MODE_DEDICATED|MODE_AUTO)) { 540 if (argc > 0 && (VarLocalAuth & LOCAL_AUTH)) { 541 Cleanup(EX_NORMAL); 542 } else { 543 VarLocalAuth = LOCAL_NO_AUTH; 544 close(netfd); 545 close(1); 546 dup2(2, 1); /* Have to have something here or the modem will be 1 */ 547 netfd = -1; 548 mode &= ~MODE_INTER; 549 } 550 } else 551 Cleanup(EX_NORMAL); 552 return(1); 553} 554 555static int 556CloseCommand() 557{ 558 LcpClose(); 559 return(1); 560} 561 562static int 563DownCommand() 564{ 565 LcpDown(); 566 return(1); 567} 568 569static int SetModemSpeed(list, argc, argv) 570struct cmdtab *list; 571int argc; 572char **argv; 573{ 574 int speed; 575 576 if (argc > 0) { 577 if (strcmp(*argv, "sync") == 0) { 578 VarSpeed = 0; 579 return(1); 580 } 581 speed = atoi(*argv); 582 if (IntToSpeed(speed) != B0) { 583 VarSpeed = speed; 584 return(1); 585 } 586 printf("invalid speed.\n"); 587 } 588 return(1); 589} 590 591static int SetRedialTimeout(list, argc, argv) 592struct cmdtab *list; 593int argc; 594char **argv; 595{ 596 int timeout; 597 int tries; 598 599 if (argc == 1 || argc == 2 ) { 600 if (strcasecmp(argv[0], "random") == 0) { 601 VarRedialTimeout = -1; 602 printf("Using random redial timeout.\n"); 603 srandom(time(0)); 604 } 605 else { 606 timeout = atoi(argv[0]); 607 608 if (timeout >= 0) { 609 VarRedialTimeout = timeout; 610 } 611 else { 612 printf("invalid redial timeout\n"); 613 printf("Usage: %s %s\n", list->name, list->syntax); 614 } 615 } 616 if (argc == 2) { 617 tries = atoi(argv[1]); 618 619 if (tries >= 0) { 620 VarDialTries = tries; 621 } 622 else { 623 printf("invalid retry value\n"); 624 printf("Usage: %s %s\n", list->name, list->syntax); 625 } 626 } 627 } 628 else { 629 printf("Usage: %s %s\n", list->name, list->syntax); 630 } 631 return(1); 632} 633 634static int SetModemParity(list, argc, argv) 635struct cmdtab *list; 636int argc; 637char **argv; 638{ 639 int parity; 640 641 if (argc > 0) { 642 parity = ChangeParity(*argv); 643 if (parity < 0) 644 printf("Invalid parity.\n"); 645 else 646 VarParity = parity; 647 } 648 return(1); 649} 650 651static int 652SetDebugLevel(list, argc, argv) 653struct cmdtab *list; 654int argc; 655char **argv; 656{ 657 int level, w; 658 659 for (level = 0; argc-- > 0; argv++) { 660 if (isdigit(**argv)) { 661 w = atoi(*argv); 662 if (w < 0 || w >= MAXLOGLEVEL) { 663 printf("invalid log level.\n"); 664 break; 665 } else 666 level |= (1 << w); 667 } else { 668 for (w = 0; w < MAXLOGLEVEL; w++) { 669 if (strcasecmp(*argv, LogLevelName[w]) == 0) { 670 level |= (1 << w); 671 continue; 672 } 673 } 674 } 675 } 676 loglevel = level; 677 return(1); 678} 679 680static int 681SetEscape(list, argc, argv) 682struct cmdtab *list; 683int argc; 684char **argv; 685{ 686 int code; 687 688 for (code = 0; code < 33; code++) 689 EscMap[code] = 0; 690 while (argc-- > 0) { 691 sscanf(*argv++, "%x", &code); 692 code &= 0xff; 693 EscMap[code >> 3] |= (1 << (code&7)); 694 EscMap[32] = 1; 695 } 696 return(1); 697} 698 699static int 700SetInitialMRU(list, argc, argv) 701struct cmdtab *list; 702int argc; 703char **argv; 704{ 705 int mru; 706 707 if (argc > 0) { 708 mru = atoi(*argv); 709 if (mru < 100) 710 printf("given value is too small.\n"); 711 else if (mru > MAX_MRU) 712 printf("given value is too big.\n"); 713 else 714 VarMRU = mru; 715 } 716 return(1); 717} 718 719static int 720SetIdleTimeout(list, argc, argv) 721struct cmdtab *list; 722int argc; 723char **argv; 724{ 725 if (argc-- > 0) { 726 VarIdleTimeout = atoi(*argv++); 727 if (argc-- > 0) { 728 VarLqrTimeout = atoi(*argv++); 729 if (VarLqrTimeout < 1) 730 VarLqrTimeout = 30; 731 if (argc > 0) { 732 VarRetryTimeout = atoi(*argv); 733 if (VarRetryTimeout < 1 || VarRetryTimeout > 10) 734 VarRetryTimeout = 3; 735 } 736 } 737 } 738 return(1); 739} 740 741struct in_addr 742GetIpAddr(cp) 743char *cp; 744{ 745 struct hostent *hp; 746 struct in_addr ipaddr; 747 748 hp = gethostbyname(cp); 749 if (hp && hp->h_addrtype == AF_INET) 750 bcopy(hp->h_addr, &ipaddr, hp->h_length); 751 else if (inet_aton(cp, &ipaddr) == 0) 752 ipaddr.s_addr = 0; 753 return(ipaddr); 754} 755 756static int 757SetInterfaceAddr(list, argc, argv) 758struct cmdtab *list; 759int argc; 760char **argv; 761{
|
762 763 DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L; 764 if (argc > 0) { 765 ParseAddr(argc, argv++, 766 &DefMyAddress.ipaddr, &DefMyAddress.mask, &DefMyAddress.width); 767 if (--argc > 0) { 768 ParseAddr(argc, argv++, 769 &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width); 770 if (--argc > 0) { 771 ifnetmask = GetIpAddr(*argv); 772 if (--argc > 0) { 773 ParseAddr(argc, argv++, 774 &DefTriggerAddress.ipaddr, 775 &DefTriggerAddress.mask, 776 &DefTriggerAddress.width); 777 } 778 } 779 } 780 } 781 /* 782 * For backwards compatibility, 0.0.0.0 means any address. 783 */ 784 if (DefMyAddress.ipaddr.s_addr == 0) { 785 DefMyAddress.mask.s_addr = 0; 786 DefMyAddress.width = 0; 787 } 788 if (DefHisAddress.ipaddr.s_addr == 0) { 789 DefHisAddress.mask.s_addr = 0; 790 DefHisAddress.width = 0; 791 } 792 793 if ((mode & MODE_AUTO) || 794 ((mode & MODE_DEDICATED) && dstsystem)) { 795 OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask); 796 } 797 return(1); 798} 799 800 801#define VAR_AUTHKEY 0 802#define VAR_DIAL 1 803#define VAR_LOGIN 2 804#define VAR_AUTHNAME 3 805#define VAR_DEVICE 4 806#define VAR_ACCMAP 5 807#define VAR_PHONE 6 808 809static int 810SetVariable(list, argc, argv, param) 811struct cmdtab *list; 812int argc; 813char **argv; 814int param; 815{ 816 u_long map; 817 818 if (argc > 0) { 819 switch (param) { 820 case VAR_AUTHKEY: 821 strncpy(VarAuthKey, *argv, sizeof(VarAuthKey)-1); 822 break; 823 case VAR_AUTHNAME: 824 strncpy(VarAuthName, *argv, sizeof(VarAuthName)-1); 825 break; 826 case VAR_DIAL: 827 strncpy(VarDialScript, *argv, sizeof(VarDialScript)-1); 828 break; 829 case VAR_LOGIN: 830 strncpy(VarLoginScript, *argv, sizeof(VarDialScript)-1); 831 break; 832 case VAR_DEVICE: 833 strncpy(VarDevice, *argv, sizeof(VarDevice)-1); 834 break; 835 case VAR_ACCMAP: 836 sscanf(*argv, "%x", &map); 837 VarAccmap = map; 838 break; 839 case VAR_PHONE: 840 strncpy(VarPhone, *argv, sizeof(VarPhone)-1); 841 break; 842 } 843 } 844 return(1); 845} 846 847static int SetOpenMode(list, argc, argv) 848struct cmdtab *list; 849int argc; 850char **argv; 851{ 852 if (argc > 0) { 853 if (strcmp(*argv, "active") == 0) 854 VarOpenMode = OPEN_ACTIVE; 855 else if (strcmp(*argv, "passive") == 0) 856 VarOpenMode = OPEN_PASSIVE; 857 else 858 printf("Invalid mode.\n"); 859 } 860 return(1); 861} 862 863static char StrChatStr[] = "chat-script"; 864static char StrValue[] = "value"; 865 866extern int SetIfilter(), SetOfilter(), SetDfilter(), SetAfilter(); 867 868struct cmdtab SetCommands[] = { 869 { "accmap", NULL, SetVariable, LOCAL_AUTH, 870 "Set accmap value", "hex-value", (void *)VAR_ACCMAP}, 871 { "afilter", NULL, SetAfilter, LOCAL_AUTH, 872 "Set keep Alive filter", "..."}, 873 { "authkey", "key", SetVariable, LOCAL_AUTH, 874 "Set authentication key", "key", (void *)VAR_AUTHKEY}, 875 { "authname", NULL, SetVariable, LOCAL_AUTH, 876 "Set authentication name", "name", (void *)VAR_AUTHNAME}, 877 { "debug", NULL, SetDebugLevel, LOCAL_AUTH, 878 "Set debug level", StrValue}, 879 { "device", "line", SetVariable, LOCAL_AUTH, 880 "Set modem device name", "device-name", (void *)VAR_DEVICE}, 881 { "dfilter", NULL, SetDfilter, LOCAL_AUTH, 882 "Set demand filter", "..."}, 883 { "dial", NULL, SetVariable, LOCAL_AUTH, 884 "Set dialing script", StrChatStr, (void *)VAR_DIAL}, 885 { "escape", NULL, SetEscape, LOCAL_AUTH, 886 "Set escape characters", "hex-digit ..."}, 887 { "ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH, 888 "Set destination address", "src-addr dst-addr netmask"}, 889 { "ifilter", NULL, SetIfilter, LOCAL_AUTH, 890 "Set input filter", "..."}, 891 { "login", NULL, SetVariable, LOCAL_AUTH, 892 "Set login script", StrChatStr, (void *)VAR_LOGIN }, 893 { "mru", "mtu", SetInitialMRU, LOCAL_AUTH, 894 "Set Initial MRU value", StrValue }, 895 { "ofilter", NULL, SetOfilter, LOCAL_AUTH, 896 "Set output filter", "..." }, 897 { "openmode", NULL, SetOpenMode, LOCAL_AUTH, 898 "Set open mode", "[active|passive]"}, 899 { "parity", NULL, SetModemParity, LOCAL_AUTH, 900 "Set modem parity", "[odd|even|none]"}, 901 { "phone", NULL, SetVariable, LOCAL_AUTH, 902 "Set telephone number", "phone-number", (void *)VAR_PHONE }, 903 { "speed", NULL, SetModemSpeed, LOCAL_AUTH, 904 "Set modem speed", "speed"}, 905 { "timeout", NULL, SetIdleTimeout, LOCAL_AUTH, 906 "Set Idle timeout", StrValue}, 907 { "redial", NULL, SetRedialTimeout, LOCAL_AUTH, 908 "Set Redial timeout", "value|random [dial_attempts]"}, 909 { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, 910 "Display this message", StrNull, (void *)SetCommands}, 911 { NULL, NULL, NULL }, 912}; 913 914static int 915SetCommand(list, argc, argv) 916struct cmdtab *list; 917int argc; 918char **argv; 919{ 920 int val = 1; 921 922 if (argc > 0) 923 val = FindExec(SetCommands, argc, argv); 924 else 925 printf("Use ``set ?'' to get a list.\n"); 926 return(val); 927} 928 929 930static int 931AddCommand(list, argc, argv) 932struct cmdtab *list; 933int argc; 934char **argv; 935{ 936 struct in_addr dest, gateway, netmask; 937 938 if (argc == 3) { 939 dest = GetIpAddr(argv[0]); 940 netmask = GetIpAddr(argv[1]); 941 if (strcmp(argv[2], "HISADDR") == 0) 942 gateway = IpcpInfo.his_ipaddr; 943 else 944 gateway = GetIpAddr(argv[2]); 945 OsSetRoute(RTM_ADD, dest, gateway, netmask); 946 } else { 947 printf("Usage: %s %s\n", list->name, list->syntax); 948 } 949 return(1); 950} 951 952static int 953DeleteCommand(list, argc, argv) 954struct cmdtab *list; 955int argc; 956char **argv; 957{ 958 struct in_addr dest, gateway, netmask; 959 960 if (argc >= 2) { 961 dest = GetIpAddr(argv[0]); 962 if (strcmp(argv[1], "HISADDR") == 0) 963 gateway = IpcpInfo.his_ipaddr; 964 else 965 gateway = GetIpAddr(argv[1]); 966 netmask.s_addr = 0; 967 if (argc == 3) { 968 if (inet_aton(argv[1], &netmask) == 0) { 969 printf("bad netmask value.\n"); 970 return(1); 971 } 972 } 973 OsSetRoute(RTM_DELETE, dest, gateway, netmask); 974 } else if (argc == 1 && strcmp(argv[0], "ALL") == 0) { 975 DeleteIfRoutes(0); 976 } else { 977 printf("Usage: %s %s\n", list->name, list->syntax); 978 } 979 return(1); 980} 981
|